Game Develop Core: LayoutEditorCanvas.h Source File

| Game Develop Core Core library for developing platforms and tools compatible with Game Develop.

- Main Page
- Modules
- Classes

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Macros Groups Pages
LayoutEditorCanvas.h
Go to the documentation of this file.
1
5 #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
6 #ifndef LAYOUTEDITORCANVAS_H
7 #define LAYOUTEDITORCANVAS_H
8 //(*Headers(LayoutEditorCanvas)
9 #include <wx/panel.h>
10 //*)
11 #include <set>
12 #include <map>
13 #include <vector>
14 #include <boost/shared_ptr.hpp>
15 #include <SFML/Graphics.hpp>
16 #include <wx/menu.h>
17 #include <wx/ribbon/buttonbar.h>
18 #include <wx/gdicmn.h>
19 #include <wx/panel.h>
20 #include "GDCore/PlatformDefinition/LayoutEditorPreviewer.h"
21 namespace gd { class MainFrameWrapper; }
22 namespace gd { class InitialInstancesContainer; }
23 namespace gd { class InitialInstance; }
24 namespace gd { class LayoutEditorCanvasAssociatedEditor; }
25 namespace gd { class Project; }
26 namespace gd { class Layout; }
27 namespace gd { class Object; }
28 namespace gd { class LayoutEditorCanvasOptions; }
29 class wxWindow;
30 class wxRibbonButtonBar;
31 class wxRibbonPage;
32 class wxAuiManager;
33 class wxScrollBar;
34
35 namespace gd
36 {
37
49 class LayoutEditorCanvasGuiElement
50 {
51 public:
52 LayoutEditorCanvasGuiElement() : associatedInitialInstance(NULL) {};
53 virtual ~LayoutEditorCanvasGuiElement() {};
54
55 std::string name;
56 wxRect area;
57 InitialInstance * associatedInitialInstance;
58 };
59
66 class GD_CORE_API LayoutEditorCanvas: public wxPanel, public sf::RenderWindow
67 {
68 friend class InstancesRenderer;
69 public:
70
71 LayoutEditorCanvas(wxWindow* parent,
72 gd::Project & project,
73 gd::Layout & layout,
74 gd::InitialInstancesContainer & instances,
75 LayoutEditorCanvasOptions & options,
76 gd::MainFrameWrapper & mainFrameWrapper);
77 virtual ~LayoutEditorCanvas();
78
82 wxWindow * GetParentControl() { return parentControl; }
83
87 gd::Project & GetProject() { return project; }
88
92 gd::Layout & GetLayout() { return layout; }
93
97 gd::MainFrameWrapper & GetMainFrameWrapper() { return mainFrameWrapper; }
98
110 void AddAssociatedEditor(gd::LayoutEditorCanvasAssociatedEditor * editor);
111
116 void SetParentAuiManager(wxAuiManager * parentAuiManager_);
117
123 wxAuiManager * GetParentAuiManager() { return parentAuiManager; };
124
131 virtual void SetScrollbars(wxScrollBar * hScrollbar_, wxScrollBar * vScrollbar_) { hScrollbar = hScrollbar_; vScrollbar = vScrollbar_; }
132
137 void UpdateSize();
138
142 void ConnectEvents();
143
149 static wxRibbonButtonBar* CreateRibbonPage(wxRibbonPage * page);
150
158 void RecreateRibbonToolbar();
159
164 virtual void OnvScrollbarScroll(wxScrollEvent& event);
165
170 virtual void OnhScrollbarScroll(wxScrollEvent& event);
171
175 std::vector<gd::InitialInstance*> GetSelection();
176
180 void ClearSelection();
181
185 void AddObject(const std::string & objectName);
186
190 void AddObject(const std::string & objectName, float x, float y);
191
195 void SelectInstance(InitialInstance * instance);
196
200 void UnselectInstance(InitialInstance * instance);
201
205 void DeleteInstances(std::vector<InitialInstance *> instances);
206
210 virtual void EnsureVisible(const gd::InitialInstance & instance);
211
215 void SetCurrentLayer(const std::string & newLayer) { currentLayer = newLayer; }
216
220 const std::string & GetCurrentLayer() const { return currentLayer; }
221
225 bool IsEditing() const { return editing; }
226
230 bool PreviewPaused() const;
231
237 virtual void PausePreview();
238
242 void ReloadResources();
243
247 void GoToEditingState();
248
249 virtual sf::Vector2f GetInitialInstanceSize(gd::InitialInstance & instance) const;
250 virtual sf::Vector2f GetInitialInstanceOrigin(gd::InitialInstance & instance) const;
251
252 //(*Declarations(LayoutEditorCanvas)
253 //*)
254
255 protected:
256 //(*Identifiers(LayoutEditorCanvas)
257 //*)
258
259 //All ribbons identifiers
260 static const long idRibbonEditMode;
261 static const long idRibbonPreviewMode;
262 static const long idRibbonHelp;
263 static const long idRibbonObjectsEditor;
264 static const long idRibbonLayersEditor;
265 static const long idRibbonGrid;
266 static const long idRibbonWindowMask;
267 static const long idRibbonGridSetup;
268 static const long idRibbonUndo;
269 static const long idUndo10;
270 static const long idUndo20;
271 static const long idClearHistory;
272 static const long idRibbonRedo;
273 static const long idRibbonObjectsPositionList;
274 static const long idRibbonFullScreen;
275 static const long idRibbonOrigine;
276 static const long idRibbonOriginalZoom;
277 static const long ID_CUSTOMZOOMMENUITEM500;
278 static const long ID_CUSTOMZOOMMENUITEM200;
279 static const long ID_CUSTOMZOOMMENUITEM150;
280 static const long ID_CUSTOMZOOMMENUITEM100;
281 static const long ID_CUSTOMZOOMMENUITEM50;
282 static const long ID_CUSTOMZOOMMENUITEM25;
283 static const long ID_CUSTOMZOOMMENUITEM10;
284 static const long ID_CUSTOMZOOMMENUITEM5;
285
286 //Context menu identifiers
287 static const long ID_ADDOBJMENU;
288 static const long ID_DELOBJMENU;
289 static const long ID_PROPMENU;
290 static const long ID_LAYERUPMENU;
291 static const long ID_LAYERDOWNMENU;
292 static const long ID_COPYMENU;
293 static const long ID_CUTMENU;
294 static const long ID_PASTEMENU;
295 static const long ID_PASTESPECIALMENU;
296 static const long ID_CREATEOBJECTMENU;
297 static const long ID_UNLOCKMENU;
298 static const long ID_LOCKMENU;
299 std::map<long, std::string> idForPlatformsMenu;
300
301 //(*Handlers(LayoutEditorCanvas)
302 //*)
303
304 //Methods allowing to run SFML within the wxWidgets control
305 virtual void OnUpdate();
306 virtual void OnPaint(wxPaintEvent& event);
307 virtual void OnEraseBackground(wxEraseEvent& event);
308 virtual void OnIdle(wxIdleEvent&);
309 //Changing the state of the editor
310 virtual void OnPreviewBtClick( wxCommandEvent & event );
311 virtual void OnPreviewDropDownBtClick( wxRibbonButtonBarEvent & event );
312 virtual void OnEditionBtClick( wxCommandEvent & event );
313 //Others events
314 virtual void OnHelpBtClick( wxCommandEvent & event );
315 virtual void OnLeftDown( wxMouseEvent &event );
316 virtual void OnLeftUp( wxMouseEvent &event );
317 virtual void OnLeftDClick( wxMouseEvent &event );
318 virtual void OnKey( wxKeyEvent& evt );
319 virtual void OnKeyUp( wxKeyEvent& evt );
320 virtual void OnMiddleDown( wxMouseEvent &event );
321 virtual void OnMouseWheel( wxMouseEvent &event );
322 virtual void OnRightUp( wxMouseEvent &event );
323 virtual void OnMotion( wxMouseEvent &event );
324 virtual void OnGridBtClick( wxCommandEvent & event );
325 virtual void OnGridSetupBtClick( wxCommandEvent & event );
326 virtual void OnObjectsPositionList( wxCommandEvent & event );
327 virtual void OnClearHistorySelected( wxCommandEvent & event );
328 virtual void OnUndo10Selected(wxCommandEvent& event) {Undo(10);};
329 virtual void OnUndo20Selected(wxCommandEvent& event) {Undo(20);};
330 virtual void OnObjectsEditor( wxCommandEvent & event );
331 virtual void OnLayersEditor( wxCommandEvent & event );
332 virtual void OnUndoBtClick( wxCommandEvent & event );
333 virtual void OnUndoMoreBtClick( wxRibbonButtonBarEvent & event );
334 virtual void OnRedoBtClick( wxCommandEvent & event );
335 virtual void OnWindowMaskBtClick( wxCommandEvent & event );
336 virtual void OnFullScreenBtClick(wxCommandEvent& event);
337 virtual void OnGuiElementHovered(const LayoutEditorCanvasGuiElement & guiElement);
338 virtual void OnGuiElementPressed(const LayoutEditorCanvasGuiElement & guiElement);
339 virtual void OnGuiElementReleased(const LayoutEditorCanvasGuiElement & guiElement);
340 virtual void OnOrigineBtClick(wxCommandEvent & event );
341 virtual void OnZoomInitBtClick( wxCommandEvent & event );
342 virtual void OnZoomMoreBtClick(wxRibbonButtonBarEvent& evt);
343 virtual void OnCustomZoom5Selected(wxCommandEvent& event);
344 virtual void OnCustomZoom10Selected(wxCommandEvent& event);
345 virtual void OnCustomZoom25Selected(wxCommandEvent& event);
346 virtual void OnCustomZoom50Selected(wxCommandEvent& event);
347 virtual void OnCustomZoom100Selected(wxCommandEvent& event);
348 virtual void OnCustomZoom150Selected(wxCommandEvent& event);
349 virtual void OnCustomZoom200Selected(wxCommandEvent& event);
350 virtual void OnCustomZoom500Selected(wxCommandEvent& event);
351 virtual void OnPropObjSelected( wxCommandEvent & event );
352 virtual void OnLayerUpSelected( wxCommandEvent & event );
353 virtual void OnLayerDownSelected( wxCommandEvent & event );
354 virtual void OnCopySelected( wxCommandEvent & event );
355 virtual void OnCutSelected( wxCommandEvent & event );
356 virtual void OnPasteSelected( wxCommandEvent & event );
357 virtual void OnPasteSpecialSelected( wxCommandEvent & event );
358 virtual void OnDeleteObjectSelected( wxCommandEvent & event );
359 virtual void OnCreateObjectSelected( wxCommandEvent & event );
360 virtual void OnLockSelected( wxCommandEvent & event );
361 virtual void OnUnLockSelected( wxCommandEvent & event );
362 virtual void OnPreviewForPlatformSelected( wxCommandEvent & event );
363
364 virtual double GetMouseXOnLayout() const;
365 virtual double GetMouseYOnLayout() const;
366
367 //Rendering methods. The rendering during preview is done by previewScene.
368 void RenderEdittime();
369 void RenderGrid();
370 void AddSmallButtonGuiElement(std::vector < boost::shared_ptr<sf::Shape> > & target, const sf::Vector2f & position, const std::string & buttonName );
371 void DrawSelectionRectangleGuiElement(std::vector < boost::shared_ptr<sf::Shape> > & target, const sf::FloatRect & rectangle );
372 void DrawAngleButtonGuiElement(std::vector < boost::shared_ptr<sf::Shape> > & target, const sf::Vector2f & position, float angle );
373 void DrawHighlightRectangleGuiElement(std::vector < boost::shared_ptr<sf::Shape> > & target, const sf::FloatRect & rectangle );
374 sf::Vector2f ConvertToWindowCoordinates(float x, float y, const sf::View & view);
375
383 void AddGuiElement(LayoutEditorCanvasGuiElement element) { guiElements.push_back(element); };
384
389 void ClearAllGuiElements() { guiElements.clear(); };
390
395 virtual void CreateEditionRibbonTools();
396
401 InitialInstance * GetInitialInstanceUnderCursor(bool pickOnlyLockedInstances = false) { return GetInitialInstanceAtPosition(GetMouseXOnLayout(), GetMouseYOnLayout(), pickOnlyLockedInstances); };
402
407 InitialInstance * GetInitialInstanceAtPosition(double xPosition, double yPosition, bool pickOnlyLockedInstances = false);
408
413 void ChangesMade();
414
418 gd::Object * GetObjectLinkedToInitialInstance(gd::InitialInstance & instance) const;
419
423 virtual void Undo(unsigned int times = 1);
424
428 virtual void Redo(unsigned int times = 1);
429
433 void UpdateMouseResizeCursor(const std::string & currentDraggableBt);
434
435 void UpdateContextMenu();
436 void UpdateScrollbars();
437 void UpdateViewAccordingToZoomFactor();
438
439 void SendSelectionToLayer(const std::string & newLayerName);
440
441 gd::Project & project;
442 gd::Layout & layout;
443 gd::InitialInstancesContainer & instances;
444 LayoutEditorCanvasOptions & options;
445 gd::MainFrameWrapper & mainFrameWrapper;
446 std::set<LayoutEditorCanvasAssociatedEditor*> associatedEditors;
447 std::map<std::string, boost::shared_ptr<gd::LayoutEditorPreviewer> > previewers;
448 wxWindow * parentControl;
449 wxAuiManager * parentAuiManager;
450 wxScrollBar * hScrollbar;
451 wxScrollBar * vScrollbar;
452 wxMenu undoMenu;
453
454 sf::View editionView;
455 std::string currentDraggableBt;
456 std::map<gd::InitialInstance*, double> resizeOriginalWidths;
457 std::map<gd::InitialInstance*, double> resizeOriginalHeights;
458 sf::Vector2f resizeMouseStartPosition;
459 sf::Vector2f angleButtonCenter;
460 bool isMovingView;
461 sf::Vector2f movingViewMouseStartPosition;
462 sf::Vector2f movingViewStartPosition;
463 bool hasJustRightClicked;
464 bool ctrlPressed;
465 bool altPressed;
466 bool shiftPressed;
467 double oldMouseX;
468 double oldMouseY;
469 bool isMovingInstance;
470 static const float gapBetweenButtonsAndRectangle = 5;
471 static const float smallButtonSize = 5;
472 bool firstRefresh;
473
474 bool isSelecting;
475 wxRect selectionRectangle;
476 std::map <InitialInstance*, wxRealPoint > selectedInstances;
477 std::string currentLayer;
478
479 std::vector < boost::shared_ptr<gd::InitialInstancesContainer> > history;
480 std::vector < boost::shared_ptr<gd::InitialInstancesContainer> > redoHistory;
481 boost::shared_ptr<gd::InitialInstancesContainer> latestState;
482
483 std::vector<LayoutEditorCanvasGuiElement> guiElements;
484
485 //State
486 bool editing;
487 boost::shared_ptr<gd::LayoutEditorPreviewer> currentPreviewer;
488
489 wxMenu contextMenu;
490 wxMenu noObjectContextMenu;
491 wxMenu zoomMenu;
492 wxMenu platformsMenu;
493
494 DECLARE_EVENT_TABLE()
495 friend class InstancesInsideSelectionPicker;
496 friend class SmallestInstanceUnderCursorPicker;
497 };
498
499 }
500
501 #endif
502 #endif