diff options
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/libui/common/control.c | 5 | ||||
-rw-r--r-- | src/libui_sdl/libui/ui.h | 11 | ||||
-rw-r--r-- | src/libui_sdl/libui/ui_windows.h | 7 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/areaevents.cpp | 14 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/box.cpp | 1 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/form.cpp | 1 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/grid.cpp | 1 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/group.cpp | 1 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/tab.cpp | 1 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/window.cpp | 1 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 45 |
11 files changed, 79 insertions, 9 deletions
diff --git a/src/libui_sdl/libui/common/control.c b/src/libui_sdl/libui/common/control.c index 2806646..771a29d 100644 --- a/src/libui_sdl/libui/common/control.c +++ b/src/libui_sdl/libui/common/control.c @@ -57,6 +57,11 @@ void uiControlDisable(uiControl *c) (*(c->Disable))(c); } +void uiControlSetFocus(uiControl *c) +{ + (*(c->SetFocus))(c); +} + #define uiControlSignature 0x7569436F uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr) diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index 835b0c2..3d81996 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -72,6 +72,7 @@ struct uiControl { int (*Enabled)(uiControl *); void (*Enable)(uiControl *); void (*Disable)(uiControl *); + void (*SetFocus)(uiControl *); }; // TOOD add argument names to all arguments #define uiControl(this) ((uiControl *) (this)) @@ -86,6 +87,7 @@ _UI_EXTERN void uiControlHide(uiControl *); _UI_EXTERN int uiControlEnabled(uiControl *); _UI_EXTERN void uiControlEnable(uiControl *); _UI_EXTERN void uiControlDisable(uiControl *); +_UI_EXTERN void uiControlSetFocus(uiControl *); _UI_EXTERN uiControl *uiAllocControl(size_t n, uint32_t OSsig, uint32_t typesig, const char *typenamestr); _UI_EXTERN void uiFreeControl(uiControl *); @@ -653,7 +655,11 @@ struct uiAreaKeyEvent { uiModifiers Modifiers; + // additional things + int Scancode; // bit0-7: scancode, bit8: ext flag + int Up; + int Repeat; }; typedef struct uiFontButton uiFontButton; @@ -701,6 +707,11 @@ _UI_EXTERN int uiGridPadded(uiGrid *g); _UI_EXTERN void uiGridSetPadded(uiGrid *g, int padded); _UI_EXTERN uiGrid *uiNewGrid(void); + +// misc. + +_UI_EXTERN char* uiKeyName(int scancode); + #ifdef __cplusplus } #endif diff --git a/src/libui_sdl/libui/ui_windows.h b/src/libui_sdl/libui/ui_windows.h index 69dda36..3917c97 100644 --- a/src/libui_sdl/libui/ui_windows.h +++ b/src/libui_sdl/libui/ui_windows.h @@ -102,6 +102,11 @@ _UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *); uiWindowsControl(c)->enabled = 0; \ uiWindowsControlSyncEnableState(uiWindowsControl(c), uiControlEnabledToUser(c)); \ } +#define uiWindowsControlDefaultSetFocus(type) \ + static void type ## SetFocus(uiControl *c) \ + { \ + SetFocus(type(c)->hwnd); \ + } #define uiWindowsControlDefaultSyncEnableState(type) \ static void type ## SyncEnableState(uiWindowsControl *c, int enabled) \ { \ @@ -152,6 +157,7 @@ _UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *); uiWindowsControlDefaultEnabled(type) \ uiWindowsControlDefaultEnable(type) \ uiWindowsControlDefaultDisable(type) \ + uiWindowsControlDefaultSetFocus(type) \ uiWindowsControlDefaultSyncEnableState(type) \ uiWindowsControlDefaultSetParentHWND(type) \ uiWindowsControlDefaultMinimumSizeChanged(type) \ @@ -177,6 +183,7 @@ _UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *); uiControl(var)->Enabled = type ## Enabled; \ uiControl(var)->Enable = type ## Enable; \ uiControl(var)->Disable = type ## Disable; \ + uiControl(var)->SetFocus = type ## SetFocus; \ uiWindowsControl(var)->SyncEnableState = type ## SyncEnableState; \ uiWindowsControl(var)->SetParentHWND = type ## SetParentHWND; \ uiWindowsControl(var)->MinimumSize = type ## MinimumSize; \ diff --git a/src/libui_sdl/libui/windows/areaevents.cpp b/src/libui_sdl/libui/windows/areaevents.cpp index 7d391b8..842f2d7 100644 --- a/src/libui_sdl/libui/windows/areaevents.cpp +++ b/src/libui_sdl/libui/windows/areaevents.cpp @@ -262,8 +262,14 @@ static int areaKeyEvent(uiArea *a, int up, WPARAM wParam, LPARAM lParam) ke.Modifiers = getModifiers(); + ke.Scancode = (lParam >> 16) & 0x1FF; + ke.Up = up; + ke.Repeat = (lParam & 0x40000000) ? 1:0; + // StapleButter note: I don't actually need all this key decoding + // raw scancodes are all I need for this +#if 0 // the numeric keypad keys when Num Lock is off are considered left-hand keys as the separate navigation buttons were added later // the numeric keypad Enter, however, is a right-hand key because it has the same virtual-key code as the typewriter Enter righthand = (lParam & 0x01000000) != 0; @@ -306,9 +312,17 @@ static int areaKeyEvent(uiArea *a, int up, WPARAM wParam, LPARAM lParam) return 0; keyFound: +#endif return (*(a->ah->KeyEvent))(a->ah, a, &ke); } +char* uiKeyName(int scancode) +{ + WCHAR tmp[64]; + GetKeyNameText(scancode<<16, tmp, 64); + return toUTF8(tmp); +} + // We don't handle the standard Windows keyboard messages directly, to avoid both the dialog manager and TranslateMessage(). // Instead, we set up a message filter and do things there. // That stuff is later in this file. diff --git a/src/libui_sdl/libui/windows/box.cpp b/src/libui_sdl/libui/windows/box.cpp index 9567954..c306989 100644 --- a/src/libui_sdl/libui/windows/box.cpp +++ b/src/libui_sdl/libui/windows/box.cpp @@ -143,6 +143,7 @@ uiWindowsControlDefaultHide(uiBox) uiWindowsControlDefaultEnabled(uiBox) uiWindowsControlDefaultEnable(uiBox) uiWindowsControlDefaultDisable(uiBox) +uiWindowsControlDefaultSetFocus(uiBox) static void uiBoxSyncEnableState(uiWindowsControl *c, int enabled) { diff --git a/src/libui_sdl/libui/windows/form.cpp b/src/libui_sdl/libui/windows/form.cpp index febcc69..83ed587 100644 --- a/src/libui_sdl/libui/windows/form.cpp +++ b/src/libui_sdl/libui/windows/form.cpp @@ -147,6 +147,7 @@ uiWindowsControlDefaultHide(uiForm) uiWindowsControlDefaultEnabled(uiForm) uiWindowsControlDefaultEnable(uiForm) uiWindowsControlDefaultDisable(uiForm) +uiWindowsControlDefaultSetFocus(uiForm) static void uiFormSyncEnableState(uiWindowsControl *c, int enabled) { diff --git a/src/libui_sdl/libui/windows/grid.cpp b/src/libui_sdl/libui/windows/grid.cpp index c63cd1e..78719ac 100644 --- a/src/libui_sdl/libui/windows/grid.cpp +++ b/src/libui_sdl/libui/windows/grid.cpp @@ -436,6 +436,7 @@ uiWindowsControlDefaultHide(uiGrid) uiWindowsControlDefaultEnabled(uiGrid) uiWindowsControlDefaultEnable(uiGrid) uiWindowsControlDefaultDisable(uiGrid) +uiWindowsControlDefaultSetFocus(uiGrid) static void uiGridSyncEnableState(uiWindowsControl *c, int enabled) { diff --git a/src/libui_sdl/libui/windows/group.cpp b/src/libui_sdl/libui/windows/group.cpp index 8824c5a..f78e7de 100644 --- a/src/libui_sdl/libui/windows/group.cpp +++ b/src/libui_sdl/libui/windows/group.cpp @@ -75,6 +75,7 @@ uiWindowsControlDefaultHide(uiGroup) uiWindowsControlDefaultEnabled(uiGroup) uiWindowsControlDefaultEnable(uiGroup) uiWindowsControlDefaultDisable(uiGroup) +uiWindowsControlDefaultSetFocus(uiGroup) static void uiGroupSyncEnableState(uiWindowsControl *c, int enabled) { diff --git a/src/libui_sdl/libui/windows/tab.cpp b/src/libui_sdl/libui/windows/tab.cpp index 365f5a1..ea6209b 100644 --- a/src/libui_sdl/libui/windows/tab.cpp +++ b/src/libui_sdl/libui/windows/tab.cpp @@ -112,6 +112,7 @@ uiWindowsControlDefaultHide(uiTab) uiWindowsControlDefaultEnabled(uiTab) uiWindowsControlDefaultEnable(uiTab) uiWindowsControlDefaultDisable(uiTab) +uiWindowsControlDefaultSetFocus(uiTab) static void uiTabSyncEnableState(uiWindowsControl *c, int enabled) { diff --git a/src/libui_sdl/libui/windows/window.cpp b/src/libui_sdl/libui/windows/window.cpp index 9cf13a2..c04410d 100644 --- a/src/libui_sdl/libui/windows/window.cpp +++ b/src/libui_sdl/libui/windows/window.cpp @@ -229,6 +229,7 @@ static void uiWindowHide(uiControl *c) uiWindowsControlDefaultEnabled(uiWindow) uiWindowsControlDefaultEnable(uiWindow) uiWindowsControlDefaultDisable(uiWindow) +uiWindowsControlDefaultSetFocus(uiWindow) // TODO we need to do something about undocumented fields in the OS control types uiWindowsControlDefaultSyncEnableState(uiWindow) // TODO diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 018049e..52c8117 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -25,6 +25,7 @@ #include "../types.h" #include "../version.h" +#include "../Config.h" #include "../NDS.h" #include "../GPU.h" @@ -38,7 +39,7 @@ SDL_Thread* EmuThread; int EmuRunning; SDL_mutex* ScreenMutex; -uiDrawBitmap* test = NULL; +uiDrawBitmap* ScreenBitmap = NULL; void AudioCallback(void* data, Uint8* stream, int len) @@ -155,21 +156,24 @@ int EmuThreadFunc(void* burp) void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) { - if (!test) test = uiDrawNewBitmap(params->Context, 256, 384); + if (!ScreenBitmap) + ScreenBitmap = uiDrawNewBitmap(params->Context, 256, 384); uiRect dorp = {0, 0, 256, 384}; //SDL_LockMutex(ScreenMutex); - uiDrawBitmapUpdate(test, GPU::Framebuffer); + uiDrawBitmapUpdate(ScreenBitmap, GPU::Framebuffer); //SDL_UnlockMutex(ScreenMutex); - uiDrawBitmapDraw(params->Context, test, &dorp, &dorp); + uiDrawBitmapDraw(params->Context, ScreenBitmap, &dorp, &dorp); //printf("draw\n"); } void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* evt) { - // + int x = (int)evt->X; + int y = (int)evt->Y; + printf("mouse: %08X %d,%d\n", (u32)evt->Held1To64, x, y); } void OnAreaMouseCrossed(uiAreaHandler* handler, uiArea* area, int left) @@ -184,8 +188,28 @@ void OnAreaDragBroken(uiAreaHandler* handler, uiArea* area) int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) { - printf("key event: %04X %02X\n", evt->ExtKey, evt->Key); - //uiAreaQueueRedrawAll(MainDrawArea); + // TODO: release all keys if the window loses focus? or somehow global key input? + if (evt->Scancode == 0x38) // ALT + return 0; + if (evt->Modifiers == 0x2) // ALT+key + return 0; + + if (evt->Up) + { + for (int i = 0; i < 10; i++) + if (evt->Scancode == Config::KeyMapping[i]) NDS::ReleaseKey(i); + if (evt->Scancode == Config::KeyMapping[10]) NDS::ReleaseKey(16); + if (evt->Scancode == Config::KeyMapping[11]) NDS::ReleaseKey(17); + } + else if (!evt->Repeat) + { + //printf("key event: %08X %08X - %s\n", evt->Scancode, evt->Modifiers, uiKeyName(evt->Scancode)); + for (int i = 0; i < 10; i++) + if (evt->Scancode == Config::KeyMapping[i]) NDS::PressKey(i); + if (evt->Scancode == Config::KeyMapping[10]) NDS::PressKey(16); + if (evt->Scancode == Config::KeyMapping[11]) NDS::PressKey(17); + } + return 1; } @@ -204,7 +228,7 @@ void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) char* file = uiOpenFile(window, "DS ROM (*.nds)|*.nds;*.srl|Any file|*.*", NULL); if (!file) return; - NDS::LoadROM(file, true); // TODO direct boot setting + NDS::LoadROM(file, Config::DirectBoot); EmuRunning = 1; } @@ -238,6 +262,8 @@ int main(int argc, char** argv) return 1; } + Config::Load(); + uiMenu* menu; uiMenuItem* menuitem; @@ -260,18 +286,19 @@ int main(int argc, char** argv) MainDrawArea = uiNewArea(&areahandler); uiWindowSetChild(MainWindow, uiControl(MainDrawArea)); - //uiWindowSetChild(MainWindow, uiControl(uiNewButton("become a girl"))); EmuRunning = 2; EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL); uiControlShow(uiControl(MainWindow)); + uiControlSetFocus(uiControl(MainDrawArea)); // TODO: this needs to be done when the window regains focus uiMain(); EmuRunning = 0; SDL_WaitThread(EmuThread, NULL); SDL_DestroyMutex(ScreenMutex); + uiDrawFreeBitmap(ScreenBitmap); uiUninit(); SDL_Quit(); |