[Avida-SVN] r1806 - in development: . source/targets/viewer-fltk source/viewer-coreGUI

ofria at myxo.css.msu.edu ofria at myxo.css.msu.edu
Sat Jul 14 12:33:11 PDT 2007


Author: ofria
Date: 2007-07-14 15:33:11 -0400 (Sat, 14 Jul 2007)
New Revision: 1806

Added:
   development/source/targets/viewer-fltk/fltk-defs.cc
   development/source/targets/viewer-fltk/fltk-defs.h
   development/source/targets/viewer-fltk/tFLTKButton.h
   development/source/viewer-coreGUI/cGUIWidget.cc
Removed:
   development/source/viewer-coreGUI/cGUIDriver.cc
   development/source/viewer-coreGUI/cGUIDriver.h
Modified:
   development/CMakeLists.txt
   development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc
   development/source/targets/viewer-fltk/cDriver_FLTKViewer.h
   development/source/targets/viewer-fltk/cFLTKBox.h
   development/source/targets/viewer-fltk/cFLTKWindow.h
   development/source/viewer-coreGUI/cGUIBox.h
   development/source/viewer-coreGUI/cGUIButton.h
   development/source/viewer-coreGUI/cGUIContainer.h
   development/source/viewer-coreGUI/cGUIWidget.h
   development/source/viewer-coreGUI/tGUIButton.h
Log:
Setup the tFLTKButton framework so that buttons are easy to add in the graphical interface.
Added a working (if ugly) "Quit" button.


Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/CMakeLists.txt	2007-07-14 19:33:11 UTC (rev 1806)
@@ -154,7 +154,7 @@
 # The core GUI  directory
 SET(COREGUI_DIR ${PROJECT_SOURCE_DIR}/source/viewer-coreGUI)
 SET(COREGUI_SOURCES
-  ${COREGUI_DIR}/cGUIDriver.cc
+  ${COREGUI_DIR}/cGUIWidget.cc
 )
 SOURCE_GROUP(coregui FILES ${COREGUI_SOURCES})
 LIST(APPEND AVIDA_CORE_SOURCES ${COREGUI_SOURCES})
@@ -488,8 +488,9 @@
     
     SET(AVIDA_FLTK_VIEWER_DIR source/targets/viewer-fltk)
     SET(AVIDA_FLTK_VIEWER_SOURCES
-      ${AVIDA_FLTK_VIEWER_DIR}/cDriver_FltkViewer.cc
+      ${AVIDA_FLTK_VIEWER_DIR}/cDriver_FLTKViewer.cc
       ${AVIDA_FLTK_VIEWER_DIR}/viewer-fltk.cc
+      ${AVIDA_FLTK_VIEWER_DIR}/fltk-defs.cc
     )
     SOURCE_GROUP(targets\\viewer-fltk FILES ${AVIDA_FLTK_VIEWER_SOURCES})
     ADD_EXECUTABLE(avida-fltkview ${AVIDA_FLTK_VIEWER_SOURCES})

Modified: development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc
===================================================================
--- development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/targets/viewer-fltk/cDriver_FLTKViewer.cc	2007-07-14 19:33:11 UTC (rev 1806)
@@ -40,32 +40,27 @@
 #include "cDriverManager.h"
 #include "cFLTKWindow.h"
 #include "cFLTKBox.h"
+#include "tFLTKButton.h"
 
 #include <cstdlib>
 
 #include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Box.H>
+// #include <FL/Fl_Window.H>
+// #include <FL/Fl_Box.H>
 
 
 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)
-  : cGUIDriver(world)
+  : m_world(world)
+  , m_info(world->GetPopulation(), 12)
+  , m_done(false)
+  , m_main_window(800, 600, "Avida")
+  , m_menu_box(m_main_window, 0, 0, 800, 50)
+  , m_body_box(m_main_window, 0, 50, 800, 550)
+  , m_update_box(m_main_window, 0, 0, 200, 50, "Update 0")
+  , m_title_box(m_main_window, 600, 0, 200, 50, "Avida")
+  , m_quit_button(m_main_window, 200, 0, 200, 50, "Quit")
 {
   // Setup the initial view mode (loaded from avida.cfg)
   m_info.SetViewMode(world->GetConfig().VIEW_MODE.Get());
@@ -73,27 +68,31 @@
   cDriverManager::Register(static_cast<cAvidaDriver*>(this));
   world->SetDriver(this);
 
-  LaunchViewer();
+  m_main_window.SetSizeRange(800, 600);
 
-//   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);
+  m_menu_box.SetType(cGUIBox::BOX_RAISED_FRAME);
+  m_menu_box.Refresh();
 
-//   int argc = 1;
-//   char * progname = "Avida";
-//   char ** argv = &progname;
+  m_update_box.SetType(cGUIBox::BOX_RAISED);
+  m_update_box.SetFontSize(30);
+  m_update_box.Refresh();
+ 
+  m_title_box.SetType(cGUIBox::BOX_RAISED);
+  m_title_box.SetFontSize(30);
+  m_title_box.Refresh();
 
-//   window->show(argc, argv);
+  m_main_window.Resizable(m_body_box);
 
-//   bool error = Fl::run();
-//   (void) error;
+  m_quit_button.SetCallback(this, &cDriver_FLTKViewer::ButtonCallback_Quit);
+
+  m_main_window.Finalize();
 }
 
+
 cDriver_FLTKViewer::~cDriver_FLTKViewer()
 {
   cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
+  delete m_world;
     
   ExitFLTKViewer(0);
 }
@@ -329,10 +328,11 @@
 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();
+  m_update_box.SetName(update_string);
+  m_update_box.Refresh();
   
 
   const int pause_level = m_info.GetPauseLevel();
@@ -403,7 +403,13 @@
 }
 
 
+void cDriver_FLTKViewer::ButtonCallback_Quit(double ignore)
+{
+  (void) ignore;
+  exit(0);
+}
 
+
 void ExitFLTKViewer(int exit_code)
 {
   signal(SIGINT, SIG_IGN);           // Ignore all future interupts.

Modified: development/source/targets/viewer-fltk/cDriver_FLTKViewer.h
===================================================================
--- development/source/targets/viewer-fltk/cDriver_FLTKViewer.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/targets/viewer-fltk/cDriver_FLTKViewer.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -37,9 +37,9 @@
 #include "cWorldDriver.h"
 #endif
 
-#ifndef cGUIDriver_h
-#include "cGUIDriver.h"
-#endif
+#include "cFLTKBox.h"
+#include "cFLTKWindow.h"
+#include "tFLTKButton.h"
 
 #include <sstream>
 #include <iostream>
@@ -50,12 +50,23 @@
 
 using namespace std;
 
-class cDriver_FLTKViewer : public cAvidaDriver, public cWorldDriver,  public cGUIDriver {
+class cDriver_FLTKViewer : public cAvidaDriver, public cWorldDriver {
 private:
-  // 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);
+  cWorld * m_world;
+  cCoreView_Info m_info;
 
+  bool m_done;              // This is set to true when run should finish.
+
+  // Graphics components...
+  cFLTKWindow m_main_window;
+
+  cFLTKBox m_menu_box;
+  cFLTKBox m_body_box;
+  cFLTKBox m_update_box;
+  cFLTKBox m_title_box;
+
+  tFLTKButton<cDriver_FLTKViewer> m_quit_button;
+
 public:
   cDriver_FLTKViewer(cWorld* world);
   ~cDriver_FLTKViewer();
@@ -89,6 +100,9 @@
 
   // Tests
   bool IsInteractive() { return true; }
+
+  // Button Callbacks...
+  void ButtonCallback_Quit(double ignore);
 };
 
 

Modified: development/source/targets/viewer-fltk/cFLTKBox.h
===================================================================
--- development/source/targets/viewer-fltk/cFLTKBox.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/targets/viewer-fltk/cFLTKBox.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -36,8 +36,8 @@
   Fl_Box * m_box;
   
 public:
-  cFLTKBox(int x, int y, int width, int height, const cString & name="")
-    : cGUIBox(x, y, width, height, name)
+  cFLTKBox(cGUIContainer & parent, int x, int y, int width, int height, const cString & name="")
+    : cGUIBox(parent, x, y, width, height, name)
   {
     m_box = new Fl_Box(x, y, width, height, name);
   }
@@ -60,6 +60,8 @@
     m_box->labelsize(m_font_size);
     m_box->redraw();
   }
+
+  Fl_Box * GetFLTKPtr() { return m_box; }
 };
 
 #endif

