From abe128a89314e2b9ac14ca56f3f304b4100249d8 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 30 Nov 2013 14:12:37 +0000 Subject: [PATCH] .uppdev: telupp git-svn-id: svn://ultimatepp.org/upp/trunk@6621 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppdev/telupp/TelDraw.cpp | 29 ++++++++----- uppdev/telupp/init | 2 + uppdev/telupp/telupp.cpp | 52 ++++++++++++++++------- uppdev/telupp/telupp.h | 16 +++---- uppdev/telupp/telupp.html | 87 +++++++++++++++++++++++++++++++-------- uppdev/telupp/telupp.upp | 7 +++- uppdev/telupp/test.qtf | 68 ++++++++++++++++++++++++++++++ 7 files changed, 211 insertions(+), 50 deletions(-) create mode 100644 uppdev/telupp/test.qtf diff --git a/uppdev/telupp/TelDraw.cpp b/uppdev/telupp/TelDraw.cpp index b9dce8679..f4deb78d6 100644 --- a/uppdev/telupp/TelDraw.cpp +++ b/uppdev/telupp/TelDraw.cpp @@ -25,22 +25,31 @@ void TelDraw::Put(const Rect& r) void TelDraw::PutImage(Point p, const Image& img, const Rect& src) { - Put8(DRAW_IMAGE); - 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); + 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()); + 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); + } } + Put8(IMAGE); + Put16(q); Put(p); Put(src); } void TelDraw::PutRect(const Rect& r, Color color) -{ - Put8(DRAW_RECT); +{ // TODO: Support InvertColor + Put8(RECT); Put(r); Put8(color.GetR()); Put8(color.GetG()); diff --git a/uppdev/telupp/init b/uppdev/telupp/init index 81d99738b..6ba042ed9 100644 --- a/uppdev/telupp/init +++ b/uppdev/telupp/init @@ -2,4 +2,6 @@ #define _telupp_icpp_init_stub #include "Core/init" #include "Draw/init" +#include "RichText/init" +#include "Painter/init" #endif diff --git a/uppdev/telupp/telupp.cpp b/uppdev/telupp/telupp.cpp index 0d8360e50..42c1e0dc2 100644 --- a/uppdev/telupp/telupp.cpp +++ b/uppdev/telupp/telupp.cpp @@ -8,11 +8,29 @@ #define IMAGEFILE #include +int mouse_x, mouse_y; + void DrawSomething(Draw& w) { - w.DrawRect(0, 0, 100, 100, LtGray); - w.DrawRect(30, 30, 25, 50, Red); - w.DrawImage(10, 10, TeltestImg::Test()); + w.DrawRect(0, 0, 1000, 1000, White); +// ParseQTF(LoadFile(GetDataFile("test.qtf"))).Paint(Zoom(2, 10), w, 20, 20, 500); + w.DrawImage(mouse_x, mouse_y, TeltestImg::Test()); +} + +void ProcessEventQueue(const String& event_queue) +{ + StringStream ss(event_queue); + while(!ss.IsEof()) { + String s = ss.GetLine(); + CParser p(s); + try { + if(p.Id("MM")) { + mouse_x = p.ReadInt(); + mouse_y = p.ReadInt(); + } + } + catch(CParser::Error) {} + } } TcpSocket server; @@ -24,19 +42,33 @@ void Server() { for(;;) { TcpSocket socket; - LOG("Waiting..."); +// LOG("Waiting..."); ServerMutex.Enter(); bool b = socket.Accept(server); ServerMutex.Leave(); if(b) { - LOG("Connection accepted"); +// LOG("Connection accepted"); HttpHeader http; + TimeStop tm; http.Read(socket); - DDUMP(http.GetURI()); +// DDUMP(http.GetURI()); +// DDUMP(http.GetContentLength()); + String event_queue = socket.Get((int)http.GetContentLength()); +// DDUMP(event_queue); + + ProcessEventQueue(event_queue); + + TelDraw draw; + draw.Init(Size(1000, 1000)); + DrawSomething(draw); + + String content = draw.result; + if(http.GetURI().GetCount() < 2) HttpResponse(socket, http.scgi, 200, "OK", "text/html", LoadFile(GetDataFile("telupp.html"))); else HttpResponse(socket, http.scgi, 200, "OK", "text/plain; charset=x-user-defined", content); + DDUMP(tm); } } } @@ -45,15 +77,7 @@ void Server() CONSOLE_APP_MAIN { StdLogSetup(LOG_COUT|LOG_FILE); - - TelDraw draw; - draw.Init(Size(400, 400)); - DrawSomething(draw); - content = draw.result; - - DUMPHEX(content); - if(!server.Listen(80, 10)) { LOG("Cannot open server port for listening\r\n"); return; diff --git a/uppdev/telupp/telupp.h b/uppdev/telupp/telupp.h index 06e5502fc..b22851fef 100644 --- a/uppdev/telupp/telupp.h +++ b/uppdev/telupp/telupp.h @@ -1,21 +1,24 @@ #ifndef _telupp_telupp_h_ #define _telupp_telupp_h_ -#include +#include using namespace Upp; -enum Code { - DRAW_RECT = 0, - DRAW_IMAGE = 1, -}; - struct TelDraw : public SDraw { public: virtual void PutImage(Point p, const Image& img, const Rect& src); virtual void PutRect(const Rect& r, Color color); public: + enum Code { + RECT = 0, + IMAGE = 1, + SETIMAGE = 2, + }; + + Index img_index; + StringBuffer result; void Put8(int x) { result.Cat(x); } @@ -23,7 +26,6 @@ public: void Put(Point p); void Put(Size sz); void Put(const Rect& r); - }; #endif diff --git a/uppdev/telupp/telupp.html b/uppdev/telupp/telupp.html index 6882ba7a2..4ec361f2f 100644 --- a/uppdev/telupp/telupp.html +++ b/uppdev/telupp/telupp.html @@ -2,15 +2,15 @@ - + Your browser does not support the HTML5 canvas tag. diff --git a/uppdev/telupp/telupp.upp b/uppdev/telupp/telupp.upp index 8d8586f50..356e38576 100644 --- a/uppdev/telupp/telupp.upp +++ b/uppdev/telupp/telupp.upp @@ -1,13 +1,16 @@ uses Core, - Draw; + Draw, + RichText, + Painter; file telupp.h, teltest.iml, TelDraw.cpp, + telupp.html, telupp.cpp, - telupp.html; + test.qtf; mainconfig "" = "SSE2"; diff --git a/uppdev/telupp/test.qtf b/uppdev/telupp/test.qtf new file mode 100644 index 000000000..09e0394b9 --- /dev/null +++ b/uppdev/telupp/test.qtf @@ -0,0 +1,68 @@ +[ $$0,0#00000000000000000000000000000000:Default] +[*C@3+75 $$1,1#36268203433472503231438721581057:code] +[*/+117 $$2,0#07143242482611002448121871408047:title] +[@(128.0.255)2 $$3,0#65874547464505293575048467215454:QTF Chr] +[{_}%EN-US +[s0; [*4 QTF]&] +[s0;= [*8 QTF]&] +[s0; &] +[s0; QTF is the native format of Ultimate`+`+ rich texts (formatted +texts).&] +[s0; &] +[s0; It is byte oriented format. Bytes with values 2`-31 are ignored. +Other are interpreted as characters or formatting commands.&] +[s0; &] +[s0; Letters ([@4 a]`-[@4 zA]`-[@4 Z]), numbers ([@4 0]`-[@4 9]), space (32) +and characters&] +[s0; &] +[s0; [*@4 . , ; ! ? % ( ) / < > #]&] +[s0; &] +[s0; and bytes [* greater] than 127 are guaranteed to be never used as +command characters (not even in future versions of QTF). Other +characters should be prefixed with escape character `` (reverse +apostrophe). Group of characters can be escaped using byte 1. +Example:&] +[s0; &] +[s1; `\"`\1a`[x`]`\1`[`* bold`]`\"&] +[s0; Normal [* Bold] [/ Italic] [*/ Bold Italic] [_ Underline] [- Stroked]&] +[Rs0; Normal [* Bold] [/ Italic] [*/ Bold Italic] [_ Underline] [- Stroked]&] +[Cs0; Normal [* Bold] [/ Italic] [*/ Bold Italic] [_ Underline] [- Stroked]&] +[s0; Byte 0 represents the end of input sequence.&] +[s0; &] +[s0; Dimension units of QTF are dots `- one dot is defined as 1/600 +of inch.&] +[s0; &] +[s0; Colors are described as either number [@(128.0.255) 0]`-[@(128.0.255) 9], +with meaning&] +[s0; &] +[ {{1000:1000:1000:1000:1000:1000:1000:1000:1000:1000<96;>96;f4; [s0;%- [* 0]] +:: [s0;%- [* 1]] +:: [s0;%- [* 2]] +:: [s0;%- [* 3]] +:: [s0;%- [* 4]] +:: [s0;%- [* 5]] +:: [s0;%- [* 6]] +:: [s0;%- [* 7]] +:: [s0;%- [* 8]] +:: [s0;%- [* 9]] +::l/0r/0t/0b/0@0 [s0; ] +::@1 [s0; ] +::@2 [s0; ] +::@3 [s0; ] +::@4 [s0; ] +::@5 [s0; ] +::@6 [s0; ] +::@7 [s0; ] +::@8 [s0; ] +::@9 [s0; ] +::l/25r/25t/15b/15@2 [s0;%- [1 Black]] +:: [s0; [1 LtGray]] +:: [s0; [1 White]] +:: [s0;%- [1 Red]] +:: [s0;%- [1 Green]] +:: [s0;%- [1 Blue]] +:: [s0;%- [1 LtRed]] +:: [s0;%- [1 WhiteGray]] +:: [s0;%- [1 LtCyan]] +:: [s0;%- [1 Yellow]]}}&] +[s0; &]