25 #include "common/scummsys.h" 26 #include "common/array.h" 27 #include "common/str.h" 28 #include "common/keyboard.h" 29 #include "graphics/font.h" 30 #include "graphics/managed_surface.h" 31 #include "gui/object.h" 32 #include "gui/ThemeEngine.h" 33 #include "common/text-to-speech.h" 34 #include "common/system.h" 35 #include "common/config-manager.h" 36 #include "common/events.h" 40 class ScrollContainerWidget;
43 WIDGET_ENABLED = 1 << 0,
44 WIDGET_INVISIBLE = 1 << 1,
45 WIDGET_HILITED = 1 << 2,
46 WIDGET_PRESSED = 1 << 3,
47 WIDGET_CLEARBG = 1 << 4,
48 WIDGET_WANT_TICKLE = 1 << 5,
49 WIDGET_TRACK_MOUSE = 1 << 6,
52 WIDGET_HOOK_DRAG = 1 << 7,
53 WIDGET_DYN_TOOLTIP = 1 << 8,
57 kStaticTextWidget =
'TEXT',
58 kEditTextWidget =
'EDIT',
59 kButtonWidget =
'BTTN',
60 kCheckboxWidget =
'CHKB',
61 kRadiobuttonWidget =
'RDBT',
62 kSliderWidget =
'SLDE',
64 kScrollBarWidget =
'SCRB',
65 kPopUpWidget =
'POPU',
67 kGraphicsWidget =
'GFXW',
68 kContainerWidget =
'CTNR',
69 kScrollContainerWidget =
'SCTR',
70 kRichTextWidget =
'RTXT',
79 kPressedButtonTime = 200
83 kPicButtonStateEnabled = 0,
84 kPicButtonHighlight = 1,
85 kPicButtonStateDisabled = 2,
86 kPicButtonStatePressed = 3,
88 kPicButtonStateMax = 3
92 kDragHookStateCancel = -2,
93 kDragHookStateMouseUp = -1,
94 kDragHookStateMouseMoved = 0,
95 kDragHookStateMouseDown = 1,
114 static Widget *findWidgetInChain(
Widget *start,
int x,
int y);
115 static Widget *findWidgetInChain(
Widget *start,
const char *name);
116 static Widget *findWidgetInChain(
Widget *w, uint32 type);
117 static bool containsWidgetInChain(
Widget *start,
Widget *search);
127 void setNext(
Widget *w) { _next = w; }
128 void setBoss(
GuiObject *newBoss) { _boss = newBoss; }
129 Widget *next() {
return _next; }
131 int16 getAbsX()
const override {
return _x + _boss->getChildX(); }
132 int16 getAbsY()
const override {
return _y + _boss->getChildY(); }
134 virtual void setPos(
int x,
int y) { _x = x; _y = y; }
135 virtual void setSize(
int w,
int h) { _w = w; _h = h; }
138 virtual void getMinSize(
int &minWidth,
int &minHeight) { minHeight = -1; minWidth = -1; }
140 virtual void handleMouseDown(
int x,
int y,
int button,
int clickCount) {}
141 virtual void handleMouseUp(
int x,
int y,
int button,
int clickCount) {}
142 virtual void handleMouseEntered(
int button) {}
143 virtual void handleMouseLeft(
int button) {}
144 virtual void handleMouseMoved(
int x,
int y,
int button) {}
145 void handleMouseWheel(
int x,
int y,
int direction)
override { assert(_boss); _boss->handleMouseWheel(x, y, direction); }
149 virtual void handleTooltipUpdate(
int x,
int y) {}
150 virtual void handleTickle() {}
151 virtual bool handleDragHook(
Widget *origTarget,
int state,
int x,
int y,
int button) {
return false; }
153 virtual void cancelDrag() {}
154 virtual void cancelTickle() {}
162 void receivedFocus() { _hasFocus =
true; receivedFocusWidget(); }
163 void lostFocus() { _hasFocus =
false; lostFocusWidget(); }
164 virtual bool wantsFocus() {
return false; }
166 uint32 getType()
const {
return _type; }
168 void setFlags(
int flags);
169 void clearFlags(
int flags);
170 int getFlags()
const {
return _flags; }
172 void setEnabled(
bool e);
173 bool isEnabled()
const;
175 void setVisible(
bool e);
176 bool isVisible()
const override;
183 bool hasTooltip()
const {
return !_tooltip.empty(); }
188 virtual bool containsWidget(
Widget *)
const {
return false; }
193 void updateState(
int oldFlags,
int newFlags);
195 virtual void drawWidget() = 0;
197 virtual void receivedFocusWidget() {}
198 virtual void lostFocusWidget() {}
200 virtual Widget *findWidget(
int x,
int y) {
return this; }
202 void releaseFocus()
override { assert(_boss); _boss->releaseFocus(); }
205 void registerTickleWidget(
Widget *widget)
override { assert(_boss); _boss->registerTickleWidget(widget); }
206 void unregisterTickleWidget(
Widget *widget)
override { assert(_boss); _boss->unregisterTickleWidget(widget); }
209 void handleCommand(
CommandSender *sender, uint32 cmd, uint32 data)
override { assert(_boss); _boss->handleCommand(sender, cmd, data); }
222 StaticTextWidget(
GuiObject *boss,
int x,
int y,
int w,
int h,
bool scale,
const Common::U32String &text,
Graphics::TextAlign align,
const Common::U32String &tooltip =
Common::U32String(),
ThemeEngine::FontStyle font =
ThemeEngine::kFontStyleBold,
Common::Language lang = Common::UNK_LANG,
bool useEllipsis =
true);
223 StaticTextWidget(
GuiObject *boss,
int x,
int y,
int w,
int h,
const Common::U32String &text,
Graphics::TextAlign align,
const Common::U32String &tooltip =
Common::U32String(),
ThemeEngine::FontStyle font =
ThemeEngine::kFontStyleBold,
Common::Language lang = Common::UNK_LANG,
bool useEllipsis =
true);
225 void setValue(
int value);
227 void handleMouseEntered(
int button)
override { readLabel(); }
231 void readLabel() { read(_label); }
235 void reflowLayout()
override;
236 void drawWidget()
override;
246 uint8 _highresHotkey;
250 ButtonWidget(
GuiObject *boss,
int x,
int y,
int w,
int h,
bool scale,
const Common::U32String &label,
const Common::U32String &tooltip =
Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0,
const Common::U32String &lowresLabel =
Common::U32String());
254 void getMinSize(
int &minWidth,
int &minHeight)
override;
256 void setCmd(uint32 cmd) { _cmd = cmd; }
257 uint32 getCmd()
const {
return _cmd; }
264 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
265 void handleMouseDown(
int x,
int y,
int button,
int clickCount)
override;
266 void handleMouseEntered(
int button)
override { readLabel();
if (_duringPress) { setFlags(WIDGET_PRESSED); }
else { setFlags(WIDGET_HILITED); }
markAsDirty(); }
267 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED | WIDGET_PRESSED);
markAsDirty(); }
269 void setHighLighted(
bool enable);
270 void setPressedState();
271 void setUnpressedState();
273 void drawWidget()
override;
280 DropdownButtonWidget(
GuiObject *boss,
int x,
int y,
int w,
int h,
bool scale,
const Common::U32String &label,
const Common::U32String &tooltip =
Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0,
const Common::U32String &lowresLabel =
Common::U32String());
284 void handleMouseMoved(
int x,
int y,
int button)
override;
285 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
286 void reflowLayout()
override;
287 void getMinSize(
int &minWidth,
int &minHeight)
override;
301 void drawWidget()
override;
304 bool isInDropDown(
int x,
int y)
const;
308 uint32 _dropdownWidth;
322 void setGfx(
const Graphics::Surface *gfx,
int statenum = kPicButtonStateEnabled,
bool scale =
true);
323 void setGfxFromTheme(
const char *name,
int statenum = kPicButtonStateEnabled);
324 void setGfx(
int w,
int h,
int r,
int g,
int b,
int statenum = kPicButtonStateEnabled);
325 void clearGfx(
int statenum = kPicButtonStateEnabled) { _gfx[statenum].reset(); }
327 void setButtonDisplay(
bool enable) {_showButton = enable; }
330 void drawWidget()
override;
333 Graphics::AlphaType _alphaType[kPicButtonStateMax + 1];
348 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
349 void handleMouseEntered(
int button)
override { readLabel(); setFlags(WIDGET_HILITED);
markAsDirty(); }
350 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED);
markAsDirty(); }
352 void setState(
bool state);
353 void toggleState() { setState(!_state); }
354 bool getState()
const {
return _state; }
356 void setOverride(
bool enable);
359 void drawWidget()
override;
372 void setValue(
int state);
373 int getValue()
const {
return _value; }
375 void setEnabled(
bool ena);
377 void setCmd(uint32 cmd) { _cmd = cmd; }
378 uint32 getCmd()
const {
return _cmd; }
394 RadiobuttonWidget(
GuiObject *boss,
int x,
int y,
int w,
int h,
bool scale,
RadiobuttonGroup *group,
int value,
const Common::U32String &label,
const Common::U32String &tooltip =
Common::U32String(), uint8 hotkey = 0);
398 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
399 void handleMouseEntered(
int button)
override { readLabel(); setFlags(WIDGET_HILITED);
markAsDirty(); }
400 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED);
markAsDirty(); }
402 void setState(
bool state,
bool setGroup =
true);
403 void toggleState() { setState(!_state); }
404 bool getState()
const {
return _state; }
405 int getValue()
const {
return _value; }
408 void drawWidget()
override;
417 int _value, _oldValue;
418 int _valueMin, _valueMax;
426 void setCmd(uint32 cmd) { _cmd = cmd; }
427 uint32 getCmd()
const {
return _cmd; }
429 void setValue(
int value) { _value = value; }
430 int getValue()
const {
return _value; }
432 void setMinValue(
int value) { _valueMin = value; }
433 int getMinValue()
const {
return _valueMin; }
434 void setMaxValue(
int value) { _valueMax = value; }
435 int getMaxValue()
const {
return _valueMax; }
437 void handleMouseMoved(
int x,
int y,
int button)
override;
438 void handleMouseDown(
int x,
int y,
int button,
int clickCount)
override;
439 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
440 void handleMouseEntered(
int button)
override { setFlags(WIDGET_HILITED);
markAsDirty(); }
441 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED);
markAsDirty(); }
442 void handleMouseWheel(
int x,
int y,
int direction)
override;
445 void drawWidget()
override;
447 int valueToPos(
int value);
448 int posToValue(
int pos);
449 int valueToBarWidth(
int value);
462 void setGfx(
int w,
int h,
int r,
int g,
int b);
463 void setGfxFromTheme(
const char *name);
464 void clearGfx() { _gfx.reset(); }
467 void drawWidget()
override;
470 Graphics::AlphaType _alphaType;
480 bool useEllipsis =
true) :
483 align, tooltip, font, Common::UNK_LANG, useEllipsis),
485 _placeholder(placeholder) { }
491 bool useEllipsis =
true) :
494 align, tooltip, font, Common::UNK_LANG, useEllipsis),
496 _placeholder(placeholder) {}
502 bool useEllipsis =
true) :
505 tooltip, font, Common::UNK_LANG, useEllipsis),
507 _placeholder(placeholder) {}
511 StaticTextWidget::setLabel(_placeholder);
517 void setEmptyPlaceHolder(
const Common::U32String &placeholder) { _placeholder = placeholder; }
530 bool containsWidget(
Widget *)
const override;
531 Widget *findWidget(
int x,
int y)
override;
532 void removeWidget(
Widget *widget)
override;
536 void drawWidget()
override;
556 virtual void load() = 0;
563 virtual bool save() = 0;
574 void setParentDialog(
Dialog *parentDialog) { _parentDialog = parentDialog; }
575 void setDomain(
const Common::String &domain) { _domain = domain; }
579 void reflowLayout()
override;
581 void drawWidget()
override {}
582 bool containsWidget(
Widget *widget)
const override;
583 Widget *findWidget(
int x,
int y)
override;
584 void removeWidget(
Widget *widget)
override;
FontColor
Font color selector.
Definition: ThemeEngine.h:288
TextAlign
Definition: font.h:48
WidgetBackground
Widget background type.
Definition: ThemeEngine.h:226
Definition: ThemeEval.h:37
Definition: printman.h:30
static const char kNativeSeparator
Definition: path.h:195
bool empty() const
Definition: path.h:353
virtual Common::Rect getClipRect() const
FontStyle
Font style selector.
Definition: ThemeEngine.h:274
String toString(char separator='/') const
A bold font. This is also the default font.
Definition: ThemeEngine.h:275
State
State of the widget to be drawn.
Definition: ThemeEngine.h:249
Definition: keyboard.h:294
Language
Definition: language.h:45