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_BORDER = 1 << 3,
47 WIDGET_PRESSED = 1 << 4,
49 WIDGET_CLEARBG = 1 << 5,
50 WIDGET_WANT_TICKLE = 1 << 7,
51 WIDGET_TRACK_MOUSE = 1 << 8,
55 WIDGET_RETAIN_FOCUS = 1 << 9,
61 WIDGET_IGNORE_DRAG = 1 << 10,
62 WIDGET_DYN_TOOLTIP = 1 << 11,
66 kStaticTextWidget =
'TEXT',
67 kEditTextWidget =
'EDIT',
68 kButtonWidget =
'BTTN',
69 kCheckboxWidget =
'CHKB',
70 kRadiobuttonWidget =
'RDBT',
71 kSliderWidget =
'SLDE',
73 kScrollBarWidget =
'SCRB',
74 kPopUpWidget =
'POPU',
76 kGraphicsWidget =
'GFXW',
77 kContainerWidget =
'CTNR',
78 kScrollContainerWidget =
'SCTR',
79 kRichTextWidget =
'RTXT',
88 kPressedButtonTime = 200
92 kPicButtonStateEnabled = 0,
93 kPicButtonHighlight = 1,
94 kPicButtonStateDisabled = 2,
95 kPicButtonStatePressed = 3,
97 kPicButtonStateMax = 3
116 static Widget *findWidgetInChain(
Widget *start,
int x,
int y);
117 static Widget *findWidgetInChain(
Widget *start,
const char *name);
118 static bool containsWidgetInChain(
Widget *start,
Widget *search);
128 void setNext(
Widget *w) { _next = w; }
129 void setBoss(
GuiObject *newBoss) { _boss = newBoss; }
130 Widget *next() {
return _next; }
132 int16 getAbsX()
const override {
return _x + _boss->getChildX(); }
133 int16 getAbsY()
const override {
return _y + _boss->getChildY(); }
135 virtual void setPos(
int x,
int y) { _x = x; _y = y; }
136 virtual void setSize(
int w,
int h) { _w = w; _h = h; }
139 virtual void getMinSize(
int &minWidth,
int &minHeight) { minHeight = -1; minWidth = -1; }
141 virtual void handleMouseDown(
int x,
int y,
int button,
int clickCount) {}
142 virtual void handleMouseUp(
int x,
int y,
int button,
int clickCount) {}
143 virtual void handleMouseEntered(
int button) {}
144 virtual void handleMouseLeft(
int button) {}
145 virtual void handleMouseMoved(
int x,
int y,
int button) {}
146 void handleMouseWheel(
int x,
int y,
int direction)
override { assert(_boss); _boss->handleMouseWheel(x, y, direction); }
150 virtual void handleTickle() {}
158 void receivedFocus() { _hasFocus =
true; receivedFocusWidget(); }
159 void lostFocus() { _hasFocus =
false; lostFocusWidget(); }
160 virtual bool wantsFocus() {
return false; }
162 uint32 getType()
const {
return _type; }
164 void setFlags(
int flags);
165 void clearFlags(
int flags);
166 int getFlags()
const {
return _flags; }
168 void setEnabled(
bool e);
169 bool isEnabled()
const;
171 void setVisible(
bool e);
172 bool isVisible()
const override;
179 bool hasTooltip()
const {
return !_tooltip.empty(); }
184 virtual bool containsWidget(
Widget *)
const {
return false; }
189 void updateState(
int oldFlags,
int newFlags);
191 virtual void drawWidget() = 0;
193 virtual void receivedFocusWidget() {}
194 virtual void lostFocusWidget() {}
196 virtual Widget *findWidget(
int x,
int y) {
return this; }
198 void releaseFocus()
override { assert(_boss); _boss->releaseFocus(); }
201 void handleCommand(
CommandSender *sender, uint32 cmd, uint32 data)
override { assert(_boss); _boss->handleCommand(sender, cmd, data); }
214 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);
215 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);
217 void setValue(
int value);
219 void handleMouseEntered(
int button)
override { readLabel(); }
223 void readLabel() { read(_label); }
227 void reflowLayout()
override;
228 void drawWidget()
override;
238 uint8 _highresHotkey;
242 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());
246 void getMinSize(
int &minWidth,
int &minHeight)
override;
248 void setCmd(uint32 cmd) { _cmd = cmd; }
249 uint32 getCmd()
const {
return _cmd; }
256 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
257 void handleMouseDown(
int x,
int y,
int button,
int clickCount)
override;
258 void handleMouseEntered(
int button)
override { readLabel();
if (_duringPress) { setFlags(WIDGET_PRESSED); }
else { setFlags(WIDGET_HILITED); }
markAsDirty(); }
259 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED | WIDGET_PRESSED);
markAsDirty(); }
261 void setHighLighted(
bool enable);
262 void setPressedState();
263 void setUnpressedState();
265 void drawWidget()
override;
272 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());
276 void handleMouseMoved(
int x,
int y,
int button)
override;
277 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
278 void reflowLayout()
override;
279 void getMinSize(
int &minWidth,
int &minHeight)
override;
293 void drawWidget()
override;
296 bool isInDropDown(
int x,
int y)
const;
300 uint32 _dropdownWidth;
314 void setGfx(
const Graphics::Surface *gfx,
int statenum = kPicButtonStateEnabled,
bool scale =
true);
315 void setGfxFromTheme(
const char *name,
int statenum = kPicButtonStateEnabled,
bool scale =
true);
316 void setGfx(
int w,
int h,
int r,
int g,
int b,
int statenum = kPicButtonStateEnabled);
318 void setButtonDisplay(
bool enable) {_showButton = enable; }
321 void drawWidget()
override;
324 Graphics::AlphaType _alphaType[kPicButtonStateMax + 1];
339 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
340 void handleMouseEntered(
int button)
override { readLabel(); setFlags(WIDGET_HILITED);
markAsDirty(); }
341 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED);
markAsDirty(); }
343 void setState(
bool state);
344 void toggleState() { setState(!_state); }
345 bool getState()
const {
return _state; }
347 void setOverride(
bool enable);
350 void drawWidget()
override;
363 void setValue(
int state);
364 int getValue()
const {
return _value; }
366 void setEnabled(
bool ena);
368 void setCmd(uint32 cmd) { _cmd = cmd; }
369 uint32 getCmd()
const {
return _cmd; }
385 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);
389 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
390 void handleMouseEntered(
int button)
override { readLabel(); setFlags(WIDGET_HILITED);
markAsDirty(); }
391 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED);
markAsDirty(); }
393 void setState(
bool state,
bool setGroup =
true);
394 void toggleState() { setState(!_state); }
395 bool getState()
const {
return _state; }
396 int getValue()
const {
return _value; }
399 void drawWidget()
override;
408 int _value, _oldValue;
409 int _valueMin, _valueMax;
417 void setCmd(uint32 cmd) { _cmd = cmd; }
418 uint32 getCmd()
const {
return _cmd; }
420 void setValue(
int value) { _value = value; }
421 int getValue()
const {
return _value; }
423 void setMinValue(
int value) { _valueMin = value; }
424 int getMinValue()
const {
return _valueMin; }
425 void setMaxValue(
int value) { _valueMax = value; }
426 int getMaxValue()
const {
return _valueMax; }
428 void handleMouseMoved(
int x,
int y,
int button)
override;
429 void handleMouseDown(
int x,
int y,
int button,
int clickCount)
override;
430 void handleMouseUp(
int x,
int y,
int button,
int clickCount)
override;
431 void handleMouseEntered(
int button)
override { setFlags(WIDGET_HILITED);
markAsDirty(); }
432 void handleMouseLeft(
int button)
override { clearFlags(WIDGET_HILITED);
markAsDirty(); }
433 void handleMouseWheel(
int x,
int y,
int direction)
override;
436 void drawWidget()
override;
438 int valueToPos(
int value);
439 int posToValue(
int pos);
440 int valueToBarWidth(
int value);
453 void setGfx(
int w,
int h,
int r,
int g,
int b);
454 void setGfxFromTheme(
const char *name);
457 void drawWidget()
override;
460 Graphics::AlphaType _alphaType;
470 bool useEllipsis =
true) :
473 align, tooltip, font, Common::UNK_LANG, useEllipsis),
475 _placeholder(placeholder) { }
481 bool useEllipsis =
true) :
484 align, tooltip, font, Common::UNK_LANG, useEllipsis),
486 _placeholder(placeholder) {}
492 bool useEllipsis =
true) :
495 tooltip, font, Common::UNK_LANG, useEllipsis),
497 _placeholder(placeholder) {}
501 StaticTextWidget::setLabel(_placeholder);
507 void setEmptyPlaceHolder(
const Common::U32String &placeholder) { _placeholder = placeholder; }
520 bool containsWidget(
Widget *)
const override;
521 Widget *findWidget(
int x,
int y)
override;
522 void removeWidget(
Widget *widget)
override;
526 void drawWidget()
override;
546 virtual void load() = 0;
553 virtual bool save() = 0;
564 void setParentDialog(
Dialog *parentDialog) { _parentDialog = parentDialog; }
565 void setDomain(
const Common::String &domain) { _domain = domain; }
569 void reflowLayout()
override;
570 void drawWidget()
override {}
571 bool containsWidget(
Widget *widget)
const override;
572 Widget *findWidget(
int x,
int y)
override;
573 void removeWidget(
Widget *widget)
override;
Definition: managed_surface.h:51
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
static const char kNativeSeparator
Definition: path.h:198
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
bool empty() const
Definition: path.h:356
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