ScummVM API documentation
gtextbox.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * aint32 with this program; if not, write to the Free Software
19  *
20  *
21  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_GTEXTBOX_H
27 #define SAGA2_GTEXTBOX_H
28 
29 namespace Saga2 {
30 
31 enum textBoxFlags {
32  // First 4 flags are the TextPositions flags for label placement
33  kTextBoxAlignRight = (1 << 4),
34  kTextBoxAlignCenter = (1 << 5),
35  kTextBoxNoFilter = (1 << 6), // let non-edit keys come through
36  kTextBoxStayActive = (1 << 7),
37  kTextBoxNoBevel = (1 << 8)
38 };
39 
40 // edit box defines
41 const int kEditLen = 35;
42 const int kNumEditLines = 50;
43 const int kTextPen = 12;
44 const int kTextDisable = 14;
45 const int kTextHilite = 11;
46 const int kTextBackground = 87;
47 const int kTextBackHilite = 211;
48 const int kCursorColor = 174;
49 const int kTextHeight = 10;
50 
51 const int32 kBlinkTime = 72 / 6;
52 const int16 kBlinkColor0 = 137;
53 const int16 kBlinkColor1 = 232;
54 const int16 kBlinkWide = 1;
55 
56 extern StaticRect editBaseRect;
57 
58 
59 /* ===================================================================== *
60  gTextBox class: Single line text-editing control
61  * ===================================================================== */
62 
63 // displays a text box and allows single line editing
64 class gTextBox : public gControl {
65 private:
66 
67  char **_fieldStrings;
68  char *_undoBuffer; // undo buffer for editing
69  bool _internalBuffer;
70 
71  // editor values
72  uint16 _maxLen,
73  _currentLen[kNumEditLines],
74  _exists[kNumEditLines],
75  _undoLen,
76  _cursorPos,
77  _anchorPos,
78  _scrollPixels;
79  uint16 _flags;
80 
81  // text display values
82  int8 _fontOffset;
83  int8 _linesPerPage;
84  int8 _index;
85  int8 _endLine;
86  int8 _oldMark;
87 
88  // font settings
89  gFont *_textFont;
90  gFont *_oldFont;
91  int8 _fontHeight;
92  int8 _fontColorFore;
93  int8 _fontColorBack;
94  int8 _fontColorHilite;
95  byte _fontColorBackHilite;
96  byte _cursorColor;
97  int32 _blinkStart;
98  int16 _blinkX;
99  int8 _blinkState;
100 
101 
102  // editing switch values
103  bool _displayOnly;
104  bool _editing;
105  Rect16 _editRect;
106  bool _hilit;
107  bool _noUndo;
108  bool _fullRedraw;
109  bool _inDrag;
110  bool _isActiveCtl;
111 
112  AppFunc *_onEnter;
113  AppFunc *_onEscape;
114 
115  gPanelList *_parent; // window
116 
117 protected:
118 
119  void prepareEdit(int which);
120  void revertEdit();
121  void commitEdit();
122  bool changed();
123 
124  void scroll(int8);
125 
126  void enSelect(int which);
127  void deSelect(bool commit = false);
128  void reSelect(int which);
129 
130  bool activate(gEventType why); // activate the control
131  void deactivate();
132 
133  bool pointerHit(gPanelMessage &msg);
134  void pointerDrag(gPanelMessage &msg);
135  void pointerRelease(gPanelMessage &msg);
136  bool keyStroke(gPanelMessage &msg);
137 
138  void selectionMove(int howMany = 1);
139 
140 
141  bool insertText(char *text, int length);
142  void setText(char *text);
143  void setEditExtent(const Rect16 &r);
144  void selectionUp(int howMany = 1) {
145  selectionMove(-howMany);
146  }
147  void selectionDown(int howMany = 1) {
148  selectionMove(howMany);
149  }
150  void drawAll(gPort &, const Point16 &, const Rect16 &);
151 
152  // Returns a pointer to the currently selected text of length
153  char *selectedText(int &length);
154  void handleTimerTick(int32 tick);
155 
156  void editRectFill(gPort &fillPort, gPen *pen);
157  void drawContents();
158 
159 public:
160 
161  gTextBox(gPanelList &list, // window
162  const Rect16 &box, // rectangle
163  gFont *font, // font specified for this box
164  int8 height, // height of the font
165  int8 FGColor, // foreground color of font
166  int8 BGColor, // background color of font
167  int8 HLColor, // hilite color of font
168  byte BGHLColor, // back ground hilite color
169  byte CRColor, // cusor color
170  const char *title, // title bar
171  const char *buffer, // buffer to edit
172  char **stringBufs,
173  uint16 length, // length of buffer
174  uint16 flg, // various flags
175  uint16 ident, // control ID
176  bool noEditing, // display text or allow edit
177  AppFunc *cmd = NULL, // application command func
178  AppFunc *cmdEnter = NULL, // Appfunc for enter key
179  AppFunc *cmdEscape = NULL); // Appfunc for escape key
180  ~gTextBox();
181 
182 
183  void drawClipped(gPort &, const Point16 &, const Rect16 &) {
184  drawClipped();
185  }
186  void drawClipped();
187  void draw() {
188  drawClipped(); // redraw the panel.
189  }
190 
191  bool tabSelect();
192 
193  virtual void timerTick(gPanelMessage &msg);
194 
195  void scrollUp();
196  void scrollDown();
197 
198  char *getLine(int8);
199  int8 getIndex() {
200  return _index;
201  }
202 
203  void killChanges() {
204  revertEdit();
205  }
206  void keepChanges() {
207  commitEdit();
208  }
209 
210  void choose(int which = 0) {
211  reSelect(which);
212  if (!isActive()) makeActive();
213  }
214 
215 };
216 
217 } // end of namespace Saga2
218 
219 #endif
Definition: actor.h:32
Definition: gdraw.h:178
Definition: rect.h:42
Definition: panel.h:255
Definition: gtextbox.h:64
Definition: panel.h:218
Definition: gdraw.h:111
Definition: rect.h:290
Definition: panel.h:406