The Battle for Wesnoth  1.13.4+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 - 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 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
18 
21 
22 #include <SDL_video.h>
23 
25 
26 namespace editor {
27 
29 {
30  click_ = true;
31  map_location hex = disp.hex_clicked_on(x, y);
32  clicked_on_ = hex;
33  last_draged_ = hex;
34  return new editor_action_chain();
35 }
36 
38  , bool& partial, editor_action* /*last_undo*/)
39 {
40  map_location hex = disp.hex_clicked_on(x, y);
41 
42  /* Cursor is still on old hex field */
43  if (hex == last_draged_)
44  return nullptr;
45  click_ = false;
46 
47  editor_action_chain* chain = nullptr;
49 
50 
51  if (label) {
52  partial = true;
54  chain->append_action(new editor_action_label(hex, label->text(), label->team_name(), label->color(),
55  label->visible_in_shroud(), label->visible_in_fog(), label->immutable(), label->category()));
56  }
57 
58  last_draged_ = hex;
59  return chain;
60 }
61 
63 {
64  if (!click_) return nullptr;
65  click_ = false;
66 
67  const map_location hex = disp.hex_clicked_on(x, y);
68  if (!disp.get_map().on_board(hex)) {
69  return nullptr;
70  }
71 
72  const terrain_label* old_label = editor::get_current_labels()->get_label(hex);
73  std::string label = old_label ? old_label->text() : "";
74  std::string team_name = old_label ? old_label->team_name() : "";
75  std::string category = old_label ? old_label->category() : "";
76  bool visible_shroud = old_label ? old_label->visible_in_shroud() : false;
77  bool visible_fog = old_label ? old_label->visible_in_fog() : true;
78  bool immutable = old_label ? old_label->immutable() : true;
79  SDL_Color color = old_label ? old_label->color() : font::NORMAL_COLOR;
80 
81  gui2::teditor_edit_label d(label, immutable, visible_fog, visible_shroud, color, category);
82 
83  editor_action* a = nullptr;
84  if(d.show(disp.video())) {
85  a = new editor_action_label(hex, label, team_name, color
86  , visible_fog, visible_shroud, immutable, category);
87  update_brush_highlights(disp, hex);
88  }
89  return a;
90 }
91 
93 {
94  return nullptr;
95 }
96 
98 {
99  map_location hex = disp.hex_clicked_on(x, y);
100 
101  //TODO
102 // const terrain_label* clicked_label = disp.map().get_map_labels().get_label(hex);
103  //if (!clicked_label)
104  // return nullptr;
105 
106  return new editor_action_label_delete(hex);
107 }
108 
110 {
111  surface image60 = image::get_image("icons/action/editor-tool-label_60.png");
112 
113  //TODO avoid hardcoded hex field size
115 
116  SDL_Rect r = sdl::create_rect(6, 6, 0, 0);
117  blit_surface(image60, nullptr, image, &r);
118 
119  Uint8 alpha = 196;
120  int size = image->w;
121  int zoom = static_cast<int>(size * disp.get_zoom_factor());
122 
123  // Add the alpha factor and scale the image
124  image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
125  disp.set_mouseover_hex_overlay(image);
126 }
127 
128 
129 } //end namespace editor
map_labels * get_current_labels()
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
Editor action classes.
void append_action(editor_action *a)
Add an action at the end of the chain.
Definition: action.cpp:113
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
Definition: dialog.cpp:34
editor_action * up_left(editor_display &disp, int x, int y)
Left click displays a dialog that is used for entering the label string.
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
Container action wrapping several actions into one.
Definition: action.hpp:79
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
#define d
const SDL_Color NORMAL_COLOR
Definition: font.cpp:564
bool immutable() const
Definition: label.cpp:454
const std::string & team_name() const
Definition: label.cpp:439
void blit_surface(const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
Definition: utils.cpp:2185
const SDL_Color & color() const
Definition: label.cpp:464
const t_string & text() const
Definition: label.cpp:419
const std::string & category() const
Definition: label.cpp:434
editor_action * click_right(editor_display &disp, int x, int y)
A click, possibly the beginning of a drag.
editor_action * drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Drag operation.
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize)
Definition: utils.cpp:1202
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
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...
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
GLuint color
Definition: glew.h:5801
const terrain_label * get_label(const map_location &loc, const std::string &team_name) const
Definition: label.cpp:97
Encapsulates the map of the game.
Definition: location.hpp:38
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.cpp:449
Base class for all editor actions.
Definition: action_base.hpp:41
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
bool visible_in_fog() const
Definition: label.cpp:444
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
editor_action * click_left(editor_display &disp, int x, int y)
A click, possibly the beginning of a drag.
GLsizeiptr size
Definition: glew.h:1649
To store label data Class implements logic for rendering.
Definition: label.hpp:103
const gamemap & get_map() const
Definition: display.hpp:92
this module manages the cache of images.
Definition: image.cpp:75
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:202
GLsizei const GLcharARB ** string
Definition: glew.h:4503