refactored code in Dialog::findWidget to Widget::findWidgetInChain; changed NewGui::box() to take colors as param (instead of hard coding _color and _shadowColor)
svn-id: r11061
This commit is contained in:
parent
7ec257ae3f
commit
ac4b9ccdb8
5 changed files with 33 additions and 26 deletions
|
@ -103,7 +103,7 @@ void Dialog::drawDialog() {
|
|||
return;
|
||||
|
||||
g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
|
||||
g_gui.box(_x, _y, _w, _h);
|
||||
g_gui.box(_x, _y, _w, _h, g_gui._color, g_gui._shadowcolor);
|
||||
|
||||
while (w) {
|
||||
w->draw();
|
||||
|
@ -267,16 +267,7 @@ void Dialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
|||
* in the local coordinate system, i.e. relative to the top left of the dialog.
|
||||
*/
|
||||
Widget *Dialog::findWidget(int x, int y) {
|
||||
Widget *w = _firstWidget;
|
||||
while (w) {
|
||||
// Stop as soon as we find a widget that contains the point (x,y)
|
||||
if (x >= w->_x && x < w->_x + w->_w && y >= w->_y && y < w->_y + w->_h)
|
||||
break;
|
||||
w = w->_next;
|
||||
}
|
||||
if (w)
|
||||
w = w->findWidget(x - w->_x, y - w->_y);
|
||||
return w;
|
||||
return Widget::findWidgetInChain(_firstWidget, x, y);
|
||||
}
|
||||
|
||||
ButtonWidget *Dialog::addButton(int x, int y, const Common::String &label, uint32 cmd, char hotkey) {
|
||||
|
|
|
@ -285,10 +285,7 @@ NewGuiColor *NewGui::getBasePtr(int x, int y) {
|
|||
return _screen + x + y * _screenPitch;
|
||||
}
|
||||
|
||||
void NewGui::box(int x, int y, int width, int height, bool inverted) {
|
||||
NewGuiColor colorA = inverted ? _shadowcolor : _color;
|
||||
NewGuiColor colorB = inverted ? _color : _shadowcolor;
|
||||
|
||||
void NewGui::box(int x, int y, int width, int height, NewGuiColor colorA, NewGuiColor colorB) {
|
||||
hLine(x + 1, y, x + width - 2, colorA);
|
||||
hLine(x, y + 1, x + width - 1, colorA);
|
||||
vLine(x, y + 1, y + height - 2, colorA);
|
||||
|
|
|
@ -128,7 +128,7 @@ public:
|
|||
|
||||
// Drawing primitives
|
||||
NewGuiColor *getBasePtr(int x, int y);
|
||||
void box(int x, int y, int width, int height, bool inverted = false);
|
||||
void box(int x, int y, int width, int height, NewGuiColor colorA, NewGuiColor colorB);
|
||||
void line(int x, int y, int x2, int y2, NewGuiColor color);
|
||||
void blendRect(int x, int y, int w, int h, NewGuiColor color, int level = 3);
|
||||
void fillRect(int x, int y, int w, int h, NewGuiColor color);
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "widget.h"
|
||||
#include "dialog.h"
|
||||
#include "newgui.h"
|
||||
#include "common/util.h"
|
||||
#include "gui/widget.h"
|
||||
#include "gui/dialog.h"
|
||||
#include "gui/newgui.h"
|
||||
|
||||
|
||||
Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
|
||||
|
@ -39,8 +40,8 @@ void Widget::draw() {
|
|||
return;
|
||||
|
||||
// Account for our relative position in the dialog
|
||||
_x += _boss->_x;
|
||||
_y += _boss->_y;
|
||||
_x += _boss->getAbsX();
|
||||
_y += _boss->getAbsY();
|
||||
|
||||
// Clear background (unless alpha blending is enabled)
|
||||
if (_flags & WIDGET_CLEARBG)
|
||||
|
@ -48,7 +49,11 @@ void Widget::draw() {
|
|||
|
||||
// Draw border
|
||||
if (_flags & WIDGET_BORDER) {
|
||||
gui->box(_x, _y, _w, _h, (_flags & WIDGET_INV_BORDER) == WIDGET_INV_BORDER);
|
||||
NewGuiColor colorA = gui->_color;
|
||||
NewGuiColor colorB = gui->_shadowcolor;
|
||||
if ((_flags & WIDGET_INV_BORDER) == WIDGET_INV_BORDER)
|
||||
SWAP(colorA, colorB);
|
||||
gui->box(_x, _y, _w, _h, colorA, colorB);
|
||||
_x += 4;
|
||||
_y += 4;
|
||||
_w -= 8;
|
||||
|
@ -69,10 +74,21 @@ void Widget::draw() {
|
|||
// Flag the draw area as dirty
|
||||
gui->addDirtyRect(_x, _y, _w, _h);
|
||||
|
||||
_x -= _boss->_x;
|
||||
_y -= _boss->_y;
|
||||
_x -= _boss->getAbsX();
|
||||
_y -= _boss->getAbsY();
|
||||
}
|
||||
|
||||
Widget *Widget::findWidgetInChain(Widget *w, int x, int y) {
|
||||
while (w) {
|
||||
// Stop as soon as we find a widget that contains the point (x,y)
|
||||
if (x >= w->_x && x < w->_x + w->_w && y >= w->_y && y < w->_y + w->_h)
|
||||
break;
|
||||
w = w->_next;
|
||||
}
|
||||
if (w)
|
||||
w = w->findWidget(x - w->_x, y - w->_y);
|
||||
return w;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
@ -161,7 +177,7 @@ void CheckboxWidget::drawWidget(bool hilite) {
|
|||
NewGui *gui = &g_gui;
|
||||
|
||||
// Draw the box
|
||||
gui->box(_x, _y, 14, 14);
|
||||
gui->box(_x, _y, 14, 14, gui->_color, gui->_shadowcolor);
|
||||
|
||||
// If checked, draw cross inside the box
|
||||
if (_state)
|
||||
|
@ -218,7 +234,7 @@ void SliderWidget::drawWidget(bool hilite) {
|
|||
NewGui *gui = &g_gui;
|
||||
|
||||
// Draw the box
|
||||
gui->box(_x, _y, _w, _h);
|
||||
gui->box(_x, _y, _w, _h, gui->_color, gui->_shadowcolor);
|
||||
|
||||
// Draw the 'bar'
|
||||
gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
|
||||
|
|
|
@ -72,6 +72,9 @@ protected:
|
|||
uint16 _flags;
|
||||
bool _hasFocus;
|
||||
|
||||
public:
|
||||
static Widget *findWidgetInChain(Widget *start, int x, int y);
|
||||
|
||||
public:
|
||||
Widget(GuiObject *boss, int x, int y, int w, int h);
|
||||
virtual ~Widget() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue