[gnome-panel/wip/free-the-fish: 7/9] Free-the-fish: Clean up variable names



commit 1c22edeccee6bad3d9a5a99b37d5f635e32117fd
Author: Sebastian Geiger <sbastig gmx net>
Date:   Mon Jun 1 12:28:33 2015 +0200

    Free-the-fish: Clean up variable names

 gnome-panel/free-the-fish.c |  116 +++++++++++++++++++++---------------------
 1 files changed, 58 insertions(+), 58 deletions(-)
---
diff --git a/gnome-panel/free-the-fish.c b/gnome-panel/free-the-fish.c
index beccf25..959f5f7 100644
--- a/gnome-panel/free-the-fish.c
+++ b/gnome-panel/free-the-fish.c
@@ -4,47 +4,47 @@
 #include "free-the-fish.h"
 
 /* free the fish code */
-#define FISHFRAMES 8
-#define FISHORIGWIDTH 288
-#define FISHORIGHEIGHT 22
-#define FISHWIDTH (FISHORIGWIDTH/FISHFRAMES)
-#define FISHHEIGHT FISHORIGHEIGHT
-#define FISHCHECKTIMEOUT (g_random_int()%120*1000)
-#define FISHTIMEOUT 120
-#define FISHHIDETIMEOUT 80
-#define FISHXS 5
-#define FISHYS ((g_random_int() % 2) + 1)
-#define FISHXSHIDEFACTOR 2.5
-#define FISHYSHIDEFACTOR 2.5
-#define FISHPIXELSTOREMOVE(a, r, g, b) (a < 128 || (a < 255 && b > r && b > g))
+#define FISH_FRAMES 8
+#define FISH_ORIG_WIDTH 288
+#define FISH_ORIG_HEIGHT 22
+#define FISH_WIDTH (FISH_ORIG_WIDTH/FISH_FRAMES)
+#define FISH_HEIGHT FISH_ORIG_HEIGHT
+#define FISH_CHECK_TIMEOUT (g_random_int()%120*1000)
+#define FISH_TIMEOUT 120
+#define FISH_HIDE_TIMEOUT 80
+#define FISH_XS 5
+#define FISH_YS ((g_random_int() % 2) + 1)
+#define FISH_XS_HIDE_FACTOR 2.5
+#define FISH_YS_HIDE_FACTOR 2.5
+#define FISH_PIXEL_STORE_MOVE(a, r, g, b) (a < 128 || (a < 255 && b > r && b > g))
 
 /* Some important code copied from PonG */
-typedef struct _AppletContainer AppletContainer;
-struct _AppletContainer {
+typedef struct _FreeTheFish FreeTheFish;
+struct _FreeTheFish {
         GdkWindow *win;
         gboolean hide_mode;
         int state;
         int x, y, xs, ys;
         int handler;
-        cairo_pattern_t *fish[FISHFRAMES];
-        cairo_pattern_t *fish_reverse[FISHFRAMES];
+        cairo_pattern_t *fish_pattern[FISH_FRAMES];
+        cairo_pattern_t *fish_pattern_reverse[FISH_FRAMES];
         cairo_region_t *fish_shape;
         cairo_region_t *fish_shape_reverse;
 };
-static AppletContainer fish = {NULL};
+static FreeTheFish fish = {NULL};
 
 static void
 fish_kill (void)
 {
         int i;
 
-        for (i = 0; i < FISHFRAMES; i++) {
-                if (fish.fish[i] != NULL)
-                        cairo_pattern_destroy (fish.fish[i]);
-                fish.fish[i] = NULL;
-                if (fish.fish_reverse[i] != NULL)
-                        cairo_pattern_destroy (fish.fish_reverse[i]);
-                fish.fish_reverse[i] = NULL;
+        for (i = 0; i < FISH_FRAMES; i++) {
+                if (fish.fish_pattern[i] != NULL)
+                        cairo_pattern_destroy (fish.fish_pattern[i]);
+                fish.fish_pattern[i] = NULL;
+                if (fish.fish_pattern_reverse[i] != NULL)
+                        cairo_pattern_destroy (fish.fish_pattern_reverse[i]);
+                fish.fish_pattern_reverse[i] = NULL;
         }
 
         if (fish.fish_shape != NULL)
@@ -59,7 +59,7 @@ fish_kill (void)
 
         g_source_remove ((guint) fish.handler);
 
-        memset (&fish, 0, sizeof (AppletContainer));
+        memset (&fish, 0, sizeof (FreeTheFish));
 
         gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
 }
@@ -72,9 +72,9 @@ fish_draw (int orient, int frame)
         cairo_t *cr;
         int shape_offset;
 
-        pattern = orient ? fish.fish[frame] : fish.fish_reverse[frame];
+        pattern = orient ? fish.fish_pattern[frame] : fish.fish_pattern_reverse[frame];
         region = orient ? fish.fish_shape : fish.fish_shape_reverse;
-        shape_offset = orient ? -frame : frame + 1 - FISHFRAMES;
+        shape_offset = orient ? -frame : frame + 1 - FISH_FRAMES;
 
         cr = gdk_cairo_create (fish.win);
         cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
@@ -86,7 +86,7 @@ fish_draw (int orient, int frame)
         gdk_window_set_background_pattern (fish.win, pattern);
 
         gdk_window_shape_combine_region (fish.win, region,
-                                         shape_offset * FISHWIDTH, 0);
+                                         shape_offset * FISH_WIDTH, 0);
 }
 
 static gboolean
