https://github.com/libsdl-org/Maelstrom/commit/7c0ef761c8c40593d93f9479d2c0ac43321aa6dd
From 7c0ef761c8c40593d93f9479d2c0ac43321aa6dd Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 23 Nov 2011 17:28:20 -0500
Subject: [PATCH] You can set an element's image by name
---
screenlib/UIElement.cpp | 46 ++++++++++++++++++++---------------------
screenlib/UIElement.h | 2 +-
2 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/screenlib/UIElement.cpp b/screenlib/UIElement.cpp
index bf2e1b23..2eaf82ec 100644
--- a/screenlib/UIElement.cpp
+++ b/screenlib/UIElement.cpp
@@ -154,7 +154,7 @@ UIElement::Load(rapidxml::xml_node<> *node, const UITemplates *templates)
attr = node->first_attribute("image", 0, false);
if (attr) {
- if (!ParseImage(attr->value())) {
+ if (!SetImage(attr->value())) {
fprintf(stderr, "Warning: Couldn't load image '%s'\n", attr->value());
return false;
}
@@ -273,28 +273,6 @@ UIElement::ParseFont(char *text)
return true;
}
-bool
-UIElement::ParseImage(const char *file)
-{
- SDL_Surface *bmp;
- SDL_Texture *image;
-
- bmp = SDL_LoadBMP_RW(PHYSFSRWOPS_openRead(file), 1);
- if (!bmp) {
- return false;
- }
-
- image = m_screen->LoadImage(bmp);
- SDL_FreeSurface(bmp);
- if (!image) {
- return false;
- }
-
- SetImage(image);
-
- return true;
-}
-
void
UIElement::SetDrawEngine(UIDrawEngine *drawEngine)
{
@@ -482,6 +460,28 @@ UIElement::SetTextShadowColor(Uint32 color)
m_textShadowColor = color;
}
+bool
+UIElement::SetImage(const char *file)
+{
+ SDL_Surface *bmp;
+ SDL_Texture *image;
+
+ bmp = SDL_LoadBMP_RW(PHYSFSRWOPS_openRead(file), 1);
+ if (!bmp) {
+ return false;
+ }
+
+ image = m_screen->LoadImage(bmp);
+ SDL_FreeSurface(bmp);
+ if (!image) {
+ return false;
+ }
+
+ SetImage(image);
+
+ return true;
+}
+
void
UIElement::SetImage(SDL_Texture *image)
{
diff --git a/screenlib/UIElement.h b/screenlib/UIElement.h
index bc9e8cfb..c0cf964f 100644
--- a/screenlib/UIElement.h
+++ b/screenlib/UIElement.h
@@ -154,6 +154,7 @@ DECLARE_TYPESAFE_CLASS(UIBaseElement)
}
// Image information
+ bool SetImage(const char *file);
void SetImage(SDL_Texture *image);
SDL_Texture *GetImage() const {
return m_image;
@@ -211,7 +212,6 @@ DECLARE_TYPESAFE_CLASS(UIBaseElement)
protected:
bool LoadColor(rapidxml::xml_node<> *node, const char *name, Uint32 &value);
bool ParseFont(char *text);
- bool ParseImage(const char *file);
override void UpdateDisabledState();
};