diff --git a/uppdev/telupp/TelDraw.cpp b/uppdev/telupp/TelDraw.cpp new file mode 100644 index 000000000..6c6adc89c --- /dev/null +++ b/uppdev/telupp/TelDraw.cpp @@ -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()); +} diff --git a/uppdev/telupp/init b/uppdev/telupp/init new file mode 100644 index 000000000..81d99738b --- /dev/null +++ b/uppdev/telupp/init @@ -0,0 +1,5 @@ +#ifndef _telupp_icpp_init_stub +#define _telupp_icpp_init_stub +#include "Core/init" +#include "Draw/init" +#endif diff --git a/uppdev/telupp/telupp.cpp b/uppdev/telupp/telupp.cpp new file mode 100644 index 000000000..2294c5da7 --- /dev/null +++ b/uppdev/telupp/telupp.cpp @@ -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(); +} diff --git a/uppdev/telupp/telupp.h b/uppdev/telupp/telupp.h new file mode 100644 index 000000000..06e5502fc --- /dev/null +++ b/uppdev/telupp/telupp.h @@ -0,0 +1,29 @@ +#ifndef _telupp_telupp_h_ +#define _telupp_telupp_h_ + +#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: + 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 diff --git a/uppdev/telupp/telupp.html b/uppdev/telupp/telupp.html new file mode 100644 index 000000000..6c977cd85 --- /dev/null +++ b/uppdev/telupp/telupp.html @@ -0,0 +1,82 @@ + + + + + +Your browser does not support the HTML5 canvas tag. + + + + + + \ No newline at end of file diff --git a/uppdev/telupp/telupp.upp b/uppdev/telupp/telupp.upp new file mode 100644 index 000000000..a60968f05 --- /dev/null +++ b/uppdev/telupp/telupp.upp @@ -0,0 +1,13 @@ +uses + Core, + Draw; + +file + telupp.h, + TelDraw.cpp, + telupp.cpp, + telupp.html; + +mainconfig + "" = "SSE2"; +