gboolean xfwmPixmapRenderGdkPixbuf (xfwmPixmap * pm, GdkPixbuf *pixbuf) { GdkPixbuf *src; GdkPixmap *destw; GdkVisual *gvisual; GdkColormap *cmap; gint width, height; gint dest_x, dest_y; g_return_val_if_fail (pm != NULL, FALSE); g_return_val_if_fail (pm->pixmap != None, FALSE); g_return_val_if_fail (pm->mask != None, FALSE); destw = gdk_xid_table_lookup (pm->pixmap); if (destw) { g_object_ref (G_OBJECT (destw)); } else { destw = gdk_pixmap_foreign_new (pm->pixmap); } if (!destw) { g_warning ("Cannot get pixmap"); return FALSE; } gvisual = gdk_screen_get_system_visual (pm->screen_info->gscr); cmap = gdk_x11_colormap_foreign_new (gvisual, pm->screen_info->cmap); if (!cmap) { g_warning ("Cannot create colormap"); g_object_unref (destw); return FALSE; } width = MIN (gdk_pixbuf_get_width (pixbuf), pm->width); height = MIN (gdk_pixbuf_get_height (pixbuf), pm->height); /* Add 1 for rounding */ dest_x = (pm->width - width + 1) / 2; dest_y = (pm->height - height + 1) / 2; src = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE (destw), cmap, dest_x, dest_y, 0, 0, width, height); gdk_pixbuf_composite (pixbuf, src, 0, 0, width, height, 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 0xFF); gdk_draw_pixbuf (GDK_DRAWABLE (destw), NULL, src, 0, 0, dest_x, dest_y, width, height, GDK_RGB_DITHER_NONE, 0, 0); g_object_unref (cmap); g_object_unref (src); g_object_unref (destw); return TRUE; }
GdkPixbuf * meta_ui_get_pixbuf_from_pixmap (Pixmap pmap) { GdkPixmap *gpmap; GdkScreen *screen; GdkPixbuf *pixbuf; GdkColormap *cmap; int width, height, depth; gpmap = gdk_pixmap_foreign_new (pmap); screen = gdk_drawable_get_screen (gpmap); gdk_drawable_get_size (GDK_DRAWABLE (gpmap), &width, &height); depth = gdk_drawable_get_depth (GDK_DRAWABLE (gpmap)); if (depth <= 24) cmap = gdk_screen_get_rgb_colormap (screen); else cmap = gdk_screen_get_rgba_colormap (screen); pixbuf = gdk_pixbuf_get_from_drawable (NULL, gpmap, cmap, 0, 0, 0, 0, width, height); g_object_unref (gpmap); return pixbuf; }
void set_desktop_background(GdkWindow *window) { Pixmap xpm = get_pixmap_prop(GDK_WINDOW_XWINDOW(window), "_XROOTPMAP_ID"); if (xpm != None) { GdkPixmap *gpm = gdk_pixmap_foreign_new(xpm); gdk_window_set_back_pixmap (window, gpm, FALSE); g_object_unref (gpm); } }
GdkPixbuf* _lightdash_gdk_pixbuf_get_from_pixmap (GdkPixbuf *dest, Pixmap xpixmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height) { GdkDrawable *drawable; GdkPixbuf *retval; GdkColormap *cmap; retval = NULL; cmap = NULL; drawable = gdk_xid_table_lookup (xpixmap); if (drawable) g_object_ref (G_OBJECT (drawable)); else drawable = gdk_pixmap_foreign_new (xpixmap); if (drawable) { cmap = get_cmap (drawable); /* GDK is supposed to do this but doesn't in GTK 2.0.2, * fixed in 2.0.3 */ if (width < 0) gdk_drawable_get_size (drawable, &width, NULL); if (height < 0) gdk_drawable_get_size (drawable, NULL, &height); retval = gdk_pixbuf_get_from_drawable (dest, drawable, cmap, src_x, src_y, dest_x, dest_y, width, height); } if (cmap) g_object_unref (G_OBJECT (cmap)); if (drawable) g_object_unref (G_OBJECT (drawable)); return retval; }
void set_desktop_background(GdkWindow *window) { Pixmap xpm = get_pixmap_prop(GDK_WINDOW_XWINDOW(window), "_XROOTPMAP_ID"); #ifdef HAVE_GTK3 if (xpm != None) { GdkScreen *screen = gdk_window_get_screen(window); Window root_return; int x, y; unsigned int width, height, bw, depth_ret; cairo_surface_t *surface = NULL; gdk_error_trap_push(); if (XGetGeometry(GDK_SCREEN_XDISPLAY(screen), xpm, &root_return, &x, &y, &width, &height, &bw, &depth_ret)) { surface = cairo_xlib_surface_create(GDK_SCREEN_XDISPLAY (screen), xpm, GDK_VISUAL_XVISUAL(gdk_screen_get_system_visual(screen)), width, height); } gdk_error_trap_pop_ignored (); cairo_pattern_t *pattern = cairo_pattern_create_for_surface(surface); gdk_window_set_background_pattern(window, pattern); cairo_surface_destroy(surface); // cairo_pattern_destroy ??? } else { GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 }; gdk_window_set_background_rgba(window, &black); } #else if (xpm != None) { GDKPIXMAP *gpm = gdk_pixmap_foreign_new(xpm); gdk_window_set_back_pixmap (window, gpm, FALSE); g_object_unref (gpm); } #endif }
GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (GdkPixbuf *dest, Pixmap xpixmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height) { GdkDrawable *drawable; GdkPixbuf *retval; #if !GTK_CHECK_VERSION (3, 0, 0) GdkColormap *cmap; #endif retval = NULL; #if !GTK_CHECK_VERSION (3, 0, 0) cmap = NULL; #endif drawable = gdk_x11_window_lookup_for_display (gdk_display_get_default (), xpixmap); if (drawable) g_object_ref (G_OBJECT (drawable)); else drawable = gdk_pixmap_foreign_new (xpixmap); if (drawable) { cmap = get_cmap (drawable); retval = gdk_pixbuf_get_from_drawable (dest, drawable, cmap, src_x, src_y, dest_x, dest_y, width, height); } #if !GTK_CHECK_VERSION (3, 0, 0) if (cmap) g_object_unref (G_OBJECT (cmap)); #endif if (drawable) g_object_unref (G_OBJECT (drawable)); return retval; }
GdkPixmap * create_native_pixmap_and_wrap (int w, int h, GtkWidget *parent_style_window) { GdkWindow *window; if (w <= 0 || h <= 0) abort (); window = gtk_widget_get_window (parent_style_window); GdkPixmap *pixmap = gdk_pixmap_foreign_new (XCreatePixmap (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), GDK_WINDOW_XID (window), w, h, gdk_drawable_get_depth (window))); GdkColormap *cmap = get_colormap_for_drawable (GDK_DRAWABLE (pixmap)); gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), cmap); return pixmap; }
GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (GdkPixbuf *dest, Pixmap xpixmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height) { GdkDrawable *drawable; GdkPixbuf *retval; GdkColormap *cmap; retval = NULL; cmap = NULL; drawable = gdk_xid_table_lookup (xpixmap); if (drawable) g_object_ref (G_OBJECT (drawable)); else drawable = gdk_pixmap_foreign_new (xpixmap); if (drawable) { cmap = get_cmap (drawable); retval = gdk_pixbuf_get_from_drawable (dest, drawable, cmap, src_x, src_y, dest_x, dest_y, width, height); } if (cmap) g_object_unref (G_OBJECT (cmap)); if (drawable) g_object_unref (G_OBJECT (drawable)); return retval; }
GdkPixbuf* meta_ui_get_pixbuf_from_pixmap(Pixmap pmap) { GdkPixmap* gpmap; GdkScreen* screen; GdkPixbuf* pixbuf; #if !GTK_CHECK_VERSION (3, 0, 0) GdkColormap* cmap; #endif int width; int height; int depth; gpmap = gdk_pixmap_foreign_new(pmap); screen = gdk_drawable_get_screen(gpmap); #if GTK_CHECK_VERSION(3, 0, 0) width = gdk_window_get_width(GDK_WINDOW(gpmap)); height = gdk_window_get_height(GDK_WINDOW(gpmap)); #else gdk_drawable_get_size(GDK_DRAWABLE(gpmap), &width, &height); #endif depth = gdk_drawable_get_depth(GDK_DRAWABLE(gpmap)); #if !GTK_CHECK_VERSION (3, 0, 0) if (depth <= 24) { cmap = gdk_screen_get_system_colormap(screen); } else { cmap = gdk_screen_get_rgba_colormap(screen); } #endif pixbuf = gdk_pixbuf_get_from_drawable(NULL, gpmap, cmap, 0, 0, 0, 0, width, height); g_object_unref(gpmap); return pixbuf; }
static gboolean xfwmPixmapDrawFromGdkPixbuf (xfwmPixmap * pm, GdkPixbuf *pixbuf) { GdkPixmap *dest_pixmap; GdkPixmap *dest_bitmap; GdkVisual *gvisual; GdkColormap *cmap; gint width, height; gint dest_x, dest_y; gint alpha_threshold; g_return_val_if_fail (pm != NULL, FALSE); g_return_val_if_fail (pm->pixmap != None, FALSE); g_return_val_if_fail (pm->mask != None, FALSE); dest_pixmap = gdk_xid_table_lookup (pm->pixmap); if (dest_pixmap) { g_object_ref (G_OBJECT (dest_pixmap)); } else { dest_pixmap = gdk_pixmap_foreign_new (pm->pixmap); } if (!dest_pixmap) { g_warning ("Cannot get pixmap"); return FALSE; } dest_bitmap = gdk_xid_table_lookup (pm->mask); if (dest_bitmap) { g_object_ref (G_OBJECT (dest_bitmap)); } else { dest_bitmap = gdk_pixmap_foreign_new (pm->mask); } if (!dest_bitmap) { g_warning ("Cannot get bitmap"); g_object_unref (dest_pixmap); return FALSE; } gvisual = gdk_screen_get_system_visual (pm->screen_info->gscr); cmap = gdk_x11_colormap_foreign_new (gvisual, pm->screen_info->cmap); if (!cmap) { g_warning ("Cannot create colormap"); g_object_unref (dest_pixmap); g_object_unref (dest_bitmap); return FALSE; } width = MIN (gdk_pixbuf_get_width (pixbuf), pm->width); height = MIN (gdk_pixbuf_get_height (pixbuf), pm->height); dest_x = (pm->width - width) / 2; dest_y = (pm->height - height) / 2; gdk_drawable_set_colormap (GDK_DRAWABLE (dest_pixmap), cmap); gdk_draw_pixbuf (GDK_DRAWABLE (dest_pixmap), NULL, pixbuf, 0, 0, dest_x, dest_y, width, height, GDK_RGB_DITHER_NONE, 0, 0); alpha_threshold = (gdk_pixbuf_get_has_alpha (pixbuf) ? 0xFF : 0); gdk_pixbuf_render_threshold_alpha (pixbuf, dest_bitmap, 0, 0, dest_x, dest_y, width, height, alpha_threshold); g_object_unref (cmap); g_object_unref (dest_pixmap); g_object_unref (dest_bitmap); return TRUE; }
GdkPixmap* gdk_pixmap_foreign_new_for_display (GdkDisplay *display, GdkNativeWindow anid) { return gdk_pixmap_foreign_new(anid); }
/* XXX: Make this more general */ static GdkPixbuf* preview_menu(RrTheme *theme) { RrAppearance *title; RrAppearance *title_text; RrAppearance *menu; RrAppearance *background; RrAppearance *normal; RrAppearance *disabled; RrAppearance *selected; RrAppearance *bullet; /* for submenu */ GdkPixmap *pixmap; GdkPixbuf *pixbuf; /* width and height of the whole menu */ gint width, height; gint x, y; gint title_h; gint tw, th; gint bw, bh; gint unused; /* set up appearances */ title = theme->a_menu_title; title_text = theme->a_menu_text_title; title_text->surface.parent = title; title_text->texture[0].data.text.string = "Menu"; normal = theme->a_menu_text_normal; normal->texture[0].data.text.string = "Normal"; disabled = theme->a_menu_text_disabled; disabled->texture[0].data.text.string = "Disabled"; selected = theme->a_menu_text_selected; selected->texture[0].data.text.string = "Selected"; bullet = theme->a_menu_bullet_normal; /* determine window size */ RrMinSize(normal, &width, &th); width += th + PADDING; /* make space for the bullet */ //height = th; width += 2*theme->mbwidth + 2*PADDING; /* get minimum title size */ RrMinSize(title, &tw, &title_h); /* size of background behind each text line */ bw = width - 2*theme->mbwidth; //title_h += 2*PADDING; title_h = theme->menu_title_height; RrMinSize(normal, &unused, &th); bh = th + 2*PADDING; height = title_h + 3*bh + 3*theme->mbwidth; //height += 3*th + 3*theme->mbwidth + 5*PADDING; /* set border */ pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height); gdk_pixbuf_fill(pixbuf, rr_color_pixel(theme->menu_border_color)); /* draw title */ x = y = theme->mbwidth; theme_pixmap_paint(title, bw, title_h); /* draw title text */ title_text->surface.parentx = 0; title_text->surface.parenty = 0; theme_pixmap_paint(title_text, bw, title_h); pixmap = gdk_pixmap_foreign_new(title_text->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, bw, title_h); /* menu appears after title */ y += theme->mbwidth + title_h; /* fill in menu appearance, used as the parent to every menu item's bg */ menu = theme->a_menu; th = height - 3*theme->mbwidth - title_h; theme_pixmap_paint(menu, bw, th); pixmap = gdk_pixmap_foreign_new(menu->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, bw, th); /* fill in background appearance, used as the parent to text items */ background = theme->a_menu_normal; background->surface.parent = menu; background->surface.parentx = 0; background->surface.parenty = 0; /* draw background for normal entry */ theme_pixmap_paint(background, bw, bh); pixmap = gdk_pixmap_foreign_new(background->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, bw, bh); /* draw normal entry */ normal->surface.parent = background; normal->surface.parentx = PADDING; normal->surface.parenty = PADDING; x += PADDING; y += PADDING; RrMinSize(normal, &tw, &th); theme_pixmap_paint(normal, tw, th); pixmap = gdk_pixmap_foreign_new(normal->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, tw, th); /* draw bullet */ RrMinSize(normal, &tw, &th); bullet->surface.parent = background; bullet->surface.parentx = bw - th; bullet->surface.parenty = PADDING; theme_pixmap_paint(bullet, th, th); pixmap = gdk_pixmap_foreign_new(bullet->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, width - theme->mbwidth - th, y, th, th); y += th + 2*PADDING; /* draw background for disabled entry */ background->surface.parenty = bh; theme_pixmap_paint(background, bw, bh); pixmap = gdk_pixmap_foreign_new(background->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x - PADDING, y - PADDING, bw, bh); /* draw disabled entry */ RrMinSize(disabled, &tw, &th); disabled->surface.parent = background; disabled->surface.parentx = PADDING; disabled->surface.parenty = PADDING; theme_pixmap_paint(disabled, tw, th); pixmap = gdk_pixmap_foreign_new(disabled->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, tw, th); y += th + 2*PADDING; /* draw background for selected entry */ background = theme->a_menu_selected; background->surface.parent = menu; background->surface.parentx = 2*bh; theme_pixmap_paint(background, bw, bh); pixmap = gdk_pixmap_foreign_new(background->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x - PADDING, y - PADDING, bw, bh); /* draw selected entry */ RrMinSize(selected, &tw, &th); selected->surface.parent = background; selected->surface.parentx = PADDING; selected->surface.parenty = PADDING; theme_pixmap_paint(selected, tw, th); pixmap = gdk_pixmap_foreign_new(selected->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, tw, th); return pixbuf; }
static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout, gboolean focus, gint width, gint height) { RrAppearance *title; RrAppearance *handle; RrAppearance *a; GdkPixmap *pixmap; GdkPixbuf *pixbuf = NULL; GdkPixbuf *scratch; gint w, label_w, h, x, y; const gchar *layout; title = focus ? theme->a_focused_title : theme->a_unfocused_title; /* set border */ pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); gdk_pixbuf_fill(pixbuf, rr_color_pixel(focus ? theme->frame_focused_border_color : theme->frame_unfocused_border_color)); /* title */ w = width - 2*theme->fbwidth; h = theme->title_height; theme_pixmap_paint(title, w, h); x = y = theme->fbwidth; pixmap = gdk_pixmap_foreign_new(title->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, w, h); /* calculate label width */ label_w = width - (theme->paddingx + theme->fbwidth + 1) * 2; for (layout = titlelayout; *layout; layout++) { switch (*layout) { case 'N': label_w -= theme->button_size + 2 + theme->paddingx + 1; break; case 'D': case 'S': case 'I': case 'M': case 'C': label_w -= theme->button_size + theme->paddingx + 1; break; default: break; } } x = theme->paddingx + theme->fbwidth + 1; y += theme->paddingy; for (layout = titlelayout; *layout; layout++) { /* icon */ if (*layout == 'N') { a = theme->a_icon; /* set default icon */ a->texture[0].type = RR_TEXTURE_RGBA; a->texture[0].data.rgba.width = 48; a->texture[0].data.rgba.height = 48; a->texture[0].data.rgba.alpha = 0xff; a->texture[0].data.rgba.data = theme->def_win_icon; a->surface.parent = title; a->surface.parentx = x - theme->fbwidth; a->surface.parenty = theme->paddingy; w = h = theme->button_size + 2; theme_pixmap_paint(a, w, h); pixmap = gdk_pixmap_foreign_new(a->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, w, h); x += theme->button_size + 2 + theme->paddingx + 1; } else if (*layout == 'L') { /* label */ a = focus ? theme->a_focused_label : theme->a_unfocused_label; a->texture[0].data.text.string = focus ? "Active" : "Inactive"; a->surface.parent = title; a->surface.parentx = x - theme->fbwidth; a->surface.parenty = theme->paddingy; w = label_w; h = theme->label_height; theme_pixmap_paint(a, w, h); pixmap = gdk_pixmap_foreign_new(a->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, w, h); x += w + theme->paddingx + 1; } else { /* buttons */ switch (*layout) { case 'D': a = focus ? theme->btn_desk->a_focused_unpressed : theme->btn_desk->a_unfocused_unpressed; break; case 'S': a = focus ? theme->btn_shade->a_focused_unpressed : theme->btn_shade->a_unfocused_unpressed; break; case 'I': a = focus ? theme->btn_iconify->a_focused_unpressed : theme->btn_iconify->a_unfocused_unpressed; break; case 'M': a = focus ? theme->btn_max->a_focused_unpressed : theme->btn_max->a_unfocused_unpressed; break; case 'C': a = focus ? theme->btn_close->a_focused_unpressed : theme->btn_close->a_unfocused_unpressed; break; default: continue; } a->surface.parent = title; a->surface.parentx = x - theme->fbwidth; a->surface.parenty = theme->paddingy + 1; w = theme->button_size; h = theme->button_size; theme_pixmap_paint(a, w, h); pixmap = gdk_pixmap_foreign_new(a->pixmap); /* use y + 1 because these buttons should be centered wrt the label */ pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y + 1, w, h); x += theme->button_size + theme->paddingx + 1; } } if (theme->handle_height) { /* handle */ handle = focus ? theme->a_focused_handle : theme->a_unfocused_handle; x = 2*theme->fbwidth + theme->grip_width; y = height - theme->fbwidth - theme->handle_height; w = width - 4*theme->fbwidth - 2*theme->grip_width; h = theme->handle_height; theme_pixmap_paint(handle, w, h); pixmap = gdk_pixmap_foreign_new(handle->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, w, h); /* openbox handles this drawing stuff differently (it fills the bottom * of the window with the handle), so it avoids this bug where * parentrelative grips are not fully filled. i'm avoiding it slightly * differently. */ theme_pixmap_paint(handle, width, h); /* grips */ a = focus ? theme->a_focused_grip : theme->a_unfocused_grip; a->surface.parent = handle; x = theme->fbwidth; /* same y and h as handle */ w = theme->grip_width; theme_pixmap_paint(a, w, h); pixmap = gdk_pixmap_foreign_new(a->pixmap); pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, w, h); /* right grip */ x = width - theme->fbwidth - theme->grip_width; pixbuf = gdk_pixbuf_get_from_drawable(pixbuf, pixmap, gdk_colormap_get_system(), 0, 0, x, y, w, h); } /* title separator colour */ x = theme->fbwidth; y = theme->fbwidth + theme->title_height; w = width - 2*theme->fbwidth; h = theme->fbwidth; scratch = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h); gdk_pixbuf_fill(scratch, rr_color_pixel(focus ? theme->title_separator_focused_color : theme->title_separator_unfocused_color)); gdk_pixbuf_copy_area(scratch, 0, 0, w, h, pixbuf, x, y); /* retarded way of adding client colour */ x = theme->fbwidth; y = theme->title_height + 2*theme->fbwidth; w = width - 2*theme->fbwidth; h = height - theme->title_height - 3*theme->fbwidth - (theme->handle_height ? (theme->fbwidth + theme->handle_height) : 0); scratch = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h); gdk_pixbuf_fill(scratch, rr_color_pixel(focus ? theme->cb_focused_color : theme->cb_unfocused_color)); gdk_pixbuf_copy_area(scratch, 0, 0, w, h, pixbuf, x, y); /* clear (no alpha!) the area where the client resides */ gdk_pixbuf_fill(scratch, 0xffffffff); gdk_pixbuf_copy_area(scratch, 0, 0, w - 2*theme->cbwidthx, h - 2*theme->cbwidthy, pixbuf, x + theme->cbwidthx, y + theme->cbwidthy); return pixbuf; }
void MdispGtkView::InitializeOverlay() { MIL_TEXT_CHAR chText[80]; // Initialize overlay if not already done if ((!m_isOverlayInitialized) && (m_MilDisplay)) { //Only do it on a valid windowed display [CALL TO MIL] if (m_MilImage && m_MilDisplay ) { // Prepare overlay buffer // //////////////////////////// // Enable display overlay annotations. MdispControl(m_MilDisplay, M_OVERLAY, M_ENABLE); // Inquire the Overlay buffer associated with the displayed buffer [CALL TO MIL] MdispInquire(m_MilDisplay, M_OVERLAY_ID, &m_MilOverlayImage); // Clear the overlay to transparent. MdispControl(m_MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT); // Disable the overlay display update to accelerate annotations. MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_DISABLE); // Draw MIL monochrome overlay annotation * //***************************************** // Inquire MilOverlayImage size x and y [CALL TO MIL] long imageWidth = MbufInquire(m_MilOverlayImage,M_SIZE_X,M_NULL); long imageHeight = MbufInquire(m_MilOverlayImage,M_SIZE_Y,M_NULL); // Set graphic text to transparent background. [CALL TO MIL] MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT); // Set drawing color to white. [CALL TO MIL] MgraColor(M_DEFAULT, M_COLOR_WHITE); // Print a string in the overlay image buffer. [CALL TO MIL] MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5, " -------------------- "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5+25, " - MIL Overlay Text - "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5+50, " -------------------- "); // Print a green string in the green component overlay image buffer. [CALL TO MIL] MgraColor(M_DEFAULT, M_COLOR_GREEN); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5, " -------------------- "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5+25, " - MIL Overlay Text - "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5+50, " -------------------- "); // Draw GDI color overlay annotation * //************************************ // Disable hook to MIL error because control might not be supported MappControl(M_ERROR_HOOKS, M_DISABLE); // Create a device context to draw in the overlay buffer with GDI. [CALL TO MIL] MbufControl(m_MilOverlayImage, M_XPIXMAP_ALLOC, M_COMPENSATION_ENABLE); // Reenable hook to MIL error MappControl(M_ERROR_HOOKS, M_ENABLE); // Retrieve the XPIXMAP of the overlay [CALL TO MIL] Pixmap XPixmap = (Pixmap)MbufInquire(m_MilOverlayImage, M_XPIXMAP_HANDLE, M_NULL); /* convert it to gdkpixmap */ GdkPixmap *gdkpixmap = gdk_pixmap_foreign_new(XPixmap); if(gdkpixmap) { GdkPoint Hor[2]; GdkPoint Ver[2]; GdkColor color[3]; GdkFont *font = NULL; font = gdk_font_load ("-misc-*-*-r-*-*-*-140-*-*-*-*-*-1"); int i; /* get graphic context from pixmap*/ GdkGC *gc = gdk_gc_new(gdkpixmap); /* allocate colors */ gdk_color_parse("blue",&color[0]); gdk_color_parse("red",&color[1]); gdk_color_parse("yellow",&color[2]); for(i=0;i<3;i++) gdk_color_alloc(gdk_colormap_get_system(), &color[i]); /* set the foreground to our color */ gdk_gc_set_foreground(gc, &color[0]); // Draw a blue cross in the overlay buffer. Hor[0].x = 0; Hor[0].y = imageHeight/2; Hor[1].x = imageWidth; Hor[1].y = imageHeight/2; gdk_draw_lines(gdkpixmap,gc,Hor,2); Ver[0].x = imageWidth/2; Ver[0].y = 0; Ver[1].x = imageWidth/2; Ver[1].y = imageHeight; gdk_draw_lines(gdkpixmap,gc,Ver,2); // Write Red text in the overlay buffer. MosStrcpy(chText, 80, "X Overlay Text "); gdk_gc_set_foreground(gc, &color[1]); gdk_draw_string(gdkpixmap, font, gc, imageWidth*3/18, imageHeight*4/6, chText); // Write Yellow text in the overlay buffer. gdk_gc_set_foreground(gc, &color[2]); gdk_draw_string(gdkpixmap, font, gc, imageWidth*12/18, imageHeight*4/6, chText); /* flush */ gdk_display_flush(gdk_display_get_default()); /* Free graphic context.*/ g_object_unref(gc); // Delete created Pixmap. [CALL TO MIL] MbufControl(m_MilOverlayImage, M_XPIXMAP_FREE, M_DEFAULT); // Signal MIL that the overlay buffer was modified. [CALL TO MIL] MbufControl(m_MilOverlayImage, M_MODIFIED, M_DEFAULT); } // Now that overlay buffer is correctly prepared, we can show it [CALL TO MIL] MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_ENABLE); // Overlay is now initialized m_isOverlayInitialized = true; } } }