void InputHandler::update() { SDL_Event event; m_keyStates = SDL_GetKeyboardState(0); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: // se o usuário saiu da aplicação TheGame::Instance()->quit(); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
LRESULT Window::wndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: { if (onCreate()) break; return 0; } case WM_DESTROY: { if (onDestroy()) break; return 0; } case WM_CLOSE: { if (onClose()) break; return 0; } case WM_MOUSEMOVE: { if (onMouseMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) break; return 0; } case WM_LBUTTONDOWN: { if (onMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0)) break; return 0; } case WM_RBUTTONDOWN: { if (onMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 1)) break; return 0; } case WM_MBUTTONDOWN: { if (onMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 2)) break; return 0; } case WM_LBUTTONUP: { if (onMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0)) break; return 0; } case WM_RBUTTONUP: { if (onMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 1)) break; return 0; } case WM_MBUTTONUP: { if (onMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 2)) break; return 0; } case WM_PAINT: { if (onPaint()) break; return 0; } case WM_SIZE: { if (onSizeChanged()) break; return 0; } case WM_KEYDOWN: { if (onKeyDown((UINT)wParam)) break; return 0; } case WM_KEYUP: { if (onKeyUp((UINT)wParam)) break; return 0; } case WM_COMMAND: { if (SendMessage(reinterpret_cast<HWND>(lParam), WM_COMMAND_REFLECT, wParam, lParam)) break; return 0; } } if (mBaseWndProc != sGlobalWndProc) { LRESULT r = CallWindowProc(mBaseWndProc, mHWND, uMsg, wParam, lParam); return r; } else { LRESULT r = DefWindowProc(mHWND, uMsg, wParam, lParam); return r; } }
LRESULT Win32Window::wndProc(UINT msg, WPARAM wParam, LPARAM lParam) { if(msg == WM_CLOSE) { PostQuitMessage(0); } switch(msg) { case WM_SIZE: onResize(ResizeEvent(LOWORD(lParam), HIWORD(lParam))); break; case WM_KEYDOWN: onKeyDown(KeyEvent(wParam)); break; case WM_KEYUP: onKeyUp(KeyEvent(wParam)); break; case WM_MOUSEMOVE: POINTS pt = MAKEPOINTS(lParam); break; } return DefWindowProc(hwnd, msg, wParam, lParam); }
void InputSystem::handleEvent(Event *event) { switch(event->getType()) { case Event::KeyUp: onKeyUp(static_cast<KeyEvent*> (event)); break; case Event::KeyDown: onKeyDown(static_cast<KeyEvent*> (event)); break; case Event::MouseLeave: mouseControl = false; { Player *player = game->getPlayer(); if(player) { Vector2 velocity = player->getVelocity(); velocity.x = 0.0f; player->setVelocity(velocity); } } break; case Event::MouseMove: onMouseMove(static_cast<MouseMoveEvent*> (event)); break; default: // Do nothing break; } }
void InputHandler::update() { SDL_Event evt; onMouseButtonUp(); while (SDL_PollEvent(&evt)) { switch (evt.type) { case SDL_QUIT: TheGame::Instance()->quit(); break; case SDL_MOUSEMOTION: onMouseMove(evt); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(evt); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
/** * @brief FilterWidget::FilterWidget * @param parent */ FilterWidget::FilterWidget(QWidget *parent) : QWidget(parent), ui(new Ui::FilterWidget) { ui->setupUi(this); ui->lineEdit->setShowMagnifier(true); ui->lineEdit->addAdditionalStyleSheet("QLineEdit { border: 1px solid rgba(0, 0, 0, 100); border-radius: 10px; }"); ui->lineEdit->setType(MyLineEdit::TypeClear); ui->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); m_list = new QListWidget(); m_list->setWindowFlags(Qt::WindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)); m_list->setAttribute(Qt::WA_ShowWithoutActivating); m_activeWidget = WidgetMovies; QPalette palette = m_list->palette(); palette.setColor(QPalette::Highlight, palette.color(QPalette::Highlight)); palette.setColor(QPalette::HighlightedText, palette.color(QPalette::HighlightedText)); m_list->setPalette(palette); m_list->setStyleSheet(QString("background-color: transparent; border: 1px solid rgba(255, 255, 255, 200); border-radius: 5px;")); m_list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); connect(ui->lineEdit, SIGNAL(textEdited(QString)), this, SLOT(onFilterTextChanged(QString))); connect(ui->lineEdit, SIGNAL(keyDown()), this, SLOT(onKeyDown())); connect(ui->lineEdit, SIGNAL(keyUp()), this, SLOT(onKeyUp())); connect(ui->lineEdit, SIGNAL(focusOut()), m_list, SLOT(hide())); connect(ui->lineEdit, SIGNAL(focusIn()), this, SLOT(setupFilters())); connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(addSelectedFilter())); connect(ui->lineEdit, SIGNAL(backspaceInFront()), this, SLOT(removeLastFilter())); connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(addFilterFromItem(QListWidgetItem*))); initFilters(); }
// Simple main loop void mainLoop() { // Window is not minimized bool active = true; for(;;)// Infinite loop { SDL_Event event; // Wait for event if(SDL_WaitEvent(&event) == 0) throw SDL_Exception(); // Screen needs redraw bool redraw = false; // Handle all waiting events do { camera += cam_velocity; // Call proper event handlers switch(event.type) { case SDL_ACTIVEEVENT : // Stop redraw when minimized if(event.active.state == SDL_APPACTIVE) active = event.active.gain; break; case SDL_KEYDOWN : onKeyDown(event.key.keysym.sym, event.key.keysym.mod); break; case SDL_KEYUP : onKeyUp(event.key.keysym.sym, event.key.keysym.mod); break; case SDL_MOUSEMOTION : onMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, event.motion.state); break; case SDL_MOUSEBUTTONDOWN : onMouseDown(event.button.button, event.button.x, event.button.y); break; case SDL_MOUSEBUTTONUP : onMouseUp(event.button.button, event.button.x, event.button.y); break; case SDL_QUIT : return; // End main loop case SDL_VIDEORESIZE : onWindowResized(event.resize.w, event.resize.h); break; case SDL_VIDEOEXPOSE : redraw = true; break; default : // Do nothing break; } } while(SDL_PollEvent(&event) == 1); // Optionally redraw window if(active && redraw) onWindowRedraw(); } }
void JoltApp::onEvent(SDL_Event* evt) { //JoltConsole::logInfo("Event", "Caught event code %i",evt->type); if(evt->type == SDL_QUIT) { running = false; //We're outta here! } else if(evt->type == SDL_KEYDOWN) { onKeyDown(evt->key.keysym.sym,evt->key.keysym.mod,evt->key.keysym.unicode); } else if(evt->type == SDL_KEYUP) { onKeyUp(evt->key.keysym.sym,evt->key.keysym.mod,evt->key.keysym.unicode); } }
void InputHandler::update() { //SDL_Event event; if (event.type != SDL_MOUSEMOTION) { MouseMoved = false; } while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: TheGame::Instance()->quit(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(event); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(event); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(event); break; case SDL_MOUSEMOTION: MouseMoved = true; onMouseMove(event); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(event); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(event); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
TEST_F(KeyBehaviorTest, FromOneKeyToAnother) { auto behavior = std::make_shared<MockKeyBehavior>("Behavior"); EXPECT_CALL(*behavior, onKeyDown(Devices::KEY_A)); EXPECT_CALL(*behavior, onKeyDown(Devices::KEY_B)); EXPECT_CALL(*behavior, onKeyUp(Devices::KEY_A)); EXPECT_CALL(*behavior, onKeyUp(Devices::KEY_B)); behavior->setInputComponent(inputComponent); element->addComponent(behavior); data.integers().set(DataStructures::Names::KEY, Devices::KeyCode::KEY_A); inputComponent->setData(data); behavior->update(0.0); data.integers().set(DataStructures::Names::KEY, Devices::KeyCode::KEY_B); inputComponent->setData(data); behavior->update(0.0); data.integers().set(DataStructures::Names::KEY, Devices::KeyCode::NONE); inputComponent->setData(data); behavior->update(0.0); // Shouldn't trigger another KeyUp .. behavior->update(0.0); }
int _tmain(int argc, _TCHAR* argv[]) { if (!init()) { printf("Failed to initialize!\n"); return 0; } bool quit = false; while (!quit) { SDL_Event e; while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } else if (e.type == SDL_MOUSEBUTTONDOWN) { onMouseDown(e.button); } else if (e.type == SDL_MOUSEBUTTONUP) { onMouseUp(e.button); } else if (e.type == SDL_KEYDOWN) { OnKeyDown(e.key); } else if (e.type == SDL_KEYUP) { onKeyUp(e.key); } else if (e.type == SDL_WINDOWEVENT) { onWindowEvent(e.window); } } // Render render(); // Update screen SDL_GL_SwapWindow(gWindow); } // Free resources and close SDL close(); return 0; }
void InputHandler::update() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: Game::getInstance()->clean(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(event); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(event); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(event); break; case SDL_MOUSEMOTION: onMouseMove(event); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(event); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(event); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
void ManejadorEntrada::actualizar() { SDL_Event evento; while(SDL_PollEvent(&evento)) { switch (evento.type) { case SDL_QUIT: ElJuego::Instancia()->salir(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(evento); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(evento); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(evento); break; case SDL_MOUSEMOTION: onMouseMove(evento); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(evento); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(evento); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
void CPP_Input::setImpl(std::unique_ptr<CPP_InputImplIF> _impl) { impl = std::move(_impl); if (impl) { impl->registerOnKeyDown([this](const CPP_Key key) { onKeyDown(key); }); impl->registerOnKeyUp([this](const CPP_Key key) { onKeyUp(key); }); } }
void Game::handleEvent( const SDL_Event& e ) { switch( e.type ) { case SDL_QUIT: running_ = false; break; case SDL_KEYDOWN: onKeyDown( e.key.keysym.sym ); break; case SDL_KEYUP: onKeyUp( e.key.keysym.sym ); break; case SDL_MOUSEBUTTONDOWN: int x, y; SDL_GetMouseState( &x, &y ); onMouseDown( Vec2( x, y ) ); break; } }
bool geGUIBase::KeyUp(int charValue, int flag) { if(m_uGUIID==GEGUI_LAYOUT && getActiveWindowPtrOnlyForLayout()) //layout hack { if(getActiveWindowPtrOnlyForLayout()->KeyUp(charValue, flag)) return true; } else { for(std::vector<geGUIBase*>::iterator it = m_vControls.begin(); it != m_vControls.end(); ++it) { geGUIBase* obj = *it; if(obj->KeyUp(charValue, flag)) return true; } } return onKeyUp(charValue, flag); }
void InputHandler::update() { SDL_Event event; m_keyStates = (Uint8*)SDL_GetKeyboardState(0); while(SDL_PollEvent(&event)){ switch (event.type) { case SDL_QUIT: TheGame::Instance() -> quit(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(event); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(event); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(event); break; case SDL_MOUSEMOTION: onMouseMove(event); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(event); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(event); break; case SDL_KEYDOWN: onKeyDown(event.key.keysym.scancode); break; case SDL_KEYUP: onKeyUp(event.key.keysym.scancode); break; default: break; } } }
bool UIWidget::propagateOnKeyUp(uchar keyCode, int keyboardModifiers) { // do a backup of children list, because it may change while looping it UIWidgetList children; for(const UIWidgetPtr& child : m_children) { // events on hidden or disabled widgets are discarded if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible()) continue; // key events go only to focused child if(child->isFocused()) children.push_back(child); } for(const UIWidgetPtr& child : children) { if(child->propagateOnKeyUp(keyCode, keyboardModifiers)) return true; } return onKeyUp(keyCode, keyboardModifiers); }
void Module::onEvent(const SDL_Event & event) { switch(event.type) { case SDL_KEYDOWN: onKeyDown(event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.unicode); break; case SDL_KEYUP: onKeyUp(event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.unicode); break; case SDL_MOUSEMOTION: onMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, event.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT), event.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT), event.motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)); break; case SDL_JOYAXISMOTION: onJoyAxis(event.jaxis.which, event.jaxis.axis, event.jaxis.value); break; case SDL_JOYBALLMOTION: onJoyBall(event.jball.which, event.jball.ball, event.jball.xrel, event.jball.yrel); break; case SDL_JOYHATMOTION: onJoyHat(event.jhat.which, event.jhat.hat, event.jhat.value); break; case SDL_JOYBUTTONDOWN: onJoyButtonDown(event.jbutton.which, event.jbutton.button); break; case SDL_JOYBUTTONUP: onJoyButtonUp(event.jbutton.which, event.jbutton.button); break; case SDL_VIDEORESIZE: onResize(event.resize.w, event.resize.h); break; //case ... default: break; } }
void CButton::run() { CTimeout bounce; while(1) { if ( bit_chk(m_flag, KEY_FLAG_DOWN) ) { if ( m_pin==HIGH ){ if ( bounce.isExpired(10) ) { bit_clr(m_flag, KEY_FLAG_DOWN); onKeyUp(); // call virtual function "onKeyUp()" } } else { bounce.reset(); } } else { if ( m_pin==LOW ){ if ( bounce.isExpired(5) ) { bit_set(m_flag, KEY_FLAG_DOWN); onKeyDown(); // call virtual function "onKeyDown()" } } else { bounce.reset(); } } } }
void CButtons::run() { CTimeout tm; uint32_t newval; while(1) { newval = m_pins; if ( newval != m_flag ) { if ( tm.isExpired(10) ) { // wait for bounce time m_down = newval; for (int i=0; i<m_pins.count(); i++) { if ( bit_chk((m_flag ^ newval), i) ) { // is different? Key Even caused... if ( bit_chk(newval, i) ) { // HIGH is key up onKeyUp(i); } else { // LOW is key down onKeyDown(i); } } } m_flag = newval; } } else { tm.reset(); } } }
void Event::onEvent(SDL_Event *event) { switch (event->type) { case SDL_ACTIVEEVENT: switch (event->active.state) { case SDL_APPMOUSEFOCUS: if (event->active.gain) { onMouseFocus(); } else { onMouseBlur(); } break; case SDL_APPINPUTFOCUS: if (event->active.gain) { onInputFocus(); } else { onInputBlur(); } break; case SDL_APPACTIVE: if (event->active.gain) { onRestore(); } else { onMinimize(); } break; } break; //SDL_ACTIVEEVENT case SDL_KEYDOWN: onKeyDown(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; case SDL_KEYUP: onKeyUp(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; case SDL_MOUSEBUTTONDOWN: onMouseDown(event->button.button, event->button.x, event->button.y); break; case SDL_MOUSEBUTTONUP: onMouseUp(event->button.button, event->button.x, event->button.y); break; case SDL_JOYAXISMOTION: onJoyAxis(event->jaxis.which, event->jaxis.axis, event->jaxis.value); break; case SDL_JOYBALLMOTION: onJoyBall(event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel); break; case SDL_JOYHATMOTION: onJoyHat(event->jhat.which, event->jhat.hat, event->jhat.value); break; case SDL_JOYBUTTONDOWN: onJoyButtonDown(event->jbutton.which, event->jbutton.button); break; case SDL_JOYBUTTONUP: onJoyButtonUp(event->jbutton.which, event->jbutton.button); break; case SDL_QUIT: onQuit(); break; case SDL_VIDEORESIZE: onResize(event->resize.w, event->resize.h); break; default: onUser(event->user.type, event->user.code, event->user.data1, event->user.data2); break; } }
//METHODS void Event::onEvent(SDL_Event* event) { switch(event->type) { case SDL_ACTIVEEVENT: { switch (event->active.state) { case SDL_APPMOUSEFOCUS: { if (event->active.gain) onMouseFocus(); else onMouseBlur(); break; } case SDL_APPINPUTFOCUS: { if (event->active.gain) onInputFocus(); else onInputBlur(); break; } case SDL_APPACTIVE: { if (event->active.gain) onRestore(); else onMinimize(); break; } } break; } case SDL_KEYDOWN: { onKeyDown(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; } case SDL_KEYUP: { onKeyUp(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; } case SDL_MOUSEMOTION: { onMouseMove(event->motion.x, event->motion.y, event->motion.xrel, event->motion.yrel, (event->motion.state & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0, (event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0, (event->motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0); break; } case SDL_MOUSEBUTTONDOWN: { switch(event->button.button) { case SDL_BUTTON_LEFT: { onLButtonDown(event->button.x, event->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonDown(event->button.x, event->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonDown(event->button.x, event->button.y); break; } } break; } case SDL_MOUSEBUTTONUP: { switch(event->button.button) { case SDL_BUTTON_LEFT: { onLButtonUp(event->button.x, event->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonUp(event->button.x, event->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonUp(event->button.x, event->button.y); break; } } break; } case SDL_JOYAXISMOTION: { onJoyAxis(event->jaxis.which, event->jaxis.axis, event->jaxis.value); break; } case SDL_JOYBALLMOTION: { onJoyBall(event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel); break; } case SDL_JOYHATMOTION: { onJoyHat(event->jhat.which, event->jhat.hat, event->jhat.value); break; } case SDL_JOYBUTTONDOWN: { onJoyButtonDown(event->jbutton.which, event->jbutton.button); break; } case SDL_JOYBUTTONUP: { onJoyButtonUp(event->jbutton.which, event->jbutton.button); break; } case SDL_QUIT: { onExit(); break; } case SDL_SYSWMEVENT: { //Ignore break; } case SDL_VIDEORESIZE: { onResize(event->resize.w, event->resize.h); break; } case SDL_VIDEOEXPOSE: { onExpose(); break; } default: { onUser(event->user.type, event->user.code, event->user.data1, event->user.data2); break; } } }
// Animation main loop // period - maximum time between redraws in ms void mainLoop(unsigned period) { // This main loop requires timer support if(SDL_InitSubSystem(SDL_INIT_TIMER) < 0) throw SDL_Exception(); // Create redraw timer class RedrawTimer { private : SDL_TimerID id; static Uint32 callback(Uint32 interval, void *) { redraw(); return interval; } public : RedrawTimer(unsigned interval) : id(SDL_AddTimer(interval, callback, NULL)) { if(id == NULL) throw SDL_Exception(); } ~RedrawTimer() { if(id != NULL) SDL_RemoveTimer(id); } } redrawTimer(period); // Window is not minimized bool active = true; for(;;)// Infinite loop { SDL_Event event; // Wait for event if(SDL_WaitEvent(&event) == 0) throw SDL_Exception(); // Screen needs redraw bool redraw = false; // Handle all waiting events do { // Call proper event handlers switch(event.type) { case SDL_ACTIVEEVENT :// Stop redraw when minimized if(event.active.state == SDL_APPACTIVE) active = event.active.gain; break; case SDL_KEYDOWN : onKeyDown(event.key.keysym.sym, event.key.keysym.mod); break; case SDL_KEYUP : onKeyUp(event.key.keysym.sym, event.key.keysym.mod); break; case SDL_MOUSEMOTION : onMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, event.motion.state); break; case SDL_MOUSEBUTTONDOWN : onMouseDown(event.button.button, event.button.x, event.button.y); break; case SDL_MOUSEBUTTONUP : onMouseUp(event.button.button, event.button.x, event.button.y); break; case SDL_QUIT : return;// End main loop case SDL_VIDEORESIZE : onWindowResized(event.resize.w, event.resize.h); break; case SDL_VIDEOEXPOSE : redraw = true; break; default :// Do nothing break; } } while(SDL_PollEvent(&event) == 1); // Optionally redraw window if(active && redraw) onWindowRedraw(); } }
void callHandlersOnKeyUp(const Keyboard& k){ CALL(onKeyUp(k)); }
/// event handlers void Module::onEvent(const SDL_Event& inEvent) { switch (inEvent.type) { case SDL_ACTIVEEVENT: { switch (inEvent.active.state) { case SDL_APPMOUSEFOCUS: { if (inEvent.active.gain) onMouseFocus(); else onMouseBlur(); break; } case SDL_APPINPUTFOCUS: { if (inEvent.active.gain) onInputFocus(); else onInputBlur(); break; } case SDL_APPACTIVE: { if (inEvent.active.gain) onRestore(); else onMinimize(); break; } } break; } case SDL_KEYDOWN: { onKeyDown(inEvent.key.keysym.sym, inEvent.key.keysym.mod, inEvent.key.keysym.unicode); break; } case SDL_KEYUP: { onKeyUp(inEvent.key.keysym.sym, inEvent.key.keysym.mod, inEvent.key.keysym.unicode); break; } case SDL_MOUSEMOTION: { onMouseMove(inEvent.motion.x, inEvent.motion.y, inEvent.motion.xrel, inEvent.motion.yrel, inEvent.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT), inEvent.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT), inEvent.motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)); break; } case SDL_MOUSEBUTTONDOWN: { switch (inEvent.button.button) { case SDL_BUTTON_LEFT: { onLButtonDown(inEvent.button.x, inEvent.button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonDown(inEvent.button.x, inEvent.button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonDown(inEvent.button.x, inEvent.button.y); break; } } break; } case SDL_MOUSEBUTTONUP: { switch (inEvent.button.button) { case SDL_BUTTON_LEFT: { onLButtonUp(inEvent.button.x, inEvent.button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonUp(inEvent.button.x, inEvent.button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonUp(inEvent.button.x, inEvent.button.y); break; } case SDL_BUTTON_WHEELUP: { onMouseWheel(true, false); break; } case SDL_BUTTON_WHEELDOWN: { onMouseWheel(false, true); break; } } break; } case SDL_JOYAXISMOTION: { onJoyAxis(inEvent.jaxis.which, inEvent.jaxis.axis, inEvent.jaxis.value); break; } case SDL_JOYBALLMOTION: { onJoyBall(inEvent.jball.which, inEvent.jball.ball, inEvent.jball.xrel, inEvent.jball.yrel); break; } case SDL_JOYHATMOTION: { onJoyHat(inEvent.jhat.which, inEvent.jhat.hat, inEvent.jhat.value); break; } case SDL_JOYBUTTONDOWN: { onJoyButtonDown(inEvent.jbutton.which, inEvent.jbutton.button); break; } case SDL_JOYBUTTONUP: { onJoyButtonUp(inEvent.jbutton.which, inEvent.jbutton.button); break; } case SDL_QUIT: { onExit(); break; } case SDL_SYSWMEVENT: { break; } case SDL_VIDEORESIZE: { onResize(inEvent.resize.w, inEvent.resize.h); break; } case SDL_VIDEOEXPOSE: { onExpose(); break; } default: { onUser(inEvent.user.type, inEvent.user.code, inEvent.user.data1, inEvent.user.data2); break; } } }
//----------------------------------------------------------------------------- bool CFrame::platformOnKeyUp (VstKeyCode& keyCode) { CollectInvalidRects cir (this); return onKeyUp (keyCode) == 1; }
// --------------------------------------------------------------------- LRESULT WinSkinWindow::wndProc( HWND hWnd, // ウィンドウハンドル UINT uMsg, // メッセージ WPARAM wParam, // メッセージの WPARAM LPARAM lParam // メッセージの LPARAM ) { LRESULT ret = 0; bool isProcessed = false; if (uiManager != NULL) { WinCCSAppearance* appearance = static_cast<WinCCSAppearance*>(uiManager->GetSkinAppearance()); if (appearance != NULL) { isProcessed = appearance->RelayWndProc(hWnd, uMsg, wParam, lParam, &ret); } } mousePositionAvailable = false; try { // ツールチップウィンドウへのリレー switch (uMsg) { case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MOUSEMOVE: case WM_RBUTTONDOWN: case WM_RBUTTONUP: { DWORD posVal; MSG msg; posVal = GetMessagePos(); msg.hwnd = hWnd; msg.message = uMsg; msg.wParam = wParam; msg.lParam = lParam; msg.time = GetMessageTime(); msg.pt.x = LOWORD(posVal); msg.pt.y = HIWORD(posVal); ::SendMessage(hToolTipWnd, TTM_RELAYEVENT, 0, reinterpret_cast<LPARAM>(&msg)); } break; } // 各メッセージのハンドリング switch (uMsg) { case WM_CREATE: return onCreate(hWnd, uMsg, wParam, lParam); break; case WM_DESTROY: return onDestroy(hWnd, uMsg, wParam, lParam); break; case WM_MOUSEMOVE: return onMouseMove(hWnd, uMsg, wParam, lParam); break; case WM_LBUTTONDOWN: return onLButtonDown(hWnd, uMsg, wParam, lParam); break; case WM_LBUTTONUP: return onLButtonUp(hWnd, uMsg, wParam, lParam); break; case WM_RBUTTONDOWN: return onRButtonDown(hWnd, uMsg, wParam, lParam); break; case WM_RBUTTONUP: return onRButtonUp(hWnd, uMsg, wParam, lParam); break; case WM_ACTIVATE: return onActivate(hWnd, uMsg, wParam, lParam); break; case UM_ACTIVATED: return onUMActivated(hWnd, uMsg, wParam, lParam); break; case WM_KEYUP: case WM_SYSKEYUP: return onKeyUp(hWnd, uMsg, wParam, lParam); break; case WM_TIMER: return onTimer(hWnd, uMsg, wParam, lParam); break; case UM_REREAD_SKIN: return onRereadSkin(hWnd, uMsg, wParam, lParam); break; case WM_COMMAND: return onCommand(hWnd, uMsg, wParam, lParam); break; default: if (isProcessed) { return ret; } else { return base::wndProc(hWnd, uMsg, wParam, lParam); } } } catch (Exception* ex) { ExceptionMessageUtils::DoExceptionMessageBox(CoveredCalcApp::GetInstance(), ex); ex->Delete(); } return 0; }
bool BaseAppInput::processEvent(SDL_Event* evt) { switch (evt->type) { case SDL_ACTIVEEVENT: { switch (evt->active.state) { case SDL_APPMOUSEFOCUS: { if (evt->active.gain) { //TODO handle mouse focus } else { //TODO handle mouse blur } break; } case SDL_APPINPUTFOCUS: { if (evt->active.gain) { //TODO handle input focus } else { //TODO handle input blur } break; } case SDL_APPACTIVE: { if (evt->active.gain) { //TODO handle restore event } else { //TODO handle minimize event } break; } } break; } case SDL_KEYDOWN: { return onKeyDown(evt->key.keysym.sym, evt->key.keysym.mod, evt->key.keysym.unicode); break; } case SDL_KEYUP: { return onKeyUp(evt->key.keysym.sym, evt->key.keysym.mod, evt->key.keysym.unicode); break; } } return true; }
void Element::handleQueuedEvent(std::shared_ptr<Events::Event> event) { switch(event->getEventType()) { case Events::EventType::MOUSE_CURSOR: { auto casted_event = std::static_pointer_cast<Input::MouseCursorEvent>(event); if(cursor_within == false && isActive() && isPointWithin(casted_event->getPosition())) { cursor_within = true; onCursorEnter(); } else if(cursor_within == true && isActive() && !isPointWithin(casted_event->getPosition())) { cursor_within = false; onCursorLeave(); } break; } case Events::EventType::MOUSE_SCROLL: { auto casted_event = std::static_pointer_cast<Input::MouseScrollEvent>(event); auto change = last_mouse_scroll_position - casted_event->getPosition(); last_mouse_scroll_position = casted_event->getPosition(); onScroll(change); break; } case Events::EventType::MOUSE_BUTTON_DOWN: { auto casted_event = std::static_pointer_cast<Input::MouseButtonDownEvent>(event); if(cursor_within && isActive() && casted_event->getButton() == GLFW_MOUSE_BUTTON_LEFT) { onLeftClick(); } else if(cursor_within && isActive() && casted_event->getButton() == GLFW_MOUSE_BUTTON_RIGHT) onRightClick(); break; } case Events::EventType::MOUSE_BUTTON_UP: { auto casted_event = std::static_pointer_cast<Input::MouseButtonUpEvent>(event); if(cursor_within && isActive() && casted_event->getButton() == GLFW_MOUSE_BUTTON_LEFT) onLeftClickRelease(); else if(cursor_within && isActive() && casted_event->getButton() == GLFW_MOUSE_BUTTON_RIGHT) onRightClickRelease(); break; } case Events::EventType::KEY_DOWN: { auto casted_event = std::static_pointer_cast<Input::KeyDownEvent>(event); onKeyDown(casted_event->getKey()); break; } case Events::EventType::KEY_UP: { auto casted_event = std::static_pointer_cast<Input::KeyUpEvent>(event); onKeyUp(casted_event->getKey()); break; } case Events::EventType::KEY_REPEAT: { auto casted_event = std::static_pointer_cast<Input::KeyRepeatEvent>(event); onKeyRepeat(casted_event->getKey()); break; } default: { Renderable::handleQueuedEvent(event); break; } } }