window update issue fixed

This commit is contained in:
Vadim Lopatin 2014-03-07 15:55:28 +04:00
parent c6c89303d8
commit a85dde2d6f
8 changed files with 56 additions and 53 deletions

View File

@ -275,6 +275,7 @@
<File path="src\dlangui\widgets\styles.d" /> <File path="src\dlangui\widgets\styles.d" />
<File path="src\dlangui\widgets\widget.d" /> <File path="src\dlangui\widgets\widget.d" />
</Folder> </Folder>
<File path="src\dlangui\all.d" />
</Folder> </Folder>
</Folder> </Folder>
</Folder> </Folder>

View File

@ -1,20 +1,12 @@
module winmain; module winmain;
import dlangui.platforms.common.platform; import dlangui.all;
import dlangui.graphics.images;
import dlangui.widgets.widget;
import dlangui.widgets.controls;
import dlangui.core.logger;
import dlangui.graphics.fonts;
import std.stdio; import std.stdio;
ImageCache imageCache; /// workaround for link issue when WinMain is located in library
string resourceDir;
version(Windows) { version(Windows) {
import win32.windows; import win32.windows;
import dlangui.platforms.windows.winapp; import dlangui.platforms.windows.winapp;
/// workaround for link issue when WinMain is located in library
extern (Windows) extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) LPSTR lpCmdLine, int nCmdShow)
@ -24,38 +16,23 @@ version(Windows) {
} }
} }
/// entry point for dlangui based application
extern (C) int UIAppMain(string[] args) { extern (C) int UIAppMain(string[] args) {
// setup resource dir
imageCache = new ImageCache(); string resourceDir = exePath() ~ "..\\res\\";
resourceDir = exePath() ~ "..\\res\\";
string[] imageDirs = [ string[] imageDirs = [
resourceDir resourceDir
]; ];
drawableCache.resourcePaths = imageDirs; drawableCache.resourcePaths = imageDirs;
// create window
Window window = Platform.instance().createWindow("My Window", null); Window window = Platform.instance().createWindow("My Window", null);
Widget myWidget = (new Button()).textColor(0x40FF4000); Widget myWidget = (new Button()).textColor(0x40FF4000);
myWidget.text = "Some strange text string. 1234567890"; myWidget.text = "Some strange text string. 1234567890";
myWidget.alignment = Align.Center;
window.mainWidget = myWidget; window.mainWidget = myWidget;
window.show(); window.show();
window.windowCaption = "New Window Caption"; window.windowCaption = "New Window Caption";
// run message loop
Log.d("Before getFont");
FontRef font = FontManager.instance.getFont(32, 400, false, FontFamily.SansSerif, "Arial");
Log.d("After getFont");
assert(!font.isNull);
int[] widths;
dchar[] text = cast(dchar[])"Test string"d;
Log.d("Calling measureText");
int charsMeasured = font.measureText(text, widths, 1000);
assert(charsMeasured > 0);
int w = widths[charsMeasured - 1];
Log.d("Measured string: ", charsMeasured, " chars, width=", w);
Glyph * g = font.getCharGlyph('A');
Log.d("Char A glyph: ", g.blackBoxX, "x", g.blackBoxY);
return Platform.instance().enterMessageLoop(); return Platform.instance().enterMessageLoop();
} }

View File

@ -32,8 +32,9 @@ public class Window {
} }
} }
public void onDraw(DrawBuf buf) { public void onDraw(DrawBuf buf) {
if (_mainWidget !is null) if (_mainWidget !is null) {
_mainWidget.onDraw(buf); _mainWidget.onDraw(buf);
}
} }
} }

View File

