git-svn-id: svn://ultimatepp.org/upp/trunk@6622 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-30 16:59:19 +00:00
parent 6a4e55ca86
commit 1ae8fa26f9
4 changed files with 57 additions and 18 deletions

View file

@ -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<int64> 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);
}

View file

@ -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");

View file

@ -17,7 +17,10 @@ public:
SETIMAGE = 2,
};
Index<int64> img_index;
static Index<int64> img_index;
static int GetImageI(TelDraw& w, const Image& img);
static void ResetI() { img_index.Clear(); }
StringBuffer result;

View file

@ -1,5 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="1000" height="1000" style="border:1px solid #c3c3c3;">
@ -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();
</script>
</body>
</html>