diff --git a/uppsrc/Turtle/Basic.upt b/uppsrc/Turtle/Basic.upt deleted file mode 100644 index cb6ab127f..000000000 --- a/uppsrc/Turtle/Basic.upt +++ /dev/null @@ -1,84 +0,0 @@ -template "U++ Basic Turtle application" main; - -option "Create header" header; - -text "Server URL" host = "localhost"; -text "Connection port" port = "8888"; -text "Connection limit" limit = "100"; -option "Debug mode" debugmode; -option "Add GUI mode switch" guiflag; - -@@<:PACKAGE:>.h -??header -#ifndef _<:PACKAGE:>_<:PACKAGE:>_h -#define _<:PACKAGE:>_<:PACKAGE:>_h -<:?guiflag:> -#ifdef flagTURTLEGUI -#include -#else -#include -#endif -<:/:> -#include -<:.:> -using namespace Upp { - -} - -#endif -@@<:PACKAGE:>.cpp -<:? header :>#include "<:PACKAGE:>.h"<:.:><:? !header && !guiflag:>#include <:.:><:? !header && guiflag :>#ifdef flagTURTLEGUI -#include -#else -#include -#endif<:.:> - -using namespace Upp; - -void AppMainLoop() -{ - // "Main" stuff should go in here... -} -<:?guiflag:> -#ifdef flagTURTLEGUI -<:.:> -CONSOLE_APP_MAIN -{ -<:?debugmode:> -#ifdef _DEBUG - TurtleServer::DebugMode(); -#endif -<:.:> - // MemoryLimitKb(100000000); // Can aid preventing DDoS attacks. - - TurtleServer guiserver; - guiserver.Host("<:host:>"); - guiserver.Port(<:port:>); - guiserver.MaxConnections(<:limit:>); - RunTurtleGui(guiserver, AppMainLoop); -} -<:?guiflag:> -#else - -GUI_APP_MAIN -{ - AppMainLoop(); -} - -#endif -<:.:> -@@<:PACKAGE:>.upp -<:?guiflag:> -uses (TURTLEGUI) Turtle; -uses (!TURTLEGUI) CtrlLib; -<:/:> -uses Turtle; -<:.:> - -file<:?header:> - <:PACKAGE:>.h,<:.:> - <:PACKAGE:>.cpp; - -mainconfig - "" = "TURTLEGUI"<:?guiflag:>,<:/:>;<:.:> - <:?guiflag:>"" = "GUI";<:.:> diff --git a/uppsrc/Turtle/Complex.upt b/uppsrc/Turtle/Complex.upt deleted file mode 100644 index de0014baa..000000000 --- a/uppsrc/Turtle/Complex.upt +++ /dev/null @@ -1,117 +0,0 @@ -template "U++ Turtle application with main window" main; - -id "Main window class name" classname = PACKAGE; - -select("No layouts", "Generate layout file", "Main window has layout", "Main window has OK/Cancel") "Layout" lay = 2; - -option "Imagelist file" iml; - -text "Server URL" host = "localhost"; -text "Connection port" port = "8888"; -text "Connection limit" limit = "100"; - -option "Debug mode" debugmode; -option "Add GUI mode switch" guiflag; - -@@<:PACKAGE:>.h -#ifndef _<:PACKAGE:>_<:PACKAGE:>_h -#define _<:PACKAGE:>_<:PACKAGE:>_h -<:?guiflag:> -#ifdef flagTURTLEGUI -#include -#else -#include -#endif -<:/:> -#include -<:.:> -namespace Upp {<:?lay:> - -#define LAYOUTFILE <<:PACKAGE:>/<:PACKAGE:>.lay> -#include <:.:><:?iml:> - -#define IMAGEFILE <<:PACKAGE:>/<:PACKAGE:>.iml> -#include <:.:> - -class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout" : "TopWindow":> { -public: - <:classname:>(); -}; - -} -#endif -@@main.cpp -#include "<:PACKAGE:>.h"<:?iml:> - -#define IMAGEFILE <<:PACKAGE:>/<:PACKAGE:>.iml> -#include <:.:> - -using namespace Upp; - -<:classname:>::<:classname:>() -{<:?lay > 1:> - CtrlLayout<:(lay == 3 ? "OKCancel" : ""):>(*this, "Window title");<:.:> -} - -void AppMainLoop() -{ - // "Main" stuff should go in here... - - <:classname:>().Run(); -} -<:?guiflag:> -#ifdef flagTURTLEGUI -<:.:> -CONSOLE_APP_MAIN -{ -<:?debugmode:> -#ifdef _DEBUG - TurtleServer::DebugMode(); -#endif -<:.:> - // MemoryLimitKb(100000000); // Can aid preventing DDoS attacks. - - TurtleServer guiserver; - guiserver.Host("<:host:>"); - guiserver.Port(<:port:>); - guiserver.MaxConnections(<:limit:>); - RunTurtleGui(guiserver, AppMainLoop); -} -<:?guiflag:> -#else - -GUI_APP_MAIN -{ - AppMainLoop(); -} - -#endif -<:.:> -@@<:PACKAGE:>.lay -??lay - -LAYOUT(<:classname:>Layout, 200, 100)<:?lay == 3:> - ITEM(Button, ok, SetLabel("OK").RightPosZ(90, 80).BottomPosZ(4, 22)) - ITEM(Button, cancel, SetLabel("Cancel").RightPosZ(4, 80).BottomPosZ(4, 22))<:.:> -END_LAYOUT -@@<:PACKAGE:>.iml -??iml - -@@<:PACKAGE:>.upp -<:?guiflag:> -uses (TURTLEGUI) Turtle; -uses (!TURTLEGUI) CtrlLib; -<:/:> -uses Turtle; -<:.:> - -file - <:PACKAGE:>.h, - main.cpp<:?lay:>, - <:PACKAGE:>.lay<:.:><:?iml:>, - <:PACKAGE:>.iml<:.:>; - -mainconfig - "" = "TURTLEGUI"<:?guiflag:>,<:/:>;<:.:> - <:?guiflag:>"" = "GUI";<:.:> - diff --git a/uppsrc/Turtle/Draw.cpp b/uppsrc/Turtle/Draw.cpp deleted file mode 100644 index 57330e3b3..000000000 --- a/uppsrc/Turtle/Draw.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include "Turtle.h" - -#define LLOG(x) // LLOG(x) -#define LDUMP(x) // RDUMP(x) -#define LTIMING(x) - -namespace Upp { - -static int sHandleCount; -static Vector sFreeHandles; -static TurtleServer::Draw sTurtleDraw; -static LRUCache sImageCache; - -struct ImageSysDataMaker : LRUCache::Maker { - Image img; - - int64 Key() const override - { - return img.GetSerialId(); - } - - int Make(TurtleServer::ImageSysData& object) const override - { - object.Init(img); - return img.GetLength(); - } -}; - -static int sAllocImageHandle() -{ - return sFreeHandles.GetCount() ? sFreeHandles.Pop() : sHandleCount++; -} - -static void sFreeImageHandle(int handle) -{ - sFreeHandles.Add(handle); -} - -TurtleServer::ImageSysData::ImageSysData() -{ -} - -TurtleServer::ImageSysData::~ImageSysData() -{ - SysImageReleased(image); - sFreeImageHandle(handle); -} - -void TurtleServer::ImageSysData::Init(const Image& img) -{ - image = img; - handle = sAllocImageHandle(); - - LLOG(Format("SetImage %`, size: %`, cache size: %", - handle, image.GetSize(), sImageCache.GetSize())); - - TurtleServer::Put8(TurtleServer::SETIMAGE); - TurtleServer::Put16(handle); - TurtleServer::Put(image.GetSize()); - Image um = Unmultiply(image); - const RGBA *end = ~um + um.GetLength(); - for(const RGBA *s = ~um; s < end; s++) { - TurtleServer::Put8(s->r); - TurtleServer::Put8(s->g); - TurtleServer::Put8(s->b); - TurtleServer::Put8(s->a); - } - TurtleServer::stat_setimage++; - TurtleServer::stat_setimage_len += image.GetLength() * sizeof(RGBA); - SysImageRealized(image); -} - -TurtleServer::Draw::Draw() -{ - pos = { 0, 0 }; - PaintOnly(); - sysdraw.SetTarget(this); - SDraw::Init(TurtleServer::desktopsize); -} - -void TurtleServer::Draw::Init(const Size& sz) -{ - SDraw::Init(sz); -} - -void TurtleServer::Draw::PutImage(Point p, const Image& img, const Rect& src) -{ - LLOG(Format("Turtle::Draw::PutImage %`, size: %`, src: %`, id: %", - p, img.GetSize(), src, img.GetSerialId())); - - TurtleServer::stat_putimage++; - ImageSysDataMaker m; - - LLOG(Format("SysImage cache pixels %`, count: %", - sImageCache.GetSize(), sImageCache.GetCount())); - - m.img = img; - ImageSysData& sd = sImageCache.Get(m); - if(Rect(img.GetSize()) == src) { - Point dp = p - pos; - if(abs(dp.x) < 256 - && abs(dp.y) < 256) { - TurtleServer::Put8(dp.x < 0 - ? dp.y < 0 ? TurtleServer::IMAGENN : TurtleServer::IMAGENP - : dp.y < 0 ? TurtleServer::IMAGEPN : TurtleServer::IMAGEPP); - TurtleServer::Put8(abs(dp.x)); - TurtleServer::Put8(abs(dp.y)); - TurtleServer::Put16(sd.handle); - pos = p; - sImageCache.Shrink(25000000, 5000); // Cache must be after Paint because of PaintOnly! - return; - } - } - TurtleServer::Put8(TurtleServer::IMAGE); - TurtleServer::Put16(sd.handle); - TurtleServer::Put(p); - TurtleServer::Put(src); - pos = p; - sImageCache.Shrink(25000000, 5000); // Cache must be after Paint because of PaintOnly! -} - -void TurtleServer::Draw::PutRect(const Rect& r, Color color) -{ - LLOG("TurtleDraw::PutRect " << r << ", color " << color); - - TurtleServer::stat_putrect++; - - Point p = r.TopLeft(); - if(color == InvertColor()) { - TurtleServer::Put8(TurtleServer::INVERTRECT); - TurtleServer::Put(r); - } - else { - Size sz = r.GetSize(); - Point dp = p - pos; - if(abs(dp.x) < 256 - && abs(dp.y) < 256 - && sz.cx < 256 - && sz.cy < 256 - && 0) { // FIXME: ? - TurtleServer::Put8(dp.x < 0 - ? dp.y < 0 ? TurtleServer::RECTNN : TurtleServer::RECTNP - : dp.y < 0 ? TurtleServer::RECTPN : TurtleServer::RECTPP); - TurtleServer::Put8(abs(dp.x)); - TurtleServer::Put8(abs(dp.y)); - TurtleServer::Put8(sz.cx); - TurtleServer::Put8(sz.cy); - } - else { - TurtleServer::Put8(TurtleServer::RECT); - TurtleServer::Put(r); - } - TurtleServer::Put8(color.GetR()); - TurtleServer::Put8(color.GetG()); - TurtleServer::Put8(color.GetB()); - } - pos = p; -} - -SystemDraw& TurtleServer::BeginDraw() -{ - return sTurtleDraw.sysdraw; -} - -void TurtleServer::CommitDraw() -{ - if(recieved_update_serial < update_serial -1) // Falling behind, wait. - SyncClient(); - Flush(); -} - -void TurtleServer::SetCanvasSize(const Size& sz) -{ - sTurtleDraw.Init(sz); -} - -void TurtleServer::ResetImageCache() -{ - sImageCache.Clear(); - sFreeHandles.Clear(); - sHandleCount = 0; -} - -} - diff --git a/uppsrc/Turtle/Event.cpp b/uppsrc/Turtle/Event.cpp deleted file mode 100644 index fd0cc91c0..000000000 --- a/uppsrc/Turtle/Event.cpp +++ /dev/null @@ -1,296 +0,0 @@ -#include "Turtle.h" - -#define LLOG(x) // RLOG(x) -#define LDUMP(x) // RDUMP(x) -#define LTIMING(x) - -namespace Upp { - -static bool sQuit; // Ctrl::IsEndSession() would be much better to use had it been implemented. -static BiVector sEventQueue; - -Point ReadPoint(CParser& p) -{ - Point pt; - pt.x = p.ReadInt(); - pt.y = p.ReadInt(); - return pt; -} - -bool TurtleServer::ProcessEvent(bool *quit) -{ - if(!IsWaitingEvent()) - return false; - - while(sEventQueue.GetCount() >= 2 - && *sEventQueue[0] == 'M' - && *sEventQueue[1] == 'M') - sEventQueue.DropHead(); // MouseMove compression - - String event = sEventQueue[0]; - sEventQueue.DropHead(); - - LLOG("Processing event " << event); - - CParser p(event); - - try - { - if(p.Id("i")) - { - ResetImageCache(); - } - else - if(p.Id("R")) - { - Resize(p); - } - else - if(p.Id("M")) - { - MouseMove(p); - } - else - if(p.Id("W")) - { - MouseWheel(p); - } - else - if(p.Id("I")) - { - mousein = true; - } - else - if(p.Id("O")) - { - mousebuttons = 0; - mousein = false; - } - else - if(p.Id("D")) - { - MouseButton(Ctrl::DOWN, p); - } - else - if(p.Id("U")) - { - MouseButton(Ctrl::UP, p); - } - else - if(p.Id("K")) - { - KeyDown(event, p); - } - else - if(p.Id("k")) - { - KeyUp(event, p); - } - else - if(p.Id("C")) - { - KeyPress(event, p); - } - } - catch(const CParser::Error& e) - { - LLOG("ProcessEvent() -> Parser error"); - } - - return true; -} - -void TurtleServer::WaitEvent(int ms) -{ - websocket.Do(); - SocketWaitEvent we; - websocket.AddTo(we); - we.Wait(ms); -} - -bool TurtleServer::IsWaitingEvent() -{ - websocket.Do(); - - String s = websocket.Receive(); - - if(websocket.IsClosed()) { - Ctrl::EndSession(); - sQuit = true; // Ugly.. - return false; - } - - if(s.GetCount() == 0) - return sEventQueue.GetCount(); - - LLOG("Received data " << s); - - StringStream ss(s); - while(!ss.IsEof()) { - String s = ss.GetLine(); - CParser p(s); - try - { - if(p.Id("S")) { - uint32 l = p.ReadNumber(); - uint32 h = p.ReadNumber(); - recieved_update_serial = MAKEQWORD(l, h); - stat_client_ms = p.ReadNumber(); - } - else - sEventQueue.AddTail(s); - } - catch(const CParser::Error& e) - { - LLOG("IsWaitingEvent() -> Parser error."); - } - } - if(recieved_update_serial == serial_0) { - serial_0 = 0; - stat_roundtrip_ms = msecs() - serial_time0; - serial_time0 = Null; - } - - if(websocket.IsError()) - LLOG("ERROR: " << websocket.GetErrorDesc()); - - return sEventQueue.GetCount(); -} - -void TurtleServer::SyncClient() -{ - while(recieved_update_serial < update_serial && !sQuit) { - Ctrl::GuiSleep(10); - IsWaitingEvent(); - } -} - -void TurtleServer::MouseButton(dword event, CParser& p) -{ - auto MaxDistance = [](Point a, Point b) -> int - { - return IsNull(a) ? INT_MAX : max(abs(a.x - b.x), abs(a.y - b.y)); - }; - - static int64 sMouseDownTime; - static Point sMouseDownPos; - - int bt = p.ReadInt(); - Point pt = ReadPoint(p); - int64 tm = p.ReadInt64(); - - dword down = (dword) event == Ctrl::DOWN; - dword bt2 = decode(bt, 0, (1 << 0), 2, (1 << 1), (1 << 2)); - mousebuttons = (mousebuttons & ~bt2) | (-down & bt2); // Toggles button flags. - - if(event == Ctrl::DOWN) { - if(MaxDistance(sMouseDownPos, pt) < GUI_DragDistance() && tm - sMouseDownTime < 800) { - event = Ctrl::DOUBLE; - sMouseDownTime = 0; - } - else { - sMouseDownPos = pt; - sMouseDownTime = tm; - } - } - - ReadModifierKeys(p); - Ctrl::DoMouseFB(decode(bt, 0, Ctrl::LEFT, 2, Ctrl::RIGHT, Ctrl::MIDDLE) | event, pt, 0); -} - -void TurtleServer::MouseWheel(CParser& p) -{ - double w = p.ReadDouble(); - Point pt = ReadPoint(p); - ReadModifierKeys(p); - Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, pt, w < 0 ? 120 : -120); -} - -void TurtleServer::MouseMove(CParser& p) -{ - Point pt = ReadPoint(p); - ReadModifierKeys(p); - Ctrl::DoMouseFB(Ctrl::MOUSEMOVE, pt, 0); -} - -void TurtleServer::KeyDown(const String& event, CParser& p) -{ - int count = 1; - int code = p.ReadInt(); - int which = p.ReadInt(); - - for(;;) { - if(sEventQueue.GetCount() - && sEventQueue[0] == event) { // Chrome autorepeat - sEventQueue.DropHead(); - count++; - } - else - if(sEventQueue.GetCount() >= 2 - && *sEventQueue[0] == 'C' - && sEventQueue[1] == event) { // Firefox autorepeat - String h = sEventQueue[0]; - sEventQueue.DropHead(); - sEventQueue.DropHead(); - sEventQueue.AddHead(h); - count++; - } - else - break; - } - - ReadModifierKeys(p); - Ctrl::DoKeyFB(TranslateWebKeyToK(which), count); -} - -void TurtleServer::KeyUp(const String& event, CParser& p) -{ - int code = p.ReadInt(); - int which = p.ReadInt(); - - ReadModifierKeys(p); - Ctrl::DoKeyFB(TranslateWebKeyToK(which) | K_KEYUP, 1); -} - -void TurtleServer::KeyPress(const String& event, CParser& p) -{ - int code = p.ReadInt(); - int which = p.ReadInt(); - - ReadModifierKeys(p); - - while(sEventQueue.GetCount() && sEventQueue[0] == event) // 'K_'s are not there anymore - sEventQueue.DropHead(); - - if(which && !GetAlt() && !GetCtrl() && findarg(which, 0x09, 0x0D, 0x20) < 0) - Ctrl::DoKeyFB(which, 1); -} - -void TurtleServer::Resize(CParser& p) -{ - desktopsize = ReadPoint(p); - SetCanvasSize(desktopsize); - Ctrl::SetDesktopSize(desktopsize); -} - -void TurtleServer::SetMouseCursor(const Image& image) -{ - int64 q = image.GetAuxData(); - if(q) { - Put8(STD_CURSORIMAGE); - Put8(clamp((int)q, 1, 16)); - } - else { - Point pt = image.GetHotSpot(); - String h; - h << "url('data:image/png;base64," - << Base64Encode(PNGEncoder().SaveString(image)) - << "') " << pt.x << ' ' << pt.y << ", default"; - Put8(SETCURSORIMAGE); - Put16(0); // TODO: Cursor cache - Put(h); - Put8(MOUSECURSOR); - Put16(0); // TODO: Cursor cache - } -} -} diff --git a/uppsrc/Turtle/Init.cpp b/uppsrc/Turtle/Init.cpp deleted file mode 100644 index b73e5bcb5..000000000 --- a/uppsrc/Turtle/Init.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "Turtle.h" - -#define LLOG(x) // LLOG(x) -#define LDUMP(x) // RDUMP(x) -#define LTIMING(x) - -namespace Upp { -String TurtleServer::host = "localhost"; -int TurtleServer::port = 8888; -String TurtleServer::ip = "0.0.0.0"; -int TurtleServer::connection_limit = 100; -bool TurtleServer::debugmode; -WebSocket TurtleServer::websocket; -int TurtleServer::mainpid; -bool TurtleServer::quit; -bool TurtleServer::mousein; -dword TurtleServer::mousebuttons = 0; -dword TurtleServer::modifierkeys = 0; -Size TurtleServer::desktopsize = Size(1024, 1024); -int64 TurtleServer::update_serial = 0; -int64 TurtleServer::recieved_update_serial; -int TurtleServer::serial_time0 = Null; -int64 TurtleServer::serial_0 = 0; -Time TurtleServer::stat_started; -int64 TurtleServer::stat_data_send; -int TurtleServer::stat_putrect; -int TurtleServer::stat_putimage; -int TurtleServer::stat_setimage; -int64 TurtleServer::stat_setimage_len; -int TurtleServer::stat_roundtrip_ms; -int TurtleServer::stat_client_ms; - -Event TurtleServer::WhenConnect; -Event TurtleServer::WhenTerminate; -Event<> TurtleServer::WhenDisconnect; - -void RunTurtleGui(TurtleServer& gui, Event<> app_main) -{ - if(TurtleServer::StartSession()) - RunVirtualGui((VirtualGui &) gui, app_main); -} - -} diff --git a/uppsrc/Turtle/Keys.cpp b/uppsrc/Turtle/Keys.cpp deleted file mode 100644 index 15b3965ba..000000000 --- a/uppsrc/Turtle/Keys.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include "Turtle.h" - -namespace Upp { - -#define WEBKEY(x) x - -const static VectorMap sKeyCodeMap = { - { WEBKEY(3), K_BREAK }, - { WEBKEY(8), K_BACKSPACE }, - { WEBKEY(9), K_TAB }, - { WEBKEY(13), K_RETURN }, - { WEBKEY(16), K_SHIFT_KEY }, - { WEBKEY(17), K_CTRL_KEY }, - { WEBKEY(18), K_ALT_KEY }, - { WEBKEY(20), K_CAPSLOCK }, - { WEBKEY(27), K_ESCAPE }, - { WEBKEY(32), K_SPACE }, - { WEBKEY(33), K_PAGEUP }, - { WEBKEY(34), K_PAGEDOWN }, - { WEBKEY(35), K_END }, - { WEBKEY(36), K_HOME }, - { WEBKEY(37), K_LEFT }, - { WEBKEY(38), K_UP }, - { WEBKEY(39), K_RIGHT }, - { WEBKEY(40), K_DOWN }, - { WEBKEY(45), K_INSERT }, - { WEBKEY(46), K_DELETE }, - { WEBKEY('A'), K_A }, - { WEBKEY('B'), K_B }, - { WEBKEY('C'), K_C }, - { WEBKEY('D'), K_D }, - { WEBKEY('E'), K_E }, - { WEBKEY('F'), K_F }, - { WEBKEY('G'), K_G }, - { WEBKEY('H'), K_H }, - { WEBKEY('I'), K_I }, - { WEBKEY('J'), K_J }, - { WEBKEY('K'), K_K }, - { WEBKEY('L'), K_L }, - { WEBKEY('M'), K_M }, - { WEBKEY('N'), K_N }, - { WEBKEY('O'), K_O }, - { WEBKEY('P'), K_P }, - { WEBKEY('Q'), K_Q }, - { WEBKEY('R'), K_R }, - { WEBKEY('S'), K_S }, - { WEBKEY('T'), K_T }, - { WEBKEY('U'), K_U }, - { WEBKEY('V'), K_V }, - { WEBKEY('W'), K_W }, - { WEBKEY('X'), K_X }, - { WEBKEY('Y'), K_Y }, - { WEBKEY('Z'), K_Z }, - { WEBKEY('0'), K_0 }, - { WEBKEY('1'), K_1 }, - { WEBKEY('2'), K_2 }, - { WEBKEY('3'), K_3 }, - { WEBKEY('4'), K_4 }, - { WEBKEY('5'), K_5 }, - { WEBKEY('6'), K_6 }, - { WEBKEY('7'), K_7 }, - { WEBKEY('8'), K_8 }, - { WEBKEY('9'), K_9 }, - { WEBKEY(96), K_NUMPAD0 }, - { WEBKEY(97), K_NUMPAD1 }, - { WEBKEY(98), K_NUMPAD2 }, - { WEBKEY(99), K_NUMPAD3 }, - { WEBKEY(100), K_NUMPAD4 }, - { WEBKEY(101), K_NUMPAD5 }, - { WEBKEY(102), K_NUMPAD6 }, - { WEBKEY(103), K_NUMPAD7 }, - { WEBKEY(104), K_NUMPAD8 }, - { WEBKEY(105), K_NUMPAD9 }, - { WEBKEY(106), K_MULTIPLY }, - { WEBKEY(107), K_ADD }, - { WEBKEY(108), K_SEPARATOR }, - { WEBKEY(109), K_SUBTRACT }, - { WEBKEY(110), K_DECIMAL }, - { WEBKEY(111), K_DIVIDE }, - { WEBKEY(145), K_SCROLL }, - { WEBKEY(112), K_F1 }, - { WEBKEY(113), K_F2 }, - { WEBKEY(114), K_F3 }, - { WEBKEY(115), K_F4 }, - { WEBKEY(116), K_F5 }, - { WEBKEY(117), K_F6 }, - { WEBKEY(118), K_F7 }, - { WEBKEY(119), K_F8 }, - { WEBKEY(120), K_F9 }, - { WEBKEY(121), K_F10 }, - { WEBKEY(122), K_F11 }, - { WEBKEY(123), K_F12 }, - { WEBKEY(219), K_CTRL_LBRACKET }, - { WEBKEY(221), K_CTRL_RBRACKET }, - { WEBKEY(173), K_CTRL_MINUS }, // Firefox specific. - { WEBKEY(189), K_CTRL_MINUS }, - { WEBKEY(192), K_CTRL_GRAVE }, - { WEBKEY(191), K_CTRL_SLASH }, - { WEBKEY(220), K_CTRL_BACKSLASH }, - { WEBKEY(188), K_CTRL_COMMA }, - { WEBKEY(190), K_CTRL_PERIOD }, - { WEBKEY(59) , K_CTRL_SEMICOLON }, // Firefox specific. - { WEBKEY(186), K_CTRL_SEMICOLON }, - { WEBKEY(61) , K_CTRL_EQUAL }, // Firefox specific. - { WEBKEY(187), K_CTRL_EQUAL }, - { WEBKEY(222), K_CTRL_APOSTROPHE }, -}; - -#undef WEBKEY - -dword TurtleServer::TranslateWebKeyToK(dword key) -{ - int i = sKeyCodeMap.Find(key); - - if(i < 0) - return key | K_DELTA; - - key = sKeyCodeMap[i]; - - if(key == K_ALT_KEY || key == K_CTRL_KEY || key == K_SHIFT_KEY) - return key; - - if(GetAlt()) key |= K_ALT; - if(GetCtrl()) key |= K_CTRL; - if(GetShift()) key |= K_SHIFT; - - return key; -} - -void TurtleServer::ReadModifierKeys(CParser& p) -{ - const char *s = p.GetPtr(); - if(*s && *s++ == '1') modifierkeys |= KM_SHIFT; else modifierkeys &= ~KM_SHIFT; - if(*s && *s++ == '1') modifierkeys |= KM_CTRL; else modifierkeys &= ~KM_CTRL; - if(*s && *s++ == '1') modifierkeys |= KM_ALT; else modifierkeys &= ~KM_ALT; -} -} diff --git a/uppsrc/Turtle/Server.cpp b/uppsrc/Turtle/Server.cpp deleted file mode 100644 index c7eb061c1..000000000 --- a/uppsrc/Turtle/Server.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "Turtle.h" -#include "Turtle.brc" - -#ifdef PLATFORM_POSIX -#include -#endif - -#define LLOG(x) // RLOG(x) -#define LDUMP(x) // RDUMP(x) -#define LTIMING(x) - -namespace Upp { - -static Vector sChildPids; - -static bool sSendTurtleHtml(TcpSocket& s, const String& host, int port) -{ - HttpHeader h; - if(!h.Read(s)) - return false; - LLOG("Sending Turtle HTML"); - String html = String(turtle_html, turtle_html_length); - html.Replace("%%host%%", Format("ws://%s:%d", host, port)); - return HttpResponse(s, h.scgi, 200, "OK", "text/html", html); -} - -static void sUpdateChildList() -{ -#ifdef PLATFORM_POSIX - int i = 0; - while(i < sChildPids.GetCount()) { - if(sChildPids[i] && waitpid(sChildPids[i], 0, WNOHANG | WUNTRACED) > 0) { - TurtleServer::WhenTerminate(sChildPids[i]); - sChildPids.Remove(i); - } - else ++i; - } -#endif -} - -void TurtleServer::Broadcast(int signal) -{ -#ifdef PLATFORM_POSIX - if(getpid() == mainpid) - for(int i = 0; i < sChildPids.GetCount(); i++) - kill(sChildPids[i], signal); -#endif -} - -bool TurtleServer::StartSession() -{ - // TODO: See if we can add secure websocket (wss://) support. - - LLOG("Connect"); - -#ifdef PLATFORM_POSIX - mainpid = getpid(); -#endif - - IpAddrInfo ipinfo; - ipinfo.Execute(ip, port, IpAddrInfo::FAMILY_IPV4); - - TcpSocket server; - -#ifdef _DEBUG - int cnt = 0; - while(!server.Listen(ipinfo, port, 5, false, true)) { - LLOG("Trying to start listening (other process using the same port?) " << ++cnt); - Sleep(1000); - } -#else - if(!server.Listen(ipinfo, port, 5, false, true)) { - LLOG("Cannot open server socket for listening!"); - Exit(1); - } -#endif - - LLOG("Starting to listen on " << port << ", pid: " << getpid()); - - for(;;) { - sUpdateChildList(); - if(server.IsError()) - server.ClearError(); - TcpSocket socket; - if(!socket.Accept(server)) - continue; - if(!sSendTurtleHtml(socket, host, port)) - continue; - websocket.NonBlocking(); - while(!websocket.Accept(server)) - Sleep(20); - LLOG("Websocket connection accepted. IP: " << websocket.GetPeerAddr()); -#ifdef PLATFORM_POSIX - if(sChildPids.GetCount() >= connection_limit) - continue; - if(debugmode) - break; - int newpid = fork(); - if(!newpid) - break; - else { - LLOG("Process forked. Pid: " << newpid); - sChildPids.Add(newpid); - WhenConnect(newpid, websocket.GetPeerAddr()); - continue; - } -#else - break; -#endif - } - - server.Close(); - stat_started = GetSysTime(); - return true; -} -} diff --git a/uppsrc/Turtle/Stream.cpp b/uppsrc/Turtle/Stream.cpp deleted file mode 100644 index 6d7ce6b30..000000000 --- a/uppsrc/Turtle/Stream.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "Turtle.h" - -#define LLOG(x) // LLOG(x) -#define LDUMP(x) // RDUMP(x) -#define LTIMING(x) - -namespace Upp { - -static TurtleServer::Stream sTurtleStream; - -TurtleServer::Stream::Stream() -{ - Reset(); -} - -void TurtleServer::Stream::Out(const void *data, dword size) -{ - zlib.Put(data, (int) size); -} - -String TurtleServer::Stream::FlushStream() -{ - Flush(); - zlib.End(); - String s = zlib.Get(); - Reset(); - return s; -} - -void TurtleServer::Stream::Reset() -{ - zlib.Clear(); - zlib.Compress(); - hasdata = false; -} - -void TurtleServer::Put8(int x) -{ - sTurtleStream.hasdata = true; - sTurtleStream.Put(x); -} - -void TurtleServer::Put16(int x) -{ - Put8(LOBYTE(x)); - Put8(HIBYTE(x)); -} - -void TurtleServer::Put32(int x) -{ - Put16(LOWORD(x)); - Put16(HIWORD(x)); -} - -void TurtleServer::Put(Point p) -{ - // TODO: Clamp? - Put16(p.x); - Put16(p.y); -} - -void TurtleServer::Put(Size sz) -{ - Put((Point)sz); -} - -void TurtleServer::Put(const Rect& r) -{ - Put(r.TopLeft()); - Put(r.GetSize()); -} - -void TurtleServer::Put(const String& s) -{ - Put32(s.GetLength()); - sTurtleStream.hasdata = true; - sTurtleStream.Put(s); -} - -//void Turtle_PutLink(const String& link) // FIXME -//{ -// TurtleServer::Put8(OPENLINK); -// TurtleServer::Put(link); -//} - -void TurtleServer::Flush() -{ - if(!sTurtleStream.hasdata || websocket.IsClosed()) - return; - - websocket.SendBinary(ZCompress(String(DISABLESENDING, 1))); // Do not send events until data transfered and processed - int64 x = ++update_serial; - if(IsNull(serial_time0)) { - serial_time0 = msecs(); - serial_0 = update_serial; - } - Put8(UPDATESERIAL); - Put32(LODWORD(x)); - Put32(HIDWORD(x)); - String s = sTurtleStream.FlushStream(); - stat_data_send += s.GetCount(); - LLOG("Sending " << s.GetLength()); - websocket.SendBinary(s); -} -} diff --git a/uppsrc/Turtle/Turtle.brc b/uppsrc/Turtle/Turtle.brc deleted file mode 100644 index e5c5409ae..000000000 --- a/uppsrc/Turtle/Turtle.brc +++ /dev/null @@ -1 +0,0 @@ -BINARY(turtle_html, "Turtle.html") diff --git a/uppsrc/Turtle/Turtle.h b/uppsrc/Turtle/Turtle.h deleted file mode 100644 index 839ef4601..000000000 --- a/uppsrc/Turtle/Turtle.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef _VirtualGui_Turtle_h -#define _VirtualGui_Turtle_h - -#include - -namespace Upp { - -class TurtleServer : public VirtualGui { -public: - TurtleServer() {} - TurtleServer(const String& host, int port) { Host(host).Port(port); } - TurtleServer(const String& ip, String& host, int port) { Bind(ip).Host(host).Port(port); } - - TurtleServer& Bind(const String& addr) { TurtleServer::ip = addr; return *this; } - TurtleServer& Host(const String& host) { TurtleServer::host = host; return *this; } - TurtleServer& Port(int port) { TurtleServer::port = port; return *this; } - TurtleServer& MaxConnections(int limit) { TurtleServer::connection_limit = max(1, limit); return *this; } - - static void DebugMode(bool b = true) { TurtleServer::debugmode = b; } - - static Event WhenConnect; - static Event WhenTerminate; - static Event<> WhenDisconnect; - -private: - virtual dword GetOptions() { return GUI_SETMOUSECURSOR; } - virtual Size GetSize() { return desktopsize; } - virtual dword GetMouseButtons() { return mousebuttons; } - virtual dword GetModKeys() { return modifierkeys; } - virtual bool IsMouseIn() { return mousein; } - virtual bool ProcessEvent(bool *quit); - virtual void WaitEvent(int ms); - virtual bool IsWaitingEvent(); - virtual void SetMouseCursor(const Image& image); - virtual void SetCaret(const Rect& caret) {} - virtual SystemDraw& BeginDraw(); - virtual void CommitDraw(); - virtual void WakeUpGuiThread() {} - virtual void Quit() { WhenDisconnect(); } - -private: - void MouseButton(dword event, CParser& p); - void MouseWheel(CParser& p); - void MouseMove(CParser& p); - void KeyDown(const String& event, CParser& p); - void KeyUp(const String& event, CParser& p); - void KeyPress(const String& event, CParser& p); - void Resize(CParser& p); - - void ReadModifierKeys(CParser& p); - dword TranslateWebKeyToK(dword key); - - static void Broadcast(int signal); - void SyncClient(); - -public: - struct Stream : OutStream - { - Stream(); - void Out(const void *data, dword size) final; - String FlushStream(); - void Reset(); - Zlib zlib; - bool hasdata; - }; - - struct ImageSysData - { - ImageSysData(); - ~ImageSysData(); - void Init(const Image& img); - Image image; - int handle; - }; - - struct Draw : SDraw - { - Draw(); - void Init(const Size& sz); - void PutImage(Point p, const Image& img, const Rect& src) final; - void PutRect(const Rect& r, Color color) final; - Point pos; - SystemDraw sysdraw; - }; - - friend struct TurtleServer::Draw; - friend struct TurtleServer::ImageSysData; - -public: - enum Commands { - RECT = 0, - IMAGE = 1, - SETIMAGE = 2, - INVERTRECT = 3, - STD_CURSORIMAGE = 4, - SETCURSORIMAGE = 5, - MOUSECURSOR = 6, - DISABLESENDING = 7, - UPDATESERIAL = 8, - - IMAGEPP = 9, - IMAGENP = 10, - IMAGEPN = 11, - IMAGENN = 12, - - RECTPP = 13, - RECTNP = 14, - RECTPN = 15, - RECTNN = 16, - - SETCARET = 17, - - HORZDRAGLINE = 18, - VERTDRAGLINE = 19, - - OPENLINK = 20, - }; - -private: - static void Put8(int x); - static void Put16(int x); - static void Put32(int x); - static void Put(Point p); - static void Put(Size sz); - static void Put(const Rect& r); - static void Put(const String& s); - static void Flush(); - - static void SetCanvasSize(const Size& sz); - static void ResetImageCache(); - -private: - static WebSocket websocket; - static dword mousebuttons; - static dword modifierkeys; - static Size desktopsize; - static int mainpid; - static int64 update_serial; - static int64 recieved_update_serial; - static int64 serial_0; - static int serial_time0; - static bool quit; - static String host; - static int port; - static String ip; - static int connection_limit; - static bool debugmode; - static bool mousein; - -public: - // Statistics. - static Time stat_started; - static int64 stat_data_send; - static int stat_putrect; - static int stat_putimage; - static int stat_setimage; - static int64 stat_setimage_len; - static int stat_roundtrip_ms; - static int stat_client_ms; - -private: - static bool StartSession(); - friend void RunTurtleGui(TurtleServer&, Event<>); -}; - -void RunTurtleGui(TurtleServer& gui, Event<> app_main); - -} -#endif diff --git a/uppsrc/Turtle/Turtle.html b/uppsrc/Turtle/Turtle.html deleted file mode 100644 index 224a86fde..000000000 --- a/uppsrc/Turtle/Turtle.html +++ /dev/null @@ -1,587 +0,0 @@ - - - - - - - - - - -Your browser does not support the HTML5 canvas tag. - - - - - diff --git a/uppsrc/Turtle/Turtle.upp b/uppsrc/Turtle/Turtle.upp deleted file mode 100644 index 71b36ed78..000000000 --- a/uppsrc/Turtle/Turtle.upp +++ /dev/null @@ -1,23 +0,0 @@ -description "HTML5 thin client backend\377B128,0,255"; - -uses - CtrlLib, - VirtualGui; - -uses(WIN32 & MSC) plugin/DroidFonts; - -file - Turtle.h, - Init.cpp, - Stream.cpp, - Server.cpp, - Keys.cpp, - Event.cpp, - Draw.cpp, - Info readonly separator, - Turtle.brc, - Turtle.html, - Docs readonly separator, - src.tpp, - issues; - diff --git a/uppsrc/Turtle/issues b/uppsrc/Turtle/issues deleted file mode 100644 index 8778a2075..000000000 --- a/uppsrc/Turtle/issues +++ /dev/null @@ -1,24 +0,0 @@ -Known Issues ------------- - -1) LaunchWebBrowser function doesn't work, at the moment. - - Hopefully, this is a temporary regression. - Maybe it should be handled generally for VirtualGUi-based stuff, using a callback? - -2) uppsrc contains various proprocessor definitons for Turtle. - - They are obsolete now and better be removed. (VIRTUALGUI is sufficient) - -3) The VirtualGui-based Turtle package inherits the problems of the old Turtle package. - - One such major problem is that on windows platform, closing the remote app throws an - exception on the server side. This requires further investigation. - -4) KeyboardEvent.KeyCode and KeyboardEvent.which properties are deprecated and are going - to be emoved from the standard. - See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode - See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which - Recommended alternatives: KeyboardEvent.key and KeyboardEvent.code. - See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code - See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key diff --git a/uppsrc/Turtle/src.tpp/Upp_TurtleServer_en-us.tpp b/uppsrc/Turtle/src.tpp/Upp_TurtleServer_en-us.tpp deleted file mode 100644 index e170fa67e..000000000 --- a/uppsrc/Turtle/src.tpp/Upp_TurtleServer_en-us.tpp +++ /dev/null @@ -1,88 +0,0 @@ -topic "TurtleServer"; -[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] -[l288;2 $$2,2#27521748481378242620020725143825:desc] -[0 $$3,0#96390100711032703541132217272105:end] -[H6;0 $$4,0#05600065144404261032431302351956:begin] -[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:item] -[l288;a4;*@5;1 $$6,6#70004532496200323422659154056402:requirement] -[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] -[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] -[b42;2 $$9,9#13035079074754324216151401829390:normal] -[2 $$0,0#00000000000000000000000000000000:Default] -[{_} -[ {{10000@(113.42.0) [s0;%% [*@7;4 TurtleServer]]}}&] -[s2; &] -[s1;:Upp`:`:TurtleServer`:`:class: [@(0.0.255)3 class][3 _][*3 TurtleServer][3 _:_][@(0.0.255)3 p -ublic][3 _][*@3;3 VirtualGui]&] -[s2;#%% This class implements a remote gui virtualization server -for U`+`+ applications. By utilizing the modern web technologies -such as HTML`-5 canvas and websockets, TurtleServer allows U`+`+ -gui applications to be accessed remotely via modern web browsers, -or, possibly, via specialized client software that understands -the Turtle wire protocol.&] -[s3;%% &] -[ {{10000F(128)G(128)@1 [s0;%% [* Public Method List]]}}&] -[s3; &] -[s5;:Upp`:`:TurtleServer`:`:Bind`(const Upp`:`:String`&`): [_^Upp`:`:TurtleServer^ Turt -leServer][@(0.0.255) `&]_[* Bind]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `& -]_[*@3 addr])&] -[s2;%% Sets the server bind address to [%-*@3 addr]. Default is `"0.0.0.0`". -Returns `*this for method chaining.&] -[s3;%% &] -[s4; &] -[s5;:Upp`:`:TurtleServer`:`:Host`(const Upp`:`:String`&`): [_^Upp`:`:TurtleServer^ Turt -leServer][@(0.0.255) `&]_[* Host]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `& -]_[*@3 host])&] -[s2;%% Sets the host URL to [%-*@3 host]. Default URL is `"localhost`". -Returns `*this for method chaining.&] -[s3;%% &] -[s4; &] -[s5;:Upp`:`:TurtleServer`:`:Port`(int`): [_^Upp`:`:TurtleServer^ TurtleServer][@(0.0.255) `& -]_[* Port]([@(0.0.255) int]_[*@3 port])&] -[s2;%% Sets the connection port number. Default port number is 8888. -Returns `*this for method chaining.&] -[s3;%% &] -[s4; &] -[s5;:Upp`:`:TurtleServer`:`:MaxConnections`(int`): [_^Upp`:`:TurtleServer^ TurtleServer -][@(0.0.255) `&]_[* MaxConnections]([@(0.0.255) int]_[*@3 limit])&] -[s2;%% Sets a limit to the maximum number of concurrent client conntections. -Default max. connection limit is 100. Returns `*this for method -chaining.&] -[s3;%% &] -[s4; &] -[s5;:Upp`:`:TurtleServer`:`:DebugMode`(bool`): [@(0.0.255) static] -[@(0.0.255) void]_[* DebugMode]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&] -[s6;%% POSIX only&] -[s2;%% If true, the server will not spawn child processes (no forking). -Useful for debugging purposes.&] -[s3;%% &] -[ {{10000F(128)G(128)@1 [s0;%% [* Constructor detail]]}}&] -[s3; &] -[s5;:Upp`:`:TurtleServer`:`:TurtleServer`(`): [* TurtleServer]()&] -[s2;%% Default constructor. Initializes the server bind address to -`"0.0.0.0`", the host URL to `"localhost`", and the connection -port number to 8888.&] -[s3; &] -[s4; &] -[s5;:Upp`:`:TurtleServer`:`:TurtleServer`(const Upp`:`:String`&`,int`): [* TurtleServer -]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `&]_[*@3 host], -[@(0.0.255) int]_[*@3 port])&] -[s2;%% Constructor overload. Initializes the host URL and the connection -port number to provided values.&] -[s3;%% &] -[s4; &] -[s5;:Upp`:`:TurtleServer`:`:TurtleServer`(const Upp`:`:String`&`,Upp`:`:String`&`,int`): [* T -urtleServer]([@(0.0.255) const]_[_^Upp`:`:String^ String][@(0.0.255) `&]_[*@3 ip], -[_^Upp`:`:String^ String][@(0.0.255) `&]_[*@3 host], [@(0.0.255) int]_[*@3 port])&] -[s2;%% Constructor overload. Initializes the server bind adrress, -the host URL and the connection port number to provided values.&] -[s3;%% &] -[ {{10000F(128)G(128)@1 [s0;%% [* Function List]]}}&] -[s3;%% &] -[s5;:Upp`:`:RunTurtleGui`(Upp`:`:TurtleServer`&`,Upp`:`:Event`<`>`): [@(0.0.255) void]_ -[* RunTurtleGui]([_^Upp`:`:TurtleServer^ TurtleServer][@(0.0.255) `&]_[*@3 gui], -[_^Upp`:`:Event^ Event]<>_[*@3 app`_main])&] -[s2;%% Starts the Turtle GUI virtualization server and runs a U`+`+ -GUI application over it.&] -[s3;%% &] -[s0;%% ]] \ No newline at end of file diff --git a/uppsrc/ide/Credentials.cpp b/uppsrc/ide/Credentials.cpp index 32229a19f..e7d1b6b4a 100644 --- a/uppsrc/ide/Credentials.cpp +++ b/uppsrc/ide/Credentials.cpp @@ -94,7 +94,7 @@ struct GetPasskeyDlg : WithGetPasskeyLayout { GetPasskeyDlg::GetPasskeyDlg() { - CtrlLayoutOKCancel(*this, "Passkey"); + CtrlLayoutOK(*this, "Passkey"); show_passkey << [=] { Sync(); }; diff --git a/uppsrc/plugin/FT_fontsys/FT_fontsys.upp b/uppsrc/plugin/FT_fontsys/FT_fontsys.upp index d65f28086..6d6061fbb 100644 --- a/uppsrc/plugin/FT_fontsys/FT_fontsys.upp +++ b/uppsrc/plugin/FT_fontsys/FT_fontsys.upp @@ -1,5 +1,7 @@ description "FreeType based Draw FONTSYS replacement\3770,128,0"; +options(BUILDER_OPTION) NOWARNINGS; + uses Draw;