* attempt at keyboard input, via raw scancodes
* load config, etc * some things are nicer, too
This commit is contained in:
parent
66106a8829
commit
8e7d46e717
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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; \
|
||||
|
|
|
@ -262,8 +262,14 @@ static int areaKeyEvent(uiArea *a, int up, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
ke.Modifiers = getModifiers();
|
||||
|
||||
ke.Up = up;
|
||||
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.
|
||||
|
|
|
@ -143,6 +143,7 @@ uiWindowsControlDefaultHide(uiBox)
|
|||
uiWindowsControlDefaultEnabled(uiBox)
|
||||
uiWindowsControlDefaultEnable(uiBox)
|
||||
uiWindowsControlDefaultDisable(uiBox)
|
||||
uiWindowsControlDefaultSetFocus(uiBox)
|
||||
|
||||
static void uiBoxSyncEnableState(uiWindowsControl *c, int enabled)
|
||||
{
|
||||
|
|
|
@ -147,6 +147,7 @@ uiWindowsControlDefaultHide(uiForm)
|
|||
uiWindowsControlDefaultEnabled(uiForm)
|
||||
uiWindowsControlDefaultEnable(uiForm)
|
||||
uiWindowsControlDefaultDisable(uiForm)
|
||||
uiWindowsControlDefaultSetFocus(uiForm)
|
||||
|
||||
static void uiFormSyncEnableState(uiWindowsControl *c, int enabled)
|
||||
{
|
||||
|
|
|
@ -436,6 +436,7 @@ uiWindowsControlDefaultHide(uiGrid)
|
|||
uiWindowsControlDefaultEnabled(uiGrid)
|
||||
uiWindowsControlDefaultEnable(uiGrid)
|
||||
uiWindowsControlDefaultDisable(uiGrid)
|
||||
uiWindowsControlDefaultSetFocus(uiGrid)
|
||||
|
||||
static void uiGridSyncEnableState(uiWindowsControl *c, int enabled)
|
||||
{
|
||||
|
|
|
@ -75,6 +75,7 @@ uiWindowsControlDefaultHide(uiGroup)
|
|||
uiWindowsControlDefaultEnabled(uiGroup)
|
||||
uiWindowsControlDefaultEnable(uiGroup)
|
||||
uiWindowsControlDefaultDisable(uiGroup)
|
||||
uiWindowsControlDefaultSetFocus(uiGroup)
|
||||
|
||||
static void uiGroupSyncEnableState(uiWindowsControl *c, int enabled)
|
||||
{
|
||||
|
|
|
@ -112,6 +112,7 @@ uiWindowsControlDefaultHide(uiTab)
|
|||
uiWindowsControlDefaultEnabled(uiTab)
|
||||
uiWindowsControlDefaultEnable(uiTab)
|
||||
uiWindowsControlDefaultDisable(uiTab)
|
||||
uiWindowsControlDefaultSetFocus(uiTab)
|
||||
|
||||
static void uiTabSyncEnableState(uiWindowsControl *c, int enabled)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue