1
0

Implement dialog result

This commit is contained in:
otya128
2016-12-25 23:14:29 +09:00
parent d5fb80708e
commit 106d64a8ef
2 changed files with 42 additions and 8 deletions

View File

@@ -51,6 +51,10 @@ class DialogButton
this.height = background.surface.h; this.height = background.surface.h;
this.result = result; this.result = result;
} }
bool colDetect(int x, int y)
{
return x >= this.x && y >= this.y && this.x + this.width > x && this.y + this.height > y;
}
} }
class DialogResources class DialogResources
@@ -107,19 +111,25 @@ class Dialog : DialogBase
} }
void renderButton(DialogButton button) void renderButton(DialogButton button)
{ {
int mx, my;
if (button.isPressed)
{
mx += 2;
my += 2;
}
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glColor3ub(255, 255, 255); glColor3ub(255, 255, 255);
glBindTexture(GL_TEXTURE_2D, button.background.glTexture); glBindTexture(GL_TEXTURE_2D, button.background.glTexture);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2i(0, 0); glTexCoord2i(0, 0);
glVertex2i(button.x, button.y); glVertex2i(button.x + mx, button.y + my);
glTexCoord2i(1, 0); glTexCoord2i(1, 0);
glVertex2i(button.x + button.width, button.y); glVertex2i(button.x + button.width + mx, button.y + my);
glTexCoord2i(1, 1); glTexCoord2i(1, 1);
glVertex2i(button.x + button.width, button.y + button.height); glVertex2i(button.x + button.width + mx, button.y + button.height + my);
glTexCoord2i(0, 1); glTexCoord2i(0, 1);
glVertex2i(button.x, button.y + button.height); glVertex2i(button.x + mx, button.y + button.height + my);
glEnd(); glEnd();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
@@ -134,6 +144,7 @@ class Dialog : DialogBase
} }
} }
int show(wstring text) int show(wstring text)
{ {
petitcom.dialog = this; petitcom.dialog = this;
@@ -154,9 +165,24 @@ class Dialog : DialogBase
DialogResult.CANCEL DialogResult.CANCEL
) )
]; ];
while (true) bool isPressed;
while (!isPressed)
{ {
auto to = petitcom.touchPosition(); auto to = petitcom.touchPosition();
auto x = to.display1X;
auto y = to.display1Y;
foreach (b; buttons)
{
if (to.tm == 1 && b.colDetect(x, y))
{
b.isPressed = true;
}
else if (b.isPressed && to.tm < 1)
{
result = b.result;
isPressed = true;
}
}
SDL_Delay(16); SDL_Delay(16);
} }
petitcom.hideTouchScreen(); petitcom.hideTouchScreen();

View File

@@ -638,7 +638,7 @@ class PetitComputer
} }
mousex = mousex.clamp(5, 314); mousex = mousex.clamp(5, 314);
mousey = mousey.clamp(5, 234); mousey = mousey.clamp(5, 234);
touchPosition = Touch(old.tm + 1, mousex, mousey); touchPosition = Touch(old.tm + 1, mousex, mousey, 0, 0, mousex, mousey);
} }
else else
{ {
@@ -1637,8 +1637,16 @@ class PetitComputer
{ {
return currentDisplay.rect[1]; return currentDisplay.rect[1];
} }
auto rect = currentDisplay.rect[0]; SDL_Rect rect;
rect.y += rect.h; if (xscreenmode == 0)
{
rect = SDL_Rect((screenWidth - screenWidthDisplay1) / 2, screenHeight, screenWidthDisplay1, screenHeightDisplay1);
}
else
{
rect = currentDisplay.rect[0];
rect.y += rect.h;
}
currentDisplay.windowSize.height += rect.h; currentDisplay.windowSize.height += rect.h;
currentDisplay.yoffset = currentDisplay.windowSize.height; currentDisplay.yoffset = currentDisplay.windowSize.height;
updateWindowSize(); updateWindowSize();