mirror of https://github.com/buggins/dlangui.git
set focus on window show; Tetris example - fix focus
This commit is contained in:
parent
9cca695c8d
commit
ba0b4df568
|
@ -66,7 +66,7 @@
|
||||||
<debuglevel>0</debuglevel>
|
<debuglevel>0</debuglevel>
|
||||||
<debugids />
|
<debugids />
|
||||||
<versionlevel>0</versionlevel>
|
<versionlevel>0</versionlevel>
|
||||||
<versionids />
|
<versionids>USE_SDL USE_OPENGL</versionids>
|
||||||
<dump_source>0</dump_source>
|
<dump_source>0</dump_source>
|
||||||
<mapverbosity>3</mapverbosity>
|
<mapverbosity>3</mapverbosity>
|
||||||
<createImplib>0</createImplib>
|
<createImplib>0</createImplib>
|
||||||
|
|
|
@ -45,86 +45,6 @@ Widget createAboutWidget()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AnimatedDrawable : Drawable {
|
|
||||||
DrawableRef background;
|
|
||||||
this() {
|
|
||||||
background = drawableCache.get("tx_fabric.tiled");
|
|
||||||
}
|
|
||||||
void drawAnimatedRect(DrawBuf buf, uint p, Rect rc, int speedx, int speedy, int sz) {
|
|
||||||
int x = (p * speedx % rc.width);
|
|
||||||
int y = (p * speedy % rc.height);
|
|
||||||
if (x < 0)
|
|
||||||
x += rc.width;
|
|
||||||
if (y < 0)
|
|
||||||
y += rc.height;
|
|
||||||
uint a = 64 + ((p / 2) & 0x7F);
|
|
||||||
uint r = 128 + ((p / 7) & 0x7F);
|
|
||||||
uint g = 128 + ((p / 5) & 0x7F);
|
|
||||||
uint b = 128 + ((p / 3) & 0x7F);
|
|
||||||
uint color = (a << 24) | (r << 16) | (g << 8) | b;
|
|
||||||
buf.fillRect(Rect(rc.left + x, rc.top + y, rc.left + x + sz, rc.top + y + sz), color);
|
|
||||||
}
|
|
||||||
void drawAnimatedIcon(DrawBuf buf, uint p, Rect rc, int speedx, int speedy, string resourceId) {
|
|
||||||
int x = (p * speedx % rc.width);
|
|
||||||
int y = (p * speedy % rc.height);
|
|
||||||
if (x < 0)
|
|
||||||
x += rc.width;
|
|
||||||
if (y < 0)
|
|
||||||
y += rc.height;
|
|
||||||
DrawBufRef image = drawableCache.getImage(resourceId);
|
|
||||||
buf.drawImage(x, y, image.get);
|
|
||||||
}
|
|
||||||
override void drawTo(DrawBuf buf, Rect rc, uint state = 0, int tilex0 = 0, int tiley0 = 0) {
|
|
||||||
background.drawTo(buf, rc, state, cast(int)(animationProgress / 695430), cast(int)(animationProgress / 1500000));
|
|
||||||
drawAnimatedRect(buf, cast(uint)(animationProgress / 295430), rc, 2, 3, 100);
|
|
||||||
drawAnimatedRect(buf, cast(uint)(animationProgress / 312400) + 100, rc, 3, 2, 130);
|
|
||||||
drawAnimatedIcon(buf, cast(uint)(animationProgress / 212400) + 200, rc, -2, 1, "dlangui-logo1");
|
|
||||||
drawAnimatedRect(buf, cast(uint)(animationProgress / 512400) + 300, rc, 2, -2, 200);
|
|
||||||
drawAnimatedRect(buf, cast(uint)(animationProgress / 214230) + 800, rc, 1, 2, 390);
|
|
||||||
drawAnimatedIcon(buf, cast(uint)(animationProgress / 123320) + 900, rc, 1, 2, "cr3_logo");
|
|
||||||
drawAnimatedRect(buf, cast(uint)(animationProgress / 100000) + 100, rc, -1, -1, 120);
|
|
||||||
}
|
|
||||||
@property override int width() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
@property override int height() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ulong animationProgress;
|
|
||||||
void animate(long interval) {
|
|
||||||
animationProgress += interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class SampleAnimationWidget : VerticalLayout {
|
|
||||||
AnimatedDrawable drawable;
|
|
||||||
DrawableRef drawableRef;
|
|
||||||
this(string ID) {
|
|
||||||
super(ID);
|
|
||||||
drawable = new AnimatedDrawable();
|
|
||||||
drawableRef = drawable;
|
|
||||||
padding = Rect(20, 20, 20, 20);
|
|
||||||
addChild(new TextWidget(null, "This is TextWidget on top of animated background"d));
|
|
||||||
addChild(new EditLine(null, "This is EditLine on top of animated background"d));
|
|
||||||
addChild(new Button(null, "This is Button on top of animated background"d));
|
|
||||||
addChild(new VSpacer());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// background drawable
|
|
||||||
@property override DrawableRef backgroundDrawable() const {
|
|
||||||
return (cast(SampleAnimationWidget)this).drawableRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// returns true is widget is being animated - need to call animate() and redraw
|
|
||||||
@property override bool animating() { return true; }
|
|
||||||
/// animates window; interval is time left from previous draw, in hnsecs (1/10000000 of second)
|
|
||||||
override void animate(long interval) {
|
|
||||||
drawable.animate(interval);
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Cell offset
|
/// Cell offset
|
||||||
struct FigureCell {
|
struct FigureCell {
|
||||||
// horizontal offset
|
// horizontal offset
|
||||||
|
@ -221,8 +141,9 @@ enum TetrisAction : int {
|
||||||
}
|
}
|
||||||
|
|
||||||
class CupWidget : Widget {
|
class CupWidget : Widget {
|
||||||
|
/// cup columns count
|
||||||
int _cols;
|
int _cols;
|
||||||
|
/// cup rows count
|
||||||
int _rows;
|
int _rows;
|
||||||
int[] _cup;
|
int[] _cup;
|
||||||
/// current figure id
|
/// current figure id
|
||||||
|
@ -268,7 +189,7 @@ class CupWidget : Widget {
|
||||||
_movementDuration = LEVEL_SPEED[level - 1];
|
_movementDuration = LEVEL_SPEED[level - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
void setState(CupState state, int animationIntervalPercent = 100, int maxProgress = 10000) {
|
void setCupState(CupState state, int animationIntervalPercent = 100, int maxProgress = 10000) {
|
||||||
_state = state;
|
_state = state;
|
||||||
if (animationIntervalPercent)
|
if (animationIntervalPercent)
|
||||||
_animation.start(_movementDuration * animationIntervalPercent / 100, maxProgress);
|
_animation.start(_movementDuration * animationIntervalPercent / 100, maxProgress);
|
||||||
|
@ -318,21 +239,21 @@ class CupWidget : Widget {
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case CupState.NewFigure:
|
case CupState.NewFigure:
|
||||||
genNextFigure();
|
genNextFigure();
|
||||||
setState(CupState.HangingFigure, 75);
|
setCupState(CupState.HangingFigure, 75);
|
||||||
break;
|
break;
|
||||||
case CupState.FallingFigure:
|
case CupState.FallingFigure:
|
||||||
if (isPositionFreeBelow()) {
|
if (isPositionFreeBelow()) {
|
||||||
_currentFigureY--;
|
_currentFigureY--;
|
||||||
setState(CupState.HangingFigure, 75);
|
setCupState(CupState.HangingFigure, 75);
|
||||||
} else {
|
} else {
|
||||||
putFigure(_currentFigure, _currentFigureOrientation, _currentFigureX, _currentFigureY);
|
putFigure(_currentFigure, _currentFigureOrientation, _currentFigureX, _currentFigureY);
|
||||||
if (!dropNextFigure()) {
|
if (!dropNextFigure()) {
|
||||||
setState(CupState.GameOver);
|
setCupState(CupState.GameOver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CupState.HangingFigure:
|
case CupState.HangingFigure:
|
||||||
setState(CupState.FallingFigure, 25);
|
setCupState(CupState.FallingFigure, 25);
|
||||||
break;
|
break;
|
||||||
case CupState.DestroyingRows:
|
case CupState.DestroyingRows:
|
||||||
break;
|
break;
|
||||||
|
@ -381,16 +302,17 @@ class CupWidget : Widget {
|
||||||
_currentFigureOrientation = ORIENTATION0;
|
_currentFigureOrientation = ORIENTATION0;
|
||||||
_currentFigureX = _cols / 2 - 1;
|
_currentFigureX = _cols / 2 - 1;
|
||||||
_currentFigureY = _rows - 1 - FIGURES[_currentFigure].shapes[_currentFigureOrientation].y0;
|
_currentFigureY = _rows - 1 - FIGURES[_currentFigure].shapes[_currentFigureOrientation].y0;
|
||||||
setState(CupState.NewFigure, 100, 255);
|
setCupState(CupState.NewFigure, 100, 255);
|
||||||
return isPositionFree();
|
return isPositionFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
this() {
|
this() {
|
||||||
super("CUP");
|
super("CUP");
|
||||||
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).layoutWeight(3);
|
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).layoutWeight(3);
|
||||||
|
setState(State.Default);
|
||||||
backgroundColor = 0xC0808080;
|
backgroundColor = 0xC0808080;
|
||||||
padding(Rect(20, 20, 20, 20));
|
padding(Rect(20, 20, 20, 20));
|
||||||
init(10, 15);
|
init(11, 15);
|
||||||
|
|
||||||
setLevel(1);
|
setLevel(1);
|
||||||
dropNextFigure();
|
dropNextFigure();
|
||||||
|
@ -591,7 +513,6 @@ class CupPage : HorizontalLayout {
|
||||||
this() {
|
this() {
|
||||||
super("CUP_PAGE");
|
super("CUP_PAGE");
|
||||||
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
setState(State.Default);
|
|
||||||
_cup = new CupWidget();
|
_cup = new CupWidget();
|
||||||
_status = new StatusWidget();
|
_status = new StatusWidget();
|
||||||
addChild(_cup);
|
addChild(_cup);
|
||||||
|
@ -615,7 +536,6 @@ class GameWidget : HorizontalLayout {
|
||||||
addChild(_cupPage);
|
addChild(_cupPage);
|
||||||
//showChild(_cupPage.id, Visibility.Invisible, true);
|
//showChild(_cupPage.id, Visibility.Invisible, true);
|
||||||
backgroundImageId = "tx_fabric.tiled";
|
backgroundImageId = "tx_fabric.tiled";
|
||||||
_cupPage.setFocus();
|
|
||||||
}
|
}
|
||||||
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
|
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
|
||||||
override void measure(int parentWidth, int parentHeight) {
|
override void measure(int parentWidth, int parentHeight) {
|
||||||
|
@ -633,6 +553,9 @@ enum : int {
|
||||||
|
|
||||||
/// entry point for dlangui based application
|
/// entry point for dlangui based application
|
||||||
extern (C) int UIAppMain(string[] args) {
|
extern (C) int UIAppMain(string[] args) {
|
||||||
|
|
||||||
|
auto power2 = delegate(int X) { return X * X; };
|
||||||
|
|
||||||
// resource directory search paths
|
// resource directory search paths
|
||||||
string[] resourceDirs = [
|
string[] resourceDirs = [
|
||||||
appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
||||||
|
|
|
@ -157,6 +157,8 @@ class SDLWindow : Window {
|
||||||
SDL_SetWindowSize(_win, _mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
SDL_SetWindowSize(_win, _mainWidget.measuredWidth, _mainWidget.measuredHeight);
|
||||||
}
|
}
|
||||||
SDL_ShowWindow(_win);
|
SDL_ShowWindow(_win);
|
||||||
|
if (_mainWidget)
|
||||||
|
_mainWidget.setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// close window
|
/// close window
|
||||||
|
|
|
@ -323,6 +323,8 @@ class Win32Window : Window {
|
||||||
} else {
|
} else {
|
||||||
ShowWindow(_hwnd, SW_SHOWNORMAL);
|
ShowWindow(_hwnd, SW_SHOWNORMAL);
|
||||||
}
|
}
|
||||||
|
if (_mainWidget)
|
||||||
|
_mainWidget.setFocus();
|
||||||
SetFocus(_hwnd);
|
SetFocus(_hwnd);
|
||||||
//UpdateWindow(_hwnd);
|
//UpdateWindow(_hwnd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue