From 540e9b85beda523cd8bc1675b3f67c8fe42c5f7c Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Fri, 17 May 2024 17:48:15 +0200 Subject: [PATCH] bugfix: Make guisan widgets active/inactive status more visible (fixes #1326) Some widgets were not greyed out when disabled --- external/libguisan/src/widgets/checkbox.cpp | 5 ++++- .../libguisan/src/widgets/imagetextbutton.cpp | 4 ++-- external/libguisan/src/widgets/inputbox.cpp | 2 +- external/libguisan/src/widgets/label.cpp | 10 ++++----- external/libguisan/src/widgets/listbox.cpp | 4 ++-- external/libguisan/src/widgets/messagebox.cpp | 2 +- .../libguisan/src/widgets/progressbar.cpp | 2 +- .../libguisan/src/widgets/radiobutton.cpp | 21 +++++++++++-------- external/libguisan/src/widgets/slider.cpp | 8 +------ external/libguisan/src/widgets/textbox.cpp | 2 +- external/libguisan/src/widgets/textfield.cpp | 2 +- .../libguisan/src/widgets/togglebutton.cpp | 4 ++-- external/libguisan/src/widgets/window.cpp | 2 +- 13 files changed, 34 insertions(+), 34 deletions(-) diff --git a/external/libguisan/src/widgets/checkbox.cpp b/external/libguisan/src/widgets/checkbox.cpp index 7ea95e8de..818fa8577 100644 --- a/external/libguisan/src/widgets/checkbox.cpp +++ b/external/libguisan/src/widgets/checkbox.cpp @@ -152,7 +152,10 @@ namespace gcn graphics->setColor(backCol); graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2)); - graphics->setColor(getForegroundColor()); + if (isEnabled()) + graphics->setColor(getForegroundColor()); + else + graphics->setColor(Color(128, 128, 128)); if (isFocused()) { diff --git a/external/libguisan/src/widgets/imagetextbutton.cpp b/external/libguisan/src/widgets/imagetextbutton.cpp index d2e5a2f2b..dc1b06a8c 100644 --- a/external/libguisan/src/widgets/imagetextbutton.cpp +++ b/external/libguisan/src/widgets/imagetextbutton.cpp @@ -200,12 +200,12 @@ namespace gcn if (isPressed()) { graphics->drawImage(mImage, imageX + 1, imageY + 1); - graphics->drawText(mCaption, textX + 1, textY + 1, Graphics::LEFT); + graphics->drawText(mCaption, textX + 1, textY + 1, Graphics::LEFT, isEnabled()); } else { graphics->drawImage(mImage, imageX, imageY); - graphics->drawText(mCaption, textX, textY, Graphics::LEFT); + graphics->drawText(mCaption, textX, textY, Graphics::LEFT, isEnabled()); if (isFocused()) { diff --git a/external/libguisan/src/widgets/inputbox.cpp b/external/libguisan/src/widgets/inputbox.cpp index 188b9e19e..0c1e31833 100644 --- a/external/libguisan/src/widgets/inputbox.cpp +++ b/external/libguisan/src/widgets/inputbox.cpp @@ -228,7 +228,7 @@ namespace gcn graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1)); - graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->drawText(getCaption(), textX, textY, getAlignment(), isEnabled()); graphics->popClipArea(); } diff --git a/external/libguisan/src/widgets/label.cpp b/external/libguisan/src/widgets/label.cpp index 0aec25c32..d07e9e4d0 100644 --- a/external/libguisan/src/widgets/label.cpp +++ b/external/libguisan/src/widgets/label.cpp @@ -121,11 +121,11 @@ namespace gcn } graphics->setFont(getFont()); - Color color = getForegroundColor(); - if (!isEnabled()) - color = Color(128, 128, 128); - graphics->setColor(color); - graphics->drawText(getCaption(), textX, textY, getAlignment()); + if (isEnabled()) + graphics->setColor(getForegroundColor()); + else + graphics->setColor(Color(128, 128, 128)); + graphics->drawText(getCaption(), textX, textY, getAlignment(), isEnabled()); } void Label::drawBorder(Graphics* graphics) diff --git a/external/libguisan/src/widgets/listbox.cpp b/external/libguisan/src/widgets/listbox.cpp index 750bae009..83f34215b 100644 --- a/external/libguisan/src/widgets/listbox.cpp +++ b/external/libguisan/src/widgets/listbox.cpp @@ -155,11 +155,11 @@ namespace gcn // draw the text with a center vertical alignment. if (rowHeight > getFont()->getHeight()) { - graphics->drawText(mListModel->getElementAt(i), 2, y + rowHeight / 2 - getFont()->getHeight() / 2); + graphics->drawText(mListModel->getElementAt(i), 2, y + rowHeight / 2 - getFont()->getHeight() / 2, Graphics::LEFT, isEnabled()); } else { - graphics->drawText(mListModel->getElementAt(i), 2, y); + graphics->drawText(mListModel->getElementAt(i), 2, y, Graphics::LEFT, isEnabled()); } y += rowHeight; diff --git a/external/libguisan/src/widgets/messagebox.cpp b/external/libguisan/src/widgets/messagebox.cpp index dfaf4bb14..eb27a5873 100644 --- a/external/libguisan/src/widgets/messagebox.cpp +++ b/external/libguisan/src/widgets/messagebox.cpp @@ -345,7 +345,7 @@ namespace gcn graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1)); - graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->drawText(getCaption(), textX, textY, getAlignment(), isEnabled()); graphics->popClipArea(); } diff --git a/external/libguisan/src/widgets/progressbar.cpp b/external/libguisan/src/widgets/progressbar.cpp index 384f2ff66..5e2c0db60 100644 --- a/external/libguisan/src/widgets/progressbar.cpp +++ b/external/libguisan/src/widgets/progressbar.cpp @@ -188,7 +188,7 @@ namespace gcn if (!isEnabled()) color = color - 0x303030; graphics->setColor(color); - graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->drawText(getCaption(), textX, textY, getAlignment(), isEnabled()); } void ProgressBar::drawBorder(Graphics* graphics) diff --git a/external/libguisan/src/widgets/radiobutton.cpp b/external/libguisan/src/widgets/radiobutton.cpp index 9deb5a5c1..302bc4d05 100644 --- a/external/libguisan/src/widgets/radiobutton.cpp +++ b/external/libguisan/src/widgets/radiobutton.cpp @@ -78,9 +78,7 @@ namespace gcn addKeyListener(this); } - RadioButton::RadioButton(const std::string& caption, - const std::string& group, - bool selected) + RadioButton::RadioButton(const std::string& caption, const std::string& group, bool selected) { setCaption(caption); setGroup(group); @@ -108,9 +106,11 @@ namespace gcn drawBox(graphics); graphics->popClipArea(); - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); + if (isEnabled()) + graphics->setColor(getForegroundColor()); + else + graphics->setColor(Color(128, 128, 128)); if (isFocused()) { @@ -119,7 +119,7 @@ namespace gcn const int h = getHeight() + getHeight() / 2; - graphics->drawText(getCaption(), h - 2, 0); + graphics->drawText(getCaption(), h - 2, 0, Graphics::LEFT, isEnabled()); } void RadioButton::drawBorder(Graphics* graphics) @@ -127,8 +127,8 @@ namespace gcn Color faceColor = getBaseColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; + int width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + int height = getHeight() + static_cast(getBorderSize()) * 2 - 1; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; @@ -199,7 +199,10 @@ namespace gcn graphics->drawLine(1, hh + 1, hh, h); graphics->drawLine(hh + 1, h - 1, h, hh); - graphics->setColor(getForegroundColor()); + if (isEnabled()) + graphics->setColor(getForegroundColor()); + else + graphics->setColor(Color(128, 128, 128)); const int hhh = hh - 3; if (mSelected) diff --git a/external/libguisan/src/widgets/slider.cpp b/external/libguisan/src/widgets/slider.cpp index 9d972a988..79882d9fc 100644 --- a/external/libguisan/src/widgets/slider.cpp +++ b/external/libguisan/src/widgets/slider.cpp @@ -130,15 +130,9 @@ namespace gcn void Slider::draw(gcn::Graphics* graphics) { - const auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto backCol = getBackgroundColor(); - if (isEnabled()) + if (!isEnabled()) backCol = backCol - 0x303030; - else - backCol = faceColor - 0x101010; graphics->setColor(backCol); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); diff --git a/external/libguisan/src/widgets/textbox.cpp b/external/libguisan/src/widgets/textbox.cpp index 7821fcefb..f653c0f8e 100644 --- a/external/libguisan/src/widgets/textbox.cpp +++ b/external/libguisan/src/widgets/textbox.cpp @@ -151,7 +151,7 @@ namespace gcn for (unsigned int i = 0; i < mTextRows.size(); i++) { // Move the text one pixel so we can have a caret before a letter. - graphics->drawText(mTextRows[i], 2, i * (getFont()->getHeight() + 2)); + graphics->drawText(mTextRows[i], 2, i * (getFont()->getHeight() + 2), Graphics::LEFT, isEnabled()); } } diff --git a/external/libguisan/src/widgets/textfield.cpp b/external/libguisan/src/widgets/textfield.cpp index 6f76c3652..9979e290c 100644 --- a/external/libguisan/src/widgets/textfield.cpp +++ b/external/libguisan/src/widgets/textfield.cpp @@ -122,7 +122,7 @@ namespace gcn graphics->setColor(Color(128, 128, 128)); graphics->setFont(getFont()); - graphics->drawText(mText, 1 - mXScroll, 2); + graphics->drawText(mText, 1 - mXScroll, 2, Graphics::LEFT, isEnabled()); } void TextField::drawBorder(Graphics* graphics) diff --git a/external/libguisan/src/widgets/togglebutton.cpp b/external/libguisan/src/widgets/togglebutton.cpp index a6ff75b80..c1fc22d3a 100644 --- a/external/libguisan/src/widgets/togglebutton.cpp +++ b/external/libguisan/src/widgets/togglebutton.cpp @@ -139,11 +139,11 @@ namespace gcn if (isPressed() || isSelected()) { - graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment()); + graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment(), isEnabled()); } else { - graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->drawText(getCaption(), textX, textY, getAlignment(), isEnabled()); if (isFocused()) { diff --git a/external/libguisan/src/widgets/window.cpp b/external/libguisan/src/widgets/window.cpp index a403a9f81..5d9901edf 100644 --- a/external/libguisan/src/widgets/window.cpp +++ b/external/libguisan/src/widgets/window.cpp @@ -227,7 +227,7 @@ namespace gcn graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->pushClipArea(Rectangle(0, 0, getWidth(), static_cast(getTitleBarHeight() - 1))); - graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->drawText(getCaption(), textX, textY, getAlignment(), isEnabled()); graphics->popClipArea(); }