Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] [PATCH] message window
Home

[Freeciv-Dev] [PATCH] message window

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: FreeCiv <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] [PATCH] message window
From: Francois Taiani <francois.taiani@xxxxxxxx>
Date: Sat, 08 Sep 2001 16:54:51 +0200

Hi everybody,

based on a suggestion by  Trent Piepho (see below), here is a proposal
to prevent "info" windows (like message and science window) from
obscuring the map when you most need to be able to look at it.

The patch sligthly rearranges the gui in order to be able to add "event"
buttons in the righ vertical box. In the present state, there is a
button for messages and for the science dialog. Each time one of these
windows used to pop up before, the corresponding button starts blinking,
and the window does not appear untill you explicitely click the button.
Clicking the button again once the window is up has the window get
hidden again. Adding new buttons is very easy, so if there is some
interest, I can add some extra ones for diplomacy and "Best Civs
Reports".

The sent patch is against the cvs snapshot of September 7.
I've put a snapshot of the new gtk gui at
ftp://ftp.freeciv.org/pub/freeciv/incoming/info_button.png.

Francois

-----------------

On Sat, Aug 25, 2001 at 07:06:33PM -0700, Trent Piepho wrote:
> You could stick a small button on the main window, "Event", or something
> short like that, that would bring the message window the foreground.
> When a new event arrives, the button gets highlighted to tell you about 
> it. Then you can click the button or push F10 when you are ready to have 
> the window obscure the map.

-----------------
Here are some further technical details:

The core functions for the "info" buttons are in the files
./client/gui-gtk/info_buttons.[c|h] . I also added a file
./client/include/info_buttons_g.h to declare the 3 functions through
which the core client code interact with the buttons. I've only changed
the gtk client so far, in order to get some feedback, so the other
clients won't work with that patch.

'stop_info_button_blink' and 'make_info_button_blink' are used to have
an info button start blinking respectively stop blinking.
'make_info_button_blink_modal' is a special version of
'make_info_button_blink' which has the button "remember" that the
corresponding window, when created should be made modal (this was needed
for the science dialog.)

Those 3 function are called in "packhand.c" instead of the previous
"popup_something". For instance instead of calling
'popup_science_dialog(1);', packhand now calls
'make_info_button_blink_modal(BUTTON_SCIENCE);'.

The popup itselft of the science dialog is made in
./client/gui-gtk/info_buttons.c, in 'science_button_callback(..)'. In
order to have the button either popping the window up or hidding it
depending on the windows state, 'science_button_callback(..)' does not
directly call 'popup_science_dialog(..)' but calls 'toggle_science(..)'
instead. 'toggle_science(..)' is a new function of 
"repodlgs.c" that does the toggle work. In the same way I added a
function 'toggle_meswin()' to 'messagewin.c' to do the same with the
message window.
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/Makefile.am 
./client/gui-gtk/Makefile.am
--- ../freeciv-cvs-Sep-07/client/gui-gtk/Makefile.am    Sat Apr  8 12:53:52 2000
+++ ./client/gui-gtk/Makefile.am        Sat Sep  8 15:00:50 2001
@@ -72,5 +72,7 @@
        spaceshipdlg.c  \
        spaceshipdlg.h  \
        wldlg.c         \
-       wldlg.h
+       wldlg.h         \
+       info_buttons.c  \
+       info_buttons.h
 
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/gui_main.c 
./client/gui-gtk/gui_main.c
--- ../freeciv-cvs-Sep-07/client/gui-gtk/gui_main.c     Wed Aug 29 13:58:32 2001
+++ ./client/gui-gtk/gui_main.c Sat Sep  8 15:00:50 2001
@@ -51,6 +51,7 @@
 #include "graphics.h"
 #include "gui_stuff.h"
 #include "helpdata.h"          /* boot_help_texts() */
+#include "info_buttons.h"
 #include "mapctrl.h"
 #include "mapview.h"
 #include "menu.h"
@@ -403,11 +404,8 @@
   GtkStyle           *text_style;
   int                 i;
 
