Scroll wheel support

- All areas with scroll wheels can be scrolled using the scroll wheel if the mouse is in the area
- In addition, the terrain view is scrollable with the scroll wheel (hold Control for horizontal scrolling)
- The above applies in the game too, whenever the scroll arrows are visible
This commit is contained in:
2015-06-04 23:51:44 -04:00
parent 80f95ba9ae
commit dd589001c6
12 changed files with 77 additions and 10 deletions

View File

@@ -59,7 +59,7 @@ cTown::cItem store_place_item;
short flood_count = 0;
rectangle terrain_rects[256],terrain_rect_base = {0,0,16,16},command_rects[21];
extern rectangle terrain_buttons_rect;
extern short cen_x, cen_y, cur_town;
extern eScenMode overall_mode;
@@ -1515,6 +1515,30 @@ void handle_keystroke(sf::Event event) {
mouse_button_held = false;
}
bool handle_scroll(sf::Event& event) {
rectangle pal_rect = terrain_buttons_rect, right_area_rect = {0,0,RIGHT_AREA_HEIGHT,RIGHT_AREA_WIDTH};
right_area_rect.offset(RIGHT_AREA_UL_X, RIGHT_AREA_UL_Y);
pal_rect.offset(RIGHT_AREA_UL_X,RIGHT_AREA_UL_Y);
pal_rect.height() = 16 * 17 + 2;
fill_rect(mainPtr, right_area_rect, sf::Color::Magenta);
location pos(event.mouseWheel.x, event.mouseWheel.y);
int amount = event.mouseWheel.delta;
if(right_sbar->isVisible() && pos.in(right_area_rect)) {
right_sbar->setPosition(right_sbar->getPosition() - amount);
redraw_screen();
} else if(pal_sbar->isVisible() && pos.in(pal_rect)) {
pal_sbar->setPosition(pal_sbar->getPosition() - amount);
set_up_terrain_buttons(false);
redraw_screen();
} else if(overall_mode < MODE_MAIN_SCREEN && pos.in(world_screen)) {
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::RControl))
cen_x -= amount;
else cen_y -= amount;
redraw_screen();
}
return true;
}
void shy_change_circle_terrain(location center,short radius,ter_num_t terrain_type,short probability) {
// prob is 0 - 20, 0 no, 20 always
location l;

View File

@@ -5,6 +5,7 @@ void flash_rect(rectangle to_flash);
void swap_terrain();
void set_new_terrain(ter_num_t selected_terrain);
void handle_keystroke(sf::Event event);
bool handle_scroll(sf::Event& event);
void get_wandering_monst();
void get_town_info();
void get_sign_resource();

View File

@@ -16,7 +16,6 @@ extern rectangle right_sbar_rect;
rectangle left_button[NLS];
extern rectangle right_buttons[NRSONPAGE];
rectangle right_scrollbar_rect;
rectangle right_area_rect;
extern short current_rs_top;
bool left_buttons_active = 1,right_buttons_active = 0;

View File

@@ -48,7 +48,6 @@ extern sf::Texture bg_gworld;
extern rectangle left_button[NLS];
extern rectangle right_buttons[NRSONPAGE];
extern rectangle right_scrollbar_rect;
extern rectangle right_area_rect;
extern std::shared_ptr<cScrollbar> right_sbar, pal_sbar;
extern bool left_buttons_active,right_buttons_active;

View File

@@ -169,6 +169,10 @@ void Handle_One_Event() {
update_mouse_spot(loc(event.mouseMove.x,event.mouseMove.y));
break;
case sf::Event::MouseWheelMoved:
handle_scroll(event);
break;
case sf::Event::MouseButtonReleased:
mouse_button_held = false;
break;