1 #pragma once
2 
3 #include <list>
4 
5 #include "iclipper.h"
6 #include "iregistry.h"
7 #include "preferencesystem.h"
8 
9 #include "XYWnd.h"
10 
11 namespace {
12 const std::string RKEY_CHASE_MOUSE = "user/ui/xyview/chaseMouse";
13 const std::string RKEY_CAMERA_XY_UPDATE = "user/ui/xyview/camXYUpdate";
14 const std::string RKEY_SHOW_CROSSHAIRS = "user/ui/xyview/showCrossHairs";
15 const std::string RKEY_SHOW_GRID = "user/ui/xyview/showGrid";
16 const std::string RKEY_SHOW_SIZE_INFO = "user/ui/xyview/showSizeInfo";
17 const std::string RKEY_SHOW_ENTITY_ANGLES = "user/ui/xyview/showEntityAngles";
18 const std::string RKEY_SHOW_ENTITY_NAMES = "user/ui/xyview/showEntityNames";
19 const std::string RKEY_SHOW_BLOCKS = "user/ui/xyview/showBlocks";
20 const std::string RKEY_SHOW_COORDINATES = "user/ui/xyview/showCoordinates";
21 const std::string RKEY_SHOW_OUTLINE = "user/ui/xyview/showOutline";
22 const std::string RKEY_SHOW_AXES = "user/ui/xyview/showAxes";
23 const std::string RKEY_SHOW_WORKZONE = "user/ui/xyview/showWorkzone";
24 const std::string RKEY_DEFAULT_BLOCKSIZE = "user/ui/xyview/defaultBlockSize";
25 const std::string RKEY_ALWAYS_CAULK_FOR_NEW_BRUSHES = "user/ui/xyview/alwaysCaulkForNewBrushes";
26 const std::string RKEY_CAULK_TEXTURE = "user/ui/xyview/caulkTexture";
27 
28 typedef std::list<XYWnd*> XYWndList;
29 }
30 
31 class XYWndManager: public RegistryKeyObserver, public PreferenceConstructor
32 {
33 		// The list containing the pointers to all the allocated views
34 		XYWndList _XYViews;
35 
36 		XYWnd* _activeXY;
37 
38 		// True, if the view is moved when the mouse cursor exceeds the view window borders
39 		bool _chaseMouse;
40 
41 		bool _camXYUpdate;
42 
43 		// The various display settings for xyviews
44 		bool _showCrossHairs;
45 		bool _showGrid;
46 		bool _showSizeInfo;
47 		bool _showBlocks;
48 		bool _showCoordinates;
49 		bool _showOutline;
50 		bool _showAxes;
51 		bool _showWorkzone;
52 		bool _alwaysCaulkForNewBrushes;
53 
54 		std::string _caulkTexture;
55 
56 		unsigned int _defaultBlockSize;
57 
58 		GtkWindow* _globalParentWindow;
59 
60 	public:
61 
62 		// Constructor
63 		XYWndManager ();
64 
65 		// Destructor, calls destroy to free all remaining views
66 		~XYWndManager ();
67 
68 		// The callback that gets called on registry key changes
69 		void keyChanged (const std::string& changedKey, const std::string& newValue);
70 
71 		// Returns the state of the xy view preferences
72 		bool chaseMouse () const;
73 		bool camXYUpdate () const;
74 		bool showCrossHairs() const;
75 		bool showGrid() const;
76 		bool showBlocks() const;
77 		bool showCoordinates() const;
78 		bool showOutline() const;
79 		bool showAxes() const;
80 		bool showWorkzone() const;
81 		bool showSizeInfo() const;
82 		bool alwaysCaulkForNewBrushes() const;
83 
84 		std::string getCaulkTexture() const;
85 
86 		unsigned int defaultBlockSize() const;
87 
88 		// Passes a queueDraw() call to each allocated view
89 		void updateAllViews ();
90 
91 		// Register the commands and capture the renderer states
92 		void construct();
93 
94 		// Zooms the currently active view in/out
95 		void zoomIn();
96 		void zoomOut();
97 
98 		// Free all the allocated views from the heap
99 		void destroy ();
100 
101 		// Release the shader states
102 		void destroyViews ();
103 
104 		XYWnd* getActiveXY () const;
105 		void setActiveXY (XYWnd* wnd);
106 
107 		// Shortcut commands for connect view the EventManager
108 		void setActiveViewXY(); // top view
109 		void setActiveViewXZ(); // side view
110 		void setActiveViewYZ(); // front view
111 		void splitViewFocus(); // Re-position all available views
112 		void zoom100(); // Sets the scale of all windows to 1
113 		void focusActiveView(); // sets the focus of the active view
114 
115 		// Sets the origin of all available views
116 		void setOrigin (const Vector3& origin);
117 
118 		// Sets the scale of all available views
119 		void setScale (float scale);
120 
121 		// Positions the view of all available views / the active view
122 		void positionAllViews (const Vector3& origin);
123 		void positionView (const Vector3& origin);
124 
125 		// Returns the view type of the currently active view
126 		EViewType getActiveViewType () const;
127 		void setActiveViewType (EViewType viewType);
128 
129 		void toggleActiveView ();
130 
131 		// Retrieves the pointer to the first view matching the given view type
132 		// @returns: NULL if no matching window could be found, the according pointer otherwise
133 		XYWnd* getView (EViewType viewType);
134 
135 		// Allocates a new XY view on the heap and returns its pointer
136 		XYWnd* createXY ();
137 
138 		// Creates a new floating XY View transient to the global parent window
139 		void createOrthoView(EViewType viewType);
140 
141 		// Creates a new orthoview
142 		void createNewOrthoView();
143 
144 		// Deletes the specified view
145 		void destroyOrthoView(XYWnd* xyWnd);
146 
147 		// Determines the global parent the xyviews are children of
148 		void setGlobalParentWindow(GtkWindow* globalParentWindow);
149 
150 		/* greebo: This function determines the point currently being "looked" at, it is used for toggling the ortho views
151 		 * If something is selected the center of the selection is taken as new origin, otherwise the camera
152 		 * position is considered to be the new origin of the toggled orthoview. */
153 		Vector3 getFocusPosition();
154 
155 		// Construct the orthoview preference page and add it to the given group
156 		void constructPreferencePage (PreferenceGroup& group);
157 
158 		// Registers all the XY commands in the EventManager
159 		void registerCommands();
160 
161 	private:
162 		// The GTK callback to catch the delete-event of orthoviews
163 		static gboolean onDeleteOrthoView(GtkWidget *widget, GdkEvent *event, gpointer data);
164 }; // class XYWndManager
165 
166 // Use this method to access the global XYWnd manager class
167 XYWndManager& GlobalXYWnd ();
168