summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/avatarlistbox.cpp6
-rw-r--r--src/gui/widgets/browserbox.cpp22
-rw-r--r--src/gui/widgets/button.cpp20
-rw-r--r--src/gui/widgets/chattab.h1
-rw-r--r--src/gui/widgets/checkbox.cpp18
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp19
-rw-r--r--src/gui/widgets/label.cpp24
-rw-r--r--src/gui/widgets/listbox.cpp6
-rw-r--r--src/gui/widgets/radiobutton.cpp20
-rw-r--r--src/gui/widgets/shoplistbox.cpp3
-rw-r--r--src/gui/widgets/tab.cpp15
-rw-r--r--src/gui/widgets/textbox.cpp24
-rw-r--r--src/gui/widgets/textpreview.cpp21
-rw-r--r--src/gui/widgets/window.cpp82
-rw-r--r--src/gui/widgets/window.h21
16 files changed, 144 insertions, 160 deletions
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 4a806d04..a5109267 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -76,11 +76,15 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
auto offlineIcon = theme->getIcon("offline");
// Draw the list elements
- graphics->setColor(Theme::getThemeColor(Theme::TEXT));
for (int i = 0, y = 0;
i < model->getNumberOfElements();
++i, y += rowHeight)
{
+ if (mSelected == i)
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT_TEXT));
+ else
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
+
Avatar *a = model->getAvatarAt(i);
int x = 1;
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 1deea30b..bf337a0f 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -23,7 +23,6 @@
#include "gui/widgets/browserbox.h"
#include "keyboardconfig.h"
-#include "textrenderer.h"
#include "gui/gui.h"
#include "gui/truetypefont.h"
@@ -292,6 +291,8 @@ void BrowserBox::draw(gcn::Graphics *graphics)
}
}
+ auto g = static_cast<Graphics*>(graphics);
+
for (const auto &row : mTextRows)
{
for (const auto &part : row.parts)
@@ -301,16 +302,15 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if (part.y > yEnd)
return;
- TextRenderer::renderText(graphics,
- part.text,
- part.x,
- part.y,
- Graphics::LEFT,
- part.color,
- part.font,
- part.outlineColor.has_value() || mOutline,
- mShadows,
- part.outlineColor);
+ g->drawText(part.text,
+ part.x,
+ part.y,
+ Graphics::LEFT,
+ part.color,
+ part.font,
+ part.outlineColor.has_value() || mOutline,
+ mShadows,
+ part.outlineColor);
}
}
}
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 31c3a677..604f5dc8 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -28,7 +28,6 @@
#include "resources/image.h"
#include "resources/theme.h"
-#include "textrenderer.h"
#include <guichan/exception.hpp>
#include <guichan/font.hpp>
@@ -132,8 +131,9 @@ void Button::draw(gcn::Graphics *graphics)
if (isPressed())
widgetState.flags |= STATE_SELECTED;
+ auto g = static_cast<Graphics *>(graphics);
auto &skin = gui->getTheme()->getSkin(SkinType::Button);
- skin.draw(static_cast<Graphics *>(graphics), widgetState);
+ skin.draw(g, widgetState);
auto skinState = skin.getState(widgetState.flags);
auto font = (skinState && skinState->textFormat.bold) ? boldFont : getFont();
@@ -196,18 +196,16 @@ void Button::draw(gcn::Graphics *graphics)
}
if (btnIconWidth)
- static_cast<Graphics *>(graphics)->drawImage(icon, btnIconX, btnIconY);
+ g->drawImage(icon, btnIconX, btnIconY);
if (auto skinState = skin.getState(widgetState.flags))
{
- auto &textFormat = skinState->textFormat;
- TextRenderer::renderText(static_cast<Graphics *>(graphics),
- getCaption(),
- textX,
- textY,
- getAlignment(),
- font,
- textFormat);
+ g->drawText(getCaption(),
+ textX,
+ textY,
+ getAlignment(),
+ font,
+ skinState->textFormat);
}
}
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index dfc07638..5232392f 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -24,7 +24,6 @@
#include "gui/chatwindow.h"
#include "gui/widgets/tab.h"
-#include "gui/widgets/textfield.h"
class BrowserBox;
class Recorder;
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index e6079f2f..4bb0bb72 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -21,8 +21,6 @@
#include "gui/widgets/checkbox.h"
-#include "textrenderer.h"
-
#include "gui/gui.h"
#include "resources/theme.h"
@@ -44,19 +42,19 @@ void CheckBox::draw(gcn::Graphics* graphics)
if (isSelected())
widgetState.flags |= STATE_SELECTED;
+ auto g = static_cast<Graphics *>(graphics);
auto &skin = gui->getTheme()->getSkin(SkinType::CheckBox);
- skin.draw(static_cast<Graphics *>(graphics), widgetState);
+ skin.draw(g, widgetState);
if (auto skinState = skin.getState(widgetState.flags))
{
auto &textFormat = skinState->textFormat;
- TextRenderer::renderText(static_cast<Graphics *>(graphics),
- getCaption(),
- skin.getMinWidth() + skin.padding + skin.spacing,
- skin.padding,
- Graphics::LEFT,
- textFormat.bold ? boldFont : getFont(),
- textFormat);
+ g->drawText(getCaption(),
+ skin.getMinWidth() + skin.padding + skin.spacing,
+ skin.padding,
+ Graphics::LEFT,
+ textFormat.bold ? boldFont : getFont(),
+ textFormat);
}
}
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index d0d24c51..63388213 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -155,7 +155,7 @@ void ItemContainer::draw(gcn::Graphics *graphics)
if (item->isEquipped())
g->setColor(theme->getColor(Theme::ITEM_EQUIPPED));
else
- g->setColor(gcn::Color(0, 0, 0));
+ g->setColor(theme->getColor(Theme::TEXT));
g->drawText(caption, itemX + slotSkin.width / 2,
itemY + slotSkin.height - 14, gcn::Graphics::CENTER);
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index 81a332ad..d9d6f506 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -33,6 +33,7 @@
#include "gui/widgets/itemlinkhandler.h"
+#include "client.h"
#include "resources/iteminfo.h"
#include "resources/itemdb.h"
#include "utils/gettext.h"
@@ -56,6 +57,24 @@ static bool isUrl(const std::string &link)
void ItemLinkHandler::handleLink(const std::string &link)
{
+#if SDL_VERSION_ATLEAST(2, 0, 14)
+ // Handle screenshots by constructing full file path
+ if (startsWith(link, "screenshot:"))
+ {
+ std::string filename = link.substr(11); // Remove "screenshot:" prefix
+
+ // Prevent directory traversal attacks or opening malicious files
+ if (filename.find("..") == std::string::npos && endsWith(filename, ".png"))
+ {
+ std::string fileUrl = "file://" + Client::getScreenshotDirectory() + "/" + filename;
+ if (SDL_OpenURL(fileUrl.c_str()) == -1)
+ new OkDialog(_("Open URL Failed"), SDL_GetError(), true, mParent);
+ }
+
+ return;
+ }
+#endif
+
if (isUrl(link))
{
mLink = link;
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index a2ed8820..9c0fd3cd 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -21,8 +21,6 @@
#include "gui/widgets/label.h"
-#include "textrenderer.h"
-
#include "resources/theme.h"
#include <guichan/exception.hpp>
@@ -59,15 +57,15 @@ void Label::draw(gcn::Graphics *graphics)
throw GCN_EXCEPTION("Unknown alignment.");
}
- TextRenderer::renderText(static_cast<Graphics *>(graphics),
- getCaption(),
- textX,
- textY,
- getAlignment(),
- getForegroundColor(),
- getFont(),
- mOutlineColor.has_value(),
- mShadowColor.has_value(),
- mOutlineColor,
- mShadowColor);
+ auto g = static_cast<Graphics *>(graphics);
+ g->drawText(getCaption(),
+ textX,
+ textY,
+ getAlignment(),
+ getForegroundColor(),
+ getFont(),
+ mOutlineColor.has_value(),
+ mShadowColor.has_value(),
+ mOutlineColor,
+ mShadowColor);
}
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 112de232..612e785f 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -56,10 +56,14 @@ void ListBox::draw(gcn::Graphics *graphics)
}
// Draw the list elements
- graphics->setColor(Theme::getThemeColor(Theme::TEXT));
for (int i = 0, y = 0; i < mListModel->getNumberOfElements();
++i, y += height)
{
+ if (mSelected == i)
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT_TEXT));
+ else
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
+
graphics->drawText(mListModel->getElementAt(i), 1, y);
}
}
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index ceba78eb..3474bbd8 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -21,11 +21,11 @@
#include "gui/widgets/radiobutton.h"
-#include "textrenderer.h"
-
#include "gui/gui.h"
#include "resources/theme.h"
+#include <guichan/font.hpp>
+
RadioButton::RadioButton(const std::string &caption,
const std::string &group,
bool marked)
@@ -44,19 +44,19 @@ void RadioButton::draw(gcn::Graphics* graphics)
if (isSelected())
widgetState.flags |= STATE_SELECTED;
+ auto g = static_cast<Graphics *>(graphics);
auto &skin = gui->getTheme()->getSkin(SkinType::RadioButton);
- skin.draw(static_cast<Graphics *>(graphics), widgetState);
+ skin.draw(g, widgetState);
if (auto skinState = skin.getState(widgetState.flags))
{
auto &textFormat = skinState->textFormat;
- TextRenderer::renderText(static_cast<Graphics *>(graphics),
- getCaption(),
- skin.getMinWidth() + skin.padding + skin.spacing,
- skin.padding,
- Graphics::LEFT,
- textFormat.bold ? boldFont : getFont(),
- textFormat);
+ g->drawText(getCaption(),
+ skin.getMinWidth() + skin.padding + skin.spacing,
+ skin.padding,
+ Graphics::LEFT,
+ textFormat.bold ? boldFont : getFont(),
+ textFormat);
}
}
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index e2313c85..d745d74d 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -75,6 +75,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
auto backgroundColor = Theme::getThemeColor(Theme::BACKGROUND);
auto warningColor = Theme::getThemeColor(Theme::SHOP_WARNING);
auto textColor = Theme::getThemeColor(Theme::TEXT);
+ auto highlightTextColor = Theme::getThemeColor(Theme::HIGHLIGHT_TEXT);
highlightColor.a = alpha;
backgroundColor.a = alpha;
warningColor.a = alpha;
@@ -136,7 +137,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
}
}
- graphics->setColor(textColor);
+ graphics->setColor(i == mSelected ? highlightTextColor : textColor);
graphics->drawText(mListModel->getElementAt(i),
ITEM_ICON_SIZE + 5,
y + (ITEM_ICON_SIZE - fontHeight) / 2);
diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp
index b2779c4f..0f6ca4e5 100644
--- a/src/gui/widgets/tab.cpp
+++ b/src/gui/widgets/tab.cpp
@@ -73,18 +73,27 @@ void Tab::draw(gcn::Graphics *graphics)
if (mTabbedArea && mTabbedArea->isTabSelected(this))
flags |= STATE_SELECTED;
- auto &skin = gui->getTheme()->getSkin(SkinType::Tab);
+ auto theme = gui->getTheme();
+ auto &palette = theme->getPalette(0);
+ auto &skin = theme->getSkin(SkinType::Tab);
+
if (auto state = skin.getState(flags))
{
gcn::Color foregroundColor = state->textFormat.color;
+ auto outlineColor = state->textFormat.outlineColor;
if (mFlash)
- foregroundColor = Theme::getThemeColor(Theme::TAB_FLASH);
+ {
+ foregroundColor = palette.getColor(Theme::TAB_FLASH);
+ outlineColor = palette.getOutlineColor(Theme::TAB_FLASH);
+ }
else if (mTabColor)
+ {
foregroundColor = *mTabColor;
+ }
auto label = static_cast<Label*>(mLabel);
label->setForegroundColor(foregroundColor);
- label->setOutlineColor(state->textFormat.outlineColor);
+ label->setOutlineColor(outlineColor);
label->setShadowColor(state->textFormat.shadowColor);
}
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index 6cc514fe..7fd7d626 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -23,7 +23,6 @@
#include "gui/gui.h"
#include "resources/theme.h"
-#include "textrenderer.h"
#include <guichan/font.hpp>
@@ -96,7 +95,7 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
xpos = width;
wrappedStream << word;
}
- else if (xpos != 0 && xpos + getFont()->getWidth(" ") + width <=
+ else if (xpos != 0 && xpos + getFont()->getWidth(" ") + width <=
mMinWidth)
{
xpos += getFont()->getWidth(" ") + width;
@@ -176,18 +175,19 @@ void TextBox::draw(gcn::Graphics *graphics)
graphics->setColor(*mTextColor);
graphics->setFont(getFont());
+ auto g = static_cast<Graphics*>(graphics);
+
for (i = 0; i < mTextRows.size(); i++)
{
// Move the text one pixel so we can have a caret before a letter.
- TextRenderer::renderText(graphics,
- mTextRows[i],
- 1,
- i * getFont()->getHeight(),
- gcn::Graphics::LEFT,
- *mTextColor,
- getFont(),
- mOutlineColor.has_value(),
- false,
- mOutlineColor);
+ g->drawText(mTextRows[i],
+ 1,
+ i * getFont()->getHeight(),
+ gcn::Graphics::LEFT,
+ *mTextColor,
+ getFont(),
+ mOutlineColor.has_value(),
+ false,
+ mOutlineColor);
}
}
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
index 2f80bd23..aed04853 100644
--- a/src/gui/widgets/textpreview.cpp
+++ b/src/gui/widgets/textpreview.cpp
@@ -21,13 +21,7 @@
#include "gui/widgets/textpreview.h"
-#include "configuration.h"
-#include "textrenderer.h"
-
#include "gui/gui.h"
-#include "gui/truetypefont.h"
-
-#include <typeinfo>
TextPreview::TextPreview(const std::string &text)
: mText(text)
@@ -36,12 +30,13 @@ TextPreview::TextPreview(const std::string &text)
mTextColor = &Theme::getThemeColor(Theme::TEXT);
}
-void TextPreview::draw(gcn::Graphics* graphics)
+void TextPreview::draw(gcn::Graphics *graphics)
{
- TextRenderer::renderText(graphics, mText, 2, 2, gcn::Graphics::LEFT,
- gcn::Color(mTextColor->r,
- mTextColor->g,
- mTextColor->b,
- 255),
- mFont, mOutline, mShadow);
+ auto g = static_cast<Graphics*>(graphics);
+ g->drawText(mText, 2, 2, gcn::Graphics::LEFT,
+ gcn::Color(mTextColor->r,
+ mTextColor->g,
+ mTextColor->b,
+ 255),
+ mFont, mOutline, mShadow);
}
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index b05731bd..14d91af1 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -23,7 +23,6 @@
#include "configuration.h"
#include "log.h"
-#include "textrenderer.h"
#include "gui/gui.h"
#include "gui/viewport.h"
@@ -139,13 +138,12 @@ void Window::drawFrame(gcn::Graphics *graphics)
if (auto skinState = skin.getState(widgetState.flags))
{
auto &textFormat = skinState->textFormat;
- TextRenderer::renderText(g,
- getCaption(),
- getFrameSize() + skin.titleOffsetX,
- getFrameSize() + skin.titleOffsetY,
- gcn::Graphics::LEFT,
- textFormat.bold ? boldFont : getFont(),
- textFormat);
+ g->drawText(getCaption(),
+ getFrameSize() + skin.titleOffsetX,
+ getFrameSize() + skin.titleOffsetY,
+ gcn::Graphics::LEFT,
+ textFormat.bold ? boldFont : getFont(),
+ textFormat);
}
}
}
@@ -191,52 +189,6 @@ void Window::setLocationRelativeTo(gcn::Widget *widget)
getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y));
}
-void Window::setLocationRelativeTo(ImageRect::ImagePosition position,
- int offsetX, int offsetY)
-{
- if (position == ImageRect::UPPER_LEFT)
- {
- }
- else if (position == ImageRect::UPPER_CENTER)
- {
- offsetX += (graphics->getWidth() - getWidth()) / 2;
- }
- else if (position == ImageRect::UPPER_RIGHT)
- {
- offsetX += graphics->getWidth() - getWidth();
- }
- else if (position == ImageRect::LEFT)
- {
- offsetY += (graphics->getHeight() - getHeight()) / 2;
- }
- else if (position == ImageRect::CENTER)
- {
- offsetX += (graphics->getWidth() - getWidth()) / 2;
- offsetY += (graphics->getHeight() - getHeight()) / 2;
- }
- else if (position == ImageRect::RIGHT)
- {
- offsetX += graphics->getWidth() - getWidth();
- offsetY += (graphics->getHeight() - getHeight()) / 2;
- }
- else if (position == ImageRect::LOWER_LEFT)
- {
- offsetY += graphics->getHeight() - getHeight();
- }
- else if (position == ImageRect::LOWER_CENTER)
- {
- offsetX += (graphics->getWidth() - getWidth()) / 2;
- offsetY += graphics->getHeight() - getHeight();
- }
- else if (position == ImageRect::LOWER_RIGHT)
- {
- offsetX += graphics->getWidth() - getWidth();
- offsetY += graphics->getHeight() - getHeight();
- }
-
- setPosition(offsetX, offsetY);
-}
-
void Window::setMinWidth(int width)
{
mMinWinWidth = std::max(getSkin().getMinWidth(), width);
@@ -599,41 +551,41 @@ void Window::setDefaultSize()
}
void Window::setDefaultSize(int defaultWidth, int defaultHeight,
- ImageRect::ImagePosition position,
+ WindowAlignment alignment,
int offsetX, int offsetY)
{
int x = 0;
int y = 0;
- switch (position)
+ switch (alignment)
{
- case ImageRect::UPPER_LEFT:
+ case WindowAlignment::TopLeft:
break;
- case ImageRect::UPPER_CENTER:
+ case WindowAlignment::Top:
x = (graphics->getWidth() - defaultWidth) / 2;
break;
- case ImageRect::UPPER_RIGHT:
+ case WindowAlignment::TopRight:
x = graphics->getWidth() - defaultWidth;
break;
- case ImageRect::LEFT:
+ case WindowAlignment::Left:
y = (graphics->getHeight() - defaultHeight) / 2;
break;
- case ImageRect::CENTER:
+ case WindowAlignment::Center:
x = (graphics->getWidth() - defaultWidth) / 2;
y = (graphics->getHeight() - defaultHeight) / 2;
break;
- case ImageRect::RIGHT:
+ case WindowAlignment::Right:
x = graphics->getWidth() - defaultWidth;
y = (graphics->getHeight() - defaultHeight) / 2;
break;
- case ImageRect::LOWER_LEFT:
+ case WindowAlignment::BottomLeft:
y = graphics->getHeight() - defaultHeight;
break;
- case ImageRect::LOWER_CENTER:
+ case WindowAlignment::Bottom:
x = (graphics->getWidth() - defaultWidth) / 2;
y = graphics->getHeight() - defaultHeight;
break;
- case ImageRect::LOWER_RIGHT:
+ case WindowAlignment::BottomRight:
x = graphics->getWidth() - defaultWidth;
y = graphics->getHeight() - defaultHeight;
break;
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 6331a715..2a47b0b9 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -36,6 +36,19 @@ class ResizeGrip;
class Skin;
class WindowContainer;
+enum class WindowAlignment
+{
+ TopLeft,
+ Top,
+ TopRight,
+ Left,
+ Center,
+ Right,
+ BottomLeft,
+ Bottom,
+ BottomRight
+};
+
/**
* A window. This window can be dragged around and has a title bar. Windows are
* invisible by default.
@@ -103,12 +116,6 @@ class Window : public gcn::Window, gcn::WidgetListener
void setLocationRelativeTo(gcn::Widget *widget);
/**
- * Sets the location relative to the given enumerated position.
- */
- void setLocationRelativeTo(ImageRect::ImagePosition position,
- int offsetX = 0, int offsetY = 0);
-
- /**
* Sets whether or not the window can be resized.
*/
void setResizable(bool resize);
@@ -303,7 +310,7 @@ class Window : public gcn::Window, gcn::WidgetListener
* on a relative enumerated position, rather than a coordinate position.
*/
void setDefaultSize(int defaultWidth, int defaultHeight,
- ImageRect::ImagePosition position,
+ WindowAlignment alignment,
int offsetx = 0, int offsetY = 0);
/**