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

On 1/19/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>  I'll send another patch containing parts of the original patch that
> were left out from these. They probably should go in later.

 Here


 - ML

diff -Nurd -X.diff_ignore freeciv/client/gui-win32/graphics.c freeciv/client/gui-win32/graphics.c
--- freeciv/client/gui-win32/graphics.c	2006-07-17 23:56:51.000000000 +0300
+++ freeciv/client/gui-win32/graphics.c	2007-01-19 00:56:56.000000000 +0200
@@ -56,8 +56,6 @@
 
 extern HINSTANCE freecivhinst;
 
-HCURSOR cursors[CURSOR_LAST * NUM_CURSOR_FRAMES];
-
 struct sprite *intro_gfx_sprite = NULL;
 struct sprite *radar_gfx_sprite = NULL;
 
@@ -86,87 +84,6 @@
   radar_gfx_sprite = load_gfxfile(tileset_mini_intro_filename(tileset));
 }
 
-/**************************************************************************
-  Load the cursors (mouse substitute sprites), including a goto cursor,
-  an airdrop cursor, a nuke cursor, and a patrol cursor.
-**************************************************************************/
-void
-load_cursors(void)
-{
-  enum cursor_type cursor;
-  ICONINFO ii;
-  int frame, i;
-
-  /* For some reason win32 lets you enter a cursor size, which
-   * only works as long as it's this size. */
-  int width = GetSystemMetrics(SM_CXCURSOR);
-  int height = GetSystemMetrics(SM_CYCURSOR);
-
-  BITMAP *xor_bmp, *and_bmp;
-
-  xor_bmp = bmp_new(width, height);
-  and_bmp = bmp_new(width, height);
-
-  ii.fIcon = FALSE;
-
-  for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
-    int hot_x, hot_y;
-    int x, y;
-    int minwidth, minheight;
-
-    for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
-
-    struct sprite *sprite = get_cursor_sprite(tileset, cursor, 
-		                              &hot_x, &hot_y, frame);
-
-    ii.xHotspot = MIN(hot_x, width);
-    ii.yHotspot = MIN(hot_y, height);
-
-    memset(xor_bmp->bmBits, 0,   width * height * 4);
-    memset(and_bmp->bmBits, 255, width * height * 4);
-
-    minwidth  = MIN(width,  sprite->img->bmWidth);
-    minheight = MIN(height, sprite->img->bmHeight);
-
-    for (y = 0; y < minheight; y++) {
-      BYTE *src = (BYTE *)sprite->img->bmBits + sprite->img->bmWidthBytes * y;
-      BYTE *xor_dst = (BYTE *)xor_bmp->bmBits + xor_bmp->bmWidthBytes * y;
-      BYTE *and_dst = (BYTE *)and_bmp->bmBits + and_bmp->bmWidthBytes * y;
-      for (x = 0; x < minwidth; x++) {
-	if (src[3] > 128) {
-	  *xor_dst++ = src[0];
-	  *xor_dst++ = src[1];
-	  *xor_dst++ = src[2];
-	  *xor_dst++ = 255;
-	  *and_dst++ = 0;
-	  *and_dst++ = 0;
-	  *and_dst++ = 0;
-	  *and_dst++ = 0;
-	} else {
-	  and_dst += 4;
-	  xor_dst += 4;
-	}
-	src += 4;
-      }
-    }
-
-    ii.hbmMask = BITMAP2HBITMAP(and_bmp);
-    ii.hbmColor = BITMAP2HBITMAP(xor_bmp);
-
-    i = cursor * NUM_CURSOR_FRAMES + frame;
-
-    cursors[i] = CreateIconIndirect(&ii);
-
-    DeleteObject(ii.hbmMask);
-    DeleteObject(ii.hbmColor);
-
-    }
-  }
-
-  bmp_free(xor_bmp);
-  bmp_free(and_bmp);
-}
-
 /****************************************************************************
   Frees the introductory sprites.
 ****************************************************************************/
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/gui_main.c freeciv/client/gui-win32/gui_main.c
--- freeciv/client/gui-win32/gui_main.c	2006-07-17 23:56:51.000000000 +0300
+++ freeciv/client/gui-win32/gui_main.c	2007-01-19 00:56:56.000000000 +0200
@@ -56,6 +56,8 @@
 #include <stdio.h>
 
 #include "gui_main.h"
+#include "gui_mouse.h"
+/*anim_cursor()*/
 
 const char *client_string = "gui-win32";
 
@@ -711,8 +713,6 @@
   return TRUE;
 }
 
-extern void anim_cursor(float time);
-
 /**************************************************************************
 
 **************************************************************************/
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/gui_mouse.c freeciv/client/gui-win32/gui_mouse.c
--- freeciv/client/gui-win32/gui_mouse.c	1970-01-01 02:00:00.000000000 +0200
+++ freeciv/client/gui-win32/gui_mouse.c	2007-01-19 00:56:56.000000000 +0200
@@ -0,0 +1,144 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+/*memset()*/
+#include "windows.h"
+
+#include "shared.h"
+/*MIN*/
+
+#include "tilespec.h"
+/*enum cursor_type
+ * NUM_CURSOR_FRAMES
+ * get_cursor_sprite() */
+
+#include "graphics.h"
+/*bmp_new()
+ load_cursors() declaration (via graphics_g.h)*/
+#include "gui_mouse.h"
+/*anim_cursor() declaration*/
+#include "mapview.h"
+/*update_mouse_cursor() declaration (via mapview_g.h)*/
+#include "sprite.h"
+/*struct sprite*/
+
+/*The cursors are initialized by load_cursors*/
+static HCURSOR anim_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES];
+static HCURSOR default_cursor;
+
+/*This must be updated every time the cursor type is changed*/
+static enum cursor_type current_cursor_type ;
+
+/**************************************************************************
+  Load the cursors (mouse substitute sprites), including a goto cursor,
+  an airdrop cursor, a nuke cursor, and a patrol cursor.
+  In most of the other clients, this is done in graphics.c
+  However, putting it here keeps the cursors array scoped to this file.
+**************************************************************************/
+void load_cursors(void)
+{
+  ICONINFO ii;
+  unsigned int cursor, frame;
+
+  /* For some reason win32 lets you enter a cursor size, which
+   * only works as long as it's this size. */
+  int width = GetSystemMetrics(SM_CXCURSOR);
+  int height = GetSystemMetrics(SM_CYCURSOR);
+
+  BITMAP *xor_bmp, *and_bmp;
+
+  xor_bmp = bmp_new(width, height);
+  and_bmp = bmp_new(width, height);
+
+  ii.fIcon = FALSE;
+
+  /*first the default cursor*/
+  default_cursor = LoadCursor( NULL , IDC_ARROW );
+
+  /*now the rest*/
+  for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
+    int hot_x, hot_y;
+    int x, y;
+    int minwidth, minheight;
+
+    for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
+
+    struct sprite *sprite = get_cursor_sprite(tileset, cursor, 
+		                              &hot_x, &hot_y, frame);
+
+    ii.xHotspot = MIN(hot_x, width);
+    ii.yHotspot = MIN(hot_y, height);
+
+    memset(xor_bmp->bmBits, 0,   width * height * 4);
+    memset(and_bmp->bmBits, 255, width * height * 4);
+
+    minwidth  = MIN(width,  sprite->img->bmWidth);
+    minheight = MIN(height, sprite->img->bmHeight);
+
+    for (y = 0; y < minheight; y++) {
+      BYTE *src = (BYTE *)sprite->img->bmBits + sprite->img->bmWidthBytes * y;
+      BYTE *xor_dst = (BYTE *)xor_bmp->bmBits + xor_bmp->bmWidthBytes * y;
+      BYTE *and_dst = (BYTE *)and_bmp->bmBits + and_bmp->bmWidthBytes * y;
+      for (x = 0; x < minwidth; x++) {
+	if (src[3] > 128) {
+	  *xor_dst++ = src[0];
+	  *xor_dst++ = src[1];
+	  *xor_dst++ = src[2];
+	  *xor_dst++ = 255;
+	  *and_dst++ = 0;
+	  *and_dst++ = 0;
+	  *and_dst++ = 0;
+	  *and_dst++ = 0;
+	} else {
+	  and_dst += 4;
+	  xor_dst += 4;
+	}
+	src += 4;
+      }
+    }
+
+    ii.hbmMask = BITMAP2HBITMAP(and_bmp);
+    ii.hbmColor = BITMAP2HBITMAP(xor_bmp);
+
+    anim_cursors[cursor][frame] = CreateIconIndirect(&ii);
+
+    DeleteObject(ii.hbmMask);
+    DeleteObject(ii.hbmColor);
+
+    }
+  }
+
+  bmp_free(xor_bmp);
+  bmp_free(and_bmp);
+}
+
+/**************************************************************************
+  This function is used to animate the mouse cursor.
+  It is not part of the generic GUI template
+**************************************************************************/
+void anim_cursor(float time)
+{
+  if (current_cursor_type != CURSOR_DEFAULT) {
+    /*animate except default cursor*/
+    unsigned int frame = (unsigned int)(time * 15.0f) % NUM_CURSOR_FRAMES; 
+    SetCursor( anim_cursors[ current_cursor_type ][ frame ] );
+  }
+
+}
+
+/**************************************************************************
+ * In most of the other clients, the function is in mapview.c.
+ * Putting it here keeps the cursors array local to this file.
+ * ***********************************************************************/
+void update_mouse_cursor(enum cursor_type new_cursor_type)
+{
+  if ( new_cursor_type == CURSOR_DEFAULT ) {
+	  SetCursor(default_cursor);
+  } else {
+	  SetCursor(anim_cursors[new_cursor_type][0]);
+  }
+
+  current_cursor_type = new_cursor_type;
+}
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/gui_mouse.h freeciv/client/gui-win32/gui_mouse.h
--- freeciv/client/gui-win32/gui_mouse.h	1970-01-01 02:00:00.000000000 +0200
+++ freeciv/client/gui-win32/gui_mouse.h	2007-01-19 00:56:56.000000000 +0200
@@ -0,0 +1,7 @@
+#ifndef FC__GUI_MOUSE_H
+#define FC__GUI_MOUSE_H
+
+void anim_cursor( float );
+
+#endif /*ifdef FC__GUI_MOUSE_H*/
+
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/happiness.c freeciv/client/gui-win32/happiness.c
--- freeciv/client/gui-win32/happiness.c	2006-10-31 18:28:41.000000000 +0200
+++ freeciv/client/gui-win32/happiness.c	2007-01-19 00:56:56.000000000 +0200
@@ -177,7 +177,7 @@
   struct player *pplayer = pcity->owner;
   int cities = city_list_size(pplayer->cities);
   int content = get_player_bonus(pcity->owner, EFT_CITY_UNHAPPY_SIZE);
