diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-23 02:58:04 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-23 02:58:04 +0200 |
commit | 14b7cf1987f01b706a902d2bafdd4e72bb88889a (patch) | |
tree | a6649108921d73c7d22ef3eb141fa35cfc513308 | |
parent | a9cacb9dd789b64e50dd09b18b863afb02b966ea (diff) |
add hooks for when the window gets/loses focus.
properly refocus draw area.
lay base for dragdrop.
-rw-r--r-- | src/libui_sdl/libui/ui.h | 8 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/window.cpp | 68 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 20 |
3 files changed, 89 insertions, 7 deletions
diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index 3d81996..7cbc6f8 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -106,8 +106,6 @@ _UI_EXTERN void uiWindowContentSize(uiWindow *w, int *width, int *height); _UI_EXTERN void uiWindowSetContentSize(uiWindow *w, int width, int height); _UI_EXTERN int uiWindowFullscreen(uiWindow *w); _UI_EXTERN void uiWindowSetFullscreen(uiWindow *w, int fullscreen); -_UI_EXTERN void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data); -_UI_EXTERN void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *w, void *data), void *data); _UI_EXTERN int uiWindowBorderless(uiWindow *w); _UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless); _UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child); @@ -115,6 +113,12 @@ _UI_EXTERN int uiWindowMargined(uiWindow *w); _UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined); _UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar); +_UI_EXTERN void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data); +_UI_EXTERN void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *w, void *data), void *data); +_UI_EXTERN void uiWindowOnDropFile(uiWindow *w, void (*f)(uiWindow *w, char *file, void *data), void *data); +_UI_EXTERN void uiWindowOnGetFocus(uiWindow *w, void (*f)(uiWindow *w, void *data), void *data); +_UI_EXTERN void uiWindowOnLoseFocus(uiWindow *w, void (*f)(uiWindow *w, void *data), void *data); + typedef struct uiButton uiButton; #define uiButton(this) ((uiButton *) (this)) _UI_EXTERN char *uiButtonText(uiButton *b); diff --git a/src/libui_sdl/libui/windows/window.cpp b/src/libui_sdl/libui/windows/window.cpp index c04410d..07496b3 100644 --- a/src/libui_sdl/libui/windows/window.cpp +++ b/src/libui_sdl/libui/windows/window.cpp @@ -10,16 +10,23 @@ struct uiWindow { uiControl *child; BOOL shownOnce; int visible; - int (*onClosing)(uiWindow *, void *); - void *onClosingData; int margined; BOOL hasMenubar; - void (*onContentSizeChanged)(uiWindow *, void *); - void *onContentSizeChangedData; BOOL changingSize; int fullscreen; WINDOWPLACEMENT fsPrevPlacement; int borderless; + + int (*onClosing)(uiWindow *, void *); + void *onClosingData; + void (*onContentSizeChanged)(uiWindow *, void *); + void *onContentSizeChangedData; + void (*onDropFile)(uiWindow *, char *, void *); + void *onDropFileData; + void (*onGetFocus)(uiWindow *, void *); + void *onGetFocusData; + void (*onLoseFocus)(uiWindow *, void *); + void *onLoseFocusData; }; // from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing @@ -108,6 +115,37 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA mmi->ptMinTrackSize.x = width; mmi->ptMinTrackSize.y = height; return lResult; + + case WM_DROPFILES: + if (w->onDropFile) + { + HDROP eggdrop = (HDROP)wParam; + WCHAR filename[1024]; + DragQueryFile(eggdrop, 0, filename, 1024); + + char* filename8 = toUTF8(filename); + w->onDropFile(w, filename8, w->onDropFileData); + uiFreeText(filename8); + + DragFinish(eggdrop); + } + break; + + case WM_SETFOCUS: + if (w->onGetFocus) + { + w->onGetFocus(w, w->onGetFocusData); + return 0; + } + break; + case WM_KILLFOCUS: + if (w->onLoseFocus) + { + w->onLoseFocus(w, w->onLoseFocusData); + return 0; + } + break; + case WM_PRINTCLIENT: // we do no special painting; just erase the background // don't worry about the return value; we let DefWindowProcW() handle this message @@ -383,6 +421,24 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) w->onClosingData = data; } +void uiWindowOnDropFile(uiWindow *w, void (*f)(uiWindow *, char *, void *), void *data) +{ + w->onDropFile = f; + w->onDropFileData = data; +} + +void uiWindowOnGetFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) +{ + w->onGetFocus = f; + w->onGetFocusData = data; +} + +void uiWindowOnLoseFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) +{ + w->onLoseFocus = f; + w->onLoseFocusData = data; +} + int uiWindowBorderless(uiWindow *w) { return w->borderless; @@ -492,6 +548,10 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) uiWindowOnClosing(w, defaultOnClosing, NULL); uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); + uiWindowOnDropFile(w, NULL, NULL); + uiWindowOnGetFocus(w, NULL, NULL); + uiWindowOnLoseFocus(w, NULL, NULL); + windows[w] = true; return w; } diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 21ace33..8d54ea5 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -295,6 +295,21 @@ int OnCloseWindow(uiWindow* window, void* blarg) return 1; } +void OnDropFile(uiWindow* window, char* file, void* blarg) +{ + printf("DROP: %s\n", file); +} + +void OnGetFocus(uiWindow* window, void* blarg) +{ + uiControlSetFocus(uiControl(MainDrawArea)); +} + +void OnLoseFocus(uiWindow* window, void* blarg) +{ + // TODO: shit here? +} + void OnCloseByMenu(uiMenuItem* item, uiWindow* window, void* blarg) { uiControlDestroy(uiControl(window)); @@ -431,6 +446,9 @@ int main(int argc, char** argv) MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, 256, 384, 1); uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); + uiWindowOnDropFile(MainWindow, OnDropFile, NULL); + uiWindowOnGetFocus(MainWindow, OnGetFocus, NULL); + uiWindowOnLoseFocus(MainWindow, OnLoseFocus, NULL); uiMenuItemDisable(MenuItem_Pause); uiMenuItemDisable(MenuItem_Reset); @@ -452,7 +470,7 @@ int main(int argc, char** argv) EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL); uiControlShow(uiControl(MainWindow)); - //uiControlSetFocus(uiControl(MainDrawArea)); // TODO: this needs to be done when the window regains focus + uiControlSetFocus(uiControl(MainDrawArea)); uiMain(); EmuRunning = 0; |