Skip to content

Commit

Permalink
GUI: Make PopUpWidget clip
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkachov authored and sev- committed Jul 3, 2016
1 parent 8f2d35b commit fca0f0e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
46 changes: 46 additions & 0 deletions gui/ThemeEngine.cpp
Expand Up @@ -270,6 +270,8 @@ void ThemeItemDrawDataClip::drawSelf(bool draw, bool restore) {
}
}

extendedRect.clip(_clip);

_engine->addDirtyRect(extendedRect);
}

Expand Down Expand Up @@ -1180,6 +1182,27 @@ void ThemeEngine::drawPopUpWidget(const Common::Rect &r, const Common::String &s
}
}

void ThemeEngine::drawPopUpWidgetClip(const Common::Rect &r, const Common::Rect &clip, const Common::String &sel, int deltax, WidgetStateInfo state, Graphics::TextAlign align) {
if (!ready())
return;

DrawData dd = kDDPopUpIdle;

if (state == kStateEnabled)
dd = kDDPopUpIdle;
else if (state == kStateHighlight)
dd = kDDPopUpHover;
else if (state == kStateDisabled)
dd = kDDPopUpDisabled;

queueDDClip(dd, r, clip);

if (!sel.empty()) {
Common::Rect text(r.left + 3, r.top + 1, r.right - 10, r.bottom);
queueDDTextClip(getTextData(dd), getTextColor(dd), text, clip, sel, true, false, _widgets[dd]->_textAlignH, _widgets[dd]->_textAlignV, deltax);
}
}

void ThemeEngine::drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans) {
if (!ready())
return;
Expand Down Expand Up @@ -1210,6 +1233,29 @@ void ThemeEngine::drawWidgetBackground(const Common::Rect &r, uint16 hints, Widg
}
}

void ThemeEngine::drawWidgetBackgroundClip(const Common::Rect &r, const Common::Rect &clip, uint16 hints, WidgetBackground background, WidgetStateInfo state) {
if (!ready())
return;

switch (background) {
case kWidgetBackgroundBorderSmall:
queueDDClip(kDDWidgetBackgroundSmall, r, clip);
break;

case kWidgetBackgroundEditText:
queueDDClip(kDDWidgetBackgroundEditText, r, clip);
break;

case kWidgetBackgroundSlider:
queueDDClip(kDDWidgetBackgroundSlider, r, clip);
break;

default:
queueDDClip(kDDWidgetBackgroundDefault, r, clip);
break;
}
}

