From 36da2fd92c65c7ece4eee31b97383fb404b9aba9 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 21 Jun 2009 12:59:58 +0100 Subject: [PATCH] Add panel objects and lighthouse model --- include/BuildingPanel.hpp | 34 ++++++++ include/gui/IContainer.hpp | 2 + include/gui/IFont.hpp | 2 +- include/gui/Internal.hpp | 4 +- lighthouse.mtl | 10 +++ lighthouse.obj | 162 +++++++++++++++++++++++++++++++++++++ lighthouse.wings | Bin 0 -> 1245 bytes src/BuildingPanel.cpp | 37 +++++++++ src/Editor.cpp | 7 +- src/Game.cpp | 2 +- src/gui/FlowBox.cpp | 10 ++- src/gui/Font.cpp | 4 +- src/gui/Panel.cpp | 87 ++++++++++++++++++++ 13 files changed, 349 insertions(+), 12 deletions(-) create mode 100644 include/BuildingPanel.hpp create mode 100644 lighthouse.mtl create mode 100644 lighthouse.obj create mode 100644 lighthouse.wings create mode 100644 src/BuildingPanel.cpp create mode 100644 src/gui/Panel.cpp diff --git a/include/BuildingPanel.hpp b/include/BuildingPanel.hpp new file mode 100644 index 0000000..c89b235 --- /dev/null +++ b/include/BuildingPanel.hpp @@ -0,0 +1,34 @@ +// +// 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_BUILDINGPANEL_HPP +#define INC_BUILDINGPANEL_HPP + +#include "gui/IContainer.hpp" + +// The panel that displays building models +class BuildingPanel { +public: + BuildingPanel(); + ~BuildingPanel(); + + void render() const; +private: + gui::IContainerPtr myPanel; +}; + +#endif diff --git a/include/gui/IContainer.hpp b/include/gui/IContainer.hpp index 2baf6ad..6749262 100644 --- a/include/gui/IContainer.hpp +++ b/include/gui/IContainer.hpp @@ -47,6 +47,8 @@ namespace gui { // Standard containers IContainerPtr makeFlowBox(FlowBoxStyle aStyle, bool wantSpacing=true); + IContainerPtr makeToolbar(); + IContainerPtr makePanel(const string& aTitle, IContainerPtr aContent); } #endif diff --git a/include/gui/IFont.hpp b/include/gui/IFont.hpp index 6807ae2..c8ba454 100644 --- a/include/gui/IFont.hpp +++ b/include/gui/IFont.hpp @@ -28,7 +28,7 @@ namespace gui { struct IFont { virtual ~IFont() {} - virtual void setColour(float r, float g, float b, float a) = 0; + virtual void setColour(float r, float g, float b, float a=1.0f) = 0; virtual void getColour(float& r, float& g, float& b, float& a) const = 0; virtual void print(int x, int y, const char* fmt, ...) const = 0; virtual int stringWidth(const char* fmt, ...) const = 0; diff --git a/include/gui/Internal.hpp b/include/gui/Internal.hpp index 7a7f58c..bb8672c 100644 --- a/include/gui/Internal.hpp +++ b/include/gui/Internal.hpp @@ -82,8 +82,8 @@ namespace gui { virtual ~Defaults() {} - bool handleClick(int x, int y) { return false; } - bool handleMouseRelease(int x, int y) { return false; } + virtual bool handleClick(int x, int y) { return false; } + virtual bool handleMouseRelease(int x, int y) { return false; } }; // Mixin to provide screen placement diff --git a/lighthouse.mtl b/lighthouse.mtl new file mode 100644 index 0000000..1cb26b7 --- /dev/null +++ b/lighthouse.mtl @@ -0,0 +1,10 @@ +# Exported from Wings 3D 1.0-rc1 +newmtl default +Ns 100.0 +d 1.0 +illum 2 +Kd 1.0 1.0 1.0 +Ka 1.0 1.0 1.0 +Ks 1.0 1.0 1.0 +Ke 0.0 0.0 0.0 + diff --git a/lighthouse.obj b/lighthouse.obj new file mode 100644 index 0000000..8da41c1 --- /dev/null +++ b/lighthouse.obj @@ -0,0 +1,162 @@ +# Exported from Wings 3D 1.0-rc1 +mtllib lighthouse.mtl +o cylinder4 +#32 vertices, 60 faces +v 0.45000000 1.77111111 -1.6953237e-16 +v 0.41574579 1.77111111 0.17220754 +v 0.31819805 1.77111111 0.31819805 +v 0.17220754 1.77111111 0.41574579 +v 2.7554553e-17 1.77111111 0.45000000 +v -0.17220754 1.77111111 0.41574579 +v -0.31819805 1.77111111 0.31819805 +v -0.41574579 1.77111111 0.17220754 +v -0.45000000 1.77111111 -1.1442327e-16 +v -0.41574579 1.77111111 -0.17220754 +v -0.31819805 1.77111111 -0.31819805 +v -0.17220754 1.77111111 -0.41574579 +v -8.2663659e-17 1.77111111 -0.45000000 +v 0.17220754 1.77111111 -0.41574579 +v 0.31819805 1.77111111 -0.31819805 +v 0.41574579 1.77111111 -0.17220754 +v 0.45000000 0.25733333 -1.6953237e-16 +v 0.41574579 0.25733333 0.17220754 +v 0.31819805 0.25733333 0.31819805 +v 0.17220754 0.25733333 0.41574579 +v 2.7554553e-17 0.25733333 0.45000000 +v -0.17220754 0.25733333 0.41574579 +v -0.31819805 0.25733333 0.31819805 +v -0.41574579 0.25733333 0.17220754 +v -0.45000000 0.25733333 -1.1442327e-16 +v -0.41574579 0.25733333 -0.17220754 +v -0.31819805 0.25733333 -0.31819805 +v -0.17220754 0.25733333 -0.41574579 +v -8.2663659e-17 0.25733333 -0.45000000 +v 0.17220754 0.25733333 -0.41574579 +v 0.31819805 0.25733333 -0.31819805 +v 0.41574579 0.25733333 -0.17220754 +vn 0.89090915 0.45418155 -1.2606070e-17 +vn 0.82309273 0.45418155 0.34093617 +vn 0.38696817 0.83696551 0.38696817 +vn 0.30398942 0.60744384 0.73389537 +vn 0.0000000e+0 0.83696551 0.54725564 +vn -0.30398942 0.60744384 0.73389537 +vn -0.38696817 0.83696551 0.38696817 +vn -0.73389537 0.60744384 0.30398942 +vn -0.89090915 0.45418155 1.5127284e-16 +vn -0.82309273 0.45418155 -0.34093617 +vn -0.38696817 0.83696551 -0.38696817 +vn -0.30398942 0.60744384 -0.73389537 +vn 0.0000000e+0 0.83696551 -0.54725564 +vn 0.30398942 0.60744384 -0.73389537 +vn 0.38696817 0.83696551 -0.38696817 +vn 0.73389537 0.60744384 -0.30398942 +vn 0.96901550 -0.24699991 0.0000000e+0 +vn 0.50559828 -0.83696551 0.20942567 +vn 0.56169920 -0.60744384 0.56169920 +vn 0.20942567 -0.83696551 0.50559828 +vn 0.0000000e+0 -0.60744384 0.79436263 +vn -0.20942567 -0.83696551 0.50559828 +vn -0.56169920 -0.60744384 0.56169920 +vn -0.64691385 -0.71393252 0.26796049 +vn -0.96901550 -0.24699991 1.6453499e-16 +vn -0.50559828 -0.83696551 -0.20942567 +vn -0.56169920 -0.60744384 -0.56169920 +vn -0.20942567 -0.83696551 -0.50559828 +vn 0.0000000e+0 -0.60744384 -0.79436263 +vn 0.20942567 -0.83696551 -0.50559828 +vn 0.56169920 -0.60744384 -0.56169920 +vn 0.64691385 -0.71393252 -0.26796049 +g cylinder4_default +usemtl default +f 1//1 16//16 2//2 +f 1//1 17//17 16//16 +f 2//2 16//16 3//3 +f 2//2 17//17 1//1 +f 2//2 19//19 18//18 +f 3//3 15//15 4//4 +f 3//3 19//19 2//2 +f 4//4 14//14 5//5 +f 4//4 19//19 3//3 +f 4//4 21//21 20//20 +f 5//5 13//13 6//6 +f 5//5 21//21 4//4 +f 6//6 12//12 7//7 +f 6//6 21//21 5//5 +f 6//6 23//23 22//22 +f 7//7 11//11 8//8 +f 7//7 23//23 6//6 +f 8//8 10//10 9//9 +f 8//8 23//23 7//7 +f 8//8 25//25 24//24 +f 9//9 25//25 8//8 +f 10//10 8//8 11//11 +f 10//10 25//25 9//9 +f 10//10 27//27 26//26 +f 11//11 7//7 12//12 +f 11//11 27//27 10//10 +f 12//12 6//6 13//13 +f 12//12 27//27 11//11 +f 12//12 29//29 28//28 +f 13//13 5//5 14//14 +f 13//13 29//29 12//12 +f 14//14 4//4 15//15 +f 14//14 29//29 13//13 +f 14//14 31//31 30//30 +f 15//15 3//3 16//16 +f 15//15 31//31 14//14 +f 16//16 17//17 32//32 +f 16//16 31//31 15//15 +f 18//18 17//17 2//2 +f 18//18 32//32 17//17 +f 19//19 31//31 18//18 +f 20//20 19//19 4//4 +f 20//20 30//30 19//19 +f 21//21 29//29 20//20 +f 22//22 21//21 6//6 +f 22//22 28//28 21//21 +f 23//23 27//27 22//22 +f 24//24 23//23 8//8 +f 24//24 26//26 23//23 +f 25//25 26//26 24//24 +f 26//26 25//25 10//10 +f 27//27 23//23 26//26 +f 28//28 22//22 27//27 +f 28//28 27//27 12//12 +f 29//29 21//21 28//28 +f 30//30 20//20 29//29 +f 30//30 29//29 14//14 +f 31//31 19//19 30//30 +f 32//32 18//18 31//31 +f 32//32 31//31 16//16 +o cube2 +#8 vertices, 12 faces +v -0.50000000 2.5605287e-3 0.50000000 +v -0.50000000 0.25256053 0.50000000 +v 0.50000000 0.25256053 0.50000000 +v 0.50000000 2.5605287e-3 0.50000000 +v -0.50000000 2.5605287e-3 -0.50000000 +v -0.50000000 0.25256053 -0.50000000 +v 0.50000000 0.25256053 -0.50000000 +v 0.50000000 2.5605287e-3 -0.50000000 +vn -0.57735027 -0.57735027 0.57735027 +vn -0.57735027 0.57735027 0.57735027 +vn 0.57735027 0.57735027 0.57735027 +vn 0.57735027 -0.57735027 0.57735027 +vn -0.57735027 -0.57735027 -0.57735027 +vn -0.57735027 0.57735027 -0.57735027 +vn 0.57735027 0.57735027 -0.57735027 +vn 0.57735027 -0.57735027 -0.57735027 +g cube2_default +usemtl default +f 33//33 36//36 34//34 +f 33//33 37//37 36//36 +f 34//34 36//36 35//35 +f 34//34 37//37 33//33 +f 34//34 39//39 38//38 +f 35//35 39//39 34//34 +f 36//36 37//37 40//40 +f 36//36 39//39 35//35 +f 37//37 39//39 40//40 +f 38//38 37//37 34//34 +f 38//38 39//39 37//37 +f 40//40 39//39 36//36 diff --git a/lighthouse.wings b/lighthouse.wings new file mode 100644 index 0000000000000000000000000000000000000000..6c52b98d2ef710503efacb0126f2ef13096c70d4 GIT binary patch literal 1245 zcmV<31S0z*Ay-LGM^h~^E-(!W8Uz3U1j>U@000nec%02vON`q@7`78Tao))$*<>Ht zZukA(rQ%c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oaGi*)w>CER1iSvm=?X}h*-dEP@M?{%z3zeU~uzLw)gPI(Q>we~w*>(Do(;B4m~ HXuoW7eaB`; literal 0 HcmV?d00001 diff --git a/src/BuildingPanel.cpp b/src/BuildingPanel.cpp new file mode 100644 index 0000000..6bd6722 --- /dev/null +++ b/src/BuildingPanel.cpp @@ -0,0 +1,37 @@ +// +// 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 "BuildingPanel.hpp" + +using namespace gui; + +BuildingPanel::BuildingPanel() +{ + myPanel = makePanel("Select Building", makeFlowBox(FLOW_BOX_VERT)); + myPanel->setOrigin(50, 50); +} + +BuildingPanel::~BuildingPanel() +{ + +} + +void BuildingPanel::render() const +{ + myPanel->render(); +} + diff --git a/src/Editor.cpp b/src/Editor.cpp index 54c19d1..b9fa8e5 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -22,6 +22,7 @@ #include "Maths.hpp" #include "ILight.hpp" #include "gui/IContainer.hpp" +#include "BuildingPanel.hpp" #include @@ -87,6 +88,7 @@ private: // GUI variables IContainerPtr myToolbar; + BuildingPanel myBuildingPanel; }; Editor::Editor(IMapPtr aMap, const string& aFileName) @@ -97,7 +99,7 @@ Editor::Editor(IMapPtr aMap, const string& aFileName) mySun = makeSunLight(); // Build the GUI - myToolbar = makeFlowBox(FLOW_BOX_HORIZ, false); + myToolbar = makeToolbar(); IButtonPtr trackButton = makeButton("data/images/track_icon.png"); trackButton->onClick(bind(&Editor::onTrackSelect, this)); @@ -130,7 +132,7 @@ Editor::Editor(IMapPtr aMap, const string& aFileName) IButtonPtr buildingButton = makeButton("data/images/buildings_icon.png"); buildingButton->onClick(bind(&Editor::onBuildingSelect, this)); myToolbar->addChild(buildingButton); - + myMap->setGrid(true); log() << "Editing " << aFileName; @@ -178,6 +180,7 @@ void Editor::display(IGraphicsPtr aContext) const void Editor::overlay() const { myToolbar->render(); + myBuildingPanel.render(); } // Prepare the next frame diff --git a/src/Game.cpp b/src/Game.cpp index d6d02cc..bf1003c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -113,7 +113,7 @@ Game::Game(IMapPtr aMap) myBrakeLabel->setColour(1.0f, 0.0f, 0.0f); myStatsPanel->addChild(myBrakeLabel); - myStatsPanel->setOrigin(5, 5); + myStatsPanel->setOrigin(5, 10); } Game::~Game() diff --git a/src/gui/FlowBox.cpp b/src/gui/FlowBox.cpp index 6e64fd6..b82b72d 100644 --- a/src/gui/FlowBox.cpp +++ b/src/gui/FlowBox.cpp @@ -22,9 +22,7 @@ #include using namespace gui; -using namespace std; -using namespace std::tr1; -using namespace std::tr1::placeholders; +using namespace placeholders; // A container which grows either horizontally or vertically as controls // are added @@ -55,7 +53,7 @@ private: typedef vector ControlList; ControlList myControls; - static const int SPACING = 3; + static const int SPACING = 10; }; FlowBox::FlowBox(FlowBoxStyle aStyle, bool doesWantSpacing) @@ -169,3 +167,7 @@ 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/Font.cpp b/src/gui/Font.cpp index 3250594..01a1c6e 100644 --- a/src/gui/Font.cpp +++ b/src/gui/Font.cpp @@ -77,8 +77,8 @@ Font::Font(const string& aFile, int aHeight, bool shadow) } // True height includes extra padding - const float h = static_cast(aHeight) / VERTICAL_PADDING; - myHeight = static_cast(h); + //const float h = static_cast(aHeight) / VERTICAL_PADDING; + myHeight = aHeight; unsigned char i; diff --git a/src/gui/Panel.cpp b/src/gui/Panel.cpp new file mode 100644 index 0000000..df9ee3d --- /dev/null +++ b/src/gui/Panel.cpp @@ -0,0 +1,87 @@ +// +// 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 = loadFont("data/fonts/Vera.ttf", 13, false); + myFont->setColour(0.0f, 0.0f, 0.0f); + myTitleWidth = myFont->stringWidth(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->maxHeight() + 2*TITLE_PAD + myContent->height(); +} + +IContainerPtr gui::makePanel(const string& aTitle, IContainerPtr aContent) +{ + return IContainerPtr(new Hideable(aTitle, aContent)); +} -- 2.39.2