~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/gui/Widget.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna, Franczen Attila, Luca Falavigna
  • Date: 2008-11-08 12:04:12 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20081108120412-w6xq87vzgokstfey
Tags: 2.6.1-0ubuntu1
[ Franczen Attila ]
* New upstream release (LP: #183571).
* Updated policy to 3.8.0.

[ Luca Falavigna ]
* debian/patches/gcc-4.3: fix FTBFS with gcc-4.3 compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
//  SS  SS   tt   ee      ll   ll  aa  aa
9
9
//   SSSS     ttt  eeeee llll llll  aaaaa
10
10
//
11
 
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
 
11
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
12
12
//
13
13
// See the file "license" for information on usage and redistribution of
14
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
15
//
16
 
// $Id: Widget.hxx,v 1.49 2006/03/25 00:34:17 stephena Exp $
 
16
// $Id: Widget.hxx,v 1.61 2008/05/11 21:18:35 stephena Exp $
17
17
//
18
18
//   Based on code from ScummVM - Scumm Interpreter
19
19
//   Copyright (C) 2002-2004 The ScummVM project
26
26
 
27
27
#include <assert.h>
28
28
 
29
 
#include "OSystem.hxx"
 
29
#include "bspf.hxx"
 
30
 
 
31
#include "Array.hxx"
 
32
#include "Event.hxx"
 
33
#include "Font.hxx"
30
34
#include "FrameBuffer.hxx"
31
35
#include "GuiObject.hxx"
32
 
#include "GuiUtils.hxx"
33
 
#include "Array.hxx"
 
36
#include "OSystem.hxx"
34
37
#include "Rect.hxx"
35
 
#include "Font.hxx"
36
 
#include "bspf.hxx"
37
38
 
38
39
enum {
39
 
  WIDGET_ENABLED      = 1 << 0,
40
 
  WIDGET_INVISIBLE    = 1 << 1,
41
 
  WIDGET_HILITED      = 1 << 2,
42
 
  WIDGET_BORDER       = 1 << 3,
43
 
  WIDGET_INV_BORDER   = 1 << 4,
44
 
  WIDGET_CLEARBG      = 1 << 5,
45
 
  WIDGET_TRACK_MOUSE  = 1 << 6,
46
 
  WIDGET_RETAIN_FOCUS = 1 << 7,
47
 
  WIDGET_NODRAW_FOCUS = 1 << 8,
48
 
  WIDGET_STICKY_FOCUS = 1 << 9,
49
 
  WIDGET_WANTS_TAB    = 1 << 10,
50
 
  WIDGET_WANTS_EVENTS = 1 << 11
 
40
  WIDGET_ENABLED       = 1 << 0,
 
41
  WIDGET_INVISIBLE     = 1 << 1,
 
42
  WIDGET_HILITED       = 1 << 2,
 
43
  WIDGET_BORDER        = 1 << 3,
 
44
  WIDGET_CLEARBG       = 1 << 4,
 
45
  WIDGET_TRACK_MOUSE   = 1 << 5,
 
46
  WIDGET_RETAIN_FOCUS  = 1 << 6,
 
47
  WIDGET_WANTS_TAB     = 1 << 7,
 
48
  WIDGET_WANTS_RAWDATA = 1 << 8
51
49
};
52
50
 
53
51
enum {
54
 
  kStaticTextWidget = 'TEXT',
55
 
  kEditTextWidget   = 'EDIT',
56
 
  kButtonWidget     = 'BTTN',
57
 
  kCheckboxWidget   = 'CHKB',
58
 
  kSliderWidget     = 'SLDE',
59
 
  kListWidget       = 'LIST',
60
 
  kScrollBarWidget  = 'SCRB',
61
 
  kPopUpWidget      = 'POPU',
62
 
  kTabWidget        = 'TABW',
63
 
  kPromptWidget     = 'PROM',
64
 
  kDataGridWidget   = 'BGRI',
65
 
  kToggleWidget     = 'TOGL',
66
 
  kColorWidget      = 'COLR'
 
52
  kStaticTextWidget   = 'TEXT',
 
53
  kEditTextWidget     = 'EDIT',
 
54
  kButtonWidget       = 'BTTN',
 
55
  kCheckboxWidget     = 'CHKB',
 
56
  kSliderWidget       = 'SLDE',
 
57
  kListWidget         = 'LIST',
 
58
  kScrollBarWidget    = 'SCRB',
 
59
  kPopUpWidget        = 'POPU',
 
60
  kTabWidget          = 'TABW',
 
61
  kEventMappingWidget = 'EVMP',
 
62
  kEditableWidget     = 'EDLE',
 
63
  kAudioWidget        = 'AUDW',
 
64
  kColorWidget        = 'COLR',
 
65
  kCpuWidget          = 'CPUW',
 
66
  kDataGridOpsWidget  = 'BGRO',
 
67
  kDataGridWidget     = 'BGRI',
 
68
  kPromptWidget       = 'PROM',
 
69
  kRamWidget          = 'RAMW',
 
70
  kRiotWidget         = 'RIOW',
 
71
  kRomListWidget      = 'ROML',
 
72
  kRomWidget          = 'ROMW',
 
73
  kTiaInfoWidget      = 'TIAI',
 
74
  kTiaOutputWidget    = 'TIAO',
 
75
  kTiaWidget          = 'TIAW',
 
76
  kTiaZoomWidget      = 'TIAZ',
 
77
  kToggleBitWidget    = 'TGLB',
 
78
  kTogglePixelWidget  = 'TGLP',
 
79
  kToggleWidget       = 'TOGL'
67
80
};
68
81
 
69
82
enum {
75
88
  This is the base class for all widgets.
76
89
  
77
90
  @author  Stephen Anthony
78
 
  @version $Id: Widget.hxx,v 1.49 2006/03/25 00:34:17 stephena Exp $
 
91
  @version $Id: Widget.hxx,v 1.61 2008/05/11 21:18:35 stephena Exp $
79
92
*/
80
93
class Widget : public GuiObject
81
94
{
100
113
    virtual void handleJoyUp(int stick, int button) {}
101
114
    virtual void handleJoyAxis(int stick, int axis, int value) {}
102
115
    virtual bool handleJoyHat(int stick, int hat, int value) { return false; }
 
116
    virtual bool handleEvent(Event::Type event) { return false; }
103
117
 
104
118
    void draw();
105
119
    void receivedFocus();
107
121
    void addFocusWidget(Widget* w) { _focusList.push_back(w); }
108
122
 
109
123
    virtual GUI::Rect getRect() const;
110
 
    virtual bool wantsFocus()  { return false; }
111
124
 
112
125
    /** Set/clear WIDGET_ENABLED flag and immediately redraw */
113
126
    void setEnabled(bool e);
116
129
    void clearFlags(int flags)  { _flags &= ~flags; }
117
130
    int  getFlags() const       { return _flags;    }
118
131
 
119
 
    bool isEnabled() const   { return _flags & WIDGET_ENABLED;      }
120
 
    bool isVisible() const   { return !(_flags & WIDGET_INVISIBLE); }
121
 
    bool isSticky() const    { return _flags & WIDGET_STICKY_FOCUS; }
122
 
    bool wantsEvents() const { return _flags & WIDGET_WANTS_EVENTS; }
 
132
    bool isEnabled() const   { return _flags & WIDGET_ENABLED;       }
 
133
    bool isVisible() const   { return !(_flags & WIDGET_INVISIBLE);  }
 
134
    bool wantsFocus() const  { return _flags & WIDGET_RETAIN_FOCUS;  }
 
135
    bool wantsTab() const    { return _flags & WIDGET_WANTS_TAB;     }
 
136
    bool wantsRaw() const    { return _flags & WIDGET_WANTS_RAWDATA; }
123
137
 
124
138
    void setID(int id)  { _id = id;   }
125
139
    int  getID()        { return _id; }
126
140
 
127
 
    void setColor(int color)        { _color = color; }
128
141
    virtual const GUI::Font* font() { return _font; }
129
142
 
 
143
    void setTextColor(int color)   { _textcolor = color;   }
 
144
    void setTextColorHi(int color) { _textcolorhi = color; }
 
145
    void setBGColor(int color)     { _bgcolor = color;     }
 
146
    void setBGColorHi(int color)   { _bgcolorhi = color;   }
 
147
 
130
148
    virtual void loadConfig() {}
131
149
 
132
150
  protected:
151
169
    int        _id;
152
170
    int        _flags;
153
171
    bool       _hasFocus;
154
 
    int        _color;
155
172
    int        _fontWidth;
156
173
    int        _fontHeight;
 
174
    int        _bgcolor;
 
175
    int        _bgcolorhi;
 
176
    int        _textcolor;
 
177
    int        _textcolorhi;
157
178
 
158
179
  public:
159
180
    static Widget* findWidgetInChain(Widget* start, int x, int y);
185
206
    void setLabel(const string& label);
186
207
    void setAlign(TextAlignment align)  { _align = align; }
187
208
    const string& getLabel() const      { return _label; }
188
 
    void setEditable(bool editable);
189
209
 
190
210
  protected:
191
211
    void drawWidget(bool hilite);
203
223
  public:
204
224
    ButtonWidget(GuiObject* boss, const GUI::Font& font,
205
225
                 int x, int y, int w, int h,
206
 
                 const string& label, int cmd = 0, uInt8 hotkey = 0);
 
226
                 const string& label, int cmd = 0);
207
227
 
208
228
    void setCmd(int cmd)  { _cmd = cmd; }
209
229
    int getCmd() const    { return _cmd; }
210
230
 
211
 
    void handleMouseUp(int x, int y, int button, int clickCount);
212
 
    void handleMouseEntered(int button);
213
 
    void handleMouseLeft(int button);
214
 
    bool handleKeyDown(int ascii, int keycode, int modifiers);
215
 
    void handleJoyDown(int stick, int button);
216
 
 
217
 
    bool wantsFocus();
218
 
    void setEditable(bool editable);
 
231
    virtual void handleMouseUp(int x, int y, int button, int clickCount);
 
232
    virtual void handleMouseEntered(int button);
 
233
    virtual void handleMouseLeft(int button);
 
234
    virtual bool handleEvent(Event::Type event);
219
235
 
220
236
  protected:
221
237
    void drawWidget(bool hilite);
222
238
 
223
239
  protected:
224
240
    int    _cmd;
225
 
    bool   _editable;
226
 
    uInt8  _hotkey;
227
241
};
228
242
 
229
243
 
237
251
    void handleMouseUp(int x, int y, int button, int clickCount);
238
252
    virtual void handleMouseEntered(int button) {}
239
253
    virtual void handleMouseLeft(int button)    {}
240
 
    virtual bool handleKeyDown(int ascii, int keycode, int modifiers);
241
 
 
242
 
    bool wantsFocus();
243
 
    void holdFocus(bool status) { _holdFocus = status; }
244
254
 
245
255
    void setEditable(bool editable);
246
256
    void setFill(bool fill) { _fillRect = fill; }
257
267
 
258
268
  protected:
259
269
    bool _state;
260
 
    bool _editable;
261
270
    bool _holdFocus;
262
271
    bool _fillRect;
263
272
    bool _drawBox;
276
285
  public:
277
286
    SliderWidget(GuiObject *boss, const GUI::Font& font,
278
287
                 int x, int y, int w, int h, const string& label = "",
279
 
                 int labelWidth = 0, int cmd = 0, uInt8 hotkey = 0);
 
288
                 int labelWidth = 0, int cmd = 0);
