Commit b7c12944 authored by Darin Adler's avatar Darin Adler
Browse files

Turned on gradients for backgrounds.

parent 8190453e
2000-01-14 Darin Adler <darin@eazel.com>
Turned on gradients for backgrounds.
* src/ntl-index-panel.c:
(nautilus_index_panel_drag_data_received): Use the new
accept_dropped_color function in NautilusBackground instead of
code in here. (nautilus_index_panel_background_changed):
(nautilus_index_panel_set_up_info): Save background to metadata
when the NautilusBackground object emits the changed signal.
* libnautilus/nautilus-background.h:
libnautilus/nautilus-background.c:
(nautilus_background_accept_dropped_color): Moved logic about
dropping a color coupon to change the background into the
NautilusBackground class. This includes a first cut at the rules
about gradients.
* libnautilus/nautilus-background.c:
(nautilus_background_get_color): Implemented this missing
function. It's used by the code in index panel now to save the
current background.
* libnautilus/nautilus-background.c:
(nautilus_background_draw_flat_box): Implemented gradient fills
through the GtkStyle subclass.
* src/ntl-main.c: (main): Made criticals and warnings be always
fatal. Next step is to make them drop into the debugger, but not
result in a core dump if the debugger is not running.
2000-01-14 Darin Adler <darin@eazel.com>
* src/ntl-index-panel.c: (nautilus_index_panel_set_up_label):
......
......@@ -157,6 +157,14 @@ nautilus_background_draw (NautilusBackground *background,
&start_color, &end_color, horizontal_gradient);
}
char *
nautilus_background_get_color (NautilusBackground *background)
{
g_return_val_if_fail (NAUTILUS_IS_BACKGROUND (background), NULL);
return g_strdup (background->details->color);
}
void
nautilus_background_set_color (NautilusBackground *background,
const char *color)
......@@ -215,6 +223,8 @@ nautilus_background_draw_flat_box (GtkStyle *style,
{
gboolean call_parent;
NautilusBackground *background;
GdkGC *gc;
GdkRectangle rectangle;
call_parent = TRUE;
......@@ -224,12 +234,27 @@ nautilus_background_draw_flat_box (GtkStyle *style,
call_parent = FALSE;
}
if (!call_parent)
g_warning ("gradient fills not yet hooked up in nautilus_background");
if (call_parent) {
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
return;
}
gc = gdk_gc_new (window);
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
nautilus_gdk_window_update_sizes (window, &width, &height);
rectangle.x = x;
rectangle.y = y;
rectangle.width = width;
rectangle.height = height;
nautilus_background_draw (background, window, gc,
gtk_widget_get_colormap(widget),
&rectangle);
gdk_gc_unref (gc);
}
static GtkStyleClass *
......@@ -318,6 +343,16 @@ nautilus_widget_background_changed (GtkWidget *widget, NautilusBackground *backg
gtk_widget_queue_clear (widget);
}
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *
nautilus_get_widget_background (GtkWidget *widget)
{
......@@ -351,6 +386,56 @@ nautilus_get_widget_background (GtkWidget *widget)
return background;
}
void
nautilus_background_receive_dropped_color (NautilusBackground *background,
GtkWidget *widget,
int drop_location_x,
int drop_location_y,
const GtkSelectionData *selection_data)
{
guint16 *channels;
char *color_spec;
char *new_gradient_spec;
int left_border, right_border, top_border, bottom_border;
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (selection_data != NULL);
/* Convert the selection data into a color spec. */
if (selection_data->length != 8 || selection_data->format != 16) {
g_warning ("received invalid color data");
return;
}
channels = (guint16 *)selection_data->data;
color_spec = g_strdup_printf ("rgb:%04hX/%04hX/%04hX", channels[0], channels[1], channels[2]);
/* Figure out if the color was dropped close enough to an edge to create a gradient.
For the moment, this is hard-wired, but later the widget will have to have some
say in where the borders are.
*/
left_border = 32;
right_border = widget->allocation.width - 32;
top_border = 32;
bottom_border = widget->allocation.height - 32;
if (drop_location_x < left_border && drop_location_x <= right_border)
new_gradient_spec = nautilus_gradient_set_left_color_spec (background->details->color, color_spec);
else if (drop_location_x >= left_border && drop_location_x > right_border)
new_gradient_spec = nautilus_gradient_set_right_color_spec (background->details->color, color_spec);
else if (drop_location_y < top_border && drop_location_y <= bottom_border)
new_gradient_spec = nautilus_gradient_set_top_color_spec (background->details->color, color_spec);
else if (drop_location_y >= top_border && drop_location_y > bottom_border)
new_gradient_spec = nautilus_gradient_set_bottom_color_spec (background->details->color, color_spec);
else
new_gradient_spec = g_strdup (color_spec);
g_free (color_spec);
nautilus_background_set_color (background, new_gradient_spec);
g_free (new_gradient_spec);
}
/* self check code */
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
......
......@@ -57,34 +57,35 @@ typedef struct _NautilusBackgroundClass NautilusBackgroundClass;
#define NAUTILUS_IS_BACKGROUND_CLASS(klass) \
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BACKGROUND))
GtkType nautilus_background_get_type (void);
NautilusBackground *nautilus_background_new (void);
void nautilus_background_set_color (NautilusBackground *background,
const char *color_or_gradient);
void nautilus_background_set_tile_image_uri (NautilusBackground *background,
const char *image_uri);
char * nautilus_background_get_color (NautilusBackground *background);
char * nautilus_background_get_tile_image_uri (NautilusBackground *background);
void nautilus_background_draw (NautilusBackground *background,
GdkDrawable *drawable,
GdkGC *gc,
GdkColormap *colormap,
const GdkRectangle *rectangle);
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
GtkType nautilus_background_get_type (void);
NautilusBackground *nautilus_background_new (void);
/* Calls to change a background. */
void nautilus_background_set_color (NautilusBackground *background,
const char *color_or_gradient);
void nautilus_background_set_tile_image_uri (NautilusBackground *background,
const char *image_uri);
/* Calls to interrogate the current state of a background. */
char * nautilus_background_get_color (NautilusBackground *background);
char * nautilus_background_get_tile_image_uri (NautilusBackground *background);
/* Explicitly fills a rectangle with a background. */
void nautilus_background_draw (NautilusBackground *background,
GdkDrawable *drawable,
GdkGC *gc,
GdkColormap *colormap,
const GdkRectangle *rectangle);
/* Handles a dragged color being dropped on a widget to change the background color. */
void nautilus_background_receive_dropped_color (NautilusBackground *background,
GtkWidget *widget,
int drop_location_x,
int drop_location_y,
const GtkSelectionData *dropped_color);
/* Gets or creates a background so that it's attached to a widget. */
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
typedef struct _NautilusBackgroundDetails NautilusBackgroundDetails;
......@@ -99,7 +100,7 @@ struct _NautilusBackgroundClass
GtkObjectClass parent_class;
/* This signal is emitted when the background image is
finished loading. This allows a window to draw with a
finished loading. This allows a window to draw with a
color background if the image takes a lot time to load.
*/
void (* changed) (NautilusBackground *);
......
......@@ -157,6 +157,14 @@ nautilus_background_draw (NautilusBackground *background,
&start_color, &end_color, horizontal_gradient);
}
char *
nautilus_background_get_color (NautilusBackground *background)
{
g_return_val_if_fail (NAUTILUS_IS_BACKGROUND (background), NULL);
return g_strdup (background->details->color);
}
void
nautilus_background_set_color (NautilusBackground *background,
const char *color)
......@@ -215,6 +223,8 @@ nautilus_background_draw_flat_box (GtkStyle *style,
{
gboolean call_parent;
NautilusBackground *background;
GdkGC *gc;
GdkRectangle rectangle;
call_parent = TRUE;
......@@ -224,12 +234,27 @@ nautilus_background_draw_flat_box (GtkStyle *style,
call_parent = FALSE;
}
if (!call_parent)
g_warning ("gradient fills not yet hooked up in nautilus_background");
if (call_parent) {
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
return;
}
gc = gdk_gc_new (window);
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
nautilus_gdk_window_update_sizes (window, &width, &height);
rectangle.x = x;
rectangle.y = y;
rectangle.width = width;
rectangle.height = height;
nautilus_background_draw (background, window, gc,
gtk_widget_get_colormap(widget),
&rectangle);
gdk_gc_unref (gc);
}
static GtkStyleClass *
......@@ -318,6 +343,16 @@ nautilus_widget_background_changed (GtkWidget *widget, NautilusBackground *backg
gtk_widget_queue_clear (widget);
}
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *
nautilus_get_widget_background (GtkWidget *widget)
{
......@@ -351,6 +386,56 @@ nautilus_get_widget_background (GtkWidget *widget)
return background;
}
void
nautilus_background_receive_dropped_color (NautilusBackground *background,
GtkWidget *widget,
int drop_location_x,
int drop_location_y,
const GtkSelectionData *selection_data)
{
guint16 *channels;
char *color_spec;
char *new_gradient_spec;
int left_border, right_border, top_border, bottom_border;
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (selection_data != NULL);
/* Convert the selection data into a color spec. */
if (selection_data->length != 8 || selection_data->format != 16) {
g_warning ("received invalid color data");
return;
}
channels = (guint16 *)selection_data->data;
color_spec = g_strdup_printf ("rgb:%04hX/%04hX/%04hX", channels[0], channels[1], channels[2]);
/* Figure out if the color was dropped close enough to an edge to create a gradient.
For the moment, this is hard-wired, but later the widget will have to have some
say in where the borders are.
*/
left_border = 32;
right_border = widget->allocation.width - 32;
top_border = 32;
bottom_border = widget->allocation.height - 32;
if (drop_location_x < left_border && drop_location_x <= right_border)
new_gradient_spec = nautilus_gradient_set_left_color_spec (background->details->color, color_spec);
else if (drop_location_x >= left_border && drop_location_x > right_border)
new_gradient_spec = nautilus_gradient_set_right_color_spec (background->details->color, color_spec);
else if (drop_location_y < top_border && drop_location_y <= bottom_border)
new_gradient_spec = nautilus_gradient_set_top_color_spec (background->details->color, color_spec);
else if (drop_location_y >= top_border && drop_location_y > bottom_border)
new_gradient_spec = nautilus_gradient_set_bottom_color_spec (background->details->color, color_spec);
else
new_gradient_spec = g_strdup (color_spec);
g_free (color_spec);
nautilus_background_set_color (background, new_gradient_spec);
g_free (new_gradient_spec);
}
/* self check code */
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
......
......@@ -57,34 +57,35 @@ typedef struct _NautilusBackgroundClass NautilusBackgroundClass;
#define NAUTILUS_IS_BACKGROUND_CLASS(klass) \
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BACKGROUND))
GtkType nautilus_background_get_type (void);
NautilusBackground *nautilus_background_new (void);
void nautilus_background_set_color (NautilusBackground *background,
const char *color_or_gradient);
void nautilus_background_set_tile_image_uri (NautilusBackground *background,
const char *image_uri);
char * nautilus_background_get_color (NautilusBackground *background);
char * nautilus_background_get_tile_image_uri (NautilusBackground *background);
void nautilus_background_draw (NautilusBackground *background,
GdkDrawable *drawable,
GdkGC *gc,
GdkColormap *colormap,
const GdkRectangle *rectangle);
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
GtkType nautilus_background_get_type (void);
NautilusBackground *nautilus_background_new (void);
/* Calls to change a background. */
void nautilus_background_set_color (NautilusBackground *background,
const char *color_or_gradient);
void nautilus_background_set_tile_image_uri (NautilusBackground *background,
const char *image_uri);
/* Calls to interrogate the current state of a background. */
char * nautilus_background_get_color (NautilusBackground *background);
char * nautilus_background_get_tile_image_uri (NautilusBackground *background);
/* Explicitly fills a rectangle with a background. */
void nautilus_background_draw (NautilusBackground *background,
GdkDrawable *drawable,
GdkGC *gc,
GdkColormap *colormap,
const GdkRectangle *rectangle);
/* Handles a dragged color being dropped on a widget to change the background color. */
void nautilus_background_receive_dropped_color (NautilusBackground *background,
GtkWidget *widget,
int drop_location_x,
int drop_location_y,
const GtkSelectionData *dropped_color);
/* Gets or creates a background so that it's attached to a widget. */
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
typedef struct _NautilusBackgroundDetails NautilusBackgroundDetails;
......@@ -99,7 +100,7 @@ struct _NautilusBackgroundClass
GtkObjectClass parent_class;
/* This signal is emitted when the background image is
finished loading. This allows a window to draw with a
finished loading. This allows a window to draw with a
color background if the image takes a lot time to load.
*/
void (* changed) (NautilusBackground *);
......
......@@ -157,6 +157,14 @@ nautilus_background_draw (NautilusBackground *background,
&start_color, &end_color, horizontal_gradient);
}
char *
nautilus_background_get_color (NautilusBackground *background)
{
g_return_val_if_fail (NAUTILUS_IS_BACKGROUND (background), NULL);
return g_strdup (background->details->color);
}
void
nautilus_background_set_color (NautilusBackground *background,
const char *color)
......@@ -215,6 +223,8 @@ nautilus_background_draw_flat_box (GtkStyle *style,
{
gboolean call_parent;
NautilusBackground *background;
GdkGC *gc;
GdkRectangle rectangle;
call_parent = TRUE;
......@@ -224,12 +234,27 @@ nautilus_background_draw_flat_box (GtkStyle *style,
call_parent = FALSE;
}
if (!call_parent)
g_warning ("gradient fills not yet hooked up in nautilus_background");
if (call_parent) {
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
return;
}
gc = gdk_gc_new (window);
(* nautilus_gtk_style_get_default_class()->draw_flat_box)
(style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
nautilus_gdk_window_update_sizes (window, &width, &height);
rectangle.x = x;
rectangle.y = y;
rectangle.width = width;
rectangle.height = height;
nautilus_background_draw (background, window, gc,
gtk_widget_get_colormap(widget),
&rectangle);
gdk_gc_unref (gc);
}
static GtkStyleClass *
......@@ -318,6 +343,16 @@ nautilus_widget_background_changed (GtkWidget *widget, NautilusBackground *backg
gtk_widget_queue_clear (widget);
}
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *
nautilus_get_widget_background (GtkWidget *widget)
{
......@@ -351,6 +386,56 @@ nautilus_get_widget_background (GtkWidget *widget)
return background;
}
void
nautilus_background_receive_dropped_color (NautilusBackground *background,
GtkWidget *widget,
int drop_location_x,
int drop_location_y,
const GtkSelectionData *selection_data)
{
guint16 *channels;
char *color_spec;
char *new_gradient_spec;
int left_border, right_border, top_border, bottom_border;
g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (selection_data != NULL);
/* Convert the selection data into a color spec. */
if (selection_data->length != 8 || selection_data->format != 16) {
g_warning ("received invalid color data");
return;
}
channels = (guint16 *)selection_data->data;
color_spec = g_strdup_printf ("rgb:%04hX/%04hX/%04hX", channels[0], channels[1], channels[2]);
/* Figure out if the color was dropped close enough to an edge to create a gradient.
For the moment, this is hard-wired, but later the widget will have to have some
say in where the borders are.
*/
left_border = 32;
right_border = widget->allocation.width - 32;
top_border = 32;
bottom_border = widget->allocation.height - 32;
if (drop_location_x < left_border && drop_location_x <= right_border)
new_gradient_spec = nautilus_gradient_set_left_color_spec (background->details->color, color_spec);
else if (drop_location_x >= left_border && drop_location_x > right_border)
new_gradient_spec = nautilus_gradient_set_right_color_spec (background->details->color, color_spec);
else if (drop_location_y < top_border && drop_location_y <= bottom_border)
new_gradient_spec = nautilus_gradient_set_top_color_spec (background->details->color, color_spec);
else if (drop_location_y >= top_border && drop_location_y > bottom_border)
new_gradient_spec = nautilus_gradient_set_bottom_color_spec (background->details->color, color_spec);
else
new_gradient_spec = g_strdup (color_spec);
g_free (color_spec);
nautilus_background_set_color (background, new_gradient_spec);
g_free (new_gradient_spec);
}
/* self check code */
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
......
......@@ -57,34 +57,35 @@ typedef struct _NautilusBackgroundClass NautilusBackgroundClass;
#define NAUTILUS_IS_BACKGROUND_CLASS(klass) \
(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BACKGROUND))
GtkType nautilus_background_get_type (void);
NautilusBackground *nautilus_background_new (void);
void nautilus_background_set_color (NautilusBackground *background,
const char *color_or_gradient);
void nautilus_background_set_tile_image_uri (NautilusBackground *background,
const char *image_uri);
char * nautilus_background_get_color (NautilusBackground *background);
char * nautilus_background_get_tile_image_uri (NautilusBackground *background);
void nautilus_background_draw (NautilusBackground *background,
GdkDrawable *drawable,
GdkGC *gc,
GdkColormap *colormap,
const GdkRectangle *rectangle);
/* Gets the background attached to a widget.
If the widget doesn't already have a NautilusBackground object,
this will create one. To change the widget's background, you can
just call nautilus_background methods on the widget.
Later, we might want a call to find out if we already have a background,
or a way to share the same background among multiple widgets; both would
be straightforward.
*/
NautilusBackground *nautilus_get_widget_background (GtkWidget *widget);
GtkType nautilus_background_get_type (void);
NautilusBackground *nautilus_background_new (void);
/* Calls to change a background. */
void nautilus_background_set_color (NautilusBackground *background,
const char *color_or_gradient);
void nautilus_background_set_tile_image_uri (NautilusBackground *background,
const char *image_uri);
/* Calls to interrogate the current state of a background. */