mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
.uppdev
git-svn-id: svn://ultimatepp.org/upp/trunk@6618 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
23cbe1f09d
commit
dcf00c9311
6 changed files with 219 additions and 0 deletions
37
uppdev/telupp/TelDraw.cpp
Normal file
37
uppdev/telupp/TelDraw.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "telupp.h"
|
||||
|
||||
void TelDraw::Put16(int x)
|
||||
{
|
||||
result.Cat(LOBYTE(x));
|
||||
result.Cat(HIBYTE(x));
|
||||
}
|
||||
|
||||
void TelDraw::Put(Point p)
|
||||
{// TODO: Clamp?
|
||||
Put16(p.x);
|
||||
Put16(p.y);
|
||||
}
|
||||
|
||||
void TelDraw::Put(Size sz)
|
||||
{
|
||||
Put((Point)sz);
|
||||
}
|
||||
|
||||
void TelDraw::Put(const Rect& r)
|
||||
{
|
||||
Put(r.TopLeft());
|
||||
Put(r.GetSize());
|
||||
}
|
||||
|
||||
void TelDraw::PutImage(Point p, const Image& img, const Rect& src)
|
||||
{
|
||||
}
|
||||
|
||||
void TelDraw::PutRect(const Rect& r, Color color)
|
||||
{
|
||||
Put8(DRAW_RECT);
|
||||
Put(r);
|
||||
Put8(color.GetR());
|
||||
Put8(color.GetG());
|
||||
Put8(color.GetB());
|
||||
}
|
||||
5
uppdev/telupp/init
Normal file
5
uppdev/telupp/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _telupp_icpp_init_stub
|
||||
#define _telupp_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "Draw/init"
|
||||
#endif
|
||||
53
uppdev/telupp/telupp.cpp
Normal file
53
uppdev/telupp/telupp.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include "telupp.h"
|
||||
|
||||
void DrawSomething(Draw& w)
|
||||
{
|
||||
w.DrawRect(0, 0, 100, 100, LtGray);
|
||||
w.DrawRect(30, 30, 25, 50, Red);
|
||||
}
|
||||
|
||||
TcpSocket server;
|
||||
StaticMutex ServerMutex;
|
||||
|
||||
String content;
|
||||
|
||||
void Server()
|
||||
{
|
||||
for(;;) {
|
||||
TcpSocket socket;
|
||||
LOG("Waiting...");
|
||||
ServerMutex.Enter();
|
||||
bool b = socket.Accept(server);
|
||||
ServerMutex.Leave();
|
||||
if(b) {
|
||||
LOG("Connection accepted");
|
||||
HttpHeader http;
|
||||
http.Read(socket);
|
||||
DDUMP(http.GetURI());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
Server();
|
||||
}
|
||||
29
uppdev/telupp/telupp.h
Normal file
29
uppdev/telupp/telupp.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef _telupp_telupp_h_
|
||||
#define _telupp_telupp_h_
|
||||
|
||||
#include <Draw/Draw.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:
|
||||
StringBuffer result;
|
||||
|
||||
void Put8(int x) { result.Cat(x); }
|
||||
void Put16(int x);
|
||||
void Put(Point p);
|
||||
void Put(Size sz);
|
||||
void Put(const Rect& r);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
82
uppdev/telupp/telupp.html
Normal file
82
uppdev/telupp/telupp.html
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<canvas id="myCanvas" width="200" height="100" 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
|
||||
}
|
||||
|
||||
function Char(p, ch)
|
||||
{
|
||||
if(p.pos < p.text.length && (255 & p.text.charCodeAt(p.pos)) == ch) {
|
||||
p.pos++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Get8(p)
|
||||
{
|
||||
return p.pos < p.text.length ? (255 & p.text.charCodeAt(p.pos++)) : 0;
|
||||
}
|
||||
|
||||
function Get16(p)
|
||||
{
|
||||
var l = Get8(p);
|
||||
var h = Get8(p);
|
||||
return (h << 8) | l;
|
||||
}
|
||||
|
||||
function ProcessDraw(s)
|
||||
{
|
||||
var p = new Object;
|
||||
p.text = s;
|
||||
p.pos = 0;
|
||||
|
||||
var c=document.getElementById("myCanvas");
|
||||
var ctx=c.getContext("2d");
|
||||
|
||||
while(p.pos < p.text.length) {
|
||||
Log(p.pos + ": " + p.text.charCodeAt(p.pos));
|
||||
if(Char(p, 0)) {
|
||||
var x = Get16(p);
|
||||
var y = Get16(p);
|
||||
var cx = Get16(p);
|
||||
var cy = Get16(p);
|
||||
var r = Get8(p);
|
||||
var g = Get8(p);
|
||||
var b = Get8(p);
|
||||
Log("rect: " + x + ", " + y + ", " + cx + ", " + cy);
|
||||
var c = "rgb(" + r + "," + g + "," + b + ")";
|
||||
ctx.fillStyle = c;
|
||||
Log("color: " + c);
|
||||
ctx.fillRect(x, y, cx, cy);
|
||||
}
|
||||
else
|
||||
p.pos++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
13
uppdev/telupp/telupp.upp
Normal file
13
uppdev/telupp/telupp.upp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
uses
|
||||
Core,
|
||||
Draw;
|
||||
|
||||
file
|
||||
telupp.h,
|
||||
TelDraw.cpp,
|
||||
telupp.cpp,
|
||||
telupp.html;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2";
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue