.uppdev: telupp

git-svn-id: svn://ultimatepp.org/upp/trunk@6621 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-30 14:12:37 +00:00
parent 8f365f9097
commit abe128a893
7 changed files with 211 additions and 50 deletions

View file

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

View file

@ -2,4 +2,6 @@
#define _telupp_icpp_init_stub
#include "Core/init"
#include "Draw/init"
#include "RichText/init"
#include "Painter/init"
#endif

View file

@ -8,11 +8,29 @@
#define IMAGEFILE <telupp/teltest.iml>
#include <Draw/iml_source.h>
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;

View file

@ -1,21 +1,24 @@
#ifndef _telupp_telupp_h_
#define _telupp_telupp_h_
#include <Draw/Draw.h>
#include <RichText/RichText.h>
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<int64> 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

View file

@ -2,15 +2,15 @@
<html>
<body>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
<canvas id="myCanvas" width="1000" height="1000" style="border:1px solid #c3c3c3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
function Log(msg)
{
if (window.console && console.log)
console.log(msg); //for firebug
if (window.console && console.log)
console.log(msg); //for firebug
}
function Char(p, ch)
@ -61,35 +61,88 @@ function ProcessDraw(s)
ctx.fillRect(x, y, cx, cy);
}
else
if(Char(p, 1)) {
if(Char(p, 2)) {
r = Get16(p);
cx = Get16(p);
cy = Get16(p);
n = cx * cy * 4;
imgData = ctx.createImageData(cx, cy);
n = icx * icy * 4;
for(i = 0; i < n; i++)
imgData.data[i] = Get8(p);
px = Get16(p);
py = Get16(p);
var img = document.createElement('canvas');
img.width = cx;
img.height = cy;
img.getContext("2d").putImageData(imgData, 0, 0);
window.img_cache[r] = img;
}
else
if(Char(p, 1)) {
n = Get16(p);
px = Get16(p);
py = Get16(p);
x = Get16(p);
y = Get16(p);
cx = Get16(p);
cy = Get16(p);
ctx.putImageData(imgData, px, py, x, y, cx, cy);
ctx.drawImage(window.img_cache[n], x, y, cx, cy, px, py, cx, cy);
}
}
}
var req = new XMLHttpRequest();
req.open('GET', 'localhost', true);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send(null);
Log("send");
req.onreadystatechange = function() {
Log("onreadystatechange");
if(req.readyState == 4 && req.status == 200)
ProcessDraw(req.responseText);
window.img_cache = {};
window.event_queue = "";
var canvas = document.getElementById("myCanvas");
canvas.onmousedown = function(event)
{
event_queue += "MD " + event.button + " " + event.clientX + " " + event.clientY + "\n";
Ping();
}
canvas.onmouseup = function(event)
{
event_queue += "MU " + event.button + " " + event.clientX + " " + event.clientY + "\n";
Ping();
}
canvas.onmousemove = function(event)
{
event_queue += "MM " + event.clientX + " " + event.clientY + "\n";
Ping();
}
var Processing = false;
var timerID;
function Ping()
{
if(!Processing) {
Processing = true;
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() {
Log("onreadystatechange");
if(req.readyState == 4 && req.status == 200) {
ProcessDraw(req.responseText);
Processing = false; // TODO: Resolve timeout
Log("FINISH");
}
}
}
if(timerID != undefined)
clearTimeout(timerID);
setTimeout(Ping, 20);
}
Ping();
</script>
</body>

View file

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

68
uppdev/telupp/test.qtf Normal file
View file

@ -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; &]