File: viewport.hpp

package info (click to toggle)
pingus 0.7.6-5.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 31,636 kB
  • sloc: cpp: 42,076; xml: 2,319; lisp: 521; ruby: 455; ansic: 365; objc: 248; sh: 247; makefile: 143; python: 15
file content (162 lines) | stat: -rw-r--r-- 4,490 bytes parent folder | download
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//  Pingus - A free Lemmings clone
//  Copyright (C) 2007 Jason Green <jave27@gmail.com>,
//                     Ingo Ruhnke <grumbel@gmx.de>
//
//  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 3 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; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef HEADER_PINGUS_EDITOR_VIEWPORT_HPP
#define HEADER_PINGUS_EDITOR_VIEWPORT_HPP

#include <boost/signals2.hpp>
#include <set>

#include "editor/selection.hpp"
#include "editor/editor_level.hpp"
#include "engine/display/graphic_context_state.hpp"
#include "engine/gui/rect_component.hpp"

class DrawingContext;
class SceneContext;

namespace Editor {

class LevelObj;
class EditorScreen;
class ContextMenu;

/** This class is where the actual level graphics will display in the
    level editor.  Objects can be added, deleted, moved, modified, etc. 
    inside of the Viewport */
class Viewport : public GUI::RectComponent 
{
private:        
  GraphicContextState state;
  std::unique_ptr<DrawingContext> drawing_context;

  /** The EditorScreen to which this viewport belongs */
  EditorScreen* editor;

  /** Whether or not Autoscrolling is turned on */
  bool autoscroll;

  /** Where the mouse is right now - used for autoscrolling */
  Vector2i mouse_world_pos;
  Vector2i mouse_screen_pos;

  /** Where the mouse started dragging from */
  Vector2i drag_world_pos;
  Vector2i drag_screen_pos;
  
  /** The currently selected LevelObjs */
  Selection selection;

  /** The region that is currently highlighted */
  Rect highlighted_area;

  /** There should only be 0 or 1 context menus on the screen */
  ContextMenu* context_menu;

  /** Whether or not the "snap-to-grid" functionality is on. */
  bool snap_to;

  /** What is the currently selected action that the mouse is doing */
  enum ActionType { NOTHING, HIGHLIGHTING, DRAGGING, SCROLLING } current_action;

  std::vector<Color> m_background_colors;
  std::vector<Color>::size_type  m_background_colors_idx;

public:
  /** Constructor
      @param e The EditorScreen to which this viewport belongs */
  Viewport(EditorScreen* e, const Rect& rect);

  /** Destructor */
  ~Viewport ();

  /** Draws all of the objects in the viewport */
  void draw(DrawingContext &gc);

  /** Update information about scrolling, etc. */
  void update(float delta);

  /** Returns whether or not the mouse is inside the viewport */
  bool is_at(int x, int y);

  /** Emitted when the pointer moved, x and y are the new pointer
      coordinates */
  void on_pointer_move (int x, int y);

  /** Refresh the list of objects (do when loading or creating a new level) */
  void refresh();
        
  /** Turns the "snap-to-grid" option on or off */
  void set_snap_to(bool s) { snap_to = s; }

  Vector2i get_scroll_pos() const;
  void     set_scroll_pos(const Vector2i& pos);

  /// Mouse actions
  void on_primary_button_press(int x, int y);
  void on_primary_button_release(int x, int y);

  void on_secondary_button_press(int x, int y);
  void on_secondary_button_release(int x, int y);

  void on_secondary_button_click(int x, int y);

  void on_key_pressed(const Input::KeyboardEvent& ev);

  void delete_selected_objects();
  void duplicate_selected_objects();

  void vflip_selected_objects();
  void hflip_selected_objects();

  void rotate_90_selected_objects();
  void rotate_270_selected_objects();

  void raise_objects();
  void lower_objects();

  void raise_objects_to_top();
  void lower_objects_to_bottom();

  void raise_objects_z_pos();
  void lower_objects_z_pos();

  void group_selection();
  void ungroup_selection();

  void move_objects(const Vector2i& offset);

  Vector2i screen2world(int x, int y) const;

  void update_layout();

  EditorLevel::Objects* get_objects();

  void clear_selection();

  boost::signals2::signal<void (const Selection&)> selection_changed;
private:
  Viewport();
  Viewport (const Viewport&);
  Viewport& operator= (const Viewport&);
};

} // Editor namespace

#endif

/* EOF */