280
289
 
281
290
    void setValue(int value);
282
291
    int getValue() const      { return _value; }
283
292
 
284
 
    void  setMinValue(int value) { _valueMin = value; }
285
 
    int getMinValue() const      { return _valueMin; }
286
 
    void  setMaxValue(int value) { _valueMax = value; }
287
 
    int getMaxValue() const      { return _valueMax; }
 
293
    void setMinValue(int value);
 
294
    int  getMinValue() const      { return _valueMin; }
 
295
    void setMaxValue(int value);
 
296
    int  getMaxValue() const      { return _valueMax; }
 
297
    void setStepValue(int value);
 
298
    int  getStepValue() const     { return _stepValue; }
288
299
 
289
 
    void handleMouseMoved(int x, int y, int button);
290
 
    void handleMouseDown(int x, int y, int button, int clickCount);
291
 
    void handleMouseUp(int x, int y, int button, int clickCount);
 
300
    virtual void handleMouseMoved(int x, int y, int button);
 
301
    virtual void handleMouseDown(int x, int y, int button, int clickCount);
 
302
    virtual void handleMouseUp(int x, int y, int button, int clickCount);
 
303
    virtual bool handleEvent(Event::Type event);
292
304
 
293
305
  protected:
294
306
    void drawWidget(bool hilite);
297
309
    int posToValue(int pos);
298
310
 
299
311
  protected:
300
 
    int  _value, _oldValue;
 
312
    int  _value, _stepValue;
301
313
    int  _valueMin, _valueMax;
302
314
    bool _isDragging;
303
315
    int  _labelWidth;