bool WindowButton::onMessage( const Message & msg ) { if ( enabled() ) { switch( msg.message ) { case HM_SYSKEYDOWN: case HM_KEYDOWN: if ( (msg.message == HM_KEYDOWN && msg.wparam == m_HotKey) || (msg.message == HM_SYSKEYDOWN && (msg.wparam | HMK_ALT_MASK) == m_HotKey) ) { if ( m_ButtonDown && m_Toggle ) { onButtonUp(); return trapKey(); } m_HotKeyDown = true; onButtonDown(); return trapKey(); } break; case HM_SYSKEYUP: case HM_KEYUP: if ( m_HotKeyDown && (msg.wparam & 0xff) == (m_HotKey & 0xff) ) { if ( !m_Toggle && m_ButtonDown ) onButtonUp(); m_HotKeyDown = false; return trapKey(); } break; } } return NodeWindow::onMessage( msg ); }
void WindowButton::onHide() { NodeWindow::onHide(); // if button was held down, release the button now.. if ( m_ButtonDown && !m_Toggle ) onButtonUp(); // save the cursor over state, in some cases a button will be hidden, then unhidden by some button logic, if // we don't do this then it makes it impossible to click on those buttons. m_bSavedCursorOver = m_CursorOver; // clear some booleans m_CursorOver = m_HotKeyDown = false; }
bool WindowButton::onLeftUp( const RectInt & window, const PointInt & position ) { if ( m_CursorOver ) { if ( !m_Toggle && !m_bGreyed ) { if ( !m_ButtonDown ) onButtonDown(); onButtonUp(); } return true; } else if (! m_Toggle ) onButtonAbort(); return NodeWindow::onLeftUp( window, position ); }
bool WindowButton::onLeftDown( const RectInt & window, const PointInt & position ) { if ( m_CursorOver ) { if ( !m_bGreyed ) { if ( m_ButtonDown && m_Toggle ) { onButtonUp(); return true; } onButtonDown(); } return true; } return NodeWindow::onLeftDown( window, position ); }
void Gosu::Input::update() { pimpl->updateMousePos(); pimpl->updateButtons(true); Impl::Events events; events.swap(pimpl->events); for (unsigned i = 0; i < events.size(); ++i) { if (events[i].action == Impl::EventInfo::buttonDown) { if (onButtonDown) onButtonDown(Button(events[i].id)); } else { if (onButtonUp) onButtonUp(Button(events[i].id)); } } }
void Gosu::Input::update() { for (unsigned int i = 0; i < pimpl->eventList.size(); i++) { ::XEvent event = pimpl->eventList[i]; if (textInput() && textInput()->feedXEvent(pimpl->display, &event)) continue; if (event.type == KeyPress) { // char buf[8]; // unsigned chars = XLookupString(&event.xkey, buf, sizeof buf, 0, 0); // unsigned keysym = XKeycodeToKeysym(pimpl->display, event.xkey.keycode, 0); // unsigned id = (chars == 0) ? keysym : widen(buf).at(0); unsigned id = XKeycodeToKeysym(pimpl->display, event.xkey.keycode, 0); pimpl->keyMap[id] = true; if (onButtonDown) onButtonDown(Button(id)); } else if (event.type == KeyRelease) { // char buf[8]; // unsigned chars = XLookupString(&event.xkey, buf, sizeof buf, 0, 0); // unsigned keysym = XKeycodeToKeysym(pimpl->display, event.xkey.keycode, 0); // unsigned id = (chars == 0) ? keysym : widen(buf).at(0); if (i < pimpl->eventList.size() - 1) { ::XEvent nextEvent = pimpl->eventList[i + 1]; if (nextEvent.type == KeyPress && nextEvent.xkey.keycode == event.xkey.keycode) { i += 1; continue; } } unsigned id = XKeycodeToKeysym(pimpl->display, event.xkey.keycode, 0); pimpl->keyMap[id] = false; if (onButtonUp) onButtonUp(Button(id)); } else if (event.type == ButtonPress) { unsigned id; switch (event.xbutton.button) { case Button1: id = msLeft; break; case Button2: id = msMiddle; break; case Button3: id = msRight; break; case Button4: id = msWheelUp; break; case Button5: id = msWheelDown; break; default: continue; } pimpl->keyMap[id] = true; // TODO: Here, above, below, who came up with that cast? Uh :) if (onButtonDown) onButtonDown(Button(id)); if (onButtonUp and id == msWheelUp or id == msWheelDown) onButtonUp(Button(id)); } else if (event.type == ButtonRelease) { unsigned id; switch (event.xbutton.button) { case Button1: id = msLeft; break; case Button2: id = msMiddle; break; case Button3: id = msRight; break; default: continue; } pimpl->keyMap[id] = false; if (onButtonUp) onButtonUp(*reinterpret_cast<Button*>(&id)); } else if (event.type == MotionNotify) { pimpl->mouseX = event.xbutton.x; pimpl->mouseY = event.xbutton.y; } else if (event.type == EnterNotify || event.type == LeaveNotify) { pimpl->mouseX = event.xcrossing.x; pimpl->mouseY = event.xcrossing.y; } } pimpl->eventList.clear(); }
void Gosu::Input::update() { for (unsigned int i = 0; i < pimpl->eventList.size(); i++) { ::XEvent event = pimpl->eventList[i]; if (textInput() && textInput()->feedXEvent(pimpl->display, &event)) continue; if (event.type == KeyPress) { unsigned id = event.xkey.keycode - 8; pimpl->keyMap[id] = true; if (onButtonDown) onButtonDown(Button(id)); } else if (event.type == KeyRelease) { if (i < pimpl->eventList.size() - 1) { ::XEvent nextEvent = pimpl->eventList[i + 1]; if (nextEvent.type == KeyPress && nextEvent.xkey.keycode == event.xkey.keycode) { i += 1; continue; } } unsigned id = event.xkey.keycode - 8; pimpl->keyMap[id] = false; if (onButtonUp) onButtonUp(Button(id)); } else if (event.type == ButtonPress) { unsigned id; switch (event.xbutton.button) { case Button1: id = msLeft; break; case Button2: id = msMiddle; break; case Button3: id = msRight; break; case Button4: id = msWheelUp; break; case Button5: id = msWheelDown; break; case 6: id = msOther0; break; case 7: id = msOther1; break; case 8: id = msOther2; break; case 9: id = msOther3; break; case 10: id = msOther4; break; case 11: id = msOther5; break; case 12: id = msOther6; break; case 13: id = msOther7; break; default: continue; } pimpl->keyMap[id] = true; if (onButtonDown) onButtonDown(Button(id)); } else if (event.type == ButtonRelease) { unsigned id; switch (event.xbutton.button) { case Button1: id = msLeft; break; case Button2: id = msMiddle; break; case Button3: id = msRight; break; case Button4: id = msWheelUp; break; case Button5: id = msWheelDown; break; case 6: id = msOther0; break; case 7: id = msOther1; break; case 8: id = msOther2; break; case 9: id = msOther3; break; case 10: id = msOther4; break; case 11: id = msOther5; break; case 12: id = msOther6; break; case 13: id = msOther7; break; default: continue; } pimpl->keyMap[id] = false; if (onButtonUp) onButtonUp(Button(id)); } else if (event.type == MotionNotify) { pimpl->mouseX = event.xbutton.x; pimpl->mouseY = event.xbutton.y; } else if (event.type == EnterNotify || event.type == LeaveNotify) { pimpl->mouseX = event.xcrossing.x; pimpl->mouseY = event.xcrossing.y; } } pimpl->eventList.clear(); }
LRESULT Gripper::runProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { create(); break; } case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: { onMove(); return TRUE; } case WM_LBUTTONUP: case WM_NCLBUTTONUP: { /* end hooking */ if (hookMouse) { ::UnhookWindowsHookEx(hookMouse); ::UnhookWindowsHookEx(hookKeyboard); hookMouse = NULL; hookKeyboard = NULL; } onButtonUp(); ::DestroyWindow(_hSelf); return TRUE; } case DMM_CANCEL_MOVE: { POINT pt = {0,0}; POINT ptBuf = {0,0}; ::GetCursorPos(&pt); getMousePoints(&pt, &ptBuf); /* erase last drawn rectangle */ drawRectangle(NULL); /* end hooking */ ::UnhookWindowsHookEx(hookMouse); ::UnhookWindowsHookEx(hookKeyboard); ::DestroyWindow(_hSelf); return FALSE; } case WM_DESTROY: { mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); ::SetWindowPos(_hParent, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); _pCont->focusClient(); delete this; break; } default: break; } return ::DefWindowProc(_hSelf, message, wParam, lParam); }
void app_event_loop() { bool isRunning=true; SDL_Event event; uint32_t lastTick; int32_t delay; int i; struct tm* now; printf("[DEBUG] Got app_event_loop\n"); while (isRunning) { lastTick=SDL_GetTicks (); SDL_PumpEvents (); while (SDL_PollEvent (&event)) { switch (event.type) { case(SDL_QUIT): { isRunning=false; } break; case(SDL_KEYDOWN): { switch (event.key.keysym.sym) { case(SDLK_ESCAPE): { isRunning=false; } break; case(SDLK_F1): { bodyID=(bodyID+1)%BODY_COUNT; bodyRender=true; } break; case(SDLK_F2): { shadow=!shadow; markDirty(true); bodyRender=true; } break; case(SDLK_F3): { toggle_24h_style(); if (clock_is_24h_style ()) SDL_WM_SetCaption("Pebble Local Simulator - 24H Style",0); else SDL_WM_SetCaption("Pebble Local Simulator - 12H Style",0); } break; case(SDLK_F4): { toggle_bluetooth_connection(); printf("[INFO] Toggle bluetooth %s\n", bluetooth_connection_service_peek() ? "ON":"OFF"); } break; case(SDLK_F5): { BatteryChargeState state; toggle_battery_charger_plugged(); state = battery_state_service_peek(); printf("[INFO] Toggle plugged: %d%%, %s charging, %s plugged\n", state.charge_percent, state.is_charging ? "":"not", state.is_plugged ? "":"not"); } break; case(SDLK_F12): { time_t timeSec=time(0); now=localtime(&timeSec); strftime (titleBuffer,strlen(titleBuffer),"./simdata/screenshots/%Y-%m-%e-%H-%M-%S",now); strcat(titleBuffer,".bmp"); if (SDL_SaveBMP(screen,titleBuffer)<0) printf("[WARN] SDL_SaveBMP: %s\n",SDL_GetError ()); else printf ("[INFO] Saved screenshot: %s\n",titleBuffer); } break; case(SDLK_PLUS): { BatteryChargeState state; battery_charge_increase(); state = battery_state_service_peek(); printf("[INFO] Battery state: %d%%, %s charging, %s plugged\n", state.charge_percent, state.is_charging ? "":"not", state.is_plugged ? "":"not"); } break; case(SDLK_MINUS): { BatteryChargeState state; battery_charge_decrease(); state = battery_state_service_peek(); printf("[INFO] Battery state: %d%%, %s charging, %s plugged\n", state.charge_percent, state.is_charging ? "":"not", state.is_plugged ? "":"not"); } break; case (SDLK_x): { int32_t direction=1; if(event.key.keysym.mod & KMOD_SHIFT) { direction=-1; } accel_do_tap_on_axis(ACCEL_AXIS_X, direction); printf("[INFO] Tap X %d\n", direction); } break; case (SDLK_y): { int32_t direction=1; if(event.key.keysym.mod & KMOD_SHIFT) { direction=-1; } accel_do_tap_on_axis(ACCEL_AXIS_Y, direction); printf("[INFO] Tap Y %d\n", direction); } break; case (SDLK_z): { int32_t direction=1; if(event.key.keysym.mod & KMOD_SHIFT) { direction=-1; } accel_do_tap_on_axis(ACCEL_AXIS_Z, direction); printf("[INFO] Tap Z %d\n", direction); } break; case (KEY_BUTTON_BACK): { buttonState[BUTTON_ID_BACK]=true; bodyRender=true; onButtonDown(BUTTON_ID_BACK); } break; case (KEY_BUTTON_UP): { buttonState[BUTTON_ID_UP]=true; bodyRender=true; onButtonDown(BUTTON_ID_UP); } break; case (KEY_BUTTON_SELECT): { buttonState[BUTTON_ID_SELECT]=true; bodyRender=true; onButtonDown(BUTTON_ID_SELECT); } break; case (KEY_BUTTON_DOWN): { buttonState[BUTTON_ID_DOWN]=true; bodyRender=true; onButtonDown(BUTTON_ID_DOWN); } break; default: ; } } break; case(SDL_KEYUP): { switch (event.key.keysym.sym) { case(KEY_BUTTON_BACK): { buttonState[BUTTON_ID_BACK]=false; bodyRender=true; onButtonUp(BUTTON_ID_BACK); } break; case(KEY_BUTTON_UP): { buttonState[BUTTON_ID_UP]=false; bodyRender=true; onButtonUp(BUTTON_ID_UP); } break; case(KEY_BUTTON_SELECT): { buttonState[BUTTON_ID_SELECT]=false; bodyRender=true; onButtonUp(BUTTON_ID_SELECT); } break; case(KEY_BUTTON_DOWN): { buttonState[BUTTON_ID_DOWN]=false; bodyRender=true; onButtonUp(BUTTON_ID_DOWN); } break; default: ; } } break; default: ; } } for (i=0;i<SIM_SERVICE_COUNT;i++) (serviceData.services[i]) (); if (lastVibeState!=getVibeState()) { bodyRender=true; lastVibeState=getVibeState(); } if (lastLightState!=getLightState()) { bodyRender=true; lastLightState=getLightState(); } if (render ()||bodyRender) simulatorRender (); delay=(SDL_GetTicks()-lastTick); elapsed=delay/1000.0f; delay=16-delay; //equals about 60 frames per second lastTick=SDL_GetTicks(); if (delay>0) SDL_Delay(delay); } }
bool InputHandlerOIS::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id) { onButtonUp(0, mouseButtonToButtonCode(id), arg.timestamp - mTimestampClockOffset); return true; }
bool InputHandlerOIS::keyReleased(const OIS::KeyEvent& arg) { onButtonUp(0, keyCodeToButtonCode(arg.key), arg.timestamp - mTimestampClockOffset); return true; }
void app_event_loop() { bool isRunning=true; SDL_Event event; uint32_t lastTick; int32_t delay; int i; struct tm* now; printf("[DEBUG] Got app_event_loop\n"); while (isRunning) { lastTick=SDL_GetTicks (); SDL_PumpEvents (); while (SDL_PollEvent (&event)) { switch (event.type) { case(SDL_QUIT): { isRunning=false; } break; case(SDL_KEYDOWN): { switch (event.key.keysym.sym) { case(SDLK_ESCAPE): { isRunning=false; } break; case(SDLK_F1): { bodyID=(bodyID+1)%BODY_COUNT; bodyRender=true; } break; case(SDLK_F2): { shadow=!shadow; markDirty(true); bodyRender=true; } break; case(SDLK_F3): { toggle_24h_style(); if (clock_is_24h_style ()) SDL_WM_SetCaption("Pebble Local Simulator - 24H Style",0); else SDL_WM_SetCaption("Pebble Local Simulator - 12H Style",0); } break; case(SDLK_F12): { time_t timeSec=time(0); now=localtime(&timeSec); strftime (titleBuffer,strlen(titleBuffer),"./simdata/screenshots/%Y-%m-%e-%H-%M-%S",now); strcat(titleBuffer,".bmp"); if (SDL_SaveBMP(screen,titleBuffer)<0) printf("[WARN] SDL_SaveBMP: %s\n",SDL_GetError ()); else printf ("[INFO] Saved screenshot: %s\n",titleBuffer); } break; case (KEY_BUTTON_BACK): { buttonState[BUTTON_ID_BACK]=true; bodyRender=true; onButtonDown(BUTTON_ID_BACK); } break; case (KEY_BUTTON_UP): { buttonState[BUTTON_ID_UP]=true; bodyRender=true; onButtonDown(BUTTON_ID_UP); } break; case (KEY_BUTTON_SELECT): { buttonState[BUTTON_ID_SELECT]=true; bodyRender=true; onButtonDown(BUTTON_ID_SELECT); } break; case (KEY_BUTTON_DOWN): { buttonState[BUTTON_ID_DOWN]=true; bodyRender=true; onButtonDown(BUTTON_ID_DOWN); } break; default: ; } } break; case(SDL_KEYUP): { switch (event.key.keysym.sym) { case(KEY_BUTTON_BACK): { buttonState[BUTTON_ID_BACK]=false; bodyRender=true; onButtonUp(BUTTON_ID_BACK); } break; case(KEY_BUTTON_UP): { buttonState[BUTTON_ID_UP]=false; bodyRender=true; onButtonUp(BUTTON_ID_UP); } break; case(KEY_BUTTON_SELECT): { buttonState[BUTTON_ID_SELECT]=false; bodyRender=true; onButtonUp(BUTTON_ID_SELECT); } break; case(KEY_BUTTON_DOWN): { buttonState[BUTTON_ID_DOWN]=false; bodyRender=true; onButtonUp(BUTTON_ID_DOWN); } break; default: ; } } break; default: ; } } for (i=0; i<SIM_SERVICE_COUNT; i++) (serviceData.services[i]) (); if (lastVibeState!=getVibeState()) { bodyRender=true; lastVibeState=getVibeState(); } if (lastLightState!=getLightState()) { bodyRender=true; lastLightState=getLightState(); } if (render ()||bodyRender) simulatorRender (); delay=(SDL_GetTicks()-lastTick); elapsed=delay/1000.0f; delay=16-delay; //equals about 60 frames per second lastTick=SDL_GetTicks(); if (delay>0) SDL_Delay(delay); } }