The Battle for Wesnoth  1.17.4+dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2022
3  by Fabian Mueller <>
4  Part of the Battle for Wesnoth Project
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,
13  See the COPYING file for more details.
14 */
21 namespace editor {
23 std::unique_ptr<editor_action> mouse_action_village::up_left(editor_display& disp, int x, int y)
24 {
25  map_location hex = disp.hex_clicked_on(x, y);
26  if (!disp.get_map().on_board(hex)) return nullptr;
27  if (!disp.get_map().is_village(hex)) return nullptr;
29  return std::make_unique<editor_action_village>(hex, disp.playing_team());
30 }
32 std::unique_ptr<editor_action> mouse_action_village::up_right(editor_display& disp, int x, int y)
33 {
34  map_location hex = disp.hex_clicked_on(x, y);
35  if (!disp.get_map().on_board(hex)) return nullptr;
36  if (!disp.get_map().is_village(hex)) return nullptr;
38  return std::make_unique<editor_action_village_delete>(hex);
39 }
42 {
43  surface image60 = image::get_image("icons/action/editor-tool-village_60.png");
45  //TODO avoid hardcoded hex field size
46  surface image(72,72);
48  SDL_Rect r {6, 6, 0, 0};
49  sdl_blit(image60, nullptr, image, &r);
51  uint8_t alpha = 196;
52  int size = image->w;
53  int zoom = static_cast<int>(size * disp.get_zoom_factor());
55  // Add the alpha factor and scale the image
56  adjust_surface_alpha(image, alpha);
57  image = scale_surface(image, zoom, zoom);
58  disp.set_mouseover_hex_overlay(image);
59 }
62 } //end namespace editor
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
Definition: picture.cpp:830
std::unique_ptr< editor_action > up_left(editor_display &disp, int x, int y) override
If clicked on a village hex field, assigns the ownership of it to the current side.
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
Definition: display.cpp:587
static double get_zoom_factor()
Returns the current zoom factor.
Definition: display.hpp:267
std::unique_ptr< editor_action > up_right(editor_display &disp, int x, int y) override
If clicked on a village hex field, unassigns it&#39;s ownership.
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
virtual void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
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:445
Manage the empty-palette in the editor.
Definition: action.cpp:30
Encapsulates the map of the game.
Definition: location.hpp:38
std::size_t playing_team() const
The playing team is the team whose turn it is.
Definition: display.hpp:105
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:385
bool is_village(const map_location &loc) const
Definition: map.cpp:66
const gamemap & get_map() const
Definition: display.hpp:100
Editor action classes.
Functions to load and save images from/to disk.
void adjust_surface_alpha(surface &surf, int32_t amount)
Definition: utils.cpp:1087
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
Definition: utils.hpp:32