From 476653d47c99a6a01199ee5a49bcd446f1340d4a Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 8 Jul 2009 12:41:59 +0100 Subject: [PATCH] Make the editor run in the same window as the toolbox --- include/GameScreens.hpp | 3 ++ include/IWindow.hpp | 3 +- src/Editor.cpp | 28 +++++++--------- src/FLTKWindow.cpp | 71 +++++++++++++++++++++++++++-------------- src/Main.cpp | 2 +- 5 files changed, 64 insertions(+), 43 deletions(-) diff --git a/include/GameScreens.hpp b/include/GameScreens.hpp index 7f242d0..16eab80 100644 --- a/include/GameScreens.hpp +++ b/include/GameScreens.hpp @@ -30,4 +30,7 @@ IScreenPtr makeGameScreen(IMapPtr aMap); // Access to the window the game is running in IWindowPtr getGameWindow(); +// Add editor GUI controls +void addEditorGUI(); + #endif diff --git a/include/IWindow.hpp b/include/IWindow.hpp index f91b735..47bffea 100644 --- a/include/IWindow.hpp +++ b/include/IWindow.hpp @@ -42,6 +42,7 @@ typedef shared_ptr IWindowPtr; // Implementors IWindowPtr makeSDLWindow(); -IWindowPtr makeFLTKWindow(); +IWindowPtr makeFLTKWindow(const string& aTitle, + function addControls); #endif diff --git a/src/Editor.cpp b/src/Editor.cpp index 18c99d5..23b6b84 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -98,23 +98,9 @@ namespace { { 0 } }; - Fl_Window* theToolbox; Fl_Menu_Button* theToolMenu; - Editor* theEditor; - - void makeToolbox(Editor* anEditor) - { - theEditor = anEditor; - - theToolbox = new Fl_Window(100, 300); - - theToolMenu = new Fl_Menu_Button(0, 0, 100, 32); - theToolMenu->copy(theTools); - - theToolbox->end(); - theToolbox->show(); - } + Editor* theEditor = NULL; void changeTool(Fl_Widget* aWidget, Editor::Tool aTool) { @@ -123,6 +109,15 @@ namespace { } } +// Add the editor panel to the FLTK window +void addEditorGUI() +{ + const int panelW = 180; + + theToolMenu = new Fl_Menu_Button(0, 0, panelW, 32); + theToolMenu->copy(theTools); +} + Editor::Editor(IMapPtr aMap, const string& aFileName) : myMap(aMap), myPosition(4.5, -17.5, -21.5), myTool(TRACK_TOOL), myFileName(aFileName), @@ -130,8 +125,7 @@ Editor::Editor(IMapPtr aMap, const string& aFileName) { mySun = makeSunLight(); - // Build the GUI - makeToolbox(this); + theEditor = this; myMap->setGrid(true); diff --git a/src/FLTKWindow.cpp b/src/FLTKWindow.cpp index 53f786f..2818ad9 100644 --- a/src/FLTKWindow.cpp +++ b/src/FLTKWindow.cpp @@ -23,15 +23,16 @@ #include #include #include +#include #include #include -// An OpenGL window that supports FLTK widgets for the editor +// An OpenGL window for the editor class FLTKWindow : public IWindow, public IGraphics, public Fl_Gl_Window, public IPickBuffer, public enable_shared_from_this { public: - FLTKWindow(); + FLTKWindow(int x, int y, int w, int h); ~FLTKWindow(); // IWindow interface @@ -71,28 +72,10 @@ private: GLuint mySelectBuffer[SELECT_BUFFER_SZ]; }; -FLTKWindow::FLTKWindow() - : Fl_Gl_Window(640, 480) +FLTKWindow::FLTKWindow(int x, int y, int w, int h) + : Fl_Gl_Window(x, y, w, h) { - size_range(300, 240); - resizable(this); - //myWindow = new Fl_Window(300, 180); - /* myBox = new Fl_Box(20, 40, 260, 100, "Hello, World!"); - - myBox->box(FL_UP_BOX); - myBox->labelsize(36); - myBox->labelfont(FL_BOLD + FL_ITALIC); - myBox->labeltype(FL_SHADOW_LABEL); - */ - //myWindow->end(); - - // Bit of a hack to get into a state where we can use OpenGL - show(); - Fl::wait(); - - make_current(); - printGLVersion(); } FLTKWindow::~FLTKWindow() @@ -270,7 +253,47 @@ bool FLTKWindow::pointInViewFrustum(float x, float y, float z) return myViewFrustum.pointInFrustum(x, y, z); } -IWindowPtr makeFLTKWindow() +// The main application window that contains the actual +// FLTKWindow and is hidden from the rest of the application +class FLTKAppWindow : public Fl_Window { +public: + FLTKAppWindow(const string& aTitle, function addControls); + + FLTKWindow* glWindow() const { return myGLWindow; } +private: + FLTKWindow* myGLWindow; + Fl_Window* myContainer; +}; + +FLTKAppWindow::FLTKAppWindow(const string& aTitle, + function addControls) + : Fl_Window(980, 600, aTitle.c_str()) { - return IWindowPtr(new FLTKWindow); + size_range(300, 240); + resizable(this); + + const int panelW = 180; + myGLWindow = new FLTKWindow(0, 0, w()-panelW, h()); + myContainer = new Fl_Window(w()-panelW, 0, panelW, h()); + end(); + + myContainer->begin(); + addControls(); + myContainer->end(); + + // Bit of a hack to get into a state where we can use OpenGL + show(); + Fl::wait(); + + myGLWindow->make_current(); + + printGLVersion(); +} + +IWindowPtr makeFLTKWindow(const string& aTitle, + function addControls) +{ + FLTKAppWindow* appWindow = new FLTKAppWindow(aTitle, addControls); + + return IWindowPtr(appWindow->glWindow()); } diff --git a/src/Main.cpp b/src/Main.cpp index 00357f6..2c3a06b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv) #endif // #ifndef WIN32 IScreenPtr screen; if (cmd == "edit") { - theWindow = makeFLTKWindow(); + theWindow = makeFLTKWindow("Train Game Editor", addEditorGUI); if (exists(mapFile)) screen = makeEditorScreen(loadMap(mapFile), mapFile); else -- 2.39.2