void AdvancedDlg::OnAutoDetectCompilers(wxButton* btn) { // Launch the auto detect compilers code wxMenu menu; menu.Append(ID_MENU_ADD_COMPILER_BY_PATH, _("Add an existing compiler")); menu.Append(ID_MENU_CLONE_COMPILER, _("Clone a compiler")); menu.AppendSeparator(); menu.Append(ID_MENU_AUTO_DETECT_COMPILERS, _("Scan computer for installed compilers")); // Menu will be shown in client coordinates wxRect size = btn->GetSize(); wxPoint menuPos(0, size.GetHeight()); int res = btn->GetPopupMenuSelectionFromUser(menu, menuPos); if(res == ID_MENU_AUTO_DETECT_COMPILERS) { if(m_compilersDetector.Locate()) { CallAfter(&AdvancedDlg::OnCompilersDetected, m_compilersDetector.GetCompilersFound()); } } else if(res == ID_MENU_CLONE_COMPILER) { CallAfter(&AdvancedDlg::OnButtonNewClicked); } else if(res == ID_MENU_ADD_COMPILER_BY_PATH) { CallAfter(&AdvancedDlg::OnAddExistingCompiler); } }
void CodeFormatterDlg::OnHelp(wxCommandEvent& e) { wxUnusedVar(e); static wxString astyleHelpUrl(wxT("http://astyle.sourceforge.net/astyle.html")); static wxString clangFormatHelpUrl(wxT("http://clang.llvm.org/docs/ClangFormatStyleOptions.html")); static wxString phpFormatHelpUrl(wxT("https://github.com/FriendsOfPHP/PHP-CS-Fixer")); wxMenu menu; menu.Append(ID_ASTYLE_HELP, _("AStyle help page")); menu.Append(ID_CLANG_FORMAST_HELP, _("clang-format help page")); menu.Append(ID_PHP_FORMAST_HELP, _("PHP-CS-Fixer help page")); wxRect size = m_buttonHelp->GetSize(); wxPoint menuPos(0, size.GetHeight()); int res = m_buttonHelp->GetPopupMenuSelectionFromUser(menu, menuPos); if(res == ID_ASTYLE_HELP) { ::wxLaunchDefaultBrowser(astyleHelpUrl); } else if(res == ID_CLANG_FORMAST_HELP) { ::wxLaunchDefaultBrowser(clangFormatHelpUrl); } else if(res == ID_PHP_FORMAST_HELP) { ::wxLaunchDefaultBrowser(phpFormatHelpUrl); } }
wxPoint calcContextMenuPosition(const wxPoint& eventPos, wxControl* control) { // use mouse coordinates if event is response to keyboard action wxPoint menuPos(eventPos); if (menuPos == wxDefaultPosition) menuPos = wxGetMousePosition(); // make sure popup appears in the focused control wxPoint menuPosClient = control->ScreenToClient(menuPos); if (!control->GetClientRect().Contains(menuPosClient)) menuPosClient = wxPoint(0, 0); return menuPosClient; }
void Inventory::touchRelease(Vector2 position) { touchOffset.set(-1, -1); if (iconTouched != NULL){ if (iconTouched->preview){ Vector2 fieldCoords = playField->screenToFieldCoordinates(position); // check to see if fieldCoords is within character's radius float length = fieldCoords.distance(belongsTo->GetPosition()); if (length < belongsTo->GetRadius()) belongsTo->equipItem(iconTouched->item); else playField->putItemInTile(iconTouched->item, fieldCoords.x, fieldCoords.y); // remove the icon here removeItem(iconTouched); } else{ // put the icon back where it belongs addItem(iconTouched , findClosestMatch(iconTouched)); } iconTouched = NULL; } else{ Vector2 menuPos(menuRec.x, menuRec.y); float dockLength = (menuPos - dockPosition).length(); float outLength = (menuPos - outPosition).length(); // check for a tap first if (outLength < TAP_LEEWAY && touchTimer < TAP_DURATION) slideTo(dockPosition, dockLength / dockToOutLength * SLIDE_TIME); else if (dockLength < TAP_LEEWAY && touchTimer < TAP_DURATION) slideTo(outPosition, outLength / dockToOutLength * SLIDE_TIME); // otherwise see if drug else if (menuPos != dockPosition && menuPos != outPosition){ if (dockLength < outLength) slideTo(dockPosition, dockLength / dockToOutLength * SLIDE_TIME); else if(outLength < dockLength) slideTo(outPosition, outLength / dockToOutLength * SLIDE_TIME); } } touchTimer = 0; }
u32 cPopMenu::itemBelowPoint( const cPoint & pt ) { cPoint menuPos(position().x + _barLeft, position().y + _itemTopLeftPoint.y - 2); cSize menuSize(barWidth(), _itemHeight * _items.size()); cRect rect(menuPos, menuPos + menuSize); if( rect.surrounds( pt ) ) { u32 item = (pt.y - menuPos.y ) / _itemHeight; if( item > _items.size() - 1) item = _items.size() - 1; return item; } return (u32)-1; }
void FindInFilesDialog::OnAddPath(wxCommandEvent& event) { #ifdef __WXOSX__ // There is a bug in OSX that prevents popup menu from being displayed from dialogs // so we use an alternative way FindInFilesLocationsDlg dlg(this, m_listPaths->GetStrings()); if(dlg.ShowModal() == wxID_OK) { m_listPaths->Clear(); m_listPaths->Append(dlg.GetLocations()); } #else // Show a popup menu wxMenu menu; int firstItem = 8994; menu.Append(firstItem + 5, "Add Folder..."); menu.AppendSeparator(); menu.Append(firstItem + 0, SEARCH_IN_WORKSPACE); menu.Append(firstItem + 1, SEARCH_IN_PROJECT); menu.Append(firstItem + 2, SEARCH_IN_CURR_FILE_PROJECT); menu.Append(firstItem + 3, SEARCH_IN_CURRENT_FILE); menu.Append(firstItem + 4, SEARCH_IN_OPEN_FILES); std::map<int, wxString> options; options.insert(std::make_pair(firstItem, SEARCH_IN_WORKSPACE)); options.insert(std::make_pair(firstItem + 1, SEARCH_IN_PROJECT)); options.insert(std::make_pair(firstItem + 2, SEARCH_IN_CURR_FILE_PROJECT)); options.insert(std::make_pair(firstItem + 3, SEARCH_IN_CURRENT_FILE)); options.insert(std::make_pair(firstItem + 4, SEARCH_IN_OPEN_FILES)); // Menu will be shown in client coordinates wxRect size = m_btnAddPath->GetSize(); wxPoint menuPos(0, size.GetHeight()); int selection = m_btnAddPath->GetPopupMenuSelectionFromUser(menu, menuPos); if(selection == wxID_NONE) return; if(selection == (firstItem + 5)) { wxString folder = ::wxDirSelector(); if(folder.IsEmpty()) return; DoAddSearchPath(folder); } else if(options.count(selection)) { DoAddSearchPath(options.find(selection)->second); } #endif }
void Inventory::touchMove(Vector2 position) { if (iconTouched != NULL) { if (!menuRec.contains(position.x, position.y)){ if (iconTouched->visible == true || iconTouched->preview == false){ iconTouched->visible = false; // add ghost Vector2 fieldCoords = playField->screenToFieldCoordinates(position); /* iconTouched->preview = iconTouched->item->addPreviewToPlayField (playField , playField->getScene() , fieldCoords);*/ if (iconTouched->item->canPlace(fieldCoords, playField)){ Item::ClearLists(); iconTouched->preview = true; iconTouched->item->SetStatus(Item::PREVIEW); iconTouched->item->SetPosition(fieldCoords.x, fieldCoords.y, playField); iconTouched->item->AddToEntityList(); Item::LoadAssets(); Item::BuildAndFinish(playField->getScene()); Item::ClearLists(); } // scoot menu back to docked Vector2 menuPos(menuRec.x, menuRec.y); if (menuPos != dockPosition){ float dockLength = (menuPos - dockPosition).length(); slideTo(dockPosition, dockLength / dockToOutLength * SLIDE_TIME); } } else{ Vector2 fieldCoords = playField->screenToFieldCoordinates(position); // check to see if fieldCoords is within character's radius float length = fieldCoords.distance(belongsTo->GetPosition()); if (length < belongsTo->GetRadius()) belongsTo->ghostEquipItem(iconTouched->item); else //iconTouched->ghost = iconTouched->item->SetPosition(fieldCoords.x, fieldCoords.y, playField); } } else{ iconTouched->rec.x = position.x + iconTouched->offset.x; iconTouched->rec.y = position.y + iconTouched->offset.y; if (iconTouched->visible == false){ iconTouched->visible = true; // remove ghost // iconTouched->item->removeFromPlayField(playField->getScene()); iconTouched->item->SetStatus(Item::ABSTRACT); iconTouched->preview = false; // scoot menu back to docked Vector2 menuPos(menuRec.x, menuRec.y); if (menuPos != outPosition){ float outLength = (menuPos - outPosition).length(); slideTo(outPosition, outLength / dockToOutLength * SLIDE_TIME); } } else{ // iconTouched->rec.x = position.x + iconTouched->offset.x; // iconTouched->rec.y = position.y + iconTouched->offset.y; } } } else{ menuRec.x = position.x + touchOffset.x; menuRec.y = position.y + touchOffset.y; // adjust it to not go out of bounds if (menuRec.x < outPosition.x) menuRec.x = outPosition.x; if (menuRec.y > outPosition.y) menuRec.y = outPosition.y; if (menuRec.x > dockPosition.x) menuRec.x = dockPosition.x; if (menuRec.y < dockPosition.y) menuRec.y = dockPosition.y; setIconPositions(); } }
void WebRenderMainWindow::popupMenu() { QPoint menuPos(mapToGlobal(menuButton->pos()).x(),mapToGlobal(menuButton->pos()).y() + menuButton->height() + 5); webrenderMainMenu->move(menuPos); webrenderMainMenu->show(); }
void OOPLyric::OnMouseEvent(VdkMouseEvent &e) { switch (e.evtCode) { case RIGHT_UP: { // 拖动歌词时不要响应右键事件 if (TestState(OLST_DRAGGING)) { return; } wxPoint menuPos(AbsoluteRect().GetPosition()); menuPos.x += e.mousePos.x; menuPos.y += e.mousePos.y; m_Window->ShowContextMenu(this, menuPos); break; } case LEFT_DOWN: { m_draggDistance = e.mousePos.y; SetAddinState(OLST_DRAGGING_STARTED); break; } case DRAGGING: { // 不接受先在一首歌的会话中拖动歌词,然后在未释放鼠标的情况下 // 另一首歌开始播放,继续前面的拖动事件 if (!TestState(OLST_DRAGGING_STARTED)) { break; } if (!IsOk()) { break; } if (m_timer.IsRunning()) { Pause(); SetAddinState(OLST_RUNNING_BEFORE_DRAGGING); } SetAddinState(OLST_DRAGGING); //====================================================== int ystart; GetViewStartCoord(NULL, &ystart); int dY = e.mousePos.y - m_draggDistance; m_draggDistance = e.mousePos.y; // 这是一行我们手工加上去的空行 int rowHeight = GetRowHeight(); int upperBound = (*(m_parser->begin()))->GetLyric().empty() ? rowHeight : 0; // 无法继续将帘布向上卷(再拖下去就到下一首了) // 我们将拖到尽头的事件视为无效 bool lastLine = false; // 情景:将虚拟画布像窗帘一样向下拖 // 拖动尽头了,不能再把窗帘哪怕拖下一寸 if (ystart - dY < upperBound) { dY = ystart - upperBound; // 加加减减的原因参照(*) } else { int maxy; GetMaxViewStartCoord(NULL, &maxy); // 将帘布向上卷,卷到尽头了,再卷下去就会导致 // 无法完整遮住窗口 if (ystart - dY > maxy) { dY = ystart - maxy; // 加加减减的原因参照(*) // 无效拖动事件 lastLine = true; } } if (dY) { SetViewStart(0, ystart - dY, &e.dc); //………………(*) } // 无效拖动事件 if (lastLine) { m_draggHit = m_parser->end(); } //=================================================== // 绘制中间线段 wxRect rc(GetAbsoluteRect()); int y = rc.y + m_blankLinesTop * GetRowHeight(); m_Window->ResetDcOrigin(e.dc); e.dc.SetPen(wxPen(m_TextColor)); e.dc.DrawLine(rc.x, y, rc.GetRight(), y); break; } case NORMAL: case LEFT_UP: { if (!TestState(OLST_DRAGGING) || !TestState(OLST_DRAGGING_STARTED)) { break; } wxASSERT(IsOk()); //----------------------------------------------------- RemoveState(OLST_DRAGGING | OLST_DRAGGING_STARTED); // 拖到最下面了,尽头 if (m_draggHit == m_parser->end()) { RefreshState(&e.dc); } else { int ystart; // 起始绘图坐标 GetViewStartCoord(NULL, &ystart); LineInfo *lineDraggHit = *m_draggHit; size_t timeToGo = lineDraggHit->GetStartTime(); int rowHeight = GetRowHeight(); double linePercentage = double(ystart % rowHeight) / rowHeight ; timeToGo += lineDraggHit->GetMilSeconds() * linePercentage; // 歌词可能并不匹配正在播放的歌曲 if (timeToGo < m_parser->GetTimeSum()) { m_currLine = m_draggHit; if (IsReadyForEvent()) { FireEvent(&e.dc, (void *) timeToGo); } } } bool resume = TestState(OLST_RUNNING_BEFORE_DRAGGING); if (resume) { RemoveState(OLST_RUNNING_BEFORE_DRAGGING); Resume(); } break; } default: break; } }