-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
mouse_action_map_label.cpp
136 lines (104 loc) · 4.12 KB
/
mouse_action_map_label.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
Copyright (C) 2008 - 2016 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "editor/action/mouse/mouse_action_map_label.hpp"
#include "editor/action/action_label.hpp"
#include "editor/editor_display.hpp"
#include "editor/map/context_manager.hpp"
#include <SDL_video.h>
#include "gui/dialogs/editor/edit_label.hpp"
#include "font/standard_colors.hpp"
#include "color.hpp"
namespace editor {
editor_action* mouse_action_map_label::click_left(editor_display& disp, int x, int y)
{
click_ = true;
map_location hex = disp.hex_clicked_on(x, y);
clicked_on_ = hex;
last_draged_ = hex;
return new editor_action_chain();
}
editor_action* mouse_action_map_label::drag_left(editor_display& disp, int x, int y
, bool& partial, editor_action* /*last_undo*/)
{
map_location hex = disp.hex_clicked_on(x, y);
/* Cursor is still on old hex field */
if (hex == last_draged_)
return nullptr;
click_ = false;
editor_action_chain* chain = nullptr;
const terrain_label* label = get_current_labels()->get_label(last_draged_);
if (label) {
partial = true;
chain = new editor_action_chain(new editor_action_label_delete(last_draged_));
chain->append_action(new editor_action_label(hex, label->text(), label->team_name(), label->color(),
label->visible_in_shroud(), label->visible_in_fog(), label->immutable(), label->category()));
}
last_draged_ = hex;
return chain;
}
editor_action* mouse_action_map_label::up_left(editor_display& disp, int x, int y)
{
if (!click_) return nullptr;
click_ = false;
const map_location hex = disp.hex_clicked_on(x, y);
if (!disp.get_map().on_board(hex)) {
return nullptr;
}
const terrain_label* old_label = editor::get_current_labels()->get_label(hex);
std::string label = old_label ? old_label->text() : "";
std::string team_name = old_label ? old_label->team_name() : "";
std::string category = old_label ? old_label->category() : "";
bool visible_shroud = old_label ? old_label->visible_in_shroud() : false;
bool visible_fog = old_label ? old_label->visible_in_fog() : true;
bool immutable = old_label ? old_label->immutable() : true;
color_t color = old_label ? old_label->color() : font::NORMAL_COLOR;
// TODO: remove once color_t is used everywhere
color_t c(color);
gui2::dialogs::editor_edit_label d(label, immutable, visible_fog, visible_shroud, c, category);
editor_action* a = nullptr;
if(d.show(disp.video())) {
a = new editor_action_label(hex, label, team_name, color
, visible_fog, visible_shroud, immutable, category);
update_brush_highlights(disp, hex);
}
return a;
}
editor_action* mouse_action_map_label::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
{
return nullptr;
}
editor_action* mouse_action_map_label::up_right(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
//TODO
// const terrain_label* clicked_label = disp.map().get_map_labels().get_label(hex);
//if (!clicked_label)
// return nullptr;
return new editor_action_label_delete(hex);
}
void mouse_action_map_label::set_mouse_overlay(editor_display& disp)
{
surface image60 = image::get_image("icons/action/editor-tool-label_60.png");
//TODO avoid hardcoded hex field size
surface image = create_neutral_surface(72,72);
SDL_Rect r = sdl::create_rect(6, 6, 0, 0);
sdl_blit(image60, nullptr, image, &r);
Uint8 alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
adjust_surface_alpha(image, alpha);
image = scale_surface(image, zoom, zoom);
disp.set_mouseover_hex_overlay(image);
}
} //end namespace editor