[Avida-SVN] r1784 - in development: . source/targets/viewer-fltk source/viewer-coreGUI
ofria at myxo.css.msu.edu
ofria at myxo.css.msu.edu
Tue Jul 10 14:58:35 PDT 2007
Author: ofria
Date: 2007-07-10 17:58:35 -0400 (Tue, 10 Jul 2007)
New Revision: 1784
Added:
development/source/targets/viewer-fltk/cFLTKBox.h
development/source/targets/viewer-fltk/cFLTKWindow.h
development/source/viewer-coreGUI/cGUIBox.h
development/source/viewer-coreGUI/cGUIDriver.cc
development/source/viewer-coreGUI/cGUIDriver.h
development/source/viewer-coreGUI/cGUIWindow.h
Modified:
development/CMakeLists.txt
development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc
development/source/targets/viewer-fltk/cDriver_FLTKViewer.h
development/source/viewer-coreGUI/cGUICanvas.h
development/source/viewer-coreGUI/cGUIContainer.h
development/source/viewer-coreGUI/cGUIWidget.h
Log:
Contined work on core GUI and FLTK interface. In FLTK, updates will now spin by as you watch.
Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt 2007-07-10 21:26:48 UTC (rev 1783)
+++ development/CMakeLists.txt 2007-07-10 21:58:35 UTC (rev 1784)
@@ -151,6 +151,16 @@
LIST(APPEND ALL_INC_DIRS ${COREVIEW_DIR})
+# The core GUI directory
+SET(COREGUI_DIR ${PROJECT_SOURCE_DIR}/source/viewer-coreGUI)
+SET(COREGUI_SOURCES
+ ${COREGUI_DIR}/cGUIDriver.cc
+)
+SOURCE_GROUP(coregui FILES ${COREGUI_SOURCES})
+LIST(APPEND AVIDA_CORE_SOURCES ${COREGUI_SOURCES})
+LIST(APPEND ALL_INC_DIRS ${COREGUI_DIR})
+
+
# The cpu directory
SET(CPU_DIR ${PROJECT_SOURCE_DIR}/source/cpu)
SET(CPU_SOURCES
Modified: development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc
===================================================================
--- development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc 2007-07-10 21:26:48 UTC (rev 1783)
+++ development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc 2007-07-10 21:58:35 UTC (rev 1784)
@@ -38,6 +38,8 @@
#include "cWorld.h"
#include "cDriverManager.h"
+#include "cFLTKWindow.h"
+#include "cFLTKBox.h"
#include <cstdlib>
@@ -48,10 +50,22 @@
using namespace std;
+cGUIWindow * cDriver_FLTKViewer::BuildWindow(int width, int height, const cString & name)
+{
+ return new cFLTKWindow(width, height, name);
+}
+
+cGUIBox * cDriver_FLTKViewer::BuildBox(cGUIContainer * container, int x, int y,
+ int width, int height, const cString & name)
+{
+ cGUIBox * box = new cFLTKBox(x, y, width, height, name);
+ container->Add(box);
+ return box;
+}
+
+
cDriver_FLTKViewer::cDriver_FLTKViewer(cWorld* world)
- : m_world(world)
- , m_info(m_world->GetPopulation(), 12)
- , m_done(false)
+ : cGUIDriver(world)
{
// Setup the initial view mode (loaded from avida.cfg)
m_info.SetViewMode(world->GetConfig().VIEW_MODE.Get());
@@ -59,28 +73,27 @@
cDriverManager::Register(static_cast<cAvidaDriver*>(this));
world->SetDriver(this);
- Fl_Window *window = new Fl_Window(300,180);
- Fl_Box *box = new Fl_Box(20,40,260,100,"Avida!");
+ LaunchViewer();
- box->box(FL_UP_BOX);
- box->labelsize(36);
- box->labelfont(FL_BOLD+FL_ITALIC);
- box->labeltype(FL_SHADOW_LABEL);
- window->end();
+// Fl_Box *box = new Fl_Box(20,40,260,100,"Avida!");
+// box->box(FL_UP_BOX);
+// box->labelsize(36);
+// box->labelfont(FL_BOLD+FL_ITALIC);
+// box->labeltype(FL_SHADOW_LABEL);
- int argc = 1;
- char * progname = "Avida";
- char ** argv = &progname;
+// int argc = 1;
+// char * progname = "Avida";
+// char ** argv = &progname;
- window->show(argc, argv);
- bool error = Fl::run();
- (void) error;
+// window->show(argc, argv);
+
+// bool error = Fl::run();
+// (void) error;
}
cDriver_FLTKViewer::~cDriver_FLTKViewer()
{
cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
- delete m_world;
ExitFLTKViewer(0);
}
@@ -315,6 +328,13 @@
void cDriver_FLTKViewer::DoUpdate()
{
+ bool error = Fl::check();
+ cString update_string;
+ update_string.Set("Update: %d", m_world->GetStats().GetUpdate());
+ m_update_box->SetName(update_string);
+ m_update_box->Refresh();
+
+
const int pause_level = m_info.GetPauseLevel();
// If we are stepping in some way, we've come to a stop, so revert to a normal pause.
Modified: development/source/targets/viewer-fltk/cDriver_FLTKViewer.h
===================================================================
--- development/source/targets/viewer-fltk/cDriver_FLTKViewer.h 2007-07-10 21:26:48 UTC (rev 1783)
+++ development/source/targets/viewer-fltk/cDriver_FLTKViewer.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -37,21 +37,25 @@
#include "cWorldDriver.h"
#endif
+#ifndef cGUIDriver_h
+#include "cGUIDriver.h"
+#endif
+
#include <sstream>
#include <iostream>
#include <fstream>
class cWorld;
+class cGUIContainer;
using namespace std;
-class cDriver_FLTKViewer : public cAvidaDriver, public cWorldDriver {
+class cDriver_FLTKViewer : public cAvidaDriver, public cWorldDriver, public cGUIDriver {
private:
- cWorld* m_world;
- cCoreView_Info m_info;
+ // Overloaded methods from cGUIDriver...
+ cGUIWindow * BuildWindow(int width, int height, const cString & name);
+ cGUIBox * BuildBox(cGUIContainer * container, int x, int y, int width, int height, const cString & name);
- bool m_done; // This is set to true when run should finish.
-
public:
cDriver_FLTKViewer(cWorld* world);
~cDriver_FLTKViewer();
Added: development/source/targets/viewer-fltk/cFLTKBox.h
===================================================================
--- development/source/targets/viewer-fltk/cFLTKBox.h (rev 0)
+++ development/source/targets/viewer-fltk/cFLTKBox.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -0,0 +1,65 @@
+/*
+ * cFLTKBox.h
+ * Avida
+ *
+ * Created by Charles on 7-9-07
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * 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; version 2
+ * of the License.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// This is a base class for the main GUI boxs...
+
+#ifndef cFLTKBox_h
+#define cFLTKBox_h
+
+#include "cGUIBox.h"
+
+#include <FL/Fl_Box.H>
+
+class cFLTKBox : public cGUIBox {
+protected:
+ Fl_Box * m_box;
+
+public:
+ cFLTKBox(int x, int y, int width, int height, const cString & name="")
+ : cGUIBox(x, y, width, height, name)
+ {
+ m_box = new Fl_Box(x, y, width, height, name);
+ }
+ ~cFLTKBox() { delete m_box; }
+
+ void SetType(int in_type) {
+ m_type = (eBoxType) in_type;
+ if (m_type == BOX_NONE) m_box->box(FL_NO_BOX);
+ else if (m_type == BOX_FLAT) m_box->box(FL_FLAT_BOX);
+ else if (m_type == BOX_RAISED) m_box->box(FL_UP_BOX);
+ else if (m_type == BOX_LOWERED) m_box->box(FL_DOWN_BOX);
+ else if (m_type == BOX_FRAME) m_box->box(FL_BORDER_FRAME);
+ else if (m_type == BOX_RAISED_FRAME) m_box->box(FL_UP_FRAME);
+ else if (m_type == BOX_LOWERED_FRAME) m_box->box(FL_DOWN_FRAME);
+ }
+
+
+ void Refresh() {
+ m_box->copy_label(m_name);
+ m_box->labelsize(m_font_size);
+ m_box->redraw();
+ }
+};
+
+#endif
Added: development/source/targets/viewer-fltk/cFLTKWindow.h
===================================================================
--- development/source/targets/viewer-fltk/cFLTKWindow.h (rev 0)
+++ development/source/targets/viewer-fltk/cFLTKWindow.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -0,0 +1,58 @@
+/*
+ * cFLTKWindow.h
+ * Avida
+ *
+ * Created by Charles on 7-9-07
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * 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; version 2
+ * of the License.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// This is a base class for the main GUI windows...
+
+#ifndef cFLTKWindow_h
+#define cFLTKWindow_h
+
+#include "cGUIWindow.h"
+
+#include <FL/Fl_Window.H>
+
+class cFLTKWindow : public cGUIWindow {
+protected:
+ Fl_Window * m_window;
+
+public:
+ cFLTKWindow() { ; }
+ cFLTKWindow(int width, int height, const cString & name="")
+ : cGUIWindow(width, height, name)
+ {
+ m_window = new Fl_Window(width, height);
+ }
+ ~cFLTKWindow() { delete m_window; }
+
+ void SetSizeRange(int min_x, int min_y, int max_x=0, int max_y=0) {
+ m_window->size_range(min_x, min_y, max_x, max_y);
+ }
+
+ void Finalize() {
+ m_window->end();
+ m_window->show();
+ }
+ void Update() { ; }
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUIBox.h
===================================================================
--- development/source/viewer-coreGUI/cGUIBox.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIBox.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -0,0 +1,49 @@
+/*
+ * cGUIBox.h
+ * Avida
+ *
+ * Created by Charles on 7-9-07
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * 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; version 2
+ * of the License.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// This is a base class for all GUI widgets that act as boxs.
+
+#ifndef cGUIBox_h
+#define cGUIBox_h
+
+#include "cGUIWidget.h"
+
+class cGUIBox : public cGUIWidget {
+public:
+ enum eBoxType { BOX_NONE, BOX_FLAT, BOX_RAISED, BOX_LOWERED, BOX_FRAME, BOX_RAISED_FRAME, BOX_LOWERED_FRAME };
+
+protected:
+ eBoxType m_type; // What type of box is this?
+
+public:
+ cGUIBox(int x, int y, int width, int height, const cString & name="")
+ : cGUIWidget(x, y, width, height, name)
+ , m_type(BOX_NONE) { ; }
+ virtual ~cGUIBox() { ; }
+
+ int GetType() const { return m_type; }
+ virtual void SetType(int in_type) { m_type = (eBoxType) in_type; }
+};
+
+#endif
Modified: development/source/viewer-coreGUI/cGUICanvas.h
===================================================================
--- development/source/viewer-coreGUI/cGUICanvas.h 2007-07-10 21:26:48 UTC (rev 1783)
+++ development/source/viewer-coreGUI/cGUICanvas.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -29,8 +29,6 @@
#include "cGUIWidget.h"
-class cGUIEvent;
-
class cGUICanvas : public cGUIWidget {
protected:
public:
@@ -38,8 +36,6 @@
cGUICanvas(int x, int y, width=0, height=0, name="") : cGUIWidget(x, y, width, height, name) { ; }
virtual ~cGUICanvas() { ; }
- virtual bool Handle(cGUIEvent & event) { (void) event; return false; }
-
virtual void DrawLine(int x1, int y1, int x2, int y2) = 0;
virtual void DrawBox(int x1, int y1, int _w, int _h, bool fill=false) = 0;
virtual void DrawCircle(int _x, int _y, int _, bool fill=false) = 0;
Modified: development/source/viewer-coreGUI/cGUIContainer.h
===================================================================
--- development/source/viewer-coreGUI/cGUIContainer.h 2007-07-10 21:26:48 UTC (rev 1783)
+++ development/source/viewer-coreGUI/cGUIContainer.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -40,19 +40,20 @@
public:
cGUIContainer() { ; }
- cGUIContainer(int x, int y, width=0, height=0, name="") : cGUIWidget(x, y, width, height, name) { ; }
+ cGUIContainer(int x, int y, int width=0, int height=0, const cString & name="")
+ : cGUIWidget(x, y, width, height, name) { ; }
virtual ~cGUIContainer() { ; }
// This method should be run when the widget is setup and its time to build it and everything it contains.
virtual void Create() {
CreateSelf();
for (int i = 0; i < widget_array.GetSize(); i++) {
- widget_array[i].Create();
+ widget_array[i]->Create();
}
}
void Add(cGUIWidget * in_widget) { widget_array.Push(in_widget); }
- void Add(cGUIWidget * in_widget, int x, int y, int width, int height, int name="") {
+ void Add(cGUIWidget * in_widget, int x, int y, int width, int height, const cString & name="") {
in_widget->m_x = x;
in_widget->m_y = y;
in_widget->m_width = width;
Added: development/source/viewer-coreGUI/cGUIDriver.cc
===================================================================
--- development/source/viewer-coreGUI/cGUIDriver.cc (rev 0)
+++ development/source/viewer-coreGUI/cGUIDriver.cc 2007-07-10 21:58:35 UTC (rev 1784)
@@ -0,0 +1,68 @@
+/*
+ * cGUIDriver.cc
+ * Avida
+ *
+ * Created by Charles on 7-9-07
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * 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; version 2
+ * of the License.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "cGUIDriver.h"
+
+#include "cWorld.h"
+
+#include "cGUIBox.h"
+#include "cGUIWindow.h"
+
+cGUIDriver::cGUIDriver(cWorld* world)
+ : m_world(world)
+ , m_info(world->GetPopulation(), 12)
+ , m_done(false)
+ , m_main_window(NULL)
+ , m_update_box(NULL)
+{
+}
+
+
+cGUIDriver::~cGUIDriver()
+{
+ if (m_main_window != NULL) delete m_main_window;
+
+ delete m_world;
+}
+
+
+bool cGUIDriver::LaunchViewer()
+{
+ m_main_window = BuildWindow(800, 600, "Avida Viewer");
+ m_main_window->SetSizeRange(800, 600);
+
+ m_update_box = BuildBox(m_main_window, 10, 10, 200, 50, "Update: 0");
+ m_update_box->SetType(cGUIBox::BOX_FLAT);
+ m_update_box->SetFontSize(30);
+ m_update_box->Refresh();
+
+ m_main_window->Finalize();
+
+ return true;
+}
+
+
+bool cGUIDriver::UpdateViewer()
+{
+}
Added: development/source/viewer-coreGUI/cGUIDriver.h
===================================================================
--- development/source/viewer-coreGUI/cGUIDriver.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIDriver.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -0,0 +1,63 @@
+/*
+ * cGUIDriver.h
+ * Avida
+ *
+ * Created by Charles on 7-9-07
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * 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; version 2
+ * of the License.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// This class manages the graphics viewer in a GUI package-agnostic manner. It should be used as a base class
+// for the graphics-based drivers.
+
+#ifndef cGUIDriver_h
+#define cGUIDriver_h
+
+#include "cString.h"
+
+#include "cCoreView_Info.h"
+
+class cWorld;
+
+class cGUIBox;
+class cGUIContainer;
+class cGUIWindow;
+
+class cGUIDriver {
+protected:
+ cWorld* m_world;
+ cCoreView_Info m_info;
+
+ bool m_done; // This is set to true when run should finish.
+
+ // Graphics components...
+ cGUIWindow * m_main_window;
+ cGUIBox * m_update_box;
+
+ virtual cGUIWindow * BuildWindow(int width, int height, const cString & name) = 0;
+ virtual cGUIBox * BuildBox(cGUIContainer * container, int x, int y,
+ int width, int height, const cString & name="") = 0;
+public:
+ cGUIDriver(cWorld* world);
+ virtual ~cGUIDriver();
+
+ bool LaunchViewer();
+ bool UpdateViewer();
+};
+
+#endif
Modified: development/source/viewer-coreGUI/cGUIWidget.h
===================================================================
--- development/source/viewer-coreGUI/cGUIWidget.h 2007-07-10 21:26:48 UTC (rev 1783)
+++ development/source/viewer-coreGUI/cGUIWidget.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -29,7 +29,11 @@
#include "cString.h"
+class cGUIContainer;
+class cGUIEvent;
+
class cGUIWidget {
+ friend class cGUIContainer;
protected:
cString m_name;
int m_x;
@@ -37,14 +41,29 @@
int m_width;
int m_height;
+ int m_font_size;
public:
- cGUIWidget() : m_x(0), m_y(0), m_width(0), m_height(0) { ; }
- cGUIWidget(int x, int y, width=0, height=0, name="")
- : m_name(name), m_x(x), m_y(y), m_width(width), m_height(height) { ; }
+ cGUIWidget() : m_x(0), m_y(0), m_width(0), m_height(0), m_font_size(20) { ; }
+ cGUIWidget(int x, int y, int width=0, int height=0, const cString & name="")
+ : m_name(name), m_x(x), m_y(y), m_width(width), m_height(height), m_font_size(20) { ; }
virtual ~cGUIWidget() { ; }
// This method should be run when the widget is setup and its time to build it.
- virtual void Create() = 0;
+ virtual void Create() { ; }
+
+ // This method should deal with GUI events.
+ virtual bool Handle(cGUIEvent & event) { (void) event; return false; }
+
+ const cString & GetName() { return m_name; }
+ int GetX() const { return m_x; }
+ int GetY() const { return m_y; }
+ int GetWidth() const { return m_width; }
+ int GetHeight() const { return m_height; }
+
+ void SetName(const cString & _name) { m_name = _name; }
+ void SetFontSize(int _size) { m_font_size = _size; }
+
+ virtual void Refresh() { ; }
};
#endif
Added: development/source/viewer-coreGUI/cGUIWindow.h
===================================================================
--- development/source/viewer-coreGUI/cGUIWindow.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIWindow.h 2007-07-10 21:58:35 UTC (rev 1784)
@@ -0,0 +1,47 @@
+/*
+ * cGUIWindow.h
+ * Avida
+ *
+ * Created by Charles on 7-9-07
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ *
+ *
+ * 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; version 2
+ * of the License.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// This is a base class for the main GUI windows...
+
+#ifndef cGUIWindow_h
+#define cGUIWindow_h
+
+#include "cGUIContainer.h"
+
+class cGUIEvent;
+
+class cGUIWindow : public cGUIContainer {
+protected:
+public:
+ cGUIWindow() { ; }
+ cGUIWindow(int width, int height, const cString & name="") : cGUIContainer(0, 0, width, height, name) { ; }
+ virtual ~cGUIWindow() { ; }
+
+ virtual void SetSizeRange(int min_x, int min_y, int max_x=0, int max_y=0) = 0;
+
+ virtual void Finalize() = 0;
+ virtual void Update() = 0;
+};
+
+#endif
More information about the Avida-cvs
mailing list