@ -3,6 +3,7 @@ module dlangui.platforms.windows.win32drawbuf;
version (Windows) { version (Windows) {
import win32.windows; import win32.windows;
import dlangui.core.logger;
import dlangui.graphics.drawbuf; import dlangui.graphics.drawbuf;
class Win32ColorDrawBuf : ColorDrawBufBase { class Win32ColorDrawBuf : ColorDrawBufBase {
@ -18,10 +19,15 @@ class Win32ColorDrawBuf : ColorDrawBufBase {
return _pixels + _dx * (_dy - 1 - y); return _pixels + _dx * (_dy - 1 - y);
return null; return null;
} }
~this() {
clear();
}
override void clear() { override void clear() {
if (_drawbmp !is null) { if (_drawbmp !is null) {
DeleteObject( _drawbmp ); DeleteObject( _drawbmp );
DeleteObject( _drawdc ); DeleteObject( _drawdc );
_drawbmp = null;
_drawdc = null;
_pixels = null; _pixels = null;
_dx = 0; _dx = 0;
_dy = 0; _dy = 0;
@ -62,7 +68,7 @@ class Win32ColorDrawBuf : ColorDrawBufBase {
_pixels[i] = color; _pixels[i] = color;
} }
void drawTo(HDC dc, int x, int y) { void drawTo(HDC dc, int x, int y) {
BitBlt(dc, x, y, _dx, _dx, _drawdc, 0, 0, SRCCOPY); BitBlt(dc, x, y, _dx, _dy, _drawdc, 0, 0, SRCCOPY);
} }
} }

View File

@ -220,27 +220,29 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int dy = rect.bottom - rect.top; int dy = rect.bottom - rect.top;
//window.onResize(pos.cx, pos.cy); //window.onResize(pos.cx, pos.cy);
window.onResize(dx, dy); window.onResize(dx, dy);
UpdateWindow(hwnd); InvalidateRect(hwnd, null, FALSE);
//UpdateWindow(hwnd);
} }
return 0; return 0;
case WM_ERASEBKGND: case WM_ERASEBKGND:
return 1; return 1;
case WM_PAINT: case WM_PAINT:
{ {
GetClientRect(hwnd, &rect); //GetClientRect(hwnd, &rect);
int dx = rect.right - rect.left; //int dx = rect.right - rect.left;
int dy = rect.bottom - rect.top; //int dy = rect.bottom - rect.top;
window.onResize(dx, dy); //window.onResize(dx, dy);
hdc = BeginPaint(hwnd, &ps); hdc = BeginPaint(hwnd, &ps);
scope(exit) EndPaint(hwnd, &ps);
Win32ColorDrawBuf buf = window.getDrawBuf(); Win32ColorDrawBuf buf = window.getDrawBuf();
buf.fill(0x808080); buf.fill(0x808080);
window.onDraw(buf); window.onDraw(buf);
buf.drawTo(hdc, 0, 0); buf.drawTo(hdc, 0, 0);
//drawBuf2DC(hdc, 0, 0, buf);
scope(exit) EndPaint(hwnd, &ps);
} }
//DrawTextA(hdc, "Hello, Windows!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); return 0; // processed
return 0;
case WM_DESTROY: case WM_DESTROY:
window.onDestroy(); window.onDestroy();

View File

@ -18,10 +18,10 @@ enum Align : ubyte {
Unspecified = ALIGN_UNSPECIFIED, Unspecified = ALIGN_UNSPECIFIED,
Left = 1, Left = 1,
Right = 2, Right = 2,
HCenter = Left | Right, HCenter = 1 | 2,
Top = 4, Top = 4,
Bottom = 8, Bottom = 8,
VCenter = Top | Bottom, VCenter = 4 | 8,
Center = VCenter | HCenter, Center = VCenter | HCenter,
TopLeft = Left | Top, TopLeft = Left | Top,
} }
@ -95,6 +95,9 @@ class Style {
return (cast(Style)this)._backgroundDrawable; return (cast(Style)this)._backgroundDrawable;
} }
//===================================================
// font properties
@property ref FontRef font() const { @property ref FontRef font() const {
if (!(cast(Style)this)._font.isNull) if (!(cast(Style)this)._font.isNull)
return (cast(Style)this)._font; return (cast(Style)this)._font;
@ -147,6 +150,9 @@ class Style {
return parentStyle.fontSize; return parentStyle.fontSize;
} }
//===================================================
// layout parameters: margins / padding
/// padding /// padding
@property ref const(Rect) padding() const { @property ref const(Rect) padding() const {
if (_stateValue != 0) if (_stateValue != 0)
@ -169,6 +175,9 @@ class Style {
return parentStyle.textColor; return parentStyle.textColor;
} }
//===================================================
// background
/// background color /// background color
@property uint backgroundColor() const { @property uint backgroundColor() const {
if (_backgroundColor != COLOR_UNSPECIFIED) if (_backgroundColor != COLOR_UNSPECIFIED)
@ -185,6 +194,9 @@ class Style {
return parentStyle.backgroundImageId; return parentStyle.backgroundImageId;
} }
//===================================================
// alignment
/// get full alignment (both vertical and horizontal) /// get full alignment (both vertical and horizontal)
@property ubyte alignment() const { @property ubyte alignment() const {
if (_align != Align.Unspecified) if (_align != Align.Unspecified)
@ -193,9 +205,9 @@ class Style {
return parentStyle.alignment; return parentStyle.alignment;
} }
/// vertical alignment: Top / VCenter / Bottom /// vertical alignment: Top / VCenter / Bottom
@property ubyte valign() const { return _align & Align.VCenter; } @property ubyte valign() const { return alignment & Align.VCenter; }
/// horizontal alignment: Left / HCenter / Right /// horizontal alignment: Left / HCenter / Right
@property ubyte halign() const { return _align & Align.HCenter; } @property ubyte halign() const { return alignment & Align.HCenter; }
/// set alignment /// set alignment
@property Style alignment(ubyte value) { @property Style alignment(ubyte value) {
@ -320,6 +332,7 @@ class Theme : Style {
Style modifyStyle(string id) { Style modifyStyle(string id) {
Style style = new Style(null, null); Style style = new Style(null, null);
style._parentId = id; style._parentId = id;
style._align = Align.Unspecified; // inherit
return style; return style;
} }
@ -346,5 +359,6 @@ private __gshared Theme _currentTheme;
static this() { static this() {
_currentTheme = new Theme("default"); _currentTheme = new Theme("default");
Style button = _currentTheme.createSubstyle("BUTTON").backgroundImageId("btn_default_normal").alignment(Align.Center); Style button = _currentTheme.createSubstyle("BUTTON").backgroundImageId("btn_default_normal");
button.alignment(Align.Center);
} }

View File

@ -169,18 +169,20 @@ class Widget {
} }
/// Applies alignment for content of size sz - set rectangle rc to aligned value of content inside of initial value of rc. /// Applies alignment for content of size sz - set rectangle rc to aligned value of content inside of initial value of rc.
void applyAlign(ref Rect rc, Point sz) { void applyAlign(ref Rect rc, Point sz) {
if (valign == Align.Bottom) { Align va = valign;
Align ha = halign;
if (va == Align.Bottom) {
rc.top = rc.bottom - sz.y; rc.top = rc.bottom - sz.y;
} else if (valign == Align.VCenter) { } else if (va == Align.VCenter) {
int dy = (rc.height - sz.y) / 2; int dy = (rc.height - sz.y) / 2;
rc.top += dy; rc.top += dy;
rc.bottom = rc.top + sz.y; rc.bottom = rc.top + sz.y;
} else { } else {
rc.bottom = rc.top + sz.y; rc.bottom = rc.top + sz.y;
} }
if (halign == Align.Right) { if (ha == Align.Right) {
rc.left = rc.right - sz.x; rc.left = rc.right - sz.x;
} else if (halign == Align.HCenter) { } else if (ha == Align.HCenter) {
int dx = (rc.width - sz.x) / 2; int dx = (rc.width - sz.x) / 2;
rc.left += dx; rc.left += dx;
rc.right = rc.left + sz.x; rc.right = rc.left + sz.x;