The Battle for Wesnoth  1.17.0-dev
mouse_action_select.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Fabian Mueller <fabianmueller5@gmx.de>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
18 
20 
21 namespace editor {
22 
23 std::set<map_location> mouse_action_select::affected_hexes(
24  editor_display& disp, const map_location& hex)
25 {
26  if (has_shift_modifier()) {
27  return disp.map().get_contiguous_terrain_tiles(hex);
28  } else {
30  }
31 }
32 
33 std::unique_ptr<editor_action> mouse_action_select::key_event(
34  editor_display& disp, const SDL_Event& event)
35 {
36  auto ret = mouse_action::key_event(disp, event);
38  return ret;
39 }
40 
41 std::unique_ptr<editor_action> mouse_action_select::click_perform_left(
42  editor_display& /*disp*/, const std::set<map_location>& hexes)
43 {
44  auto chain = std::make_unique<editor_action_chain>();
45  if (has_ctrl_modifier())
46  chain->append_action(std::make_unique<editor_action_deselect>(hexes));
47  else
48  chain->append_action(std::make_unique<editor_action_select>(hexes));
49  return chain;
50 }
51 
52 std::unique_ptr<editor_action> mouse_action_select::click_perform_right(
53  editor_display& /*disp*/, const std::set<map_location>& /*hexes*/)
54 {
55  return nullptr;
56 }
57 
58 std::unique_ptr<editor_action> mouse_action_select::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
59 {
60  return nullptr;
61 }
62 
64 {
65  surface image;
66  if (has_shift_modifier()) {
67  image = image::get_image("editor/tool-overlay-select-wand.png");
68  } else {
69  image = image::get_image("editor/tool-overlay-select-brush.png");
70  }
71  uint8_t alpha = 196;
72  int size = image->w;
73  int zoom = static_cast<int>(size * disp.get_zoom_factor());
74 
75  // Add the alpha factor and scale the image
76  adjust_surface_alpha(image, alpha);
77  image = scale_surface(image, zoom, zoom);
78  disp.set_mouseover_hex_overlay(image);
79 }
80 
81 
82 } //end namespace editor
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
Definition: picture.cpp:816
const editor_map & map() const
map_location previous_move_hex_
The hex previously used in move operations.
static double get_zoom_factor()
Returns the current zoom factor.
Definition: display.hpp:263
std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y) override
Right click does nothing for now.
virtual void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
surface scale_surface(const surface &surf, int w, int h)
Scale a surface using alpha-weighted modified bilinear filtering Note: causes artifacts with alpha gr...
Definition: utils.cpp:197
std::unique_ptr< editor_action > key_event(editor_display &disp, const SDL_Event &e) override
Force a fake "move" event to update brush overlay on key event.
std::unique_ptr< editor_action > click_perform_right(editor_display &disp, const std::set< map_location > &hexes) override
Right click/drag.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
void adjust_surface_alpha(surface &surf, fixed_t amount)
Definition: utils.cpp:1087
virtual std::unique_ptr< editor_action > key_event(editor_display &disp, const SDL_Event &e)
Function called by the controller on a key event for the current mouse action.
std::set< map_location > affected_hexes(editor_display &disp, const map_location &hex) override
Overridden to allow special behavior based on modifier keys.
bool has_shift_modifier() const
std::set< map_location > get_contiguous_terrain_tiles(const map_location &start) const
Get a contiguous set of tiles having the same terrain as the starting location.
Definition: editor_map.cpp:115
void update_brush_highlights(editor_display &disp, const map_location &hex)
Unconditionally update the brush highlights for the current tool when hex is the center location...
void set_mouseover_hex_overlay(const surface &image)
mouseover_hex_overlay_ require a prerendered surface and is drawn underneath the mouse&#39;s location ...
Definition: display.hpp:448
Manage the empty-palette in the editor.
Definition: action.cpp:30
Encapsulates the map of the game.
Definition: location.hpp:38
Functions to load and save images from/to disk.
bool has_ctrl_modifier() const
std::unique_ptr< editor_action > click_perform_left(editor_display &disp, const std::set< map_location > &hexes) override
Left click/drag selects.
Editor action classes.
std::set< map_location > affected_hexes(editor_display &disp, const map_location &hex)
The affected hexes of a brush action are the result of projecting the current brush on the mouseover ...