@@ -97,24 +97,24 @@ fish_move (gpointer data)
 
         fish.x += fish.xs;
         fish.y += fish.ys;
-        if (fish.x <= -FISHWIDTH ||
+        if (fish.x <= -FISH_WIDTH ||
             fish.x >= gdk_screen_width ()) {
                 fish_kill ();
                 return FALSE;
         }
         if (fish.y <= 0 ||
-            fish.y >= gdk_screen_height () - FISHHEIGHT ||
+            fish.y >= gdk_screen_height () - FISH_HEIGHT ||
             g_random_int() % (fish.hide_mode?10:50) == 0)
                 fish.ys = -fish.ys;
 
         fish.state ++;
         if (fish.hide_mode) {
                 fish.state ++;
-                if (fish.state >= 2*FISHFRAMES)
+                if (fish.state >= 2* FISH_FRAMES)
                         fish.state = 0;
                 if (fish.state % 2 == 0)
                         change = TRUE;
-        } else if (fish.state >= FISHFRAMES) {
+        } else if (fish.state >= FISH_FRAMES) {
                 fish.state = 0;
                 change = TRUE;
         }
@@ -145,11 +145,11 @@ fish_handle_event (GdkEvent *event)
                 case GDK_BUTTON_PRESS:
                 case GDK_2BUTTON_PRESS:
                 case GDK_3BUTTON_PRESS:
-                        g_source_remove (fish.handler);
-                        fish.handler = g_timeout_add (FISHHIDETIMEOUT,
+                        g_source_remove ((guint) fish.handler);
+                        fish.handler = g_timeout_add (FISH_HIDE_TIMEOUT,
                                                       fish_move, NULL);
-                        fish.xs *= FISHXSHIDEFACTOR;
-                        fish.ys *= FISHYSHIDEFACTOR;
+                        fish.xs *= FISH_XS_HIDE_FACTOR;
+                        fish.ys *= FISH_YS_HIDE_FACTOR;
                         fish.hide_mode = TRUE;
                         if (fish.xs > 0) {
                                 if (fish.x < (gdk_screen_width () / 2))
@@ -191,7 +191,7 @@ fish_unsea (cairo_surface_t *surface)
                         r = ((*p)>>16)&0xff;
                         g = ((*p)>> 8)&0xff;
                         b = ((*p)>> 0)&0xff;
-                        if (FISHPIXELSTOREMOVE(a, r, g, b))
+                        if (FISH_PIXEL_STORE_MOVE(a, r, g, b))
                                 *p = 0;
                 }
         }
@@ -207,10 +207,10 @@ get_fish_frame (GdkWindow *win, cairo_surface_t *source, int frame)
         /* We need an Xlib surface for gdk_window_set_background_pattern() */
         surface = gdk_window_create_similar_surface (win,
                                                      CAIRO_CONTENT_COLOR_ALPHA,
-                                                     FISHWIDTH, FISHHEIGHT);
+                                                     FISH_WIDTH, FISH_HEIGHT);
 
         cr = cairo_create (surface);
-        cairo_set_source_surface (cr, source, - frame * FISHWIDTH, 0);
+        cairo_set_source_surface (cr, source, - frame * FISH_WIDTH, 0);
         cairo_paint (cr);
         cairo_destroy (cr);
 
@@ -231,13 +231,13 @@ get_fish_frame_reverse (GdkWindow *win, cairo_surface_t *source, int frame)
         /* We need an Xlib surface for gdk_window_set_background_pattern() */
         surface = gdk_window_create_similar_surface (win,
                                                      CAIRO_CONTENT_COLOR_ALPHA,
-                                                     FISHWIDTH, FISHHEIGHT);
+                                                     FISH_WIDTH, FISH_HEIGHT);
 
         cr = cairo_create (surface);
         cairo_matrix_init_identity (&matrix);
         cairo_matrix_scale (&matrix, -1.0, 1.0);
         cairo_set_matrix (cr, &matrix);
