diff options
author | Max Horn | 2003-11-02 22:31:20 +0000 |
---|---|---|
committer | Max Horn | 2003-11-02 22:31:20 +0000 |
commit | 1d9ac7b91b86973a298acdc8e29659343e41c5dc (patch) | |
tree | 095e7d4651b26d8a0c720733385c92fa9d58061f /gui | |
parent | 95db1c18dbefaa691174ffe80b8282f0b922eb74 (diff) | |
download | scummvm-rg350-1d9ac7b91b86973a298acdc8e29659343e41c5dc.tar.gz scummvm-rg350-1d9ac7b91b86973a298acdc8e29659343e41c5dc.tar.bz2 scummvm-rg350-1d9ac7b91b86973a298acdc8e29659343e41c5dc.zip |
more changes to allow widget nesting to fully work
svn-id: r11068
Diffstat (limited to 'gui')
-rw-r--r-- | gui/TabWidget.cpp | 19 | ||||
-rw-r--r-- | gui/TabWidget.h | 2 | ||||
-rw-r--r-- | gui/dialog.cpp | 4 | ||||
-rw-r--r-- | gui/object.h | 8 | ||||
-rw-r--r-- | gui/widget.cpp | 17 | ||||
-rw-r--r-- | gui/widget.h | 5 |
6 files changed, 41 insertions, 14 deletions
diff --git a/gui/TabWidget.cpp b/gui/TabWidget.cpp index 4b29bd2d7b..a55cc72638 100644 --- a/gui/TabWidget.cpp +++ b/gui/TabWidget.cpp @@ -42,16 +42,23 @@ TabWidget::TabWidget(GuiObject *boss, int x, int y, int w, int h) // TODO: Dummy for now addTab("Tab 1"); + new ButtonWidget(this, 10, 20, kButtonWidth, 16, "Foo", 0, 0); addTab("Tab 2"); + new ButtonWidget(this, 20, 30, kButtonWidth, 16, "Bar", 0, 0); addTab("Tab 3"); - setActiveTab(1); + new PushButtonWidget(this, 30, 10, kButtonWidth, 16, "Qux", 0, 0); +} + +int16 TabWidget::getChildY() const { + return getAbsY() + kTabHeight; } int TabWidget::addTab(const String &title) { // TODO Tab newTab = { title, NULL }; _tabs.push_back(newTab); - return _tabs.size() - 1; + setActiveTab(_tabs.size() - 1); + return _activeTab; } /* @@ -63,9 +70,12 @@ void TabWidget::removeTab(int tabID) { void TabWidget::setActiveTab(int tabID) { assert(0 <= tabID && tabID < _tabs.size()); if (_activeTab != tabID) { + // Exchange the widget lists, and switch to the new tab + if (_activeTab != -1) + _tabs[_activeTab].firstWidget = _firstWidget; _activeTab = tabID; _firstWidget = _tabs[tabID].firstWidget; - draw(); + _boss->draw(); } } @@ -95,7 +105,6 @@ bool TabWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) { return Widget::handleKeyDown(ascii, keycode, modifiers); } - void TabWidget::drawWidget(bool hilite) { // TODO @@ -126,6 +135,6 @@ Widget *TabWidget::findWidget(int x, int y) { return this; } else { // Iterate over all child widgets and find the one which was clicked - return Widget::findWidgetInChain(_firstWidget, x, y); + return Widget::findWidgetInChain(_firstWidget, x, y - kTabHeight); } } diff --git a/gui/TabWidget.h b/gui/TabWidget.h index 76165e5b1b..1f71fe2063 100644 --- a/gui/TabWidget.h +++ b/gui/TabWidget.h @@ -40,6 +40,8 @@ protected: public: TabWidget(GuiObject *boss, int x, int y, int w, int h); + virtual int16 getChildY() const; + // use Dialog::releaseFocus() when changing to another tab // Problem: how to add items to a tab? diff --git a/gui/dialog.cpp b/gui/dialog.cpp index ffa0b191e8..65c1e62c06 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -97,7 +97,6 @@ void Dialog::draw() { } void Dialog::drawDialog() { - Widget *w = _firstWidget; if (!isVisible()) return; @@ -105,11 +104,14 @@ void Dialog::drawDialog() { g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor); g_gui.box(_x, _y, _w, _h, g_gui._color, g_gui._shadowcolor); + // Draw all children + Widget *w = _firstWidget; while (w) { w->draw(); w = w->_next; } + // Flag the draw area as dirty g_gui.addDirtyRect(_x, _y, _w, _h); } diff --git a/gui/object.h b/gui/object.h index 8393acf671..f842a708f8 100644 --- a/gui/object.h +++ b/gui/object.h @@ -60,13 +60,17 @@ protected: public: GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _firstWidget(0) { } - virtual bool isVisible() const = 0; - virtual int16 getAbsX() const { return _x; } virtual int16 getAbsY() const { return _y; } + virtual int16 getChildX() const { return getAbsX(); } + virtual int16 getChildY() const { return getAbsY(); } virtual uint16 getWidth() const { return _w; } virtual uint16 getHeight() const { return _h; } + virtual bool isVisible() const = 0; + + virtual void draw() = 0; + protected: virtual void releaseFocus() = 0; }; diff --git a/gui/widget.cpp b/gui/widget.cpp index 2a337b9dd2..2e7a502b08 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -38,10 +38,12 @@ void Widget::draw() { if (!isVisible() || !_boss->isVisible()) return; + + int oldX = _x, oldY = _y; // Account for our relative position in the dialog - _x += _boss->getAbsX(); - _y += _boss->getAbsY(); + _x = getAbsX(); + _y = getAbsY(); // Clear background (unless alpha blending is enabled) if (_flags & WIDGET_CLEARBG) @@ -74,8 +76,15 @@ void Widget::draw() { // Flag the draw area as dirty gui->addDirtyRect(_x, _y, _w, _h); - _x -= _boss->getAbsX(); - _y -= _boss->getAbsY(); + _x = oldX; + _y = oldY; + + // Draw all children + Widget *w = _firstWidget; + while (w) { + w->draw(); + w = w->_next; + } } Widget *Widget::findWidgetInChain(Widget *w, int x, int y) { diff --git a/gui/widget.h b/gui/widget.h index 11722aacac..d6da1a5229 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -79,8 +79,8 @@ public: Widget(GuiObject *boss, int x, int y, int w, int h); virtual ~Widget() {} - virtual int16 getAbsX() const { return _x + _boss->getAbsX(); } - virtual int16 getAbsY() const { return _y + _boss->getAbsY(); } + virtual int16 getAbsX() const { return _x + _boss->getChildX(); } + virtual int16 getAbsY() const { return _y + _boss->getChildY(); } virtual void handleMouseDown(int x, int y, int button, int clickCount) {} virtual void handleMouseUp(int x, int y, int button, int clickCount) {} @@ -91,6 +91,7 @@ public: virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled virtual bool handleKeyUp(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled virtual void handleTickle() {} + void draw(); void receivedFocus() { _hasFocus = true; receivedFocusWidget(); } void lostFocus() { _hasFocus = false; lostFocusWidget(); } |