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(); }
bool scroll_widget_rep::handle (event ev) { if (ev->type != SCROLL_EVENT) return attribute_widget_rep::handle (ev); scroll_event e (ev); handle_scroll (e); return true; }
void print_char(char ch, int row, int col){ unsigned char* vm = (unsigned char*)VIDEO_ADDRESS; //get the memory offset to write the char. int offset = get_screen_offset(row, col); if(offset == -1){ offset = get_cursor(); } switch(ch){ case '\n': //row may be changed to the row of cursor row = offset / (MAX_COLS * 2); //scroll screen offset = get_screen_offset(row, MAX_COLS - 1); break; default: vm[offset] = ch; vm[offset + 1] = text_color; break; } offset += 2; //move offset to the next cell offset = handle_scroll(offset); //scroll if required set_cursor(offset); //update the location of cursor }
int handle_console_msg(int cons_fd) { int ret = 0; struct cons_msg msg; ret = read(cons_fd, &msg, sizeof(struct cons_msg)); if (ret != sizeof(struct cons_msg)) { printf("ERROR: Could not read console message\n"); return ret; } switch (msg.op) { case CONSOLE_CURS_SET: // printf("Console cursor set (x=%d, y=%d)\n", msg.cursor.x, msg.cursor.y); handle_curs_set(&(msg.cursor)); break; case CONSOLE_CHAR_SET: handle_char_set(&(msg.character)); /* printf("Console character set (x=%d, y=%d, c=%c, style=%c)\n", msg.character.x, msg.character.y, msg.character.c, msg.character.style);*/ break; case CONSOLE_SCROLL: // printf("Console scroll (lines=%d)\n", msg.scroll.lines); handle_scroll(&(msg.scroll)); break; case CONSOLE_UPDATE: // printf("Console update\n"); handle_update(); break; case CONSOLE_RESOLUTION: handle_text_resolution(&(msg.resolution)); break; default: printf("Invalid console message operation (%d)\n", msg.op); break; } return 0; }
void controller_base::play_slice(bool is_delay_enabled) { CKey key; if (plugins_context *l = get_plugins_context()) { l->play_slice(); } events::pump(); events::raise_process_event(); events::raise_draw_event(); // Update sound sources before scrolling if (soundsource::manager *l = get_soundsource_man()) { l->update(); } 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, get_display()); return; } const theme::action* const a = get_display().action_pressed(); if(a != NULL) { const SDL_Rect& action_loc = a->location(get_display().screen_area()); execute_action(a->items(), action_loc.x+1, action_loc.y + action_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(is_browsing(), highlighted_hex); } }
void Handle_One_Event() { static const long twentyTicks = time_in_ticks(20).asMilliseconds(); static const long fortyTicks = time_in_ticks(40).asMilliseconds(); through_sending(); Handle_Update(); //(cur_time - last_anim_time > 42) if((animTimer.getElapsedTime().asMilliseconds() >= fortyTicks) && (overall_mode != MODE_STARTUP) && (anim_onscreen) && get_bool_pref("DrawTerrainAnimation", true) && (!gInBackground)) { animTimer.restart(); draw_terrain(); } if((animTimer.getElapsedTime().asMilliseconds() > twentyTicks) && (overall_mode == MODE_STARTUP)) { animTimer.restart(); draw_startup_anim(true); } clear_sound_memory(); if(map_visible && mini_map.pollEvent(event)){ if(event.type == sf::Event::Closed) { mini_map.setVisible(false); map_visible = false; } else if(event.type == sf::Event::GainedFocus) makeFrontWindow(mainPtr); } if(!mainPtr.pollEvent(event)) { if(changed_display_mode) { changed_display_mode = false; adjust_window_mode(); } flushingInput = false; redraw_screen(REFRESH_NONE); return; } switch(event.type) { case sf::Event::KeyPressed: if(flushingInput) return; if(!(event.key.*systemKey)) handle_keystroke(event); break; case sf::Event::MouseButtonPressed: if(flushingInput) return; Mouse_Pressed(); break; case sf::Event::MouseLeft: // Make sure we don't have an arrow cursor when it's outside the window make_cursor_sword(); break; case sf::Event::GainedFocus: Handle_Update(); makeFrontWindow(mainPtr); case sf::Event::MouseMoved: if(!gInBackground) { location where(event.mouseMove.x, event.mouseMove.y); change_cursor(where); } break; case sf::Event::MouseWheelMoved: if(flushingInput) return; handle_scroll(event); break; case sf::Event::Closed: if(overall_mode == MODE_STARTUP) { if(party_in_memory) { std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show(); if(choice == "cancel") break; if(choice == "save") { fs::path file = nav_put_party(); if(!file.empty()) break; save_party(file, univ); } } All_Done = true; break; } if(overall_mode > MODE_TOWN){ std::string choice = cChoiceDlog("quit-confirm-nosave", {"quit", "cancel"}).show(); if(choice == "cancel") break; } else { std::string choice = cChoiceDlog("quit-confirm-save", {"save", "quit", "cancel"}).show(); if(choice == "cancel") break; if(choice == "save") save_party(univ.file, univ); } All_Done = true; default: break; // There's several events we don't need to handle at all } flushingInput = false; // TODO: Could there be a case when the key and mouse input that needs to be flushed has other events interspersed? }
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(); }