guiPopUpCtrl.h

Engine/source/gui/controls/guiPopUpCtrl.h

More...

Classes:

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 _GUIPOPUPCTRL_H_
 25#define _GUIPOPUPCTRL_H_
 26
 27#ifndef _GUITEXTCTRL_H_
 28#include "gui/controls/guiTextCtrl.h"
 29#endif
 30#ifndef _GUITEXTLISTCTRL_H_
 31#include "gui/controls/guiTextListCtrl.h"
 32#endif
 33#ifndef _GUIBUTTONCTRL_H_
 34#include "gui/buttons/guiButtonCtrl.h"
 35#endif
 36#ifndef _GUIBACKGROUNDCTRL_H_
 37#include "gui/controls/guiBackgroundCtrl.h"
 38#endif
 39#ifndef _GUISCROLLCTRL_H_
 40#include "gui/containers/guiScrollCtrl.h"
 41#endif
 42class GuiPopUpMenuCtrl;
 43class GuiPopupTextListCtrl;
 44
 45class GuiPopUpBackgroundCtrl : public GuiControl
 46{
 47protected:
 48   GuiPopUpMenuCtrl *mPopUpCtrl;
 49   GuiPopupTextListCtrl *mTextList; 
 50public:
 51   GuiPopUpBackgroundCtrl(GuiPopUpMenuCtrl *ctrl, GuiPopupTextListCtrl* textList);
 52   void onMouseDown(const GuiEvent &event);
 53};
 54
 55class GuiPopupTextListCtrl : public GuiTextListCtrl
 56{
 57   private:
 58   typedef GuiTextListCtrl Parent;
 59
 60protected:
 61   GuiPopUpMenuCtrl *mPopUpCtrl;
 62
 63public:
 64   GuiPopupTextListCtrl(); // for inheritance
 65   GuiPopupTextListCtrl(GuiPopUpMenuCtrl *ctrl);
 66
 67   // GuiArrayCtrl overload:
 68   void onCellSelected(Point2I cell);
 69
 70   // GuiControl overloads:
 71   bool onKeyDown(const GuiEvent &event);
 72   void onMouseUp(const GuiEvent &event);
 73   void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver);
 74};
 75
 76class GuiPopUpMenuCtrl : public GuiTextCtrl
 77{
 78   typedef GuiTextCtrl Parent;
 79
 80public:
 81   struct Entry
 82   {
 83      char buf[256];
 84      S32 id;
 85      U16 ascii;
 86      U16 scheme;
 87      bool usesColorBox;   //  Added
 88      ColorI colorbox;     //  Added
 89   };
 90
 91   struct Scheme
 92   {
 93      U32      id;
 94      ColorI   fontColor;
 95      ColorI   fontColorHL;
 96      ColorI   fontColorSEL;
 97   };
 98
 99   bool mBackgroundCancel; //  Added
100
101protected:
102   GuiPopupTextListCtrl *mTl;
103   GuiScrollCtrl *mSc;
104   GuiPopUpBackgroundCtrl *mBackground;
105   Vector<Entry> mEntries;
106   Vector<Scheme> mSchemes;
107   S32 mSelIndex;
108   S32 mMaxPopupHeight;
109   F32 mIncValue;
110   F32 mScrollCount;
111   S32 mLastYvalue;
112   GuiEvent mEventSave;
113   S32 mRevNum;
114   bool mInAction;
115   bool mReplaceText;
116   bool mMouseOver; //  Added
117   bool mRenderScrollInNA; //  Added
118   bool mReverseTextList;  //  Added - Should we reverse the text list if we display up?
119   StringTableEntry mBitmapName; //  Added
120   Point2I mBitmapBounds; //  Added
121   GFXTexHandle mTextureNormal; //  Added
122   GFXTexHandle mTextureDepressed; //  Added
123   S32 mIdMax;
124
125   virtual void addChildren();
126   virtual void repositionPopup();
127
128public:
129   GuiPopUpMenuCtrl(void);
130   ~GuiPopUpMenuCtrl();   
131   GuiScrollCtrl::Region mScrollDir;
132   bool onWake(); //  Added
133   bool onAdd();
134   void onSleep();
135   void setBitmap(const char *name); //  Added
136   void sort();
137   void sortID(); //  Added
138   void addEntry(const char *buf, S32 id = -1, U32 scheme = 0);
139   void addScheme(U32 id, ColorI fontColor, ColorI fontColorHL, ColorI fontColorSEL);
140   void onRender(Point2I offset, const RectI &updateRect);
141   void onAction();
142   virtual void closePopUp();
143   void clear();
144   void clearEntry( S32 entry ); //  Added
145   void onMouseDown(const GuiEvent &event);
146   void onMouseUp(const GuiEvent &event);
147   void onMouseEnter(const GuiEvent &event); //  Added
148   void onMouseLeave(const GuiEvent &); //  Added
149   void setupAutoScroll(const GuiEvent &event);
150   void autoScroll();
151   bool onKeyDown(const GuiEvent &event);
152   void reverseTextList();
153   bool getFontColor(ColorI &fontColor, S32 id, bool selected, bool mouseOver);
154   bool getColoredBox(ColorI &boxColor, S32 id); //  Added
155   bool setEntryText( S32 id, const char* buf );
156
157   S32 getSelected();
158   void setSelected(S32 id, bool bNotifyScript = true);
159   void setFirstSelected(bool bNotifyScript = true); //  Added
160   void setNoneSelected(); //  Added
161   const char *getScriptValue();
162   const char *getTextById(S32 id);
163   S32 findText( const char* text );
164   S32 getNumEntries()   { return( mEntries.size() ); }
165   void replaceText(S32);
166
167   DECLARE_CONOBJECT( GuiPopUpMenuCtrl );
168   DECLARE_CATEGORY( "Gui Lists" );
169   DECLARE_DESCRIPTION( "A control that allows to select a value from a drop-down list." );
170   
171   static void initPersistFields(void);
172
173};
174
175#endif //_GUI_POPUPMENU_CTRL_H
176