guiFrameCtrl.h

Engine/source/gui/containers/guiFrameCtrl.h

More...

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

Public Typedefs

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   FrameDetail mFramesetDetails;
119   VectorPtr<FrameDetail*> mFrameDetails;
120   bool mAutoBalance;
121   S32   mFudgeFactor;
122
123   /* divider activation member variables */
124   Region mCurHitRegion;
125   Point2I mLocOnDivider;
126   S32 mCurVerticalHit;
127   S32 mCurHorizontalHit;
128
129   bool init(U32 columns, U32 rows, const U32 columnOffsets[], const U32 rowOffsets[]);
130
131   Region findHitRegion(const Point2I &point);
132   Region pointInAnyRegion(const Point2I &point);
133   S32 findResizableFrames(S32 indexes[]);
134   bool hitVerticalDivider(S32 x, const Point2I &point);
135   bool hitHorizontalDivider(S32 y, const Point2I &point);
136
137   virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
138   void rebalance(const Point2I &newExtent);
139
140   void computeSizes(bool balanceFrames = false);
141   void computeMovableRange(Region hitRegion, S32 vertHit, S32 horzHit, S32 numIndexes, const S32 indexes[], S32 ranges[]);
142
143   void drawDividers(const Point2I &offset);
144public:
145   U32 columns() const                                   { return(mColumnOffsets.size()); }
146   U32 rows() const                                      { return(mRowOffsets.size()); }
147   U32 borderWidth() const                               { return(mFramesetDetails.mBorderWidth); }
148   Vector<S32>* columnOffsets()                          { return(&mColumnOffsets); }
149   Vector<S32>* rowOffsets()                             { return(&mRowOffsets); }
150   FrameDetail* framesetDetails()                        { return(&mFramesetDetails); }
151
152   bool findFrameContents(S32 index, GuiControl **gc, FrameDetail **fd);
153
154   void frameBorderEnable(S32 index, const char *state = NULL);
155   void frameBorderMovable(S32 index, const char *state = NULL);
156   void frameMinExtent(S32 index, const Point2I &extent);
157   void framePadding(S32 index, const RectSpacingI &padding);
158   RectSpacingI getFramePadding(S32 index);
159
160   void balanceFrames()    { computeSizes(true); }
161   void updateSizes()      { computeSizes();     }
162
163   bool onWake();
164
165private:
166   GuiFrameSetCtrl(const GuiFrameSetCtrl &);
167   GuiFrameSetCtrl& operator=(const GuiFrameSetCtrl &);
168};
169
170typedef GuiFrameSetCtrl::FrameState GuiFrameState;
171DefineEnumType( GuiFrameState );
172
173//-----------------------------------------------------------------------------
174// x is the first value inside the next column, so the divider x-coords
175// precede x.
176inline bool GuiFrameSetCtrl::hitVerticalDivider(S32 x, const Point2I &point)
177{
178   return((point.x >= S32(x - mFramesetDetails.mBorderWidth)) && (point.x < x) && (point.y >= 0) && (point.y < S32(getHeight())));
179}
180
181//-----------------------------------------------------------------------------
182// y is the first value inside the next row, so the divider y-coords precede y.
183inline bool GuiFrameSetCtrl::hitHorizontalDivider(S32 y, const Point2I &point)
184{
185   return((point.x >= 0) && (point.x < S32(getWidth())) && (point.y >= S32(y - mFramesetDetails.mBorderWidth)) && (point.y < y));
186}
187
188#endif // _GUI_FRAME_CTRL_H
189