Implement DIALOG (4)
This commit is contained in:
@@ -13,6 +13,13 @@ class DialogBase
|
|||||||
abstract void render();
|
abstract void render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ButtonType
|
||||||
|
{
|
||||||
|
abxyButton = 1,
|
||||||
|
dpad = 2,
|
||||||
|
lrButton = 4,
|
||||||
|
touchPanel = 8,
|
||||||
|
}
|
||||||
enum SelectionType
|
enum SelectionType
|
||||||
{
|
{
|
||||||
ok,
|
ok,
|
||||||
@@ -210,6 +217,10 @@ class Dialog : DialogBase
|
|||||||
|
|
||||||
int show(wstring text, SelectionType selType = SelectionType.ok, wstring caption = "■DIALOG", int timeout = 0)
|
int show(wstring text, SelectionType selType = SelectionType.ok, wstring caption = "■DIALOG", int timeout = 0)
|
||||||
{
|
{
|
||||||
|
if (selType >= cast(ptrdiff_t)petitcom.dialogResource.buttonCaptions.length || -selType >= 15)
|
||||||
|
{
|
||||||
|
throw new OutOfRange("DIALOG", 2);
|
||||||
|
}
|
||||||
area = petitcom.showTouchScreen();
|
area = petitcom.showTouchScreen();
|
||||||
scope (exit)
|
scope (exit)
|
||||||
petitcom.hideTouchScreen();
|
petitcom.hideTouchScreen();
|
||||||
@@ -229,11 +240,16 @@ class Dialog : DialogBase
|
|||||||
int buttonMarginWidth = 12;
|
int buttonMarginWidth = 12;
|
||||||
int buttonMarginHeight = 12;
|
int buttonMarginHeight = 12;
|
||||||
|
|
||||||
int buttonCount;
|
Text button1text;
|
||||||
|
DialogButton button1;
|
||||||
|
Text button2text;
|
||||||
|
DialogButton button2;
|
||||||
|
if (selType >= 0)
|
||||||
|
{
|
||||||
auto cs = petitcom.dialogResource.buttonCaptions[cast(size_t)selType];
|
auto cs = petitcom.dialogResource.buttonCaptions[cast(size_t)selType];
|
||||||
|
|
||||||
auto button1text = Text(petitcom, cs[0], SDL_Color(0, 0, 0, 255));
|
button1text = Text(petitcom, cs[0], SDL_Color(0, 0, 0, 255));
|
||||||
auto button1 =
|
button1 =
|
||||||
new DialogButton(
|
new DialogButton(
|
||||||
petitcom.dialogResource.button1,
|
petitcom.dialogResource.button1,
|
||||||
button1text.texture,
|
button1text.texture,
|
||||||
@@ -243,8 +259,6 @@ class Dialog : DialogBase
|
|||||||
22,
|
22,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
Text button2text;
|
|
||||||
DialogButton button2;
|
|
||||||
if (cs.length > 1)
|
if (cs.length > 1)
|
||||||
{
|
{
|
||||||
ubyte sr, sg, sb, sa;
|
ubyte sr, sg, sb, sa;
|
||||||
@@ -266,6 +280,7 @@ class Dialog : DialogBase
|
|||||||
{
|
{
|
||||||
buttons = [button1];
|
buttons = [button1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
petitcom.dialog = this;
|
petitcom.dialog = this;
|
||||||
scope (exit)
|
scope (exit)
|
||||||
petitcom.dialog = null;
|
petitcom.dialog = null;
|
||||||
@@ -280,8 +295,12 @@ class Dialog : DialogBase
|
|||||||
timeoutframe = -timeout;
|
timeoutframe = -timeout;
|
||||||
}
|
}
|
||||||
auto startmaincnt = petitcom.maincnt;
|
auto startmaincnt = petitcom.maincnt;
|
||||||
|
auto oldbutton = petitcom.button;
|
||||||
while (!isPressed)
|
while (!isPressed)
|
||||||
{
|
{
|
||||||
|
auto pbutton = petitcom.button;
|
||||||
|
auto button = pbutton ^ oldbutton & pbutton;
|
||||||
|
oldbutton = pbutton;
|
||||||
petitcom.maincnt++;
|
petitcom.maincnt++;
|
||||||
if (petitcom.maincnt - startmaincnt == timeoutframe)
|
if (petitcom.maincnt - startmaincnt == timeoutframe)
|
||||||
{
|
{
|
||||||
@@ -290,6 +309,8 @@ class Dialog : DialogBase
|
|||||||
auto to = petitcom.touchPosition();
|
auto to = petitcom.touchPosition();
|
||||||
auto x = to.display1X;
|
auto x = to.display1X;
|
||||||
auto y = to.display1Y;
|
auto y = to.display1Y;
|
||||||
|
if (selType >= 0)
|
||||||
|
{
|
||||||
foreach (b; buttons)
|
foreach (b; buttons)
|
||||||
{
|
{
|
||||||
if (to.tm == 1 && b.colDetect(x, y))
|
if (to.tm == 1 && b.colDetect(x, y))
|
||||||
@@ -302,6 +323,78 @@ class Dialog : DialogBase
|
|||||||
isPressed = true;
|
isPressed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto buttonType = -selType;
|
||||||
|
if (buttonType & ButtonType.abxyButton)
|
||||||
|
{
|
||||||
|
if (button & Button.A)
|
||||||
|
{
|
||||||
|
result = ButtonResult.a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (button & Button.B)
|
||||||
|
{
|
||||||
|
result = ButtonResult.b;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (button & Button.X)
|
||||||
|
{
|
||||||
|
result = ButtonResult.x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (button & Button.Y)
|
||||||
|
{
|
||||||
|
result = ButtonResult.y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (buttonType & ButtonType.dpad)
|
||||||
|
{
|
||||||
|
if (button & Button.UP)
|
||||||
|
{
|
||||||
|
result = ButtonResult.up;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (button & Button.DOWN)
|
||||||
|
{
|
||||||
|
result = ButtonResult.down;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (button & Button.LEFT)
|
||||||
|
{
|
||||||
|
result = ButtonResult.left;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (button & Button.RIGHT)
|
||||||
|
{
|
||||||
|
result = ButtonResult.right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (buttonType & ButtonType.lrButton)
|
||||||
|
{
|
||||||
|
if (button & Button.L)
|
||||||
|
{
|
||||||
|
result = ButtonResult.l;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (button & Button.R)
|
||||||
|
{
|
||||||
|
result = ButtonResult.r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (buttonType & ButtonType.touchPanel)
|
||||||
|
{
|
||||||
|
if (to.tm == 1)
|
||||||
|
{
|
||||||
|
result = ButtonResult.touch;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
SDL_Delay(16);
|
SDL_Delay(16);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user