let GimpColorArea optionally draw a thin border around itself.

2003-03-14  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/gimpcolorarea.[ch]: let GimpColorArea optionally
	draw a thin border around itself.

	* app/widgets/gimpitemfactory.c (gimp_item_factory_set_color): use
	a GimpColorArea instead of a deprecated GtkPreview.
This commit is contained in:
Sven Neumann 2003-03-14 15:08:10 +00:00 committed by Sven Neumann
parent 46c234c774
commit 0225506c43
7 changed files with 84 additions and 114 deletions

View File

@ -1,3 +1,11 @@
2003-03-14 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpcolorarea.[ch]: let GimpColorArea optionally
draw a thin border around itself.
* app/widgets/gimpitemfactory.c (gimp_item_factory_set_color): use
a GimpColorArea instead of a deprecated GtkPreview.
2003-03-14 Sven Neumann <sven@gimp.org>
* app/tools/gimpcurvestool.[ch]: some cleanup to event handling

View File

@ -20,11 +20,6 @@
#include "string.h"
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@ -45,6 +40,10 @@
#include "libgimp/gimpintl.h"
#define COLOR_BOX_WIDTH 16
#define COLOR_BOX_HEIGHT 16
/* local function prototypes */
static void gimp_item_factory_class_init (GimpItemFactoryClass *klass);
@ -459,8 +458,8 @@ gimp_item_factory_set_color (GtkItemFactory *factory,
gboolean set_label)
{
GtkWidget *widget;
GtkWidget *preview = NULL;
GtkWidget *label = NULL;
GtkWidget *area = NULL;
GtkWidget *label = NULL;
g_return_if_fail (GTK_IS_ITEM_FACTORY (factory));
g_return_if_fail (path != NULL);
@ -476,13 +475,10 @@ gimp_item_factory_set_color (GtkItemFactory *factory,
return;
}
#define COLOR_BOX_WIDTH 16
#define COLOR_BOX_HEIGHT 16
if (GTK_IS_HBOX (GTK_BIN (widget)->child))
{
preview = g_object_get_data (G_OBJECT (GTK_BIN (widget)->child),
"preview");
area = g_object_get_data (G_OBJECT (GTK_BIN (widget)->child),
"color_area");
label = g_object_get_data (G_OBJECT (GTK_BIN (widget)->child),
"label");
}
@ -500,100 +496,24 @@ gimp_item_factory_set_color (GtkItemFactory *factory,
gtk_container_add (GTK_CONTAINER (widget), hbox);
gtk_widget_show (hbox);
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (preview),
COLOR_BOX_WIDTH, COLOR_BOX_HEIGHT);
gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0);
gtk_widget_show (preview);
area = gimp_color_area_new (color, GIMP_COLOR_AREA_FLAT, 0);
gimp_color_area_set_draw_border (GIMP_COLOR_AREA (area), TRUE);
gtk_widget_set_size_request (area, COLOR_BOX_WIDTH, COLOR_BOX_HEIGHT);
gtk_box_pack_start (GTK_BOX (hbox), area, FALSE, FALSE, 0);
gtk_widget_show (area);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
g_object_unref (label);
g_object_set_data (G_OBJECT (hbox), "preview", preview);
g_object_set_data (G_OBJECT (hbox), "label", label);
g_object_set_data (G_OBJECT (hbox), "color_area", area);
g_object_set_data (G_OBJECT (hbox), "label", label);
}
if (preview)
{
guchar rows[3][COLOR_BOX_WIDTH * 3];
gint x, y;
gint r0, g0, b0;
gint r1, g1, b1;
guchar *p0, *p1, *p2;
/* Fill rows */
r0 = (GIMP_CHECK_DARK + (color->r - GIMP_CHECK_DARK) * color->a) * 255.0;
r1 = (GIMP_CHECK_LIGHT + (color->r - GIMP_CHECK_LIGHT) * color->a) * 255.0;
g0 = (GIMP_CHECK_DARK + (color->g - GIMP_CHECK_DARK) * color->a) * 255.0;
g1 = (GIMP_CHECK_LIGHT + (color->g - GIMP_CHECK_LIGHT) * color->a) * 255.0;
b0 = (GIMP_CHECK_DARK + (color->b - GIMP_CHECK_DARK) * color->a) * 255.0;
b1 = (GIMP_CHECK_LIGHT + (color->b - GIMP_CHECK_LIGHT) * color->a) * 255.0;
p0 = rows[0];
p1 = rows[1];
p2 = rows[2];
for (x = 0; x < COLOR_BOX_WIDTH; x++)
{
if ((x == 0) || (x == (COLOR_BOX_WIDTH - 1)))
{
*p0++ = 0;
*p0++ = 0;
*p0++ = 0;
*p1++ = 0;
*p1++ = 0;
*p1++ = 0;
}
else if ((x / GIMP_CHECK_SIZE) & 1)
{
*p0++ = r1;
*p0++ = g1;
*p0++ = b1;
*p1++ = r0;
*p1++ = g0;
*p1++ = b0;
}
else
{
*p0++ = r0;
*p0++ = g0;
*p0++ = b0;
*p1++ = r1;
*p1++ = g1;
*p1++ = b1;
}
*p2++ = 0;
*p2++ = 0;
*p2++ = 0;
}
/* Fill preview */
gtk_preview_draw_row (GTK_PREVIEW (preview), rows[2],
0, 0, COLOR_BOX_WIDTH);
for (y = 1; y < (COLOR_BOX_HEIGHT - 1); y++)
if ((y / GIMP_CHECK_SIZE) & 1)
gtk_preview_draw_row (GTK_PREVIEW (preview), rows[1],
0, y, COLOR_BOX_WIDTH);
else
gtk_preview_draw_row (GTK_PREVIEW (preview), rows[0],
0, y, COLOR_BOX_WIDTH);
gtk_preview_draw_row (GTK_PREVIEW (preview), rows[2],
0, y, COLOR_BOX_WIDTH);
gtk_widget_queue_draw (preview);
}
if (area)
gimp_color_area_set_color (GIMP_COLOR_AREA (area), color);
if (label && set_label)
{
@ -606,9 +526,6 @@ gimp_item_factory_set_color (GtkItemFactory *factory,
g_free (str);
}
#undef COLOR_BOX_WIDTH
#undef COLOR_BOX_HEIGHT
}
void

