The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mouse_action_village.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Fabian Mueller <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "mouse_action_village.hpp"
17 
19 
20 namespace editor {
21 
23 {
24  map_location hex = disp.hex_clicked_on(x, y);
25  if (!disp.get_map().on_board(hex)) return nullptr;
26  if (!disp.get_map().is_village(hex)) return nullptr;
27 
28  return new editor_action_village(hex, disp.playing_team());
29 }
30 
32 {
33  map_location hex = disp.hex_clicked_on(x, y);
34  if (!disp.get_map().on_board(hex)) return nullptr;
35  if (!disp.get_map().is_village(hex)) return nullptr;
36 
37  return new editor_action_village_delete(hex);
38 }
39 
41 {
42  surface image60 = image::get_image("icons/action/editor-tool-village_60.png");
43 
44  //TODO avoid hardcoded hex field size
46 
47  SDL_Rect r = sdl::create_rect(6, 6, 0, 0);
48  blit_surface(image60, nullptr, image, &r);
49 
50  Uint8 alpha = 196;
51  int size = image->w;
52  int zoom = static_cast<int>(size * disp.get_zoom_factor());
53 
54  // Add the alpha factor and scale the image
55  image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
56  disp.set_mouseover_hex_overlay(image);
57 }
58 
59 
60 } //end namespace editor
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: image.cpp:878
surface create_neutral_surface(int w, int h)
Definition: utils.cpp:150
bool is_village(const map_location &loc) const
Definition: map.cpp:68
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:577
double get_zoom_factor() const
Returns the current zoom factor.
Definition: display.hpp:269
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
surface scale_surface(const surface &surf, int w, int h)
Definition: utils.cpp:443
Sets the ownership of a village to the current side.
void blit_surface(const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
Definition: utils.cpp:2185
size_t playing_team() const
The playing team is the team whose turn it is.
Definition: display.hpp:97
virtual void set_mouse_overlay(editor_display &disp)
Set the mouse overlay for this action.
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize)
Definition: utils.cpp:1202
editor_action * up_right(editor_display &disp, int x, int y)
If clicked on a village hex field, unassigns it's ownership.
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1488
void set_mouseover_hex_overlay(const surface &image)
mouseover_hex_overlay_ require a prerendered surface and is drawn underneath the mouse's location ...
Definition: display.hpp:458
Manage the empty-palette in the editor.
Definition: action.cpp:28
Encapsulates the map of the game.
Definition: location.hpp:38
Base class for all editor actions.
Definition: action_base.hpp:41
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
Definition: rect.cpp:28
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:467
GLsizeiptr size
Definition: glew.h:1649
Editor action classes.
const gamemap & get_map() const
Definition: display.hpp:92
this module manages the cache of images.
Definition: image.cpp:75
editor_action * up_left(editor_display &disp, int x, int y)
If clicked on a village hex field, assigns the ownership of it to the current side.
Clears the ownership of a village.