ScoreWindow Class Reference

#include <ScoreWindow.h>

Collaboration diagram for ScoreWindow:

Collaboration graph
[legend]

Public Member Functions

 ScoreWindow (const int default_width=-1, const int default_height=-1, const int default_x_pos=-1, const int default_y_pos=-1)
 ~ScoreWindow ()
void set_window_title ()
void add_robots ()
void update_robots ()
GtkWidgetget_window_p ()
GtkWidgetget_clist ()
Robotget_selected_robot ()
bool is_window_shown ()
void set_selected_robot (Robot *rp)
void set_window_shown (bool r)

Static Public Member Functions

gboolean hide_window (GtkWidget *widget, GdkEvent *event, class ScoreWindow *scorewindow_p)
void show_window (GtkWidget *widget, class ScoreWindow *scorewindow_p)
void new_robot_selected (GtkWidget *clist, gint row, gint column, GdkEventButton *event, class ScoreWindow *scorewindow_p)

Private Attributes

bool window_shown
GtkWidgetwindow_p
GtkWidgetclist
Robotselected_robot

Constructor & Destructor Documentation

ScoreWindow::ScoreWindow const int  default_width = -1,
const int  default_height = -1,
const int  default_x_pos = -1,
const int  default_y_pos = -1
 

Definition at line 34 of file ScoreWindow.cc.

References _, clist, controlwindow_p, Gui::get_bg_gdk_colour_p(), Gui::get_fg_gdk_colour_p(), gpointer, GtkWidget, hide_window(), ControlWindow::is_scorewindow_checked(), make_gdk_colour(), new_robot_selected(), selected_robot, set_window_title(), the_gui, window_p, and window_shown.

00038 {
00039   window_p = gtk_window_new( GTK_WINDOW_TOPLEVEL );
00040   gtk_widget_set_name( window_p, "RTB Score" );
00041 
00042   set_window_title();
00043 
00044   gtk_container_border_width( GTK_CONTAINER( window_p ), 12 );
00045 
00046   if( default_width != -1 && default_height != -1 )
00047     {
00048       gtk_window_set_default_size( GTK_WINDOW( window_p ),
00049                                    default_width, default_height );
00050       gtk_widget_set_usize( window_p , 175, 80 );
00051     }
00052   if( default_x_pos != -1 && default_y_pos != -1 )
00053     gtk_widget_set_uposition( window_p, default_x_pos, default_y_pos );
00054 
00055   gtk_signal_connect( GTK_OBJECT( window_p ), "delete_event",
00056                       (GtkSignalFunc) ScoreWindow::hide_window,
00057                       (gpointer) this );
00058 
00059   GtkObject* hadj = gtk_adjustment_new ( 0.0, 0.0, 100.0, 1.0, 1.0, 1.0 );
00060   GtkObject* vadj = gtk_adjustment_new ( 0.0, 0.0, 100.0, 1.0, 1.0, 1.0 );
00061   GtkWidget* scrolled_win =
00062     gtk_scrolled_window_new( GTK_ADJUSTMENT ( hadj ),
00063                              GTK_ADJUSTMENT ( vadj ) );
00064   gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( scrolled_win ),
00065                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
00066   gtk_container_add( GTK_CONTAINER( window_p ), scrolled_win );
00067   gtk_widget_show ( scrolled_win );
00068 
00069   char * titles[6] = { "", _("Name"), _("Energy"), _("Place"),
00070                        _("Last"), _("Score") };
00071   clist = gtk_clist_new_with_titles( 6, titles );
00072   gtk_clist_set_selection_mode( GTK_CLIST( clist ), GTK_SELECTION_BROWSE );
00073   gtk_clist_set_column_width( GTK_CLIST( clist ), 0, 5 );
00074   gtk_clist_set_column_width( GTK_CLIST( clist ), 1, 120 );
00075   gtk_clist_set_column_width( GTK_CLIST( clist ), 2, 44 );
00076   gtk_clist_set_column_width( GTK_CLIST( clist ), 3, 38 );
00077   gtk_clist_set_column_width( GTK_CLIST( clist ), 4, 35 );
00078   gtk_clist_set_column_width( GTK_CLIST( clist ), 5, 45 );
00079   gtk_clist_set_column_justification( GTK_CLIST( clist ), 0,
00080                                       GTK_JUSTIFY_CENTER );
00081   gtk_clist_set_column_justification( GTK_CLIST( clist ), 1,
00082                                       GTK_JUSTIFY_LEFT );
00083   gtk_clist_set_column_justification( GTK_CLIST( clist ), 2,
00084                                       GTK_JUSTIFY_RIGHT );
00085   gtk_clist_set_column_justification( GTK_CLIST( clist ), 3,
00086                                       GTK_JUSTIFY_RIGHT );
00087   gtk_clist_set_column_justification( GTK_CLIST( clist ), 4,
00088                                       GTK_JUSTIFY_RIGHT );
00089   gtk_clist_set_column_justification( GTK_CLIST( clist ), 5,
00090                                       GTK_JUSTIFY_RIGHT );
00091   gtk_clist_column_titles_passive( GTK_CLIST( clist ) );
00092   gtk_signal_connect( GTK_OBJECT( clist ), "select_row",
00093                       (GtkSignalFunc) new_robot_selected, this );
00094 
00095   gtk_clist_set_column_resizeable( GTK_CLIST( clist ), 0, FALSE );
00096   gtk_clist_set_column_max_width( GTK_CLIST( clist ), 0, 5 );
00097   gtk_clist_set_shadow_type( GTK_CLIST( clist ), GTK_SHADOW_IN );
00098   gtk_container_add( GTK_CONTAINER( scrolled_win ), clist );
00099 
00100   for( int i=2; i <=5; i++ )
00101     gtk_clist_set_column_auto_resize( GTK_CLIST( clist ), i, TRUE );
00102 
00103   GtkStyle* clist_style = gtk_rc_get_style(window_p);
00104   if( clist_style == NULL )
00105     clist_style = gtk_style_new();
00106   else
00107     clist_style = gtk_style_copy(clist_style);
00108   clist_style->base[GTK_STATE_NORMAL] = *(the_gui.get_bg_gdk_colour_p());
00109   clist_style->base[GTK_STATE_ACTIVE] = make_gdk_colour( 0xffffff );
00110   clist_style->bg[GTK_STATE_SELECTED] = make_gdk_colour( 0xf0d2b4 );
00111   clist_style->fg[GTK_STATE_SELECTED] = *(the_gui.get_fg_gdk_colour_p());
00112   gtk_widget_set_style( clist, clist_style );
00113   gtk_widget_show( clist );
00114 
00115   if( window_shown = ( controlwindow_p->is_scorewindow_checked() ) )
00116     gtk_widget_show_now( window_p );
00117 
00118   selected_robot = NULL;
00119 }

Here is the call graph for this function:

ScoreWindow::~ScoreWindow  ) 
 

Definition at line 124 of file ScoreWindow.cc.

References window_p.

00125 {
00126   gtk_widget_destroy( window_p );
00127 }


Member Function Documentation

void ScoreWindow::add_robots  ) 
 

Definition at line 241 of file ScoreWindow.cc.

References clist, Robot::display_score(), List< T >::first(), Gui::get_bg_gdk_colour_p(), Gui::get_fg_gdk_colour_p(), Robot::get_robot_name(), Robot::get_row_in_score_clist(), Robot::get_score_pixmap(), String::non_const_chars(), ListIterator< T >::ok(), Robot::reset_last_displayed(), selected_robot, Robot::set_row_in_score_clist(), the_arena, the_gui, and window_p.

Referenced by update_robots().

00242 {
00243   gtk_clist_clear( GTK_CLIST( clist ) );
00244   Robot* robot_p;
00245   List<Shape>* object_lists = the_arena.get_object_lists();
00246   ListIterator<Shape> li;
00247 
00248   bool found_robot = false;
00249 
00250   for( object_lists[ROBOT].first(li); li.ok(); li++ )
00251     {
00252       robot_p = (Robot*)li();
00253 
00254       char* empty_list[] = { "", "", "", "", "", "" };
00255       int row = gtk_clist_append( GTK_CLIST( clist ), empty_list );
00256 
00257       gtk_clist_set_foreground( GTK_CLIST( clist ), row,
00258                                 the_gui.get_fg_gdk_colour_p() );
00259       gtk_clist_set_background( GTK_CLIST( clist ), row,
00260                                 the_gui.get_bg_gdk_colour_p() );
00261 
00262       robot_p->set_row_in_score_clist( row );
00263 
00264       GdkPixmap* colour_pixmap;
00265       GdkBitmap* bitmap_mask;
00266       robot_p->get_score_pixmap( window_p->window,
00267                                 colour_pixmap, bitmap_mask );
00268       gtk_clist_set_pixmap( GTK_CLIST( clist ), row, 0,
00269                             colour_pixmap, bitmap_mask );
00270       gtk_clist_set_text( GTK_CLIST( clist ), row, 1,
00271                           robot_p->get_robot_name().non_const_chars() );
00272       gtk_clist_set_text( GTK_CLIST( clist ), row, 3, "" );
00273       robot_p->reset_last_displayed();
00274       robot_p->display_score();
00275       if( selected_robot == NULL && row == 0 )
00276         selected_robot = robot_p;
00277       if( selected_robot == robot_p )
00278         {
00279           found_robot = true;
00280           gtk_clist_select_row( GTK_CLIST( clist ), row, 1 );
00281         }
00282     }
00283 
00284   if( !found_robot )
00285     for( object_lists[ROBOT].first(li); li.ok(); li++ )
00286       {
00287         robot_p = (Robot*)li();
00288         if( robot_p->get_row_in_score_clist() == 0 )
00289           {
00290             selected_robot = robot_p;
00291             gtk_clist_select_row( GTK_CLIST( clist ), 0, 1 );
00292           }
00293       }
00294 }

Here is the call graph for this function:

GtkWidget* ScoreWindow::get_clist  )  [inline]
 

Definition at line 63 of file ScoreWindow.h.

References GtkWidget.

Referenced by Robot::display_score().

00063 { return clist; }

Robot* ScoreWindow::get_selected_robot  )  [inline]
 

Definition at line 64 of file ScoreWindow.h.

Referenced by ControlWindow::kill_robot(), and MessageWindow::show_one_robot().

00064 { return selected_robot; }

GtkWidget* ScoreWindow::get_window_p  )  [inline]
 

Definition at line 62 of file ScoreWindow.h.

References GtkWidget.

Referenced by OptionsWindow::grab_windows(), and ControlWindow::score_window_toggle().

00062 { return window_p; }

gboolean ScoreWindow::hide_window GtkWidget widget,
GdkEvent event,
class ScoreWindow scorewindow_p
[static]
 

Definition at line 154 of file ScoreWindow.cc.

References controlwindow_p, ControlWindow::get_show_score_menu_item(), GtkWidget, and ControlWindow::is_scorewindow_checked().

Referenced by ScoreWindow().

00156 {
00157   if( scorewindow_p->is_window_shown() )
00158     {
00159           gtk_widget_hide( scorewindow_p->get_window_p() );
00160       
00161           scorewindow_p->set_window_shown( false );
00162       if( controlwindow_p->is_scorewindow_checked() )
00163         {
00164           GtkWidget* menu_item = controlwindow_p->get_show_score_menu_item();
00165           gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( menu_item ), FALSE );
00166         }
00167     }
00168  return true;
00169 }

Here is the call graph for this function:

bool ScoreWindow::is_window_shown  )  [inline]
 

Definition at line 65 of file ScoreWindow.h.

00065 { return window_shown; }

void ScoreWindow::new_robot_selected GtkWidget clist,
gint  row,
gint  column,
GdkEventButton event,
class ScoreWindow scorewindow_p
[static]
 

Definition at line 190 of file ScoreWindow.cc.

References Robot::get_row_in_score_clist(), ListIterator< T >::ok(), and the_arena.

Referenced by ScoreWindow().

