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;
|
return;
|
||||||
|
|
||||||
g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
|
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) {
|
while (w) {
|
||||||
w->draw();
|
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.
|
* in the local coordinate system, i.e. relative to the top left of the dialog.
|
||||||
*/
|
*/
|
||||||
Widget *Dialog::findWidget(int x, int y) {
|
Widget *Dialog::findWidget(int x, int y) {
|
||||||
Widget *w = _firstWidget;
|
return Widget::findWidgetInChain(_firstWidget, x, 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonWidget *Dialog::addButton(int x, int y, const Common::String &label, uint32 cmd, char hotkey) {
|
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;
|
return _screen + x + y * _screenPitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewGui::box(int x, int y, int width, int height, bool inverted) {
|
void NewGui::box(int x, int y, int width, int height, NewGuiColor colorA, NewGuiColor colorB) {
|
||||||
NewGuiColor colorA = inverted ? _shadowcolor : _color;
|
|
||||||
NewGuiColor colorB = inverted ? _color : _shadowcolor;
|
|
||||||
|
|
||||||
hLine(x + 1, y, x + width - 2, colorA);
|
hLine(x + 1, y, x + width - 2, colorA);
|
||||||
hLine(x, y + 1, x + width - 1, colorA);
|
hLine(x, y + 1, x + width - 1, colorA);
|
||||||
vLine(x, y + 1, y + height - 2, colorA);
|
vLine(x, y + 1, y + height - 2, colorA);
|
||||||
|
|
|
@ -128,7 +128,7 @@ public:
|
||||||
|
|
||||||
// Drawing primitives
|
// Drawing primitives
|
||||||
NewGuiColor *getBasePtr(int x, int y);
|
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 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 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);
|
void fillRect(int x, int y, int w, int h, NewGuiColor color);
|
||||||
|
|
|
@ -19,9 +19,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "widget.h"
|
#include "common/util.h"
|
||||||
#include "dialog.h"
|
#include "gui/widget.h"
|
||||||
#include "newgui.h"
|
#include "gui/dialog.h"
|
||||||
|
#include "gui/newgui.h"
|
||||||
|
|
||||||
|
|
||||||
Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
|
Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
|
||||||
|
@ -39,8 +40,8 @@ void Widget::draw() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Account for our relative position in the dialog
|
// Account for our relative position in the dialog
|
||||||
_x += _boss->_x;
|
_x += _boss->getAbsX();
|
||||||
_y += _boss->_y;
|
_y += _boss->getAbsY();
|
||||||
|
|
||||||
// Clear background (unless alpha blending is enabled)
|
// Clear background (unless alpha blending is enabled)
|
||||||
if (_flags & WIDGET_CLEARBG)
|
if (_flags & WIDGET_CLEARBG)
|
||||||
|
@ -48,7 +49,11 @@ void Widget::draw() {
|
||||||
|
|
||||||
// Draw border
|
// Draw border
|
||||||
if (_flags & WIDGET_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;
|
_x += 4;
|
||||||
_y += 4;
|
_y += 4;
|
||||||
_w -= 8;
|
_w -= 8;
|
||||||
|
@ -69,10 +74,21 @@ void Widget::draw() {
|
||||||
// Flag the draw area as dirty
|
// Flag the draw area as dirty
|
||||||
gui->addDirtyRect(_x, _y, _w, _h);
|
gui->addDirtyRect(_x, _y, _w, _h);
|
||||||
|
|
||||||
_x -= _boss->_x;
|
_x -= _boss->getAbsX();
|
||||||
_y -= _boss->_y;
|
_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 -
|
#pragma mark -
|
||||||
|
|
||||||
|
@ -161,7 +177,7 @@ void CheckboxWidget::drawWidget(bool hilite) {
|
||||||
NewGui *gui = &g_gui;
|
NewGui *gui = &g_gui;
|
||||||
|
|
||||||
// Draw the box
|
// 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 checked, draw cross inside the box
|
||||||
if (_state)
|
if (_state)
|
||||||
|
@ -218,7 +234,7 @@ void SliderWidget::drawWidget(bool hilite) {
|
||||||
NewGui *gui = &g_gui;
|
NewGui *gui = &g_gui;
|
||||||
|
|
||||||
// Draw the box
|
// Draw the box
|
||||||
gui->box(_x, _y, _w, _h);
|
gui->box(_x, _y, _w, _h, gui->_color, gui->_shadowcolor);
|
||||||
|
|
||||||
// Draw the 'bar'
|
// Draw the 'bar'
|
||||||
gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
|
gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
|
||||||
|
|
|
@ -72,6 +72,9 @@ protected:
|
||||||
uint16 _flags;
|
uint16 _flags;
|
||||||
bool _hasFocus;
|
bool _hasFocus;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Widget *findWidgetInChain(Widget *start, int x, int y);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Widget(GuiObject *boss, int x, int y, int w, int h);
|
Widget(GuiObject *boss, int x, int y, int w, int h);
|
||||||
virtual ~Widget() {}
|
virtual ~Widget() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue