?? gdkcolor-win32.c
字號(hào):
static voidcreate_colormap (GdkColormap *cmap, gboolean writeable){ struct { LOGPALETTE pal; PALETTEENTRY pe[256-1]; } lp; HPALETTE hpal; GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (cmap); gint i; /* Allocate a starting palette with all the static colors. */ hpal = GetStockObject (DEFAULT_PALETTE); lp.pal.palVersion = 0x300; lp.pal.palNumEntries = GetPaletteEntries (hpal, 0, 256, lp.pal.palPalEntry); if (cmap->visual->type == GDK_VISUAL_STATIC_COLOR && cmap->visual->depth == 4) { /* Use only 16 colors */ for (i = 8; i < 16; i++) lp.pal.palPalEntry[i] = lp.pal.palPalEntry[i+4]; lp.pal.palNumEntries = 16; } for (i = 0; i < lp.pal.palNumEntries; i++) lp.pal.palPalEntry[i].peFlags = 0; GDK_NOTE (COLORMAP, (g_print ("Default palette %p: %d entries\n", hpal, lp.pal.palNumEntries), _gdk_win32_print_paletteentries (lp.pal.palPalEntry, lp.pal.palNumEntries))); DeleteObject (hpal); /* For writeable colormaps, allow all 256 entries to be set. They won't * set all 256 system palette entries anyhow, of course, but we shouldn't * let the app see that, I think. */ if (writeable) cmapp->current_size = 0; else cmapp->current_size = lp.pal.palNumEntries; cmapp->private_val = writeable; if (!(cmapp->hpal = CreatePalette (&lp.pal))) WIN32_GDI_FAILED ("CreatePalette"); else GDK_NOTE (COLORMAP, g_print ("Created palette %p\n", cmapp->hpal)); switch (cmap->visual->type) { case GDK_VISUAL_PSEUDO_COLOR: cmapp->use = g_new (GdkWin32PalEntryState, cmap->size); /* Mark static colors in use. */ for (i = 0; i < cmapp->current_size; i++) { cmapp->use[i] = GDK_WIN32_PE_STATIC; cmapp->info[i].ref_count = G_MAXUINT/2; } /* Mark rest not in use */ for (; i < cmap->size; i++) cmapp->use[i] = GDK_WIN32_PE_AVAILABLE; break; default: break; }}static voidsync_colors (GdkColormap *colormap){ PALETTEENTRY *pe; GdkColormapPrivateWin32 *private = GDK_WIN32_COLORMAP_DATA (colormap); gint nlookup; gint i; pe = g_new (PALETTEENTRY, colormap->size); nlookup = GetPaletteEntries (private->hpal, 0, colormap->size, pe); GDK_NOTE (COLORMAP, (g_print ("sync_colors: %p hpal=%p: %d entries\n", private, private->hpal, nlookup), _gdk_win32_print_paletteentries (pe, nlookup))); for (i = 0; i < nlookup; i++) { colormap->colors[i].pixel = i; colormap->colors[i].red = (pe[i].peRed * 65535) / 255; colormap->colors[i].green = (pe[i].peGreen * 65535) / 255; colormap->colors[i].blue = (pe[i].peBlue * 65535) / 255; } for ( ; i < colormap->size; i++) { colormap->colors[i].pixel = i; colormap->colors[i].red = 0; colormap->colors[i].green = 0; colormap->colors[i].blue = 0; } g_free (pe);}GdkColormap*gdk_colormap_new (GdkVisual *visual, gboolean private_cmap){ GdkColormap *colormap; GdkColormapPrivateWin32 *private; g_return_val_if_fail (visual != NULL, NULL); colormap = g_object_new (gdk_colormap_get_type (), NULL); private = GDK_WIN32_COLORMAP_DATA (colormap); colormap->visual = visual; colormap->size = visual->colormap_size; switch (visual->type) { case GDK_VISUAL_GRAYSCALE: case GDK_VISUAL_PSEUDO_COLOR: private->info = g_new0 (GdkColorInfo, colormap->size); colormap->colors = g_new (GdkColor, colormap->size); private->hash = g_hash_table_new ((GHashFunc) gdk_color_hash, (GEqualFunc) gdk_color_equal); create_colormap (colormap, private_cmap); if (private_cmap) { sync_colors (colormap);#if 0 /* XXX is this needed or not? Seems redundant */ gdk_colormap_change (colormap, colormap->size);#endif } break; case GDK_VISUAL_STATIC_GRAY: case GDK_VISUAL_STATIC_COLOR: create_colormap (colormap, FALSE); colormap->colors = g_new (GdkColor, colormap->size); sync_colors (colormap); break; case GDK_VISUAL_TRUE_COLOR: break; default: g_assert_not_reached (); } return colormap;}GdkColormap*gdk_screen_get_system_colormap (GdkScreen *screen){ static GdkColormap *colormap = NULL; GdkColormapPrivateWin32 *private; if (!colormap) { colormap = g_object_new (gdk_colormap_get_type (), NULL); private = GDK_WIN32_COLORMAP_DATA (colormap); colormap->visual = gdk_visual_get_system (); colormap->size = colormap->visual->colormap_size; private->private_val = FALSE; switch (colormap->visual->type) { case GDK_VISUAL_GRAYSCALE: case GDK_VISUAL_PSEUDO_COLOR: private->info = g_new0 (GdkColorInfo, colormap->size); private->hash = g_hash_table_new ((GHashFunc) gdk_color_hash, (GEqualFunc) gdk_color_equal); /* Fallthrough */ case GDK_VISUAL_STATIC_GRAY: case GDK_VISUAL_STATIC_COLOR: create_colormap (colormap, FALSE); colormap->colors = g_new (GdkColor, colormap->size); sync_colors (colormap); break; case GDK_VISUAL_TRUE_COLOR: break; default: g_assert_not_reached (); } } return colormap;}gintgdk_colormap_get_system_size (void){ return gdk_colormap_get_system ()->size;}voidgdk_colormap_change (GdkColormap *colormap, gint ncolors){ GdkColormapPrivateWin32 *cmapp; PALETTEENTRY *pe; int i; g_return_if_fail (colormap != NULL); cmapp = GDK_WIN32_COLORMAP_DATA (colormap); GDK_NOTE (COLORMAP, g_print ("gdk_colormap_change: hpal=%p ncolors=%d\n", cmapp->hpal, ncolors)); switch (colormap->visual->type) { case GDK_VISUAL_GRAYSCALE: case GDK_VISUAL_PSEUDO_COLOR: pe = g_new (PALETTEENTRY, ncolors); for (i = 0; i < ncolors; i++) { pe[i].peRed = (colormap->colors[i].red >> 8); pe[i].peGreen = (colormap->colors[i].green >> 8); pe[i].peBlue = (colormap->colors[i].blue >> 8); pe[i].peFlags = 0; } if (!SetPaletteEntries (cmapp->hpal, 0, ncolors, pe)) WIN32_GDI_FAILED ("SetPaletteEntries"); g_free (pe); break; default: break; }}gbooleangdk_colors_alloc (GdkColormap *colormap, gboolean contiguous, gulong *planes, gint nplanes, gulong *pixels, gint npixels){ GdkColormapPrivateWin32 *private; gint return_val; gint i; g_return_val_if_fail (GDK_IS_COLORMAP (colormap), 0); private = GDK_WIN32_COLORMAP_DATA (colormap); return_val = alloc_color_cells (colormap, contiguous, planes, nplanes, pixels, npixels); if (return_val) { for (i = 0; i < npixels; i++) { private->info[pixels[i]].ref_count++; private->info[pixels[i]].flags |= GDK_COLOR_WRITEABLE; } } return return_val != 0;}voidgdk_colors_free (GdkColormap *colormap, gulong *in_pixels, gint in_npixels, gulong planes){ GdkColormapPrivateWin32 *private; gulong *pixels; gint npixels = 0; gint i; g_return_if_fail (GDK_IS_COLORMAP (colormap)); g_return_if_fail (in_pixels != NULL); private = GDK_WIN32_COLORMAP_DATA (colormap); if ((colormap->visual->type != GDK_VISUAL_PSEUDO_COLOR) && (colormap->visual->type != GDK_VISUAL_GRAYSCALE)) return; pixels = g_new (gulong, in_npixels); for (i = 0; i < in_npixels; i++) { gulong pixel = in_pixels[i]; if (private->use[pixel] == GDK_WIN32_PE_STATIC) continue; if (private->info[pixel].ref_count) { private->info[pixel].ref_count--; if (private->info[pixel].ref_count == 0) { pixels[npixels++] = pixel; if (!(private->info[pixel].flags & GDK_COLOR_WRITEABLE)) g_hash_table_remove (private->hash, &colormap->colors[pixel]); private->info[pixel].flags = 0; } } } if (npixels) free_colors (colormap, pixels, npixels, planes); g_free (pixels);}voidgdk_colormap_free_colors (GdkColormap *colormap, GdkColor *colors, gint ncolors){ gulong *pixels; gint i; g_return_if_fail (GDK_IS_COLORMAP (colormap)); g_return_if_fail (colors != NULL); if ((colormap->visual->type != GDK_VISUAL_PSEUDO_COLOR) && (colormap->visual->type != GDK_VISUAL_GRAYSCALE)) return; pixels = g_new (gulong, ncolors); for (i = 0; i < ncolors; i++) pixels[i] = colors[i].pixel; gdk_colors_free (colormap, pixels, ncolors, 0); g_free (pixels);}/******************** * Color allocation * ********************//* Try to allocate a single color using alloc_color. If it succeeds, * cache the result in our colormap, and store in ret. */static gboolean gdk_colormap_alloc1 (GdkColormap *colormap, GdkColor *color, GdkColor *ret){ GdkColormapPrivateWin32 *private; PALETTEENTRY pe; private = GDK_WIN32_COLORMAP_DATA (colormap); pe.peRed = color->red >> 8; pe.peGreen = color->green >> 8; pe.peBlue = color->blue >> 8; if (alloc_color (colormap, &pe, &ret->pixel)) { ret->red = (pe.peRed * 65535) / 255; ret->green = (pe.peGreen * 65535) / 255; ret->blue = (pe.peBlue * 65535) / 255; if ((guint) ret->pixel < colormap->size) { if (private->info[ret->pixel].ref_count) /* got a duplicate */ { } else { colormap->colors[ret->pixel] = *color; colormap->colors[ret->pixel].pixel = ret->pixel; private->info[ret->pixel].ref_count = 1; g_hash_table_insert (private->hash, &colormap->colors[ret->pixel], &colormap->colors[ret->pixel]); } } return TRUE; } return FALSE;}static gintgdk_colormap_alloc_colors_writeable (GdkColormap *colormap, GdkColor *colors, gint ncolors, gboolean writeable, gboolean best_match, gboolean *success){ GdkColormapPrivateWin32 *private; gulong *pixels; gboolean status; gint i, index; private = GDK_WIN32_COLORMAP_DATA (colormap); if (private->private_val) { index = 0; for (i=0; i<ncolors; i++) { while ((index < colormap->size) && (private->info[index].ref_count != 0)) index++; if (index < colormap->size) { colors[i].pixel = index; success[i] = TRUE; private->info[index].ref_count++; private->info[i].flags |= GDK_COLOR_WRITEABLE; } else break; } return i;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -