[Avida-SVN] r1773 - development/source/viewer-coreGUI
ofria at myxo.css.msu.edu
ofria at myxo.css.msu.edu
Tue Jul 10 09:58:30 PDT 2007
Author: ofria
Date: 2007-07-10 12:58:30 -0400 (Tue, 10 Jul 2007)
New Revision: 1773
Added:
development/source/viewer-coreGUI/cGUIButton.h
development/source/viewer-coreGUI/cGUICanvas.h
development/source/viewer-coreGUI/cGUIColor.h
development/source/viewer-coreGUI/cGUIContainer.h
development/source/viewer-coreGUI/cGUIEvent.h
development/source/viewer-coreGUI/cGUIScrollArea.h
development/source/viewer-coreGUI/cGUISlider.h
development/source/viewer-coreGUI/cGUIWidget.h
development/source/viewer-coreGUI/tGUIButton.h
development/source/viewer-coreGUI/tGUISlider.h
Log:
Created a set of base classes for the core GUI.
Added: development/source/viewer-coreGUI/cGUIButton.h
===================================================================
--- development/source/viewer-coreGUI/cGUIButton.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIButton.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,52 @@
+/*
+ * cGUIButton.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 buttons.
+
+#ifndef cGUIButton_h
+#define cGUIButton_h
+
+#include "cGUIWidget.h"
+
+class cGUIButton : public cGUIWidget {
+public:
+ 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) { ; }
+ virtual ~cGUIButton() { ; }
+
+ virtual void DoPress() = 0;
+ virtual void DoRelease() = 0;
+ virtual void BindKey(int key) = 0;
+
+ int GetType() const { return m_type; }
+ int GetBinding() const { return m_binding; }
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUICanvas.h
===================================================================
--- development/source/viewer-coreGUI/cGUICanvas.h (rev 0)
+++ development/source/viewer-coreGUI/cGUICanvas.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,50 @@
+/*
+ * cGUICanvas.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 GUI widgets that can be drawn on.
+
+#ifndef cGUICanvas_h
+#define cGUICanvas_h
+
+#include "cGUIWidget.h"
+
+class cGUIEvent;
+
+class cGUICanvas : public cGUIWidget {
+protected:
+public:
+ cGUICanvas() { ; }
+ 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;
+
+ virtual void SetColor(cColor color) = 0;
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUIColor.h
===================================================================
--- development/source/viewer-coreGUI/cGUIColor.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIColor.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,49 @@
+/*
+ * cGUIColor.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 deals with colors in the GUI.
+
+#ifndef cGUIColor_h
+#define cGUIColor_h
+
+class cGUIColor {
+protected:
+ int m_red; // Limited to 0-255
+ int m_green; // Limited to 0-255
+ int m_blue; // Limited to 0-255
+
+public:
+ cGUIColor(int _r, int _g, int _b) : m_red(_r), m_green(_g), m_blue(_b) {
+ assert(m_red >= 0 && m_red < 256);
+ assert(m_green >= 0 && m_green < 256);
+ assert(m_blue >= 0 && m_blue < 256);
+ }
+ virtual ~cGUIColor() { ; }
+
+ int GetRed() const { return m_red; }
+ int GetGreen() const { return m_green; }
+ int GetBlue() const { return m_blue; }
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUIContainer.h
===================================================================
--- development/source/viewer-coreGUI/cGUIContainer.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIContainer.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,64 @@
+/*
+ * cGUIContainer.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 can be used as containers for other widgets in Avida.
+
+#ifndef cGUIContainer_h
+#define cGUIContainer_h
+
+#include "cGUIWidget.h"
+
+#include "tArray.h"
+
+class cGUIContainer : public cGUIWidget {
+protected:
+ tArray<cGUIWidget *> widget_array;
+
+ // The Create() method recursively builds everything contained here; create self is run first to set it up.
+ virtual void CreateSelf() { ; }
+
+public:
+ cGUIContainer() { ; }
+ cGUIContainer(int x, int y, width=0, height=0, 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();
+ }
+ }
+
+ 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="") {
+ in_widget->m_x = x;
+ in_widget->m_y = y;
+ in_widget->m_width = width;
+ in_widget->m_height = height;
+ if (name != "") in_widget->m_name = name;
+ }
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUIEvent.h
===================================================================
--- development/source/viewer-coreGUI/cGUIEvent.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIEvent.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,44 @@
+/*
+ * cGUIEvent.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 events that can occur in the GUI, such as mouse clicks.
+
+#ifndef cGUIEvent_h
+#define cGUIEvent_h
+
+class cGUIEvent {
+public:
+ enum eGUIEventType { MOUSE_CLICK, MOUSE_MOVE, MOUSE_RELEASE, KEYPRESS };
+
+protected:
+ eGUIEventType m_type;
+
+public:
+ cGUIEvent() { ; }
+ virtual ~cGUIEvent() { ; }
+
+ eGUIEventType GetType() { return m_type; }
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUIScrollArea.h
===================================================================
--- development/source/viewer-coreGUI/cGUIScrollArea.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIScrollArea.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,39 @@
+/*
+ * cGUIScrollArea.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 a panels containing widgets and have scollbars.
+
+#ifndef cGUIScrollArea_h
+#define cGUIScrollArea_h
+
+#include "cGUIContainer.h"
+
+class cGUIScrollArea : public cGUIContainer {
+protected:
+public:
+ cGUIScrollArea(int x, int y, width, height, name="") : cGUIContainer(x, y, width, height, name) { ; }
+ virtual ~cGUIScrollArea() { ; }
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUISlider.h
===================================================================
--- development/source/viewer-coreGUI/cGUISlider.h (rev 0)
+++ development/source/viewer-coreGUI/cGUISlider.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,54 @@
+/*
+ * cGUISlider.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 sliders.
+
+#ifndef cGUISlider_h
+#define cGUISlider_h
+
+#include "cGUIWidget.h"
+
+class cGUISlider : public cGUIWidget {
+public:
+ enum eSliderType { SLIDER_DEFAULT, SLIDER_VERT, SLIDER_HOIZ, SLIDER_DEFAULT_VALUE, SLIDER_VERT_VALUE, SLIDER_HOIZ_VALUE };
+
+protected:
+ eSliderType m_type; // What type of slider is this?
+ double m_min;
+ double m_max;
+ double m_default;
+
+public:
+ cGUISlider(int x, int y, width, height, name="") : cGUIWidget(x, y, width, height, name) { ; }
+ virtual ~cGUISlider() { ; }
+
+ virtual void DoSlide() = 0;
+
+ int GetType() const { return m_type; }
+ int GetMin() const { return m_min; }
+ int GetMax() const { return m_max; }
+ int GetDefault() const { return m_default; }
+};
+
+#endif
Added: development/source/viewer-coreGUI/cGUIWidget.h
===================================================================
--- development/source/viewer-coreGUI/cGUIWidget.h (rev 0)
+++ development/source/viewer-coreGUI/cGUIWidget.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,50 @@
+/*
+ * cGUIWidget.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 used in Avida.
+
+#ifndef cGUIWidget_h
+#define cGUIWidget_h
+
+#include "cString.h"
+
+class cGUIWidget {
+protected:
+ cString m_name;
+ int m_x;
+ int m_y;
+ int m_width;
+ int m_height;
+
+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) { ; }
+ virtual ~cGUIWidget() { ; }
+
+ // This method should be run when the widget is setup and its time to build it.
+ virtual void Create() = 0;
+};
+
+#endif
Added: development/source/viewer-coreGUI/tGUIButton.h
===================================================================
--- development/source/viewer-coreGUI/tGUIButton.h (rev 0)
+++ development/source/viewer-coreGUI/tGUIButton.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,52 @@
+/*
+ * tGUIButton.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 buttons.
+
+#ifndef tGUIButton_h
+#define tGUIButton_h
+
+#include "cGUIWidget.h"
+
+template <class T> class tGUIButton : public cGUIButton {
+protected:
+ T * m_target;
+ void (T::*m_press_callback)(double);
+ void (T::*m_release_callback)(double);
+
+public:
+ tGUIButton(int x, int y, width, height, name="") : cGUIButton(x, y, width, height, name) { ; }
+ virtual ~tGUIButton() { ; }
+
+ T & GetTarget() { return *m_target; }
+
+ 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; }
+
+ 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); }
+};
+
+#endif
Added: development/source/viewer-coreGUI/tGUISlider.h
===================================================================
--- development/source/viewer-coreGUI/tGUISlider.h (rev 0)
+++ development/source/viewer-coreGUI/tGUISlider.h 2007-07-10 16:58:30 UTC (rev 1773)
@@ -0,0 +1,49 @@
+/*
+ * tGUISlider.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 sliders.
+
+#ifndef tGUISlider_h
+#define tGUISlider_h
+
+#include "cGUIWidget.h"
+
+template <class T> class tGUISlider : public cGUISlider {
+protected:
+ T * m_target;
+ void (T::*m_slide_callback)(double);
+
+public:
+ tGUISlider(int x, int y, width, height, name="") : cGUISlider(x, y, width, height, name) { ; }
+ virtual ~tGUISlider() { ; }
+
+ T & GetTarget() { return *m_target; }
+
+ void SetTarget(T & _target) { m_target = _target; }
+ void SetSlideCallback(void (T::*cb_fun)(double)) { m_slide_callback = cb_fun; }
+
+ virtual void DoSlide(double value=1.0) { if (m_slide_callback != NULL) (m_target->*(m_slide_callback))(value); }
+};
+
+#endif
More information about the Avida-cvs
mailing list