-  int basis = get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_MOD);
+  int basis = get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_BASE);
   int step = get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_STEP);
   int excess = cities - basis;
   int penalty = 0;
@@ -240,7 +240,6 @@
   char buf[512], *bptr = buf;
   int nleft = sizeof(buf);
   struct city *pcity = pdialog->pcity;
-  struct government *g = get_gov_pcity(pcity);
   int mlmax = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
   int uhcfac = get_player_bonus(city_owner(pcity), EFT_UNHAPPY_FACTOR);
 
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/Makefile.am freeciv/client/gui-win32/Makefile.am
--- freeciv/client/gui-win32/Makefile.am	2006-10-31 18:28:41.000000000 +0200
+++ freeciv/client/gui-win32/Makefile.am	2007-01-19 00:56:56.000000000 +0200
@@ -33,6 +33,8 @@
 	graphics.h	\
 	gui_main.c	\
 	gui_main.h	\
+	gui_mouse.c	\
+	gui_mouse.h	\
 	gui_stuff.h	\
 	gui_stuff.c	\
 	happiness.c	\
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/mapctrl.c freeciv/client/gui-win32/mapctrl.c
--- freeciv/client/gui-win32/mapctrl.c	2006-10-31 18:28:41.000000000 +0200
+++ freeciv/client/gui-win32/mapctrl.c	2007-01-19 00:56:56.000000000 +0200
@@ -52,8 +52,6 @@
 #include "mapctrl.h"
 #include "gui_main.h"
 
-extern HCURSOR cursors[];
-
 HWND popit_popup=NULL;
 static bool popit_is_orders;
 /*************************************************************************
@@ -230,17 +228,17 @@
       SetCursor (LoadCursor(NULL, IDC_ARROW));
       break;
     case HOVER_PATROL:
-      SetCursor (cursors[CURSOR_PATROL]);
+      update_mouse_cursor(CURSOR_PATROL);
       break;
     case HOVER_GOTO:
     case HOVER_CONNECT:
-      SetCursor (cursors[CURSOR_GOTO]);
+      update_mouse_cursor(CURSOR_GOTO);
       break;
     case HOVER_NUKE:
-      SetCursor (cursors[CURSOR_NUKE]);
+      update_mouse_cursor(CURSOR_NUKE);
       break;
     case HOVER_PARADROP:
-      SetCursor (cursors[CURSOR_PARADROP]);
+      update_mouse_cursor(CURSOR_PARADROP);
       break;
     }
     break;
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/mapview.c freeciv/client/gui-win32/mapview.c
--- freeciv/client/gui-win32/mapview.c	2006-10-31 18:28:41.000000000 +0200
+++ freeciv/client/gui-win32/mapview.c	2007-01-19 00:56:56.000000000 +0200
@@ -53,14 +53,10 @@
 #include "sprite.h"
 #include "text.h"
 
-extern HCURSOR cursors[];
-
 static struct sprite *indicator_sprite[3];
 
 static HBITMAP intro_gfx;
 
-static int cursor_type = -1;
-
 extern void do_mainwin_layout();
 
 extern int seconds_to_turndone;   
@@ -69,20 +65,6 @@
 static void draw_rates(HDC hdc);
 
 /**************************************************************************
-  This function is used to animate the mouse cursor. 
-**************************************************************************/
-void anim_cursor(float time)
-{
-  int cursor_frame = (int)(time * 15.0f) % NUM_CURSOR_FRAMES;
-
-  if (cursor_type == CURSOR_DEFAULT) {
-    SetCursor (LoadCursor(NULL, IDC_ARROW));
-  } else {
-    SetCursor(cursors[cursor_type * NUM_CURSOR_FRAMES + cursor_frame]);
-  }
-}
-
-/**************************************************************************
 
 **************************************************************************/
 void map_expose(int x, int y, int width, int height)
@@ -199,51 +181,6 @@
   SetWindowText(unit_info_frame, get_unit_info_label_text1(punitlist));
   SetWindowText(unit_info_label, get_unit_info_label_text2(punitlist));
 
-  switch (hover_state) {
-    case HOVER_NONE:
-      if (action_state == CURSOR_ACTION_SELECT) {
-        cursor_type = CURSOR_SELECT;
-      } else if (action_state == CURSOR_ACTION_PARATROOPER) {
-        cursor_type = CURSOR_PARADROP;
-      } else if (action_state == CURSOR_ACTION_NUKE) {
-        cursor_type = CURSOR_NUKE;
-      } else {
-        cursor_type = CURSOR_DEFAULT;
-      }
-      break;
-    case HOVER_PATROL:
-      if (action_state == CURSOR_ACTION_INVALID) {
-        cursor_type = CURSOR_INVALID;
-      } else {
-        cursor_type = CURSOR_PATROL;
-      }
-      break;
-    case HOVER_GOTO:
-      if (action_state == CURSOR_ACTION_GOTO) {
-        cursor_type = CURSOR_GOTO;
-      } else if (action_state == CURSOR_ACTION_DEFAULT) {
-        cursor_type = CURSOR_DEFAULT;
-      } else if (action_state == CURSOR_ACTION_ATTACK) {
-        cursor_type = CURSOR_ATTACK;
-      } else {
-        cursor_type = CURSOR_INVALID;
-      }
-      break;
-    case HOVER_CONNECT:
-      if (action_state == CURSOR_ACTION_INVALID) {
-        cursor_type = CURSOR_INVALID;
-      } else {
-        cursor_type = CURSOR_GOTO;
-      }
-      break;
-    case HOVER_NUKE:
-      cursor_type = CURSOR_NUKE;
-      break;
-    case HOVER_PARADROP:
-      cursor_type = CURSOR_PARADROP;
-      break;
-  }
-
   do_mainwin_layout();
 }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to