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(); 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(gui.video().getWindow()) & SDL_APPACTIVE) == 0) { get_display().delay(200); } if (!scrolling_ && was_scrolling) { #if (defined(__APPLE__) && TARGET_OS_IPHONE) || defined(ANDROID) #else // scrolling ended, update the cursor and the brightened hex get_mouse_handler_base().mouse_update(browse_); #endif } slice_end(); }
void controller_base::play_slice(bool is_delay_enabled) { CKey key; events::pump(); events::raise_process_event(); events::raise_draw_event(); slice_before_scroll(); const theme::menu* const m = get_display().menu_pressed(); if(m != NULL) { const SDL_Rect& menu_loc = m->location(get_display().screen_area()); show_menu(m->items(),menu_loc.x+1,menu_loc.y + menu_loc.h + 1,false); return; } bool was_scrolling = scrolling_; std::pair<double, double> values = joystick_manager_.get_scroll_axis_pair(); const double joystickx = values.first; const double joysticky = values.second; int mousex, mousey; Uint8 mouse_flags = SDL_GetMouseState(&mousex, &mousey); /* TODO fendrin enable after an axis choosing mechanism is implemented std::pair<double, double> values = joystick_manager_.get_mouse_axis_pair(); mousex += values.first * 10; mousey += values.second * 10; SDL_WarpMouse(mousex, mousey); */ scrolling_ = handle_scroll(key, mousex, mousey, mouse_flags, joystickx, joysticky); map_location highlighted_hex = get_display().mouseover_hex(); /* TODO fendrin enable when the relative cursor movement is implemented well enough const map_location& selected_hex = get_display().selected_hex(); if (selected_hex != map_location::null_location) { if (joystick_manager_.next_highlighted_hex(highlighted_hex, selected_hex)) { get_mouse_handler_base().mouse_motion(0,0, true, true, highlighted_hex); get_display().scroll_to_tile(highlighted_hex, display::ONSCREEN_WARP, false, true); scrolling_ = true; } } else */ if (joystick_manager_.update_highlighted_hex(highlighted_hex) && get_display().get_map().on_board(highlighted_hex)) { get_mouse_handler_base().mouse_motion(0,0, true, true, highlighted_hex); get_display().scroll_to_tile(highlighted_hex, display::ONSCREEN_WARP, false, true); scrolling_ = true; } 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) { // scrolling ended, update the cursor and the brightened hex get_mouse_handler_base().mouse_update(browse_, highlighted_hex); } slice_end(); }
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(); }