[Aptitude-svn-commit] r3347 - in branches/aptitude-0.3/aptitude: . src src/mine

Daniel Burrows dburrows@costa.debian.org
Tue, 07 Jun 2005 03:35:04 +0000


Author: dburrows
Date: Tue Jun  7 03:35:01 2005
New Revision: 3347

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/desc_parse.cc
   branches/aptitude-0.3/aptitude/src/mine/cmine.cc
   branches/aptitude-0.3/aptitude/src/mine/cmine.h
Log:
Fix Minesweeper for the new display system.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Tue Jun  7 03:35:01 2005
@@ -1,5 +1,9 @@
 2005-06-06  Daniel Burrows  <dburrows@debian.org>
 
+	* src/mine/cmine.cc, src/mine/cmine.h:
+
+	Fix the minesweeper game for the new display system.
+
 	* src/cmdline/cmdline_prompt.cc, src/cmdline/cmdline_resolver.cc, src/cmdline/cmdline_show.cc:
 
 	Adjust the command-line code to work properly with the new

Modified: branches/aptitude-0.3/aptitude/src/desc_parse.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/desc_parse.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/desc_parse.cc	Tue Jun  7 03:35:01 2005
@@ -114,8 +114,8 @@
 							    nspaces2+2,
 							    start);
 
-		fragments.push_back(text_fragment(bullet,
-						  get_color("Bullet")));
+		fragments.push_back(style_fragment(text_fragment(bullet),
+						   get_style("Bullet")));
 		fragments.push_back(indentbox(1,
 					      (level+1)*2,
 					      item_contents));

Modified: branches/aptitude-0.3/aptitude/src/mine/cmine.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/mine/cmine.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/mine/cmine.cc	Tue Jun  7 03:35:01 2005
@@ -76,7 +76,7 @@
   vscreen_update();
 };
 
-void cmine::paint_header()
+void cmine::paint_header(const style &st)
   // Shows the header with its extra info
 {
   if(board)
@@ -113,10 +113,10 @@
 	  header+=buf[loc++];
 	}
 
-      display_header(header.c_str(), get_color("ScreenHeaderColor"));
+      display_header(header.c_str(), (st+get_style("Header")).get_attrs());
     }
   else
-    display_header(_("Minesweeper"), get_color("ScreenHeaderColor"));
+    display_header(_("Minesweeper"), (st+get_style("Header")).get_attrs());
 }
 
 void cmine::do_load_game(string s)
@@ -130,7 +130,7 @@
 
 	  snprintf(buf, 512, _("Could not open file \"%s\""), s.c_str());
 
-	  popup_widget(vs_dialog_ok(buf, NULL, get_color("Error")));
+	  popup_widget(vs_dialog_ok(buf, NULL, get_style("Error")));
 	}
       else
 	{
@@ -144,7 +144,7 @@
 
 	      snprintf(buf, 512, _("Could not load game from %s"), s.c_str());
 
-	      popup_widget(vs_dialog_ok(buf, NULL, get_color("Error")));
+	      popup_widget(vs_dialog_ok(buf, NULL, get_style("Error")));
 	      delete brd;
 	    }
 	  else
@@ -167,7 +167,7 @@
 
 	  snprintf(buf, 512, _("Could not open file \"%s\""), s.c_str());
 
-	  popup_widget(vs_dialog_ok(buf, NULL, get_color("Error")));
+	  popup_widget(vs_dialog_ok(buf, NULL, get_style("Error")));
 	}
       else
 	{
@@ -194,7 +194,7 @@
       // lynch me ;-)
       popup_widget(vs_dialog_ok(_("The board height must be a number"),
 				NULL,
-				get_color("Error")));
+				get_style("Error")));
       return;
     }
 
@@ -206,7 +206,7 @@
     {
       popup_widget(vs_dialog_ok(_("The board width must be a number"),
 				NULL,
-				get_color("Error")));
+				get_style("Error")));
       return;
     }
 
@@ -219,7 +219,7 @@
       // awkward wording
       popup_widget(vs_dialog_ok(_("The number of mines must be a number"),
 				NULL,
-				get_color("Error")));
+				get_style("Error")));
       return;
     }
 
@@ -230,32 +230,24 @@
 
 void cmine::do_custom_game()
 {
-  int attr=get_color("DefaultWidgetBackground")|A_REVERSE;
-
   vs_center *center=new vs_center;
+  center->set_bg_style(style_attrs_flip(A_REVERSE));
 
   vs_table *table=new vs_table;
-  table->set_bg(attr);
 
-  vs_label *overalllabel=new vs_label(_("Setup custom game"),
-				      attr);
+  vs_label *overalllabel=new vs_label(_("Setup custom game"));
 
-  vs_label *heightlabel=new vs_label(_("Height of board: "),
-				     attr);
+  vs_label *heightlabel=new vs_label(_("Height of board: "));
   vs_editline *heightedit=new vs_editline("");
 
-  vs_label *widthlabel=new vs_label(_("Width of board: "),
-				    attr);
+  vs_label *widthlabel=new vs_label(_("Width of board: "));
   vs_editline *widthedit=new vs_editline("");
 
-  vs_label *mineslabel=new vs_label(_("Number of mines: "),
-				    attr);
+  vs_label *mineslabel=new vs_label(_("Number of mines: "));
   vs_editline *minesedit=new vs_editline("");
 
   vs_button *okbutton=new vs_button(_("Ok"));
-  okbutton->set_bg(attr);
   vs_button *cancelbutton=new vs_button(_("Cancel"));
-  cancelbutton->set_bg(attr);
 
   table->connect_key("Confirm", &global_bindings, okbutton->pressed.make_slot());
 
@@ -298,7 +290,6 @@
   cno->show();
 
   vs_frame *frame=new vs_frame(table);
-  frame->set_bg(attr);
   center->add_widget(frame);
 
   popup_widget(center);
@@ -306,29 +297,20 @@
 
 void cmine::do_new_game()
 {
-  int attr=get_color("DefaultWidgetBackground")|A_REVERSE;
-
   vs_center *center=new vs_center;
+  center->set_bg_style(style_attrs_flip(A_REVERSE));
 
   vs_table *table=new vs_table;
-  table->set_bg(attr);
 
-  vs_label *overalllabel=new vs_label(_("Choose difficulty level"), attr);
+  vs_label *overalllabel=new vs_label(_("Choose difficulty level"));
 
   vs_radiobutton *easybutton=new vs_radiobutton(_("Easy"), true);
   vs_radiobutton *mediumbutton=new vs_radiobutton(_("Medium"), false);
   vs_radiobutton *hardbutton=new vs_radiobutton(_("Hard"), false);
   vs_radiobutton *custombutton=new vs_radiobutton(_("Custom"), false);
 
-  easybutton->set_bg(attr);
-  mediumbutton->set_bg(attr);
-  hardbutton->set_bg(attr);
-  custombutton->set_bg(attr);
-
   vs_button *okbutton=new vs_button(_("Ok"));
-  okbutton->set_bg(attr);
   vs_button *cancelbutton=new vs_button(_("Cancel"));
-  cancelbutton->set_bg(attr);
 
   table->connect_key("Confirm", &global_bindings, okbutton->pressed.make_slot());
 
@@ -359,7 +341,6 @@
   table->add_widget(ccancel,      6, 1, 1, 1, false, false);
 
   vs_frame *frame=new vs_frame(table);
-  frame->set_bg(attr);
   center->add_widget(frame);
 
   popup_widget(center);
@@ -387,7 +368,7 @@
       default:
 	popup_widget(vs_dialog_ok("Internal error: execution reached an impossible point",
 				  NULL,
-				  get_color("Error")));
+				  get_style("Error")));
 	break;
       }
 
@@ -634,7 +615,7 @@
   return true;
 }
 
