The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mouse_action_map_label.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2017 by Fabian Mueller <fabianmueller5@gmx.de>
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 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
18 
22 
24 
25 #include "font/standard_colors.hpp"
26 #include "color.hpp"
27 
28 namespace editor {
29 
31 {
32  click_ = true;
33  map_location hex = disp.hex_clicked_on(x, y);
34  clicked_on_ = hex;
35  last_draged_ = hex;
36  return new editor_action_chain();
37 }
38 
40  , bool& partial, editor_action* /*last_undo*/)
41 {
42  map_location hex = disp.hex_clicked_on(x, y);
43 
44  /* Cursor is still on old hex field */
45  if (hex == last_draged_)
46  return nullptr;
47  click_ = false;
48 
49  editor_action_chain* chain = nullptr;
51 
52 
53  if (label) {
54  partial = true;
56  chain->append_action(new editor_action_label(hex, label->text(), label->team_name(), label->color(),
57  label->visible_in_fog(), label->visible_in_shroud(), label->immutable(), label->category()));
58  }
59 
60  last_draged_ = hex;
61  return chain;
62 }
63 
65 {
66  if (!click_) return nullptr;
67  click_ = false;
68 
69  const map_location hex = disp.hex_clicked_on(x, y);
70  if (!disp.get_map().on_board(hex)) {
71  return nullptr;
72  }
73 
74  const terrain_label* old_label = disp.get_controller().get_current_map_context().get_labels().get_label(hex);
75  std::string label = old_label ? old_label->text() : "";
76  std::string team_name = old_label ? old_label->team_name() : "";
77  std::string category = old_label ? old_label->category() : "";
78  bool visible_shroud = old_label ? old_label->visible_in_shroud() : false;
79  bool visible_fog = old_label ? old_label->visible_in_fog() : true;
80  bool immutable = old_label ? old_label->immutable() : true;
81  color_t color = old_label ? old_label->color() : font::NORMAL_COLOR;
82 
83  gui2::dialogs::editor_edit_label d(label, immutable, visible_fog, visible_shroud, color, category);
84 
85  editor_action* a = nullptr;
86  if(d.show(disp.video())) {
87  a = new editor_action_label(hex, label, team_name, color
88  , visible_fog, visible_shroud, immutable, category);
89  update_brush_highlights(disp, hex);
90  }
91  return a;
92 }
93 
95 {
96  return nullptr;
97 }
98 
100 {
101  map_location hex = disp.hex_clicked_on(x, y);
102 
103  //TODO
104 // const terrain_label* clicked_label = disp.map().get_map_labels().get_label(hex);
105  //if (!clicked_label)
106  // return nullptr;
107 
108  return new editor_action_label_delete(hex);
109 }
110 
112 {
113  surface image60 = image::get_image("icons/action/editor-tool-label_60.png");
114 
115  //TODO avoid hardcoded hex field size
117 
118  SDL_Rect r {6, 6, 0, 0};
119  sdl_blit(image60, nullptr, image, &r);
120 
121  Uint8 alpha = 196;
122  int size = image->w;
123  int zoom = static_cast<int>(size * disp.get_zoom_factor());
124 
125  // Add the alpha factor and scale the image
126  adjust_surface_alpha(image, alpha);
127  image = scale_surface(image, zoom, zoom);
128  disp.set_mouseover_hex_overlay(image);
129 }
130 
131 
132 } //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:926
surface create_neutral_surface(int w, int h)
Definition: utils.cpp:77
Editor action classes.
const std::string & category() const
Definition: label.hpp:156
std::vector< char_t > string
void append_action(editor_action *a)
Add an action at the end of the chain.
Definition: action.cpp:125
#define a
editor_action * up_left(editor_display &disp, int x, int y)
Left click displays a dialog that is used for entering the label string.
map_labels & get_labels()
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:585
double get_zoom_factor() const
Returns the current zoom factor.
Definition: display.hpp:262
Container action wrapping several actions into one.
Definition: action.hpp:90
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:262
#define d
bool immutable() const
Definition: label.hpp:171
map_context & get_current_map_context() const
const t_string & text() const
Definition: label.hpp:136
void adjust_surface_alpha(surface &surf, fixed_t amount)
Definition: utils.cpp:1162
editor_action * click_right(editor_display &disp, int x, int y)
A click, possibly the beginning of a drag.
const color_t & color() const
Definition: label.hpp:181
editor_action * drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Drag operation.
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...
const terrain_label * get_label(const map_location &loc, const std::string &team_name) const
Definition: label.hpp:47
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:442
Manage the empty-palette in the editor.
Definition: action.cpp:29
const std::string & team_name() const
Definition: label.hpp:151
const color_t NORMAL_COLOR
Encapsulates the map of the game.
Definition: location.hpp:40
size_t size(const utf8::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
editor_action * up_right(editor_display &disp, int x, int y)
Right click erases the label under the mouse.
virtual void set_mouse_overlay(editor_display &disp)
Set the mouse overlay for this action.
bool visible_in_shroud() const
Definition: label.hpp:166
Base class for all editor actions.
Definition: action_base.hpp:40
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
bool visible_in_fog() const
Definition: label.hpp:161
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:369
editor_action * click_left(editor_display &disp, int x, int y)
A click, possibly the beginning of a drag.
To store label data Class implements logic for rendering.
Definition: label.hpp:107
const gamemap & get_map() const
Definition: display.hpp:92
editor_controller & get_controller()
this module manages the cache of images.
Definition: image.cpp:109
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:195
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
Definition: utils.hpp:33