View File

@ -1,3 +1,8 @@
2003-03-14 Sven Neumann <sven@gimp.org>
* libgimpwidgets/libgimpwidgets-sections.txt
* tmpl/gimpcolorarea.sgml: updated.
2003-03-06 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am

View File

@ -27,6 +27,7 @@ gimp_color_area_set_color
gimp_color_area_get_color
gimp_color_area_has_alpha
gimp_color_area_set_type
gimp_color_area_set_draw_border
<SUBSECTION Standard>
GIMP_COLOR_AREA
GIMP_IS_COLOR_AREA

View File

@ -85,3 +85,12 @@ GimpColorArea
@gca:
<!-- ##### FUNCTION gimp_color_area_set_draw_border ##### -->
<para>
</para>
@area:
@draw_border:

View File

@ -151,6 +151,7 @@ gimp_color_area_init (GimpColorArea *area)
area->type = GIMP_COLOR_AREA_FLAT;
gimp_rgba_set (&area->color, 0.0, 0.0, 0.0, 1.0);
area->draw_border = FALSE;
area->needs_render = TRUE;
}
@ -227,6 +228,13 @@ gimp_color_area_expose (GtkWidget *widget,
event->area.x,
event->area.y);
if (area->draw_border)
gdk_draw_rectangle (widget->window,
widget->style->fg_gc[widget->state],
FALSE,
0, 0,
area->width - 1, area->height - 1);
return FALSE;
}
@ -355,6 +363,26 @@ gimp_color_area_set_type (GimpColorArea *area,
gtk_widget_queue_draw (GTK_WIDGET (area));
}
/**
* gimp_color_area_set_draw_border:
* @area: Pointer to a #GimpColorArea.
* @draw_border: whether to draw a border or not
*
* The @area can draw a thin border in the foreground color around
* itself. This function allows to toggle this behaviour on and
* off. The default is not draw a border.
**/
void
gimp_color_area_set_draw_border (GimpColorArea *area,
gboolean draw_border)
{
g_return_if_fail (GIMP_IS_COLOR_AREA (area));
area->draw_border = draw_border ? TRUE : FALSE;
gtk_widget_queue_draw (GTK_WIDGET (area));
}
static void
gimp_color_area_render (GimpColorArea *area)
{

View File

@ -55,8 +55,8 @@ struct _GimpColorArea
GimpColorAreaType type;
GimpRGB color;
gboolean needs_render;
guint draw_border : 1;
guint needs_render : 1;
};
struct _GimpColorAreaClass
@ -67,19 +67,21 @@ struct _GimpColorAreaClass
};
GType gimp_color_area_get_type (void) G_GNUC_CONST;
GType gimp_color_area_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_color_area_new (const GimpRGB *color,
GimpColorAreaType type,
GdkModifierType drag_mask);
GtkWidget * gimp_color_area_new (const GimpRGB *color,
GimpColorAreaType type,
GdkModifierType drag_mask);
void gimp_color_area_set_color (GimpColorArea *area,
const GimpRGB *color);
void gimp_color_area_get_color (GimpColorArea *area,
GimpRGB *color);
gboolean gimp_color_area_has_alpha (GimpColorArea *area);
void gimp_color_area_set_type (GimpColorArea *area,
GimpColorAreaType type);
void gimp_color_area_set_color (GimpColorArea *area,
const GimpRGB *color);
void gimp_color_area_get_color (GimpColorArea *area,
GimpRGB *color);
gboolean gimp_color_area_has_alpha (GimpColorArea *area);
void gimp_color_area_set_type (GimpColorArea *area,
GimpColorAreaType type);
void gimp_color_area_set_draw_border (GimpColorArea *area,
gboolean draw_border);
G_END_DECLS