00193 {
00194   if( event == NULL ) return;
00195 
00196   Robot* robotp;
00197   
00198   ListIterator<Shape> li;
00199   for( the_arena.get_object_lists()[ROBOT].first(li); li.ok(); li++ )
00200     {
00201       robotp = (Robot*)li();
00202 
00203       if( row == robotp->get_row_in_score_clist() )
00204         scorewindow_p->set_selected_robot( robotp );
00205     }
00206 }

Here is the call graph for this function:

void ScoreWindow::set_selected_robot Robot rp  )  [inline]
 

Definition at line 66 of file ScoreWindow.h.

00066 { selected_robot = rp; }

void ScoreWindow::set_window_shown bool  r  )  [inline]
 

Definition at line 67 of file ScoreWindow.h.

00067 { window_shown = r; }

void ScoreWindow::set_window_title  ) 
 

Definition at line 134 of file ScoreWindow.cc.

References _, String::chars(), the_arena, and window_p.

Referenced by ScoreWindow(), ArenaRealTime::start_game(), ArenaReplay::step_forward(), ArenaReplay::timeout_function(), and ArenaRealTime::timeout_function().

00135 {
00136   String title = (String)
00137     (String)_("Score") + "  " + 
00138     (String)_(" Seq: ") + String( the_arena.get_sequence_nr() ) + 
00139     " (" + String( the_arena.get_sequences_in_tournament() ) +
00140 
00141     ")  " + (String)_("Game") + ": " + String( the_arena.get_game_nr() ) +
00142     " (" + String( the_arena.get_games_per_sequence() ) +
00143 
00144     ")  " + (String)_("Time") + ": " + String( (int)the_arena.get_total_time() );
00145 
00146   gtk_window_set_title( GTK_WINDOW( window_p ), title.chars() );
00147 }

Here is the call graph for this function:

void ScoreWindow::show_window GtkWidget widget,
class ScoreWindow scorewindow_p
[static]
 

Definition at line 175 of file ScoreWindow.cc.

00177 {
00178   if( !scorewindow_p->is_window_shown() )
00179     {
00180       gtk_widget_show_now( scorewindow_p->get_window_p() );
00181       scorewindow_p->set_window_shown( true );
00182     }
00183 }

void ScoreWindow::update_robots  ) 
 

Definition at line 213 of file ScoreWindow.cc.

References add_robots(), clist, Robot::display_score(), List< T >::first(), Robot::get_row_in_score_clist(), ListIterator< T >::ok(), Robot::reset_last_displayed(), and the_arena.

Referenced by ArenaRealTime::start_game(), and ArenaReplay::timeout_function().

00214 {
00215   if( the_arena.get_game_nr() == 1 )
00216     {
00217       add_robots();
00218       return;
00219     }
00220 
00221   Robot* robot_p;
00222   List<Shape>* object_lists = the_arena.get_object_lists();
00223   ListIterator<Shape> li;
00224   
00225   for( object_lists[ROBOT].first(li); li.ok(); li++ )
00226     {
00227       robot_p = (Robot*)li();
00228       robot_p->reset_last_displayed();
00229       for( int i = 2; i <=5 ; i++ )
00230         gtk_clist_set_text( GTK_CLIST( clist ),
00231                             robot_p->get_row_in_score_clist(), i, "" );
00232       robot_p->display_score();
00233     }
00234 }

Here is the call graph for this function:


Field Documentation

GtkWidget* ScoreWindow::clist [private]
 

Definition at line 74 of file ScoreWindow.h.

Referenced by add_robots(), ScoreWindow(), and update_robots().

Robot* ScoreWindow::selected_robot [private]
 

Definition at line 76 of file ScoreWindow.h.

Referenced by add_robots(), and ScoreWindow().

GtkWidget* ScoreWindow::window_p [private]
 

Definition at line 73 of file ScoreWindow.h.

Referenced by add_robots(), ScoreWindow(), set_window_title(), and ~ScoreWindow().

bool ScoreWindow::window_shown [private]
 

Definition at line 71 of file ScoreWindow.h.

Referenced by ScoreWindow().


The documentation for this class was generated from the following files:
Generated on Fri Oct 15 15:50:57 2004 for Real Time Battle by  doxygen 1.3.9.1