void update_widget_bg(GtkWidget *widget, gchar *img_file) { GtkStyle *style; GdkPixbuf *pixbuf;/*缓存文件*/ GdkPixmap *pixmap;/*表明显示区域*/ gint width, height; pixbuf = gdk_pixbuf_new_from_file(img_file, NULL);/*把文件读到缓存中*/ width = gdk_pixbuf_get_width(pixbuf); height = gdk_pixbuf_get_height(pixbuf); pixmap = gdk_pixmap_new(NULL, width, height, 24);/*建立一个显示的区域,以告诉在哪里显示图*/ gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 0);/*将缓存和显示区域联系*/ /*设置显示图片构件的相应参数风格*/ style = gtk_style_copy(GTK_WIDGET (widget)->style); if (style->bg_pixmap[GTK_STATE_NORMAL]) g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]); style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_ACTIVE] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_PRELIGHT] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_SELECTED] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_INSENSITIVE] = g_object_ref(pixmap); gtk_widget_set_style(GTK_WIDGET (widget), style);//替代了 //gtk_widget_modify_style(GTK_WIDGET (widget), style);//直接改,但是style类型不同了 g_object_unref(style); }
void SetBG(char * image) { GdkPixbuf * pixbuf = NULL; GdkPixmap * pixmap = NULL; GtkStyle * style = NULL; GtkWidget * p_win = (GtkWidget *) gtk_builder_get_object (g_interface, "window"); char * lien = (char*)calloc (sizeof IMG_FOLDER + sizeof image, sizeof(char)); if(image != NULL) { strcpy(lien,IMG_FOLDER); strcat(lien,image); pixbuf = gdk_pixbuf_new_from_file_at_scale(lien,SizeWin[0],SizeWin[1],FALSE,NULL); gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, NULL, 0); g_object_unref(pixbuf); style = gtk_style_new(); style->bg_pixmap[0] = pixmap; if(strcmp(BackMenu,image) != 0) { BackMenu = (char*)realloc(NULL, sizeof image * sizeof(char)); strcpy(BackMenu,image); } gtk_widget_set_style (p_win, style); } else { BackMenu = NULL; gtk_widget_set_style(p_win, NULL); } }
static int gtkDialogSetBackgroundAttrib(Ihandle* ih, const char* value) { if (iupdrvBaseSetBgColorAttrib(ih, value)) { GtkStyle *style = gtk_widget_get_style(ih->handle); if (style->bg_pixmap[GTK_STATE_NORMAL]) { style = gtk_style_copy(style); style->bg_pixmap[GTK_STATE_NORMAL] = NULL; gtk_widget_set_style(ih->handle, style); } return 1; } else { GdkPixbuf* pixbuf = iupImageGetImage(value, ih, 0); if (pixbuf) { GdkPixmap* pixmap; GtkStyle *style; gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 255); style = gtk_style_copy(gtk_widget_get_style(ih->handle)); style->bg_pixmap[GTK_STATE_NORMAL] = pixmap; gtk_widget_set_style(ih->handle, style); return 1; } } return 0; }
static void inline_F24_261 (EIF_POINTER arg1, EIF_POINTER* arg2, EIF_POINTER* arg3, EIF_INTEGER_32 arg4) { #if GTK_MAJOR_VERSION > 1 gdk_pixbuf_render_pixmap_and_mask ((GdkPixbuf*) arg1, (GdkPixmap**) arg2, (GdkBitmap**) arg3, (int) arg4); #endif ; }
static VALUE rg_render_pixmap_and_mask(int argc, VALUE *argv, VALUE self) { VALUE colormap_or_alpha, alpha; GdkPixmap *pixmap; GdkBitmap *mask; rb_scan_args(argc, argv, "11", &colormap_or_alpha, &alpha); if (rb_obj_is_kind_of(colormap_or_alpha, GTYPE2CLASS(GDK_TYPE_COLORMAP))){ gdk_pixbuf_render_pixmap_and_mask_for_colormap(_SELF(self), RVAL2GOBJ(colormap_or_alpha), &pixmap, &mask, NIL_P(alpha)?0:NUM2INT(alpha)); } else { gdk_pixbuf_render_pixmap_and_mask(_SELF(self), &pixmap, &mask, NIL_P(colormap_or_alpha)? 0:NUM2INT(colormap_or_alpha)); } return rb_ary_new3(2, pixmap ? GOBJ2RVAL(pixmap) : Qnil, mask ? GOBJ2RVAL(mask) : Qnil); }
NOTIFYICONDATA systray_init(GdkPixbuf *pixbuf, char* text) { GdkPixmap *pm; GdkBitmap *mask; gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pm, &mask, 128); char* locenc=NULL; ZeroMemory(&nid,sizeof(nid)); systray_hicon = pixmap_to_hicon (pm, mask); systray_hwnd = systray_create_hiddenwin(); nid.cbSize=sizeof(NOTIFYICONDATA); nid.hWnd=systray_hwnd; nid.uID=0; nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP ; nid.uCallbackMessage=WM_TRAYMESSAGE; nid.hIcon=systray_hicon; if(text) { locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL); lstrcpy(nid.szTip, locenc); g_free(locenc); } Shell_NotifyIcon(NIM_ADD,&nid); return nid; }
void update_widget_bg(GtkWidget *widget, gchar *img_file) { GtkStyle *style; GdkPixbuf *pixbuf; GdkPixmap *pixmap; gint width, height; pixbuf = gdk_pixbuf_new_from_file(img_file, NULL); width = gdk_pixbuf_get_width(pixbuf); height = gdk_pixbuf_get_height(pixbuf); pixmap = gdk_pixmap_new(NULL, width, height, 24); gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 0); style = gtk_style_copy(GTK_WIDGET (widget)->style); if (style->bg_pixmap[GTK_STATE_NORMAL]) g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]); style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_ACTIVE] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_PRELIGHT] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_SELECTED] = g_object_ref(pixmap); style->bg_pixmap[GTK_STATE_INSENSITIVE] = g_object_ref(pixmap); gtk_widget_set_style(GTK_WIDGET (widget), style); g_object_unref(style); }
GdkBitmap * gp_image_get_mask ( GpImage *image ) { GdkBitmap *mask; gdk_pixbuf_render_pixmap_and_mask ( image->priv->pixbuf, NULL, &mask, 255 ); return mask; }
/**************************************************************************** Render a mask from the sprite. NOTE: the pixbuf of a sprite must not change after this function is called! ****************************************************************************/ GdkBitmap *sprite_get_mask(struct sprite *sprite) { if (!sprite->pixmap && !sprite->mask) { /* If we're not in pixmap mode and we don't yet have a mask, render * the pixbuf to a mask. */ gdk_pixbuf_render_pixmap_and_mask(sprite->pixbuf, NULL, &sprite->mask, 1); } return sprite->mask; }
gint thumb_loader_to_pixmap (ThumbLoader * tl, GdkPixmap ** pixmap, GdkBitmap ** mask) { if (!tl || !tl->pixbuf) return -1; gdk_pixbuf_render_pixmap_and_mask (tl->pixbuf, pixmap, mask, 128); return thumb_loader_get_space (tl); }
void pixmap_from_xpm (const char **data, GdkPixmap **pixmap, GdkBitmap **mask) { GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_new_from_xpm_data (data); gdk_pixbuf_render_pixmap_and_mask (pixbuf, pixmap, mask, 127); g_object_unref (pixbuf); }
void setWindow(GtkWidget *widget,gpointer data ) { GdkPixbuf *LoadImage = NULL; GtkStyle *StyleNew = NULL; GdkPixmap *LoadPixmap = NULL; LoadImage = load_pixbuf_from_file ((gchar*)data); gdk_pixbuf_render_pixmap_and_mask (LoadImage, &LoadPixmap, NULL, 0); StyleNew = gtk_style_new (); StyleNew->bg_pixmap [0] = LoadPixmap; gtk_widget_set_style (GTK_WIDGET(window), GTK_STYLE (StyleNew)); }
struct pixmap* get_pixmap_for_country(int id) { GdkPixbuf* pixbuf = NULL; struct pixmap* pix = NULL; char* filename = NULL; if (!flags) { return NULL; } if (id < 1) { // no flag for N/A return NULL; } pix = &flags[id]; if (pix->pix == GINT_TO_POINTER(-1)) { return NULL; } if (pix->pix) { return pix; } if (!GDK_PIXBUF_INSTALLED) { return NULL; } filename = find_flag_file(id); if (!filename || access(filename,R_OK)) { g_free(filename); return NULL; } debug(4, "loading gdk_pixbuf from file: %s", filename); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); if (pixbuf == NULL) { pix->pix=GINT_TO_POINTER(-1); g_warning (_("Error loading pixmap file: %s"), filename); g_free (filename); return NULL; } gdk_pixbuf_render_pixmap_and_mask(pixbuf,&pix->pix,&pix->mask,255); g_object_unref(pixbuf); g_free (filename); return pix; }
static GdkPixmap * pixmap_load_from_file_real (char *file) { GdkPixbuf *img; GdkPixmap *pixmap; img = gdk_pixbuf_new_from_file (file, 0); if (!img) return NULL; gdk_pixbuf_render_pixmap_and_mask (img, &pixmap, NULL, 128); gdk_pixbuf_unref (img); return pixmap; }
static void update_image(Osd * self) { GdkPixmap *shape; GdkGC *shape_gc; GdkPixbuf *shape_pixbuf; GdkPixbuf *pixbuf; // make shape pixmap from pango layout shape = gdk_pixmap_new(GTK_WIDGET(self)->window, self->width, self->height, -1); shape_gc = gdk_gc_new(shape); gdk_gc_set_rgb_fg_color(shape_gc, &self->mask_color); gdk_draw_rectangle(shape, shape_gc, TRUE, 0, 0, self->width + 1, self->height + 1); gdk_gc_set_rgb_fg_color(shape_gc, &self->shadow_color); gdk_draw_layout(shape, shape_gc, self->shadow_offset_x, self->shadow_offset_y, self->layout); gdk_gc_set_rgb_fg_color(shape_gc, &self->text_color); gdk_draw_layout(shape, shape_gc, 0, 0, self->layout); gtk_image_set_from_pixmap(GTK_IMAGE(self->image), shape, NULL); // make shape pixbuf from shape pixmap shape_pixbuf = gdk_pixbuf_get_from_drawable(NULL, shape, NULL, 0, 0, 0, 0, self->width, self->height); g_object_unref(shape); g_object_unref(shape_gc); // make alpha enabled pixbuf from shape pixbuf pixbuf = gdk_pixbuf_add_alpha(shape_pixbuf, TRUE, self->mask_color.red, self->mask_color.green, self->mask_color.blue); // finally, i got the mask bitmap! // it's needed to update_shape(). // FIXME: somewhat clumsy :( need better/easy/efficient way. gdk_pixbuf_render_pixmap_and_mask(pixbuf, NULL, &self->mask, 1); g_object_unref(pixbuf); g_object_unref(shape_pixbuf); }
/* desktopicon_update_transparency */ static void _desktopicon_update_transparency(DesktopIcon * desktopicon) { GdkPixbuf * icon; int width; int height; int iwidth; int iheight; GdkBitmap * mask; GdkBitmap * iconmask; GdkGC * gc; GdkColor black = { 0, 0, 0, 0 }; GdkColor white = { 0xffffffff, 0xffff, 0xffff, 0xffff }; GtkRequisition req; int offset; if((icon = gtk_image_get_pixbuf(GTK_IMAGE(desktopicon->image))) == NULL) return; /* XXX report error */ gtk_window_get_size(GTK_WINDOW(desktopicon->window), &width, &height); iwidth = gdk_pixbuf_get_width(icon); iheight = gdk_pixbuf_get_height(icon); #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\") window is %dx%d\n", __func__, desktopicon->name, width, height); #endif mask = gdk_pixmap_new(NULL, width, height, 1); gdk_pixbuf_render_pixmap_and_mask(icon, NULL, &iconmask, 255); gc = gdk_gc_new(mask); gdk_gc_set_foreground(gc, &black); gdk_draw_rectangle(mask, gc, TRUE, 0, 0, width, height); gdk_draw_drawable(mask, gc, iconmask, 0, 0, (width - iwidth) / 2, (DESKTOPICON_ICON_SIZE - iheight) / 2, -1, -1); gdk_gc_set_foreground(gc, &white); gtk_widget_size_request(desktopicon->label, &req); #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\") label is %dx%d\n", __func__, desktopicon->name, req.width, req.height); #endif offset = DESKTOPICON_ICON_SIZE + 4; gdk_draw_rectangle(mask, gc, TRUE, (width - req.width - 8) / 2, offset /* + ((height - offset - req.height - 8) / 2) */, req.width + 8, req.height + 8); gtk_widget_shape_combine_mask(desktopicon->window, mask, 0, 0); g_object_unref(gc); g_object_unref(iconmask); g_object_unref(mask); }
void change_background(GtkWidget *widget, int w, int h, const gchar *path) { gtk_widget_set_app_paintable(widget, TRUE); gtk_widget_realize(widget); gtk_widget_queue_draw(widget); GdkPixbuf *src_pixbuf = gdk_pixbuf_new_from_file(path, NULL); GdkPixbuf *dst_pixbuf = gdk_pixbuf_scale_simple(src_pixbuf, w, h, GDK_INTERP_BILINEAR); GdkPixmap *pixmap = NULL; gdk_pixbuf_render_pixmap_and_mask(dst_pixbuf, &pixmap, NULL, 128); gdk_window_set_back_pixmap(widget->window, pixmap, FALSE); g_object_unref(src_pixbuf); g_object_unref(dst_pixbuf); g_object_unref(pixmap); }
/**************************************************************************** Create a new sprite with the given pixmap, dimensions, and (optional) mask. FIXME: should be renamed as sprite_new or some such. ****************************************************************************/ struct sprite *ctor_sprite(GdkPixbuf *pixbuf) { struct sprite *sprite = fc_malloc(sizeof(*sprite)); bool has_alpha = FALSE, has_mask = FALSE; sprite->width = gdk_pixbuf_get_width(pixbuf); sprite->height = gdk_pixbuf_get_height(pixbuf); /* Check to see if this pixbuf has an alpha layer. */ if (gdk_pixbuf_get_has_alpha(pixbuf)) { guchar *pixels = gdk_pixbuf_get_pixels(pixbuf); int x, y, rowstride = gdk_pixbuf_get_rowstride(pixbuf); for (y = 0; y < sprite->height; y++) { for (x = 0; x < sprite->width; x++) { int i = y * rowstride + 4 * x + 3; guchar pixel = pixels[i]; if (pixel > 0 && pixel < 255) { has_alpha = TRUE; } if (pixel == 0) { has_mask = TRUE; } } } } sprite->pixbuf_fogged = NULL; sprite->pixmap_fogged = NULL; if (has_alpha) { sprite->pixbuf = pixbuf; sprite->pixmap = NULL; sprite->mask = NULL; } else { gdk_pixbuf_render_pixmap_and_mask(pixbuf, &sprite->pixmap, &sprite->mask, 1); if (!has_mask && sprite->mask) { g_object_unref(sprite->mask); sprite->mask = NULL; } g_object_unref(pixbuf); sprite->pixbuf = NULL; } return sprite; }
void adm_changeIcon_systray(void) { GdkPixmap *pm; GdkBitmap *mask; GdkPixbuf *icon; flipflop=flipflop%win32egg_nb; icon=win32egg_pixbuf[flipflop]; //ADM_assert(icon); gdk_pixbuf_render_pixmap_and_mask(icon, &pm, &mask, 128); systray_modify_icon (pm, mask) ; flipflop++; flipflop=flipflop%win32egg_nb; }
static int gtkDialogSetOpacityImageAttrib(Ihandle *ih, const char *value) { GdkPixbuf* pixbuf = iupImageGetImage(value, ih, 0); if (pixbuf) { #if GTK_CHECK_VERSION(3, 0, 0) GdkWindow* window = iupgtkGetWindow(ih->handle); if (window) { cairo_region_t *shape; #if GTK_CHECK_VERSION(3, 10, 0) cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, 0, window); #else int width = gdk_pixbuf_get_width(pixbuf); int height = gdk_pixbuf_get_height(pixbuf); cairo_surface_t* surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, width, height); cairo_t* cr = cairo_create(surface); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_destroy(cr); #endif shape = gdk_cairo_region_create_from_surface(surface); cairo_surface_destroy(surface); gtk_widget_shape_combine_region(ih->handle, shape); cairo_region_destroy(shape); } #else GdkBitmap* mask = NULL; gdk_pixbuf_render_pixmap_and_mask(pixbuf, NULL, &mask, 255); if (mask) { gtk_widget_shape_combine_mask(ih->handle, mask, 0, 0); g_object_unref(mask); } #endif return 1; } return 0; }
void ami_desktop_set_background(AmiDesktop *desktop) { GdkPixmap *pixmap; GdkPixbuf *pixbuf; GtkStyle *style; pixbuf = gdk_pixbuf_new_from_file(amiconfig->wallpaper, NULL); gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 0); style = gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(desktop->window))); if (style->bg_pixmap[GTK_STATE_NORMAL]) { g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]); } style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap); gtk_widget_set_style (GTK_WIDGET(desktop->window), style); g_object_unref (pixbuf); g_object_unref (pixmap); g_object_unref (style); }
QCursor::QCursor(const QPixmap &pixmap) : cursor(NULL) { ERROR("not yet implemented"); GdkPixbuf* buf = pixmap.image()->handle(); QPoint hotSpot(0,0); #if (GTK_MAJOR_VERSION >= 2) && (GTK_MINOR_VERSION >=4) cursor = gdk_cursor_new_from_pixbuf(GDK_DISPLAY(), buf, hotSpot.x(), hotSpot.y()); #else GdkPixmap *gdkpixmap; GdkBitmap *mask; gdk_pixbuf_render_pixmap_and_mask(buf, &gdkpixmap, &mask, 100); GdkColor fg = { 0, 65535, 65535, 65535 }; /* White. */ GdkColor bg = { 0, 0, 0, 0 }; /* Black. */ cursor = gdk_cursor_new_from_pixmap(mask, mask, &fg, &bg, hotSpot.x(), hotSpot.y()); g_object_unref(gdkpixmap); g_object_unref(mask); #endif }
void load_and_scale_pixmap_and_mask (const gchar *file, gfloat x_ratio, gfloat y_ratio, GdkPixmap **pixmap_return, GdkBitmap **mask_return) { GdkPixbuf *pixbuf = NULL; if (pixmap_return) *pixmap_return = NULL; if (mask_return) *mask_return = NULL; pixbuf = _load_and_scale_pixbuf(file, x_ratio, y_ratio); if (!pixbuf) return; gdk_pixbuf_render_pixmap_and_mask(pixbuf, pixmap_return, mask_return, 128); g_object_unref(pixbuf); return; }
/************************************************************************** Created a fogged version of the sprite. This can fail on older systems in which case the callers needs a fallback. **************************************************************************/ static void fog_sprite(struct sprite *sprite) { int x, y; GdkPixbuf *fogged; guchar *pixel; const int bright = 65; /* Brightness percentage */ if (sprite->pixmap) { fogged = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, sprite->width, sprite->height); gdk_pixbuf_get_from_drawable(fogged, sprite->pixmap, NULL, 0, 0, 0, 0, sprite->width, sprite->height); } else { fogged = gdk_pixbuf_copy(sprite->pixbuf); } /* Iterate over all pixels, reducing brightness by 50%. */ for (x = 0; x < sprite->width; x++) { for (y = 0; y < sprite->height; y++) { pixel = gdk_pixbuf_get_pixels(fogged) + y * gdk_pixbuf_get_rowstride(fogged) + x * gdk_pixbuf_get_n_channels(fogged); pixel[0] = pixel[0] * bright / 100; pixel[1] = pixel[1] * bright / 100; pixel[2] = pixel[2] * bright / 100; } } if (sprite->pixmap) { gdk_pixbuf_render_pixmap_and_mask(fogged, &sprite->pixmap_fogged, NULL, 0); g_object_unref(fogged); } else { sprite->pixbuf_fogged = fogged; } }
// set the shape and background of the main window void set_window_shape(char *filepad) { GtkRcStyle *style; GError *error=NULL; pixelbuffer = gdk_pixbuf_new_from_file(filepad, &error); if (error) fprintf(stderr, "set windowshape error: %s\n", error->message); gdk_pixbuf_render_pixmap_and_mask(pixelbuffer, &gdk_pixmap, &win_mask, 1); // set background image style = gtk_widget_get_modifier_style(GTK_WIDGET(window)); style->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup(filepad); gtk_widget_modify_style(GTK_WIDGET(window), style); // set the shape gdk_window_shape_combine_mask(window->window, win_mask,0,0); // set the size width = gdk_pixbuf_get_width(pixelbuffer); height = gdk_pixbuf_get_height(pixelbuffer); gtk_widget_set_usize(window, width, height); }
GtkWidget* registUI() { GtkWidget* window; GtkWidget* box; GtkWidget* urnamebox; GtkWidget* psdbox; GtkWidget* repeatpsdbox; GtkWidget* btnbox; GtkWidget* urnamelabel; GtkWidget* psdlabel; GtkWidget* repeatpsdlabel; GtkWidget* button; GtkWidget* loginbtn; GtkWidget* urname; GtkWidget* password; GtkWidget* rpassword; GtkWidget* sep; GtkWidget* main_box; //图片buf GdkPixbuf* pixbuf = NULL; GdkPixmap* pixmap = NULL; GdkBitmap* bitmap = NULL; // GtkWidget* vbox,*hbox; GtkWidget* box1,*box2; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL); main_box=gtk_vbox_new(FALSE,0); vbox = gtk_vbox_new(FALSE,0); hbox = gtk_hbox_new(FALSE,0); box1 = gtk_vbox_new(FALSE,0); box2 = gtk_vbox_new(FALSE,0); gtk_window_set_decorated(GTK_WINDOW(window),FALSE); //==========================显示小埋=============================== gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK); gtk_widget_set_size_request(window, 844, 415); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect(G_OBJECT(window), "button_press_event", G_CALLBACK(window_drag), NULL); pixbuf = gdk_pixbuf_new_from_file ("./xiaomai.png",NULL); gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128); gtk_widget_shape_combine_mask(window, bitmap, 0, 0); GtkStyle *style = gtk_style_copy(window->style); if(style->bg_pixmap[GTK_STATE_NORMAL]) g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]); style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap); gtk_widget_set_style(window, style); //===================================================================== gtk_widget_set_size_request(vbox,844,125); gtk_box_pack_start(GTK_BOX(main_box),vbox,FALSE,FALSE,0); gtk_widget_set_size_request(hbox,844,250); gtk_box_pack_start(GTK_BOX(main_box),hbox,FALSE,FALSE,0); gtk_widget_set_size_request(box1,350,250); gtk_box_pack_start(GTK_BOX(hbox),box1,FALSE,FALSE,0); gtk_widget_set_size_request(box2,316,250); gtk_box_pack_start(GTK_BOX(hbox),box2,FALSE,FALSE,0); gtk_window_set_title(GTK_WINDOW(window),"regist"); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); gtk_container_set_border_width(GTK_CONTAINER(window),20); gtk_container_add(GTK_CONTAINER(window),main_box); //main box init box = gtk_vbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(box2),box,FALSE,FALSE,5); urnamebox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(box),urnamebox,FALSE,FALSE,5); psdbox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(box),psdbox,FALSE,FALSE,5); repeatpsdbox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(box),repeatpsdbox,FALSE,FALSE,5); sep=gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX(box),sep,FALSE,FALSE,5); btnbox=gtk_hbox_new(TRUE,0); gtk_box_pack_start(GTK_BOX(box),btnbox,FALSE,FALSE,5); //uesrname box init urnamelabel = gtk_label_new(" uesrname:"); urname=gtk_entry_new(); gtk_box_pack_end(GTK_BOX(urnamebox),urname,FALSE,FALSE,5); gtk_box_pack_end(GTK_BOX(urnamebox),urnamelabel,FALSE,FALSE,5); //password box init psdlabel = gtk_label_new(" password:"******"confirm password:"******"regist"); loginbtn=gtk_button_new_with_label("return to login"); g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(regist_on_button_clicked),®msg); //g_signal_connect_swapped(G_OBJECT(button),"clicked",G_CALLBACK(gtk_widget_destroy),window); g_signal_connect(G_OBJECT(loginbtn),"clicked",G_CALLBACK(regist_to_login_on_button_clicked),window); gtk_box_pack_start(GTK_BOX(btnbox),button,FALSE,FALSE,5); gtk_box_pack_start(GTK_BOX(btnbox),loginbtn,FALSE,FALSE,5); //gtk_widget_show_all(window); //gtk_main(); return window; }
static int gtkDialogSetBackgroundAttrib(Ihandle* ih, const char* value) { if (iupdrvBaseSetBgColorAttrib(ih, value)) { #if GTK_CHECK_VERSION(3, 0, 0) GdkWindow* window = iupgtkGetWindow(ih->handle); if (window) gdk_window_set_background_pattern(window, NULL); #else GtkStyle *style = gtk_widget_get_style(ih->handle); if (style->bg_pixmap[GTK_STATE_NORMAL]) { style = gtk_style_copy(style); style->bg_pixmap[GTK_STATE_NORMAL] = NULL; gtk_widget_set_style(ih->handle, style); } #endif return 1; } else { GdkPixbuf* pixbuf = iupImageGetImage(value, ih, 0); if (pixbuf) { #if GTK_CHECK_VERSION(3, 0, 0) GdkWindow* window = iupgtkGetWindow(ih->handle); if (window) { /* TODO: this is NOT working!!!! */ cairo_pattern_t* pattern; int width = gdk_pixbuf_get_width(pixbuf); int height = gdk_pixbuf_get_height(pixbuf); cairo_surface_t* surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, width, height); cairo_t* cr = cairo_create(surface); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_destroy(cr); pattern = cairo_pattern_create_for_surface(surface); cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); gdk_window_set_background_pattern(window, pattern); cairo_pattern_destroy (pattern); cairo_surface_destroy(surface); } #else GdkPixmap* pixmap; GtkStyle *style = gtk_style_copy(gtk_widget_get_style(ih->handle)); gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 255); style->bg_pixmap[GTK_STATE_NORMAL] = pixmap; gtk_widget_set_style(ih->handle, style); #endif return 1; } } return 0; }
int main(int argc, char *argv[]) { GtkWidget *box, *button, *poz, *reg_b, *frame; GtkStyle *style; GdkPixmap *bg; char buffer[buffsize]; if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { fprintf(stderr, "WSAStartup() failed"); exit(1); } if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) puts("socket() failed"); memset(&server, 0, sizeof(server)); /* Zero out structure */ server.sin_family = AF_INET; /* Internet address family */ server.sin_addr.s_addr = inet_addr("127.0.0.1"); /* Server IP address */ server.sin_port = htons(21); /* Server port */ if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0) /* Establish the connection to the server */ puts("connect() failed"); gtk_init(&argc, &argv); //start GTK+ pixbuf = gdk_pixbuf_new_from_file_utf8("bgm.jpg", error); //read background gdk_pixbuf_render_pixmap_and_mask(pixbuf, &bg, NULL, 0); style = gtk_style_new(); style->bg_pixmap[0] = bg; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); //create window //gtk_window_set_default_size(GTK_WINDOW(window), 1280, 720); pixbuf = gdk_pixbuf_new_from_file_utf8("logo.gif", error); //read logo gtk_window_set_icon(GTK_WINDOW (window), pixbuf); //set logo gtk_container_set_border_width(GTK_CONTAINER (window), 10); //create close window event g_signal_connect(window, "delete-event", G_CALLBACK (delete_event), NULL); gtk_widget_set_style(GTK_WIDGET(window), GTK_STYLE(style)); //set background box = gtk_vbox_new(FALSE, 0); //the mess of positioning poz = gtk_hbox_new(FALSE, 0); logbox = gtk_vbox_new(FALSE, 0); gamebox = gtk_vbox_new(FALSE, 0); //positioning ends here //Setting up used Widgets -> buttons, input fields, ... //image = gtk_image_new_from_file_utf8("maemo.png"); pixbuf = gdk_pixbuf_new_from_file_at_scale_utf8("pic/0.jpg", 500, 500, TRUE, //read shown image error); image = gtk_image_new_from_pixbuf(pixbuf); //set image frame = gtk_frame_new(NULL); gtk_frame_set_shadow_type((GtkFrame *) frame, GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER (frame), image); gtk_container_add(GTK_CONTAINER (poz), frame); gtk_widget_show(frame); gtk_box_pack_start(GTK_BOX (poz), box, FALSE, FALSE, 10); //a bit of positioning gtk_box_pack_start(GTK_BOX (box), logbox, FALSE, FALSE, 10); gtk_box_pack_start(GTK_BOX (box), gamebox, FALSE, FALSE, 10); //end logname = gtk_entry_new(); gtk_box_pack_start(GTK_BOX (logbox), logname, FALSE, FALSE, 10); gtk_widget_show(logname); pass = gtk_entry_new(); gtk_box_pack_start(GTK_BOX (logbox), pass, FALSE, FALSE, 10); gtk_widget_show(pass); button = gtk_button_new_with_label("login"); g_signal_connect(button, "clicked", G_CALLBACK (login), (gpointer) NULL); gtk_box_pack_start(GTK_BOX (logbox), button, FALSE, FALSE, 10); gtk_widget_show(button); reg_b = gtk_button_new_with_label("Register"); g_signal_connect(reg_b, "clicked", G_CALLBACK (reg), (gpointer) "NULL"); gtk_box_pack_start(GTK_BOX (logbox), reg_b, FALSE, FALSE, 10); gtk_widget_show(reg_b); cbutton = gtk_button_new_with_label(buffer); g_signal_connect(cbutton, "clicked", G_CALLBACK (lan), (gpointer) buffer); gtk_box_pack_start(GTK_BOX (gamebox), cbutton, FALSE, FALSE, 10); button = gtk_button_new_with_label("picture"); g_signal_connect(button, "clicked", G_CALLBACK (set_image), "pic"); gtk_box_pack_start(GTK_BOX (gamebox), button, FALSE, FALSE, 10); stats = make_stats(); gtk_box_pack_start(GTK_BOX (gamebox), stats, FALSE, FALSE, 10); status = gtk_toggle_button_new_with_label("connected"); gtk_toggle_button_set_active((GtkToggleButton *) status, TRUE); g_signal_connect(status, "toggled", G_CALLBACK (clcon), (gpointer) NULL); gtk_box_pack_start(GTK_BOX (box), status, FALSE, FALSE, 10); gtk_container_add(GTK_CONTAINER (window), poz); //showing the parts of the window gtk_widget_show(status); gtk_widget_show(image); gtk_widget_show(logbox); gtk_widget_show(poz); gtk_widget_show(box); gtk_widget_show(window); gtk_main(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *frame0; GtkWidget *frame1; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *label; GtkWidget *cancelbutton; GtkWidget *image; GdkWindow *root; GdkCursor *cursor; GdkPixbuf *bkpixbuf; GdkPixmap *bkpixmap; int timeout_cnt; char btntextbuf[32]; gtk_init(&argc, &argv); bindtextdomain(DOMAIN, POSITION); bind_textdomain_codeset(DOMAIN, "UTF-8"); textdomain(DOMAIN); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); frame0 = gtk_frame_new(NULL); gtk_frame_set_shadow_type(GTK_FRAME(frame0), GTK_SHADOW_OUT); gtk_container_add(GTK_CONTAINER(window), frame0); frame1 = gtk_frame_new(NULL); gtk_frame_set_shadow_type(GTK_FRAME(frame1), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(frame0), frame1); vbox = gtk_vbox_new(FALSE, 4); gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); gtk_container_add(GTK_CONTAINER(frame1), vbox); label = gtk_label_new(_("Please click 'OK' before timeout if you can see it.")); gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); label = gtk_label_new(""); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0); timeout_cnt = TIMEOUT_MAX; snprintf(btntextbuf, sizeof(btntextbuf), _(btnfmt), timeout_cnt); button = gtk_button_new_with_mnemonic(btntextbuf); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(ok_clicked), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); label = gtk_label_new(""); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0); cancelbutton = gtk_button_new_with_mnemonic(_("_Cancel")); g_signal_connect(G_OBJECT(cancelbutton), "clicked", G_CALLBACK(cancel_clicked), NULL); gtk_box_pack_start(GTK_BOX(hbox), cancelbutton, FALSE, FALSE, 0); label = gtk_label_new(""); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0); root = gdk_get_default_root_window(); cursor = gdk_cursor_new(GDK_LEFT_PTR); gdk_window_set_cursor(root, cursor); image = gtk_image_new_from_file(POSITION "/txbackground.png"); bkpixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); gdk_pixbuf_render_pixmap_and_mask(bkpixbuf, &bkpixmap, NULL, 0); gdk_window_set_back_pixmap(root, bkpixmap, 0); gdk_window_clear(root); gtk_widget_show_all(window); gtk_timeout_add(1000, timeout_func, &timeout_cnt); gtk_main(); return 0; }
static gint thumbview_thumbs_next (void) { ZAlbumCell *cell; thumbview->thumbs_count++; if (thumbview->thumbs_stop) { thumbview_thumbs_cleanup (); return FALSE; } if (thumbview->thumbs_count < ZALBUM (thumbview->album)->len) { gchar *path; cell = ZLIST_CELL_FROM_INDEX (ZLIST (thumbview->album), thumbview->thumbs_count); path = g_strdup (cell->name); if (file_type_is_movie (cell->name)) { GdkPixbuf *pixbuf = NULL; GdkPixmap *pixmap; GdkBitmap *mask; gchar *cache_dir; mode_t mode = 0755; gfloat status; cache_dir = cache_get_location (CACHE_THUMBS, path, FALSE, NULL, &mode); if (cache_ensure_dir_exists (cache_dir, mode)) { gchar *cache_path; cache_path = g_strconcat (cache_dir, "/", g_basename (cell->name), PORNVIEW_CACHE_THUMB_EXT, NULL); #ifdef USE_GTK2 pixbuf = gdk_pixbuf_new_from_file (cache_path, NULL); #else pixbuf = gdk_pixbuf_new_from_file (cache_path); #endif if (pixbuf) { gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, 128); zalbum_set_pixmap (ZALBUM (thumbview->album), thumbview->thumbs_count, pixmap, mask); if (pixmap) gdk_pixmap_unref (pixmap); if (mask) gdk_bitmap_unref (mask); gdk_pixbuf_unref (pixbuf); } else { pixbuf = image_get_video_pixbuf (); gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, 128); zalbum_set_pixmap (ZALBUM (thumbview->album), thumbview->thumbs_count, pixmap, mask); if (pixmap) gdk_pixmap_unref (pixmap); if (mask) gdk_bitmap_unref (mask); gdk_pixbuf_unref (pixbuf); } g_free (cache_path); } g_free (cache_dir); g_free (path); status = (gfloat) thumbview->thumbs_count / ZALBUM (thumbview->album)->len; thumbview_thumbs_progressbar (status); while (gtk_events_pending ()) gtk_main_iteration (); thumbview_thumbs_do (NULL); return TRUE; } else { thumb_loader_free (thumbview->thumbs_loader); thumbview->thumbs_loader = thumb_loader_new (path, 100, 100); g_free (path); thumb_loader_set_error_func (thumbview->thumbs_loader, cb_thumbview_thumbs_error, NULL); if (!thumb_loader_start (thumbview->thumbs_loader, cb_thumbview_thumbs_done, NULL)) { thumbview_thumbs_do (NULL); return TRUE; } } return FALSE; } else { thumbview_thumbs_cleanup (); return FALSE; } return TRUE; }