-  paned = gtk_vpaned_new();
-  gtk_container_add(GTK_CONTAINER(toplevel), paned);
-
   top_vbox = gtk_vbox_new(FALSE, 5);
-  gtk_paned_pack1(GTK_PANED(paned), top_vbox, TRUE, FALSE);
+  gtk_container_add(GTK_CONTAINER(toplevel), top_vbox);
   
   setup_menus(toplevel, &menubar);
   gtk_box_pack_start(GTK_BOX(top_vbox), menubar, FALSE, FALSE, 0);
@@ -579,8 +577,13 @@
     gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap, 4, 5, 1, 2);
   }
 
+  add_info_buttons(GTK_BOX(avbox));
+
+  paned = gtk_vpaned_new();
+  gtk_box_pack_start( GTK_BOX( hbox ), paned, TRUE, TRUE, 0 );
+  
   table = gtk_table_new( 2, 2, FALSE );
-  gtk_box_pack_start( GTK_BOX( hbox ), table, TRUE, TRUE, 0 );
+  gtk_paned_pack1(GTK_PANED(paned), table, TRUE, TRUE);
 
   frame = gtk_frame_new( NULL );
   gtk_table_attach(GTK_TABLE(table), frame,
@@ -628,7 +631,7 @@
 
       text = gtk_text_new(NULL, NULL);
       gtk_box_pack_start(GTK_BOX(hbox), text, TRUE, TRUE, 0);
-      gtk_widget_set_usize(text, 600, 100);
+      gtk_widget_set_usize(text, 550, 100);
       gtk_text_set_editable (GTK_TEXT (text), FALSE);
 
       text_scrollbar = gtk_vscrollbar_new (GTK_TEXT(text)->vadj);
@@ -661,7 +664,7 @@
                     GTK_SIGNAL_FUNC(keyboard_handler), NULL);
   /*  gtk_key_snooper_install(keyboard_handler, NULL);*/
 
-  gtk_widget_show_all(paned);
+  gtk_widget_show_all(top_vbox);
   gtk_widget_hide(more_arrow_pixmap);
 }
 
@@ -999,6 +1002,7 @@
     }
     
     blink_active_unit();
+    blink_info_buttons();
     
     if(flip) {
       update_timeout_label();
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/info_buttons.c 
./client/gui-gtk/info_buttons.c
--- ../freeciv-cvs-Sep-07/client/gui-gtk/info_buttons.c Thu Jan  1 01:00:00 1970
+++ ./client/gui-gtk/info_buttons.c     Sat Sep  8 15:00:50 2001
@@ -0,0 +1,171 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   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; either version 2, or (at your option)
+   any later version.
+
+   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.
+***********************************************************************/
+
+#include "info_buttons.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "fcintl.h"
+#include "gui_stuff.h"
+#include "mapview.h"
+#include "messagewin.h"
+#include "repodlgs.h"
+
+unsigned short is_blicking[BUTTON_LAST] ;
+unsigned short flip_state [BUTTON_LAST] ;
+GtkWidget *    button     [BUTTON_LAST] ;
+unsigned short is_modal   [BUTTON_LAST] ; /* Tells how the window is to be 
created if the
+                                             button blinks. */
+
+/* File scope functions. Forward declarations - fta */
+
+void  meswin_button_callback( GtkWidget * widget, gpointer data);
+void science_button_callback( GtkWidget * widget, gpointer data);
+
+void restore_flipped_widget( GtkWidget * widget_to_restore, unsigned short* 
flip_state );
+void flip_widget           ( GtkWidget * widget_to_flip   , unsigned short* 
flip_state );
+void create_and_add_info_button( int           button_type,
+                                 char*         button_name,
+                                 GtkSignalFunc call_back)  ;
+
+
+/**************************************************************************
+Adds info buttons to the right control panel of the gui. The passed
+vertical box is the main box of that panel. This function is
+called at gui initialization.
+**************************************************************************/
+GtkBox* avbox ;
+
+void  add_info_buttons(GtkBox* vbox)
+{ 
+  avbox = vbox ;
+  create_and_add_info_button(BUTTON_MESSAGES,"Messages", 
meswin_button_callback);
+  create_and_add_info_button(BUTTON_SCIENCE ,"Science" 
,science_button_callback);
+} /* EndFunc add_info_buttons */
+
+
+/**************************************************************************
+Is used in add_info_buttons to add each info button individually.
+**************************************************************************/
+void create_and_add_info_button( int           button_type,
+                                 char*         button_name,
+                                 GtkSignalFunc call_back) 
+{
+  GtkWidget *  new_button ;
+
+  new_button = gtk_button_new_with_label( _(button_name) );
+  gtk_widget_set_style(new_button, gtk_style_copy(new_button->style));
+  gtk_box_pack_end(GTK_BOX(avbox), new_button, FALSE, FALSE, 0);
+  gtk_signal_connect(GTK_OBJECT(new_button), "clicked",
+                     GTK_SIGNAL_FUNC(call_back), NULL);
+
+  is_blicking[button_type] = 0 ;
+  flip_state [button_type] = 0 ;
+  is_modal   [button_type] = 0 ;
+  button     [button_type] = new_button ;
+
+} /* EndFunc create_and_add_info_button */
+
+/**************************************************************************
+...
+**************************************************************************/
+void make_info_button_blink(int button_type)
+{
+  is_blicking[button_type]=1 ;
+  is_modal   [button_type]=0 ;
+} /* EndFunc make_info_button_blink */
+
+/**************************************************************************
+As make_info_button_blink and specifies that when the button is clicked 
+the corresponding windows should be made modal (for instance: for the
+science dialog, after a new technology has been found.)
+**************************************************************************/
+void  make_info_button_blink_modal (int button_type)
+{
+  is_blicking[button_type]=1 ;
+  is_modal   [button_type]=1 ;
+} /* make_info_button_blink_modal */
+
+/**************************************************************************
+...
+**************************************************************************/
+void stop_info_button_blink(int button_type)
+{
+  is_blicking[button_type]=0 ;
+  is_modal   [button_type]=0 ;
+  restore_flipped_widget (  button     [button_type] ,
+                           &flip_state [button_type] );
+
+} /* EndFunc stop_info_button_blink */
+
+/**************************************************************************
+...
+**************************************************************************/
+void blink_info_buttons()
+{
+  int i ;
+  for (i=0; i<BUTTON_LAST; i++)
+      if (is_blicking[i])
+        flip_widget(   button     [i] ,
+                      &flip_state [i] );
+
+} /* EndFunc blink_info_buttons */
+
+/**************************************************************************
+Switch the forground and the background colors of a wigdet, in order
+to create a blink effect. The parameter flip_state is used to
+remember the state of the widget (flipped or not flipped), in order
+to be able to restore it to its normal state.
+**************************************************************************/
+void flip_widget(GtkWidget * widget_to_flip, unsigned short* flip_state)
+{
+   GdkGC      *fore, *back;
+ 
+   fore = widget_to_flip->style->   bg_gc[GTK_STATE_NORMAL];
+   back = widget_to_flip->style->light_gc[GTK_STATE_NORMAL];
+   
+   widget_to_flip->style->   bg_gc[GTK_STATE_NORMAL] = back;
+   widget_to_flip->style->light_gc[GTK_STATE_NORMAL] = fore;
+   
+   gtk_expose_now(widget_to_flip);
+   
+   *flip_state=!*flip_state;
+} /* EndFunction flip_widget */
+
+/**************************************************************************
+Takes a possibly flipped widget back to its normal state
+**************************************************************************/
+void restore_flipped_widget(GtkWidget * widget_to_restore,unsigned short* 
flip_state)
+{
+  if (*flip_state) flip_widget(widget_to_restore,flip_state);
+} // EndFunction restore_flipped_widget
+
+
+/**************************************************************************
+This method is called back when the message button is pressed.
+**************************************************************************/
+void meswin_button_callback(GtkWidget *widget, gpointer data)
+{
+  toggle_meswin() ;
+}
+
+
+/**************************************************************************
+This method is called back when the message button is pressed.
+**************************************************************************/
+void science_button_callback(GtkWidget *widget, gpointer data)
+{
+  toggle_science(is_modal[BUTTON_SCIENCE]) ;
+}
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/info_buttons.h 
./client/gui-gtk/info_buttons.h
--- ../freeciv-cvs-Sep-07/client/gui-gtk/info_buttons.h Thu Jan  1 01:00:00 1970
+++ ./client/gui-gtk/info_buttons.h     Sat Sep  8 16:29:21 2001
@@ -0,0 +1,23 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   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; either version 2, or (at your option)
+   any later version.
+
+   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.
+***********************************************************************/
+#ifndef INFO_BUTTONS_H
+#define INFO_BUTTONS_H
+
+#include <gtk/gtk.h>
+
+#include "info_buttons_g.h"
+
+void   add_info_buttons(GtkBox* avbox);
+void blink_info_buttons();
+
+#endif /* INFO_BUTTONS_H */
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/messagewin.c 
./client/gui-gtk/messagewin.c
--- ../freeciv-cvs-Sep-07/client/gui-gtk/messagewin.c   Tue Jan 30 13:59:51 2001
+++ ./client/gui-gtk/messagewin.c       Sat Sep  8 15:31:55 2001
@@ -35,6 +35,7 @@
 #include "colors.h"
 #include "gui_main.h"
 #include "gui_stuff.h"
+#include "info_buttons.h"
 #include "mapview.h"
 #include "options.h"
 
@@ -89,12 +90,15 @@
     updated = 1;              /* create_ calls update_ */
   }
 
