diff --git a/uppdev/telupp/TelDraw.cpp b/uppdev/telupp/TelDraw.cpp index f4deb78d6..95bd460ab 100644 --- a/uppdev/telupp/TelDraw.cpp +++ b/uppdev/telupp/TelDraw.cpp @@ -23,26 +23,34 @@ void TelDraw::Put(const Rect& r) Put(r.GetSize()); } -void TelDraw::PutImage(Point p, const Image& img, const Rect& src) +Index TelDraw::img_index; + +int TelDraw::GetImageI(TelDraw& w, const Image& img) { int id = img.GetSerialId(); int q = img_index.Find(id); if(q < 0) { // TODO: Implement some sort of victim elimination q = img_index.GetCount(); img_index.Add(id); - Put8(SETIMAGE); - Put16(q); - Put(img.GetSize()); + w.Put8(SETIMAGE); + w.Put16(q); + w.Put(img.GetSize()); const RGBA *end = ~img + img.GetLength(); for(const RGBA *s = ~img; s < end; s++) { - Put8(s->r); - Put8(s->g); - Put8(s->b); - Put8(s->a); + w.Put8(s->r); + w.Put8(s->g); + w.Put8(s->b); + w.Put8(s->a); } } + return q; +} + +void TelDraw::PutImage(Point p, const Image& img, const Rect& src) +{ + int i = GetImageI(*this, img); Put8(IMAGE); - Put16(q); + Put16(i); Put(p); Put(src); } diff --git a/uppdev/telupp/telupp.cpp b/uppdev/telupp/telupp.cpp index 42c1e0dc2..7221a812b 100644 --- a/uppdev/telupp/telupp.cpp +++ b/uppdev/telupp/telupp.cpp @@ -13,7 +13,8 @@ int mouse_x, mouse_y; void DrawSomething(Draw& w) { w.DrawRect(0, 0, 1000, 1000, White); -// ParseQTF(LoadFile(GetDataFile("test.qtf"))).Paint(Zoom(2, 10), w, 20, 20, 500); + ParseQTF(LoadFile(GetDataFile("test.qtf"))).Paint(Zoom(2, 10), w, 20, 20, 500); + w.DrawText(10, 10, AsString(mouse_x) + ' ' + AsString(mouse_y)); w.DrawImage(mouse_x, mouse_y, TeltestImg::Test()); } @@ -24,6 +25,9 @@ void ProcessEventQueue(const String& event_queue) String s = ss.GetLine(); CParser p(s); try { + if(p.Id("RI")) + TelDraw::ResetI(); + else if(p.Id("MM")) { mouse_x = p.ReadInt(); mouse_y = p.ReadInt(); @@ -54,7 +58,7 @@ void Server() // DDUMP(http.GetURI()); // DDUMP(http.GetContentLength()); String event_queue = socket.Get((int)http.GetContentLength()); -// DDUMP(event_queue); + DDUMP(event_queue); ProcessEventQueue(event_queue); @@ -63,6 +67,9 @@ void Server() DrawSomething(draw); String content = draw.result; + + DDUMP(content.GetLength()); + DDUMP(ZCompress(content).GetLength()); if(http.GetURI().GetCount() < 2) HttpResponse(socket, http.scgi, 200, "OK", "text/html", LoadFile(GetDataFile("telupp.html"))); @@ -76,7 +83,7 @@ void Server() CONSOLE_APP_MAIN { - StdLogSetup(LOG_COUT|LOG_FILE); +// StdLogSetup(LOG_COUT|LOG_FILE); if(!server.Listen(80, 10)) { LOG("Cannot open server port for listening\r\n"); diff --git a/uppdev/telupp/telupp.h b/uppdev/telupp/telupp.h index b22851fef..c43cba86d 100644 --- a/uppdev/telupp/telupp.h +++ b/uppdev/telupp/telupp.h @@ -17,7 +17,10 @@ public: SETIMAGE = 2, }; - Index img_index; + static Index img_index; + + static int GetImageI(TelDraw& w, const Image& img); + static void ResetI() { img_index.Clear(); } StringBuffer result; diff --git a/uppdev/telupp/telupp.html b/uppdev/telupp/telupp.html index 4ec361f2f..2f8fd200c 100644 --- a/uppdev/telupp/telupp.html +++ b/uppdev/telupp/telupp.html @@ -1,5 +1,17 @@ + + + + + @@ -74,6 +86,7 @@ function ProcessDraw(s) img.height = cy; img.getContext("2d").putImageData(imgData, 0, 0); window.img_cache[r] = img; + Log("Set image: " + r); } else if(Char(p, 1)) { @@ -85,14 +98,15 @@ function ProcessDraw(s) y = Get16(p); cx = Get16(p); cy = Get16(p); - + + Log("Draw image: " + n); ctx.drawImage(window.img_cache[n], x, y, cx, cy, px, py, cx, cy); } } } window.img_cache = {}; -window.event_queue = ""; +window.event_queue = "RI\n"; var canvas = document.getElementById("myCanvas"); @@ -114,6 +128,14 @@ canvas.onmousemove = function(event) Ping(); } +function ResizeCanvas() +{ + canvas.width = window.innerWidth; + canvas.height = window.innerHeight; +} + +window.onresize = ResizeCanvas(); + var Processing = false; var timerID; @@ -124,7 +146,6 @@ function Ping() var req = new XMLHttpRequest(); req.open('POST', 'localhost', true); req.overrideMimeType('text/plain; charset=x-user-defined'); - Log("SEND"); req.send(event_queue); event_queue = ""; req.onreadystatechange = function() { @@ -132,7 +153,6 @@ function Ping() if(req.readyState == 4 && req.status == 200) { ProcessDraw(req.responseText); Processing = false; // TODO: Resolve timeout - Log("FINISH"); } } } @@ -141,9 +161,10 @@ function Ping() setTimeout(Ping, 20); } +ResizeCanvas(); + Ping(); - \ No newline at end of file