void ThemeEngine::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state) {
if (!ready())
return;
Expand Down
5 changes: 5 additions & 0 deletions gui/ThemeEngine.h
Expand Up @@ -341,6 +341,9 @@ class ThemeEngine {
void drawWidgetBackground(const Common::Rect &r, uint16 hints,
WidgetBackground background = kWidgetBackgroundPlain, WidgetStateInfo state = kStateEnabled);

void drawWidgetBackgroundClip(const Common::Rect &r, const Common::Rect &clippingArea, uint16 hints,
WidgetBackground background = kWidgetBackgroundPlain, WidgetStateInfo state = kStateEnabled);

void drawButton(const Common::Rect &r, const Common::String &str,
WidgetStateInfo state = kStateEnabled, uint16 hints = 0);

Expand Down Expand Up @@ -368,6 +371,8 @@ class ThemeEngine {

void drawPopUpWidget(const Common::Rect &r, const Common::String &sel,
int deltax, WidgetStateInfo state = kStateEnabled, Graphics::TextAlign align = Graphics::kTextAlignLeft);
void drawPopUpWidgetClip(const Common::Rect &r, const Common::Rect &clippingArea, const Common::String &sel,
int deltax, WidgetStateInfo state = kStateEnabled, Graphics::TextAlign align = Graphics::kTextAlignLeft);

void drawCaret(const Common::Rect &r, bool erase,
WidgetStateInfo state = kStateEnabled);
Expand Down
12 changes: 3 additions & 9 deletions gui/widget.cpp
Expand Up @@ -280,11 +280,8 @@ void StaticTextWidget::setAlign(Graphics::TextAlign align) {


void StaticTextWidget::drawWidget() {
int px = _boss->getAbsX();
int py = _boss->getAbsY();
g_gui.theme()->drawTextClip(
Common::Rect(_x, _y, _x+_w, _y+_h),
Common::Rect(px, py, px + _boss->getWidth(), py + _boss->getHeight()),
Common::Rect(_x, _y, _x+_w, _y+_h), getBossClipRect(),
_label, _state, _align, ThemeEngine::kTextInversionNone, 0, true, _font
);
}
Expand Down Expand Up @@ -324,12 +321,9 @@ void ButtonWidget::handleMouseDown(int x, int y, int button, int clickCount) {
setPressedState();
}

void ButtonWidget::drawWidget() {
int px = _boss->getAbsX();
int py = _boss->getAbsY();
void ButtonWidget::drawWidget() {
g_gui.theme()->drawButtonClip(
Common::Rect(_x, _y, _x + _w, _y + _h),
Common::Rect(px, py, px + _boss->getWidth(), py + _boss->getHeight()),
Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(),
_label, _state, getFlags()
);
}
Expand Down
5 changes: 5 additions & 0 deletions gui/widget.h
Expand Up @@ -112,6 +112,11 @@ class Widget : public GuiObject {

virtual int16 getAbsX() const { return _x + _boss->getChildX(); }
virtual int16 getAbsY() const { return _y + _boss->getChildY(); }
virtual Common::Rect getBossClipRect() const {
int px = _boss->getAbsX();
int py = _boss->getAbsY();
return Common::Rect(px, py, px + _boss->getWidth(), py + _boss->getHeight());
}

virtual void setPos(int x, int y) { _x = x; _y = y; }
virtual void setSize(int w, int h) { _w = w; _h = h; }
Expand Down
14 changes: 10 additions & 4 deletions gui/widgets/popup.cpp
Expand Up @@ -150,7 +150,7 @@ PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)

void PopUpDialog::drawDialog() {
// Draw the menu border
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), 0);
g_gui.theme()->drawWidgetBackgroundClip(Common::Rect(_x, _y, _x+_w, _y+_h), _popUpBoss->getBossClipRect(), 0);

/*if (_twoColumns)
g_gui.vLine(_x + _w / 2, _y, _y + _h - 2, g_gui._color);*/
Expand Down Expand Up @@ -364,8 +364,11 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
// Draw a separator
g_gui.theme()->drawLineSeparator(Common::Rect(x, y, x+w, y+kLineHeight));
} else {
g_gui.theme()->drawText(Common::Rect(x+1, y+2, x+w, y+2+kLineHeight), name, hilite ? ThemeEngine::kStateHighlight : ThemeEngine::kStateEnabled,
Graphics::kTextAlignLeft, ThemeEngine::kTextInversionNone, _leftPadding);
g_gui.theme()->drawTextClip(
Common::Rect(x+1, y+2, x+w, y+2+kLineHeight), _popUpBoss->getBossClipRect(),
name, hilite ? ThemeEngine::kStateHighlight : ThemeEngine::kStateEnabled,
Graphics::kTextAlignLeft, ThemeEngine::kTextInversionNone, _leftPadding
);
}
}

Expand Down Expand Up @@ -470,7 +473,10 @@ void PopUpWidget::drawWidget() {
Common::String sel;
if (_selectedItem >= 0)
sel = _entries[_selectedItem].name;
g_gui.theme()->drawPopUpWidget(Common::Rect(_x, _y, _x + _w, _y + _h), sel, _leftPadding, _state, Graphics::kTextAlignLeft);
g_gui.theme()->drawPopUpWidgetClip(
Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(),
sel, _leftPadding, _state, Graphics::kTextAlignLeft
);
}

} // End of namespace GUI

0 comments on commit fca0f0e

Please sign in to comment.