From 4681e09aac67947787179829ed4b048f87a21784 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Aug 2002 09:17:21 +0000 Subject: Unix coder playing win32 programmer, added button_get_w_tmo() and it what do you know, it might just work. There was no win32 programmer in sight. How hard can it be? ;-P git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1580 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/win32/button.c | 138 +++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 55 deletions(-) (limited to 'uisimulator') diff --git a/uisimulator/win32/button.c b/uisimulator/win32/button.c index 3ecdca2b19..4fb4bd0612 100644 --- a/uisimulator/win32/button.c +++ b/uisimulator/win32/button.c @@ -50,61 +50,89 @@ int button_set_release(int newmask) return oldmask; } +static int real_button_get(void) +{ + if (bActive) + { + if (KEY (VK_NUMPAD4) || + KEY (VK_LEFT)) // left button + btn |= BUTTON_LEFT; + + if (KEY (VK_NUMPAD6) || + KEY (VK_RIGHT)) + btn |= BUTTON_RIGHT; // right button + + if (KEY (VK_NUMPAD8) || + KEY (VK_UP)) + btn |= BUTTON_UP; // up button + + if (KEY (VK_NUMPAD2) || + KEY (VK_DOWN)) + btn |= BUTTON_DOWN; // down button + + if (KEY (VK_ADD)) + btn |= BUTTON_ON; // on button + +#ifdef HAVE_RECORDER_KEYPAD + if (KEY (VK_RETURN)) + btn |= BUTTON_OFF; // off button + + if (KEY (VK_DIVIDE) || KEY(VK_F1)) + btn |= BUTTON_F1; // F1 button + + if (KEY (VK_MULTIPLY) || KEY(VK_F2)) + btn |= BUTTON_F2; // F2 button + + if (KEY (VK_SUBTRACT) || KEY(VK_F3)) + btn |= BUTTON_F3; // F3 button + + if (KEY (VK_NUMPAD5) || + KEY (VK_SPACE)) + btn |= BUTTON_PLAY; // play button +#else + if (KEY (VK_RETURN)) + btn |= BUTTON_MENU; // menu button +#endif + + if (btn != 0) { + last_key = 0 ; + } + } + + return btn; +} + int button_get(bool block) { - int btn = 0; - do - { - if (bActive) - { - if (KEY (VK_NUMPAD4) || - KEY (VK_LEFT)) // left button - btn |= BUTTON_LEFT; - - if (KEY (VK_NUMPAD6) || - KEY (VK_RIGHT)) - btn |= BUTTON_RIGHT; // right button - - if (KEY (VK_NUMPAD8) || - KEY (VK_UP)) - btn |= BUTTON_UP; // up button - - if (KEY (VK_NUMPAD2) || - KEY (VK_DOWN)) - btn |= BUTTON_DOWN; // down button - - if (KEY (VK_ADD)) - btn |= BUTTON_ON; // on button - - #ifdef HAVE_RECORDER_KEYPAD - if (KEY (VK_RETURN)) - btn |= BUTTON_OFF; // off button - - if (KEY (VK_DIVIDE) || KEY(VK_F1)) - btn |= BUTTON_F1; // F1 button - - if (KEY (VK_MULTIPLY) || KEY(VK_F2)) - btn |= BUTTON_F2; // F2 button - - if (KEY (VK_SUBTRACT) || KEY(VK_F3)) - btn |= BUTTON_F3; // F3 button - - if (KEY (VK_NUMPAD5) || - KEY (VK_SPACE)) - btn |= BUTTON_PLAY; // play button - #else - if (KEY (VK_RETURN)) - btn |= BUTTON_MENU; // menu button - #endif - - if (btn != 0) { - last_key = 0 ; - } - } - } - while (btn == 0 && block); - - Sleep (50); - - return btn; + int btn; + do { + + btn = real_button_get(); + + if(!btn) + /* prevent busy-looping */ + Sleep (50); /* ms */ + else + break; + + } while (block); + + return btn; +} + +int button_get_w_tmo(int ticks) +{ + int btn; + do { + btn = real_button_get(); + + if(!btn) + /* prevent busy-looping */ + sleep(1); /* one tick! */ + else + break; + + } while (block); + + return btn; } -- cgit v1.2.3