2 * Sherman's aquarium - Applet v3.0.1
4 * (Formely known as aquarium applet.)
6 * Copyright (C) 2002-2003 Jonas Aaberg <cja@gmx.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You did not receive a copy of the GNU General Public License along with
19 * this program; chances are, you already have at least 10 copies of this
20 * license somewhere on your system. If you still want it, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 * This applet was once based upon timecop's <timecop@japan.co.jp> fishmon,
25 * but not much is now left of his code. (draw.c is mainly his code)
32 #include <sys/types.h>
42 #define GAI_APPLET_DEFINES
43 #include "../config.h"
54 #include "thermometer.h"
56 #include "background.h"
60 #include "soundeffects.h"
66 /* keeps track of mouse focus */
67 static int over_ruled;
68 static AquariumData ad;
69 static General_settings general_settings;
71 /* Only there for screensaver compability */
72 int fullscreen = 0, window_id = -1;
75 static void aquarium_enter(gpointer d)
81 static void aquarium_keypress(int key, gpointer d)
87 static void aquarium_joystick(GaiFlagsJoystick flags, gpointer d)
93 static void aquarium_leave(gpointer d)
99 static void mouse_action(int flag, char *option)
101 if(flag == MOUSE_OFF)
104 if(flag == MOUSE_RUN){
110 static void aquarium_mouseclick_left(int x, int y, gpointer d)
112 mouse_action(general_settings.mouse_left, general_settings.mouse_left_option);
115 static void aquarium_mouseclick_middle(int x, int y, gpointer d)
117 mouse_action(general_settings.mouse_middle, general_settings.mouse_middle_option);
120 static void aquarium_mouseclick_updown(int dir, gpointer d)
122 if(dir == GDK_SCROLL_UP)
123 mouse_action(general_settings.mouse_up, general_settings.mouse_up_option);
124 if(dir == GDK_SCROLL_DOWN)
125 mouse_action(general_settings.mouse_down, general_settings.mouse_down_option);
130 void aquarium_change(int orient, int new_w, int new_h, gpointer d)
132 static int old_xmax = -1, old_ymax = -1;
135 ad.ymin = gai_scale(YMIN);
136 ad.xmin = gai_scale(XMIN);
138 if(gai_applet_mode() == GAI_DOCKAPP){
139 if(general_settings.ratio_width > general_settings.ratio_height){
140 ad.xmax = gai_get_size()*general_settings.ratio_width/general_settings.ratio_height - 2*ad.xmin;
141 ad.ymax = gai_get_size() - 2*ad.ymin;
143 ad.xmax = gai_get_size() - 2*ad.xmin;
144 ad.ymax = gai_get_size()*general_settings.ratio_height/general_settings.ratio_width - 2*ad.ymin;
146 if(old_ymax != ad.ymax || old_xmax != ad.xmax)
147 gai_background_set(ad.xmax+2*ad.xmin, ad.ymax+2*ad.ymin, GAI_BACKGROUND_MAX_SIZE_NONE, TRUE);
149 if(orient == GAI_HORIZONTAL){
150 if(general_settings.ratio_width > general_settings.ratio_height){
151 ad.xmax = gai_get_size()*general_settings.ratio_width/general_settings.ratio_height - 2*ad.xmin;
152 ad.ymax = gai_get_size() - 2*ad.ymin;
154 ad.ymax = gai_get_size() - 2*ad.ymin;
155 ad.xmax = gai_get_size()*general_settings.ratio_height/general_settings.ratio_width - 2*ad.xmin;
157 if(old_ymax != ad.ymax || old_xmax != ad.xmax)
158 gai_background_set(ad.xmax+2*ad.xmin, ad.ymax+2*ad.ymin, GAI_BACKGROUND_MAX_SIZE_NONE, TRUE);
161 if(general_settings.ratio_width > general_settings.ratio_height){
162 ad.ymax = gai_get_size() * general_settings.ratio_width/general_settings.ratio_height - 2*ad.ymin;
163 ad.xmax = gai_get_size() - 2*ad.xmin;
165 ad.xmax = gai_get_size() - 2*ad.xmin;
166 ad.ymax = gai_get_size()*general_settings.ratio_height/general_settings.ratio_width - 2*ad.ymin;
168 if(old_ymax != ad.ymax || old_xmax != ad.xmax)
169 gai_background_set(ad.ymax+2*ad.ymin,ad.xmax+2*ad.xmin, GAI_BACKGROUND_MAX_SIZE_NONE, TRUE);
176 ad.virtual_aquarium_x = ad.xmax + 2 * VIRTUAL_AQUARIUM_DX;
177 ad.virtual_aquarium_y = ad.ymax + 2 * VIRTUAL_AQUARIUM_DX;
182 ad.rgb = g_malloc0((ad.xmax + 2) * (ad.ymax + 2) * 3);
183 ad.bgr = g_malloc0((ad.xmax + 2) * (ad.ymax + 2) * 3);
194 void prepare_graphics(void)
219 void aquarium_update(gpointer d)
221 static gboolean inited = 0;
222 /* If this function is called during reload of images,
223 just quit and wait until that is done. */
230 if(gai_applet_mode() == GAI_DOCKAPP){
231 if(ad.xmax < ad.ymax){
232 aquarium_change(gai_get_orient(),
234 gai_get_size()*general_settings.ratio_height/general_settings.ratio_width,
237 aquarium_change(gai_get_orient(),
238 gai_get_size()*general_settings.ratio_width/general_settings.ratio_height,
243 if(gai_get_orient() == GAI_HORIZONTAL){
244 aquarium_change(gai_get_orient(),
246 gai_get_size()*general_settings.ratio_height/general_settings.ratio_width,
251 aquarium_change(gai_get_orient(),
252 gai_get_size()*general_settings.ratio_width/general_settings.ratio_height,
259 if(ad.drawingarea == NULL)
260 ad.drawingarea = gai_get_drawingarea();
262 memcpy(ad.rgb, ad.bgr, ad.ymax * ad.xmax * 3);
264 /* If the mouse over function is completly domiating,
265 then, only call the mouse over function */
268 leds_update(DRAW_BEFORE);
269 thermometer_update(DRAW_BEFORE);
270 clock_update(DRAW_BEFORE);
272 xmms_sn_update(DRAW_BEFORE);
274 date_update(DRAW_BEFORE);
281 thermometer_update(DRAW_AFTER);
282 clock_update(DRAW_AFTER);
284 xmms_sn_update(DRAW_AFTER);
286 date_update(DRAW_AFTER);
287 leds_update(DRAW_AFTER);
290 over_ruled = over_update(ad.proximity);
292 ad.gc = gai_get_gc();
294 /* Draw it, not using gai */
295 gdk_draw_rgb_image(ad.drawingarea->window, ad.gc, ad.xmin, ad.ymin, ad.xmax, ad.ymax,
296 GDK_RGB_DITHER_NONE,ad.rgb, ad.xmax*3);
302 void aquarium_free_all()
322 void aquarium_reload_all()
333 /* We are loading fishes before aquarium_change gets activated, since it needs to call bottom and bg */
334 // printf("fish init\n");
336 bottom_init(); /* Must be after fish, because it draw bottom creatures. */
341 /* This function (re)sets all the global variables to their default */
342 /* Some globals, don't have a default, those are not set ofcourse */
347 memset(&ad, 0, sizeof(AquariumData));
349 ad.rnd = g_rand_new();
351 clock_load_settings();
352 date_load_settings();
354 xmms_sn_load_settings();
357 bubble_load_settings();
359 thermometer_load_settings();
360 over_load_settings();
361 leds_load_settings();
364 background_load_settings();
365 bottom_load_settings();
367 fish_load_settings();
368 general_load_settings();
369 sound_load_settings();
370 tetris_load_settings();
372 /* Default at start up is horizontal gnome-panel */
376 if(general_settings.ratio_width > general_settings.ratio_height){
377 ad.xmax = (XMAX+2*XMIN)*general_settings.ratio_width/general_settings.ratio_height - 2*XMIN;
379 ad.ymax = (YMAX+2*YMIN)*general_settings.ratio_height/general_settings.ratio_width - 2*YMIN;
385 ad.virtual_aquarium_x = XMAX + 2 * VIRTUAL_AQUARIUM_DX;
386 ad.virtual_aquarium_y = YMAX + 2 * VIRTUAL_AQUARIUM_DY;
387 ad.viewpoint_start_x = VIEWPOINT_START_X;
388 ad.viewpoint_start_y = VIEWPOINT_START_Y;
396 ad.drawingarea = NULL;
398 ad.special_action = 0;
404 int main(int argc, char **argv)
407 gai_init2(&applet_defines ,&argc, &argv);
410 /* Load saved settings and reset others */
413 ad.rgb = g_malloc0((ad.xmax + 2) * (ad.ymax + 2) * 3);
414 ad.bgr = g_malloc0((ad.xmax + 2) * (ad.ymax + 2) * 3);
420 gai_background_set(ad.xmax+2*ad.xmin, ad.ymax+2*ad.ymin, GAI_BACKGROUND_MAX_SIZE_NONE, TRUE);
422 gai_preferences2("Sherman's aquarium - Preferences",
424 "You cannot do anything dangerous with this applet,\n"
425 "so just play around and look at what the applet does.\n"
426 "If you still have some questions, feel free to mail me, cja@gmx.net.\n\n"
427 "Thanks for trying Sherman's aquarium!\n\n"
428 "http://aquariumapplet.sourceforge.net",
429 (GaiCallback0 *)pref_restart, NULL);
431 /* 20 frames per second */
432 gai_signal_on_update((GaiCallback0 *)aquarium_update, 1000/50, NULL);
433 gai_signal_on_enter((GaiCallback0 *)aquarium_enter, NULL);
434 gai_signal_on_leave((GaiCallback0 *)aquarium_leave, NULL);
435 gai_signal_on_change((GaiCallback3 *)aquarium_change, NULL);
436 gai_signal_on_keypress((GaiCallback1 *)aquarium_keypress, NULL);
437 gai_signal_on_joystick((GaiCallback1 *)aquarium_joystick, NULL);
439 gai_signal_on_mouse_button_click((GaiCallback2 *)aquarium_mouseclick_left, GAI_MOUSE_BUTTON_1, NULL);
440 gai_signal_on_mouse_button_click((GaiCallback2 *)aquarium_mouseclick_middle, GAI_MOUSE_BUTTON_2, NULL);
441 gai_signal_on_scroll_buttons((GaiCallback1 *)aquarium_mouseclick_updown, NULL);
449 AquariumData *aquarium_get_settings_ptr(void)
454 unsigned char *aquarium_install_path(void)
456 return applet_defines.image_path;
459 General_settings *general_get_settings_ptr(void)
461 return &general_settings;
465 void aquarium_draw_image(int x, int y, int idx, int rev, SA_Image *image)
467 draw_image(x, y, idx, rev, image);
470 void aquarium_draw_pic_alpha(SA_Image *image, int w, int h, int x, int y, int idx, int alpha)
472 draw_pic_alpha(image->image, w, h, x, y, idx, alpha);
476 void aquarium_clean_image(int x, int y, int w, int h)
481 /* This is just to keep background.c happy */
482 void grab_screen_image (Screen *s, Window w)