fix win32 build w/o SDL

This commit is contained in:
Vadim Lopatin 2014-05-21 06:38:56 +04:00
parent c71da5b7fc
commit c4de481f69
2 changed files with 69 additions and 24 deletions

View File

@ -12,21 +12,29 @@ extern (C) int UIAppMain(string[] args) {
// 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
appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
appendPath(exePath, "../../../../res/"),// for Mono-D builds appendPath(exePath, "../../../../res/"),// for Mono-D builds
appendPath(exePath, "res/") // when res dir is located at the same directory as executable appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
]; appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
appendPath(exePath, "../res/"), // when res dir is located at project directory
appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
];
// setup resource directories - will use only existing directories // setup resource directories - will use only existing directories
drawableCache.setResourcePaths(resourceDirs); Platform.instance.resourceDirs = resourceDirs;
// setup i18n - look for i18n directory inside one of passed directories
i18n.findTranslationsDir(resourceDirs);
// select translation file - for english language // select translation file - for english language
i18n.load("en.ini"); //"ru.ini", "en.ini" Platform.instance.uiLanguage = "en";
// load theme from file "theme_default.xml"
Platform.instance.uiTheme = "theme_default";
// create window // create window
Window window = Platform.instance.createWindow("My Window", null); Window window = Platform.instance.createWindow("My Window", null);
// create some widget to show in window // create some widget to show in window
window.mainWidget = (new Button()).text("Hello world"d); window.mainWidget = (new Button()).text("Hello world"d).margins(Rect(20,20,20,20));
// show window // show window
window.show(); window.show();

View File

@ -134,10 +134,10 @@ class Win32Window : Window {
HGLRC _hGLRC; // opengl context HGLRC _hGLRC; // opengl context
HPALETTE _hPalette; HPALETTE _hPalette;
} }
string _caption; dstring _caption;
Win32ColorDrawBuf _drawbuf; Win32ColorDrawBuf _drawbuf;
bool useOpengl; bool useOpengl;
this(Win32Platform platform, string windowCaption, Window parent) { this(Win32Platform platform, dstring windowCaption, Window parent, uint flags) {
_platform = platform; _platform = platform;
_caption = windowCaption; _caption = windowCaption;
_hwnd = CreateWindow(toUTF16z(WIN_CLASS_NAME), // window class name _hwnd = CreateWindow(toUTF16z(WIN_CLASS_NAME), // window class name
@ -277,13 +277,16 @@ class Win32Window : Window {
ShowWindow(_hwnd, _cmdShow); ShowWindow(_hwnd, _cmdShow);
//UpdateWindow(_hwnd); //UpdateWindow(_hwnd);
} }
override @property string windowCaption() {
return _caption; override @property dstring windowCaption() {
} return _caption;
override @property void windowCaption(string caption) { }
_caption = caption;
SetWindowTextW(_hwnd, toUTF16z(_caption)); override @property void windowCaption(dstring caption) {
} _caption = caption;
if (_hwnd)
SetWindowTextW(_hwnd, toUTF16z(_caption));
}
void onCreate() { void onCreate() {
Log.d("Window onCreate"); Log.d("Window onCreate");
_platform.onWindowCreated(_hwnd, this); _platform.onWindowCreated(_hwnd, this);
@ -293,6 +296,24 @@ class Win32Window : Window {
_platform.onWindowDestroyed(_hwnd, this); _platform.onWindowDestroyed(_hwnd, this);
} }
/// close window
override void close() {
Log.d("Window.close()");
_platform.closeWindow(this);
}
/// sets window icon
@property override void windowIcon(DrawBufRef buf) {
ColorDrawBuf icon = cast(ColorDrawBuf)buf.get;
if (!icon) {
Log.e("Trying to set null icon for window");
return;
}
//icon = new ColorDrawBuf(icon);
//icon.invertAlpha();
//destroy(icon);
}
private void paintUsingGDI() { private void paintUsingGDI() {
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc = BeginPaint(_hwnd, &ps); HDC hdc = BeginPaint(_hwnd, &ps);
@ -528,10 +549,26 @@ class Win32Platform : Platform {
return _windowMap[cast(ulong)hwnd]; return _windowMap[cast(ulong)hwnd];
return null; return null;
} }
override Window createWindow(string windowCaption, Window parent) { override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable) {
return new Win32Window(this, windowCaption, parent); return new Win32Window(this, windowCaption, parent, flags);
} }
/// calls request layout for all windows
override void requestLayout() {
foreach(w; _windowMap) {
w.requestLayout();
w.invalidate();
}
}
Win32Window _windowToClose;
/// close window
override void closeWindow(Window w) {
Win32Window window = cast(Win32Window)w;
_windowToClose = window;
}
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux) /// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override dstring getClipboardText(bool mouseBuffer = false) { override dstring getClipboardText(bool mouseBuffer = false) {
dstring res = null; dstring res = null;
@ -634,7 +671,7 @@ string[] splitCmdLine(string line) {
return res; return res;
} }
private __gshared Win32Platform platform; private __gshared Win32Platform w32platform;
int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{ {
@ -651,12 +688,12 @@ int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
_cmdShow = iCmdShow; _cmdShow = iCmdShow;
_hInstance = hInstance; _hInstance = hInstance;
platform = new Win32Platform(); w32platform = new Win32Platform();
if (!platform.registerWndClass()) { if (!w32platform.registerWndClass()) {
MessageBoxA(null, "This program requires Windows NT!", "DLANGUI App".toStringz, MB_ICONERROR); MessageBoxA(null, "This program requires Windows NT!", "DLANGUI App".toStringz, MB_ICONERROR);
return 0; return 0;
} }
Platform.setInstance(platform); Platform.setInstance(w32platform);
/// testing freetype font manager /// testing freetype font manager
@ -734,7 +771,7 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
void * p = cast(void*)GetWindowLongPtr(hwnd, GWLP_USERDATA); void * p = cast(void*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
Win32Window windowParam = p is null ? null : cast(Win32Window)(p); Win32Window windowParam = p is null ? null : cast(Win32Window)(p);
Win32Window window = platform.getWindow(hwnd); Win32Window window = w32platform.getWindow(hwnd);
if (windowParam !is null && window !is null) if (windowParam !is null && window !is null)
assert(window is windowParam); assert(window is windowParam);
if (window is null && windowParam !is null) { if (window is null && windowParam !is null) {
@ -756,7 +793,7 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_DESTROY: case WM_DESTROY:
if (window !is null) if (window !is null)
window.onDestroy(); window.onDestroy();
if (platform.windowCount == 0) if (w32platform.windowCount == 0)
PostQuitMessage(0); PostQuitMessage(0);
return 0; return 0;
case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGED: