From 1ff9749b872afe85ed90a74cc1c140ed956b0fdf Mon Sep 17 00:00:00 2001 From: Paweł Kołodziejski Date: Thu, 6 Mar 2003 19:52:54 +0000 Subject: and more cleanup .... Last svn-id: r6721 --- gui/widget.cpp | 84 +++++++++++++++++++--------------------------------------- 1 file changed, 27 insertions(+), 57 deletions(-) (limited to 'gui/widget.cpp') diff --git a/gui/widget.cpp b/gui/widget.cpp index 9afb874524..0265ac5820 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -24,26 +24,22 @@ #include "newgui.h" - #ifdef _MSC_VER # pragma warning( disable : 4068 ) // unknown pragma #endif - Widget::Widget (Dialog *boss, int x, int y, int w, int h) : _type(0), _boss(boss), _x(x), _y(y), _w(w), _h(h), - _id(0), _flags(0), _hasFocus(false) -{ + _id(0), _flags(0), _hasFocus(false) { // Insert into the widget list of the boss _next = _boss->_firstWidget; _boss->_firstWidget = this; } -void Widget::draw() -{ +void Widget::draw() { NewGui *gui = _boss->getGui(); - + if (!isVisible() || !_boss->isVisible()) return; @@ -62,7 +58,7 @@ void Widget::draw() _y += 4; _w -= 8; } - + // Now perform the actual widget draw drawWidget((_flags & WIDGET_HILITED) ? true : false); @@ -72,7 +68,7 @@ void Widget::draw() _y -= 4; _w += 8; } - + // Flag the draw area as dirty gui->addDirtyRect(_x, _y, _w, _h); @@ -80,69 +76,55 @@ void Widget::draw() _y -= _boss->_y; } - #pragma mark - - StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align) - : Widget (boss, x, y, w, h), _align(align) -{ + : Widget (boss, x, y, w, h), _align(align) { _type = kStaticTextWidget; setLabel(text); } -void StaticTextWidget::setValue(int value) -{ +void StaticTextWidget::setValue(int value) { char buf[256]; sprintf(buf, "%d", value); _label = buf; } -void StaticTextWidget::drawWidget(bool hilite) -{ +void StaticTextWidget::drawWidget(bool hilite) { NewGui *gui = _boss->getGui(); gui->drawString(_label, _x, _y, _w, gui->_textcolor, _align); } - #pragma mark - - ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey) : StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), CommandSender(boss), - _cmd(cmd), _hotkey(hotkey) -{ + _cmd(cmd), _hotkey(hotkey) { _flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG; _type = kButtonWidget; } -void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) -{ +void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) { if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) sendCommand(_cmd, 0); } -void ButtonWidget::drawWidget(bool hilite) -{ +void ButtonWidget::drawWidget(bool hilite) { NewGui *gui = _boss->getGui(); gui->drawString(_label, _x, _y, _w, - !isEnabled() ? gui->_color : - hilite ? gui->_textcolorhi : gui->_textcolor, _align); + !isEnabled() ? gui->_color : + hilite ? gui->_textcolorhi : gui->_textcolor, _align); } - #pragma mark - - PushButtonWidget::PushButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey) - : ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) -{ + : ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) { _flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG; _type = kButtonWidget; } -void PushButtonWidget::setState(bool state) -{ +void PushButtonWidget::setState(bool state) { if (_state != state) { _state = state; _flags ^= WIDGET_INV_BORDER; @@ -150,10 +132,8 @@ void PushButtonWidget::setState(bool state) } } - #pragma mark - - /* 8x8 checkbox bitmap */ static uint32 checked_img[8] = { 0x00000000, @@ -167,33 +147,30 @@ static uint32 checked_img[8] = { }; CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey) - : PushButtonWidget(boss, x, y, w, h, label, cmd, hotkey) -{ + : PushButtonWidget(boss, x, y, w, h, label, cmd, hotkey) { _flags = WIDGET_ENABLED; _type = kCheckboxWidget; } -void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) -{ +void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) { if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) { toggleState(); sendCommand(_cmd, 0); } } -void CheckboxWidget::drawWidget(bool hilite) -{ +void CheckboxWidget::drawWidget(bool hilite) { NewGui *gui = _boss->getGui(); - + // Draw the box gui->box(_x, _y, 14, 14); - + // If checked, draw cross inside the box if (_state) gui->drawBitmap(checked_img, _x + 3, _y + 3, gui->_textcolor); else gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor); - + // Finally draw the label gui->drawString(_label, _x + 20, _y + 3, _w, gui->_textcolor); } @@ -202,8 +179,7 @@ void CheckboxWidget::drawWidget(bool hilite) SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), - _value(0), _valueMin(0), _valueMax(100) -{ + _value(0), _valueMin(0), _valueMax(100) { _flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG; _type = kSliderWidget; } @@ -227,7 +203,6 @@ void SliderWidget::handleMouseMoved(int x, int y, int button) { } void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) { - if (isEnabled()) { _isDragging = true; handleMouseMoved(x, y, button); @@ -235,31 +210,26 @@ void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) { } void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) { - if (isEnabled() && _isDragging) { sendCommand(_cmd, _value); } - _isDragging = false; } -void SliderWidget::drawWidget(bool hilite) -{ +void SliderWidget::drawWidget(bool hilite) { NewGui *gui = _boss->getGui(); - + // Draw the box gui->box(_x, _y, _w, _h); - + // Draw the 'bar' gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor); } -int SliderWidget::valueToPos(int value) -{ +int SliderWidget::valueToPos(int value) { return ((_w - 4) * (value - _valueMin) / (_valueMax - _valueMin)); } -int SliderWidget::posToValue(int pos) -{ +int SliderWidget::posToValue(int pos) { return (pos) * (_valueMax - _valueMin) / (_w - 4) + _valueMin; } -- cgit v1.2.3