diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-04-11 21:19:48 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-13 22:40:52 +0100 |
commit | e0e9997a5e92ce2a31f0ff4d139109be4434105b (patch) | |
tree | e8c3baa67eb65ffc16a9c96fdbb067d142f194bd /src/menu | |
parent | 40caf6163ff2e1274d71146c207fbde0c099b089 (diff) | |
download | usdx-e0e9997a5e92ce2a31f0ff4d139109be4434105b.tar.gz usdx-e0e9997a5e92ce2a31f0ff4d139109be4434105b.tar.xz usdx-e0e9997a5e92ce2a31f0ff4d139109be4434105b.zip |
menu: generalized frame_background to background
background could now be a background for all DrawableControl instances
each subclass should call the parents draw() during executing the
draw() method for background painting
TODO: background should know the size of the control to only draw the
background there
Diffstat (limited to 'src/menu')
-rw-r--r-- | src/menu/background.hpp (renamed from src/menu/frame_background.hpp) | 21 | ||||
-rw-r--r-- | src/menu/background_color.cpp (renamed from src/menu/frame_background_color.cpp) | 8 | ||||
-rw-r--r-- | src/menu/background_color.hpp (renamed from src/menu/frame_background_color.hpp) | 12 | ||||
-rw-r--r-- | src/menu/background_image.cpp (renamed from src/menu/frame_background_image.cpp) | 8 | ||||
-rw-r--r-- | src/menu/background_image.hpp (renamed from src/menu/frame_background_image.hpp) | 12 | ||||
-rw-r--r-- | src/menu/container.cpp | 2 | ||||
-rw-r--r-- | src/menu/drawable_control.cpp | 34 | ||||
-rw-r--r-- | src/menu/drawable_control.hpp | 9 | ||||
-rw-r--r-- | src/menu/frame.cpp | 34 | ||||
-rw-r--r-- | src/menu/frame.hpp | 11 | ||||
-rw-r--r-- | src/menu/frame_background.cpp | 38 | ||||
-rw-r--r-- | src/menu/text.cpp | 2 |
12 files changed, 80 insertions, 111 deletions
diff --git a/src/menu/frame_background.hpp b/src/menu/background.hpp index 9cb7c504..4f997700 100644 --- a/src/menu/frame_background.hpp +++ b/src/menu/background.hpp @@ -24,27 +24,26 @@ * $Id$ */ -#ifndef FRAME_BACKGROUND_HPP -#define FRAME_BACKGROUND_HPP +#ifndef BACKGROUND_HPP +#define BACKGROUND_HPP #include "drawable.hpp" namespace usdx { - // Exception - class FrameBackgroundException { }; - - // FrameBackground - abstract class for FrameBackgrounds - class FrameBackground : public Drawable + // Background - abstract class for Backgrounds + class Background : public Drawable { public: - FrameBackground(); - virtual ~FrameBackground(); + virtual ~Background() {}; protected: + // abstract base class + Background() {}; + // no copy and no assignment - FrameBackground(const FrameBackground&); - FrameBackground& operator=(const FrameBackground&); + Background(const Background&); + Background& operator=(const Background&); }; }; diff --git a/src/menu/frame_background_color.cpp b/src/menu/background_color.cpp index a0558082..aa8a90d2 100644 --- a/src/menu/frame_background_color.cpp +++ b/src/menu/background_color.cpp @@ -24,22 +24,22 @@ * $Id$ */ -#include "frame_background_color.hpp" +#include "background_color.hpp" #include <GL/gl.h> namespace usdx { - FrameBackgroundColor::FrameBackgroundColor(RgbColor &color) : + BackgroundColor::BackgroundColor(RgbColor &color) : color(color) { } - FrameBackgroundColor::FrameBackgroundColor(void) : + BackgroundColor::BackgroundColor(void) : color(0, 0, 0) { } - void FrameBackgroundColor::draw() + void BackgroundColor::draw() { glClearColor(color.get_red(), color.get_green(), color.get_blue(), 1.0f); glClear(GL_COLOR_BUFFER_BIT); diff --git a/src/menu/frame_background_color.hpp b/src/menu/background_color.hpp index 2e850d2c..d91edcdf 100644 --- a/src/menu/frame_background_color.hpp +++ b/src/menu/background_color.hpp @@ -24,15 +24,15 @@ * $Id$ */ -#ifndef FRAME_BACKGROUND_COLOR_HPP -#define FRAME_BACKGROUND_COLOR_HPP +#ifndef BACKGROUND_COLOR_HPP +#define BACKGROUND_COLOR_HPP -#include "frame_background.hpp" +#include "background.hpp" #include "utils/rgb_color.hpp" namespace usdx { - class FrameBackgroundColor : public FrameBackground + class BackgroundColor : public Background { private: RgbColor color; @@ -41,8 +41,8 @@ namespace usdx void draw(void); public: - FrameBackgroundColor(void); - FrameBackgroundColor(RgbColor &color); + BackgroundColor(void); + BackgroundColor(RgbColor &color); }; }; diff --git a/src/menu/frame_background_image.cpp b/src/menu/background_image.cpp index 893d573c..c8d8642c 100644 --- a/src/menu/frame_background_image.cpp +++ b/src/menu/background_image.cpp @@ -24,11 +24,11 @@ * $Id$ */ -#include "frame_background_image.hpp" +#include "background_image.hpp" namespace usdx { - FrameBackgroundImage::FrameBackgroundImage(boost::filesystem::wpath filename) + BackgroundImage::BackgroundImage(boost::filesystem::wpath filename) { texture = new Texture(filename); @@ -68,12 +68,12 @@ namespace usdx this->tex[7] = 0.0f; } - FrameBackgroundImage::~FrameBackgroundImage() + BackgroundImage::~BackgroundImage() { delete texture; } - void FrameBackgroundImage::draw(void) + void BackgroundImage::draw(void) { glClear(GL_COLOR_BUFFER_BIT); diff --git a/src/menu/frame_background_image.hpp b/src/menu/background_image.hpp index 5aaa58b6..7c0549bf 100644 --- a/src/menu/frame_background_image.hpp +++ b/src/menu/background_image.hpp @@ -24,18 +24,18 @@ * $Id$ */ -#ifndef FRAME_BACKGROUND_IMAGE_HPP -#define FRAME_BACKGROUND_IMAGE_HPP +#ifndef BACKGROUND_IMAGE_HPP +#define BACKGROUND_IMAGE_HPP #include <boost/filesystem.hpp> #include <GL/gl.h> -#include "frame_background.hpp" +#include "background.hpp" #include "texture.hpp" namespace usdx { - class FrameBackgroundImage : public FrameBackground + class BackgroundImage : public Background { private: Texture* texture; @@ -48,8 +48,8 @@ namespace usdx void draw(void); public: - FrameBackgroundImage(boost::filesystem::wpath filename); - virtual ~FrameBackgroundImage(); + BackgroundImage(boost::filesystem::wpath filename); + virtual ~BackgroundImage(); }; }; diff --git a/src/menu/container.cpp b/src/menu/container.cpp index bf742dff..8c267819 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -58,6 +58,8 @@ namespace usdx void Container::draw(void) { + DrawableControl::draw(); + if (frame) { frame->repaint(); } diff --git a/src/menu/drawable_control.cpp b/src/menu/drawable_control.cpp index 9d00d3f1..a0b4ad27 100644 --- a/src/menu/drawable_control.cpp +++ b/src/menu/drawable_control.cpp @@ -37,7 +37,8 @@ namespace usdx DrawableControl::DrawableControl(Container* parent) : Control(parent), position(0, 0), size(0, 0), - clipping_required(false), parent(parent) + clipping_required(false), background(NULL), + parent(parent) { ContainerHelper(this).add(parent); } @@ -45,7 +46,8 @@ namespace usdx DrawableControl::DrawableControl(Container* parent, const ContainerHelper& helper) : Control(parent), position(0, 0), size(0, 0), - clipping_required(false), parent(parent) + clipping_required(false), background(NULL), + parent(parent) { helper.add(parent); } @@ -53,6 +55,11 @@ namespace usdx DrawableControl::~DrawableControl() { remove_parent(); + + if (background) { + delete background; + background = NULL; + } } bool DrawableControl::get_clipping_required(void) const @@ -66,6 +73,14 @@ namespace usdx clipping_required = value; } + void DrawableControl::draw(void) + { + boost::mutex::scoped_lock lock(background_mutex); + if (background) { + background->repaint(); + } + } + void DrawableControl::repaint(void) { { @@ -164,4 +179,19 @@ namespace usdx c->add(self); } } + + void DrawableControl::set_background(Background* background) + { + boost::mutex::scoped_lock lock(background_mutex); + if (this->background) { + delete this->background; + } + + this->background = background; + } + + const Background* DrawableControl::get_background(void) const + { + return background; + } }; diff --git a/src/menu/drawable_control.hpp b/src/menu/drawable_control.hpp index 261f0514..fa1fdd4d 100644 --- a/src/menu/drawable_control.hpp +++ b/src/menu/drawable_control.hpp @@ -35,6 +35,7 @@ #include "control.hpp" #include "utils/point.hpp" #include "utils/dimension.hpp" +#include "background.hpp" namespace usdx { @@ -50,9 +51,12 @@ namespace usdx bool clipping_required; + Background* background; + boost::mutex position_mutex; boost::mutex size_mutex; boost::mutex clipping_required_mutex; + boost::mutex background_mutex; protected: Container* parent; @@ -71,6 +75,8 @@ namespace usdx bool get_clipping_required(void) const; void set_clipping_required(const bool); + virtual void draw(void); + public: DrawableControl(Container*); virtual ~DrawableControl(); @@ -92,6 +98,9 @@ namespace usdx int get_height(void) const; void remove_parent(void); + + void set_background(Background*); + const Background* get_background(void) const; }; }; diff --git a/src/menu/frame.cpp b/src/menu/frame.cpp index cbf073f5..ae529444 100644 --- a/src/menu/frame.cpp +++ b/src/menu/frame.cpp @@ -32,12 +32,12 @@ namespace usdx log4cpp::Category::getInstance("usdx.menu.frame"); Frame::Frame(Container* parent) - : Container(parent, FrameContainerHelper(this)), background(NULL) + : Container(parent, FrameContainerHelper(this)) { } - Frame::Frame(Container* parent, FrameBackground* background) - : Container(parent, FrameContainerHelper(this)), background(background) + Frame::Frame(Container* parent, Background* background) + : Container(parent, FrameContainerHelper(this)) { } @@ -47,34 +47,6 @@ namespace usdx parent->removeFrame(); parent = NULL; } - - if (background) { - delete background; - background = NULL; - } - } - - void Frame::set_background(FrameBackground* background) - { - if (this->background) { - delete this->background; - } - - this->background = background; - } - - const FrameBackground* Frame::get_background(void) const - { - return background; - } - - void Frame::draw(void) - { - if (background) { - background->repaint(); - } - - Container::draw(); } Frame::FrameContainerHelper::FrameContainerHelper(Frame* self) : diff --git a/src/menu/frame.hpp b/src/menu/frame.hpp index 7b2e315a..eeeee4e1 100644 --- a/src/menu/frame.hpp +++ b/src/menu/frame.hpp @@ -31,7 +31,7 @@ #include <log4cpp/Category.hh> #include "container.hpp" -#include "frame_background.hpp" +#include "background.hpp" namespace usdx { @@ -39,7 +39,6 @@ namespace usdx { private: static log4cpp::Category& log; - FrameBackground* background; protected: class FrameContainerHelper : public ContainerHelper @@ -52,17 +51,11 @@ namespace usdx virtual void add(Container*) const; }; - virtual void draw(void); - public: Frame(Container*); - Frame(Container*, FrameBackground*); + Frame(Container*, Background*); virtual ~Frame(); - - void set_background(FrameBackground* background); - - const FrameBackground* get_background() const; }; }; diff --git a/src/menu/frame_background.cpp b/src/menu/frame_background.cpp deleted file mode 100644 index 5c18cf45..00000000 --- a/src/menu/frame_background.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 "frame_background.hpp" - -namespace usdx -{ - FrameBackground::FrameBackground() - { - } - - FrameBackground::~FrameBackground() - { - } -}; diff --git a/src/menu/text.cpp b/src/menu/text.cpp index 96c22626..aa4a3195 100644 --- a/src/menu/text.cpp +++ b/src/menu/text.cpp @@ -79,6 +79,8 @@ namespace usdx void Text::draw(void) { + DrawableControl::draw(); + boost::mutex::scoped_lock lock(font_mutex); glTranslatef(offset.get_x(), offset.get_y(), 0.0f); |