From 4fd71d50f507c941200d52716fd7010f9a6e7bd5 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 5 Dec 2009 13:11:30 +0000 Subject: [PATCH] Display images in toggle bar buttons --- include/gui/RenderContext.hpp | 2 ++ include/gui/ToggleButton.hpp | 4 ++++ layouts/editor.xml | 3 ++- src/gui/RenderContext.cpp | 24 ++++++++++++++++++++++++ src/gui/ToggleButton.cpp | 5 +++-- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/gui/RenderContext.hpp b/include/gui/RenderContext.hpp index 3fce9d7..2d63cd7 100644 --- a/include/gui/RenderContext.hpp +++ b/include/gui/RenderContext.hpp @@ -22,6 +22,7 @@ #include "Platform.hpp" #include "Colour.hpp" +#include "ITexture.hpp" #include "gui/Theme.hpp" #include @@ -43,6 +44,7 @@ namespace gui { void rectangle(int x, int y, int w, int h, Colour c); void border(int x, int y, int w, int h, Colour c); + void image(int x, int y, int w, int h, ITexturePtr tex); void print(IFontPtr font, int x, int y, const string& s, Colour col = colour::WHITE); diff --git a/include/gui/ToggleButton.hpp b/include/gui/ToggleButton.hpp index 0772dc2..ea173dc 100644 --- a/include/gui/ToggleButton.hpp +++ b/include/gui/ToggleButton.hpp @@ -19,6 +19,7 @@ #define INC_TOGGLE_BUTTON_HPP #include "Platform.hpp" +#include "ITexture.hpp" #include "gui/Widget.hpp" namespace gui { @@ -29,6 +30,9 @@ namespace gui { ToggleButton(const AttributeSet& attrs); void render(RenderContext& rc) const; + + private: + ITexturePtr texture; }; } diff --git a/layouts/editor.xml b/layouts/editor.xml index 2d33e5c..1efeaf8 100644 --- a/layouts/editor.xml +++ b/layouts/editor.xml @@ -7,7 +7,8 @@ x="5" y="5"/> - + diff --git a/src/gui/RenderContext.cpp b/src/gui/RenderContext.cpp index edd6cc8..be6c186 100644 --- a/src/gui/RenderContext.cpp +++ b/src/gui/RenderContext.cpp @@ -90,6 +90,30 @@ void RenderContext::border(int x, int y, int w, int h, Colour c) glEnd(); } +void RenderContext::image(int x, int y, int w, int h, ITexturePtr tex) +{ + glPushAttrib(GL_ENABLE_BIT); + glEnable(GL_TEXTURE_2D); + + offset(x, y); + + tex->bind(); + glColor3f(1.0f, 1.0f, 1.0f); + + glBegin(GL_QUADS); + glTexCoord2i(0, 0); + glVertex2i(x, y); + glTexCoord2i(1, 0); + glVertex2i(x + w, y); + glTexCoord2i(1, 1); + glVertex2i(x + w, y + h); + glTexCoord2i(0, 1); + glVertex2i(x, y + h); + glEnd(); + + glPopAttrib(); +} + void RenderContext::print(IFontPtr font, int x, int y, const string& s, Colour col) { diff --git a/src/gui/ToggleButton.cpp b/src/gui/ToggleButton.cpp index 7094760..1837d4c 100644 --- a/src/gui/ToggleButton.cpp +++ b/src/gui/ToggleButton.cpp @@ -23,10 +23,11 @@ using namespace gui; ToggleButton::ToggleButton(const AttributeSet& attrs) : Widget(attrs) { - + texture = loadTexture(attrs.get("image")); } void ToggleButton::render(RenderContext& rc) const { - rc.rectangle(x(), y(), width(), height(), colour::WHITE); + // rc.rectangle(x(), y(), width(), height(), colour::WHITE); + rc.image(x(), y(), width(), height(), texture); } -- 2.39.2