diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 34fe5d5..b51addf 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -305,9 +305,10 @@ class BuiltinFunction { writeln("NOTIMPL:TOUCH MPID"); } - tm = 0; - tchx = 0; - tchy = 0; + auto pos = p.touchPosition; + tm = pos.tm; + tchx = pos.x; + tchy = pos.y; } static void XSCREEN(PetitComputer p, int mode, DefaultValue!(int, false) a, DefaultValue!(int, false) b) { diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index fef2093..e8e1281 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -465,6 +465,28 @@ class PetitComputer protected BG[4] bg; bool quit; Condition renderCondition; + struct Touch + { + int tm; + int x; + int y; + }; + Object touchSync = new Object(); + Touch m_touch; + Touch touchPosition() + { + synchronized(touchSync) + { + return m_touch; + } + } + void touchPosition(Touch to) + { + synchronized(touchSync) + { + m_touch = to; + } + } void render() { try @@ -680,6 +702,19 @@ class PetitComputer SDL_GL_SwapWindow(window); auto renderticks = (SDL_GetTicks() - profile); if(renderprofile) writeln(renderticks); + int mousex, mousey; + if (SDL_GetMouseState(&mousex, &mousey) & SDL_BUTTON_LMASK) + { + auto old = touchPosition; + touchPosition = Touch(old.tm + 1, mousex, mousey); + } + else + { + if (touchPosition.tm) + { + touchPosition = Touch(0, mousex, mousey); + } + } while (SDL_PollEvent(&event)) { switch (event.type)