[gnome-panel] Free-the-fish: Rename prefix PHSH to FISH
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] Free-the-fish: Rename prefix PHSH to FISH
- Date: Tue, 2 Jun 2015 15:40:03 +0000 (UTC)
commit b7156cee0deeb9ca4cba0a3711be19667b0857f5
Author: Sebastian Geiger <sbastig gmx net>
Date: Tue Jun 2 14:16:50 2015 +0200
Free-the-fish: Rename prefix PHSH to FISH
gnome-panel/free-the-fish.c | 258 +++++++++++++++++++++---------------------
1 files changed, 129 insertions(+), 129 deletions(-)
---
diff --git a/gnome-panel/free-the-fish.c b/gnome-panel/free-the-fish.c
index 954be7d..9681abc 100644
--- a/gnome-panel/free-the-fish.c
+++ b/gnome-panel/free-the-fish.c
@@ -3,141 +3,141 @@
#include "free-the-fish.h"
-/* phish code */
-#define PHSHFRAMES 8
-#define PHSHORIGWIDTH 288
-#define PHSHORIGHEIGHT 22
-#define PHSHWIDTH (PHSHORIGWIDTH/PHSHFRAMES)
-#define PHSHHEIGHT PHSHORIGHEIGHT
-#define PHSHCHECKTIMEOUT (g_random_int()%120*1000)
-#define PHSHTIMEOUT 120
-#define PHSHHIDETIMEOUT 80
-#define PHSHXS 5
-#define PHSHYS ((g_random_int() % 2) + 1)
-#define PHSHXSHIDEFACTOR 2.5
-#define PHSHYSHIDEFACTOR 2.5
-#define PHSHPIXELSTOREMOVE(a, r, g, b) (a < 128 || (a < 255 && b > r && b > g))
+/* free the fish code */
+#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 *phsh[PHSHFRAMES];
- cairo_pattern_t *phsh_reverse[PHSHFRAMES];
- cairo_region_t *phsh_shape;
- cairo_region_t *phsh_shape_reverse;
+ 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 phsh = {NULL};
+static FreeTheFish fish = {NULL};
static void
-phsh_kill (void)
+fish_kill (void)
{
int i;
- for (i = 0; i < PHSHFRAMES; i++) {
- if (phsh.phsh[i] != NULL)
- cairo_pattern_destroy (phsh.phsh[i]);
- phsh.phsh[i] = NULL;
- if (phsh.phsh_reverse[i] != NULL)
- cairo_pattern_destroy (phsh.phsh_reverse[i]);
- phsh.phsh_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 (phsh.phsh_shape != NULL)
- cairo_region_destroy (phsh.phsh_shape);
- phsh.phsh_shape = NULL;
+ if (fish.fish_shape != NULL)
+ cairo_region_destroy (fish.fish_shape);
+ fish.fish_shape = NULL;
- if (phsh.phsh_shape_reverse != NULL)
- cairo_region_destroy (phsh.phsh_shape_reverse);
- phsh.phsh_shape_reverse = NULL;
+ if (fish.fish_shape_reverse != NULL)
+ cairo_region_destroy (fish.fish_shape_reverse);
+ fish.fish_shape_reverse = NULL;
- gdk_window_destroy (phsh.win);
+ gdk_window_destroy (fish.win);
- g_source_remove (phsh.handler);
+ g_source_remove (fish.handler);
- memset (&phsh, 0, sizeof (AppletContainer));
+ memset (&fish, 0, sizeof (FreeTheFish));
gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
}
static void
-phsh_draw (int orient, int frame)
+fish_draw (int orient, int frame)
{
cairo_pattern_t *pattern;
cairo_region_t *region;
cairo_t *cr;
int shape_offset;
- pattern = orient ? phsh.phsh[frame] : phsh.phsh_reverse[frame];
- region = orient ? phsh.phsh_shape : phsh.phsh_shape_reverse;
- shape_offset = orient ? -frame : frame + 1 - PHSHFRAMES;
+ 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 - FISH_FRAMES;
- cr = gdk_cairo_create (phsh.win);
+ cr = gdk_cairo_create (fish.win);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source (cr, pattern);
cairo_paint (cr);
cairo_destroy (cr);
/* Yes. Don't ask. */
- gdk_window_set_background_pattern (phsh.win, pattern);
+ gdk_window_set_background_pattern (fish.win, pattern);
- gdk_window_shape_combine_region (phsh.win, region,
- shape_offset * PHSHWIDTH, 0);
+ gdk_window_shape_combine_region (fish.win, region,
+ shape_offset * FISH_WIDTH, 0);
}
static gboolean
-phsh_move (gpointer data)
+fish_move (gpointer data)
{
int orient, frame;
gboolean change = TRUE;
- phsh.x += phsh.xs;
- phsh.y += phsh.ys;
- if (phsh.x <= -PHSHWIDTH ||
- phsh.x >= gdk_screen_width ()) {
- phsh_kill ();
+ fish.x += fish.xs;
+ fish.y += fish.ys;
+ if (fish.x <= -FISH_WIDTH ||
+ fish.x >= gdk_screen_width ()) {
+ fish_kill ();
return FALSE;
}
- if (phsh.y <= 0 ||
- phsh.y >= gdk_screen_height () - PHSHHEIGHT ||
- g_random_int() % (phsh.hide_mode?10:50) == 0)
- phsh.ys = -phsh.ys;
-
- phsh.state ++;
- if (phsh.hide_mode) {
- phsh.state ++;
- if (phsh.state >= 2*PHSHFRAMES)
- phsh.state = 0;
- if (phsh.state % 2 == 0)
+ if (fish.y <= 0 ||
+ 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* FISH_FRAMES)
+ fish.state = 0;
+ if (fish.state % 2 == 0)
change = TRUE;
- } else if (phsh.state >= PHSHFRAMES) {
- phsh.state = 0;
+ } else if (fish.state >= FISH_FRAMES) {
+ fish.state = 0;
change = TRUE;
}
- frame = phsh.state / (phsh.hide_mode?2:1);
- orient = phsh.xs >= 0 ? 0 : 1;
+ frame = fish.state / (fish.hide_mode?2:1);
+ orient = fish.xs >= 0 ? 0 : 1;
if (change)
- phsh_draw (orient, frame);
+ fish_draw (orient, frame);
- gdk_window_move (phsh.win, phsh.x, phsh.y);
- gdk_window_raise (phsh.win);
+ gdk_window_move (fish.win, fish.x, fish.y);
+ gdk_window_raise (fish.win);
return TRUE;
}
static void
-phsh_handle_event (GdkEvent *event)
+fish_handle_event (GdkEvent *event)
{
- if (event->any.window != phsh.win)
+ if (event->any.window != fish.win)
goto out;
- if (phsh.hide_mode)
+ if (fish.hide_mode)
goto out;
switch (event->type) {
@@ -145,18 +145,18 @@ phsh_handle_event (GdkEvent *event)
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
- g_source_remove (phsh.handler);
- phsh.handler = g_timeout_add (PHSHHIDETIMEOUT,
- phsh_move, NULL);
- phsh.xs *= PHSHXSHIDEFACTOR;
- phsh.ys *= PHSHYSHIDEFACTOR;
- phsh.hide_mode = TRUE;
- if (phsh.xs > 0) {
- if (phsh.x < (gdk_screen_width () / 2))
- phsh.xs *= -1;
+ g_source_remove (fish.handler);
+ fish.handler = g_timeout_add (FISH_HIDE_TIMEOUT,
+ fish_move, NULL);
+ 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))
+ fish.xs *= -1;
} else {
- if (phsh.x > (gdk_screen_width () / 2))
- phsh.xs *= -1;
+ if (fish.x > (gdk_screen_width () / 2))
+ fish.xs *= -1;
}
break;
default:
@@ -168,7 +168,7 @@ out:
}
static void
-phsh_unsea (cairo_surface_t *surface)
+fish_unsea (cairo_surface_t *surface)
{
guchar *pixels = cairo_image_surface_get_data (surface);
int rs = cairo_image_surface_get_stride (surface);
@@ -185,14 +185,14 @@ phsh_unsea (cairo_surface_t *surface)
r = ((*p)>>16)&0xff;
g = ((*p)>> 8)&0xff;
b = ((*p)>> 0)&0xff;
- if (PHSHPIXELSTOREMOVE(a, r, g, b))
+ if (FISH_PIXEL_STORE_MOVE(a, r, g, b))
*p = 0;
}
}
}
static cairo_pattern_t *
-get_phsh_frame (GdkWindow *win, cairo_surface_t *source, int frame)
+get_fish_frame (GdkWindow *win, cairo_surface_t *source, int frame)
{
cairo_pattern_t *pattern;
cairo_surface_t *surface;
@@ -201,10 +201,10 @@ get_phsh_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,
- PHSHWIDTH, PHSHHEIGHT);
+ FISH_WIDTH, FISH_HEIGHT);
cr = cairo_create (surface);
- cairo_set_source_surface (cr, source, - frame * PHSHWIDTH, 0);
+ cairo_set_source_surface (cr, source, - frame * FISH_WIDTH, 0);
cairo_paint (cr);
cairo_destroy (cr);
@@ -215,7 +215,7 @@ get_phsh_frame (GdkWindow *win, cairo_surface_t *source, int frame)
}
static cairo_pattern_t *
-get_phsh_frame_reverse (GdkWindow *win, cairo_surface_t *source, int frame)
+get_fish_frame_reverse (GdkWindow *win, cairo_surface_t *source, int frame)
{
cairo_pattern_t *pattern;
cairo_surface_t *surface;
@@ -225,13 +225,13 @@ get_phsh_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,
- PHSHWIDTH, PHSHHEIGHT);
+ 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) * PHSHWIDTH, 0);
+ cairo_set_source_surface (cr, source, - (frame + 1) * FISH_WIDTH, 0);
cairo_paint (cr);
cairo_destroy (cr);
@@ -242,13 +242,13 @@ get_phsh_frame_reverse (GdkWindow *win, cairo_surface_t *source, int frame)
}
static cairo_region_t *
-get_phsh_shape (cairo_surface_t *surface)
+get_fish_shape (cairo_surface_t *surface)
{
return gdk_cairo_region_create_from_surface (surface);
}
static cairo_region_t *
-get_phsh_shape_reverse (cairo_surface_t *surface)
+get_fish_shape_reverse (cairo_surface_t *surface)
{
cairo_region_t *region;
cairo_surface_t *surface_reverse;
@@ -257,14 +257,14 @@ get_phsh_shape_reverse (cairo_surface_t *surface)
surface_reverse = cairo_surface_create_similar (surface,
CAIRO_CONTENT_COLOR_ALPHA,
- PHSHORIGWIDTH,
- PHSHORIGHEIGHT);
+ 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, -PHSHORIGWIDTH, 0);
+ cairo_set_source_surface (cr, surface, -FISH_ORIG_WIDTH, 0);
cairo_paint (cr);
cairo_destroy (cr);
@@ -279,82 +279,82 @@ static void
check_screen (void)
{
GdkWindowAttr attributes;
- GdkPixbuf *phsh_pixbuf;
+ GdkPixbuf *fish_pixbuf;
int width, height;
cairo_surface_t *surface;
cairo_t *cr;
int orient;
int i;
- if (phsh.win != NULL)
+ if (fish.win != NULL)
return;
- phsh_pixbuf = gdk_pixbuf_new_from_resource ("/org/gnome/panel/anim/wanda.png", NULL);
+ fish_pixbuf = gdk_pixbuf_new_from_resource ("/org/gnome/panel/anim/wanda.png", NULL);
- if (phsh_pixbuf == NULL)
+ if (fish_pixbuf == NULL)
return;
- width = gdk_pixbuf_get_width (phsh_pixbuf);
- height = gdk_pixbuf_get_height (phsh_pixbuf);
+ width = gdk_pixbuf_get_width (fish_pixbuf);
+ height = gdk_pixbuf_get_height (fish_pixbuf);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
cr = cairo_create (surface);
- gdk_cairo_set_source_pixbuf (cr, phsh_pixbuf, 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, fish_pixbuf, 0, 0);
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
cairo_destroy (cr);
- g_object_unref (phsh_pixbuf);
+ g_object_unref (fish_pixbuf);
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy (surface);
return;
}
- if (cairo_image_surface_get_width (surface) != PHSHORIGWIDTH ||
- cairo_image_surface_get_height (surface) != PHSHORIGHEIGHT) {
+ if (cairo_image_surface_get_width (surface) != FISH_ORIG_WIDTH ||
+ cairo_image_surface_get_height (surface) != FISH_ORIG_HEIGHT) {
cairo_surface_destroy (surface);
return;
}
- phsh_unsea (surface);
+ fish_unsea (surface);
orient = g_random_int() % 2;
- phsh.state = 0;
- phsh.hide_mode = FALSE;
- phsh.x = orient ? -PHSHWIDTH : gdk_screen_width ();
- phsh.y = (g_random_int() % (gdk_screen_height() - PHSHHEIGHT - 2)) + 1;
- phsh.xs = orient ? PHSHXS : -PHSHXS;
- phsh.ys = PHSHYS;
+ fish.state = 0;
+ fish.hide_mode = FALSE;
+ 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 = phsh.x;
- attributes.y = phsh.y;
- attributes.width = PHSHWIDTH;
- attributes.height = PHSHHEIGHT;
+ attributes.x = fish.x;
+ attributes.y = fish.y;
+ attributes.width = FISH_WIDTH;
+ attributes.height = FISH_HEIGHT;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.event_mask = GDK_BUTTON_PRESS_MASK;
- phsh.win = gdk_window_new (NULL, &attributes,
+ fish.win = gdk_window_new (NULL, &attributes,
GDK_WA_X | GDK_WA_Y);
- for (i = 0; i < PHSHFRAMES; i++) {
- phsh.phsh[i] = get_phsh_frame (phsh.win, surface, i);
- phsh.phsh_reverse[i] = get_phsh_frame_reverse (phsh.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);
}
- phsh.phsh_shape = get_phsh_shape (surface);
- phsh.phsh_shape_reverse = get_phsh_shape_reverse (surface);
+ fish.fish_shape = get_fish_shape (surface);
+ fish.fish_shape_reverse = get_fish_shape_reverse (surface);
cairo_surface_destroy (surface);
- phsh_draw (0, 0);
- gdk_window_show (phsh.win);
+ fish_draw (0, 0);
+ gdk_window_show (fish.win);
- gdk_event_handler_set ((GdkEventFunc)phsh_handle_event, NULL, NULL);
+ gdk_event_handler_set ((GdkEventFunc)fish_handle_event, NULL, NULL);
- phsh.handler = g_timeout_add (PHSHTIMEOUT, phsh_move, NULL);
+ fish.handler = g_timeout_add (FISH_TIMEOUT, fish_move, NULL);
}
static guint screen_check_id = 0;
@@ -366,7 +366,7 @@ check_screen_timeout (gpointer data)
check_screen ();
- screen_check_id = g_timeout_add (PHSHCHECKTIMEOUT,
+ 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]