Implement dialog SelectionType
This commit is contained in:
@@ -3058,6 +3058,27 @@ class BuiltinFunction
|
|||||||
auto dialog = new Dialog(p);
|
auto dialog = new Dialog(p);
|
||||||
p.project.result = cast(DialogResult)dialog.show(text);
|
p.project.result = cast(DialogResult)dialog.show(text);
|
||||||
}
|
}
|
||||||
|
static void DIALOG(PetitComputer p, wstring text, DefaultValue!int selType)
|
||||||
|
{
|
||||||
|
selType.setDefaultValue(0);
|
||||||
|
auto dialog = new Dialog(p);
|
||||||
|
p.project.result = cast(DialogResult)dialog.show(text, cast(SelectionType)selType);
|
||||||
|
}
|
||||||
|
static void DIALOG(PetitComputer p, wstring text, DefaultValue!int selType, DefaultValue!wstring cap)
|
||||||
|
{
|
||||||
|
selType.setDefaultValue(0);
|
||||||
|
cap.setDefaultValue("■DIALOG");
|
||||||
|
auto dialog = new Dialog(p);
|
||||||
|
p.project.result = cast(DialogResult)dialog.show(text, cast(SelectionType)selType, cast(wstring)cap);
|
||||||
|
}
|
||||||
|
static void DIALOG(PetitComputer p, wstring text, DefaultValue!int selType, DefaultValue!wstring cap, DefaultValue!int timeout)
|
||||||
|
{
|
||||||
|
selType.setDefaultValue(0);
|
||||||
|
cap.setDefaultValue("■DIALOG");
|
||||||
|
timeout.setDefaultValue(0);
|
||||||
|
auto dialog = new Dialog(p);
|
||||||
|
p.project.result = cast(DialogResult)dialog.show(text, cast(SelectionType)selType, cast(wstring)cap, cast(int)timeout);
|
||||||
|
}
|
||||||
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
||||||
static BuiltinFunctions[wstring] builtinFunctions;
|
static BuiltinFunctions[wstring] builtinFunctions;
|
||||||
static wstring getBasicName(BFD)(const wstring def)
|
static wstring getBasicName(BFD)(const wstring def)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module otya.smilebasic.dialog;
|
module otya.smilebasic.dialog;
|
||||||
import otya.smilebasic.petitcomputer;
|
import otya.smilebasic.petitcomputer;
|
||||||
import otya.smilebasic.project;
|
import otya.smilebasic.project;
|
||||||
|
import otya.smilebasic.error;
|
||||||
import derelict.sdl2.sdl;
|
import derelict.sdl2.sdl;
|
||||||
import derelict.sdl2.image;
|
import derelict.sdl2.image;
|
||||||
import derelict.sdl2.ttf;
|
import derelict.sdl2.ttf;
|
||||||
@@ -70,6 +71,7 @@ class DialogResources
|
|||||||
public GraphicPage button1;
|
public GraphicPage button1;
|
||||||
public GraphicPage button2;
|
public GraphicPage button2;
|
||||||
public TTF_Font* font;
|
public TTF_Font* font;
|
||||||
|
wstring[][] buttonCaptions;
|
||||||
public this(SDL_Renderer* renderer, GLenum textureScaleMode)
|
public this(SDL_Renderer* renderer, GLenum textureScaleMode)
|
||||||
{
|
{
|
||||||
button1 = new GraphicPage("dialogresource/yes.png");
|
button1 = new GraphicPage("dialogresource/yes.png");
|
||||||
@@ -77,6 +79,7 @@ class DialogResources
|
|||||||
button2 = new GraphicPage("dialogresource/no.png");
|
button2 = new GraphicPage("dialogresource/no.png");
|
||||||
button2.createTexture(renderer, textureScaleMode);
|
button2.createTexture(renderer, textureScaleMode);
|
||||||
font = TTF_OpenFont("dialogresource/mplus-1c-regular.ttf", 14);
|
font = TTF_OpenFont("dialogresource/mplus-1c-regular.ttf", 14);
|
||||||
|
buttonCaptions = [["了解"], ["はい", "いいえ"], ["次へ", "戻る"], ["中止", "決定"], ["中止", "実行"]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,11 +100,14 @@ struct Text
|
|||||||
texture.createTexture(petitcom.renderer, petitcom.textureScaleMode);
|
texture.createTexture(petitcom.renderer, petitcom.textureScaleMode);
|
||||||
}
|
}
|
||||||
~this()
|
~this()
|
||||||
|
{
|
||||||
|
if (texture)
|
||||||
{
|
{
|
||||||
texture.deleteGL();
|
texture.deleteGL();
|
||||||
texture.deleteSDL();
|
texture.deleteSDL();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Dialog : DialogBase
|
class Dialog : DialogBase
|
||||||
{
|
{
|
||||||
@@ -202,7 +208,7 @@ class Dialog : DialogBase
|
|||||||
|
|
||||||
GraphicPage message;
|
GraphicPage message;
|
||||||
|
|
||||||
int show(wstring text)
|
int show(wstring text, SelectionType selType = SelectionType.ok, wstring caption = "■DIALOG", int timeout = 0)
|
||||||
{
|
{
|
||||||
area = petitcom.showTouchScreen();
|
area = petitcom.showTouchScreen();
|
||||||
wchar[257] buffer;
|
wchar[257] buffer;
|
||||||
@@ -221,11 +227,11 @@ class Dialog : DialogBase
|
|||||||
int buttonMarginWidth = 12;
|
int buttonMarginWidth = 12;
|
||||||
int buttonMarginHeight = 12;
|
int buttonMarginHeight = 12;
|
||||||
|
|
||||||
auto button1text = Text(petitcom, "はい", SDL_Color(0, 0, 0, 255));
|
int buttonCount;
|
||||||
ubyte sr, sg, sb, sa;
|
auto cs = petitcom.dialogResource.buttonCaptions[cast(size_t)selType];
|
||||||
SDL_GetRGBA((cast(uint*)petitcom.dialogResource.button2.surface.pixels)[0], petitcom.dialogResource.button2.surface.format, &sr, &sg, &sb, &sa);
|
|
||||||
auto button2text = Text(petitcom, "いいえ", SDL_Color(sr, sg, sb, 255));
|
auto button1text = Text(petitcom, cs[0], SDL_Color(0, 0, 0, 255));
|
||||||
buttons = [
|
auto button1 =
|
||||||
new DialogButton(
|
new DialogButton(
|
||||||
petitcom.dialogResource.button1,
|
petitcom.dialogResource.button1,
|
||||||
button1text.texture,
|
button1text.texture,
|
||||||
@@ -234,7 +240,15 @@ class Dialog : DialogBase
|
|||||||
DialogResult.SUCCESS,
|
DialogResult.SUCCESS,
|
||||||
22,
|
22,
|
||||||
1
|
1
|
||||||
),
|
);
|
||||||
|
Text button2text;
|
||||||
|
DialogButton button2;
|
||||||
|
if (cs.length > 1)
|
||||||
|
{
|
||||||
|
ubyte sr, sg, sb, sa;
|
||||||
|
SDL_GetRGBA((cast(uint*)petitcom.dialogResource.button2.surface.pixels)[0], petitcom.dialogResource.button2.surface.format, &sr, &sg, &sb, &sa);
|
||||||
|
button2text = Text(petitcom, cs[1], SDL_Color(sr, sg, sb, 255));
|
||||||
|
button2 =
|
||||||
new DialogButton(
|
new DialogButton(
|
||||||
petitcom.dialogResource.button2,
|
petitcom.dialogResource.button2,
|
||||||
button2text.texture,
|
button2text.texture,
|
||||||
@@ -243,8 +257,13 @@ class Dialog : DialogBase
|
|||||||
DialogResult.CANCEL,
|
DialogResult.CANCEL,
|
||||||
22,
|
22,
|
||||||
1
|
1
|
||||||
)
|
);
|
||||||
];
|
buttons = [button1, button2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buttons = [button1];
|
||||||
|
}
|
||||||
petitcom.dialog = this;
|
petitcom.dialog = this;
|
||||||
bool isPressed;
|
bool isPressed;
|
||||||
while (!isPressed)
|
while (!isPressed)
|
||||||
|
|||||||
Reference in New Issue
Block a user