diff --git a/libs/directx/dx/Window.hx b/libs/directx/dx/Window.hx index a0c5b7872..e0089e09b 100644 --- a/libs/directx/dx/Window.hx +++ b/libs/directx/dx/Window.hx @@ -41,6 +41,7 @@ class Window { public function new( title : String, width : Int, height : Int, x : Int = CW_USEDEFAULT, y : Int = CW_USEDEFAULT, windowFlags : Int = RESIZABLE ) { win = winCreateEx(x, y, width, height, windowFlags); + if( win == null ) throw "Failed to create window (" + winError() + ")"; this.title = title; windows.push(this); vsync = true; @@ -238,6 +239,14 @@ class Window { static function winDestroy( win : WinPtr ) { } + static function winError() { + return @:privateAccess String.fromUTF8(win_error()); + } + + static function win_error() : hl.Bytes { + return null; + } + public static function getScreenWidth() { return 0; } @@ -253,4 +262,4 @@ class Window { static function winClipCursor( win : WinPtr ) : Void { } -} \ No newline at end of file +} diff --git a/libs/directx/window.c b/libs/directx/window.c index 5f5743f95..52a1c2217 100644 --- a/libs/directx/window.c +++ b/libs/directx/window.c @@ -141,8 +141,8 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar case WM_SYSCOMMAND: if( wparam == SC_KEYMENU && (lparam>>16) <= 0 ) return 0; - break; - case WM_MOUSEMOVE: + break; + case WM_MOUSEMOVE: { dx_events *evt = get_events(wnd); if( !evt->is_over ) { @@ -154,7 +154,7 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar evt->is_over = true; addState(Enter); } - addMouse(MouseMove,0); + addMouse(MouseMove,0); } break; case WM_MOUSELEAVE: @@ -174,7 +174,7 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar } } bool repeat = (umsg == WM_KEYDOWN || umsg == WM_SYSKEYDOWN) && (lparam & 0x40000000) != 0; - // see + // see e = addEvent(wnd,(umsg == WM_KEYUP || umsg == WM_SYSKEYUP) ? KeyUp : KeyDown); e->keyCode = (int)wparam; e->scanCode = (lparam >> 16) & 0xFF; @@ -201,13 +201,13 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar shift_downs[0] = false; e = addEvent(wnd,KeyUp); e->keyCode = VK_SHIFT | 256; - } + } if( shift_downs[1] && GetKeyState(VK_RSHIFT) >= 0 ) { //printf("RSHIFT RELEASED\n"); shift_downs[1] = false; e = addEvent(wnd,KeyUp); e->keyCode = VK_SHIFT | 512; - } + } break; case WM_CHAR: e = addEvent(wnd,TextInput); @@ -541,6 +541,10 @@ HL_PRIM void HL_NAME(win_destroy)(dx_window *win) { DestroyWindow(win); } +HL_PRIM vbyte *HL_NAME(win_error)() { + return GetLastError(); +} + HL_PRIM bool HL_NAME(win_get_next_event)( dx_window *win, dx_event *e ) { dx_events *buf = get_events(win); hl_type *save; @@ -593,6 +597,7 @@ DEFINE_PRIM(_VOID, win_get_position, TWIN _REF(_I32) _REF(_I32)); DEFINE_PRIM(_F64, win_get_opacity, TWIN); DEFINE_PRIM(_BOOL, win_set_opacity, TWIN _F64); DEFINE_PRIM(_VOID, win_destroy, TWIN); +DEFINE_PRIM(_BYTES, win_error, _NO_ARG); DEFINE_PRIM(_BOOL, win_get_next_event, TWIN _DYN); DEFINE_PRIM(_VOID, win_clip_cursor, TWIN); diff --git a/libs/sdl/sdl.c b/libs/sdl/sdl.c index bbcfb3f3e..d47180b14 100644 --- a/libs/sdl/sdl.c +++ b/libs/sdl/sdl.c @@ -592,6 +592,10 @@ HL_PRIM void HL_NAME(win_destroy)(SDL_Window *win, SDL_GLContext gl) { SDL_GL_DeleteContext(gl); } +HL_PRIM const char *HL_NAME(win_error)() { + return SDL_GetError(); +} + #define TWIN _ABSTRACT(sdl_window) #define TGL _ABSTRACT(sdl_gl) DEFINE_PRIM(TWIN, win_create_ex, _I32 _I32 _I32 _I32 _I32); @@ -613,6 +617,7 @@ DEFINE_PRIM(_BOOL, win_set_opacity, TWIN _F64); DEFINE_PRIM(_VOID, win_swap_window, TWIN); DEFINE_PRIM(_VOID, win_render_to, TWIN TGL); DEFINE_PRIM(_VOID, win_destroy, TWIN TGL); +DEFINE_PRIM(_BYTES, win_error, _NO_ARG); // game controller diff --git a/libs/sdl/sdl/Window.hx b/libs/sdl/sdl/Window.hx index 899307101..aac00ab00 100644 --- a/libs/sdl/sdl/Window.hx +++ b/libs/sdl/sdl/Window.hx @@ -63,7 +63,7 @@ class Window { public function new( title : String, width : Int, height : Int, x : Int = SDL_WINDOWPOS_CENTERED, y : Int = SDL_WINDOWPOS_CENTERED, sdlFlags : Int = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ) { while( true ) { win = winCreateEx(x, y, width, height, sdlFlags); - if( win == null ) throw "Failed to create window"; + if( win == null ) throw "Failed to create window (" + winError() + ")"; glctx = winGetGLContext(win); if( glctx == null || !GL.init() || !testGL() ) { destroy(); @@ -332,6 +332,14 @@ class Window { static function winDestroy( win : WinPtr, gl : GLContext ) { } + static function winError() { + return @:privateAccess String.fromUTF8(win_error()); + } + + static function win_error() : hl.Bytes { + return null; + } + static function setVsync( b : Bool ) { }