void CGameGUIList::OnMouseDown(int nButton,double x,double y) { CGameWindowBase::OnMouseDown(nButton,x,y); SGamePos pos(x,y); if(m_nVisibleCount<(int)m_vElements.size() && x>=m_rScroll.x) { if(m_rScrollUp.Contains(pos)){SelectPrevious();} else if(m_rScrollDown.Contains(pos)){SelectNext();} else if(m_rScrollThumb.Contains(pos)) { if(DetectDrag(x,y)) { m_piGUIManager->SetMouseCapture(this); m_ptScrollThumbDragStart=pos; m_nScrollThumbDragStartFirstVisible=m_nFirstVisible; } } else if(m_rScroll.Contains(pos)) { if(y<m_rScrollThumb.y){SelectNextPage();} else if(y>(m_rScrollThumb.y+m_rScrollThumb.h)){SelectPreviousPage();} } } else { m_nSelectedElement=m_nFirstVisible+(int)((m_rRealRect.h-y)/m_dFontPixelHeight); if(m_nSelectedElement<0){m_nSelectedElement=-1;} if(m_nSelectedElement>=(int)m_vElements.size()){m_nSelectedElement=-1;} std::string sElement=(m_nSelectedElement!=-1)?m_vElements[m_nSelectedElement]:""; NOTIFY_EVENT(IGameGUIListEvents,OnSelectionChanged(this,m_nSelectedElement,sElement)); } }
bool ButtonPanel::KeyPress(unsigned key_code) { assert(key_code != 0); const unsigned n = buttons.size(); for (unsigned i = 0; i < n; ++i) { if (keys[i] == key_code) { buttons[i]->Click(); return true; } } if (selected_index >= 0 && !HasPointer()) { if (key_code == KEY_LEFT) { SelectPrevious(); return true; } else if (key_code == KEY_RIGHT) { SelectNext(); return true; } else if (key_code == KEY_RETURN) { auto &button = *buttons[selected_index]; if (button.IsVisible() && button.IsEnabled()) button.Click(); } } return false; }
void CGameGUIList::OnKeyDown(int nKey,bool *pbProcessed) { CGameWindowBase::OnKeyDown(nKey,pbProcessed); if(nKey==GK_UP){SelectPrevious();*pbProcessed=true;} if(nKey==GK_DOWN){SelectNext();*pbProcessed=true;} if(nKey==GK_PAGEDOWN){SelectNextPage();*pbProcessed=true;} if(nKey==GK_PAGEUP){SelectPreviousPage();*pbProcessed=true;} if(nKey==GK_HOME){m_nSelectedElement=0;ValidateSelection();*pbProcessed=true;} if(nKey==GK_END){m_nSelectedElement=m_vElements.size()-1;ValidateSelection();*pbProcessed=true;} }
GLboolean drimi::Gui::Container::HandleEvent ( const drimi::Event::Type eEventType, const sf::Keyboard::Key sfKeyCode ) { // If a child is selected then give it events. if (HasSelection ()) { m_oChildren[m_iSelectedChild]->HandleEvent (eEventType, sfKeyCode); } if (eEventType == drimi::Event::Type::KeyPressed) { if (sfKeyCode == sf::Keyboard::Up) SelectPrevious (); else if (sfKeyCode == sf::Keyboard::Down) SelectNext (); } return GL_FALSE; }
WINDOWPROC MainWndProc( HWND hwnd, UINT msg, WPARAM wParam, LONG lParam) { switch (msg) { case WM_CREATE: { RECT rc; /* * Create the status window. */ CreateDialog(ghInst, MAKEINTRESOURCE(DID_STATUS), hwnd, StatusDlgProc); /* * Save away its height for sizing later (like when * the app is minimized then restored). */ GetWindowRect(hwndStatus, &rc); gcyStatus = rc.bottom - rc.top; ghwndSubClient = CreateWindow(szSubClientClass, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, NULL, ghInst, NULL); ghMenuMain = GetMenu(hwnd); LoadMenuBitmaps(ghMenuMain); } break; case WM_ACTIVATE: /* * If the main window is getting activated, there is no * currently active dialog. */ if (GET_WM_ACTIVATE_STATE(wParam, lParam)) gidCurrentDlg = 0; goto DoDefault; case WM_INITMENU: if (GetMenu(ghwndMain) == (HMENU)wParam) InitMenu((HMENU)wParam); break; case WM_MENUSELECT: if (GET_WM_MENUSELECT_FLAGS(wParam, lParam) & (MF_POPUP | MF_SYSMENU)) gMenuSelected = 0; else gMenuSelected = GET_WM_MENUSELECT_CMD(wParam, lParam); break; case WM_COMMAND: DialogMenu(GET_WM_COMMAND_ID(wParam, lParam)); break; case WM_KEYDOWN: switch (wParam) { case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT: if ((GetKeyState(VK_SHIFT) & 0x8000) || (GetKeyState(VK_CONTROL) & 0x8000)) break; /* * Ignore it if we are not in a normal state * (don't allow when dragging). */ if (gState != STATE_NORMAL) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; /* * Move the control in the specified direction. */ MoveControl(wParam); break; case VK_TAB: if (GetKeyState(VK_CONTROL) & 0x8000) break; /* * Ignore it if we are not in a normal state * (don't allow when dragging). */ if (gState != STATE_NORMAL) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; /* * Is the shift key pressed also? */ if (GetKeyState(VK_SHIFT) & 0x8000) SelectPrevious(); else SelectNext(); break; case VK_ESCAPE: if ((GetKeyState(VK_SHIFT) & 0x8000) || (GetKeyState(VK_CONTROL) & 0x8000)) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; if (gState == STATE_SELECTING) OutlineSelectCancel(); /* * Cancel any drag operation they might have been doing. */ if (gState != STATE_NORMAL) DragCancel(); break; case VK_RETURN: if ((GetKeyState(VK_SHIFT) & 0x8000) || (GetKeyState(VK_CONTROL) & 0x8000)) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; switch (gState) { MPOINT mpt; POINT pt; DWORD dwPos; case STATE_SELECTING: /* * In outline selection mode. Map the * location of the mouse at the time that * the user pressed Enter into a point * relative to the dialog client and complete * the selection operation. */ dwPos = GetMessagePos(); mpt = MAKEMPOINT(dwPos); MPOINT2POINT(mpt, pt); ScreenToClient(gcd.npc->hwnd, &pt); OutlineSelectEnd(pt.x, pt.y); break; case STATE_DRAGGING: case STATE_DRAGGINGNEW: /* * We are dragging something. Map the * location of the mouse at the time * that the user pressed Enter into a * point relative to the proper window * and complete the drag operation. */ dwPos = GetMessagePos(); mpt = MAKEMPOINT(dwPos); MPOINT2POINT(mpt, pt); /* * The point must be changed to be relative to * the window that the ending mouse up message * would have come through, which will be the * capture window for the drag. This will be * the dialog if we are adding a new control, * or it will be the selected control if we are * dragging an existing control. */ ScreenToClient((gState == STATE_DRAGGING) ? gnpcSel->hwnd : gcd.npc->hwnd, &pt); /* * If the dialog is selected, map the points from * the client area to the window. */ if (gfDlgSelected) MapDlgClientPoint(&pt, TRUE); DragEnd(pt.x, pt.y); break; } break; } break; case WM_NCCALCSIZE: /* * Save away what is going to be the new window position. */ if (!IsIconic(hwnd) && !IsZoomed(hwnd)) grcAppPos = *((LPRECT)lParam); /* * Now let the DefWindowProc calculate the client area normally. */ goto DoDefault; case WM_MOVE: if (gfEditingDlg) RepositionDialog(); break; case WM_SIZE: SizeRibbons(hwnd); /* * Did the app start minimized and is it being restored * for the first time? If so, show the toolbox if * the user has requested it. */ if (fStartAsIcon && !IsIconic(hwnd)) { if (gfShowToolbox) ToolboxShow(TRUE); fStartAsIcon = FALSE; } break; case WM_SYSCOLORCHANGE: LoadSysColorBitmaps(); break; case WM_CLOSE: if (ghwndTestDlg) DestroyTestDialog(); if (DoWeSave(FILE_INCLUDE) == IDCANCEL || DoWeSave(FILE_RESOURCE) == IDCANCEL) break; /* * First destroy the Properties Bar. */ DestroyWindow(hwndStatus); hwndStatus = NULL; DestroyWindow(hwnd); break; case WM_QUERYENDSESSION: if (ghwndTestDlg) DestroyTestDialog(); if (DoWeSave(FILE_INCLUDE) == IDCANCEL || DoWeSave(FILE_RESOURCE) == IDCANCEL) return FALSE; else return TRUE; case WM_DESTROY: /* * Save the position of the app's window. */ WriteWindowPos(&grcAppPos, IsZoomed(hwnd), szAppPos); WinHelp(hwnd, gszHelpFile, HELP_QUIT, 0L); FreeMenuBitmaps(); PostQuitMessage(0); break; default: /* * Is this the registered help message from one of the common * dialogs? If so, show the help for it. * * The check to be sure gmsgHelp is non-zero is just in * case the call to register the help message failed * (it will return zero) and there happens to be a zero * message that gets sent to this window somehow. */ if (msg == gmsgHelp && gmsgHelp) { ShowHelp(FALSE); return 0; } DoDefault: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }