Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2006:
[Freeciv-Dev] (PR#15924) cursors cleanup
Home

[Freeciv-Dev] (PR#15924) cursors cleanup

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#15924) cursors cleanup
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 15 Mar 2006 22:51:34 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15924 >

I wanted to add a new cursor type, but I was confused by the 
intermediate action_state variable used to transfer cursor information 
from core-client to GUI code.

After a moment I realized this was simply unnecessary.  The action_state 
is only set in the handle_mouse_cursor code and is used immediately 
thereafter in the called function.  So this patch removes the complex 
decoding and simply sets the cursor type directly in handle_mouse_cursor.

Only the gtk2 client is updated.

-jason

Index: client/control.c
===================================================================
--- client/control.c    (revision 11774)
+++ client/control.c    (working copy)
@@ -61,7 +61,6 @@
 struct unit_list *hover_units;
 enum cursor_hover_state hover_state = HOVER_NONE;
 struct tile *hover_tile = NULL;
-enum cursor_action_state action_state = CURSOR_ACTION_DEFAULT;
 enum unit_activity connect_activity;
 enum unit_orders goto_last_order; /* Last order for goto */
 
@@ -883,6 +882,7 @@
   struct unit *punit = NULL;
   struct city *pcity = NULL;
   struct unit_list *active_units = get_units_in_focus();
+  enum cursor_type mouse_cursor_type = CURSOR_DEFAULT;
 
   if (!ptile) {
     if (hover_tile) {
@@ -896,42 +896,60 @@
   punit = find_visible_unit(ptile);
   pcity = ptile ? ptile->city : NULL;
 
-  if (hover_state == HOVER_NONE) {
+  switch (hover_state) {
+  case HOVER_NONE:
     if (punit && game.player_ptr == punit->owner) {
       /* Set mouse cursor to select a unit.  */
-      action_state = CURSOR_ACTION_SELECT;
-    } else if (pcity && can_player_see_city_internals(game.player_ptr, pcity)) 
{
+      mouse_cursor_type = CURSOR_SELECT;
+    } else if (pcity
+              && can_player_see_city_internals(game.player_ptr, pcity)) {
       /* Set mouse cursor to select a city. */
-      action_state = CURSOR_ACTION_SELECT;
+      mouse_cursor_type = CURSOR_SELECT;
     } else {
       /* Set default mouse cursor, because nothing selectable found. */
-      action_state = CURSOR_ACTION_DEFAULT;
     }
-
-  } else if (hover_state == HOVER_GOTO) {
+    break;
+  case HOVER_GOTO:
     /* Determine if the goto is valid, invalid or will attack. */
     if (is_valid_goto_destination(ptile)) {
       if (can_units_attack_at(active_units, ptile)) {
         /* Goto results in military attack. */
-        action_state = CURSOR_ACTION_ATTACK;
+       mouse_cursor_type = CURSOR_ATTACK;
       } else if (is_enemy_city_tile(ptile, game.player_ptr)) {
         /* Goto results in attack of enemy city. */
-        action_state = CURSOR_ACTION_ATTACK;
+       mouse_cursor_type = CURSOR_ATTACK;
       } else {
-        action_state = CURSOR_ACTION_GOTO;
+       mouse_cursor_type = CURSOR_GOTO;
       }
     } else {
-      action_state = CURSOR_ACTION_INVALID;
+      mouse_cursor_type = CURSOR_INVALID;
     }
-  } else if (hover_state == HOVER_PATROL || hover_state == HOVER_CONNECT) {
+    break;
+  case HOVER_PATROL:
     if (is_valid_goto_destination(ptile)) {
-      action_state = CURSOR_ACTION_GOTO;
+      mouse_cursor_type = CURSOR_PATROL;
     } else {
-      action_state = CURSOR_ACTION_INVALID;
+      mouse_cursor_type = CURSOR_INVALID;
     }
+    break;
+  case HOVER_CONNECT:
+    if (is_valid_goto_destination(ptile)) {
+      mouse_cursor_type = CURSOR_GOTO;
+    } else {
+      mouse_cursor_type = CURSOR_INVALID;
+    }
+    break;
+  case HOVER_NUKE:
+    /* FIXME: check for invalid tiles. */
+    mouse_cursor_type = CURSOR_NUKE;
+    break;
+  case HOVER_PARADROP:
+    /* FIXME: check for invalid tiles. */
+    mouse_cursor_type = CURSOR_PARADROP;
+    break;
   }
 
-  update_unit_info_label(active_units);
+  update_mouse_cursor(mouse_cursor_type);
 }
 
 /**************************************************************************
Index: client/gui-gtk-2.0/mapview.c
===================================================================
--- client/gui-gtk-2.0/mapview.c        (revision 11774)
+++ client/gui-gtk-2.0/mapview.c        (working copy)
@@ -185,7 +185,7 @@
 /**************************************************************************
   This function will change the current mouse cursor.
 **************************************************************************/
-static void modify_mouse_cursor(enum cursor_type new_cursor_type)
+void update_mouse_cursor(enum cursor_type new_cursor_type)
 {
   cursor_type = new_cursor_type;
   if (!cursor_timer_id) {
@@ -205,7 +205,6 @@
 **************************************************************************/
 void update_unit_info_label(struct unit_list *punits)
 {
-  enum cursor_type mouse_cursor_type = CURSOR_DEFAULT;
   GtkWidget *label;
 
   label = gtk_frame_get_label_widget(GTK_FRAME(unit_info_frame));
@@ -215,53 +214,6 @@
   gtk_label_set_text(GTK_LABEL(unit_info_label),
                     get_unit_info_label_text2(punits));
 
-  switch (hover_state) {
-  case HOVER_NONE:
-    if (action_state == CURSOR_ACTION_SELECT) {
-      mouse_cursor_type = CURSOR_SELECT;
-    } else if (action_state == CURSOR_ACTION_PARATROOPER) {
-      mouse_cursor_type = CURSOR_PARADROP;
-    } else if (action_state == CURSOR_ACTION_NUKE) {
-      mouse_cursor_type = CURSOR_NUKE;
-    } else {
-      mouse_cursor_type = CURSOR_DEFAULT;
-    }
-    break;
-  case HOVER_PATROL:
-    if (action_state == CURSOR_ACTION_INVALID) {
-      mouse_cursor_type = CURSOR_INVALID;
-    } else {
-      mouse_cursor_type = CURSOR_PATROL;
-    }
-    break;
-  case HOVER_GOTO:
-    if (action_state == CURSOR_ACTION_GOTO) {
-      mouse_cursor_type = CURSOR_GOTO;
-    } else if (action_state == CURSOR_ACTION_DEFAULT) {
-      mouse_cursor_type = CURSOR_DEFAULT;
-    } else if (action_state == CURSOR_ACTION_ATTACK) {
-      mouse_cursor_type = CURSOR_ATTACK;
-    } else {
-      mouse_cursor_type = CURSOR_INVALID;
-    }
-    break;
-  case HOVER_CONNECT:
-    if (action_state == CURSOR_ACTION_INVALID) {
-      mouse_cursor_type = CURSOR_INVALID;
-    } else {
-      mouse_cursor_type = CURSOR_GOTO;
-    }
-    break;
-  case HOVER_NUKE:
-    mouse_cursor_type = CURSOR_NUKE;
-    break;
-  case HOVER_PARADROP:
-    mouse_cursor_type = CURSOR_PARADROP;
-    break;
-  }
-
-  modify_mouse_cursor(mouse_cursor_type);
-
   update_unit_pix_label(punits);
 }
 
Index: client/gui-gtk-2.0/mapctrl.c
===================================================================
--- client/gui-gtk-2.0/mapctrl.c        (revision 11774)
+++ client/gui-gtk-2.0/mapctrl.c        (working copy)
@@ -394,8 +394,8 @@
 {
   struct unit_list *active_units = get_units_in_focus();
 
-  action_state = CURSOR_ACTION_DEFAULT;
-  update_unit_info_label(active_units); 
+  update_mouse_cursor(CURSOR_DEFAULT);
+  update_unit_info_label(active_units);
   return TRUE;
 }
 
Index: client/control.h
===================================================================
--- client/control.h    (revision 11774)
+++ client/control.h    (working copy)
@@ -24,16 +24,6 @@
   HOVER_PATROL
 };
 
-enum cursor_action_state {
-  CURSOR_ACTION_DEFAULT,
-  CURSOR_ACTION_GOTO,
-  CURSOR_ACTION_SELECT,
-  CURSOR_ACTION_INVALID,
-  CURSOR_ACTION_ATTACK,
-  CURSOR_ACTION_NUKE,
-  CURSOR_ACTION_PARATROOPER
-};
-
 /* Selecting unit from a stack without popup. */
 enum quickselect_type {
   SELECT_POPUP = 0, SELECT_SEA, SELECT_LAND, SELECT_APPEND
Index: client/include/mapview_g.h
===================================================================
--- client/include/mapview_g.h  (revision 11774)
+++ client/include/mapview_g.h  (working copy)
@@ -23,6 +23,7 @@
 
 void update_info_label(void);
 void update_unit_info_label(struct unit_list *punitlist);
+void update_mouse_cursor(enum cursor_type new_cursor_type);
 void update_timeout_label(void);
 void update_turn_done_button(bool do_restore);
 void update_city_descriptions(void);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#15924) cursors cleanup, Jason Short <=