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

ofria at myxo.css.msu.edu ofria at myxo.css.msu.edu
Wed Nov 22 12:56:59 PST 2006


Author: ofria
Date: 2006-11-22 15:56:59 -0500 (Wed, 22 Nov 2006)
New Revision: 1097

Modified:
   development/source/targets/avida-viewer/cBarScreen.cc
   development/source/targets/avida-viewer/cMenuWindow.cc
   development/source/targets/avida-viewer/cMenuWindow.h
   development/source/targets/avida-viewer/cOptionsScreen.cc
   development/source/targets/avida-viewer/cStatsScreen.cc
   development/source/targets/avida-viewer/cView.cc
   development/source/targets/avida-viewer/cZoomScreen.cc
Log:
More cleanup on ncurses viewer.

Genetic surgery is now possible in Zoom mode (if you hit enter on an
insturction, it will give you options about what you want to do with that
line).


Modified: development/source/targets/avida-viewer/cBarScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cBarScreen.cc	2006-11-22 08:13:07 UTC (rev 1096)
+++ development/source/targets/avida-viewer/cBarScreen.cc	2006-11-22 20:56:59 UTC (rev 1097)
@@ -42,7 +42,7 @@
   // 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("[A]nalyze", max_x, cur_x);
+  // cur_x = AddMenuOption("[A]nalyze", max_x, cur_x);
   cur_x = AddMenuOption("[Z]oom", max_x, cur_x);
   cur_x = AddMenuOption("[O]ptions", max_x, cur_x);
   cur_x = AddMenuOption("[H]ist", max_x, cur_x);

Modified: development/source/targets/avida-viewer/cMenuWindow.cc
===================================================================
--- development/source/targets/avida-viewer/cMenuWindow.cc	2006-11-22 08:13:07 UTC (rev 1096)
+++ development/source/targets/avida-viewer/cMenuWindow.cc	2006-11-22 20:56:59 UTC (rev 1097)
@@ -11,10 +11,11 @@
 
 
 cMenuWindow::cMenuWindow(int menu_size)
+  : option_array(menu_size)
+  , key_array(menu_size)
+
 {
   window = NULL;
-  option_list = new cString[menu_size];
-  key_list = new char[menu_size];
   num_options = menu_size;
   active_id = 0;
 }
@@ -22,59 +23,72 @@
 cMenuWindow::~cMenuWindow()
 {
   if (window) delete window;
-  delete [] option_list;
-  delete [] key_list;
 }
 
-void cMenuWindow::AddOption(int option_id, const char * in_option)
+void cMenuWindow::AddOption(int option_id, const cString & in_option)
 {
-  option_list[option_id] = in_option;
+  assert(option_id >= 0 && option_id < option_array.GetSize());
+  option_array[option_id] = in_option;
   int hot_pos = FindHotkeyPos(in_option);
-  key_list[option_id] = (hot_pos == -1)  ?  -1 : in_option[hot_pos];
+  key_array[option_id] = (hot_pos == -1)  ?  -1 : in_option[hot_pos];
 }
 
-int cMenuWindow::Activate()
+int cMenuWindow::Activate(cTextWindow * parent_window)
 {
-  int i;
-
   // Calculate number of columns needed and the width of each
-
-  max_width = 0;
-  for (i = 0; i < num_options; i++) {
-    if (max_width < option_list[i].GetSize())
-      max_width = option_list[i].GetSize();
+  max_entry = 0;
+  for (int i = 0; i < num_options; i++) {
+    if (max_entry < option_array[i].GetSize())
+      max_entry = option_array[i].GetSize();
   }
 
-  // @CAO should make these more flexible.
-  int max_lines = title.IsEmpty() ? 20 : 18;
-  // int max_cols = 80 / (max_width + 3);
+  const int max_height = parent_window->Height() - 4;
+  const int max_width = parent_window->Width() - 4;
+  const int min_width = title.GetSize() + 2;
 
   // The minimum number of columns available is determined by the title.
-  int min_cols = (title.GetSize() + 2) / (max_width + 2) ;
+  const int max_rows = max_height - (title.IsEmpty() ? 0 : 2);
+  const int min_cols = min_width / (max_entry + 2);
+  const int max_cols = max_width / (max_entry + 2);
 
-  cols = num_options / max_lines + 1;
-  if (cols < min_cols) cols = min_cols;
-  lines = num_options / cols;
-  if (lines * cols < num_options) lines++;  // In case of roundoff error.
+  // The number of columns should be adjusted by the number of items, and then
+  // forced back into range.
+  num_cols = 1;
+  if (num_options > 80) num_cols = 5;
+  else if (num_options > 45) num_cols = 4;
+  else if (num_options > 20) num_cols = 3;
+  else if (num_options > 6) num_cols = 2;
+  
+  // Now force the number of columns back into range.
+  if (num_cols < min_cols) num_cols = min_cols;
+  if (num_cols > max_cols) num_cols = max_cols;
 
+  // Next, figure out how many rows we need for this to work.
+  num_rows = 1 + (num_options-1) / num_cols;
+
+  // @CAO We need to identify if we have a problem fitting everything!)
+  if (num_rows > max_rows) ;
+
   // Determine dimenstions for window
-  int win_height = lines + 4;
-  int win_width = (max_width + 2) * cols + 2;
+  int win_height = num_rows + 4;
+  int win_width = (max_entry + 2) * num_cols + 2;
 
   // Adjust the dimensions to make sure the title will fit.
   if (!title.IsEmpty()) win_height += 2;
   if (win_width < title.GetSize() + 4) win_width = title.GetSize() + 4;
 
   // Create and draw the window.
-  window = new cTextWindow(win_height, win_width,
-			   (23 - win_height) / 2, (80 - win_width) / 2);
+  const int win_x = (parent_window->Width() - win_width) / 2;
+  const int win_y = (parent_window->Height() - win_height) / 2;
+  window = new cTextWindow(win_height, win_width, win_y, win_x);
+
   window->Box();
   if (!title.IsEmpty()) {
     window->SetBoldColor(COLOR_WHITE);
-//    window->Print (2, 2, title());
+    window->Print(2, 2, title);
   }
 
-  for (i = 0; i < num_options; i++) {
+  for (int i = 0; i < num_options; i++) {
     DrawOption(i);
   }
   DrawOption(active_id, true);
@@ -89,8 +103,8 @@
 
     // First see if we have hit a hotkey for an option.
 
-    for (i = 0; i < num_options; i++) {
-      const char test_char = key_list[i];
+    for (int i = 0; i < num_options; i++) {
+      const char test_char = key_array[i];
       if (test_char != -1 &&
 	  (test_char == cur_char || test_char - 'A' + 'a' == cur_char)) {
 	active_id = i;
@@ -104,6 +118,7 @@
     switch (cur_char) {
     case 'q':
     case 'Q':
+    case 27: // ESCAPE
       // Abort!
       finished = true;
       active_id = -1;
@@ -121,10 +136,10 @@
       MoveActiveID(active_id + 1);
       break;
     case KEY_LEFT:
-      MoveActiveID(active_id - lines);
+      MoveActiveID(active_id - num_rows);
       break;
     case KEY_RIGHT:
-      MoveActiveID(active_id + lines);
+      MoveActiveID(active_id + num_rows);
       break;
     case KEY_HOME:
       MoveActiveID(0);
@@ -146,21 +161,21 @@
 
 void cMenuWindow::DrawOption(int option_id, bool is_active)
 {
-  if (is_active) window->SetBoldColor(COLOR_CYAN);
+  if (is_active) window->SetBoldColor(COLOR_YELLOW);
   else window->SetColor(COLOR_CYAN);
 
-  int line_id = option_id % lines;
-  int col_id  = option_id / lines;
-  int x_pos = col_id * (max_width + 2) + 2;
+  int line_id = option_id % num_rows;
+  int col_id  = option_id / num_rows;
+  int x_pos = col_id * (max_entry + 2) + 2;
   int y_pos = line_id + ((title.IsEmpty()) ? 2 : 4);
-  window->Print(y_pos, x_pos, static_cast<const char*>(option_list[option_id]));
+  window->Print(y_pos, x_pos, static_cast<const char*>(option_array[option_id]));
 
-  int hot_pos = FindHotkeyPos(option_list[option_id]);
+  int hot_pos = FindHotkeyPos(option_array[option_id]);
   if (hot_pos != -1) {
     window->SetBoldColor(COLOR_WHITE);
-    window->Print(y_pos, x_pos + hot_pos, option_list[option_id][hot_pos]);
+    window->Print(y_pos, x_pos + hot_pos, option_array[option_id][hot_pos]);
   }
-  window->Move(y_pos, x_pos + option_list[option_id].GetSize());
+  window->Move(y_pos, x_pos + option_array[option_id].GetSize());
 }
 
 void cMenuWindow::MoveActiveID(int new_id)

Modified: development/source/targets/avida-viewer/cMenuWindow.h
===================================================================
--- development/source/targets/avida-viewer/cMenuWindow.h	2006-11-22 08:13:07 UTC (rev 1096)
+++ development/source/targets/avida-viewer/cMenuWindow.h	2006-11-22 20:56:59 UTC (rev 1097)
@@ -8,6 +8,10 @@
 #ifndef cMenuWindow_h
 #define cMenuWindow_h
 
+#ifndef tArray_h
+#include "tArray.h"
+#endif
+
 #ifndef cString_h
 #include "cString.h"
 #endif
@@ -19,15 +23,15 @@
 private:
   cTextWindow * window;
   cString title;
-  cString * option_list;
-  char * key_list;
+  tArray<cString> option_array;
+  cString key_array;
   int num_options;
 
   // menu status variables
-  int active_id;
-  int max_width;
-  int lines;
-  int cols;
+  int active_id; // Currently active option.
+  int num_rows;  // Number of rows of options.
+  int num_cols;  // Number of columns of options.
+  int max_entry; // Maximum width of any entry.
 
   // Private helper functions
   void DrawOption(int option_id, bool is_active=false);
@@ -38,8 +42,8 @@
   ~cMenuWindow();
 
   void SetTitle(const char * in_title) { title = in_title; }
-  void AddOption(int option_id, const char * in_option);
-  int Activate();
+  void AddOption(int option_id, const cString & in_option);
+  int Activate(cTextWindow * parent_window);
 
   inline void SetActive(int in_id) { active_id = in_id; }
 };

Modified: development/source/targets/avida-viewer/cOptionsScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cOptionsScreen.cc	2006-11-22 08:13:07 UTC (rev 1096)
+++ development/source/targets/avida-viewer/cOptionsScreen.cc	2006-11-22 20:56:59 UTC (rev 1097)
@@ -124,11 +124,11 @@
 
   Print(5, 55, "%d", info.GetConfig().AVE_TIME_SLICE.Get());
 
-  Print(7, 52, "%.3f", info.GetConfig().POINT_MUT_PROB.Get());
-  Print(8, 52, "%.3f", info.GetConfig().COPY_MUT_PROB.Get());
-  Print(9, 52, "%.3f", info.GetConfig().DIVIDE_MUT_PROB.Get());
-  Print(10, 52, "%.3f", info.GetConfig().DIVIDE_INS_PROB.Get());
-  Print(11, 52, "%.3f", info.GetConfig().DIVIDE_DEL_PROB.Get());
+  PrintDouble(7, 52, info.GetConfig().POINT_MUT_PROB.Get());
+  PrintDouble(8, 52, info.GetConfig().COPY_MUT_PROB.Get());
+  PrintDouble(9, 52, info.GetConfig().DIVIDE_MUT_PROB.Get());
+  PrintDouble(10, 52, info.GetConfig().DIVIDE_INS_PROB.Get());
+  PrintDouble(11, 52, info.GetConfig().DIVIDE_DEL_PROB.Get());
 
   SetColor(COLOR_WHITE);
 

Modified: development/source/targets/avida-viewer/cStatsScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cStatsScreen.cc	2006-11-22 08:13:07 UTC (rev 1096)
+++ development/source/targets/avida-viewer/cStatsScreen.cc	2006-11-22 20:56:59 UTC (rev 1097)
@@ -46,9 +46,9 @@
   Print(2, 50, "Fitness..:");
   Print(3, 50, "Merit....:");
   Print(4, 50, "Gestation:");
-  Print(5, 50, "Size.....:");
-  Print(6, 50, "Copy Size:");
-  Print(7, 50, "Exec Size:");
+  Print(5, 50, "Length...:");
+  Print(6, 50, "Copy Len.:");
+  Print(7, 50, "Exec Len.:");
   Print(8, 50, "Abundance:");
   Print(9, 50, "Births...:");
   Print(10, 50, "BirthRate:");

Modified: development/source/targets/avida-viewer/cView.cc
===================================================================
--- development/source/targets/avida-viewer/cView.cc	2006-11-22 08:13:07 UTC (rev 1096)
+++ development/source/targets/avida-viewer/cView.cc	2006-11-22 20:56:59 UTC (rev 1097)
@@ -259,7 +259,7 @@
 	  menu.AddOption(j, message);
 	}
 	menu.SetActive(3);
-	menu.Activate();
+	menu.Activate(base_window);
 	Redraw();
       }
       break;

Modified: development/source/targets/avida-viewer/cZoomScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cZoomScreen.cc	2006-11-22 08:13:07 UTC (rev 1096)
+++ development/source/targets/avida-viewer/cZoomScreen.cc	2006-11-22 20:56:59 UTC (rev 1097)
@@ -208,19 +208,19 @@
   Print(OPTIONS_Y, OPTIONS_X+4,    "Component Zoom");
   SetBoldColor(COLOR_WHITE);
   
-  PrintOption(OPTIONS_Y+6, OPTIONS_X+2, "[E]dit Component");
-  PrintOption(OPTIONS_Y+7, OPTIONS_X+2, "[V]iew Component");
-  if(info.GetConfig().MAX_CPU_THREADS.Get() >1)
-    PrintOption(OPTIONS_Y+8, OPTIONS_X+2, "Next [T]hread");
-  PrintOption(OPTIONS_Y+9, OPTIONS_X+2, "[TAB] Shift Active");
-  
   if (info.GetPauseLevel()) {
-    PrintOption(OPTIONS_Y+10, OPTIONS_X+2, "[Arrows] Scroll");
+    PrintOption(OPTIONS_Y+5, OPTIONS_X+2, "[Arrows] Scroll");
   } else {
-    Print(OPTIONS_Y+10, OPTIONS_X+2, "               ");
+    Print(OPTIONS_Y+5, OPTIONS_X+2, "               ");
   }
+  PrintOption(OPTIONS_Y+6, OPTIONS_X+2, "[Enter] View/Edit");
+  PrintOption(OPTIONS_Y+7, OPTIONS_X+2, "[TAB] Shift Active");
   
+  if(info.GetConfig().MAX_CPU_THREADS.Get() >1) {
+    PrintOption(OPTIONS_Y+8, OPTIONS_X+2, "Next [T]hread");
+  }
   
+  
   // Highlight the active section...
   SetActiveSection(active_section);
   
@@ -1018,7 +1018,7 @@
   menu1.AddOption(INST_EDIT_INSERT,     "[I]nsert Instruction");
   menu1.AddOption(INST_EDIT_REMOVE,     "[D]elete Instruction");
   menu1.SetActive(INST_EDIT_CHANGE);
-  int edit_method = menu1.Activate();
+  int edit_method = menu1.Activate(this);
   cView::Redraw();
   
   // If we need to choose a new instruction, bring up a window for it.
@@ -1031,7 +1031,7 @@
       inst_menu.AddOption(j, static_cast<const char*>(inst_set.GetName(j)));
     }
     inst_menu.SetActive(edit_head.GetInst().GetOp());
-    new_inst = inst_menu.Activate();
+    new_inst = inst_menu.Activate(this);
     
     cView::Redraw();
     if (new_inst == -1) {
@@ -1069,21 +1069,6 @@
   Update();
 }
 
-void cZoomScreen::ViewMemory()
-{
-  // Collect all of the needed variables.
-  cHardwareBase& hardware = info.GetActiveCell()->GetOrganism()->GetHardware();
-  cHeadCPU view_head(hardware.IP());
-  if (parasite_zoom == true) view_head.Set(0);
-  view_head.LoopJump(memory_offset);
-  
-  // Act on the view method!
-  if (inst_view_mode == true) inst_view_mode = false;
-  else inst_view_mode = true;
-  
-  Update();
-}
-
 void cZoomScreen::ThreadOptions()
 {
   int thread_method = THREAD_OPTIONS_VIEW;
@@ -1094,7 +1079,7 @@
   menu1.AddOption(THREAD_OPTIONS_VIEW, "[V]iew Thread Info");
   menu1.AddOption(THREAD_OPTIONS_LOCK, "[T]oggle Thread Lock");
   menu1.SetActive(THREAD_OPTIONS_VIEW);
-  thread_method = menu1.Activate();
+  thread_method = menu1.Activate(this);
   cView::Redraw();
   
   // Act on the view method!
@@ -1593,10 +1578,25 @@
       break;
     case '\n':
     case '\r':
-      if (active_section == ZOOM_SECTION_MAP) {
+      switch (active_section) {
+      case ZOOM_SECTION_MEMORY:
+	EditMemory();
+	break;
+      case ZOOM_SECTION_MAP:
         memory_offset = 0;
         info.SetActiveCell(&(population.GetCell(mini_center_id)));
+	break;
+      case ZOOM_SECTION_REGISTERS:
+	ViewRegisters();
+	break;
+      case ZOOM_SECTION_STACK:
+	ViewStack();
+	break;
+      case ZOOM_SECTION_INPUTS:
+	ViewInputs();
+	break;
       }
+      
       Update();
       break;
     case '\t':
@@ -1608,32 +1608,7 @@
       Refresh();
       break;
       
-    case 'e':
-    case 'E':
-      if( active_section == ZOOM_SECTION_MEMORY) {
-        EditMemory();
-      }
-      break;
-      
-    case 'v':
-    case 'V':
-      switch (active_section) {
-        case ZOOM_SECTION_MEMORY:
-          ViewMemory();
-          break;
-        case ZOOM_SECTION_REGISTERS:
-          ViewRegisters();
-          break;
-        case ZOOM_SECTION_STACK:
-          ViewStack();
-          break;
-        case ZOOM_SECTION_INPUTS:
-          ViewInputs();
-          break;
-      }
-      break;
-      
-      
+        
     default:
       return false;
   };




More information about the Avida-cvs mailing list