Modified: development/source/targets/viewer-fltk/cFLTKWindow.h
===================================================================
--- development/source/targets/viewer-fltk/cFLTKWindow.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/targets/viewer-fltk/cFLTKWindow.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -31,6 +31,8 @@
 
 #include <FL/Fl_Window.H>
 
+#include "cFLTKBox.h"
+
 class cFLTKWindow : public cGUIWindow {
 protected:
   Fl_Window * m_window;
@@ -53,6 +55,12 @@
     m_window->show();
   }
   void Update() { ; }
+
+  void Resizable(cFLTKBox & box) {
+    m_window->resizable(box.GetFLTKPtr());
+  }
+
+  Fl_Window * GetFLTKPtr() { return m_window; }
 };
 
 #endif

Added: development/source/targets/viewer-fltk/fltk-defs.cc
===================================================================
--- development/source/targets/viewer-fltk/fltk-defs.cc	                        (rev 0)
+++ development/source/targets/viewer-fltk/fltk-defs.cc	2007-07-14 19:33:11 UTC (rev 1806)
@@ -0,0 +1,32 @@
+/*
+ *  fltk_defs.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 "fltk-defs.h"
+
+#include "cGUIButton.h"
+
+void GenericButtonCallback(void *, cGUIButton * button)
+{
+  button->Press();
+}

Added: development/source/targets/viewer-fltk/fltk-defs.h
===================================================================
--- development/source/targets/viewer-fltk/fltk-defs.h	                        (rev 0)
+++ development/source/targets/viewer-fltk/fltk-defs.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -0,0 +1,34 @@
+/*
+ *  fltk_defs.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 fltk_defs_h
+#define fltk_defs_h
+
+class cGUIButton;
+
+void GenericButtonCallback(void *, cGUIButton * button);
+
+#endif

Added: development/source/targets/viewer-fltk/tFLTKButton.h
===================================================================
--- development/source/targets/viewer-fltk/tFLTKButton.h	                        (rev 0)
+++ development/source/targets/viewer-fltk/tFLTKButton.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -0,0 +1,57 @@
+/*
+ *  tFLTKButton.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 class to manage the FLTK GUI buttons...
+
+#ifndef tFLTKButton_h
+#define tFLTKButton_h
+
+#include "tGUIButton.h"
+#include "fltk-defs.h"
+
+#include "FL/Fl_Button.H"
+
+template <class T> class tFLTKButton : public tGUIButton<T> {
+protected:
+  Fl_Button * m_button;
+
+public:
+  tFLTKButton(cGUIContainer & parent, int x, int y, int width, int height, const cString & name="")
+    : tGUIButton<T>(parent, x, y, width, height, name)
+  {
+    m_button = new Fl_Button(x, y, width, height, name);
+    m_button->callback((Fl_Callback*) GenericButtonCallback, (void*)(this));
+  }
+  ~tFLTKButton() { delete m_button; }
+
+  void BindKey(int key) { (void) key; }
+};
+
+
+#include <FL/Fl_Button.H>
+
+
+
+
+#endif

Modified: development/source/viewer-coreGUI/cGUIBox.h
===================================================================
--- development/source/viewer-coreGUI/cGUIBox.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/viewer-coreGUI/cGUIBox.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -37,8 +37,8 @@
   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)
+  cGUIBox(cGUIContainer & parent, int x, int y, int width, int height, const cString & name="")
+    : cGUIWidget(parent, x, y, width, height, name)
     , m_type(BOX_NONE) { ; }
   virtual ~cGUIBox() { ; }
 

Modified: development/source/viewer-coreGUI/cGUIButton.h
===================================================================
--- development/source/viewer-coreGUI/cGUIButton.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/viewer-coreGUI/cGUIButton.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -31,18 +31,19 @@
 
 class cGUIButton : public cGUIWidget {
 public:
-  enum eButtonType { BUTTON_NORMAL, BUTTON_TOGGLE, BUTTON_RADIO, BUTTON_LIGHT, BUTTON_RADIO_LIGHT, BUTTON_RETURN, BUTTON_REPEAT };
+  enum eButtonType { BUTTON_NORMAL, BUTTON_TOGGLE, BUTTON_RADIO, BUTTON_LIGHT,
+		     BUTTON_RADIO_LIGHT, BUTTON_RETURN, BUTTON_REPEAT };
 
 protected:
   int m_type;    // What type of button is this?
   int m_binding; // What keypress is this button bound to?
 
 public:
-  cGUIButton(int x, int y, width, height, name="") : cGUIWidget(x, y, width, height, name) { ; }
+  cGUIButton(cGUIContainer & parent, int x, int y, int width, int height, const cString & name="")
+    : cGUIWidget(parent, x, y, width, height, name) { ; }
   virtual ~cGUIButton() { ; }
 
-  virtual void DoPress() = 0;
-  virtual void DoRelease() = 0;
+  virtual void Press() = 0;
   virtual void BindKey(int key) = 0;
 
   int GetType() const { return m_type; }

Modified: development/source/viewer-coreGUI/cGUIContainer.h
===================================================================
--- development/source/viewer-coreGUI/cGUIContainer.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/viewer-coreGUI/cGUIContainer.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -42,6 +42,8 @@
   cGUIContainer() { ; }
   cGUIContainer(int x, int y, int width=0, int height=0, const cString & name="")
     : cGUIWidget(x, y, width, height, name) { ; }
+  cGUIContainer(cGUIContainer & parent, int x, int y, int width=0, int height=0, const cString & name="")
+    : cGUIWidget(parent, 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.

Deleted: development/source/viewer-coreGUI/cGUIDriver.cc
===================================================================
--- development/source/viewer-coreGUI/cGUIDriver.cc	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/viewer-coreGUI/cGUIDriver.cc	2007-07-14 19:33:11 UTC (rev 1806)
@@ -1,68 +0,0 @@
-/*
- *  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()
-{
-}

Deleted: development/source/viewer-coreGUI/cGUIDriver.h
===================================================================
--- development/source/viewer-coreGUI/cGUIDriver.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/viewer-coreGUI/cGUIDriver.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -1,63 +0,0 @@
-/*
- *  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

Added: development/source/viewer-coreGUI/cGUIWidget.cc
===================================================================
--- development/source/viewer-coreGUI/cGUIWidget.cc	                        (rev 0)
+++ development/source/viewer-coreGUI/cGUIWidget.cc	2007-07-14 19:33:11 UTC (rev 1806)
@@ -0,0 +1,42 @@
+/*
+ *  cGUIWidget.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 "cGUIWidget.h"
+#include "cGUIContainer.h"
+
+cGUIWidget::cGUIWidget()
+  : m_parent(NULL), m_x(0), m_y(0), m_width(0), m_height(0), m_font_size(20)
+{
+}
+
+cGUIWidget::cGUIWidget(int x, int y, int width, int height, const cString & name)
+    : m_parent(NULL), m_name(name), m_x(x), m_y(y), m_width(width), m_height(height), m_font_size(20)
+{
+}
+
+cGUIWidget::cGUIWidget(cGUIContainer & parent, int x, int y, int width, int height, const cString & name)
+  : m_parent(&parent), m_name(name), m_x(x), m_y(y), m_width(width), m_height(height), m_font_size(20)
+{
+  parent.Add(this);
+}

Modified: development/source/viewer-coreGUI/cGUIWidget.h
===================================================================
--- development/source/viewer-coreGUI/cGUIWidget.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/viewer-coreGUI/cGUIWidget.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -35,6 +35,7 @@
 class cGUIWidget {
   friend class cGUIContainer;
 protected:
+  cGUIContainer * m_parent;
   cString m_name;
   int m_x;
   int m_y;
@@ -43,9 +44,9 @@
 
   int m_font_size;
 public:
-  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) { ; }
+  cGUIWidget();
+  cGUIWidget(int x, int y, int width=0, int height=0, const cString & name="");
+  cGUIWidget(cGUIContainer & parent, int x, int y, int width=0, int height=0, const cString & name="");
   virtual ~cGUIWidget() { ; }
 
   // This method should be run when the widget is setup and its time to build it.
@@ -54,6 +55,7 @@
   // This method should deal with GUI events.
   virtual bool Handle(cGUIEvent & event) { (void) event; return false; }
 
+  cGUIContainer * GetParent() { return m_parent; }
   const cString & GetName() { return m_name; }
   int GetX() const { return m_x; }
   int GetY() const { return m_y; }

Modified: development/source/viewer-coreGUI/tGUIButton.h
===================================================================
--- development/source/viewer-coreGUI/tGUIButton.h	2007-07-14 16:17:54 UTC (rev 1805)
+++ development/source/viewer-coreGUI/tGUIButton.h	2007-07-14 19:33:11 UTC (rev 1806)
@@ -27,26 +27,30 @@
 #ifndef tGUIButton_h
 #define tGUIButton_h
 
-#include "cGUIWidget.h"
+#include "cGUIButton.h"
 
 template <class T> class tGUIButton : public cGUIButton {
 protected:
   T * m_target;
-  void (T::*m_press_callback)(double);
-  void (T::*m_release_callback)(double);
+  void (T::*m_callback)(double);
+  double m_arg;
 
 public:
-  tGUIButton(int x, int y, width, height, name="") : cGUIButton(x, y, width, height, name) { ; }
+  tGUIButton(cGUIContainer & parent, int x, int y, int width, int height, const cString & name="")
+    : cGUIButton(parent, x, y, width, height, name), m_target(NULL), m_callback(NULL), m_arg(0.0) { ; }
   virtual ~tGUIButton() { ; }
 
   T & GetTarget() { return *m_target; }
+  double GetArg() { return m_arg; }
 
-  void SetTarget(T & _target) { m_target = _target; }
-  void SetPressCallback(void (T::*cb_fun)(double)) { m_press_callback = cb_fun; }
-  void SetReleaseCallback(void (T::*cb_fun)(double)) { m_release_callback = cb_fun; }
+  void SetCallback(T * target, void (T::*cb_fun)(double), double arg=0.0) {
+    m_target = target;
+    m_callback = cb_fun;
+    m_arg = arg;
+  }
 
-  virtual void DoPress(double value=1.0) { if (m_press_callback != NULL) (m_target->*(m_press_callback))(value); }
-  virtual void DoRelease(double value=0.0) { if (m_release_callback != NULL) (m_target->*(m_release_callback))(value); }
+  virtual void Press() { if (m_callback != NULL) (m_target->*(m_callback))(m_arg); }
+  virtual void Press(double arg) { if (m_callback != NULL) (m_target->*(m_callback))(arg); }
 };
 
 #endif




More information about the Avida-cvs mailing list