[Avida-SVN] r1093 - development/source/targets/avida-viewer

ofria at myxo.css.msu.edu ofria at myxo.css.msu.edu
Tue Nov 21 07:18:17 PST 2006


Author: ofria
Date: 2006-11-21 10:18:16 -0500 (Tue, 21 Nov 2006)
New Revision: 1093

Modified:
   development/source/targets/avida-viewer/cBarScreen.cc
   development/source/targets/avida-viewer/cBarScreen.h
Log:
In the ncurses viewer, show as many options in the bar along the top of the
screen as will fit, based on the width of the window.  Currently, [E]nv is
always up there, but I want the environment screen to be a regular screen,
not available only when resources are limited.



Modified: development/source/targets/avida-viewer/cBarScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cBarScreen.cc	2006-11-21 03:08:34 UTC (rev 1092)
+++ development/source/targets/avida-viewer/cBarScreen.cc	2006-11-21 15:18:16 UTC (rev 1093)
@@ -13,6 +13,18 @@
 
 using namespace std;
 
+int cBarScreen::AddMenuOption(const cString option, int max_x, int cur_x)
+{
+  if (cur_x + option.GetSize() + 2 >= max_x) return cur_x;
+
+  SetBoldColor(COLOR_WHITE);
+  Print(1, cur_x, option);
+  SetBoldColor(COLOR_CYAN);
+  Print(1, cur_x+1, option[1]);  
+
+  return cur_x+option.GetSize()+2;
+}
+
 void cBarScreen::Draw()
 {
   SetBoldColor(COLOR_WHITE);
@@ -27,30 +39,22 @@
 
   Print(1, 2, "Update:");
 
-  if(info.GetPopulation().GetEnvironment().GetResourceLib().GetSize() > 0)
-    Print(1, 20, "[M]ap [S]tats [O]ptions [Z]oom [E]nviron [Q]uit");
-  else
-    Print(1, 20, "[M]ap  [S]tats  [O]ptions  [Z]oom  [Q]uit");
+  const int max_x = Width() - offset - 10;
+  int cur_x = 21;
 
-  SetBoldColor(COLOR_CYAN);
+  // Include options in their general order of importance.
+  cur_x = AddMenuOption("[M]ap", max_x, cur_x);
+  cur_x = AddMenuOption("[S]tats", max_x, cur_x);
+  cur_x = AddMenuOption("[O]ptions", max_x, cur_x);
+  cur_x = AddMenuOption("[Z]oom", max_x, cur_x);
+  cur_x = AddMenuOption("[E]nv", max_x, cur_x);
+  cur_x = AddMenuOption("[H]ist", max_x, cur_x);
+  cur_x = AddMenuOption("[B]lank", max_x, cur_x);
+  cur_x = AddMenuOption("[P]ause", max_x, cur_x);
+  cur_x = AddMenuOption("[C]hoose CPU", max_x, cur_x);
 
-  if(info.GetPopulation().GetEnvironment().GetResourceLib().GetSize() > 0)
-    {
-      Print(1, 21, 'M');
-      Print(1, 27, 'S');
-      Print(1, 35, 'O');
-      Print(1, 45, 'Z');
-      Print(1, 52, 'E');
-      Print(1, 62, 'Q');
-    }
-  else
-    {
-      Print(1, 21, 'M');
-      Print(1, 28, 'S');
-      Print(1, 37, 'O');
-      Print(1, 48, 'Z');
-      Print(1, 56, 'Q');
-    }
+  // Always place Quit as the last option.
+  cur_x = AddMenuOption("[Q]uit", max_x+8, cur_x);
 
   Refresh();
 }

Modified: development/source/targets/avida-viewer/cBarScreen.h
===================================================================
--- development/source/targets/avida-viewer/cBarScreen.h	2006-11-21 03:08:34 UTC (rev 1092)
+++ development/source/targets/avida-viewer/cBarScreen.h	2006-11-21 15:18:16 UTC (rev 1093)
@@ -19,6 +19,8 @@
 protected:
   cWorld* m_world;
   cString prog_name;
+
+  int AddMenuOption(const cString option, int max_x, int cur_x);
 public:
   cBarScreen(cWorld* world, int y_size, int x_size, int y_start, int x_start, cViewInfo & in_info, const cString & in_name)
     : cScreen(y_size, x_size, y_start, x_start, in_info), m_world(world), prog_name(in_name) { ; }




More information about the Avida-cvs mailing list