mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-05 16:20:10 +00:00
2f50232a42
2006-09-21 Michael Natterer <mitch@imendio.com> Implement lots of value setters for GdkGC, based on a heavily modified patch from Thomas Broyer (bug #328853): * gdk/quartz/gdkcolor-quartz.c: removed functions which set colors on the CGContext. Instead, added gdk_quartz_get_rgba_from_pixel() which simply returns RGBA values from a GdkColor's pixel value. See gdk_quartz_update_context_from_gc() below. * gdk/quartz/gdkprivate-quartz.h (struct GdkGCQuartz): added lots of members for the newly suppored GC values. Added enum GdkQuartzContextValuesMask which is used for setting up the CGContext for filling and/or stroking. * gdk/quartz/gdkgc-quartz.c (gdk_quartz_gc_get_values) (gdk_quartz_gc_set_values) (_gdk_windowing_gc_copy): support a lot more GC values. (gdk_quartz_update_context_from_gc): added GdkQuartzContextValuesMask parameter and set filling/stroking parameters accordingly. This function also gained full control over the FG and BG colors (they can't be set separately any more). The stipple mask part of the patch doesn't work but seems to take the right approach and doesn't make things worse, so I applied it. Did *not* apply the clipping part of the patch since I don't understand it (I don't understand the version in CVS either, but it at least works :-) * gdk/quartz/gdkdrawable-quartz.c: pass the right masks to gdk_quartz_update_context_from_gc() and removed separate color setting calls. Some minor fixes. * gdk/quartz/gdkwindow-quartz.c (gdk_window_impl_quartz_begin_paint_region): set the CGContext's fill color manually. We don't have/need a GC here.
200 lines
4.4 KiB
C
200 lines
4.4 KiB
C
/* gdkcolor-quartz.c
|
|
*
|
|
* Copyright (C) 2005 Imendio AB
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "gdkcolor.h"
|
|
#include "gdkprivate-quartz.h"
|
|
|
|
GType
|
|
gdk_colormap_get_type (void)
|
|
{
|
|
static GType object_type = 0;
|
|
|
|
if (!object_type)
|
|
{
|
|
static const GTypeInfo object_info =
|
|
{
|
|
sizeof (GdkColormapClass),
|
|
(GBaseInitFunc) NULL,
|
|
(GBaseFinalizeFunc) NULL,
|
|
(GClassInitFunc) NULL,
|
|
NULL, /* class_finalize */
|
|
NULL, /* class_data */
|
|
sizeof (GdkColormap),
|
|
0, /* n_preallocs */
|
|
(GInstanceInitFunc) NULL,
|
|
};
|
|
|
|
object_type = g_type_register_static (G_TYPE_OBJECT,
|
|
"GdkColormap",
|
|
&object_info,
|
|
0);
|
|
}
|
|
|
|
return object_type;
|
|
}
|
|
|
|
GdkColormap *
|
|
gdk_colormap_new (GdkVisual *visual,
|
|
gint private_cmap)
|
|
{
|
|
g_return_val_if_fail (visual != NULL, NULL);
|
|
|
|
/* FIXME: Implement */
|
|
return NULL;
|
|
}
|
|
|
|
GdkColormap *
|
|
gdk_screen_get_system_colormap (GdkScreen *screen)
|
|
{
|
|
static GdkColormap *colormap = NULL;
|
|
|
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
|
|
|
if (!colormap)
|
|
{
|
|
colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
|
|
|
|
colormap->visual = gdk_visual_get_system ();
|
|
colormap->size = colormap->visual->colormap_size;
|
|
}
|
|
|
|
return colormap;
|
|
}
|
|
|
|
|
|
GdkColormap *
|
|
gdk_screen_get_rgba_colormap (GdkScreen *screen)
|
|
{
|
|
static GdkColormap *colormap = NULL;
|
|
|
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
|
|
|
if (!colormap)
|
|
{
|
|
colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
|
|
|
|
colormap->visual = gdk_screen_get_rgba_visual (screen);
|
|
colormap->size = colormap->visual->colormap_size;
|
|
}
|
|
|
|
return colormap;
|
|
}
|
|
|
|
gint
|
|
gdk_colormap_get_system_size (void)
|
|
{
|
|
/* FIXME: Implement */
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
gdk_colormap_change (GdkColormap *colormap,
|
|
gint ncolors)
|
|
{
|
|
/* FIXME: Implement */
|
|
}
|
|
|
|
void
|
|
gdk_colormap_free_colors (GdkColormap *colormap,
|
|
GdkColor *colors,
|
|
gint ncolors)
|
|
{
|
|
/* This function shouldn't do anything since
|
|
* colors are neve allocated.
|
|
*/
|
|
}
|
|
|
|
gint
|
|
gdk_colormap_alloc_colors (GdkColormap *colormap,
|
|
GdkColor *colors,
|
|
gint ncolors,
|
|
gboolean writeable,
|
|
gboolean best_match,
|
|
gboolean *success)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ncolors; i++)
|
|
{
|
|
colors[i].pixel = ((colors[i].red >> 8) & 0xff) << 16 |
|
|
((colors[i].green >> 8) & 0xff) << 8 |
|
|
((colors[i].blue >> 8) & 0xff);
|
|
}
|
|
|
|
if (success)
|
|
*success = TRUE;
|
|
|
|
return ncolors;
|
|
}
|
|
|
|
void
|
|
gdk_colormap_query_color (GdkColormap *colormap,
|
|
gulong pixel,
|
|
GdkColor *result)
|
|
{
|
|
result->red = pixel >> 16 & 0xff;
|
|
result->red += result->red << 8;
|
|
|
|
result->green = pixel >> 8 & 0xff;
|
|
result->green += result->green << 8;
|
|
|
|
result->blue = pixel & 0xff;
|
|
result->blue += result->blue << 8;
|
|
}
|
|
|
|
GdkScreen*
|
|
gdk_colormap_get_screen (GdkColormap *cmap)
|
|
{
|
|
g_return_val_if_fail (cmap != NULL, NULL);
|
|
|
|
return gdk_screen_get_default ();
|
|
}
|
|
|
|
void
|
|
gdk_quartz_get_rgba_from_pixel (GdkColormap *colormap,
|
|
guint32 pixel,
|
|
float *red,
|
|
float *green,
|
|
float *blue,
|
|
float *alpha)
|
|
{
|
|
*red = (pixel >> 16 & 0xff) / 255.0;
|
|
*green = (pixel >> 8 & 0xff) / 255.0;
|
|
*blue = (pixel & 0xff) / 255.0;
|
|
|
|
if (colormap && gdk_colormap_get_visual (colormap)->depth == 32)
|
|
*alpha = (pixel >> 24 & 0xff) / 255.0;
|
|
else
|
|
*alpha = 1.0;
|
|
}
|
|
|
|
gboolean
|
|
gdk_color_change (GdkColormap *colormap,
|
|
GdkColor *color)
|
|
{
|
|
if (color->pixel < 0 || color->pixel >= colormap->size)
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|