From 7d81e1c14f5f9742f8b0222a279a53edd684b417 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 25 Feb 2020 18:23:00 +0100 Subject: [PATCH] GRAPHICS: MACGUI: Implemented addWidget() to BaseMacWindow class --- graphics/macgui/maceditabletext.cpp | 10 ++++------ graphics/macgui/maceditabletext.h | 4 ++-- graphics/macgui/macwidget.cpp | 12 ++++++------ graphics/macgui/macwidget.h | 7 ++++--- graphics/macgui/macwindow.cpp | 17 +++++++++++++++++ graphics/macgui/macwindow.h | 13 +++++++++++++ 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp index b5aa7ecbc96..02579a55b39 100644 --- a/graphics/macgui/maceditabletext.cpp +++ b/graphics/macgui/maceditabletext.cpp @@ -45,19 +45,17 @@ enum { static void cursorTimerHandler(void *refCon); -MacEditableText::MacEditableText(MacWindow *parent, int x, int y, int w, int h, Common::U32String s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) : - MacWidget(parent, x, y, w, h, true), MacText(s, parent->_wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) { +MacEditableText::MacEditableText(int w, int h, MacWindowManager *wm, Common::U32String s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) : + MacWidget(w, h, true), MacText(s, wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) { - _parent = parent; _maxWidth = maxWidth; init(); } -MacEditableText::MacEditableText(MacWindow *parent, int x, int y, int w, int h, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) : - MacWidget(parent, x, y, w, h, true), MacText(s, parent->_wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) { +MacEditableText::MacEditableText(int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) : + MacWidget(w, h, true), MacText(s, wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) { - _parent = parent; _maxWidth = maxWidth; init(); diff --git a/graphics/macgui/maceditabletext.h b/graphics/macgui/maceditabletext.h index 519052893f8..39747775b82 100644 --- a/graphics/macgui/maceditabletext.h +++ b/graphics/macgui/maceditabletext.h @@ -52,9 +52,9 @@ struct SelectedText { class MacEditableText : public MacText, public MacWidget { public: - MacEditableText(MacWindow *parent, int x, int y, int w, int h, Common::U32String s, const MacFont *font, int fgcolor, int bgcolor, + MacEditableText(int w, int h, MacWindowManager *wm, Common::U32String s, const MacFont *font, int fgcolor, int bgcolor, int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0); - MacEditableText(MacWindow *parent, int x, int y, int w, int h, const Common::String &s, const MacFont *font, int fgcolor, int bgcolor, + MacEditableText(int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *font, int fgcolor, int bgcolor, int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0); // 0 pixels between the lines by default virtual ~MacEditableText(); diff --git a/graphics/macgui/macwidget.cpp b/graphics/macgui/macwidget.cpp index 56fa13c5fcf..66901e8f392 100644 --- a/graphics/macgui/macwidget.cpp +++ b/graphics/macgui/macwidget.cpp @@ -24,14 +24,14 @@ namespace Graphics { -MacWidget::MacWidget(MacWindow *parent, int x, int y, int w, int h, bool focusable) : - _focusable(focusable), _parent(parent) { +MacWidget::MacWidget(int w, int h, bool focusable) : + _focusable(focusable) { _contentIsDirty = true; - _dims.left = x; - _dims.right = x + w; - _dims.top = y; - _dims.bottom = y + h; + _dims.left = 0; + _dims.right = w; + _dims.top = 0; + _dims.bottom = h; } } // End of namespace Graphics diff --git a/graphics/macgui/macwidget.h b/graphics/macgui/macwidget.h index b5a4cd92176..3b2d70017e4 100644 --- a/graphics/macgui/macwidget.h +++ b/graphics/macgui/macwidget.h @@ -31,14 +31,14 @@ namespace Common { namespace Graphics { -class MacWindow; +class BaseMacWindow; class ManagedSurface; class MacWidget { friend class MacEditableText; public: - MacWidget(MacWindow *parent, int x, int y, int w, int h, bool focusable); + MacWidget(int w, int h, bool focusable); virtual ~MacWidget() {} const Common::Rect &getDimensions() { return _dims; } @@ -48,6 +48,7 @@ public: virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0; virtual bool processEvent(Common::Event &event) = 0; virtual bool hasAllFocus() = 0; + void setParent(BaseMacWindow *parent) { _parent = parent; } protected: bool _focusable; @@ -56,7 +57,7 @@ protected: Common::Rect _dims; public: - MacWindow *_parent; + BaseMacWindow *_parent; }; } // End of namespace Graphics diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp index 803dc762e58..c9a276857a8 100644 --- a/graphics/macgui/macwindow.cpp +++ b/graphics/macgui/macwindow.cpp @@ -26,6 +26,7 @@ #include "graphics/macgui/macfontmanager.h" #include "graphics/macgui/macwindowmanager.h" #include "graphics/macgui/macwindow.h" +#include "graphics/macgui/macwidget.h" #include "image/bmp.h" namespace Graphics { @@ -40,6 +41,22 @@ BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) : _type = kWindowUnknown; } +WidgetInfo::WidgetInfo(MacWidget *widget_, int x, int y) { + widget = widget_; + bbox = widget->getDimensions(); + bbox.moveTo(x, y); +} + +WidgetInfo::~WidgetInfo() { + delete widget; +} + +void BaseMacWindow::addWidget(MacWidget *widget, int x, int y) { + _widgets.push_back(new WidgetInfo(widget, x, y)); + + widget->setParent(this); +} + MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) : BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) { _active = false; diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h index 47c9189d5f3..c6ebdd20f57 100644 --- a/graphics/macgui/macwindow.h +++ b/graphics/macgui/macwindow.h @@ -36,6 +36,7 @@ namespace Graphics { class MacWindowManager; class MacWindowBorder; +class MacWidget; namespace MacWindowConstants { enum WindowType { @@ -62,6 +63,14 @@ enum WindowClick { } using namespace MacWindowConstants; +struct WidgetInfo { + Common::Rect bbox; + MacWidget *widget; + + WidgetInfo(MacWidget *widget_, int x, int y); + ~WidgetInfo(); +}; + /** * Abstract class that defines common functionality for all window classes. * It supports event callbacks and drawing. @@ -150,6 +159,8 @@ public: */ void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; } + void addWidget(MacWidget *widget, int x, int y); + protected: int _id; WindowType _type; @@ -164,6 +175,8 @@ protected: bool (*_callback)(WindowClick, Common::Event &, void *); void *_dataPtr; + Common::List _widgets; + public: MacWindowManager *_wm; };