aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-04-15 22:50:28 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-13 22:40:52 +0100
commit816030e73aad13c39bc84ca6fdb814ba7131f19f (patch)
treeead3c4c691b3db7f396982327307c5da6ca99855 /src
parente0e9997a5e92ce2a31f0ff4d139109be4434105b (diff)
downloadusdx-816030e73aad13c39bc84ca6fdb814ba7131f19f.tar.gz
usdx-816030e73aad13c39bc84ca6fdb814ba7131f19f.tar.xz
usdx-816030e73aad13c39bc84ca6fdb814ba7131f19f.zip
menu/background: backgrounds get to know the parent component
Backgrounds now know the parent control, they are painted in, to query the size. Backgrounds are not allowed to use glClear anymore, should only draw something during the extend of the parent control and should take care to do not modify the opengl cursor position.
Diffstat (limited to 'src')
-rw-r--r--src/frames/loading_frame.cpp4
-rw-r--r--src/menu/application.cpp2
-rw-r--r--src/menu/background.cpp44
-rw-r--r--src/menu/background.hpp13
-rw-r--r--src/menu/background_color.cpp56
-rw-r--r--src/menu/background_color.hpp11
-rw-r--r--src/menu/background_image.cpp33
-rw-r--r--src/menu/background_image.hpp8
8 files changed, 133 insertions, 38 deletions
diff --git a/src/frames/loading_frame.cpp b/src/frames/loading_frame.cpp
index ef05bd48..b1de9b68 100644
--- a/src/frames/loading_frame.cpp
+++ b/src/frames/loading_frame.cpp
@@ -38,8 +38,8 @@ namespace usdx
Frame(app)
{
// RgbColor background(100, 100, 100);
-// set_background(new BackgroundColor(background));
- set_background(new BackgroundImage("game/themes/Deluxe/[bg-load]blue.jpg"));
+// set_background(new BackgroundColor(*this, background));
+ set_background(new BackgroundImage(*this, "game/themes/Deluxe/[bg-load]blue.jpg"));
DrawableControl *c = new Text(this, "Halloäöüß");
c->set_position(100, 100);
diff --git a/src/menu/application.cpp b/src/menu/application.cpp
index 86bb9232..493053a8 100644
--- a/src/menu/application.cpp
+++ b/src/menu/application.cpp
@@ -82,6 +82,8 @@ namespace usdx
running = true;
while (running) {
// repaint everything
+ glClear(GL_COLOR_BUFFER_BIT);
+ glLoadIdentity();
repaint();
SDL_GL_SwapBuffers();
diff --git a/src/menu/background.cpp b/src/menu/background.cpp
new file mode 100644
index 00000000..ad528039
--- /dev/null
+++ b/src/menu/background.cpp
@@ -0,0 +1,44 @@
+/*
+ * UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "background.hpp"
+
+namespace usdx
+{
+ Background::Background(const DrawableControl &control) :
+ parent(control)
+ {
+ }
+
+ Background::~Background()
+ {
+ }
+
+ const DrawableControl &Background::get_parent(void) const
+ {
+ return parent;
+ }
+};
diff --git a/src/menu/background.hpp b/src/menu/background.hpp
index 4f997700..050b7d6c 100644
--- a/src/menu/background.hpp
+++ b/src/menu/background.hpp
@@ -31,19 +31,26 @@
namespace usdx
{
+ class DrawableControl;
+
// Background - abstract class for Backgrounds
class Background : public Drawable
{
- public:
- virtual ~Background() {};
+ private:
+ const DrawableControl& parent;
protected:
// abstract base class
- Background() {};
+ Background(const DrawableControl&);
// no copy and no assignment
Background(const Background&);
Background& operator=(const Background&);
+
+ public:
+ virtual ~Background();
+
+ const DrawableControl& get_parent(void) const;
};
};
diff --git a/src/menu/background_color.cpp b/src/menu/background_color.cpp
index aa8a90d2..bb579f06 100644
--- a/src/menu/background_color.cpp
+++ b/src/menu/background_color.cpp
@@ -25,23 +25,65 @@
*/
#include "background_color.hpp"
-#include <GL/gl.h>
+#include "drawable_control.hpp"
namespace usdx
{
- BackgroundColor::BackgroundColor(RgbColor &color) :
- color(color)
+ BackgroundColor::BackgroundColor(const DrawableControl &control) :
+ Background(control)
{
+ this->color[0] = 0;
+ this->color[1] = 0;
+ this->color[2] = 0;
+ this->color[3] = 0;
+ this->color[4] = 0;
+ this->color[5] = 0;
+ this->color[6] = 0;
+ this->color[7] = 0;
+ this->color[8] = 0;
+ this->color[9] = 0;
+ this->color[10] = 0;
+ this->color[11] = 0;
}
- BackgroundColor::BackgroundColor(void) :
- color(0, 0, 0)
+ BackgroundColor::BackgroundColor(const DrawableControl &control,
+ const RgbColor &color) :
+ Background(control)
{
+ this->color[0] = color.get_red();
+ this->color[1] = color.get_green();
+ this->color[2] = color.get_blue();
+ this->color[3] = color.get_red();
+ this->color[4] = color.get_green();
+ this->color[5] = color.get_blue();
+ this->color[6] = color.get_red();
+ this->color[7] = color.get_green();
+ this->color[8] = color.get_blue();
+ this->color[9] = color.get_red();
+ this->color[10] = color.get_green();
+ this->color[11] = color.get_blue();
}
void BackgroundColor::draw()
{
- glClearColor(color.get_red(), color.get_green(), color.get_blue(), 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
+ 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;
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ glVertexPointer(2, GL_INT, 0, vertices);
+ glColorPointer(3, GL_UNSIGNED_BYTE, 0, color);
+
+ glDrawArrays(GL_QUADS, 0, 4);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
}
};
diff --git a/src/menu/background_color.hpp b/src/menu/background_color.hpp
index d91edcdf..d1793744 100644
--- a/src/menu/background_color.hpp
+++ b/src/menu/background_color.hpp
@@ -27,6 +27,8 @@
#ifndef BACKGROUND_COLOR_HPP
#define BACKGROUND_COLOR_HPP
+#include <GL/gl.h>
+
#include "background.hpp"
#include "utils/rgb_color.hpp"
@@ -35,14 +37,15 @@ namespace usdx
class BackgroundColor : public Background
{
private:
- RgbColor color;
-
+ GLint vertices[8];
+ GLubyte color[12];
protected:
void draw(void);
public:
- BackgroundColor(void);
- BackgroundColor(RgbColor &color);
+ BackgroundColor(const DrawableControl &control);
+ BackgroundColor(const DrawableControl &control,
+ const RgbColor &color);
};
};
diff --git a/src/menu/background_image.cpp b/src/menu/background_image.cpp
index c8d8642c..03836902 100644
--- a/src/menu/background_image.cpp
+++ b/src/menu/background_image.cpp
@@ -25,22 +25,16 @@
*/
#include "background_image.hpp"
+#include "drawable_control.hpp"
namespace usdx
{
- BackgroundImage::BackgroundImage(boost::filesystem::wpath filename)
+ BackgroundImage::BackgroundImage(const DrawableControl &control,
+ boost::filesystem::wpath filename) :
+ Background(control)
{
texture = new Texture(filename);
- this->vertices[0] = 0.0f;
- this->vertices[1] = 600.0f;
- this->vertices[2] = 800.0f;
- this->vertices[3] = 600.0f;
- this->vertices[4] = 800.0f;
- this->vertices[5] = 0.0f;
- this->vertices[6] = 0.0f;
- this->vertices[7] = 0.0f;
-
this->color[0] = 255;
this->color[1] = 255;
this->color[2] = 255;
@@ -53,10 +47,6 @@ namespace usdx
this->color[9] = 255;
this->color[10] = 255;
this->color[11] = 255;
- this->color[12] = 255;
- this->color[13] = 255;
- this->color[14] = 255;
- this->color[15] = 255;
this->tex[0] = 0.0f;
this->tex[1] = 1.0f;
@@ -75,9 +65,14 @@ namespace usdx
void BackgroundImage::draw(void)
{
- glClear(GL_COLOR_BUFFER_BIT);
-
- glLoadIdentity();
+ 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;
glBindTexture(GL_TEXTURE_2D, texture->get_texture());
@@ -85,8 +80,8 @@ namespace usdx
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, vertices);
- glColorPointer(4, GL_UNSIGNED_BYTE, 0, color);
+ glVertexPointer(2, GL_INT, 0, vertices);
+ glColorPointer(3, GL_UNSIGNED_BYTE, 0, color);
glTexCoordPointer(2, GL_FLOAT, 0, tex);
glDrawArrays(GL_QUADS, 0, 4);
diff --git a/src/menu/background_image.hpp b/src/menu/background_image.hpp
index 7c0549bf..2a61255b 100644
--- a/src/menu/background_image.hpp
+++ b/src/menu/background_image.hpp
@@ -40,15 +40,17 @@ namespace usdx
private:
Texture* texture;
- GLfloat vertices[8];
- GLubyte color[16];
+ GLint vertices[8];
+ GLubyte color[12];
GLfloat tex[8];
protected:
void draw(void);
public:
- BackgroundImage(boost::filesystem::wpath filename);
+ BackgroundImage(const DrawableControl &control,
+ boost::filesystem::wpath filename);
+
virtual ~BackgroundImage();
};
};