Commit 814648e0 authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

added "themability", so that you can load up a different animation file

Sun Aug 23 23:24:30 1998  George Lebl  <jirka@5z.com>

        * fish/fish.c,fish/fish?.xpm,fish/fishanim.png,fish/Makefile.am:
          added "themability", so that you can load up a different
          animation file and change the speed in the config dialog
parent 4a477ac5
Sun Aug 23 23:24:30 1998 George Lebl <jirka@5z.com>
* fish/fish.c,fish/fish?.xpm,fish/fishanim.png,fish/Makefile.am:
added "themability", so that you can load up a different
animation file and change the speed in the config dialog
1998-08-23 Martin Baulig <martin@home-of-linux.org>
* cpuload: This applet now requires libgtop.
......
Sun Aug 23 23:24:30 1998 George Lebl <jirka@5z.com>
* fish/fish.c,fish/fish?.xpm,fish/fishanim.png,fish/Makefile.am:
added "themability", so that you can load up a different
animation file and change the speed in the config dialog
1998-08-23 Martin Baulig <martin@home-of-linux.org>
* cpuload: This applet now requires libgtop.
......
......@@ -22,11 +22,14 @@ fish_applet_LDADD = ../../panel/libpanel_applet.la \
fish_applet_LINK = $(CXXLINK)
FISH_BITMAPS = fishanim.png
EXTRA_DIST = \
fish_applet.desktop \
fish1.xpm \
fish2.xpm \
fish3.xpm
fish_applet.desktop \
$(FISH_BITMAPS)
fishbitmapsdir = $(datadir)/pixmaps/fish
fishbitmaps_DATA = $(FISH_BITMAPS)
sysdir = $(datadir)/applets/Amusements
sys_DATA = fish_applet.desktop
......
/* fish.c - The msot useless applet, it's an ugly fish drawing
/* fish.c - The most useless applet, it's an ugly fish drawing
* by the least sane person, yes you guessed, George, it's nice
* to break the monotony of finals
*/
......@@ -10,25 +10,29 @@
#include "applet-lib.h"
#include "applet-widget.h"
#include "fish1.xpm"
#include "fish2.xpm"
#include "fish3.xpm"
typedef struct _fish_properties fish_properties;
struct _fish_properties {
gchar * name;
char *name;
char *image;
int frames;
float speed;
};
static const fish_properties defaults = {
"Wanda"
static fish_properties defaults = {
"Wanda",
NULL,
3,
0.3
};
static fish_properties properties = { NULL };
static GtkWidget *applet;
static GdkImlibImage *pix[3];
static gint curpix = 0;
static GtkWidget *darea;
static GdkImlibImage *pix=NULL;
static int curpix = 0;
static int timeout_id = 0;
static GtkWidget * fortune_dialog = NULL;
static GtkWidget * fortune_label;
......@@ -36,165 +40,281 @@ static GtkWidget * fortune_label;
static void
load_properties(char *privcfgpath)
{
if (properties.name) g_free(properties.name);
char buf[256];
if(!defaults.image)
defaults.image = gnome_unconditional_pixmap_file ("fish/fishanim.png");
gnome_config_push_prefix(privcfgpath);
properties.name = gnome_config_get_string("fish/name");
gnome_config_pop_prefix();
gnome_config_push_prefix(privcfgpath);
g_free(properties.name);
g_snprintf(buf,256,"fish/name=%s",defaults.name);
properties.name = gnome_config_get_string(buf);
g_free(properties.image);
g_snprintf(buf,256,"fish/image=%s",defaults.image);
properties.image = gnome_config_get_string(buf);
g_snprintf(buf,256,"fish/frames=%d",defaults.frames);
properties.frames = gnome_config_get_int(buf);
g_snprintf(buf,256,"fish/speed=%f",defaults.speed);
properties.speed = gnome_config_get_float(buf);
gnome_config_pop_prefix();
if (properties.name == NULL) properties.name = g_strdup(defaults.name);
if(pix)
gdk_imlib_destroy_image(pix);
pix = gdk_imlib_load_image(properties.image);
gdk_imlib_render (pix, pix->rgb_width, pix->rgb_height);
}
static gchar *
splice_name(const gchar * format, const gchar * name)
static char *
splice_name(const char * format, const char * name)
{
gchar * buf;
gint len;
len = strlen(name) + strlen(format);
buf = g_malloc(len+1);
g_snprintf(buf, len, format, name);
return buf;
char * buf;
int len;
len = strlen(name) + strlen(format);
buf = g_malloc(len+1);
g_snprintf(buf, len, format, name);
return buf;
}
static void
apply_properties()
fish_draw(GtkWidget *darea)
{
gchar * tmp;
const gchar * title_format = _("%s the Fish");
const gchar * label_format = _("%s the GNOME Fish Says:");
if ( fortune_dialog != NULL ) {
tmp = splice_name(title_format, properties.name);
gtk_window_set_title(GTK_WINDOW(fortune_dialog), tmp);
g_free(tmp);
tmp = splice_name(label_format, properties.name);
gtk_label_set(GTK_LABEL(fortune_label), tmp);
g_free(tmp);
}
if(!GTK_WIDGET_REALIZED(darea))
return;
gdk_draw_pixmap(darea->window,
darea->style->fg_gc[GTK_WIDGET_STATE(darea)],
pix->pixmap,
(pix->rgb_width*curpix)/properties.frames, 0,
0, 0,
-1, -1);
}
static void
apply_cb(GnomePropertyBox * pb, gint page, gpointer data)
static int
fish_timeout(gpointer data)
{
gchar * new_name;
if (page != -1) return; /* Only honor global apply */
new_name = gtk_entry_get_text(GTK_ENTRY(data));
if (new_name) {
g_free(properties.name);
properties.name = g_strdup(new_name);
}
curpix++;
if(curpix>=properties.frames) curpix=0;
fish_draw(GTK_WIDGET(data));
apply_properties();
return TRUE;
}
static void
properties_dialog(AppletWidget * w, gpointer data)
static void
apply_properties(void)
{
GtkWidget * pb;
GtkWidget * vbox;
GtkWidget * entry;
GtkWidget * label;
pb = gnome_property_box_new();
gtk_window_set_title(GTK_WINDOW(pb), _("GNOME Fish Properties"));
vbox = gtk_vbox_new(GNOME_PAD, FALSE);
gtk_container_border_width(GTK_CONTAINER(vbox), GNOME_PAD);
char * tmp;
const char * title_format = _("%s the Fish");
const char * label_format = _("%s the GNOME Fish Says:");
GtkAllocation a;
if (fortune_dialog != NULL) {
tmp = splice_name(title_format, properties.name);
gtk_window_set_title(GTK_WINDOW(fortune_dialog), tmp);
g_free(tmp);
tmp = splice_name(label_format, properties.name);
gtk_label_set(GTK_LABEL(fortune_label), tmp);
g_free(tmp);
}
if(pix)
gdk_imlib_destroy_image(pix);
pix = gdk_imlib_load_image(properties.image);
gdk_imlib_render (pix, pix->rgb_width, pix->rgb_height);
label = gtk_label_new(_("Your GNOME Fish's Name:"));
entry = gtk_entry_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(darea),
pix->rgb_width/properties.frames,
pix->rgb_height);
gtk_entry_set_text(GTK_ENTRY(entry), properties.name);
gtk_widget_set_usize(darea,
pix->rgb_width/properties.frames,
pix->rgb_height);
gtk_signal_connect_object(GTK_OBJECT(entry), "changed",
GTK_SIGNAL_FUNC(gnome_property_box_changed),
GTK_OBJECT(pb));
if(timeout_id)
gtk_timeout_remove(timeout_id);
timeout_id = gtk_timeout_add(properties.speed*1000,
fish_timeout,darea);
}
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, GNOME_PAD);
gtk_box_pack_start(GTK_BOX(vbox), entry, TRUE, TRUE, GNOME_PAD);
static void
apply_cb(GnomePropertyBox * pb, int page, gpointer data)
{
char *s;
GtkWidget *name = gtk_object_get_data(GTK_OBJECT(pb),
"name");
GtkWidget *image = gtk_object_get_data(GTK_OBJECT(pb),
"image");
GtkAdjustment *frames =
gtk_object_get_data(GTK_OBJECT(pb), "frames");
GtkAdjustment *speed =
gtk_object_get_data(GTK_OBJECT(pb), "speed");
if (page != -1) return; /* Only honor global apply */
s = gtk_entry_get_text(GTK_ENTRY(name));
if (s) {
g_free(properties.name);
properties.name = g_strdup(s);
}
s = gtk_entry_get_text(GTK_ENTRY(image));
if (s) {
g_free(properties.image);
properties.image = g_strdup(s);
}
properties.frames = frames->value;
properties.speed = speed->value;
apply_properties();
}
gnome_property_box_append_page(GNOME_PROPERTY_BOX(pb), vbox,
gtk_label_new(_("Name")));
static void
close_cb(GnomePropertyBox * pb, gpointer data)
{
char *s;
GtkWidget *name = gtk_object_get_data(GTK_OBJECT(pb),
"name");
GtkWidget *image = gtk_object_get_data(GTK_OBJECT(pb),
"image");
gtk_signal_disconnect_by_data(GTK_OBJECT(name),pb);
gtk_signal_disconnect_by_data(GTK_OBJECT(image),pb);
}
gtk_signal_connect(GTK_OBJECT(pb), "apply", GTK_SIGNAL_FUNC(apply_cb),
entry);
static void
properties_dialog(AppletWidget *aw, gpointer data)
{
GtkWidget *pb;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *w;
GtkWidget *e;
GtkAdjustment *adj;
pb = gnome_property_box_new();
gtk_window_set_title(GTK_WINDOW(pb), _("GNOME Fish Properties"));
vbox = gtk_vbox_new(FALSE, GNOME_PAD);
gtk_container_border_width(GTK_CONTAINER(vbox), GNOME_PAD);
hbox = gtk_hbox_new(FALSE, GNOME_PAD);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
w = gtk_label_new(_("Your GNOME Fish's Name:"));
gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
e = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(e), properties.name);
gtk_box_pack_start(GTK_BOX(hbox), e, TRUE, TRUE, 0);
gtk_object_set_data(GTK_OBJECT(pb),"name",e);
gtk_signal_connect_object(GTK_OBJECT(e), "changed",
GTK_SIGNAL_FUNC(gnome_property_box_changed),
GTK_OBJECT(pb));
hbox = gtk_hbox_new(FALSE, GNOME_PAD);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
w = gtk_label_new(_("The Animation Filename:"));
gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
w = gnome_file_entry_new("fish_animation",_("Browse"));
gtk_box_pack_start(GTK_BOX(hbox),w,TRUE,TRUE,0);
e = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (w));
gtk_entry_set_text(GTK_ENTRY(e), properties.image);
gtk_object_set_data(GTK_OBJECT(pb),"image",e);
gtk_signal_connect_object(GTK_OBJECT(e), "changed",
GTK_SIGNAL_FUNC(gnome_property_box_changed),
GTK_OBJECT(pb));
hbox = gtk_hbox_new(FALSE, GNOME_PAD);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
w = gtk_label_new(_("Frames In Animation:"));
gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (properties.frames,
0.0, 255.0, 1.0, 5.0, 0.0);
w = gtk_spin_button_new(adj,0,0);
gtk_widget_set_usize(w,70,0);
gtk_box_pack_start(GTK_BOX(hbox),w,FALSE,FALSE,0);
gtk_object_set_data(GTK_OBJECT(pb),"frames",adj);
gtk_signal_connect_object(GTK_OBJECT(adj), "value_changed",
GTK_SIGNAL_FUNC(gnome_property_box_changed),
GTK_OBJECT(pb));
hbox = gtk_hbox_new(FALSE, GNOME_PAD);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
w = gtk_label_new(_("Pause per frame (s):"));
gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (properties.speed,
0.1, 10.0, 0.1, 1.0, 0.0);
w = gtk_spin_button_new(adj,0,2);
gtk_widget_set_usize(w,70,0);
gtk_box_pack_start(GTK_BOX(hbox),w,FALSE,FALSE,0);
gtk_object_set_data(GTK_OBJECT(pb),"speed",adj);
gtk_signal_connect_object(GTK_OBJECT(adj), "value_changed",
GTK_SIGNAL_FUNC(gnome_property_box_changed),
GTK_OBJECT(pb));
gnome_property_box_append_page(GNOME_PROPERTY_BOX(pb), vbox,
gtk_label_new(_("Fish")));
gtk_signal_connect(GTK_OBJECT(pb), "apply",
GTK_SIGNAL_FUNC(apply_cb),
NULL);
gtk_signal_connect(GTK_OBJECT(pb), "close",
GTK_SIGNAL_FUNC(close_cb),
NULL);
gtk_widget_show_all(pb);
gtk_widget_show_all(pb);
}
static void
update_fortune_dialog()
{
static GtkWidget * fortune_less = NULL;
if ( fortune_dialog == NULL ) {
fortune_dialog =
gnome_dialog_new("", GNOME_STOCK_BUTTON_CLOSE, NULL);
gnome_dialog_set_close(GNOME_DIALOG(fortune_dialog), TRUE);
gnome_dialog_close_hides(GNOME_DIALOG(fortune_dialog), TRUE);
fortune_less = gnome_less_new();
fortune_label = gtk_label_new("");
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(fortune_dialog)->vbox),
fortune_label,
FALSE, FALSE, GNOME_PAD);
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(fortune_dialog)->vbox),
fortune_less,
TRUE, TRUE, GNOME_PAD);
gnome_less_set_fixed_font(GNOME_LESS(fortune_less),TRUE);
gtk_widget_show(fortune_less);
gtk_widget_show(fortune_label);
apply_properties();
}
if (!GTK_WIDGET_VISIBLE(fortune_dialog)) gtk_widget_show(fortune_dialog);
gnome_less_show_command(GNOME_LESS(fortune_less), g_file_exists("/usr/games/fortune")?"/usr/games/fortune":"fortune");
}
static GtkWidget * fortune_less = NULL;
static gint
fish_clicked_cb(GtkWidget * widget, GdkEventButton * e,
gpointer data)
{
if (e->button != 1) {
/* Ignore buttons 2 and 3 */
return FALSE;
}
if ( fortune_dialog == NULL ) {
fortune_dialog =
gnome_dialog_new("", GNOME_STOCK_BUTTON_CLOSE, NULL);
gnome_dialog_set_close(GNOME_DIALOG(fortune_dialog), TRUE);
gnome_dialog_close_hides(GNOME_DIALOG(fortune_dialog), TRUE);
update_fortune_dialog();
fortune_less = gnome_less_new();
fortune_label = gtk_label_new("");
return TRUE;
}
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(fortune_dialog)->vbox),
fortune_label,
FALSE, FALSE, GNOME_PAD);
static void
fish_draw(GtkWidget *darea)
{
if(!GTK_WIDGET_REALIZED(darea))
return;
gdk_draw_pixmap(darea->window,
darea->style->fg_gc[GTK_WIDGET_STATE(darea)],
pix[curpix]->pixmap,
0, 0,
0, 0,
-1, -1);
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(fortune_dialog)->vbox),
fortune_less,
TRUE, TRUE, GNOME_PAD);
gnome_less_set_fixed_font(GNOME_LESS(fortune_less),TRUE);
gtk_widget_show(fortune_less);
gtk_widget_show(fortune_label);
apply_properties();
}
if (!GTK_WIDGET_VISIBLE(fortune_dialog)) gtk_widget_show(fortune_dialog);
gnome_less_show_command(GNOME_LESS(fortune_less), g_file_exists("/usr/games/fortune")?"/usr/games/fortune":"fortune");
}
static gint
fish_timeout(gpointer data)
static int
fish_clicked_cb(GtkWidget * widget, GdkEventButton * e,
gpointer data)
{
curpix++;
if(curpix>=3) curpix=0;
fish_draw(GTK_WIDGET(data));
if (e->button != 1) {
/* Ignore buttons 2 and 3 */
return FALSE;
}
return TRUE;
update_fortune_dialog();
return TRUE;
}
static int
......@@ -202,7 +322,8 @@ fish_expose(GtkWidget *darea, GdkEventExpose *event)
{
gdk_draw_pixmap(darea->window,
darea->style->fg_gc[GTK_WIDGET_STATE(darea)],
pix[curpix]->pixmap,
pix->pixmap,
((pix->rgb_width*curpix)/properties.frames)+
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
......@@ -213,25 +334,16 @@ static GtkWidget *
create_fish_widget(GtkWidget *window)
{
GtkWidget *frame;
GtkWidget *darea;
GtkStyle *style;
gtk_widget_push_visual (gdk_imlib_get_visual ());
gtk_widget_push_colormap (gdk_imlib_get_colormap ());
style = gtk_widget_get_style(window);
/*we render everything to be the same sizee as the first image*/
pix[0] = gdk_imlib_create_image_from_xpm_data((gchar **)fish1_xpm);
gdk_imlib_render (pix[0], pix[0]->rgb_width, pix[0]->rgb_height);
pix[1] = gdk_imlib_create_image_from_xpm_data((gchar **)fish2_xpm);
gdk_imlib_render (pix[1], pix[0]->rgb_width, pix[0]->rgb_height);
pix[2] = gdk_imlib_create_image_from_xpm_data((gchar **)fish3_xpm);
gdk_imlib_render (pix[2], pix[0]->rgb_width, pix[0]->rgb_height);
darea = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(darea),
pix[0]->rgb_width,pix[0]->rgb_height);
pix->rgb_width/properties.frames,
pix->rgb_height);
gtk_widget_set_events(darea, gtk_widget_get_events(darea) |
GDK_BUTTON_PRESS_MASK);
gtk_signal_connect(GTK_OBJECT(darea), "button_press_event",
......@@ -244,7 +356,8 @@ create_fish_widget(GtkWidget *window)
curpix = 0;
gtk_timeout_add(300,fish_timeout,darea);
timeout_id = gtk_timeout_add(properties.speed*1000,
fish_timeout,darea);
frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_IN);
......@@ -260,8 +373,8 @@ void
about_cb (AppletWidget *widget, gpointer data)
{
GtkWidget *about;
gchar *authors[3];
const gchar * author_format = _("%s the Fish");
char *authors[3];
const char * author_format = _("%s the Fish");
authors[0] = splice_name(author_format, properties.name);
authors[1] = _("(with minor help from George)");
......@@ -269,7 +382,7 @@ about_cb (AppletWidget *widget, gpointer data)
about = gnome_about_new (_("The GNOME Fish Applet"), "3.4.7.4",
"(C) 1998 the Free Software Foundation",
(const gchar **)authors,
(const char **)authors,
_("This applet has no use what-so-ever. "
"It only takes up disk space and "
"compilation time, and if loaded it also "
......@@ -285,13 +398,16 @@ about_cb (AppletWidget *widget, gpointer data)
return;
}
static gint
static int
applet_save_session(GtkWidget *w,
const char *privcfgpath,
const char *globcfgpath)
{
gnome_config_push_prefix(privcfgpath);
gnome_config_set_string("fish/name",properties.name);
gnome_config_set_string("fish/image",properties.image);
gnome_config_set_int("fish/frames",properties.frames);
gnome_config_set_float("fish/speed",properties.speed);
gnome_config_pop_prefix();
gnome_config_sync();
......@@ -318,12 +434,12 @@ main(int argc, char *argv[])
if (!applet)
g_error(_("Can't create applet!\n"));
load_properties(APPLET_WIDGET(applet)->privcfgpath);
gtk_widget_realize(applet);
fish = create_fish_widget(applet);
gtk_widget_show(fish);
load_properties(APPLET_WIDGET(applet)->privcfgpath);
applet_widget_add(APPLET_WIDGET(applet), fish);
gtk_widget_show(applet);
gtk_signal_connect(GTK_OBJECT(applet),"save_session",
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Sun Aug 23 23:24:30 1998 George Lebl <jirka@5z.com>
* fish/fish.c,fish/fish?.xpm,fish/fishanim.png,fish/Makefile.am:
added "themability", so that you can load up a different
animation file and change the speed in the config dialog
1998-08-23 Martin Baulig <martin@home-of-linux.org>
* cpuload: This applet now requires libgtop.
......
Sun Aug 23 23:24:30 1998 George Lebl <jirka@5z.com>
* fish/fish.c,fish/fish?.xpm,fish/fishanim.png,fish/Makefile.am:
added "themability", so that you can load up a different
animation file and change the speed in the config dialog
1998-08-23 Martin Baulig <martin@home-of-linux.org>
* cpuload: This applet now requires libgtop.
......
Sun Aug 23 23:24:30 1998 George Lebl <jirka@5z.com>
* fish/fish.c,fish/fish?.xpm,fish/fishanim.png,fish/Makefile.am:
added "themability", so that you can load up a different
animation file and change the speed in the config dialog
1998-08-23 Martin Baulig <martin@home-of-linux.org>
* cpuload: This applet now requires libgtop.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment