guiFrameCtrl.h
Engine/source/gui/containers/guiFrameCtrl.h
Classes:
class
A gui control allowing a window to be subdivided into panes, each of which displays a gui control child of the GuiFrameSetCtrl.
Public Defines
define
Public Typedefs
GuiFrameState
Public Functions
Detailed Description
Public Defines
GUI_FRAME_DEBUG()
Public Typedefs
typedef GuiFrameSetCtrl::FrameState GuiFrameState
Public Functions
DefineEnumType(GuiFrameState )
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 _GUIFRAMECTRL_H_ 25#define _GUIFRAMECTRL_H_ 26 27#ifndef _GUICONTAINER_H_ 28 #include "gui/containers/guiContainer.h" 29#endif 30 31 32// for debugging porpoises... 33#define GUI_FRAME_DEBUG 34// ...save the porpoises 35 36 37/// A gui control allowing a window to be subdivided into panes, 38/// each of which displays a gui control child of the 39/// GuiFrameSetCtrl. Each gui control child will have an associated 40/// FrameDetail through which frame-specific details can be 41/// assigned. Frame-specific values override the values specified 42/// for the entire frameset. 43/// 44/// Note that it is possible to have more children than frames, 45/// or more frames than children. In the former case, the extra 46/// children will not be visible (they are moved beyond the 47/// visible extent of the frameset). In the latter case, frames 48/// will be empty. 49/// 50/// If a frameset had two columns and two rows but only three 51/// gui control children they would be assigned to frames as 52/// follows: 53/// 1 | 2 54/// ----- 55/// 3 | 56/// 57/// The last frame would be blank. 58/// 59class GuiFrameSetCtrl : public GuiContainer 60{ 61private: 62 typedef GuiContainer Parent; 63public: 64 enum FrameState 65 { 66 FRAME_STATE_ON, // ON overrides OFF 67 FRAME_STATE_OFF, // OFF overrides AUTO 68 FRAME_STATE_AUTO, // AUTO == ON, unless overridden 69 70 NO_HIT = -1, 71 72 DEFAULT_BORDER_WIDTH = 4, 73 DEFAULT_COLUMNS = 1, 74 DEFAULT_ROWS = 1, 75 DEFAULT_MIN_FRAME_EXTENT = 64 76 }; 77 enum Region 78 { 79 VERTICAL_DIVIDER, 80 HORIZONTAL_DIVIDER, 81 DIVIDER_INTERSECTION, 82 NONE 83 }; 84 struct FrameDetail 85 { 86 U32 mBorderWidth; 87 ColorI mBorderColor; 88 S32 mBorderEnable; 89 S32 mBorderMovable; 90 Point2I mMinExtent; 91 RectSpacingI mPadding; 92 FrameDetail() { mBorderWidth = DEFAULT_BORDER_WIDTH; mBorderEnable = FRAME_STATE_AUTO; mBorderMovable = FRAME_STATE_AUTO; mMinExtent.set(DEFAULT_MIN_FRAME_EXTENT, DEFAULT_MIN_FRAME_EXTENT); mPadding.setAll( 0 ); } 93 }; 94 DECLARE_CONOBJECT(GuiFrameSetCtrl); 95 DECLARE_DESCRIPTION( "A container that allows to subdivide its space into rows and columns.\n" 96 "Child controls are assigned to the cells row by row." ); 97 static void initPersistFields(); 98 99 GuiFrameSetCtrl(); 100 GuiFrameSetCtrl(U32 columns, U32 rows, const U32 columnOffsets[] = NULL, const U32 rowOffsets[] = NULL); 101 virtual ~GuiFrameSetCtrl(); 102 103 void addObject(SimObject *obj); 104 void removeObject(SimObject *obj); 105 106 virtual bool resize(const Point2I &newPosition, const Point2I &newExtent); 107 108 virtual void onMouseDown(const GuiEvent &event); 109 virtual void onMouseUp(const GuiEvent &event); 110 virtual void onMouseDragged(const GuiEvent &event); 111 112 bool onAdd(); 113 void onRender(Point2I offset, const RectI &updateRect ); 114protected: 115 /* member variables */ 116 Vector<S32> mColumnOffsets; 117 Vector<S32> mRowOffsets; 118 GuiCursor *mMoveCursor; 119 GuiCursor *mUpDownCursor; 120 GuiCursor *mLeftRightCursor; 121 GuiCursor *mDefaultCursor; 122 FrameDetail mFramesetDetails; 123 VectorPtr<FrameDetail*> mFrameDetails; 124 bool mAutoBalance; 125 S32 mFudgeFactor; 126 127 /* divider activation member variables */ 128 Region mCurHitRegion; 129 Point2I mLocOnDivider; 130 S32 mCurVerticalHit; 131 S32 mCurHorizontalHit; 132 133 bool init(U32 columns, U32 rows, const U32 columnOffsets[], const U32 rowOffsets[]); 134 135 Region findHitRegion(const Point2I &point); 136 Region pointInAnyRegion(const Point2I &point); 137 S32 findResizableFrames(S32 indexes[]); 138 bool hitVerticalDivider(S32 x, const Point2I &point); 139 bool hitHorizontalDivider(S32 y, const Point2I &point); 140 141 virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent); 142 void rebalance(const Point2I &newExtent); 143 144 void computeSizes(bool balanceFrames = false); 145 void computeMovableRange(Region hitRegion, S32 vertHit, S32 horzHit, S32 numIndexes, const S32 indexes[], S32 ranges[]); 146 147 void drawDividers(const Point2I &offset); 148public: 149 U32 columns() const { return(mColumnOffsets.size()); } 150 U32 rows() const { return(mRowOffsets.size()); } 151 U32 borderWidth() const { return(mFramesetDetails.mBorderWidth); } 152 Vector<S32>* columnOffsets() { return(&mColumnOffsets); } 153 Vector<S32>* rowOffsets() { return(&mRowOffsets); } 154 FrameDetail* framesetDetails() { return(&mFramesetDetails); } 155 156 bool findFrameContents(S32 index, GuiControl **gc, FrameDetail **fd); 157 158 void frameBorderEnable(S32 index, const char *state = NULL); 159 void frameBorderMovable(S32 index, const char *state = NULL); 160 void frameMinExtent(S32 index, const Point2I &extent); 161 void framePadding(S32 index, const RectSpacingI &padding); 162 RectSpacingI getFramePadding(S32 index); 163 164 void balanceFrames() { computeSizes(true); } 165 void updateSizes() { computeSizes(); } 166 167 bool onWake(); 168 169private: 170 GuiFrameSetCtrl(const GuiFrameSetCtrl &); 171 GuiFrameSetCtrl& operator=(const GuiFrameSetCtrl &); 172}; 173 174typedef GuiFrameSetCtrl::FrameState GuiFrameState; 175DefineEnumType( GuiFrameState ); 176 177//----------------------------------------------------------------------------- 178// x is the first value inside the next column, so the divider x-coords 179// precede x. 180inline bool GuiFrameSetCtrl::hitVerticalDivider(S32 x, const Point2I &point) 181{ 182 return((point.x >= S32(x - mFramesetDetails.mBorderWidth)) && (point.x < x) && (point.y >= 0) && (point.y < S32(getHeight()))); 183} 184 185//----------------------------------------------------------------------------- 186// y is the first value inside the next row, so the divider y-coords precede y. 187inline bool GuiFrameSetCtrl::hitHorizontalDivider(S32 y, const Point2I &point) 188{ 189 return((point.x >= 0) && (point.x < S32(getWidth())) && (point.y >= S32(y - mFramesetDetails.mBorderWidth)) && (point.y < y)); 190} 191 192#endif // _GUI_FRAME_CTRL_H 193
