[Avida-SVN] r1762 - in development/source: . targets targets/viewer-fltk targets/viewer-text viewer-core
ofria at myxo.css.msu.edu
ofria at myxo.css.msu.edu
Sun Jul 8 11:15:17 PDT 2007
Author: ofria
Date: 2007-07-08 14:15:17 -0400 (Sun, 08 Jul 2007)
New Revision: 1762
Added:
development/source/targets/viewer-fltk/
development/source/targets/viewer-fltk/viewer-fltk.cc
development/source/viewer-coreGUI/
Modified:
development/source/targets/viewer-text/cDriver_TextViewer.cc
development/source/targets/viewer-text/cDriver_TextViewer.h
development/source/targets/viewer-text/cTextWindow.cc
development/source/targets/viewer-text/cTextWindow.h
development/source/viewer-core/cCoreView_Info.cc
development/source/viewer-core/cCoreView_Info.h
Log:
Continuing work on core viewer...
Added: development/source/targets/viewer-fltk/viewer-fltk.cc
===================================================================
--- development/source/targets/viewer-fltk/viewer-fltk.cc (rev 0)
+++ development/source/targets/viewer-fltk/viewer-fltk.cc 2007-07-08 18:15:17 UTC (rev 1762)
@@ -0,0 +1,65 @@
+/*
+ * viewer.cc
+ * Avida
+ *
+ * Created by Charles on 7/1/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 <csignal>
+
+#include "avida.h"
+#include "cAvidaConfig.h"
+#include "cDriverManager.h"
+#include "PlatformExpert.h"
+#include "cWorld.h"
+
+#include "cDriver_TextViewer.h"
+
+
+using namespace std;
+
+
+int main(int argc, char * argv[])
+{
+ PlatformExpert::Initialize();
+
+ printVersionBanner();
+
+ // Initialize the configuration data...
+ cWorld* world = new cWorld(cAvidaConfig::LoadWithCmdLineArgs(argc, argv));
+ cAvidaDriver* driver = NULL;
+
+ // Test to see if we should be in analyze mode only...
+ if (world->GetConfig().ANALYZE_MODE.Get() > 0); // @CAO Do something here...
+
+ cout << "We Made IT! Now we stop." << endl;
+
+ driver = new cDriver_TextViewer(world);
+
+ cout << "And a bit more for the console to swallow..." << endl;
+
+
+ driver->Run();
+
+ // Exit Nicely
+ ExitAvida(0);
+
+ return 0;
+}
Modified: development/source/targets/viewer-text/cDriver_TextViewer.cc
===================================================================
--- development/source/targets/viewer-text/cDriver_TextViewer.cc 2007-07-07 15:47:31 UTC (rev 1761)
+++ development/source/targets/viewer-text/cDriver_TextViewer.cc 2007-07-08 18:15:17 UTC (rev 1762)
@@ -49,11 +49,9 @@
: m_world(world)
, m_info(m_world->GetPopulation(), 12)
, m_main_window(NULL, m_info)
- , m_bar_window(&m_main_window, m_info)
+ , m_bar_window(NULL, m_info)
, m_done(false)
{
- m_info.fp << "::cDriver_TextViewer()" << endl; // DEBUG!!!!!!!!!
-
// Setup the initial view mode (loaded from avida.cfg)
m_info.SetViewMode(world->GetConfig().VIEW_MODE.Get());
@@ -84,34 +82,23 @@
// Build the main body of this window.
m_main_window.Construct(0,0,3,0);
- m_info.fp << "Base Width = " << m_main_window.GetWidth()
- << " Height = " << m_main_window.GetHeight()
- << endl;
m_bar_window.Construct(3,0,0,0);
- m_info.fp << "Bar Width = " << m_bar_window.GetWidth()
- << " Height = " << m_bar_window.GetHeight()
- << endl;
- m_bar_window.Box();
+ Draw();
m_main_window.SetBoldColor(COLOR_WHITE);
- m_main_window.Box(5, 5, 30, 30);
m_main_window.Print(10, 10, "This is a test!");
- m_main_window.Refresh();
- int tmp = 5;
- for (int i = 0; i < 1000000000; i++) tmp = tmp + 2;
-
// NoDelay(false);
+ wrefresh(stdscr);
m_bar_window.Redraw();
- getch();
+ m_main_window.Redraw();
- exit(0);
+// getch();
+// exit(0);
}
cDriver_TextViewer::~cDriver_TextViewer()
{
- m_info.fp << "::~cDriver_TextViewer()" << endl; // DEBUG!!!!!!!!!
-
cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
delete m_world;
@@ -121,8 +108,6 @@
void cDriver_TextViewer::Run()
{
- m_info.fp << "::Run()" << endl; // DEBUG!!!!!!!!!
-
cClassificationManager& classmgr = m_world->GetClassificationManager();
cPopulation& population = m_world->GetPopulation();
cStats& stats = m_world->GetStats();
@@ -168,7 +153,7 @@
for (int i = 0; i < UD_size; i++) {
const int next_id = population.ScheduleOrganism();
if (next_id == m_info.GetStepOrganism()) {
- NotifyUpdate();
+ DoUpdate();
// m_view.NewUpdate();
// This is needed to have the top bar drawn properly; I'm not sure why...
@@ -192,7 +177,7 @@
// Setup the viewer for the new update.
if (m_info.GetStepOrganism() == -1) {
- NotifyUpdate();
+ DoUpdate();
// NewUpdate();
// This is needed to have the top bar drawn properly; I'm not sure why...
@@ -227,8 +212,6 @@
void cDriver_TextViewer::Flush()
{
- m_info.fp << "::Flush()" << endl; // DEBUG!!!!!!!!!
-
cStringList & out_list = m_info.GetOutList();
cStringList & err_list = m_info.GetErrList();
@@ -247,8 +230,6 @@
bool cDriver_TextViewer::ProcessKeypress(int keypress)
{
- m_info.fp << "::ProcessKeypress()" << endl; // DEBUG!!!!!!!!!
-
bool unknown = false;
switch (keypress) {
@@ -305,14 +286,14 @@
break;
case 'q':
-// if (!Confirm("Are you sure you want to quit?")) break;
+ if (!Confirm("Are you sure you want to quit?")) break;
case 'Q': // Note: Capital 'Q' quits w/o confirming.
// clear the windows before we go. Do bar window last to end at top.
m_main_window.Clear();
m_main_window.Redraw();
m_bar_window.Clear();
m_bar_window.Redraw();
- ExitTextViewer(0); // This implementation calls exit(), blowing us clean away
+ ExitTextViewer(0);
break;
// case 's':
// case 'S':
@@ -334,25 +315,14 @@
exit(0);
break;
case 12: // CTRL-L...
- m_main_window.Refresh();
+ wclear(stdscr);
+ wrefresh(stdscr);
+ m_bar_window.Redraw();
+ m_main_window.Redraw();
break;
case 26: // CTRL-Z
kill(getpid(), SIGTSTP);
break;
-// case '*': // Test Key!!!
-// if (true) {
-// Confirm("Starting Tests.");
-// cMenuWindow menu(50);
-// char message[40];
-// for (int j = 0; j < 50; j++) {
-// sprintf(message, "Line %d", j);
-// menu.AddOption(j, message);
-// }
-// menu.SetActive(3);
-// menu.Activate(main_window);
-// Redraw();
-// }
-// break;
case ERR:
break;
default:
@@ -376,10 +346,42 @@
exit(exit_code);
}
-void cDriver_TextViewer::NotifyUpdate()
+
+void cDriver_TextViewer::Draw()
{
- m_info.fp << "::NotifyUpdate()" << endl; // DEBUG!!!!!!!!!
+ m_bar_window.SetBoldColor(COLOR_WHITE);
+ m_bar_window.Box();
+ m_bar_window.VLine(18);
+ m_bar_window.VLine(-11);
+
+ m_bar_window.Print(1, -8, "Avida");
+ m_bar_window.Print(1, 2, "Update:");
+
+ const int max_x = m_bar_window.GetWidth() - 19;
+ int cur_x = 21;
+
+ // Include options in their general order of importance.
+ cur_x = m_bar_window.PrintMenuBarOption("[M]ap ", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[S]tats", max_x, cur_x);
+ // cur_x = m_bar_window.PrintMenuBarOption("[A]nalyze", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[Z]oom", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[O]ptions", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[H]ist", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[E]nv ", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[P]ause", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[B]lank", max_x, cur_x);
+ cur_x = m_bar_window.PrintMenuBarOption("[C]hoose CPU", max_x, cur_x);
+
+ // Always place Quit as the last option.
+ cur_x = m_bar_window.PrintMenuBarOption("[Q]uit", max_x+8, cur_x);
+
+ m_bar_window.Refresh();
+}
+
+
+void cDriver_TextViewer::DoUpdate()
+{
// @CAO What else should happen on an update?
// - Update bar at top of screen
// - Update current view
@@ -387,7 +389,12 @@
// const int update = m_world->GetStats().GetUpdate();
// if (update % 10 == 0) clog << update << endl;
+
+ m_bar_window.SetBoldColor(COLOR_WHITE);
+ m_bar_window.Print(1, 11, "%d", m_world->GetStats().GetUpdate());
+ m_bar_window.SetColor(COLOR_WHITE);
+ m_bar_window.Refresh();
m_main_window.Refresh();
const int pause_level = m_info.GetPauseLevel();
@@ -448,12 +455,61 @@
void cDriver_TextViewer::Notify(const cString& in_string)
{
- m_info.fp << "::Notify()" << endl; // DEBUG!!!!!!!!!
// @CAO We need to display this!
}
+int cDriver_TextViewer::Confirm(const cString & message)
+{
+ const int mess_length = message.GetSize();
+ // Create a confirm window, and draw it on the screen.
+
+ const int conf_width = mess_length + 10;
+ const int conf_x = (m_main_window.GetWidth() - conf_width) / 2;
+ cTextWindow conf_win(NULL, m_info, 3, conf_width, 10, conf_x);
+ conf_win.Box();
+ conf_win.SetBoldColor(COLOR_WHITE);
+ conf_win.Print(1, 2, "%s (y/n)", static_cast<const char*>(message));
+ conf_win.SetBoldColor(COLOR_CYAN);
+ conf_win.Print(1, mess_length + 4, 'y');
+ conf_win.Print(1, mess_length + 6, 'n');
+ conf_win.SetColor(COLOR_WHITE);
+ conf_win.Refresh();
+
+ // Wait for the results.
+ bool finished = false;
+ bool result = false;
+ int cur_char;
+
+ while (finished == false) {
+ cur_char = GetKeypress();
+ switch (cur_char) {
+ case 'q':
+ case 'Q':
+ case 'n':
+ case 'N':
+ case ' ':
+ case '\n':
+ case '\r':
+ finished = true;
+ result = false;
+ break;
+ case 'y':
+ case 'Y':
+ finished = true;
+ result = true;
+ break;
+ }
+ }
+
+ // Redraw the screen, and return the results.
+ m_main_window.Redraw();
+ return result;
+}
+
+
+
void ExitTextViewer(int exit_code)
{
signal(SIGINT, SIG_IGN); // Ignore all future interupts.
Modified: development/source/targets/viewer-text/cDriver_TextViewer.h
===================================================================
--- development/source/targets/viewer-text/cDriver_TextViewer.h 2007-07-07 15:47:31 UTC (rev 1761)
+++ development/source/targets/viewer-text/cDriver_TextViewer.h 2007-07-08 18:15:17 UTC (rev 1762)
@@ -74,22 +74,25 @@
// IO
void Flush();
- int GetKeypress() { m_info.fp << "GK" << endl; return getch(); }
+ int GetKeypress() { return getch(); }
bool ProcessKeypress(int keypress);
- void NoDelay(bool _nd=true) { m_info.fp << "ND" << endl; nodelay(stdscr, _nd); } // Don't wait for input if no key is pressed.
+ void NoDelay(bool _nd=true) { nodelay(stdscr, _nd); } // Don't wait for input if no key is pressed.
void RaiseException(const cString& in_string);
void RaiseFatalException(int exit_code, const cString& in_string);
+ // Drawing and interaction.
+ void Draw();
+ void DoUpdate();
+
// Notifications
- void NotifyUpdate();
void NotifyComment(const cString& in_string);
void NotifyWarning(const cString& in_string);
void NotifyError(const cString& in_string);
void NotifyOutput(const cString& in_string);
void Notify(const cString& in_string);
- int Confirm(const cString& in_string) { ; } // @CAO Do this...
+ int Confirm(const cString& in_string);
// Tests
bool IsInteractive() { return true; }
Modified: development/source/targets/viewer-text/cTextWindow.cc
===================================================================
--- development/source/targets/viewer-text/cTextWindow.cc 2007-07-07 15:47:31 UTC (rev 1761)
+++ development/source/targets/viewer-text/cTextWindow.cc 2007-07-08 18:15:17 UTC (rev 1762)
@@ -34,7 +34,6 @@
cTextWindow::cTextWindow(cTextWindow * parent, cCoreView_Info & info)
: m_win_id(NULL), m_parent_window(parent), m_info(info)
{
- m_info.fp << "cTW::cTextWindow -- Base constructor for " << this << endl; // DEBUG!!!!!
}
@@ -44,9 +43,6 @@
// Build this window.
m_win_id = newwin(y_size, x_size, y_start, x_start);
- m_info.fp << "cTW::cTextWindow -- Full constructor for " << this << "; id=" << m_win_id << endl; // DEBUG!!!!!
-
-
// If a parent was given, register with it.
if (m_parent_window != NULL) m_parent_window->AddSubWindow(this);
@@ -57,8 +53,6 @@
cTextWindow::~cTextWindow()
{
- m_info.fp << "cTW::~cTextWindow -- Destructor for " << this << endl; // DEBUG!!!!!
-
// Delete all sub-windows...
for (int i = 0; i < m_sub_windows.GetSize(); i++) {
if (m_sub_windows[i]) delete m_sub_windows[i];
@@ -76,8 +70,6 @@
m_win_id = newwin(y_size, x_size, y_start, x_start);
- m_info.fp << "cTW::Construct() for " << this << "; new id = " << m_win_id << endl; // DEBUG!!!!!
-
// If a parent was given, register with it.
if (m_parent_window != NULL) m_parent_window->AddSubWindow(this);
keypad(m_win_id, 1); // Allows the keypad to be used.
@@ -89,8 +81,6 @@
{
assert(in_window != NULL);
- m_info.fp << "cTW::AddSubWindow(" << in_window << ") for " << this << endl; // DEBUG!!!!!
-
// Scan existing array for open spots...
for (int i = 0; i < m_sub_windows.GetSize(); i++) {
if (m_sub_windows[i] == NULL) {
@@ -121,8 +111,6 @@
void cTextWindow::Refresh()
{
- m_info.fp << "cTW::Refresh() for " << this << endl; // DEBUG!!!!!
-
RefreshSelf();
for (int i = 0; i < m_sub_windows.GetSize(); i++) {
if (m_sub_windows[i]) m_sub_windows[i]->Refresh();
@@ -132,8 +120,6 @@
void cTextWindow::Redraw()
{
- m_info.fp << "cTW::Redraw() for " << this << endl; // DEBUG!!!!!
-
RedrawSelf();
for (int i = 0; i < m_sub_windows.GetSize(); i++) {
if (m_sub_windows[i]) m_sub_windows[i]->Redraw();
@@ -142,8 +128,6 @@
void cTextWindow::Clear()
{
- m_info.fp << "cTW::Clear() for " << this << endl; // DEBUG!!!!!
-
ClearMain();
for (int i = 0; i < m_sub_windows.GetSize(); i++) {
if (m_sub_windows[i]) m_sub_windows[i]->Clear();
@@ -165,6 +149,9 @@
void cTextWindow::Print(int in_y, int in_x, const char * fmt, ...)
{
+ if (in_x < 0) in_x = GetWidth() + in_x;
+ if (in_y < 0) in_y = GetHeight() + in_y;
+
va_list argp;
char buf[BUFSIZ];
@@ -173,23 +160,75 @@
va_end(argp);
wmove(m_win_id, in_y, in_x);
waddstr(m_win_id, buf);
-
- m_info.fp << "cTW::Print(" << buf << ") for " << this << endl; // DEBUG!!!!!
}
void cTextWindow::PrintBinary(int in_y, int in_x, unsigned int value)
{
+ if (in_x < 0) in_x = GetWidth() + in_x;
+ if (in_y < 0) in_y = GetHeight() + in_y;
+
for (int i = 0; i < 32; i++) {
if ((value >> i) & 1) Print(in_y, in_x+31-i, '1');
else Print(in_y, in_x+31-i, '0');
}
}
+
+void cTextWindow::PrintDouble(int in_y, int in_x, double in_value)
+{
+ if (in_x < 0) in_x = GetWidth() + in_x;
+ if (in_y < 0) in_y = GetHeight() + in_y;
+
+ // If we have an integer, just include one zero at the end.
+ int int_value = (int) in_value;
+ if (in_value == ((double) int_value)) Print(in_y, in_x, "%5.1f", in_value);
+
+ // Otherwise give as many decimal places as we can...
+ else if (in_value < 10.0) Print(in_y, in_x, "%1.5f", in_value);
+ else if (in_value < 100.0) Print(in_y, in_x, "%2.4f", in_value);
+ else if (in_value < 1000.0) Print(in_y, in_x, "%3.3f", in_value);
+ else if (in_value < 10000.0) Print(in_y, in_x, "%4.2f", in_value);
+ else if (in_value < 100000.0) Print(in_y, in_x, "%5.1f", in_value);
+ else if (in_value < 10000000.0) Print(in_y, in_x, "%7d", int_value);
+
+ // And if its too big, use scientific notation.
+ else Print(in_y, in_x, "%7.1e", in_value);
+}
+
+
+void cTextWindow::PrintOption(int in_y, int in_x, const cString & option)
+{
+ if (in_x < 0) in_x = GetWidth() + in_x;
+ if (in_y < 0) in_y = GetHeight() + in_y;
+
+ // Print the main option...
+ SetBoldColor(COLOR_WHITE);
+ Print(in_y, in_x, option);
+
+ // Highlight the keypress...
+ SetBoldColor(COLOR_YELLOW);
+ bool highlight = false;
+ for (int i = 0; i < option.GetSize(); i++) {
+ if (option[i] == '[') { highlight = true; continue; }
+ if (option[i] == ']') { highlight = false; continue; }
+ if (highlight == true) Print(in_y, in_x+i, option[i]);
+ }
+}
+
+
+int cTextWindow::PrintMenuBarOption(const cString & option, int max_x, int cur_x)
+{
+ // If there isn't enough room for this option, don't print it; just return cur position.
+ if (cur_x + option.GetSize() >= max_x) return cur_x;
+
+ PrintOption(1, cur_x, option);
+ return cur_x+option.GetSize()+1;
+}
+
+
void cTextWindow::Box(int y, int x, int h, int w)
{
- m_info.fp << "cTW::Box(inputs!!) for " << this << endl; // DEBUG!!!!!
-
int i;
for (i = 1; i < h - 1; i++) {
mvwaddch(m_win_id, i + y, x, ACS_VLINE);
@@ -207,6 +246,8 @@
void cTextWindow::VLine(int in_x)
{
+ if (in_x < 0) in_x = GetWidth() + in_x;
+
mvwaddch(m_win_id, 0, in_x, ACS_TTEE);
mvwaddch(m_win_id, GetHeight() - 1, in_x, ACS_BTEE);
for (int i = 1; i < GetHeight() - 1; i++) {
@@ -216,6 +257,9 @@
void cTextWindow::VLine(int in_x, int start_y, int length)
{
+ if (in_x < 0) in_x = GetWidth() + in_x;
+ if (start_y < 0) start_y = GetHeight() + start_y;
+
mvwaddch(m_win_id, start_y, in_x, ACS_TTEE);
mvwaddch(m_win_id, start_y + length - 1, in_x, ACS_BTEE);
for (int i = 1; i < length - 1; i++) {
@@ -225,6 +269,8 @@
void cTextWindow::HLine(int in_y)
{
+ if (in_y < 0) in_y = GetHeight() + in_y;
+
mvwaddch(m_win_id, in_y, 0, ACS_LTEE);
mvwaddch(m_win_id, in_y, GetWidth() - 1, ACS_RTEE);
for (int i = 1; i < GetWidth() - 1; i++) {
@@ -234,6 +280,9 @@
void cTextWindow::HLine(int in_y, int start_x, int length)
{
+ if (in_y < 0) in_y = GetHeight() + in_y;
+ if (start_x < 0) start_x = GetWidth() + start_x;
+
mvwaddch(m_win_id, in_y, start_x, ACS_LTEE);
mvwaddch(m_win_id, in_y, start_x + length - 1, ACS_RTEE);
for (int i = 1; i < length - 1; i++) {
Modified: development/source/targets/viewer-text/cTextWindow.h
===================================================================
--- development/source/targets/viewer-text/cTextWindow.h 2007-07-07 15:47:31 UTC (rev 1761)
+++ development/source/targets/viewer-text/cTextWindow.h 2007-07-08 18:15:17 UTC (rev 1762)
@@ -25,6 +25,10 @@
#ifndef cTextWindow_h
#define cTextWindow_h
+#ifndef cString_h
+#include "cString.h"
+#endif
+
#ifndef tArray_h
#include "tArray.h"
#endif
@@ -92,6 +96,9 @@
void Print(const char * fmt, ...);
void Print(int in_y, int in_x, const char * fmt, ...);
void PrintBinary(int in_y, int in_x, unsigned int value);
+ void PrintDouble(int in_y, int in_x, double value);
+ void PrintOption(int in_y, int in_x, const cString & option);
+ int PrintMenuBarOption(const cString & option, int max_x, int cur_x);
// ------ Drawing & Erasing ------
Modified: development/source/viewer-core/cCoreView_Info.cc
===================================================================
--- development/source/viewer-core/cCoreView_Info.cc 2007-07-07 15:47:31 UTC (rev 1761)
+++ development/source/viewer-core/cCoreView_Info.cc 2007-07-08 18:15:17 UTC (rev 1762)
@@ -7,7 +7,6 @@
, m_pause_level(PAUSE_OFF)
, m_step_organism_id(-1)
, m_step_organism_thread(-1)
- , fp("debug.dat")
{
// Redirect standard output...
std::cout.rdbuf(m_cout_stream.rdbuf());
Modified: development/source/viewer-core/cCoreView_Info.h
===================================================================
--- development/source/viewer-core/cCoreView_Info.h 2007-07-07 15:47:31 UTC (rev 1761)
+++ development/source/viewer-core/cCoreView_Info.h 2007-07-08 18:15:17 UTC (rev 1762)
@@ -45,7 +45,6 @@
public:
// Constant Information across all viewers.
enum ePause { PAUSE_ON, PAUSE_OFF, PAUSE_ADVANCE_INST, PAUSE_ADVANCE_UPDATE, PAUSE_ADVANCE_DIVIDE };
- ofstream fp; // DEBUG!!!!
public:
cCoreView_Info(cPopulation & in_pop, int in_total_colors);
More information about the Avida-cvs
mailing list