aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/menu/background_color.cpp29
-rw-r--r--src/menu/background_color.hpp14
-rw-r--r--src/menu/background_image.cpp24
-rw-r--r--src/menu/background_image.hpp19
4 files changed, 66 insertions, 20 deletions
diff --git a/src/menu/background_color.cpp b/src/menu/background_color.cpp
index f55763b7..031ffe26 100644
--- a/src/menu/background_color.cpp
+++ b/src/menu/background_color.cpp
@@ -28,26 +28,33 @@
namespace usdx
{
BackgroundColor::BackgroundColor(const DrawableControl &control)
- : Background(control), color(0,0,0)
+ : Background(control), color(0,0,0), size(0, 0)
{
}
BackgroundColor::BackgroundColor(const DrawableControl &control,
const RgbColor &color) :
- Background(control), color(color)
+ Background(control), color(color), size(0, 0)
{
}
- void BackgroundColor::draw()
+ void BackgroundColor::updateVertices() {
+ vertices[0] = 0;
+ vertices[1] = get_parent().get_height();
+ vertices[2] = get_parent().get_width();
+ vertices[3] = get_parent().get_height();
+ vertices[4] = get_parent().get_width();
+ vertices[5] = 0;
+ vertices[6] = 0;
+ vertices[7] = 0;
+ }
+
+ void BackgroundColor::draw(void)
{
- this->vertices[0] = 0;
- this->vertices[1] = get_parent().get_height();
- this->vertices[2] = get_parent().get_width();
- this->vertices[3] = get_parent().get_height();
- this->vertices[4] = get_parent().get_width();
- this->vertices[5] = 0;
- this->vertices[6] = 0;
- this->vertices[7] = 0;
+ if (size != get_parent().get_size()) {
+ this->updateVertices();
+ size = get_parent().get_size();
+ }
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
diff --git a/src/menu/background_color.hpp b/src/menu/background_color.hpp
index 7913fe30..4ba040cb 100644
--- a/src/menu/background_color.hpp
+++ b/src/menu/background_color.hpp
@@ -29,6 +29,7 @@
#include "background.hpp"
#include "utils/rgb_color.hpp"
+#include "utils/dimension.hpp"
namespace usdx
{
@@ -37,6 +38,19 @@ namespace usdx
private:
GLint vertices[8];
RgbColor color;
+
+ /**
+ * Cache for the size of the parent component, to be able to detect
+ * changes.
+ */
+ Dimension<int> size;
+
+ /**
+ * Update the vertices for drawing the background, if the size if the
+ * parent component changes.
+ */
+ void updateVertices();
+
protected:
void draw(void);
diff --git a/src/menu/background_image.cpp b/src/menu/background_image.cpp
index bb398304..451587f7 100644
--- a/src/menu/background_image.cpp
+++ b/src/menu/background_image.cpp
@@ -30,7 +30,7 @@ namespace usdx
{
BackgroundImage::BackgroundImage(const DrawableControl &control,
boost::filesystem::wpath filename) :
- Background(control)
+ Background(control), texture(NULL), size(0,0)
{
texture = new Disposer<Texture>(new Texture(filename));
}
@@ -42,18 +42,24 @@ namespace usdx
texture = NULL;
}
}
+
+ void BackgroundImage::updateVertices() {
+ vertices[0] = 0;
+ vertices[1] = get_parent().get_height();
+ vertices[2] = get_parent().get_width();
+ vertices[3] = get_parent().get_height();
+ vertices[4] = get_parent().get_width();
+ vertices[5] = 0;
+ vertices[6] = 0;
+ vertices[7] = 0;
}
void BackgroundImage::draw(void)
{
- this->vertices[0] = 0;
- this->vertices[1] = get_parent().get_height();
- this->vertices[2] = get_parent().get_width();
- this->vertices[3] = get_parent().get_height();
- this->vertices[4] = get_parent().get_width();
- this->vertices[5] = 0;
- this->vertices[6] = 0;
- this->vertices[7] = 0;
+ if (size != get_parent().get_size()) {
+ this->updateVertices();
+ size = get_parent().get_size();
+ }
Activator<Texture> t(texture->get());
diff --git a/src/menu/background_image.hpp b/src/menu/background_image.hpp
index 23b1a68e..8b28a2e3 100644
--- a/src/menu/background_image.hpp
+++ b/src/menu/background_image.hpp
@@ -31,6 +31,7 @@
#include "background.hpp"
#include "texture.hpp"
#include "utils/disposer.hpp"
+#include "utils/dimension.hpp"
namespace usdx
{
@@ -46,8 +47,26 @@ namespace usdx
*/
Disposer<Texture>* texture;
+ /**
+ * Vertices to draw the background rectangle filled with the
+ * texture. Cached until size of the parent component changes.
+ *
+ * @see updateVertices()
+ */
GLint vertices[8];
+ /**
+ * Cache for the size of the parent component, to be able to detect
+ * changes.
+ */
+ Dimension<int> size;
+
+ /**
+ * Update the vertices for drawing the background, if the size if the
+ * parent component changes.
+ */
+ void updateVertices();
+
protected:
void draw(void);