/** * @brief Receives a context menu event. * @param event The event to handle. */ void TilesetView::contextMenuEvent(QContextMenuEvent* event) { if (scene == nullptr) { return; } QPoint where; if (event->pos() != QPoint(0, 0)) { where = event->pos(); } else { QList<QGraphicsItem*> selected_items = scene->selectedItems(); where = mapFromScene(selected_items.first()->pos() + QPoint(8, 8)); } show_context_menu(where); }
void controller_base::play_slice(bool is_delay_enabled) { display& gui = get_display(); CKey key; events::pump(); events::raise_process_event(); events::raise_draw_event(); slice_before_scroll(); // const theme::menu* const m = get_display().menu_pressed(); const button_loc& loc = get_display().menu_pressed(); const theme::menu* m = loc.first; if (m && (m == gui.access_troop_menu())) { map_location pressed_loc = gui.access_unit_press(loc.second); if (pressed_loc.valid() && !get_mouse_handler_base().is_moving() && !get_mouse_handler_base().is_recalling() && !get_mouse_handler_base().is_building() && !get_mouse_handler_base().is_card_playing()) { gui.scroll_to_tile(pressed_loc, display::WARP); events::mouse_handler::get_singleton()->select_hex(map_location(), false); // gui.select_hex(pressed_loc); // sound::play_UI_sound("select-unit.wav"); resources::units->find(pressed_loc)->set_selecting(); resources::screen->invalidate_unit(); // now, selectedHex_ is invalid, hide context menu. gui.goto_main_context_menu(); } } else if (m != NULL){ const SDL_Rect& menu_loc = m->location(get_display().screen_area()); if (m->is_context()) { // Is pressed menu a father menu of context-menu? const std::string& item = m->items()[loc.second]; std::vector<std::string> item2 = utils::split(item, ':'); if (item2.size() == 1) { // item2.push_back(item2[0]) is wrong way, resulting item2[1] is null string. item2.push_back(""); } size_t pos = item2[0].rfind("_m"); if (pos == item2[0].size() - 2) { // cancel current menu, and display sub-menu gui.hide_context_menu(NULL, true); const std::string item1 = item2[0].substr(0, pos); gui.get_theme().set_current_context_menu(get_display().get_theme().context_menu(item1)); show_context_menu(NULL, get_display()); } else { // execute one menu command pos = item2[0].rfind("_c"); if (pos == item2[0].size() - 2) { const std::string item1 = item2[0].substr(0, pos); // hotkey::execute_command(gui, hotkey::get_hotkey(item1).get_id(), this, -1, item2[1]); execute_command(hotkey::get_hotkey(item1).get_id(), -1, item2[1]); gui.hide_context_menu(NULL, true); } else { // hotkey::execute_command(gui, hotkey::get_hotkey(item2[0]).get_id(), this, -1, item2[1]); execute_command(hotkey::get_hotkey(item2[0]).get_id(), -1, item2[1]); } } } else { show_menu(m->items(), menu_loc.x+1, menu_loc.y + menu_loc.h + 1, false); } return; } int mousex, mousey; Uint8 mouse_flags = SDL_GetMouseState(&mousex, &mousey); bool was_scrolling = scrolling_; scrolling_ = handle_scroll(key, mousex, mousey, mouse_flags); get_display().draw(); // be nice when window is not visible // NOTE should be handled by display instead, to only disable drawing if (is_delay_enabled && (SDL_GetAppState() & SDL_APPACTIVE) == 0) { get_display().delay(200); } if (!scrolling_ && was_scrolling) { #if (defined(__APPLE__) && TARGET_OS_IPHONE) || defined(ANDROID) // swip result to scroll, don't update mouse hex. SDL_Event new_event; while(SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_FINGERMOTION, SDL_FINGERMOTION) > 0) { posix_print("SDL_FINGERMOTION(discard), (x, y): (%u, %u), (dx, dy): (%i, %i)\n", new_event.tfinger.x, new_event.tfinger.y, new_event.tfinger.dx, new_event.tfinger.dy); }; #else // scrolling ended, update the cursor and the brightened hex get_mouse_handler_base().mouse_update(browse_); #endif } slice_end(); }