static VALUE rg_initialize(int argc, VALUE *argv, VALUE self) { VALUE image; GtkWidget *widget = NULL; rb_scan_args(argc, argv, "01", &image); if (NIL_P(image)) { widget = gtk_image_new(); } else if (TYPE(image) == T_HASH) { VALUE stock, icon_name, icon_set, gicon, file, pixbuf, animation, size, buffer; rbg_scan_options(image, "stock", &stock, "icon_name", &icon_name, "icon_set", &icon_set, "gicon", &gicon, "file", &file, "pixbuf", &pixbuf, "animation", &animation, "size", &size, NULL); if (!NIL_P(stock)) widget = gtk_image_new_from_stock(RVAL2GLIBID(stock, buffer), RVAL2GTKICONSIZE(size)); else if (!NIL_P(icon_name)) widget = gtk_image_new_from_icon_name(RVAL2CSTR(icon_name), RVAL2GTKICONSIZE(size)); else if (!NIL_P(icon_set)) widget = gtk_image_new_from_icon_set(RVAL2GTKICONSET(icon_set), RVAL2GTKICONSIZE(size)); else if (!NIL_P(gicon)) widget = gtk_image_new_from_gicon(RVAL2GICON(gicon), RVAL2GTKICONSIZE(size)); else if (!NIL_P(file)) widget = gtk_image_new_from_file(RVAL2CSTR(file)); else if (!NIL_P(pixbuf)) widget = gtk_image_new_from_pixbuf(RVAL2GDKPIXBUF(pixbuf)); else if (!NIL_P(animation)) widget = gtk_image_new_from_animation(RVAL2GDKPIXBUFANIMATION(animation)); } else { GType gtype = RVAL2GTYPE(image); if (gtype == GDK_TYPE_PIXBUF) widget = gtk_image_new_from_pixbuf(RVAL2GDKPIXBUF(image)); else if (g_type_is_a(gtype, GDK_TYPE_PIXBUF_ANIMATION)) widget = gtk_image_new_from_animation(RVAL2GDKPIXBUFANIMATION(image)); } if (!widget) rb_raise(rb_eArgError, "Invalid arguments."); RBGTK_INITIALIZE(self, widget); return Qnil; }
void * tray_icon_new_from_data (const char *name, const char *data, unsigned long size) { TrayIcon *ticon; GdkPixbufLoader *loader; GdkPixbufAnimation *animation; gboolean rc; ticon = malloc (sizeof (TrayIcon)); if (__running) gtk_main_quit(); pthread_mutex_lock(&mutex); ticon->icon = egg_tray_icon_new ((const gchar *) name); ticon->eventbox = gtk_event_box_new (); g_signal_connect (ticon->eventbox, "button_press_event", G_CALLBACK (tray_icon_pressed), ticon); gtk_container_add (GTK_CONTAINER (ticon->icon), ticon->eventbox); // tray icon image loader=gdk_pixbuf_loader_new(); rc = gdk_pixbuf_loader_write (loader, (const guchar *)data, (gsize) size,NULL); gdk_pixbuf_loader_close (loader,NULL); if(rc) { // get animation animation=gdk_pixbuf_loader_get_animation(loader); ticon->image = gtk_image_new_from_animation (animation); } gtk_container_add (GTK_CONTAINER (ticon->eventbox), ticon->image); gtk_widget_show_all (GTK_WIDGET (ticon->icon)); pthread_mutex_unlock(&mutex); if (__running) pthread_cond_signal(&cond); return (void *) ticon; }
int main (int argc, char *argv[]) { if(argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-H"))) { printf("Ponies for Linux/GTK+ by rabbit\n"); printf("Command list:\n"); printf("No Parameters: Run with the settings used from last run\n"); printf("-h: Display this help\n"); printf("file path: Set new file path to look for pony gif files\n"); printf("ponyname: Sets to run one of the pony type listed\n"); return 0; } for(int i = 1; i < argc; i++) if(*argv[i] == '/') setPonyDirectory(argv[i]); char* ponyDirectory = NULL; char* ponyHomeFile = NULL; ponyHomeFile = malloc((strlen(getenv("HOME"))+ 9) * sizeof(char)); if(!ponyHomeFile) { printf("Could not allocate memory for ponyHomeFile\n"); return 0; } strcpy(ponyHomeFile, getenv("HOME")); strcat(ponyHomeFile,"/.ponies"); ponyDirectory = getPonyDirectory(); if(!ponyDirectory) { free(ponyHomeFile); printf("Error locating pony directory\n"); return 0; } //Initialize GTK+ and set up loggers GError* error = NULL; g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL); gtk_init (&argc, &argv); g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL); //For command line commands later, require input on inital load //Normally would close, but hard coded in for easier testing int numberOfPonies = 0; if(argc == 1) { //Read in from ~/.ponies file to find saved settings FILE* ifp = NULL; char buffer[256]; ifp = fopen(ponyHomeFile,"r"); if(!ifp) { free(ponyHomeFile); free(ponyDirectory); printf("Could not open file for reading\n"); return 0; } //fread(buffer, sizeof(char), 256, ifp); while(fgets(buffer, 256, ifp)) if(buffer[0] != '\n') numberOfPonies++; fclose(ifp); numberOfPonies--;//First line is directory } //Not default arguments else { for(int i = 1; i < argc; i++) { if(*argv[i] == '/') continue; numberOfPonies++; } } //Seed the randomizer srand(time(0)); //Number of ponies pony ponyArray[numberOfPonies]; char buffer[256]; FILE* ifp = NULL; ifp = fopen(ponyHomeFile,"r"); if(!ifp) { printf("Could not open ~/.ponies\n"); free(ponyDirectory); free(ponyHomeFile); return 0; } fgets(buffer, 256, ifp);//throw away first line //0 Ponies if(!numberOfPonies) { free(ponyDirectory); free(ponyHomeFile); printf("No ponies in the ~/.ponies file! Add some ponies!\n"); printf("allowable ponies are: "); for(int i = 0; i <= Zecora; i++) printf("%s ", getDirectoryName(i)); return 0; } //Make pony windows for( int i = 0; i < numberOfPonies; i++) { fgets(buffer, 256, ifp); char* temp = NULL; temp = strchr(buffer, '\n'); if(temp) buffer[temp - buffer] = '\0'; ponyArray[i].name = ponyNameFromString(buffer); ponyArray[i].direction = DirNone; ponyArray[i].dragActive = 0; ponyArray[i].speed = SpeedStopped; ponyArray[i].animation = AnimIdle; ponyArray[i].active = 1; ponyArray[i].facing = FaceLeft; //Create animation from file, default is idle_left char* initialPicturePath; initialPicturePath = malloc((strlen(ponyDirectory) + strlen(getDirectoryName(ponyArray[i].name)) + 14) * sizeof(char)); if(!initialPicturePath) { printf("Unable to allocate memory for directory"); continue; } strcpy(initialPicturePath, ponyDirectory); strcat(initialPicturePath, getDirectoryName(ponyArray[i].name)); strcat(initialPicturePath, "/idle_left.gif"); ponyArray[i].pictureanim = gdk_pixbuf_animation_new_from_file (initialPicturePath, &error); free(initialPicturePath); ponyArray[i].image = gtk_image_new_from_animation(ponyArray[i].pictureanim); ponyArray[i].pictureanimit = gdk_pixbuf_animation_get_iter (ponyArray[i].pictureanim, NULL); ponyArray[i].win = gtk_window_new(GTK_WINDOW_TOPLEVEL); //Resize everytime the gif updates g_timeout_add(gdk_pixbuf_animation_iter_get_delay_time(ponyArray[i]. pictureanimit),(GSourceFunc)updateWinSize, &ponyArray[i]); //Name the window the name of the pony being animated gtk_window_set_title(GTK_WINDOW(ponyArray[i].win), getPonyName(ponyArray[i].name)); //Size down the window before showing it gtk_window_set_default_size(GTK_WINDOW(ponyArray[i].win), gdk_pixbuf_animation_get_width(ponyArray[i]. pictureanim), gdk_pixbuf_animation_get_height (ponyArray[i].pictureanim)); //Remove the titlebar gtk_window_set_decorated(GTK_WINDOW(ponyArray[i].win), FALSE); //Set up the signals ponyArray[i].clickEventID = g_signal_connect(G_OBJECT(ponyArray[i].win), "button_press_event", G_CALLBACK(click_event), &ponyArray[i]); ponyArray[i].enterEventID = g_signal_connect(G_OBJECT(ponyArray[i].win), "enter-notify-event", G_CALLBACK(enter_event), &ponyArray[i]); ponyArray[i].leaveEventID = g_signal_connect(G_OBJECT(ponyArray[i].win), "leave-notify-event", G_CALLBACK(enter_event), &ponyArray[i]); gtk_widget_add_events(ponyArray[i].win, GDK_BUTTON_PRESS_MASK); gtk_container_add(GTK_CONTAINER(ponyArray[i].win), GTK_WIDGET(ponyArray[i]. image)); //Get rid of taskbar item gtk_window_set_skip_taskbar_hint(GTK_WINDOW(ponyArray[i].win), TRUE); //Make it so it can't be selected gtk_window_set_accept_focus(GTK_WINDOW(ponyArray[i].win), FALSE); gtk_widget_realize(ponyArray[i].win); //Always on top gtk_window_set_keep_above(GTK_WINDOW(ponyArray[i].win), TRUE); updateWinSize(&ponyArray[i]); if(error != NULL) break; } free(ponyDirectory); free(ponyHomeFile); //Quit out if there were any errors and give a message if( error != NULL) { printf("%s\n",error->message); return 0; } //Make it transparent? /*cr = gdk_cairo_create(win->window); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0); cairo_set_operator( cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(image));*/ //Main loop for( int i = 0; i < numberOfPonies; i++) gtk_widget_show_all(ponyArray[i].win); gtk_main(); return 0; }
void splash_create (gboolean be_verbose) { GtkWidget *frame; GtkWidget *vbox; GdkPixbufAnimation *pixbuf; GdkScreen *screen; g_return_if_fail (splash == NULL); pixbuf = splash_image_load (be_verbose); if (! pixbuf) return; splash = g_slice_new0 (GimpSplash); splash->window = g_object_new (GTK_TYPE_WINDOW, "type", GTK_WINDOW_TOPLEVEL, "type-hint", GDK_WINDOW_TYPE_HINT_SPLASHSCREEN, "title", _("GIMP Startup"), "role", "gimp-startup", "window-position", GTK_WIN_POS_CENTER, "resizable", FALSE, NULL); g_signal_connect_swapped (splash->window, "delete-event", G_CALLBACK (exit), GINT_TO_POINTER (0)); screen = gtk_widget_get_screen (splash->window); splash->width = MIN (gdk_pixbuf_animation_get_width (pixbuf), gdk_screen_get_width (screen)); splash->height = MIN (gdk_pixbuf_animation_get_height (pixbuf), gdk_screen_get_height (screen)); frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); gtk_container_add (GTK_CONTAINER (splash->window), frame); gtk_widget_show (frame); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); /* If the splash image is static, we use a drawing area and set the * image as back pixmap, otherwise a GtkImage is being used. */ if (gdk_pixbuf_animation_is_static_image (pixbuf)) { splash->area = gtk_drawing_area_new (); } else { splash->area = gtk_image_new_from_animation (pixbuf); } gtk_box_pack_start (GTK_BOX (vbox), splash->area, TRUE, TRUE, 0); gtk_widget_show (splash->area); gtk_widget_set_size_request (splash->area, splash->width, splash->height); /* create the pango layouts */ splash->upper = gtk_widget_create_pango_layout (splash->area, ""); splash->lower = gtk_widget_create_pango_layout (splash->area, ""); gimp_pango_layout_set_scale (splash->lower, PANGO_SCALE_SMALL); /* this sets the initial layout positions */ splash_position_layouts (splash, "", "", NULL); splash_average_text_area (splash, gdk_pixbuf_animation_get_static_image (pixbuf), &splash->color); gtk_widget_realize (splash->area); if (gdk_pixbuf_animation_is_static_image (pixbuf)) { GdkPixbuf *static_pixbuf = gdk_pixbuf_animation_get_static_image (pixbuf); GdkPixmap *pixmap; cairo_t *cr; pixmap = gdk_pixmap_new (gtk_widget_get_window (splash->area), splash->width, splash->height, -1); cr = gdk_cairo_create (pixmap); gdk_cairo_set_source_pixbuf (cr, static_pixbuf, 0.0, 0.0); cairo_paint (cr); cairo_destroy (cr); gdk_window_set_back_pixmap (gtk_widget_get_window (splash->area), pixmap, FALSE); g_object_unref (pixmap); } g_object_unref (pixbuf); g_signal_connect_after (splash->area, "expose-event", G_CALLBACK (splash_area_expose), splash); /* add a progress bar */ splash->progress = gtk_progress_bar_new (); gtk_box_pack_end (GTK_BOX (vbox), splash->progress, FALSE, FALSE, 0); gtk_widget_show (splash->progress); gtk_widget_show_now (splash->window); #ifdef STARTUP_TIMER splash->timer = g_timer_new (); #endif }