-void cmine::paint_square(int x, int y)
+void cmine::paint_square(int x, int y, const style &st)
   // Displays a single square.
 {
   int width,height;
@@ -648,6 +629,7 @@
   if(screenx>=0 && screenx<width && screeny>=0 && screeny<height-1)
     {
       chtype ch;
+      style cur_st;
       const mine_board::board_entry &entry=board->get_square(x, y);
       // We want to handle the case of 'game-over' differently from
       // the case of 'still playing' -- when the game is over, all
@@ -657,16 +639,25 @@
 	  if(!entry.uncovered)
 	    {
 	      if(entry.flagged)
-		ch='F'|get_color("MineFlagColor");
+		{
+		  ch='F';
+		  cur_st=get_style("MineFlag");
+		}
 	      else
-		ch=' '|get_color("DefaultWidgetBackground");
+		{
+		  ch=' ';
+		  cur_st=get_style("DefaultWidgetBackground");
+		}
 	    }
 	  else if(entry.contains_mine)
-	    ch='^'|get_color("MineBombColor");
+	    {
+	      ch='^';
+	      cur_st=get_style("MineBombColor");
+	    }
 	  else if(entry.adjacent_mines==0)
-	    ch='.'|get_color("DefaultWidgetBackground");
+	    ch='.';
 	  else
-	    ch=('0'+entry.adjacent_mines)|get_color("DefaultWidgetBackground");
+	    ch=('0'+entry.adjacent_mines);
 	}
       else
 	{
@@ -674,27 +665,33 @@
 	    {
 	      if(board->get_state()==mine_board::lost &&
 		 x==board->get_minex() && y==board->get_miney())
-		ch='*'|get_color("MineDetonatedColor");
+		{
+		  ch='*';
+		  cur_st=get_style("MineDetonated");
+		}
 	      else
-		ch='^'|get_color("MineBombColor");
+		{
+		  ch='^';
+		  cur_st=get_style("MineBomb");
+		}
 	    }
 	  else if(entry.uncovered)
 	    {
 	      if(entry.adjacent_mines==0)
-		ch='.'|get_color("DefaultWidgetBackground");
+		ch='.';
 	      else
-		ch=('0'+entry.adjacent_mines)|get_color("DefaultWidgetBackground");
+		ch=('0'+entry.adjacent_mines);
 	    }
 	  else
-	    ch=' '|get_color("DefaultWidgetBackground");
+	    ch=' ';
 	}
       if(board->get_state()==mine_board::playing && x==curx && y==cury)
-	ch|=A_REVERSE;
+	cur_st+=style_attrs_flip(A_REVERSE);
       mvaddch(screeny, screenx, ch);
     }
 }
 
-void cmine::paint()
+void cmine::paint(const style &st)
 {
   if(get_win())
     {
@@ -718,12 +715,10 @@
 	  basey=(height-board->get_height()-4)/2;
 	}
 
-      paint_header();
+      paint_header(st);
 
       if(board)
 	{
-	  attrset(get_color("DefaultWidgetBackground"));
-
 	  int right=basex+board->get_width()+1, down=basey+1+board->get_height()+1;
 	  // x and y coordinates, respectively, of the right and lower board
 	  // edges.
@@ -806,7 +801,7 @@
 	  // Now the squares:
 	  for(int y=miny; y<maxy; y++)
 	    for(int x=minx; x<maxx; x++)
-	      paint_square(x, y);
+	      paint_square(x, y, st);
 	}
     }
 }
@@ -815,9 +810,9 @@
 {
   srand(time(0));
 
-  set_color("MineFlagColor", COLOR_RED, COLOR_BLACK, A_BOLD);
-  set_color("MineBombColor", COLOR_RED, COLOR_BLACK, A_BOLD);
-  set_color("MineDetonatedColor", COLOR_CYAN, COLOR_BLACK, 0);
+  set_style("MineFlag", style_fg(COLOR_RED)+style_attrs_on(A_BOLD));
+  set_style("MineBomb", style_fg(COLOR_RED)+style_attrs_on(A_BOLD));
+  set_style("MineDetonated", style_fg(COLOR_CYAN));
 
   global_bindings.set("MineUncoverSweepSquare", KEY_ENTER);
   global_bindings.set("MineFlagSquare", 'f');

Modified: branches/aptitude-0.3/aptitude/src/mine/cmine.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/mine/cmine.h	(original)
+++ branches/aptitude-0.3/aptitude/src/mine/cmine.h	Tue Jun  7 03:35:01 2005
@@ -47,7 +47,7 @@
   // Deletes the old board, and replaces it with the new one.  cur[xy] and
   // base[xy] are set so that the board appears in the center of the screen,
   // with the cursor approxiomately in its center.
-  void paint_square(int x, int y);
+  void paint_square(int x, int y, const style &st);
 
   void checkend();
   // Checks whether the game is over, prints cute message if so.
@@ -67,11 +67,11 @@
 			    vs_editline *widthedit,
 			    vs_editline *minesedit);
 protected:
-  void paint_header();
+  void paint_header(const style &st);
 public:
   cmine();
   bool handle_char(chtype ch);
-  void paint();
+  void paint(const style &st);
   ~cmine()
   {
     delete board;