-        cairo_set_source_surface (cr, source, - (frame + 1) * FISHWIDTH, 0);
+        cairo_set_source_surface (cr, source, - (frame + 1) * FISH_WIDTH, 0);
         cairo_paint (cr);
         cairo_destroy (cr);
 
@@ -263,14 +263,14 @@ get_fish_shape_reverse (cairo_surface_t *surface)
 
         surface_reverse = cairo_surface_create_similar (surface,
                                                         CAIRO_CONTENT_COLOR_ALPHA,
-                                                        FISHORIGWIDTH,
-                                                        FISHORIGHEIGHT);
+                                                        FISH_ORIG_WIDTH,
+                                                        FISH_ORIG_HEIGHT);
 
         cr = cairo_create (surface_reverse);
         cairo_matrix_init_identity (&matrix);
         cairo_matrix_scale (&matrix, -1.0, 1.0);
         cairo_set_matrix (cr, &matrix);
-        cairo_set_source_surface (cr, surface, -FISHORIGWIDTH, 0);
+        cairo_set_source_surface (cr, surface, -FISH_ORIG_WIDTH, 0);
         cairo_paint (cr);
         cairo_destroy (cr);
 
@@ -317,8 +317,8 @@ check_screen (void)
                 return;
         }
 
-        if (cairo_image_surface_get_width (surface) != FISHORIGWIDTH ||
-            cairo_image_surface_get_height (surface) != FISHORIGHEIGHT) {
+        if (cairo_image_surface_get_width (surface) != FISH_ORIG_WIDTH ||
+            cairo_image_surface_get_height (surface) != FISH_ORIG_HEIGHT) {
                 cairo_surface_destroy (surface);
                 return;
         }
@@ -329,25 +329,25 @@ check_screen (void)
 
         fish.state = 0;
         fish.hide_mode = FALSE;
-        fish.x = orient ? -FISHWIDTH : gdk_screen_width ();
-        fish.y = (g_random_int() % (gdk_screen_height() - FISHHEIGHT - 2)) + 1;
-        fish.xs = orient ? FISHXS : -FISHXS;
-        fish.ys = FISHYS;
+        fish.x = orient ? -FISH_WIDTH : gdk_screen_width ();
+        fish.y = (g_random_int() % (gdk_screen_height() - FISH_HEIGHT - 2)) + 1;
+        fish.xs = orient ? FISH_XS : -FISH_XS;
+        fish.ys = FISH_YS;
 
         attributes.window_type = GDK_WINDOW_TEMP;
         attributes.x = fish.x;
         attributes.y = fish.y;
-        attributes.width = FISHWIDTH;
-        attributes.height = FISHHEIGHT;
+        attributes.width = FISH_WIDTH;
+        attributes.height = FISH_HEIGHT;
         attributes.wclass = GDK_INPUT_OUTPUT;
         attributes.event_mask = GDK_BUTTON_PRESS_MASK;
 
         fish.win = gdk_window_new (NULL, &attributes,
                                    GDK_WA_X | GDK_WA_Y);
 
-        for (i = 0; i < FISHFRAMES; i++) {
-                fish.fish[i] = get_fish_frame (fish.win, surface, i);
-                fish.fish_reverse[i] = get_fish_frame_reverse (fish.win, surface, i);
+        for (i = 0; i < FISH_FRAMES; i++) {
+                fish.fish_pattern[i] = get_fish_frame (fish.win, surface, i);
+                fish.fish_pattern_reverse[i] = get_fish_frame_reverse (fish.win, surface, i);
         }
 
         fish.fish_shape = get_fish_shape (surface);
@@ -360,7 +360,7 @@ check_screen (void)
 
         gdk_event_handler_set ((GdkEventFunc)fish_handle_event, NULL, NULL);
 
-        fish.handler = g_timeout_add (FISHTIMEOUT, fish_move, NULL);
+        fish.handler = g_timeout_add (FISH_TIMEOUT, fish_move, NULL);
 }
 
 static guint screen_check_id = 0;
@@ -372,7 +372,7 @@ check_screen_timeout (gpointer data)
 
         check_screen ();
 
-        screen_check_id = g_timeout_add (FISHCHECKTIMEOUT,
+        screen_check_id = g_timeout_add (FISH_CHECK_TIMEOUT,
                                          check_screen_timeout, NULL);
         return FALSE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]