diff options
Diffstat (limited to 'src/menu')
-rw-r--r-- | src/menu/application.cpp | 2 | ||||
-rw-r--r-- | src/menu/background.cpp | 44 | ||||
-rw-r--r-- | src/menu/background.hpp | 13 | ||||
-rw-r--r-- | src/menu/background_color.cpp | 56 | ||||
-rw-r--r-- | src/menu/background_color.hpp | 11 | ||||
-rw-r--r-- | src/menu/background_image.cpp | 33 | ||||
-rw-r--r-- | src/menu/background_image.hpp | 8 |
7 files changed, 131 insertions, 36 deletions
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(); }; }; |