-  gtk_set_relative_position(toplevel, meswin_dialog_shell, 25, 25);
   gtk_widget_show(meswin_dialog_shell);
+  gdk_window_show(meswin_dialog_shell->window) ;
+
   if(!updated) 
     update_meswin_dialog();
   
   meswin_scroll_down();
+  stop_info_button_blink(BUTTON_MESSAGES);
+
 }
 
 
@@ -198,6 +202,7 @@
 
   gtk_widget_show_all( GTK_DIALOG(meswin_dialog_shell)->vbox );
   gtk_widget_show_all( GTK_DIALOG(meswin_dialog_shell)->action_area );
+  gtk_set_relative_position(toplevel, meswin_dialog_shell, 25, 25);
 }
 
 /**************************************************************************
@@ -326,8 +331,8 @@
   if (!meswin_dialog_shell) { 
     if (messages_total > 0 &&
         (!game.player_ptr->ai.control || ai_popup_windows)) {
-      popup_meswin_dialog();
-      /* Can return here because popup_meswin_dialog will call
+          create_meswin_dialog();
+      /* Can return here because create_meswin_dialog will call
        * this very function again.
        */
       return;
@@ -349,6 +354,23 @@
      gtk_widget_show_all(meswin_list);
    }
 
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void toggle_meswin() 
+{
+   stop_info_button_blink(BUTTON_MESSAGES);
+   if(meswin_dialog_shell) 
+       if (meswin_dialog_shell->window)
+           if (gdk_window_is_visible (meswin_dialog_shell->window)) 
+             {
+               gdk_window_hide(meswin_dialog_shell->window) ;
+               return ;
+             } /* EndIf gdk_window_is_visible */
+
+   popup_meswin_dialog();
 }
 
 /**************************************************************************
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/messagewin.h 
./client/gui-gtk/messagewin.h
--- ../freeciv-cvs-Sep-07/client/gui-gtk/messagewin.h   Tue Jul 20 13:43:15 1999
+++ ./client/gui-gtk/messagewin.h       Sat Sep  8 15:00:50 2001
@@ -15,6 +15,8 @@
 
 #include "messagewin_g.h"
 
+void toggle_meswin() ;
+
 /* nothing else */
 
 #endif  /* FC__MESSAGEWIN_H */
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/repodlgs.c 
./client/gui-gtk/repodlgs.c
--- ../freeciv-cvs-Sep-07/client/gui-gtk/repodlgs.c     Fri Sep  7 07:56:00 2001
+++ ./client/gui-gtk/repodlgs.c Sat Sep  8 15:00:50 2001
@@ -26,6 +26,7 @@
 #include "fcintl.h"
 #include "game.h"
 #include "government.h"
+#include "info_buttons.h"
 #include "packets.h"
 #include "shared.h"
 #include "support.h"
@@ -159,6 +160,24 @@
 
     gtk_widget_show( science_dialog_shell );
   }
+  gdk_window_show( science_dialog_shell->window ) ;
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void toggle_science(int make_modal) 
+{
+   stop_info_button_blink(BUTTON_SCIENCE);
+   if(science_dialog_shell) 
+       if (science_dialog_shell->window)
+           if (gdk_window_is_visible (science_dialog_shell->window)) 
+             {
+               gdk_window_hide(science_dialog_shell->window) ;
+               return ;
+             } /* EndIf gdk_window_is_visible */
+
+   popup_science_dialog(make_modal);
 }
 
 
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/gui-gtk/repodlgs.h 
./client/gui-gtk/repodlgs.h
--- ../freeciv-cvs-Sep-07/client/gui-gtk/repodlgs.h     Tue Jan 30 13:59:52 2001
+++ ./client/gui-gtk/repodlgs.h Sat Sep  8 15:00:50 2001
@@ -16,5 +16,6 @@
 #include "repodlgs_g.h"
 
 extern int delay_report_update;
+void toggle_science(int make_modal) ;
 
 #endif  /* FC__REPODLGS_H */
diff -NuBwr -X diff_ignore 
../freeciv-cvs-Sep-07/client/include/info_buttons_g.h 
./client/include/info_buttons_g.h
--- ../freeciv-cvs-Sep-07/client/include/info_buttons_g.h       Thu Jan  1 
01:00:00 1970
+++ ./client/include/info_buttons_g.h   Sat Sep  8 16:35:16 2001
@@ -0,0 +1,27 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   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; either version 2, or (at your option)
+   any later version.
+
+   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.
+***********************************************************************/
+#ifndef INFO_BUTTONS_G_H
+#define INFO_BUTTONS_G_H
+
+enum info_button_type {
+  BUTTON_MESSAGES,
+  BUTTON_SCIENCE,
+  BUTTON_LAST     /* leave it last */
+} ; /* End info_button_type */
+
+void  stop_info_button_blink       (int button_type);
+void  make_info_button_blink       (int button_type);
+void  make_info_button_blink_modal (int button_type);
+
+
+#endif /* INFO_BUTTONS_G_H */
diff -NuBwr -X diff_ignore ../freeciv-cvs-Sep-07/client/packhand.c 
./client/packhand.c
--- ../freeciv-cvs-Sep-07/client/packhand.c     Fri Sep  7 07:55:56 2001
+++ ./client/packhand.c Sat Sep  8 15:00:50 2001
@@ -48,6 +48,7 @@
 #include "graphics_g.h"
 #include "gui_main_g.h"
 #include "helpdata.h"          /* boot_help_texts() */
+#include "info_buttons_g.h"
 #include "mapctrl_g.h"         /* popup_newcity_dialog() */
 #include "mapview_g.h"
 #include "menu_g.h"
@@ -642,6 +643,8 @@
 
   update_city_descriptions();
 
+  make_info_button_blink(BUTTON_MESSAGES);
+
   if(game.player_ptr->ai.control && !ai_manual_turn_done)
     user_ended_turn();
 
@@ -1100,7 +1103,7 @@
   if(get_client_state()==CLIENT_GAME_RUNNING_STATE && 
pplayer==game.player_ptr) {
     if(poptechup) {
       if(!game.player_ptr->ai.control || ai_popup_windows)
-       popup_science_dialog(1);
+         make_info_button_blink_modal(BUTTON_SCIENCE);
       did_advance_tech_this_turn=game.year;
       science_dialog_update();
 
Binary files ../freeciv-cvs-Sep-07/current.sav.gz and ./current.sav.gz differ

[Prev in Thread] Current Thread [Next in Thread]