Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add window winError #401

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion libs/directx/dx/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -253,4 +262,4 @@ class Window {
static function winClipCursor( win : WinPtr ) : Void {
}

}
}
17 changes: 11 additions & 6 deletions libs/directx/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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:
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions libs/sdl/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down
10 changes: 9 additions & 1 deletion libs/sdl/sdl/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 ) {
}

Expand Down