00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef EDITOR_MOUSE_ACTION_HPP
00017 #define EDITOR_MOUSE_ACTION_HPP
00018
00019 #include "editor/action/action_base.hpp"
00020 #include "editor/map/editor_map.hpp"
00021 #include "theme.hpp"
00022 #include "editor/palette/editor_palettes.hpp"
00023 #include "editor/palette/terrain_palettes.hpp"
00024 #include "editor/palette/empty_palette.hpp"
00025
00026 class CKey;
00027
00028 namespace editor {
00029
00030
00031
00032
00033
00034
00035
00036
00037 class mouse_action
00038 {
00039 public:
00040 mouse_action(common_palette& palette, const CKey& key)
00041 : previous_move_hex_()
00042 , key_(key)
00043 , toolbar_button_(NULL)
00044 , palette_(palette)
00045 {
00046 }
00047
00048 virtual ~mouse_action() {}
00049
00050 virtual bool has_context_menu() const;
00051
00052
00053
00054
00055 void move(editor_display& disp, const map_location& hex);
00056
00057
00058
00059
00060 void update_brush_highlights(editor_display& disp, const map_location& hex);
00061
00062
00063
00064
00065
00066 virtual std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
00067
00068
00069
00070
00071 virtual editor_action* click_left(editor_display& disp, int x, int y) = 0;
00072
00073
00074
00075
00076 virtual editor_action* click_right(editor_display& disp, int x, int y) = 0;
00077
00078
00079
00080
00081 virtual editor_action* drag_left(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
00082
00083
00084
00085
00086 virtual editor_action* drag_right(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
00087
00088
00089
00090
00091 virtual editor_action* drag_end(editor_display& disp, int x, int y);
00092
00093
00094 virtual editor_action* up_left(editor_display& disp, int x, int y);
00095
00096 virtual editor_action* up_right(editor_display& disp, int x, int y);
00097
00098
00099
00100
00101
00102 virtual editor_action* key_event(editor_display& disp, const SDL_Event& e);
00103
00104
00105
00106
00107
00108 void set_toolbar_button(const theme::menu* value) { toolbar_button_ = value; }
00109
00110
00111
00112
00113 const theme::menu* toolbar_button() const { return toolbar_button_; }
00114
00115
00116
00117
00118 common_palette& get_palette() { return palette_; }
00119
00120
00121
00122
00123 virtual void set_mouse_overlay(editor_display& disp);
00124
00125
00126 protected:
00127 bool has_alt_modifier() const;
00128 bool has_shift_modifier() const;
00129 bool has_ctrl_modifier() const;
00130
00131
00132
00133
00134 void set_terrain_mouse_overlay(editor_display& disp, t_translation::t_terrain fg,
00135 t_translation::t_terrain bg);
00136
00137
00138
00139
00140 map_location previous_move_hex_;
00141
00142
00143
00144
00145 const CKey& key_;
00146
00147 private:
00148
00149
00150
00151 const theme::menu* toolbar_button_;
00152
00153
00154
00155
00156 common_palette& palette_;
00157 };
00158
00159
00160
00161
00162 class brush_drag_mouse_action : public mouse_action
00163 {
00164 public:
00165 brush_drag_mouse_action(common_palette& palette, const brush* const * const brush, const CKey& key)
00166 : mouse_action(palette, key)
00167 , previous_drag_hex_()
00168 , brush_(brush)
00169 {
00170 }
00171
00172
00173
00174
00175 std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
00176
00177
00178
00179
00180 virtual editor_action* click_perform_left(editor_display& disp, const std::set<map_location>& hexes) = 0;
00181
00182
00183
00184
00185 virtual editor_action* click_perform_right(editor_display& disp, const std::set<map_location>& hexes) = 0;
00186
00187
00188
00189
00190 editor_action* click_left(editor_display& disp, int x, int y);
00191
00192
00193
00194
00195 editor_action* click_right(editor_display& disp, int x, int y);
00196
00197
00198
00199
00200
00201 editor_action* drag_left(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
00202
00203
00204
00205
00206
00207 editor_action* drag_right(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
00208
00209
00210
00211
00212
00213 editor_action* drag_end(editor_display& disp, int x, int y);
00214
00215 protected:
00216
00217 const brush& get_brush();
00218
00219
00220
00221
00222
00223 map_location previous_drag_hex_;
00224
00225 private:
00226
00227
00228
00229
00230
00231 template <editor_action* (brush_drag_mouse_action::*perform_func)(editor_display&, const std::set<map_location>&)>
00232 editor_action* drag_generic(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
00233
00234
00235
00236
00237
00238
00239
00240 const brush* const * const brush_;
00241 };
00242
00243
00244
00245
00246 class mouse_action_paint : public brush_drag_mouse_action
00247 {
00248 public:
00249 mouse_action_paint(
00250 const brush* const * const brush, const CKey& key, terrain_palette& palette)
00251 : brush_drag_mouse_action(palette, brush, key)
00252 , terrain_palette_(palette)
00253 {
00254 }
00255
00256
00257
00258
00259 editor_action* click_left(editor_display& disp, int x, int y);
00260
00261
00262
00263
00264 editor_action* click_right(editor_display& disp, int x, int y);
00265
00266
00267
00268
00269 editor_action* click_perform_left(editor_display& disp, const std::set<map_location>& hexes);
00270
00271
00272
00273
00274 editor_action* click_perform_right(editor_display& disp, const std::set<map_location>& hexes);
00275
00276 void set_mouse_overlay(editor_display& disp);
00277
00278 protected:
00279
00280 const terrain_palette& terrain_palette_;
00281
00282
00283
00284 };
00285
00286
00287
00288
00289 class mouse_action_select : public brush_drag_mouse_action
00290 {
00291 public:
00292 mouse_action_select(const brush* const * const brush, const CKey& key, empty_palette& palette)
00293 : brush_drag_mouse_action(palette, brush, key)
00294 {
00295 }
00296
00297
00298
00299
00300 std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
00301
00302
00303
00304
00305 editor_action* key_event(editor_display& disp, const SDL_Event& e);
00306
00307
00308
00309
00310 editor_action* click_perform_left(editor_display& disp, const std::set<map_location>& hexes);
00311
00312
00313
00314
00315 editor_action* click_perform_right(editor_display& disp, const std::set<map_location>& hexes);
00316
00317 virtual void set_mouse_overlay(editor_display& disp);
00318 };
00319
00320
00321
00322
00323 class mouse_action_paste : public mouse_action
00324 {
00325 public:
00326 mouse_action_paste(const map_fragment& paste, const CKey& key, common_palette& palette)
00327 : mouse_action(palette, key), paste_(paste)
00328 {
00329 }
00330
00331 bool has_context_menu() const;
00332
00333
00334
00335
00336 std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
00337
00338
00339
00340
00341 editor_action* click_left(editor_display& disp, int x, int y);
00342
00343
00344
00345
00346 editor_action* click_right(editor_display& disp, int x, int y);
00347
00348 virtual void set_mouse_overlay(editor_display& disp);
00349
00350 protected:
00351
00352
00353
00354 const map_fragment& paste_;
00355 };
00356
00357
00358
00359
00360 class mouse_action_fill : public mouse_action
00361 {
00362 public:
00363 mouse_action_fill(
00364
00365 const CKey& key, terrain_palette& terrain_palette)
00366 : mouse_action(terrain_palette, key)
00367 , terrain_palette_(terrain_palette)
00368
00369
00370 {
00371 }
00372
00373
00374
00375
00376 std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
00377
00378
00379
00380
00381 editor_action* click_left(editor_display& disp, int x, int y);
00382
00383
00384
00385
00386 editor_action* click_right(editor_display& disp, int x, int y);
00387
00388 virtual void set_mouse_overlay(editor_display& disp);
00389
00390 protected:
00391 const terrain_palette& terrain_palette_;
00392
00393
00394 };
00395
00396
00397
00398
00399 class mouse_action_starting_position : public mouse_action
00400 {
00401 public:
00402 mouse_action_starting_position(const CKey& key, empty_palette& palette)
00403 : mouse_action(palette, key), click_(false)
00404 {
00405 }
00406
00407
00408
00409
00410
00411
00412 editor_action* up_left(editor_display& disp, int x, int y);
00413
00414 editor_action* click_left(editor_display& disp, int x, int y);
00415
00416
00417
00418
00419 editor_action* up_right(editor_display& disp, int x, int y);
00420
00421 editor_action* click_right(editor_display& disp, int x, int y);
00422
00423 virtual void set_mouse_overlay(editor_display& disp);
00424
00425 private:
00426 bool click_;
00427 };
00428
00429
00430
00431 }
00432
00433 #endif