summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-04-18 19:35:48 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-04-18 19:35:48 +0200
commit55e76bdaafa1e2a94fbd717335c1c7bd8c8fc156 (patch)
treecb9e0b4a9dd9f069098fead2f1b0fd0dd7311a62
parent0986cf8f33df8926dd8da67f98ed18f696141313 (diff)
Basic tool implementation.
-rw-r--r--GUI/layouts/raisewnd.layout55
-rw-r--r--gui.cpp149
-rw-r--r--gui.h27
-rw-r--r--scene.cpp36
-rw-r--r--scene.h2
-rw-r--r--tool.cpp43
-rw-r--r--tool.h36
7 files changed, 233 insertions, 115 deletions
diff --git a/GUI/layouts/raisewnd.layout b/GUI/layouts/raisewnd.layout
new file mode 100644
index 0000000..a2f9561
--- /dev/null
+++ b/GUI/layouts/raisewnd.layout
@@ -0,0 +1,55 @@
+<?xml version="1.0" ?>
+<GUILayout>
+ <Window Type="Vanilla/FrameWindow" Name="RaiseWindow">
+ <Property Name="UnifiedPosition" Value="{{.25, 0}, {.40, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.5, 0}, {.2, 0}}" />
+ <Property Name="Text" Value="foobar" />
+
+ <Window Type="Vanilla/StaticText" Name="radius_lbl">
+ <Property Name="UnifiedPosition" Value="{{0, 0}, {0, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.2, 0}, {.3, 0}}" />
+ <Property Name="Text" Value="Radius" />
+ </Window>
+ <Window Type="Vanilla/HorizontalScrollbar" Name="radius_sb">
+ <Property Name="UnifiedPosition" Value="{{.2, 0}, {0, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.65, 0}, {.3, 0}}" />
+ <Property Name="DocumentSize" Value="50.0" />
+ </Window>
+ <Window Type="Vanilla/StaticText" Name="radius_sb_lbl">
+ <Property Name="UnifiedPosition" Value="{{.85, 0}, {0, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.15, 0}, {.3, 0}}" />
+ </Window>
+
+ <Window Type="Vanilla/StaticText" Name="focus_lbl">
+ <Property Name="UnifiedPosition" Value="{{0, 0}, {.3, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.2, 0}, {.3, 0}}" />
+ <Property Name="Text" Value="Focus" />
+ </Window>
+ <Window Type="Vanilla/HorizontalScrollbar" Name="focus_sb">
+ <Property Name="UnifiedPosition" Value="{{.2, 0}, {.3, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.65, 0}, {.3, 0}}" />
+ <Property Name="DocumentSize" Value="2.0" />
+ <Property Name="StepSize" Value=".1" />
+ </Window>
+ <Window Type="Vanilla/StaticText" Name="focus_sb_lbl">
+ <Property Name="UnifiedPosition" Value="{{.85, 0}, {.3, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.15, 0}, {.3, 0}}" />
+ </Window>
+
+ <Window Type="Vanilla/StaticText" Name="strength_lbl">
+ <Property Name="UnifiedPosition" Value="{{0, 0}, {.6, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.2, 0}, {.3, 0}}" />
+ <Property Name="Text" Value="Strength" />
+ </Window>
+ <Window Type="Vanilla/HorizontalScrollbar" Name="strength_sb">
+ <Property Name="UnifiedPosition" Value="{{.2, 0}, {.6, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.65, 0}, {.3, 0}}" />
+ <Property Name="DocumentSize" Value="1.0" />
+ <Property Name="StepSize" Value=".1" />
+ </Window>
+ <Window Type="Vanilla/StaticText" Name="strength_sb_lbl">
+ <Property Name="UnifiedPosition" Value="{{.85, 0}, {.6, 0}}" />
+ <Property Name="UnifiedSize" Value="{{.15, 0}, {.3, 0}}" />
+ </Window>
+ </Window>
+</GUILayout>
diff --git a/gui.cpp b/gui.cpp
index 8824237..72275c8 100644
--- a/gui.cpp
+++ b/gui.cpp
@@ -2,18 +2,21 @@
#include "video.h"
#include <boost/format.hpp>
+#include <RendererModules/OpenGL/CEGUIOpenGLRenderer.h>
using namespace CEGUI;
-GUI::GUI() {
+CEGUI::Window *GUI::root = NULL;
+void GUI::init() {
OpenGLRenderer::bootstrapSystem();
+
DefaultResourceProvider* rp = static_cast<DefaultResourceProvider*>
(System::getSingleton().getResourceProvider());
rp->setResourceGroupDirectory("schemes", "GUI/");
rp->setResourceGroupDirectory("imagesets", "GUI/");
rp->setResourceGroupDirectory("fonts", "fonts/");
- rp->setResourceGroupDirectory("layouts", "GUI/");
+ rp->setResourceGroupDirectory("layouts", "GUI/layouts/");
rp->setResourceGroupDirectory("looknfeels", "GUI/");
Imageset::setDefaultResourceGroup("imagesets");
@@ -33,112 +36,68 @@ GUI::GUI() {
root = wmgr.createWindow("DefaultWindow", "root");
System::getSingleton().setGUISheet(root);
+}
- wnd = static_cast<FrameWindow*>(wmgr.createWindow("Vanilla/FrameWindow", "foo"));
- root->addChildWindow(wnd);
-
- wnd->setPosition(UVector2(UDim(.25, 0), UDim(.25, 0)));
- wnd->setSize(UVector2(UDim(.5, 0), UDim(.5, 0)));
- wnd->setText("foobar");
-
- btn = static_cast<PushButton*>(wmgr.createWindow("Vanilla/Button", "button"));
- wnd->addChildWindow(btn);
-
- btn->setPosition(UVector2(UDim(0, 0), UDim(.9, 0)));
- btn->setSize(UVector2(UDim(.3, 0), UDim(.1, 0)));
- btn->setText("buttan");
-
- /* radius */
- radius_lbl = wmgr.createWindow("Vanilla/StaticText", "radius_lbl");
- wnd->addChildWindow(radius_lbl);
-
- radius_lbl->setPosition(UVector2(UDim(0, 0), UDim(0, 0)));
- radius_lbl->setSize(UVector2(UDim(.2, 0), UDim(.1, 0)));
- radius_lbl->setText("Radius");
-
- radius_sb = static_cast<Scrollbar*>(wmgr.createWindow("Vanilla/HorizontalScrollbar", "radius_sb"));
- wnd->addChildWindow(radius_sb);
-
- radius_sb->setPosition(UVector2(UDim(.2, 0), UDim(0, 0)));
- radius_sb->setSize(UVector2(UDim(.65, 0), UDim(.1, 0)));
- radius_sb->setDocumentSize(50.0);
-
- radius_sb_lbl = wmgr.createWindow("Vanilla/StaticText", "radius_sb_lbl");
- wnd->addChildWindow(radius_sb_lbl);
-
- radius_sb_lbl->setPosition(UVector2(UDim(.85, 0), UDim(0, 0)));
- radius_sb_lbl->setSize(UVector2(UDim(.15, 0), UDim(.1, 0)));
-
- /* focus */
- focus_lbl = wmgr.createWindow("Vanilla/StaticText", "focus_lbl");
- wnd->addChildWindow(focus_lbl);
-
- focus_lbl->setPosition(UVector2(UDim(0, 0), UDim(.1, 0)));
- focus_lbl->setSize(UVector2(UDim(.2, 0), UDim(.1, 0)));
- focus_lbl->setText("Focus");
-
- focus_sb = static_cast<Scrollbar*>(wmgr.createWindow("Vanilla/HorizontalScrollbar", "focus_sb"));
- wnd->addChildWindow(focus_sb);
-
- focus_sb->setPosition(UVector2(UDim(.2, 0), UDim(.1, 0)));
- focus_sb->setSize(UVector2(UDim(.65, 0), UDim(.1, 0)));
- focus_sb->setDocumentSize(2.0);
- focus_sb->setStepSize(.1);
-
- focus_sb_lbl = wmgr.createWindow("Vanilla/StaticText", "focus_sb_lbl");
- wnd->addChildWindow(focus_sb_lbl);
-
- focus_sb_lbl->setPosition(UVector2(UDim(.85, 0), UDim(.1, 0)));
- focus_sb_lbl->setSize(UVector2(UDim(.15, 0), UDim(.1, 0)));
-
- /* strength */
- strength_lbl = wmgr.createWindow("Vanilla/StaticText", "strength_lbl");
- wnd->addChildWindow(strength_lbl);
+void GUI::render() {
+ /* Disable depth testing to avoid cursor bugginess. */
+ glDisable(GL_DEPTH_TEST);
+ System::getSingleton().renderGUI();
+ glEnable(GL_DEPTH_TEST);
+}
- strength_lbl->setPosition(UVector2(UDim(0, 0), UDim(.2, 0)));
- strength_lbl->setSize(UVector2(UDim(.2, 0), UDim(.1, 0)));
- strength_lbl->setText("Strength");
+/* RaiseWindow */
- strength_sb = static_cast<Scrollbar*>(wmgr.createWindow("Vanilla/HorizontalScrollbar", "strength_sb"));
- wnd->addChildWindow(strength_sb);
+/* default values */
+float RaiseWindow::radius = 5;
+float RaiseWindow::focus = .8;
+float RaiseWindow::strength = .3;
- strength_sb->setPosition(UVector2(UDim(.2, 0), UDim(.2, 0)));
- strength_sb->setSize(UVector2(UDim(.65, 0), UDim(.1, 0)));
- strength_sb->setDocumentSize(1.0);
- strength_sb->setStepSize(.1);
+RaiseWindow::RaiseWindow() {
+ WindowManager& wmgr(WindowManager::getSingleton());
- strength_sb_lbl = wmgr.createWindow("Vanilla/StaticText", "strength_sb_lbl");
- wnd->addChildWindow(strength_sb_lbl);
+ wnd = static_cast<FrameWindow*>(wmgr.loadWindowLayout("raisewnd.layout"));
+ root->addChildWindow(wnd);
- strength_sb_lbl->setPosition(UVector2(UDim(.85, 0), UDim(.2, 0)));
- strength_sb_lbl->setSize(UVector2(UDim(.15, 0), UDim(.1, 0)));
+ radius_sb = static_cast<Scrollbar*>(wmgr.getWindow("radius_sb"));
+ radius_sb_lbl = wmgr.getWindow("radius_sb_lbl");
+ focus_sb = static_cast<Scrollbar*>(wmgr.getWindow("focus_sb"));
+ focus_sb_lbl = wmgr.getWindow("focus_sb_lbl");
+ strength_sb = static_cast<Scrollbar*>(wmgr.getWindow("strength_sb"));
+ strength_sb_lbl = wmgr.getWindow("strength_sb_lbl");
+
+ /* load default/last used values */
+ radius_sb->setScrollPosition(radius);
+ focus_sb->setScrollPosition(focus);
+ strength_sb->setScrollPosition(strength);
}
-GUI::~GUI() {
- delete root;
- delete wnd;
- delete btn;
-
- delete radius_lbl;
- delete radius_sb;
- delete radius_sb_lbl;
-
- delete focus_lbl;
- delete focus_sb;
- delete focus_sb_lbl;
+RaiseWindow::~RaiseWindow() {
+ /* store current values */
+ radius = get_radius();
+ focus = get_focus();
+ strength = get_strength();
- delete strength_lbl;
- delete strength_sb;
- delete strength_sb_lbl;
+ WindowManager& wmgr(WindowManager::getSingleton());
+ wmgr.destroyWindow(wnd);
+ wmgr.cleanDeadPool();
}
-void GUI::render() {
+void RaiseWindow::render() {
radius_sb_lbl->setText((boost::format("%.2f") % radius_sb->getScrollPosition()).str().c_str());
focus_sb_lbl->setText((boost::format("%.2f") % focus_sb->getScrollPosition()).str().c_str());
strength_sb_lbl->setText((boost::format("%.2f") % strength_sb->getScrollPosition()).str().c_str());
- /* Disable depth testing to avoid cursor bugginess. */
- glDisable(GL_DEPTH_TEST);
- System::getSingleton().renderGUI();
- glEnable(GL_DEPTH_TEST);
+ GUI::render();
+}
+
+float RaiseWindow::get_radius() {
+ return radius_sb->getScrollPosition();
+}
+
+float RaiseWindow::get_focus() {
+ return focus_sb->getScrollPosition();
+}
+
+float RaiseWindow::get_strength() {
+ return strength_sb->getScrollPosition();
}
diff --git a/gui.h b/gui.h
index 22ad354..30bf6dd 100644
--- a/gui.h
+++ b/gui.h
@@ -2,30 +2,41 @@
#define GUI_H
#include <CEGUI.h>
-#include <RendererModules/OpenGL/CEGUIOpenGLRenderer.h>
class GUI {
public:
- CEGUI::Window *root;
+ static CEGUI::Window *root;
+
+ virtual ~GUI() {};
+
+ static void init();
+ virtual void render();
+};
+
+class RaiseWindow : public GUI {
+ private:
CEGUI::FrameWindow *wnd;
CEGUI::PushButton *btn;
- CEGUI::Window *radius_lbl;
CEGUI::Scrollbar *radius_sb;
CEGUI::Window *radius_sb_lbl;
- CEGUI::Window *focus_lbl;
CEGUI::Scrollbar *focus_sb;
CEGUI::Window *focus_sb_lbl;
- CEGUI::Window *strength_lbl;
CEGUI::Scrollbar *strength_sb;
CEGUI::Window *strength_sb_lbl;
- GUI();
- ~GUI();
+ static float radius, focus, strength;
+
+ public:
+ RaiseWindow();
+ virtual ~RaiseWindow();
- void render();
+ virtual void render();
+ float get_radius();
+ float get_focus();
+ float get_strength();
};
#endif
diff --git a/scene.cpp b/scene.cpp
index f994627..6cb6cc7 100644
--- a/scene.cpp
+++ b/scene.cpp
@@ -22,6 +22,7 @@ Scene::Scene() {
do_select = false;
show_selection = false;
dialog = false;
+ tool = NULL;
/* setup shader programs */
GLVertexShader terrain_vertex("shaders/terrain_vertex.glsl");
@@ -63,14 +64,15 @@ Scene::Scene() {
font = new FTTextureFont("fonts/VeraMono.ttf");
font->FaceSize(10);
- gui = new GUI();
+ GUI::init();
}
Scene::~Scene() {
+ if(tool)
+ delete tool;
if(qt)
delete qt;
delete font;
- delete gui;
}
void Scene::lookat() {
@@ -144,6 +146,9 @@ void Scene::update() {
void Scene::events() {
SDL_Event event;
while(SDL_PollEvent(&event)) {
+ if(tool && !dialog && tool->handle_event(event, selected))
+ continue;
+
switch(event.type) {
case SDL_QUIT:
running = false;
@@ -151,7 +156,11 @@ void Scene::events() {
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
- running = false;
+ if(tool) {
+ delete tool;
+ tool = NULL;
+ } else
+ running = false;
break;
case SDLK_g:
grid = !grid;
@@ -169,7 +178,12 @@ void Scene::events() {
update();
break;
case SDLK_TAB:
- dialog = !dialog;
+ dialog = !dialog && tool;
+ break;
+ case SDLK_1:
+ if(tool) delete tool;
+ tool = new RaiseTool(qt);
+ break;
default:
break;
}
@@ -206,16 +220,10 @@ void Scene::events() {
case SDL_BUTTON_WHEELUP:
if(dialog)
CEGUI::System::getSingleton().injectMouseWheelChange(1);
- else
- qt->raise(selected.x, selected.z, gui->radius_sb->getScrollPosition(), gui->focus_sb->getScrollPosition(),
- gui->strength_sb->getScrollPosition());
break;
case SDL_BUTTON_WHEELDOWN:
if(dialog)
CEGUI::System::getSingleton().injectMouseWheelChange(-1);
- else
- qt->raise(selected.x, selected.z, gui->radius_sb->getScrollPosition(), gui->focus_sb->getScrollPosition(),
- -gui->strength_sb->getScrollPosition());
break;
}
break;
@@ -413,14 +421,18 @@ void Scene::render() {
font->Render(move_str.c_str());
glTranslatef(0, -height, 0);
font->Render(selected.str().c_str());
+ if(tool) {
+ glTranslatef(0, -height, 0);
+ font->Render((boost::format("Tool: %s") % tool->get_name()).str().c_str());
+ }
/*if(selected) {
glTranslatef(0, height, 0);
//font->Render((boost::format("(%s %s %s %s)") % selected->a->str() % selected->b->str() % selected->c->str() % selected->d->str()).str().c_str());
font->Render(selected->str().c_str());
}*/
- if(dialog)
- gui->render();
+ if(dialog && tool)
+ tool->render_gui();
SDL_GL_SwapBuffers();
}
diff --git a/scene.h b/scene.h
index 95ae158..59f0c79 100644
--- a/scene.h
+++ b/scene.h
@@ -6,6 +6,7 @@
#include "gl.h"
#include "shader.h"
#include "gui.h"
+#include "tool.h"
#include <FTGL/ftgl.h>
@@ -17,6 +18,7 @@ class Scene {
Quadtree *qt;
FTFont *font;
GUI *gui;
+ Tool *tool;
bool running;
bool grid;
diff --git a/tool.cpp b/tool.cpp
new file mode 100644
index 0000000..83353b4
--- /dev/null
+++ b/tool.cpp
@@ -0,0 +1,43 @@
+#include "tool.h"
+
+/* Tool */
+Tool::Tool(Quadtree *tree) {
+ this->tree = tree;
+}
+
+void Tool::render_gui() {
+ gui->render();
+}
+
+/* RaiseTool */
+RaiseTool::RaiseTool(Quadtree *tree) : Tool(tree) {
+ gui = new RaiseWindow();
+}
+
+RaiseTool::~RaiseTool() {
+ delete gui;
+}
+
+bool RaiseTool::handle_event(SDL_Event& event, Vector3& selected) {
+ RaiseWindow *wnd = static_cast<RaiseWindow*>(gui);
+
+ switch(event.type) {
+ case SDL_MOUSEBUTTONUP:
+ switch(event.button.button) {
+ case SDL_BUTTON_WHEELUP:
+ tree->raise(selected.x, selected.z, wnd->get_radius(), wnd->get_focus(),
+ wnd->get_strength());
+ return true;
+ case SDL_BUTTON_WHEELDOWN:
+ tree->raise(selected.x, selected.z, wnd->get_radius(), wnd->get_focus(),
+ -wnd->get_strength());
+ return true;
+ }
+ }
+
+ return false;
+}
+
+const char* RaiseTool::get_name() {
+ return "RaiseTool";
+}
diff --git a/tool.h b/tool.h
new file mode 100644
index 0000000..13a833a
--- /dev/null
+++ b/tool.h
@@ -0,0 +1,36 @@
+#ifndef TOOL_H
+#define TOOL_H
+
+#include "quadtree.h"
+#include "vector.h"
+#include "gui.h"
+
+#include <SDL.h>
+
+class Tool {
+ protected:
+ Quadtree *tree;
+ GUI *gui;
+
+ public:
+ Tool(Quadtree *tree);
+ virtual ~Tool() {};
+
+ virtual bool handle_event(SDL_Event& event, Vector3& selected) = 0;
+ virtual void render_gui();
+ virtual const char* get_name() = 0;
+};
+
+class RaiseTool : public Tool {
+ protected:
+ static std::string name;
+
+ public:
+ RaiseTool(Quadtree *tree);
+ virtual ~RaiseTool();
+
+ virtual bool handle_event(SDL_Event& event, Vector3& selected);
+ virtual const char* get_name();
+};
+
+#endif