Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ActiveWindow.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: nGenEx.lib
6  FILE: ActiveWindow.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Active Window class (a window that knows how to draw itself)
13 */
14 
15 #ifndef ActiveWindow_h
16 #define ActiveWindow_h
17 
18 #include <vector>
19 #include "Types.h"
20 #include "Color.h"
21 #include "Geometry.h"
22 #include "Bitmap.h"
23 #include "Window.h"
24 #include "EventTarget.h"
25 #include "List.h"
26 #include "Text.h"
27 
28 // +--------------------------------------------------------------------+
29 
30 struct Poly;
31 struct Material;
32 struct VertexSet;
33 class Layout;
34 
35 // +--------------------------------------------------------------------+
36 
37 enum {
38  WIN_NO_FRAME = 0x0000,
39  WIN_BLACK_FRAME = 0x0001,
40  WIN_WHITE_FRAME = 0x0002,
41  WIN_THIN_FRAME = 0x0004,
42  WIN_THICK_FRAME = 0x0008,
43  WIN_RAISED_FRAME = 0x0010,
44  WIN_SUNK_FRAME = 0x0020,
45  WIN_TEXT_SHADOW = 0x0040,
46  WIN_FRAME_ONLY = 0x0080
47 };
48 
49 enum {
67 
72 
74 };
75 
76 // +--------------------------------------------------------------------+
77 
78 class ActiveWindow;
79 
80 struct AWEvent
81 {
82  static const char* TYPENAME() { return "AWEvent"; }
83 
84  AWEvent() : window(0), eid(0), x(0), y(0) { }
85  AWEvent(ActiveWindow* w, int e, int ax=0, int ay=0) : window(w), eid(e), x(ax), y(ay) { }
86 
87  int operator == (const AWEvent& e) const { return (window == e.window) &&
88  (eid == e.eid) &&
89  (x == e.x) &&
90  (y == e.y); }
91 
93  int eid;
94  int x;
95  int y;
96 };
97 
98 typedef void (*PFVAWE)(ActiveWindow*, AWEvent*);
99 
100 struct AWMap
101 {
102  static const char* TYPENAME() { return "AWMap"; }
103 
104  AWMap() : eid(0), client(0), func(0) { }
105  AWMap(int e, ActiveWindow* w, PFVAWE f) : eid(e), client(w), func(f) { }
106 
107  int operator == (const AWMap& m) const { return (eid == m.eid) &&
108  (client == m.client); }
109 
110  int eid;
113 };
114 
115 // +--------------------------------------------------------------------+
116 
117 class ActiveWindow : public Window,
118 public EventTarget
119 {
120 public:
121  static const char* TYPENAME() { return "ActiveWindow"; }
122 
123  ActiveWindow(Screen* s, int ax, int ay, int aw, int ah,
124  DWORD id=0, DWORD style=0, ActiveWindow* parent=0);
125  virtual ~ActiveWindow();
126 
127  int operator == (const ActiveWindow& w) const { return id == w.id; }
128 
129  // Operations:
130  virtual void Paint(); // blt to screen
131  virtual void Draw(); // refresh backing store
132  virtual void Show();
133  virtual void Hide();
134  virtual void MoveTo(const Rect& r);
135  virtual void UseLayout(const std::vector<DWORD>& min_x,
136  const std::vector<DWORD>& min_y,
137  const std::vector<float>& weight_x,
138  const std::vector<float>& weight_y);
139  virtual void UseLayout(const std::vector<float>& min_x,
140  const std::vector<float>& min_y,
141  const std::vector<float>& weight_x,
142  const std::vector<float>& weight_y);
143  virtual void UseLayout(int ncols,
144  int nrows,
145  int* min_x,
146  int* min_y,
147  float* weight_x,
148  float* weight_y);
149  virtual void DoLayout();
150 
151  // Event Target Interface:
152  virtual int OnMouseMove(int x, int y);
153  virtual int OnLButtonDown(int x, int y);
154  virtual int OnLButtonUp(int x, int y);
155  virtual int OnClick();
156  virtual int OnSelect();
157  virtual int OnRButtonDown(int x, int y);
158  virtual int OnRButtonUp(int x, int y);
159  virtual int OnMouseEnter(int x, int y);
160  virtual int OnMouseExit(int x, int y);
161  virtual int OnMouseWheel(int wheel);
162 
163  virtual int OnKeyDown(int vk, int flags);
164 
165  virtual const char* GetDescription() const { return desc; }
166 
167  // pseudo-events:
168  virtual int OnDragStart(int x, int y);
169  virtual int OnDragDrop(int x, int y, ActiveWindow* source);
170 
171  virtual ActiveWindow* FindControl(int x, int y) { return 0; }
172  virtual Rect TargetRect() const;
173 
174  virtual ActiveWindow* GetCapture();
175  virtual int SetCapture();
176  virtual int ReleaseCapture();
177 
178  // Property accessors:
179  virtual void SetFocus();
180  virtual void KillFocus();
181  virtual bool HasFocus() const { return focus; }
182 
183  void SetEnabled(bool e=true) { enabled = e; }
184  bool IsEnabled() const { return enabled; }
185  bool IsVisible() const { return shown; }
186 
187  DWORD GetID() const { return id; }
188  void SetStyle(DWORD s) { style = s; }
189  DWORD GetStyle() const { return style; }
190 
191  void SetText(const char* t);
192  void SetText(const Text& t);
193  void AddText(const char* t);
194  void AddText(const Text& t);
195  const Text& GetText() const { return text; }
196 
197  void SetAltText(const char* t) { alt_text = t; }
198  void SetAltText(const Text& t) { alt_text = t; }
199  const Text& GetAltText() const { return alt_text; }
200 
201  void SetTexture(Bitmap* bmp) { texture = bmp; }
202  Bitmap* GetTexture() { return texture; }
203  void SetMargins(const Insets& m);
204  Insets& GetMargins() { return margins; }
205  void SetTextInsets(const Insets& t);
207 
209  void SetCellInsets(const Insets& c);
211  void SetCells(int cx, int cy, int cw=1, int ch=1);
212  void SetCells(const Rect& r) { cells = r; }
213  Rect& GetCells() { return cells; }
214  void SetFixedWidth(int w) { fixed_width = w; }
215  int GetFixedWidth() const { return fixed_width; }
216  void SetFixedHeight(int h) { fixed_height = h; }
217  int GetFixedHeight() const { return fixed_height;}
218 
219  void SetAlpha(double a);
220  double GetAlpha() const { return alpha; }
221  void SetBackColor(Color c) { back_color = c; }
222  Color GetBackColor() const { return back_color; }
223  void SetBaseColor(Color c) { base_color = c; }
224  Color GetBaseColor() const { return base_color; }
225  void SetForeColor(Color c) { fore_color = c; }
226  Color GetForeColor() const { return fore_color; }
227  void SetSingleLine(bool a) { single_line = a; }
228  bool GetSingleLine() const { return single_line; }
229  void SetTextAlign(DWORD a);
230  DWORD GetTextAlign() const { return text_align; }
231  void SetTransparent(bool t) { transparent = t; }
232  bool GetTransparent() const { return transparent; }
233  void SetHidePartial(bool a) { hide_partial = a; }
234  bool GetHidePartial() const { return hide_partial;}
235 
236  void SetTabStop(int n, int x);
237  int GetTabStop(int n) const;
238 
239  void DrawText(const char* txt, int count, Rect& txt_rect, DWORD flags);
240 
241  // class properties:
242  static void SetSystemFont(Font* f);
243  static void SetSystemBackColor(Color c);
244  static void SetSystemForeColor(Color c);
245 
246  // callback function registration:
247  virtual void RegisterClient(int EID, ActiveWindow* client, PFVAWE callback);
248  virtual void UnregisterClient(int EID, ActiveWindow* client);
249  virtual void ClientEvent(int EID, int x=0, int y=0);
250 
251  // form context:
252  virtual ActiveWindow* GetForm() { return form; }
253  virtual void SetForm(ActiveWindow* f) { form = f; }
254  virtual bool IsFormActive() const;
255  virtual bool IsTopMost() const { return topmost; }
256  virtual void SetTopMost(bool t) { topmost = t; }
257 
258  virtual ActiveWindow* FindChild(DWORD id);
259  virtual ActiveWindow* FindChild(int x, int y);
260 
261 protected:
262  virtual Color ShadeColor(Color c, double shade);
263  virtual void AddChild(ActiveWindow* child);
264  virtual void DrawStyleRect(const Rect& r, int style);
265  virtual void DrawStyleRect(int x1, int y1, int x2, int y2, int style);
266  virtual void DrawTabbedText();
267  virtual void DrawTextureGrid();
268  virtual void CalcGrid();
269 
270  DWORD id;
271  DWORD style;
272  DWORD text_align;
274  bool focus;
275  bool enabled;
277  float alpha;
291  int tab[10];
292 
296  bool topmost;
297 
302 
303  int rows;
304  int cols;
308 
309  static Font* sys_font;
312 };
313 
314 #define DEF_MAP_CLIENT(cname, fname)\
315  void Map##cname##fname(ActiveWindow* client, AWEvent* event) \
316  { cname* c = (cname*) client; c->fname(event); }
317 
318 #define REGISTER_CLIENT(eid, ctrl, cname, fname)\
319  if (ctrl) ctrl->RegisterClient(eid, this, Map##cname##fname);
320 
321 #define UNREGISTER_CLIENT(eid, ctrl, cname)\
322  if (ctrl) ctrl->UnregisterClient(eid, this);
323 
324 #endif ActiveWindow_h
325