From 9c341039e3ce938c51dcf948ed66e12480fdfe75 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 20 Nov 2009 20:59:50 +0000 Subject: [PATCH] Delete old GUI code --- include/gui/IContainer.hpp | 54 ------------ include/gui/IControl.hpp | 94 -------------------- include/gui/IImage.hpp | 42 --------- include/gui/Internal.hpp | 117 ------------------------- src/gui/Button.cpp | 106 ----------------------- src/gui/FlowBox.cpp | 173 ------------------------------------- src/gui/FuelMeter.cpp | 127 --------------------------- src/gui/Image.cpp | 83 ------------------ src/gui/Label.cpp | 101 ---------------------- src/gui/Panel.cpp | 87 ------------------- src/gui/ThrottleMeter.cpp | 141 ------------------------------ 11 files changed, 1125 deletions(-) delete mode 100644 include/gui/IContainer.hpp delete mode 100644 include/gui/IControl.hpp delete mode 100644 include/gui/IImage.hpp delete mode 100644 include/gui/Internal.hpp delete mode 100644 src/gui/Button.cpp delete mode 100644 src/gui/FlowBox.cpp delete mode 100644 src/gui/FuelMeter.cpp delete mode 100644 src/gui/Image.cpp delete mode 100644 src/gui/Label.cpp delete mode 100644 src/gui/Panel.cpp delete mode 100644 src/gui/ThrottleMeter.cpp diff --git a/include/gui/IContainer.hpp b/include/gui/IContainer.hpp deleted file mode 100644 index 6749262..0000000 --- a/include/gui/IContainer.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#ifndef INC_GUI_ICONTAINER_HPP -#define INC_GUI_ICONTAINER_HPP - -#include "Platform.hpp" -#include "IControl.hpp" - -// GUI objects that contain other controls -namespace gui { - - struct IContainer : IControl { - virtual ~IContainer() {} - - // Add a control to the container in the next available position - virtual void addChild(IControlPtr aControl) = 0; - - // Set the absolute position of the container - // Note that containers ignore the position on calls - // to render - virtual void setOrigin(int x, int y) = 0; - - // Get the position of the origin - void origin(int& x, int& y) const; - }; - - typedef std::tr1::shared_ptr IContainerPtr; - - enum FlowBoxStyle { - FLOW_BOX_HORIZ, FLOW_BOX_VERT - }; - - // Standard containers - IContainerPtr makeFlowBox(FlowBoxStyle aStyle, bool wantSpacing=true); - IContainerPtr makeToolbar(); - IContainerPtr makePanel(const string& aTitle, IContainerPtr aContent); -} - -#endif diff --git a/include/gui/IControl.hpp b/include/gui/IControl.hpp deleted file mode 100644 index 471d0ed..0000000 --- a/include/gui/IControl.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#ifndef INC_GUI_ICONTROL_HPP -#define INC_GUI_ICONTROL_HPP - -#include "Platform.hpp" -#include "IFont.hpp" -#include "Colour.hpp" - -#include - -#include - -namespace gui { - - // Interface to any UI control - struct IControl { - virtual ~IControl() {} - - // Render in a specific place - virtual void render(int x=0, int y=0) const = 0; - - // Return the dimensions of the control - virtual int width() const = 0; - virtual int height() const = 0; - - // Show / hide the control - virtual void setVisible(bool visible) = 0; - - // Events - // Return true if handled - virtual bool handleClick(int x, int y) = 0; - virtual bool handleMouseRelease(int x, int y) = 0; - }; - - typedef std::tr1::shared_ptr IControlPtr; - - // Interface to clickable controls - struct IButton : IControl { - virtual ~IButton() {} - - typedef std::tr1::function ClickHandler; - - virtual void onClick(ClickHandler aHandler) = 0; - }; - - typedef std::tr1::shared_ptr IButtonPtr; - - // Interface to a UI control that contains text - struct ITextControl : IControl { - virtual ~ITextControl() {} - - virtual void setText(const std::string& aString) = 0; - virtual void setText(const char* fmt, ...) = 0; - - virtual void setColour(float r, float g, float b) = 0; - }; - - typedef std::tr1::shared_ptr ITextControlPtr; - - // Interface to controls that are progress meters, etc. - struct IMeterControl : IControl { - virtual ~IMeterControl() {} - - virtual void setValue(int aValue) = 0; - virtual void setRange(int aLowValue, int aHighValue) = 0; - }; - - typedef std::tr1::shared_ptr IMeterControlPtr; - - // Standard controls - IButtonPtr makeButton(const std::string& aGlyphFile); - ITextControlPtr makeLabel(IFontPtr aFont, const std::string& aString=""); - IMeterControlPtr makeThrottleMeter(IFontPtr aFont); - IMeterControlPtr makeFuelMeter(IFontPtr aFont, const std::string& aCaption, - const Colour& aColour); -} - -#endif diff --git a/include/gui/IImage.hpp b/include/gui/IImage.hpp deleted file mode 100644 index bc84e09..0000000 --- a/include/gui/IImage.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#ifndef INC_IIMAGE_HPP -#define INC_IIMAGE_HPP - -#include "Platform.hpp" - -#include - -namespace gui { - - // Displays a simple 2D image - // This is not a control but is used by some of them - struct IImage { - virtual ~IImage() {} - - virtual void render(int x, int y) const = 0; - virtual int width() const = 0; - virtual int height() const = 0; - }; - - typedef std::tr1::shared_ptr IImagePtr; - - IImagePtr makeImage(const std::string& aFile); -} - -#endif diff --git a/include/gui/Internal.hpp b/include/gui/Internal.hpp deleted file mode 100644 index bb8672c..0000000 --- a/include/gui/Internal.hpp +++ /dev/null @@ -1,117 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#ifndef INC_INTERNAL_HPP -#define INC_INTERNAL_HPP - -#include "IControl.hpp" - -// Common implementation details for GUI components -namespace gui { - - // It would be nice if we could use variadic templates to - // implement variable-arity generic constructors but these - // are only supported in experimental GCC and not at all - // in Visual C++ - - // Mixin to add hide/show ability - template - class Hideable : public Base { - public: - Hideable() : amVisible(true) {} - - template - Hideable(const A& a) - : Base(a), amVisible(true) {} - - template - Hideable(const A& a, const B& b) - : Base(a, b), amVisible(true) {} - - template - Hideable(const A& a, const B& b, const C& c) - : Base(a, b, c), amVisible(true) {} - - virtual ~Hideable() {} - - void setVisible(bool visible) - { - amVisible = visible; - } - - void render(int x, int y) const - { - if (amVisible) - Base::render(x, y); - } - private: - bool amVisible; - }; - - // Mixin to provide default event handlers - template - class Defaults : public Base { - public: - Defaults() {} - - template - Defaults(const A& a) - : Base(a) {} - - template - Defaults(const A& a, const B& b) - : Base(a, b) {} - - template - Defaults(const A& a, const B& b, const C& c) - : Base(a, b, c) {} - - virtual ~Defaults() {} - - virtual bool handleClick(int x, int y) { return false; } - virtual bool handleMouseRelease(int x, int y) { return false; } - }; - - // Mixin to provide screen placement - template - class Moveable : public Base { - public: - Moveable() : myX(0), myY(0) {} - - template - Moveable(const A& a) - : Base(a), myX(0), myY(0) {} - - template - Moveable(const A& a, const B& b) - : Base(a, b), myX(0), myY(0) {} - - template - Moveable(const A& a, const B& b, const C& c) - : Base(a, b, c), myX(0), myY(0) {} - - virtual ~Moveable() {} - - void setOrigin(int x, int y) { myX = x; myY = y; } - void origin(int& x, int& y) const { x = myX; y = myY; } - private: - int myX, myY; - }; - -} - -#endif diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp deleted file mode 100644 index fb1101a..0000000 --- a/src/gui/Button.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#include "gui/IControl.hpp" -#include "gui/IImage.hpp" -#include "gui/Internal.hpp" - -#include - -using namespace gui; -using namespace std; - -// Concrete implementation of push buttons -class Button : public IButton { -public: - Button(const string& aGlyphFile); - virtual ~Button() {} - - // IControl interface - int width() const; - int height() const; - void render(int x, int y) const; - bool handleClick(int x, int y); - bool handleMouseRelease(int x, int y); - - // IButton interface - void onClick(ClickHandler aHandler); -private: - IImagePtr myGlyphImage; - boost::signal myClickSignal; - bool amActive; - - static IImagePtr ourBaseImage, ourActiveImage; -}; - -IImagePtr Button::ourBaseImage, Button::ourActiveImage; - -Button::Button(const string& aGlyphFile) - : amActive(false) -{ - if (!ourBaseImage) - ourBaseImage = makeImage("data/images/button_base.png"); - - if (!ourActiveImage) - ourActiveImage = makeImage("data/images/button_active.png"); - - myGlyphImage = makeImage(aGlyphFile); -} - -void Button::onClick(ClickHandler aHandler) -{ - myClickSignal.connect(aHandler); -} - -int Button::width() const -{ - return myGlyphImage->width(); -} - -int Button::height() const -{ - return myGlyphImage->height(); -} - -void Button::render(int x, int y) const -{ - if (amActive) - ourActiveImage->render(x, y); - else - ourBaseImage->render(x, y); - myGlyphImage->render(x, y); -} - -bool Button::handleClick(int x, int y) -{ - amActive = true; - myClickSignal(); - return true; -} - -bool Button::handleMouseRelease(int x, int y) -{ - amActive = false; - return true; -} - -IButtonPtr gui::makeButton(const string& aGlyphFile) -{ - return IButtonPtr - (new Moveable >(aGlyphFile)); -} - diff --git a/src/gui/FlowBox.cpp b/src/gui/FlowBox.cpp deleted file mode 100644 index b82b72d..0000000 --- a/src/gui/FlowBox.cpp +++ /dev/null @@ -1,173 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#include "gui/IContainer.hpp" -#include "gui/Internal.hpp" - -#include -#include - -using namespace gui; -using namespace placeholders; - -// A container which grows either horizontally or vertically as controls -// are added -class FlowBox : public Moveable { -public: - FlowBox(FlowBoxStyle aStyle, bool doesWantSpacing); - ~FlowBox() {} - - // IContainer interface - void addChild(IControlPtr aControl); - - // IControl interface - int width() const; - int height() const; - bool handleClick(int mouseX, int mouseY); - bool handleMouseRelease(int mouseX, int mouseY); - void render(int x, int y) const = 0; -private: - typedef function PositionVisitor; - void positionAfterControl(IControlPtr aControl, int& x, int& y) const; - - static void clickTest(IControlPtr aControl, int ctrlX, int ctrlY, - int mouseX, int mouseY, bool* handled); - - FlowBoxStyle myStyle; - bool wantSpacing; - - typedef vector ControlList; - ControlList myControls; - - static const int SPACING = 10; -}; - -FlowBox::FlowBox(FlowBoxStyle aStyle, bool doesWantSpacing) - : myStyle(aStyle), wantSpacing(doesWantSpacing) -{ - -} - -bool FlowBox::handleClick(int mouseX, int mouseY) -{ - bool handled = false; - - int x, y; - origin(x, y); - - for (ControlList::const_iterator it = myControls.begin(); - it != myControls.end(); ++it) { - clickTest(*it, x, y, mouseX, mouseY, &handled); - - positionAfterControl(*it, x, y); - } - - return handled; -} - -bool FlowBox::handleMouseRelease(int mouseX, int mouseY) -{ - int x, y; - origin(x, y); - - for (ControlList::const_iterator it = myControls.begin(); - it != myControls.end(); ++it) { - (*it)->handleMouseRelease(mouseX, mouseY); - - positionAfterControl(*it, x, y); - } - - return false; -} - -void FlowBox::clickTest(IControlPtr aControl, int ctrlX, int ctrlY, - int mouseX, int mouseY, bool* handled) -{ - if (mouseX >= ctrlX && mouseX < ctrlX + aControl->width() - && mouseY >= mouseY && mouseY < ctrlY + aControl->height()) { - aControl->handleClick(mouseX, mouseY); - *handled = true; - } -} - -int FlowBox::width() const -{ - int w = 0; - - // Width is the maximum for BOX_VERT and sum for BOX_HORIZ - for (ControlList::const_iterator it = myControls.begin(); - it != myControls.end(); ++it) { - if (myStyle == FLOW_BOX_VERT) - w = max(w, (*it)->width()); - else - w += (*it)->width(); - } - - return w; -} - -int FlowBox::height() const -{ - int h = 0; - - // Height is the sum for BOX_VERT and maximum for BOX_HORIZ - for (ControlList::const_iterator it = myControls.begin(); - it != myControls.end(); ++it) { - if (myStyle == FLOW_BOX_VERT) - h = max(h, (*it)->height()); - else - h += (*it)->height(); - } - - return h; -} - -void FlowBox::positionAfterControl(IControlPtr aControl, int& x, int& y) const -{ - if (myStyle == FLOW_BOX_VERT) - y += aControl->height() + (wantSpacing ? SPACING : 0); - else - x += aControl->width() + (wantSpacing ? SPACING : 0); -} - -void FlowBox::render(int absX, int absY) const -{ - int x, y; - origin(x, y); - - for (ControlList::const_iterator it = myControls.begin(); - it != myControls.end(); ++it) { - (*it)->render(x, y); - - positionAfterControl(*it, x, y); - } -} - -void FlowBox::addChild(IControlPtr aControl) -{ - myControls.push_back(aControl); -} - -IContainerPtr gui::makeFlowBox(FlowBoxStyle aStyle, bool wantSpacing) -{ - return IContainerPtr(new Hideable(aStyle, wantSpacing)); -} - -IContainerPtr gui::makeToolbar() -{ - return makeFlowBox(FLOW_BOX_HORIZ, false); -} diff --git a/src/gui/FuelMeter.cpp b/src/gui/FuelMeter.cpp deleted file mode 100644 index 4676902..0000000 --- a/src/gui/FuelMeter.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#include "gui/IControl.hpp" -#include "gui/Internal.hpp" -#include "OpenGLHelper.hpp" - -#include - -#include -#include - -using namespace gui; -using namespace std; -using namespace std::tr1; -using namespace boost; - -class FuelMeter : public IMeterControl { -public: - FuelMeter(IFontPtr aFont, const string& aCaption, - const Colour& aColour); - ~FuelMeter() {} - - // IControl interface - void render(int x, int y) const; - int width() const; - int height() const; - - // IMeterControl interface - void setValue(int aValue); - void setRange(int aLowValue, int aHighValue); -private: - int myValue; - IFontPtr myFont; - const string myCaption; - const Colour myColour; - const int myTextWidth; - int myMin, myMax; - - static const int METER_HEIGHT, METER_WIDTH; -}; - -const int FuelMeter::METER_HEIGHT(16); -const int FuelMeter::METER_WIDTH(100); - -FuelMeter::FuelMeter(IFontPtr aFont, const string& aCaption, - const Colour& aColour) - : myValue(0), myFont(aFont), myCaption(aCaption + ": "), - myColour(aColour), - myTextWidth(myFont->string_width(myCaption.c_str())), - myMin(0), myMax(10) -{ - -} - -int FuelMeter::height() const -{ - return max(myFont->max_height(), METER_HEIGHT); -} - -int FuelMeter::width() const -{ - return myTextWidth + METER_WIDTH; -} - -void FuelMeter::setValue(int aValue) -{ - if (aValue < myMin) - throw runtime_error("Fuel meter underflow: " - + lexical_cast(aValue)); - else if (aValue > myMax) - throw runtime_error("Fuel meter overflow: " - + lexical_cast(aValue)); - - myValue = aValue; -} - -void FuelMeter::setRange(int aLowValue, int aHighValue) -{ - myMin = aLowValue; - myMax = aHighValue; -} - -void FuelMeter::render(int x, int y) const -{ - myFont->print(x, y, myCaption.c_str()); - - glPushMatrix(); - - const int off = height() - METER_HEIGHT + 1; - - glTranslatef(static_cast(myTextWidth), - static_cast(y + off), 0.0f); - - const float unit = METER_WIDTH / static_cast(myMax + 1); - - gl::colour(myColour); - glBegin(GL_QUADS); - glVertex2i(0, 0); - glVertex2i(0, METER_HEIGHT); - glVertex2f(unit * myValue, static_cast(METER_HEIGHT)); - glVertex2f(unit * myValue, 0); - glEnd(); - - glPopMatrix(); -} - -IMeterControlPtr gui::makeFuelMeter(IFontPtr aFont, const string& aCaption, - const Colour& aColour) -{ - return IMeterControlPtr - (new Defaults > >(aFont, aCaption, aColour)); -} diff --git a/src/gui/Image.cpp b/src/gui/Image.cpp deleted file mode 100644 index 7710e3f..0000000 --- a/src/gui/Image.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#include "gui/IImage.hpp" -#include "ITexture.hpp" - -#include - -using namespace gui; -using namespace std; - -// Concrete implementaton of images -class Image : public IImage { -public: - Image(const string& aFile); - ~Image() {} - - void render(int x, int y) const; - int width() const; - int height() const; -private: - ITexturePtr myTexture; -}; - -Image::Image(const string& aFile) -{ - myTexture = loadTexture(aFile); -} - -int Image::width() const -{ - return myTexture->width(); -} - -int Image::height() const -{ - return myTexture->height(); -} - -void Image::render(int x, int y) const -{ - glPushAttrib(GL_ENABLE_BIT); - glEnable(GL_TEXTURE_2D); - - myTexture->bind(); - - const int w = myTexture->width(); - const int h = myTexture->height(); - - glColor4f(1.0f, 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(); -} - -IImagePtr gui::makeImage(const string& aFile) -{ - return IImagePtr(new Image(aFile)); -} diff --git a/src/gui/Label.cpp b/src/gui/Label.cpp deleted file mode 100644 index ca29cc4..0000000 --- a/src/gui/Label.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#include "gui/IControl.hpp" -#include "gui/Internal.hpp" - -#include -#include -#include - -using namespace gui; -using namespace std; - -// A simple text label -class Label : public ITextControl { -public: - Label(IFontPtr aFont, const std::string& aString); - virtual ~Label() {} - - // IControl interface - int width() const; - int height() const; - void render(int x, int y) const; - - // ITextControl interface - void setText(const string& aString) { myText = aString; } - void setText(const char* fmt, ...); - void setColour(float r, float g, float b); -private: - string myText; - IFontPtr myFont; - float myR, myG, myB; -}; - -Label::Label(IFontPtr aFont, const std::string& aString) - : myText(aString), myFont(aFont), - myR(1.0f), myG(1.0f), myB(1.0f) -{ - -} - -void Label::setColour(float r, float g, float b) -{ - myR = r; - myG = g; - myB = b; -} - -int Label::width() const -{ - return myFont->string_width(myText.c_str()); -} - -int Label::height() const -{ - return myFont->max_height(); -} - -void Label::render(int x, int y) const -{ - float r, g, b, a; - myFont->get_colour(r, g, b, a); - - myFont->set_colour(myR, myG, myB, 1.0f); - myFont->print(x, y, myText.c_str()); - - myFont->set_colour(r, g, b, a); -} - -void Label::setText(const char* fmt, ...) -{ - const int MAX_FMT_LENGTH = 1024; - static char buf[MAX_FMT_LENGTH]; - - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, MAX_FMT_LENGTH, fmt, ap); - va_end(ap); - - myText = buf; -} - -ITextControlPtr gui::makeLabel(IFontPtr aFont, const std::string& aString) -{ - return ITextControlPtr - (new Defaults > >(aFont, aString)); -} diff --git a/src/gui/Panel.cpp b/src/gui/Panel.cpp deleted file mode 100644 index c3490e7..0000000 --- a/src/gui/Panel.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#include "gui/IContainer.hpp" -#include "gui/Internal.hpp" - -#include - -using namespace gui; - -// A window with a title bar -class Panel : public Defaults > { -public: - Panel(const string& aTitle, IContainerPtr aContent); - ~Panel() {} - - // IControl interface - int width() const; - int height() const; - void render(int x, int y) const; - - // IContainer interface - void addChild(IControlPtr aControl) { myContent->addChild(aControl); } -private: - string myTitle; - int myTitleWidth; - IFontPtr myFont; - IContainerPtr myContent; - - static const int TITLE_PAD = 6; -}; - -Panel::Panel(const string& aTitle, IContainerPtr aContent) - : myTitle(aTitle), myContent(aContent) -{ - myFont = load_font("data/fonts/Vera.ttf", 13, false); - myFont->set_colour(0.0f, 0.0f, 0.0f); - myTitleWidth = myFont->string_width(aTitle.c_str()); -} - -void Panel::render(int x, int y) const -{ - // Discard the given x and y and use the absolute position - origin(x, y); - - const int w = width(); - const int h = height(); - - glColor4f(1.0f, 1.0f, 1.0f, 0.9f); - glBegin(GL_QUADS); - glVertex2i(x, y); - glVertex2i(x + w, y); - glVertex2i(x + w, y + h); - glVertex2i(x, y + h); - glEnd(); - - myFont->print(x + TITLE_PAD, y + TITLE_PAD, myTitle.c_str()); -} - -int Panel::width() const -{ - return max(myTitleWidth + 2*TITLE_PAD, myContent->width()); -} - -int Panel::height() const -{ - return myFont->max_height() + 2*TITLE_PAD + myContent->height(); -} - -IContainerPtr gui::makePanel(const string& aTitle, IContainerPtr aContent) -{ - return IContainerPtr(new Hideable(aTitle, aContent)); -} diff --git a/src/gui/ThrottleMeter.cpp b/src/gui/ThrottleMeter.cpp deleted file mode 100644 index eeacdb7..0000000 --- a/src/gui/ThrottleMeter.cpp +++ /dev/null @@ -1,141 +0,0 @@ -// -// Copyright (C) 2009 Nick Gasson -// -// 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 3 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. If not, see . -// - -#include "gui/IControl.hpp" -#include "gui/Internal.hpp" - -#include - -#include - -using namespace std; -using namespace gui; - -class ThrottleMeter : public IMeterControl { -public: - ThrottleMeter(IFontPtr aFont); - ~ThrottleMeter() {} - - // IControl interface - int width() const; - int height() const; - void render(int x, int y) const; - - // IMeterControl interface - void setValue(int aValue); - void setRange(int aLowValue, int aHighValue); -private: - int myValue; - IFontPtr myFont; - const int myTextWidth; - int myMin, myMax; - - static const int THROTTLE_MAX = 10; - static const int THROTTLE_MIN = 0; - - static const int METER_HEIGHT, METER_WIDTH; -}; - -const int ThrottleMeter::METER_HEIGHT(16); -const int ThrottleMeter::METER_WIDTH(100); - -ThrottleMeter::ThrottleMeter(IFontPtr aFont) - : myValue(0), myFont(aFont), - myTextWidth(myFont->string_width("Throttle: ")), - myMin(THROTTLE_MIN), myMax(THROTTLE_MAX) -{ - -} - -int ThrottleMeter::height() const -{ - return max(myFont->max_height(), METER_HEIGHT); -} - -int ThrottleMeter::width() const -{ - return myTextWidth + METER_WIDTH; -} - -void ThrottleMeter::setValue(int aValue) -{ - myValue = aValue; -} - -void ThrottleMeter::setRange(int aLowValue, int aHighValue) -{ - myMin = aLowValue; - myMax = aHighValue; -} - -void ThrottleMeter::render(int x, int y) const -{ - myFont->print(x, y, "Throttle: "); - - glPushMatrix(); - - const int off = height() - METER_HEIGHT + 1; - - glTranslatef(static_cast(myTextWidth), - static_cast(y + off), 0.0f); - - const int unit = METER_WIDTH / (myMax + 1); - - // Neutral bit - glColor3f(1.0f, 1.0f, 0.0f); - glBegin(GL_QUADS); - glVertex2i(0, 0); - glVertex2i(0, METER_HEIGHT); - glVertex2i(unit, METER_HEIGHT); - glVertex2i(unit, 0); - glEnd(); - - int squareLen = myValue >= myMax - ? (myMax - 1) * unit - : (myValue > 0 ? unit * (myValue - 1) : 0); - - glTranslatef(static_cast(unit), 0.0f, 0.0f); - glColor3f(0.0f, 1.0f, 0.0f); - - // Forwards bit - if (squareLen > 0) { - glBegin(GL_QUADS); - glVertex2i(0, 0); - glVertex2i(0, METER_HEIGHT); - glVertex2i(squareLen, METER_HEIGHT); - glVertex2i(squareLen, 0); - glEnd(); - } - - const bool wantTriangle = myValue < myMax && myValue > 0; - if (wantTriangle) { - // Triangle bit - glBegin(GL_TRIANGLES); - glVertex2i(squareLen, 0); - glVertex2i(squareLen, METER_HEIGHT); - glVertex2i(squareLen + unit, METER_HEIGHT / 2); - glEnd(); - } - - glPopMatrix(); -} - -IMeterControlPtr gui::makeThrottleMeter(IFontPtr aFont) -{ - return IMeterControlPtr - (new Defaults > >(aFont)); -} -- 2.39.2