mirror of https://github.com/buggins/dlangui.git
tweal Tetris example for High DPI
This commit is contained in:
parent
c32df24ad9
commit
94d1761b84
|
@ -493,12 +493,14 @@ class StatusWidget : VerticalLayout {
|
||||||
private TextWidget _rowsDestroyed;
|
private TextWidget _rowsDestroyed;
|
||||||
private TextWidget _score;
|
private TextWidget _score;
|
||||||
private CupWidget _cup;
|
private CupWidget _cup;
|
||||||
|
private TextWidget[] _labels;
|
||||||
void setCup(CupWidget cup) {
|
void setCup(CupWidget cup) {
|
||||||
_cup = cup;
|
_cup = cup;
|
||||||
}
|
}
|
||||||
TextWidget createTextWidget(dstring str, uint color) {
|
TextWidget createTextWidget(dstring str, uint color) {
|
||||||
TextWidget res = new TextWidget(null, str);
|
TextWidget res = new TextWidget(null, str);
|
||||||
res.layoutWidth(FILL_PARENT).alignment(Align.Center).fontSize(25).textColor(color);
|
res.layoutWidth(FILL_PARENT).alignment(Align.Center).fontSize(18.pointsToPixels).textColor(color);
|
||||||
|
_labels ~= res;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,10 +509,12 @@ class StatusWidget : VerticalLayout {
|
||||||
res.colCount = 3;
|
res.colCount = 3;
|
||||||
foreach(const Action a; CUP_ACTIONS) {
|
foreach(const Action a; CUP_ACTIONS) {
|
||||||
ImageButton btn = new ImageButton(a);
|
ImageButton btn = new ImageButton(a);
|
||||||
|
btn.padding = 5.pointsToPixels;
|
||||||
btn.focusable = false;
|
btn.focusable = false;
|
||||||
res.addChild(btn);
|
res.addChild(btn);
|
||||||
}
|
}
|
||||||
res.layoutWidth(WRAP_CONTENT).layoutHeight(WRAP_CONTENT).margins(Rect(10, 10, 10, 10)).alignment(Align.Center);
|
res.alignment = Align.Center;
|
||||||
|
res.layoutWidth(WRAP_CONTENT).layoutHeight(WRAP_CONTENT).margins(Rect(10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels)).alignment(Align.Center);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,10 +545,25 @@ class StatusWidget : VerticalLayout {
|
||||||
addChild(createTextWidget("Score:"d, 0x800000));
|
addChild(createTextWidget("Score:"d, 0x800000));
|
||||||
addChild((_score = createTextWidget(""d, 0x800000)));
|
addChild((_score = createTextWidget(""d, 0x800000)));
|
||||||
addChild(new VSpacer());
|
addChild(new VSpacer());
|
||||||
addChild(createControls());
|
HorizontalLayout h = new HorizontalLayout();
|
||||||
|
h.layoutWidth = FILL_PARENT;
|
||||||
|
h.layoutHeight = FILL_PARENT;
|
||||||
|
h.addChild(new HSpacer());
|
||||||
|
h.addChild(createControls());
|
||||||
|
h.addChild(new HSpacer());
|
||||||
|
addChild(h);
|
||||||
addChild(new VSpacer());
|
addChild(new VSpacer());
|
||||||
|
|
||||||
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).layoutWeight(2).padding(Rect(10, 10, 10, 10));
|
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).layoutWeight(2).padding(Rect(5.pointsToPixels, 5.pointsToPixels, 5.pointsToPixels, 5.pointsToPixels));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
|
||||||
|
override void measure(int parentWidth, int parentHeight) {
|
||||||
|
int minw = min(parentWidth, parentHeight);
|
||||||
|
foreach(lbl; _labels) {
|
||||||
|
lbl.fontSize = minw / 20;
|
||||||
|
}
|
||||||
|
super.measure(parentWidth, parentHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLevel(int level) {
|
void setLevel(int level) {
|
||||||
|
@ -574,6 +593,8 @@ class CupPage : HorizontalLayout {
|
||||||
_status = new StatusWidget();
|
_status = new StatusWidget();
|
||||||
_cup = new CupWidget(_status);
|
_cup = new CupWidget(_status);
|
||||||
_status.setCup(_cup);
|
_status.setCup(_cup);
|
||||||
|
_cup.layoutWidth = 50.makePercentSize;
|
||||||
|
_status.layoutWidth = 50.makePercentSize;
|
||||||
addChild(_cup);
|
addChild(_cup);
|
||||||
addChild(_status);
|
addChild(_status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
// load theme from file "theme_default.xml"
|
// load theme from file "theme_default.xml"
|
||||||
Platform.instance.uiTheme = "theme_default";
|
Platform.instance.uiTheme = "theme_default";
|
||||||
|
|
||||||
|
//SCREEN_DPI = 150;
|
||||||
|
|
||||||
// create window
|
// create window
|
||||||
Window window = Platform.instance.createWindow("DLangUI: Tetris game example"d, null, WindowFlag.Modal, 600, 400);
|
Window window = Platform.instance.createWindow("DLangUI: Tetris game example"d, null, WindowFlag.Modal, 600, 400);
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 810 B |
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
|
@ -8,3 +8,9 @@ res/popup_background.9.png
|
||||||
res/rotate.png
|
res/rotate.png
|
||||||
res/tetris_logo_big.png
|
res/tetris_logo_big.png
|
||||||
res/tx_fabric.jpg
|
res/tx_fabric.jpg
|
||||||
|
res/hdpi_arrow-down.png
|
||||||
|
res/hdpi_arrow-left.png
|
||||||
|
res/hdpi_arrow-right.png
|
||||||
|
res/hdpi_levelup.png
|
||||||
|
res/hdpi_pause.png
|
||||||
|
res/hdpi_rotate.png
|
||||||
|
|
Loading…
Reference in New Issue