1
0

Implement TOUCH

This commit is contained in:
otya128
2016-12-07 00:14:23 +09:00
parent 443319d4e6
commit 02d2bf99fc
2 changed files with 39 additions and 3 deletions

View File

@@ -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)
{

View File

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