1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//
17// Based on code from ScummVM - Scumm Interpreter
18// Copyright (C) 2002-2004 The ScummVM project
19//============================================================================
20
21#ifndef GUI_OBJECT_HXX
22#define GUI_OBJECT_HXX
23
24class Dialog;
25class DialogContainer;
26class Widget;
27class OSystem;
28
29#include "Command.hxx"
30#include "OSystem.hxx"
31#include "Vec.hxx"
32
33using WidgetArray = vector<Widget*>;
34
35/**
36 This is the base class for all GUI objects/widgets.
37
38 @author Stephen Anthony
39*/
40class GuiObject : public CommandReceiver
41{
42 friend class Widget;
43 friend class DialogContainer;
44
45 public:
46 // The commands generated by various widgets
47 enum {
48 kOKCmd = 'OK ',
49 kCloseCmd = 'CLOS',
50 kNextCmd = 'NEXT',
51 kPrevCmd = 'PREV',
52 kDefaultsCmd = 'DEFA',
53 kSetPositionCmd = 'SETP'
54 };
55
56 public:
57 GuiObject(OSystem& osystem, DialogContainer& parent, Dialog& dialog,
58 int x, int y, int w, int h)
59 : myOSystem(osystem),
60 myParent(parent),
61 myDialog(dialog),
62 _x(x), _y(y), _w(w), _h(h),
63 _firstWidget(nullptr) { }
64
65 virtual ~GuiObject() = default;
66
67 OSystem& instance() const { return myOSystem; }
68 DialogContainer& parent() const { return myParent; }
69 Dialog& dialog() const { return myDialog; }
70
71 virtual int getAbsX() const { return _x; }
72 virtual int getAbsY() const { return _y; }
73 virtual int getChildX() const { return getAbsX(); }
74 virtual int getChildY() const { return getAbsY(); }
75 virtual int getWidth() const { return _w; }
76 virtual int getHeight() const { return _h; }
77
78 virtual void setWidth(int w) { _w = w; }
79 virtual void setHeight(int h) { _h = h; }
80
81 virtual bool isVisible() const = 0;
82 virtual void setDirty() = 0;
83
84 /** Add given widget(s) to the focus list */
85 virtual void addFocusWidget(Widget* w) = 0;
86 virtual void addToFocusList(WidgetArray& list) = 0;
87
88 /** Return focus list for this object */
89 WidgetArray& getFocusList() { return _focusList; }
90
91 /** Redraw the focus list */
92 virtual void redrawFocus() { }
93
94 /** Special character for menues */
95 const string ELLIPSIS = "\x1d";
96
97 protected:
98 virtual void releaseFocus() = 0;
99 virtual void draw() = 0;
100
101 private:
102 OSystem& myOSystem;
103 DialogContainer& myParent;
104 Dialog& myDialog;
105
106 protected:
107 int _x, _y, _w, _h;
108
109 Widget* _firstWidget;
110 WidgetArray _focusList;
111
112 private:
113 // Following constructors and assignment operators not supported
114 GuiObject() = delete;
115 GuiObject(const GuiObject&) = delete;
116 GuiObject(GuiObject&&) = delete;
117 GuiObject& operator=(const GuiObject&) = delete;
118 GuiObject& operator=(GuiObject&&) = delete;
119};
120
121#endif
122