bool RenderWidget::event(QEvent* event) { switch (event->type()) { case QEvent::KeyPress: { QKeyEvent* ke = static_cast<QKeyEvent*>(event); if (ke->key() == Qt::Key_Escape) emit EscapePressed(); break; } case QEvent::WinIdChange: emit HandleChanged((void*)winId()); break; case QEvent::FocusIn: case QEvent::FocusOut: emit FocusChanged(hasFocus()); break; case QEvent::WindowStateChange: emit StateChanged(isFullScreen()); break; case QEvent::Close: emit Closed(); break; default: break; } return QWidget::event(event); }
void CShop::Draw() { // This draws the first menu to the player to have them select if they // want to buy or sell items. First, draw menu and it's buy/sell buttons DrawBox(kShopPromptWidth, kShopPromptHeight, kMenuX, kMenuY); DrawString("Buy", 3, kMenuX + kTileWidth, kMenuY + kTileWidth-3, NULL, ShowBuyMenu); DrawString("Sell", 4, kMenuX + kTileWidth*3, kMenuY + kTileWidth-3, NULL, ShowSellMenu); // Swap the buffers to display the change g_Buffer.SwapBackBuffer(FALSE); // Loop until the user escapes or clicks on one of the buttons while(!EscapePressed() && !ChoiceMade()) { HandleInput(); } // Reset the flag that says we hit escape and redraw the map ResetEscapeFlag(); g_Map.SetDrawFlag(true); g_Map.Draw(); g_Buffer.SwapBackBuffer(FALSE); // If there was a button clicked, let's go to it's associated function if(ChoiceMade()) ChoiceMade()->m_function(); // More pausing for feeling :) Sleep(100); }
//============================================================================= // as usual our main function ... //============================================================================= void _main(void) { LCD_BUFFER lcd; LCD_BUFFER doublebuffer; short i; short ball_to_update; INT_HANDLER oldint1 = GetIntVec(AUTO_INT_1); // fetch default interrupt handler INT_HANDLER oldint5 = GetIntVec(AUTO_INT_5); // fetch default interrupt handler // save screen LCD_save(lcd); // install dummy interrupt handlers for AUTO_INT1 and AUTO_INT5 SetIntVec(AUTO_INT_1,DUMMY_HANDLER); SetIntVec(AUTO_INT_5,DUMMY_HANDLER); do { // clear doublebuffer memset(doublebuffer,0,LCD_SIZE); for (i=0;i<NR_BALLS;i++) { // NOTE: DRAWSPRITE is a macro defined at the beginning of this file! DRAWSPRITE(balls[i].x,balls[i].y); } // copy double buffer to visible screen FastCopyScreen_R(doublebuffer,LCD_MEM); for (ball_to_update=0;ball_to_update<NR_BALLS;ball_to_update++) { // calculate new position of ball which should get updated CalcNewPosition(&balls[ball_to_update],max_x,max_y); // loop over all possible combinations and check for collision ... for (i=0;i<NR_BALLS;i++) { if (i==ball_to_update) continue; // don't check against myself // NOTE: TESTCOLLIDE is a macro defined at the beginning of this file! if (TESTCOLLIDE(balls[ball_to_update].newx,balls[ball_to_update].newy,balls[i].newx,balls[i].newy)) { // collision detected -> exchange dirx/diry of involved balls ExchangeDirections(&balls[ball_to_update],&balls[i]); // recalculate new position of ball which should get updated CalcNewPosition(&balls[ball_to_update],max_x,max_y); // if we still stick together than this opponent then this // is not the right target to change my direction ... if (TESTCOLLIDE(balls[ball_to_update].newx,balls[ball_to_update].newy,balls[i].newx,balls[i].newy)) { ExchangeDirections(&balls[ball_to_update],&balls[i]); CalcNewPosition(&balls[ball_to_update],max_x,max_y); } } } // NOTE: this demo is somewhat sloppy. Normally we should not // proceed if a collision is detected AND we shouldn't do the // VERY simple collision detection routine above. // But I don't care about this. It seems to be good enough // to demonstrate the bouncing balls ... balls[ball_to_update].x = balls[ball_to_update].newx; balls[ball_to_update].y = balls[ball_to_update].newy; } } while (!EscapePressed()); // restore old interrupt handlers SetIntVec(AUTO_INT_1,oldint1); SetIntVec(AUTO_INT_5,oldint5); // restore screen LCD_restore(lcd); // empty the keyboard buffer and write "powered by ..." string GKeyFlush(); ST_helpMsg(EXTGRAPH_VERSION_PWDSTR); }
bool RenderWidget::event(QEvent* event) { PassEventToImGui(event); switch (event->type()) { case QEvent::Paint: return !autoFillBackground(); case QEvent::KeyPress: { QKeyEvent* ke = static_cast<QKeyEvent*>(event); if (ke->key() == Qt::Key_Escape) emit EscapePressed(); // The render window might flicker on some platforms because Qt tries to change focus to a new // element when there is none (?) Handling this event before it reaches QWidget fixes the issue. if (ke->key() == Qt::Key_Tab) return true; break; } case QEvent::MouseMove: if (g_Config.bFreeLook) OnFreeLookMouseMove(static_cast<QMouseEvent*>(event)); // [[fallthrough]] case QEvent::MouseButtonPress: if (!Settings::Instance().GetHideCursor() && isActiveWindow()) { setCursor(Qt::ArrowCursor); m_mouse_timer->start(MOUSE_HIDE_DELAY); } break; case QEvent::WinIdChange: emit HandleChanged(reinterpret_cast<void*>(winId())); break; case QEvent::WindowActivate: if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::State::Paused) Core::SetState(Core::State::Running); emit FocusChanged(true); break; case QEvent::WindowDeactivate: if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::State::Running) Core::SetState(Core::State::Paused); emit FocusChanged(false); break; case QEvent::Resize: { const QResizeEvent* se = static_cast<QResizeEvent*>(event); QSize new_size = se->size(); auto* desktop = QApplication::desktop(); int screen_nr = desktop->screenNumber(this); if (screen_nr == -1) screen_nr = desktop->screenNumber(parentWidget()); const auto dpr = desktop->screen(screen_nr)->devicePixelRatio(); emit SizeChanged(new_size.width() * dpr, new_size.height() * dpr); break; } case QEvent::WindowStateChange: emit StateChanged(isFullScreen()); break; case QEvent::Close: emit Closed(); break; default: break; } return QWidget::event(event); }