guiWindowCtrl.h
Engine/source/gui/containers/guiWindowCtrl.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _GUIWINDOWCTRL_H_ 25#define _GUIWINDOWCTRL_H_ 26 27#ifndef _GUICONTAINER_H_ 28 #include "gui/containers/guiContainer.h" 29#endif 30 31 32/// @addtogroup gui_container_group Containers 33/// 34/// @ingroup gui_group Gui System 35/// @{ 36class GuiWindowCtrl : public GuiContainer 37{ 38 public: 39 40 typedef GuiContainer Parent; 41 42 protected: 43 44 enum 45 { 46 /// Pixel distance across which snapping takes effect. 47 SnapDistance = 12 48 }; 49 50 /// Base indices for the button bitmap rects. Each button 51 /// bitmap is defined in each of the BitmapStates. 52 enum BitmapIndices 53 { 54 BmpClose, 55 BmpMaximize, 56 BmpNormal, 57 BmpMinimize, 58 59 BmpCount 60 }; 61 62 /// Button bitmap states. 63 enum BitmapStates 64 { 65 BmpDefault = 0, 66 BmpHilite, 67 BmpDown, 68 69 BmpStates 70 }; 71 72 /// Indices for non-button bitmap rects. 73 enum 74 { 75 BorderTopLeftKey = 12, 76 BorderTopRightKey, 77 BorderTopKey, 78 BorderTopLeftNoKey, 79 BorderTopRightNoKey, 80 BorderTopNoKey, 81 BorderLeft, 82 BorderRight, 83 BorderBottomLeft, 84 BorderBottom, 85 BorderBottomRight, 86 NumBitmaps 87 }; 88 89 /// Window Edge Bit Masks 90 /// 91 /// Edges can be combined to create a mask of multiple edges. 92 /// This is used for hit detection throughout this class. 93 enum Edges 94 { 95 edgeNone = 0, ///< No Edge 96 edgeTop = BIT(1), ///< Top Edge 97 edgeLeft = BIT(2), ///< Left Edge 98 edgeRight = BIT(3), ///< Right Edge 99 edgeBottom = BIT(4) ///< Bottom Edge 100 }; 101 102 /// @name Flags 103 /// @{ 104 105 /// Allow resizing width of window. 106 bool mResizeWidth; 107 108 /// Allow resizing height of window. 109 bool mResizeHeight; 110 111 /// Allow moving window. 112 bool mCanMove; 113 114 /// Display close button. 115 bool mCanClose; 116 117 /// Display minimize button. 118 bool mCanMinimize; 119 120 /// Display maximize button. 121 bool mCanMaximize; 122 123 /// 124 bool mCanCollapse; 125 126 bool mCanDock; ///< Show a docking button on the title bar? 127 bool mEdgeSnap; ///< Should this window snap to other windows edges? 128 129 /// @} 130 131 bool mCloseButtonPressed; 132 bool mMinimizeButtonPressed; 133 bool mMaximizeButtonPressed; 134 135 bool mRepositionWindow; 136 bool mResizeWindow; 137 bool mSnapSignal; 138 139 StringTableEntry mCloseCommand; 140 141 /// Window title string. 142 String mText; 143 144 S32 mResizeEdge; ///< Resizing Edges Mask (See Edges Enumeration) 145 146 S32 mTitleHeight; 147 148 F32 mResizeMargin; 149 150 bool mMouseMovingWin; 151 bool mMouseResizeWidth; 152 bool mMouseResizeHeight; 153 bool mMinimized; 154 bool mMaximized; 155 156 Point2I mMousePosition; 157 Point2I mMouseDownPosition; 158 RectI mOrigBounds; 159 RectI mStandardBounds; 160 161 RectI mCloseButton; 162 RectI mMinimizeButton; 163 RectI mMaximizeButton; 164 S32 mMinimizeIndex; 165 S32 mTabIndex; 166 167 void positionButtons(void); 168 169 RectI *mBitmapBounds; //bmp is [3*n], bmpHL is [3*n + 1], bmpNA is [3*n + 2] 170 GFXTexHandle mTextureObject; 171 172 /// @name Collapsing 173 /// @{ 174 175 typedef Vector< GuiWindowCtrl*> CollapseGroupNumVec; 176 177 S32 mCollapseGroup; 178 S32 mCollapseGroupNum; 179 S32 mPreCollapsedYExtent; 180 S32 mPreCollapsedYMinExtent; 181 182 bool mIsCollapsed; 183 bool mIsMouseResizing; 184 185 S32 getCollapseGroupNum() { return mCollapseGroupNum; } 186 187 void moveFromCollapseGroup(); 188 void moveWithCollapseGroup(Point2I windowPosition); 189 190 bool resizeCollapseGroup(bool resizeX, bool resizeY, Point2I resizePos, Point2I resizeWidth); 191 void refreshCollapseGroups(); 192 193 void handleCollapseGroup(); 194 195 /// @} 196 197 /// @name Callbacks 198 /// @{ 199 200 DECLARE_CALLBACK( void, onClose, () ); 201 DECLARE_CALLBACK( void, onMinimize, () ); 202 DECLARE_CALLBACK( void, onMaximize, () ); 203 DECLARE_CALLBACK( void, onCollapse, () ); 204 DECLARE_CALLBACK( void, onRestore, () ); 205 206 /// @} 207 208 public: 209 210 GuiWindowCtrl(); 211 212 bool isMinimized(S32 &index); 213 214 virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent); 215 216 void setFont(S32 fntTag); 217 218 void setCloseCommand(const char *newCmd); 219 220 GuiControl* findHitControl (const Point2I &pt, S32 initialLayer = -1 ); 221 S32 findHitEdges( const Point2I &globalPoint ); 222 void getSnappableWindows( Vector<GuiWindowCtrl*> &windowOutVector, bool canCollapse = false ); 223 bool resize( const Point2I &newPosition, const Point2I &newExtent ); 224 225 //only cycle tabs through the current window, so overwrite the method 226 GuiControl* findNextTabable(GuiControl *curResponder, bool firstCall = true); 227 GuiControl* findPrevTabable(GuiControl *curResponder, bool firstCall = true); 228 229 S32 getTabIndex(void) { return mTabIndex; } 230 void selectWindow(void); 231 232 //// 233 const RectI getClientRect(); 234 235 /// Mutators for window properties from code. 236 /// Using setDataField is a bit overkill. 237 void setMobility( bool canMove, bool canClose, bool canMinimize, bool canMaximize, bool canDock, bool edgeSnap ) 238 { 239 mCanMove = canMove; 240 mCanClose = canClose; 241 mCanMinimize = canMinimize; 242 mCanMaximize = canMaximize; 243 mCanDock = canDock; 244 mEdgeSnap = edgeSnap; 245 } 246 247 /// Mutators for window properties from code. 248 /// Using setDataField is a bit overkill. 249 void setCanResize( bool canResizeWidth, bool canResizeHeight ) 250 { 251 mResizeWidth = canResizeWidth; 252 mResizeHeight = canResizeHeight; 253 } 254 255 /// Set the text on the window title bar. 256 void setText( const String& text ) 257 { 258 mText = text; 259 } 260 261 /// @name Collapsing 262 /// @{ 263 264 void setCollapseGroup( bool state ); 265 void toggleCollapseGroup(); 266 void moveToCollapseGroup( GuiWindowCtrl* hitWindow, bool orientation ); 267 268 /// @} 269 270 // GuiContainer. 271 virtual bool onWake(); 272 virtual void onSleep(); 273 virtual void parentResized(const RectI &oldParentRect, const RectI &newParentRect); 274 virtual void onMouseDown(const GuiEvent &event); 275 virtual void onMouseDragged(const GuiEvent &event); 276 virtual void onMouseUp(const GuiEvent &event); 277 virtual void onMouseMove(const GuiEvent &event); 278 virtual bool onKeyDown(const GuiEvent &event); 279 virtual void onRender(Point2I offset, const RectI &updateRect); 280 281 DECLARE_CONOBJECT( GuiWindowCtrl ); 282 DECLARE_DESCRIPTION( "A control that shows an independent window inside the canvas." ); 283 284 static void initPersistFields(); 285}; 286/// @} 287 288#endif //_GUI_WINDOW_CTRL_H 289