Torque3D Documentation / _generateds / guiMLTextCtrl.h

guiMLTextCtrl.h

Engine/source/gui/controls/guiMLTextCtrl.h

More...

Classes:

Public Functions

GFX_DeclareTextureProfile(GFXMLTextureProfile )

Detailed Description

Public Functions

GFX_DeclareTextureProfile(GFXMLTextureProfile )

  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 _GUIMLTEXTCTRL_H_
 25#define _GUIMLTEXTCTRL_H_
 26
 27#ifndef _GUICONTROL_H_
 28#include "gui/core/guiControl.h"
 29#endif
 30
 31#ifndef _STRINGBUFFER_H_
 32#include "core/stringBuffer.h"
 33#endif
 34
 35class GFont;
 36class SFXTrack;
 37
 38GFX_DeclareTextureProfile(GFXMLTextureProfile);
 39class GuiMLTextCtrl : public GuiControl
 40{
 41   typedef GuiControl Parent;
 42
 43   //-------------------------------------- Public interfaces...
 44  public:
 45   enum Justification
 46   {
 47      LeftJustify,
 48      RightJustify,
 49      CenterJustify,
 50   };
 51
 52   struct Font {
 53      char *faceName;
 54      U32 faceNameLen;
 55      U32 size;
 56      Resource<GFont> fontRes;
 57      Font *next;
 58   };
 59
 60   struct Bitmap {
 61      char bitmapName[1024];
 62      U32 bitmapNameLen;
 63      GFXTexHandle bitmapObject;
 64      Bitmap *next;
 65   };
 66
 67   struct URL
 68   {
 69      bool mouseDown;
 70      U32 textStart;
 71      U32 len;
 72      bool noUnderline;
 73   };
 74
 75   struct Style
 76   {
 77      ColorI color;
 78      ColorI shadowColor;
 79      ColorI linkColor;
 80      ColorI linkColorHL;
 81      Point2I shadowOffset;
 82      Font *font;
 83      bool used;
 84      Style *next;
 85   };
 86
 87   struct Atom
 88   {
 89      U32 textStart;
 90      U32 len;
 91      U32 xStart;
 92      U32 yStart;
 93      U32 width;
 94      U32 baseLine;
 95      U32 descent;
 96      Style *style;
 97      bool isClipped;
 98
 99      URL *url;
100      Atom *next;
101   };
102
103   struct Line {
104      U32 y;
105      U32 height;
106      U32 divStyle;
107      U32 textStart;
108      U32 len;
109      Atom *atomList;
110      Line *next;
111   };
112
113   struct BitmapRef : public RectI
114   {
115      BitmapRef *nextBlocker;
116      U32 textStart;
117      U32 len;
118      Bitmap *bitmap;
119      BitmapRef *next;
120   };
121
122   struct LineTag {
123      U32 id;
124      S32 y;
125      LineTag *next;
126   };
127
128   GuiMLTextCtrl();
129   ~GuiMLTextCtrl();
130
131   DECLARE_CALLBACK( void, onURL, (const char* url));
132   DECLARE_CALLBACK( void, onResize, ( S32 width, S32 maxY ));
133
134   // Text retrieval functions
135   U32 getNumChars() const;
136   U32 getText(char* pBuffer, const U32 bufferSize) const;
137   U32 getWrappedText(char* pBuffer, const U32 bufferSize) const;
138   const char* getTextContent();
139   void insertChars(const char* inputChars,
140                    const U32   numInputChars,
141                    const U32   position);
142
143   // Text substitution functions
144   void setText(const char* textBuffer, const U32 numChars);
145   void addText(const char* textBuffer, const U32 numChars, bool reformat);
146
147   void setAlpha(F32 alpha) { mAlpha = alpha;}
148
149   bool setCursorPosition(const S32);
150   void ensureCursorOnScreen();
151
152   // Scroll functions
153   void scrollToTag( U32 id );
154   void scrollToTop();
155   void scrollToBottom();
156
157   virtual void reflow();
158
159   DECLARE_CONOBJECT(GuiMLTextCtrl);
160   DECLARE_CATEGORY( "Gui Text" );
161   DECLARE_DESCRIPTION( "A control that displays multiple lines of text." );
162   
163   static void initPersistFields();
164
165   void setScriptValue(const char *value);
166   const char *getScriptValue();
167
168   static char *stripControlChars(const char *inString);
169
170   //-------------------------------------- Protected Structures and constants
171  protected:
172   bool mIsEditCtrl;
173
174   U32 *mTabStops;
175   U32 mTabStopCount;
176   U32 mCurTabStop;
177
178   F32 mAlpha;
179
180   DataChunker mViewChunker;
181   DataChunker mResourceChunker;
182   Line *mLineList;
183   Bitmap *mBitmapList;
184   BitmapRef *mBitmapRefList;
185   Font *mFontList;
186   LineTag *mTagList;
187   bool mDirty;
188   Style *mCurStyle;
189
190   U32 mCurLMargin;
191   U32 mCurRMargin;
192   U32 mCurJustify;
193   U32 mCurDiv;
194   U32 mCurY;
195   U32 mCurClipX;
196   Atom *mLineAtoms;
197   Atom **mLineAtomPtr;
198
199   Atom *mEmitAtoms;
200   Atom **mEmitAtomPtr;
201
202   BitmapRef mSentinel;
203   Line **mLineInsert;
204   BitmapRef *mBlockList;
205   U32 mScanPos;
206   U32 mCurX;
207   U32 mMaxY;
208   URL *mCurURL;
209
210   URL *mHitURL;
211
212   void freeLineBuffers();
213   void freeResources();
214
215   Bitmap *allocBitmap(const char *bitmapName, U32 bitmapNameLen);
216   Font *allocFont(const char *faceName, U32 faceNameLen, U32 size);
217   LineTag *allocLineTag(U32 id);
218   void emitNewLine(U32 textStart);
219   Atom *buildTextAtom(U32 start, U32 len, U32 left, U32 right, URL *url);
220   void emitTextToken(U32 textStart, U32 len);
221   void emitBitmapToken(Bitmap *bmp, U32 textStart, bool bitmapBreak);
222   void processEmitAtoms();
223   Atom *splitAtomListEmit(Atom *list, U32 width);
224   void drawAtomText(bool sel, U32 start, U32 end, Atom *atom, Line *line, Point2I offset);
225   Atom *findHitAtom(const Point2I localCoords);
226   Style *allocStyle(Style *style);
227
228   static const U32 csmTextBufferGrowthSize;
229
230   //-------------------------------------- Data...
231  protected:
232   // Cursor position should always be <= mCurrTextSize
233   U32  mCursorPosition;
234
235   // Actual text data. The line buffer is rebuilt from the linear text
236   //  given a specific width.  TextBuffer is /not/ \0 terminated
237   StringBuffer mTextBuffer;
238   U32   mLineStart;
239   S32   mMaxBufferSize;
240   StringTableEntry mInitialText;
241
242   // Selection information
243   bool mSelectionActive;
244   U32  mSelectionStart;
245   U32  mSelectionEnd;
246
247   U32  mVertMoveAnchor;
248   bool mVertMoveAnchorValid;
249
250   S32     mSelectionAnchor;
251   Point2I mSelectionAnchorDropped;
252
253   // Font resource
254   Resource<GFont> mFont;
255
256   // Console settable parameters
257   S32 mLineSpacingPixels;
258   bool mAllowColorChars;
259   bool mUseURLMouseCursor;
260
261   // Too many chars sound:
262   SFXTrack*  mDeniedSound;
263
264   //-------------------------------------- Protected interface
265  protected:
266   // Inserting and deleting character blocks...
267   void deleteChars(const U32 rangeStart,
268                    const U32 rangeEnd);
269   void copyToClipboard(const U32 rangeStart,
270                     const U32 rangeEnd);
271
272   // Selection maintainence
273   bool isSelectionActive() const;
274   void clearSelection();
275
276   // Pixel -> text position mappings
277   S32 getTextPosition(const Point2I& localPosition);
278
279   // Gui control overrides
280   bool onWake();
281   void onSleep();
282   void onPreRender();
283   void onRender(Point2I offset, const RectI &updateRect);
284   void getCursorPositionAndColor(Point2I &cursorTop, Point2I &cursorBottom, ColorI &color);
285   void inspectPostApply();
286   void parentResized(const RectI& oldParentRect, const RectI& newParentRect);
287   bool onKeyDown(const GuiEvent& event);
288   void onMouseDown(const GuiEvent&);
289   void onMouseDragged(const GuiEvent&);
290   void onMouseUp(const GuiEvent&);
291
292   virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
293
294  public:
295   // Gui control overrides
296   bool onAdd();
297
298   void setSelectionStart( U32 start ) { clearSelection(); mSelectionStart = start; };
299   void setSelectionEnd( U32 end ) { mSelectionEnd = end;};
300   void setSelectionActive(bool active) { mSelectionActive = active; };
301   S32 getCursorPosition()  { return( mCursorPosition ); }
302
303   virtual bool resize(const Point2I &newPosition, const Point2I &newExtent);
304};
305
306#endif  // _H_GUIMLTEXTCTRL_
307