summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-11 02:07:42 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-13 01:02:41 +0300
commit1df2b0fb0bc00991eb506ed8915be4b7674e534d (patch)
tree32b5d5c53063b221a089329ffbf84851f5f8b281
parent47e405bb722a222ae7e536bbada2c44d8ea0cd73 (diff)
downloadmv-1df2b0fb0bc00991eb506ed8915be4b7674e534d.tar.gz
mv-1df2b0fb0bc00991eb506ed8915be4b7674e534d.tar.bz2
mv-1df2b0fb0bc00991eb506ed8915be4b7674e534d.tar.xz
mv-1df2b0fb0bc00991eb506ed8915be4b7674e534d.zip
Change theme loading.
-rw-r--r--data/graphics/gui/CMakeLists.txt2
-rw-r--r--data/graphics/gui/Makefile.am2
-rw-r--r--data/graphics/gui/close_button.pngbin650 -> 0 bytes
-rw-r--r--data/graphics/gui/sticky_button.pngbin526 -> 0 bytes
-rw-r--r--data/graphics/gui/window.pngbin13236 -> 14682 bytes
-rw-r--r--data/graphics/gui/window.xml4
-rw-r--r--src/gui/theme.cpp185
-rw-r--r--src/gui/theme.h2
8 files changed, 118 insertions, 77 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt
index af8e0b2b2..0fe74e18c 100644
--- a/data/graphics/gui/CMakeLists.txt
+++ b/data/graphics/gui/CMakeLists.txt
@@ -8,7 +8,6 @@ SET (FILES
checkbox.png
circle-gray.png
circle-green.png
- close_button.png
colors.xml
dropdown.xml
dropdown_background.xml
@@ -33,7 +32,6 @@ SET (FILES
slider.xml
slider_highlighted.xml
speechbubble.xml
- sticky_button.png
tab.xml
tab_highlighted.xml
tab_selected.xml
diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am
index 75ea12a3a..0e99c8a98 100644
--- a/data/graphics/gui/Makefile.am
+++ b/data/graphics/gui/Makefile.am
@@ -11,7 +11,6 @@ gui_DATA = \
checkbox.png \
circle-gray.png \
circle-green.png \
- close_button.png \
colors.xml \
dropdown.xml \
dropdown_background.xml \
@@ -36,7 +35,6 @@ gui_DATA = \
slider.xml \
slider_highlighted.xml \
speechbubble.xml \
- sticky_button.png \
tab.xml \
tab_highlighted.xml \
tab_selected.xml \
diff --git a/data/graphics/gui/close_button.png b/data/graphics/gui/close_button.png
deleted file mode 100644
index f87cc2a91..000000000
--- a/data/graphics/gui/close_button.png
+++ /dev/null
Binary files differ
diff --git a/data/graphics/gui/sticky_button.png b/data/graphics/gui/sticky_button.png
deleted file mode 100644
index 8c5705736..000000000
--- a/data/graphics/gui/sticky_button.png
+++ /dev/null
Binary files differ
diff --git a/data/graphics/gui/window.png b/data/graphics/gui/window.png
index 2e3454976..5eeb95ab5 100644
--- a/data/graphics/gui/window.png
+++ b/data/graphics/gui/window.png
Binary files differ
diff --git a/data/graphics/gui/window.xml b/data/graphics/gui/window.xml
index f27dbc7f3..1b1d7b30e 100644
--- a/data/graphics/gui/window.xml
+++ b/data/graphics/gui/window.xml
@@ -14,5 +14,9 @@
<part type="bottom-left-corner" xpos="0" ypos="220" width="4" height="4" />
<part type="bottom-edge" xpos="4" ypos="220" width="32" height="4" />
<part type="bottom-right-corner" xpos="36" ypos="220" width="4" height="4" />
+
+ <part type="closeImage" xpos="130" ypos="0" width="15" height="15" />
+ <part type="stickyImageUp" xpos="130" ypos="51" width="15" height="15" />
+ <part type="stickyImageDown" xpos="145" ypos="51" width="15" height="15" />
</widget>
</skinset>
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 727777286..fb1dfa086 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -87,13 +87,12 @@ Skin::~Skin()
mBorder.grid[i] = nullptr;
}
- if (mCloseImage)
- {
- mCloseImage->decRef();
- mCloseImage = nullptr;
- }
+ delete mCloseImage;
+ mCloseImage = nullptr;
+
delete mStickyImageUp;
mStickyImageUp = nullptr;
+
delete mStickyImageDown;
mStickyImageDown = nullptr;
}
@@ -307,33 +306,74 @@ void Theme::optionChanged(const std::string &)
updateAlpha();
}
-#define loadSkinImage(obj, name) \
- if (partType == name) \
- { \
- if (dBorders) \
- { \
- border.grid[obj] = dBorders->getSubImage( \
- xPos, yPos, width, height); \
- } \
- else \
- { \
- border.grid[obj] = nullptr; \
- } \
- }
-
-#define loadSkinImage2(obj, name1, name2) \
- if (partType == name1 || partType == name2) \
- { \
- if (dBorders) \
- { \
- border.grid[obj] = dBorders->getSubImage( \
- xPos, yPos, width, height); \
- } \
- else \
- { \
- border.grid[obj] = nullptr; \
- } \
+struct SkinParameter
+{
+ int index;
+ std::string name;
+};
+
+static SkinParameter skinParam[] =
+{
+ {0, "top-left-corner"},
+ {0, "standart"},
+ {0, "up"},
+ {0, "hstart"},
+ {1, "top-edge"},
+ {1, "highlighted"},
+ {1, "down"},
+ {1, "hmiddle"},
+ {2, "top-right-corner"},
+ {2, "pressed"},
+ {2, "left"},
+ {2, "hend"},
+ {3, "left-edge"},
+ {3, "disabled"},
+ {3, "right"},
+ {3, "hgrip"},
+ {4, "bg-quad"},
+ {4, "vstart"},
+ {5, "right-edge"},
+ {5, "vmiddle"},
+ {6, "bottom-left-corner"},
+ {6, "vend"},
+ {7, "bottom-edge"},
+ {7, "vgrip"},
+ {8, "bottom-right-corner"},
+};
+
+static SkinParameter imageParam[] =
+{
+ {0, "closeImage"},
+ {1, "stickyImageUp"},
+ {2, "stickyImageDown"},
+};
+
+struct SkinHelper
+{
+ std::string partType;
+ int xPos;
+ int yPos;
+ int width;
+ int height;
+ ImageRect *rect;
+ XmlNodePtr *node;
+ Image *image;
+
+ bool loadList(SkinParameter *params, size_t size)
+ {
+ for (unsigned f = 0; f < size; f ++)
+ {
+ logger->log("%s vs %s", partType.c_str(), params[f].name.c_str());
+ if (partType == params[f].name)
+ {
+ rect->grid[params[f].index] = image->getSubImage(
+ xPos, yPos, width, height);
+ return true;
+ }
+ }
+ return false;
}
+};
Skin *Theme::readSkin(const std::string &filename)
{
@@ -364,7 +404,9 @@ Skin *Theme::readSkin(const std::string &filename)
Image *dBorders = Theme::getImageFromTheme(skinSetImage);
ImageRect border;
+ ImageRect images;
memset(&border, 0, sizeof(ImageRect));
+ memset(&images, 0, sizeof(ImageRect));
int padding = 3;
int titlePadding = 4;
@@ -378,54 +420,31 @@ Skin *Theme::readSkin(const std::string &filename)
XML::getProperty(widgetNode, "type", "unknown");
if (widgetType == "Window")
{
+ SkinHelper helper;
const int globalXPos = XML::getProperty(widgetNode, "xpos", 0);
const int globalYPos = XML::getProperty(widgetNode, "ypos", 0);
for_each_xml_child_node(partNode, widgetNode)
{
if (xmlNameEqual(partNode, "part"))
{
- const std::string partType =
- XML::getProperty(partNode, "type", "unknown");
- const int xPos = XML::getProperty(
+ helper.partType = XML::getProperty(
+ partNode, "type", "unknown");
+ helper.xPos = XML::getProperty(
partNode, "xpos", 0) + globalXPos;
- const int yPos = XML::getProperty(
+ helper.yPos = XML::getProperty(
partNode, "ypos", 0) + globalYPos;
- const int width = XML::getProperty(partNode, "width", 1);
- const int height = XML::getProperty(partNode, "height", 1);
-
- loadSkinImage2(0, "top-left-corner", "standart")
- else
- loadSkinImage2(1, "top-edge", "highlighted")
- else
- loadSkinImage2(2, "top-right-corner", "pressed")
- else
- loadSkinImage2(3, "left-edge", "disabled")
- else
- loadSkinImage(4, "bg-quad")
- else
- loadSkinImage(5, "right-edge")
- else
- loadSkinImage(6, "bottom-left-corner")
- else
- loadSkinImage(7, "bottom-edge")
- else
- loadSkinImage(8, "bottom-right-corner")
- else
- loadSkinImage2(0, "up", "hstart")
- else
- loadSkinImage2(1, "down", "hmiddle")
- else
- loadSkinImage2(2, "left", "hend")
- else
- loadSkinImage2(3, "right", "hgrip")
- else
- loadSkinImage(4, "vstart")
- else
- loadSkinImage(5, "vmiddle")
- else
- loadSkinImage(6, "vend")
- else
- loadSkinImage(7, "vgrip")
+ helper.width = XML::getProperty(partNode, "width", 1);
+ helper.height = XML::getProperty(partNode, "height", 1);
+ helper.image = dBorders;
+
+ helper.rect = &border;
+ if (!helper.loadList(skinParam,
+ sizeof(skinParam) / sizeof(SkinParameter)))
+ {
+ helper.rect = &images;
+ helper.loadList(imageParam,
+ sizeof(imageParam) / sizeof(SkinParameter));
+ }
}
else if (xmlNameEqual(partNode, "option"))
{
@@ -452,6 +471,7 @@ Skin *Theme::readSkin(const std::string &filename)
// Hard-coded for now until we update the above code
// to look for window buttons
+/*
Image *closeImage = Theme::getImageFromTheme("close_button.png");
Image *sticky = Theme::getImageFromTheme("sticky_button.png");
Image *stickyImageUp = nullptr;
@@ -462,9 +482,10 @@ Skin *Theme::readSkin(const std::string &filename)
stickyImageDown = sticky->getSubImage(15, 0, 15, 15);
sticky->decRef();
}
+*/
- Skin *skin = new Skin(border, closeImage, stickyImageUp, stickyImageDown,
- filename, "", padding, titlePadding);
+ Skin *skin = new Skin(border, images.grid[0], images.grid[1],
+ images.grid[2], filename, "", padding, titlePadding);
skin->updateAlpha(mMinimumOpacity);
return skin;
}
@@ -852,3 +873,21 @@ void Theme::loadRect(ImageRect &image, std::string name, int start, int end)
unload(skin);
}
}
+
+Image *Theme::getImageFromThemeXml(const std::string &name)
+{
+ Theme *theme = Theme::instance();
+ Skin *skin = theme->load(name);
+ if (skin)
+ {
+ const ImageRect &rect = skin->getBorder();
+ if (rect.grid[0])
+ {
+ rect.grid[0]->incRef();
+ theme->unload(skin);
+ return rect.grid[0];
+ }
+ theme->unload(skin);
+ }
+ return nullptr;
+}
diff --git a/src/gui/theme.h b/src/gui/theme.h
index 144cfd274..bd5359c65 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -272,6 +272,8 @@ class Theme : public Palette, public ConfigListener
void loadRect(ImageRect &image, std::string name,
int start = 0, int end = 8);
+ static Image *getImageFromThemeXml(const std::string &name);
+
private:
Theme();
~Theme();