summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-30 02:53:13 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-30 22:00:10 +0300
commit793bcbe5d8308c8c33419f67378df9dc83462445 (patch)
treead03064158e791e4831c5f67e174babeba66a1f7 /src/gui
parent03d04b42b9578616715a4483b0ef581f1fb11fd8 (diff)
downloadmv-793bcbe5d8308c8c33419f67378df9dc83462445.tar.gz
mv-793bcbe5d8308c8c33419f67378df9dc83462445.tar.bz2
mv-793bcbe5d8308c8c33419f67378df9dc83462445.tar.xz
mv-793bcbe5d8308c8c33419f67378df9dc83462445.zip
Add addition options to skin objects.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/theme.cpp72
-rw-r--r--src/gui/theme.h23
-rw-r--r--src/gui/widgets/window.cpp7
-rw-r--r--src/gui/widgets/window.h2
4 files changed, 80 insertions, 24 deletions
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 1ec40b3ad..2ea8ba840 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -63,18 +63,19 @@ static void initDefaultThemePath()
defaultThemePath = "themes/";
}
-Skin::Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown,
- const std::string &filePath,
- const std::string &name, int padding, int titlePadding):
+Skin::Skin(ImageRect skin, ImageRect images, const std::string &filePath,
+ const std::string &name, int padding, int titlePadding,
+ std::map<std::string, int> *options):
instances(1),
mFilePath(filePath),
mName(name),
mBorder(skin),
- mCloseImage(close),
- mStickyImageUp(stickyUp),
- mStickyImageDown(stickyDown),
+ mCloseImage(images.grid[0]),
+ mStickyImageUp(images.grid[1]),
+ mStickyImageDown(images.grid[2]),
mPadding(padding),
- mTitlePadding(titlePadding)
+ mTitlePadding(titlePadding),
+ mOptions(options)
{
}
@@ -107,6 +108,9 @@ Skin::~Skin()
mStickyImageDown->decRef();
mStickyImageDown = nullptr;
}
+
+ delete mOptions;
+ mOptions = nullptr;
}
void Skin::updateAlpha(float minimumOpacityAllowed)
@@ -226,7 +230,8 @@ gcn::Color Theme::getProgressColor(int type, float progress)
return gcn::Color(color[0], color[1], color[2]);
}
-Skin *Theme::load(const std::string &filename, const std::string &defaultPath)
+Skin *Theme::load(const std::string &filename, bool full,
+ const std::string &defaultPath)
{
// Check if this skin was already loaded
@@ -238,10 +243,10 @@ Skin *Theme::load(const std::string &filename, const std::string &defaultPath)
return skinIterator->second;
}
- Skin *skin = readSkin(filename);
+ Skin *skin = readSkin(filename, full);
- if (!skin)
- skin = readSkin("window.xml");
+ if (!skin && filename != "window.xml")
+ skin = readSkin("window.xml", full);
if (!skin)
{
@@ -251,7 +256,7 @@ Skin *Theme::load(const std::string &filename, const std::string &defaultPath)
logger->log("Error loading skin '%s', falling back on default.",
filename.c_str());
- skin = readSkin(defaultPath);
+ skin = readSkin(defaultPath, full);
}
if (!skin)
@@ -397,7 +402,7 @@ struct SkinHelper
}
};
-Skin *Theme::readSkin(const std::string &filename)
+Skin *Theme::readSkin(const std::string &filename, bool full)
{
if (filename.empty())
return nullptr;
@@ -425,6 +430,7 @@ Skin *Theme::readSkin(const std::string &filename)
memset(&images, 0, sizeof(ImageRect));
int padding = 3;
int titlePadding = 4;
+ std::map<std::string, int> *mOptions = new std::map<std::string, int>();
// iterate <widget>'s
for_each_xml_child_node(widgetNode, rootNode)
@@ -463,14 +469,23 @@ Skin *Theme::readSkin(const std::string &filename)
sizeof(imageParam) / sizeof(SkinParameter));
}
}
- else if (xmlNameEqual(partNode, "option"))
+ else if (full && xmlNameEqual(partNode, "option"))
{
const std::string name = XML::getProperty(
partNode, "name", "");
if (name == "padding")
+ {
padding = XML::getProperty(partNode, "value", 3);
+ }
else if (name == "titlePadding")
+ {
titlePadding = XML::getProperty(partNode, "value", 4);
+ }
+ else
+ {
+ (*mOptions)[name] = XML::getProperty(
+ partNode, "value", 0);
+ }
}
}
}
@@ -484,8 +499,8 @@ Skin *Theme::readSkin(const std::string &filename)
if (dBorders)
dBorders->decRef();
- Skin *skin = new Skin(border, images.grid[0], images.grid[1],
- images.grid[2], filename, "", padding, titlePadding);
+ Skin *skin = new Skin(border, images, filename, "", padding,
+ titlePadding, mOptions);
skin->updateAlpha(mMinimumOpacity);
return skin;
}
@@ -860,7 +875,7 @@ void Theme::loadColors(std::string file)
void Theme::loadRect(ImageRect &image, std::string name, int start, int end)
{
- Skin *skin = load(name);
+ Skin *skin = load(name, false);
if (skin)
{
const ImageRect &rect = skin->getBorder();
@@ -876,6 +891,25 @@ void Theme::loadRect(ImageRect &image, std::string name, int start, int end)
}
}
+Skin *Theme::loadSkinRect(ImageRect &image, std::string name,
+ int start, int end)
+{
+ Skin *skin = load(name);
+ if (skin)
+ {
+ const ImageRect &rect = skin->getBorder();
+ for (int f = start; f <= end; f ++)
+ {
+ if (rect.grid[f])
+ {
+ image.grid[f] = rect.grid[f];
+ image.grid[f]->incRef();
+ }
+ }
+ }
+ return skin;
+}
+
void Theme::unloadRect(ImageRect &rect, int start, int end)
{
for (int f = start; f <= end; f ++)
@@ -888,7 +922,7 @@ void Theme::unloadRect(ImageRect &rect, int start, int end)
Image *Theme::getImageFromThemeXml(const std::string &name)
{
Theme *theme = Theme::instance();
- Skin *skin = theme->load(name);
+ Skin *skin = theme->load(name, false);
if (skin)
{
const ImageRect &rect = skin->getBorder();
@@ -908,7 +942,7 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name,
int w, int h)
{
Theme *theme = Theme::instance();
- Skin *skin = theme->load(name);
+ Skin *skin = theme->load(name, false);
if (skin)
{
const ImageRect &rect = skin->getBorder();
diff --git a/src/gui/theme.h b/src/gui/theme.h
index 1cf8d9aa6..69a08bff0 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -42,9 +42,10 @@ class ProgressBar;
class Skin
{
public:
- Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown,
- const std::string &filePath, const std::string &name = "",
- int padding = 3, int titlePadding = 4);
+ Skin(ImageRect skin, ImageRect images, const std::string &filePath,
+ const std::string &name = "", int padding = 3,
+ int titlePadding = 4,
+ std::map<std::string, int> *options = nullptr);
~Skin();
@@ -101,6 +102,14 @@ class Skin
int getTitlePadding() const
{ return mTitlePadding; }
+ int getOption(std::string name)
+ {
+ if (mOptions->find(name) != mOptions->end())
+ return (*mOptions)[name];
+ else
+ return 0;
+ }
+
int instances;
private:
@@ -112,6 +121,7 @@ class Skin
Image *mStickyImageDown; /**< Sticky Button Image */
int mPadding;
int mTitlePadding;
+ std::map<std::string, int> *mOptions;
};
class Theme : public Palette, public ConfigListener
@@ -249,9 +259,12 @@ class Theme : public Palette, public ConfigListener
/**
* Loads a skin.
*/
- Skin *load(const std::string &filename,
+ Skin *load(const std::string &filename, bool full = true,
const std::string &defaultPath = getThemePath());
+ Skin *loadSkinRect(ImageRect &image, std::string name,
+ int start = 0, int end = 8);
+
void unload(Skin *skin);
/**
@@ -284,7 +297,7 @@ class Theme : public Palette, public ConfigListener
Theme();
~Theme();
- Skin *readSkin(const std::string &filename0);
+ Skin *readSkin(const std::string &filename0, bool full);
// Map containing all window skins
typedef std::map<std::string, Skin*> Skins;
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index d2ba03e07..f84376f2d 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -1022,3 +1022,10 @@ gcn::Rectangle Window::getWindowArea()
getWidth() - getPadding() * 2,
getHeight() - getPadding() * 2);
}
+
+int Window::getOption(std::string name)
+{
+ if (mSkin)
+ return mSkin->getOption(name);
+ return 0;
+}
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 6e6fcdaf0..ee49f2852 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -399,6 +399,8 @@ class Window : public gcn::Window, gcn::WidgetListener
void setCaptionFont(gcn::Font *font)
{ mCaptionFont = font; }
+ int getOption(std::string name);
+
protected:
bool canMove();