Commit f2238c5c authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen
Browse files

Improve drawing of the outline for icon stretching, make the knob image

2005-10-28  Matthias Clasen  <mclasen@redhat.com>

	* libnautilus-private/nautilus-icon-canvas-item.h:
	* libnautilus-private/nautilus-icon-canvas-item.c (draw_stretch_handles:
	(hit_test_stretch_handle): Improve drawing of the outline for icon stretching,
	make the knob image themable as stock-nautilus-knob.

	* libnautilus-private/nautilus-icon-container.c: Implement icon stretching
	via keyboard, with <Control>+, <Control>- and <Control>0.

	* src/nautilus-window-manage-views.c (zoom_level_changed_callback): Make the
	ZOOM_NORMAL action insensitive when zooming is not supported, so that it
	does not eat <Control>0.
parent d741b23d
2005-10-28 Matthias Clasen <mclasen@redhat.com>
* libnautilus-private/nautilus-icon-canvas-item.h:
* libnautilus-private/nautilus-icon-canvas-item.c (draw_stretch_handles:
(hit_test_stretch_handle): Improve drawing of the outline for icon stretching,
make the knob image themable as stock-nautilus-knob.
* libnautilus-private/nautilus-icon-container.c: Implement icon stretching
via keyboard, with <Control>+, <Control>- and <Control>0.
* src/nautilus-window-manage-views.c (zoom_level_changed_callback): Make the
ZOOM_NORMAL action insensitive when zooming is not supported, so that it
does not eat <Control>0.
2005-10-26 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
......
......@@ -44,6 +44,7 @@
#include <eel/eel-accessibility.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtksignal.h>
#include <gdk/gdk.h>
#include <libart_lgpl/art_rgb.h>
#include <libart_lgpl/art_rgb_affine.h>
#include <libart_lgpl/art_rgb_rgba_affine.h>
......@@ -209,7 +210,8 @@ static void draw_label_layout (NautilusIconCanvasItem
GdkGC *gc);
static gboolean hit_test_stretch_handle (NautilusIconCanvasItem *item,
ArtIRect canvas_rect);
ArtIRect canvas_rect,
GtkCornerType *corner);
static void clear_rounded_corners (GdkPixbuf *destination_pixbuf,
GdkPixbuf *corner_pixbuf,
int corner_size);
......@@ -1152,12 +1154,30 @@ draw_label_text (NautilusIconCanvasItem *item, GdkDrawable *drawable,
draw_or_measure_label_text (item, drawable, create_mask, icon_rect);
}
static GdkPixbuf *
get_knob_pixbuf (void)
{
GdkPixbuf *knob_pixbuf;
char *knob_filename;
knob_pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"stock-nautilus-knob",
8, 0, NULL);
if (!knob_pixbuf) {
knob_filename = nautilus_pixmap_file ("knob.png");
knob_pixbuf = gdk_pixbuf_new_from_file (knob_filename, NULL);
g_free (knob_filename);
}
return knob_pixbuf;
}
static void
draw_stretch_handles (NautilusIconCanvasItem *item, GdkDrawable *drawable,
const ArtIRect *rect)
{
GtkWidget *widget;
GdkGC *gc;
char *knob_filename;
GdkPixbuf *knob_pixbuf;
GdkBitmap *stipple;
int knob_width, knob_height;
......@@ -1166,17 +1186,26 @@ draw_stretch_handles (NautilusIconCanvasItem *item, GdkDrawable *drawable,
return;
}
gc = gdk_gc_new (drawable);
widget = GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas);
knob_filename = nautilus_pixmap_file ("knob.png");
knob_pixbuf = gdk_pixbuf_new_from_file (knob_filename, NULL);
gc = gdk_gc_new (drawable);
knob_pixbuf = get_knob_pixbuf ();
knob_width = gdk_pixbuf_get_width (knob_pixbuf);
knob_height = gdk_pixbuf_get_height (knob_pixbuf);
stipple = eel_stipple_bitmap_for_screen (
gdk_drawable_get_screen (GDK_DRAWABLE (drawable)));
/* first draw the box */
/* first draw the box */
gdk_gc_set_rgb_fg_color (gc, &widget->style->white);
gdk_draw_rectangle
(drawable, gc, FALSE,
rect->x0,
rect->y0,
rect->x1 - rect->x0 - 1,
rect->y1 - rect->y0 - 1);
gdk_gc_set_rgb_fg_color (gc, &widget->style->black);
gdk_gc_set_stipple (gc, stipple);
gdk_gc_set_fill (gc, GDK_STIPPLED);
gdk_draw_rectangle
......@@ -1192,8 +1221,6 @@ draw_stretch_handles (NautilusIconCanvasItem *item, GdkDrawable *drawable,
draw_pixbuf (knob_pixbuf, drawable, rect->x0, rect->y1 - knob_height);
draw_pixbuf (knob_pixbuf, drawable, rect->x1 - knob_width, rect->y0);
draw_pixbuf (knob_pixbuf, drawable, rect->x1 - knob_width, rect->y1 - knob_height);
g_free (knob_filename);
g_object_unref (knob_pixbuf);
g_object_unref (gc);
......@@ -1828,7 +1855,7 @@ hit_test (NautilusIconCanvasItem *icon_item, ArtIRect canvas_rect)
}
/* Check for hits in the stretch handles. */
if (hit_test_stretch_handle (icon_item, canvas_rect)) {
if (hit_test_stretch_handle (icon_item, canvas_rect, NULL)) {
return TRUE;
}
......@@ -2055,12 +2082,13 @@ nautilus_icon_canvas_item_set_show_stretch_handles (NautilusIconCanvasItem *item
/* Check if one of the stretch handles was hit. */
static gboolean
hit_test_stretch_handle (NautilusIconCanvasItem *item,
ArtIRect probe_canvas_rect)
ArtIRect probe_canvas_rect,
GtkCornerType *corner)
{
ArtIRect icon_rect;
char *knob_filename;
GdkPixbuf *knob_pixbuf;
int knob_width, knob_height;
int hit_corner;
g_return_val_if_fail (NAUTILUS_IS_ICON_CANVAS_ITEM (item), FALSE);
......@@ -2074,25 +2102,36 @@ hit_test_stretch_handle (NautilusIconCanvasItem *item,
if (!eel_art_irect_hits_irect (probe_canvas_rect, icon_rect)) {
return FALSE;
}
knob_filename = nautilus_pixmap_file ("knob.png");
knob_pixbuf = gdk_pixbuf_new_from_file (knob_filename, NULL);
knob_pixbuf = get_knob_pixbuf ();
knob_width = gdk_pixbuf_get_width (knob_pixbuf);
knob_height = gdk_pixbuf_get_height (knob_pixbuf);
g_object_unref (knob_pixbuf);
g_free (knob_filename);
g_object_unref (knob_pixbuf);
/* Check for hits in the stretch handles. */
return (probe_canvas_rect.x0 < icon_rect.x0 + knob_width
|| probe_canvas_rect.x1 >= icon_rect.x1 - knob_width)
&& (probe_canvas_rect.y0 < icon_rect.y0 + knob_height
|| probe_canvas_rect.y1 >= icon_rect.y1 - knob_height);
hit_corner = -1;
if (probe_canvas_rect.x0 < icon_rect.x0 + knob_width) {
if (probe_canvas_rect.y0 < icon_rect.y0 + knob_height)
hit_corner = GTK_CORNER_TOP_LEFT;
else if (probe_canvas_rect.y1 >= icon_rect.y1 - knob_height)
hit_corner = GTK_CORNER_BOTTOM_LEFT;
}
else if (probe_canvas_rect.x1 >= icon_rect.x1 - knob_width) {
if (probe_canvas_rect.y0 < icon_rect.y0 + knob_height)
hit_corner = GTK_CORNER_TOP_RIGHT;
else if (probe_canvas_rect.y1 >= icon_rect.y1 - knob_height)
hit_corner = GTK_CORNER_BOTTOM_RIGHT;
}
if (corner)
*corner = hit_corner;
return hit_corner != -1;
}
gboolean
nautilus_icon_canvas_item_hit_test_stretch_handles (NautilusIconCanvasItem *item,
ArtPoint world_point)
ArtPoint world_point,
GtkCornerType *corner)
{
ArtIRect canvas_rect;
......@@ -2105,7 +2144,7 @@ nautilus_icon_canvas_item_hit_test_stretch_handles (NautilusIconCanvasItem *item
&canvas_rect.y0);
canvas_rect.x1 = canvas_rect.x0 + 1;
canvas_rect.y1 = canvas_rect.y0 + 1;
return hit_test_stretch_handle (item, canvas_rect);
return hit_test_stretch_handle (item, canvas_rect, corner);
}
/* nautilus_icon_canvas_item_hit_test_rectangle
......
......@@ -84,7 +84,8 @@ void nautilus_icon_canvas_item_set_renaming (NautilusIconCanv
gboolean nautilus_icon_canvas_item_hit_test_rectangle (NautilusIconCanvasItem *item,
ArtIRect canvas_rect);
gboolean nautilus_icon_canvas_item_hit_test_stretch_handles (NautilusIconCanvasItem *item,
ArtPoint world_point);
ArtPoint world_point,
GtkCornerType *corner);
void nautilus_icon_canvas_item_invalidate_label_size (NautilusIconCanvasItem *item);
ArtDRect nautilus_icon_canvas_item_get_icon_rectangle (const NautilusIconCanvasItem *item);
ArtDRect nautilus_icon_canvas_item_get_text_rectangle (const NautilusIconCanvasItem *item);
......
......@@ -3294,6 +3294,8 @@ start_stretching (NautilusIconContainer *container)
NautilusIcon *icon;
ArtPoint world_point;
GtkWidget *toplevel;
GtkCornerType corner;
GdkCursor *cursor;
details = container->details;
icon = details->stretch_icon;
......@@ -3301,11 +3303,27 @@ start_stretching (NautilusIconContainer *container)
/* Check if we hit the stretch handles. */
world_point.x = details->drag_x;
world_point.y = details->drag_y;
if (!nautilus_icon_canvas_item_hit_test_stretch_handles
(icon->item, world_point)) {
if (!nautilus_icon_canvas_item_hit_test_stretch_handles (icon->item, world_point, &corner)) {
return FALSE;
}
switch (corner) {
case GTK_CORNER_TOP_LEFT:
cursor = gdk_cursor_new (GDK_TOP_LEFT_CORNER);
break;
case GTK_CORNER_BOTTOM_LEFT:
cursor = gdk_cursor_new (GDK_BOTTOM_LEFT_CORNER);
break;
case GTK_CORNER_TOP_RIGHT:
cursor = gdk_cursor_new (GDK_TOP_RIGHT_CORNER);
break;
case GTK_CORNER_BOTTOM_RIGHT:
cursor = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER);
break;
default:
cursor = NULL;
break;
}
/* Set up the dragging. */
details->drag_state = DRAG_STATE_STRETCH;
eel_canvas_w2c (EEL_CANVAS (container),
......@@ -3323,8 +3341,10 @@ start_stretching (NautilusIconContainer *container)
eel_canvas_item_grab (EEL_CANVAS_ITEM (icon->item),
(GDK_POINTER_MOTION_MASK
| GDK_BUTTON_RELEASE_MASK),
NULL,
cursor,
GDK_CURRENT_TIME);
if (cursor)
gdk_cursor_unref (cursor);
/* Ensure the window itself is focused.. */
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
......@@ -3385,6 +3405,43 @@ continue_stretching (NautilusIconContainer *container,
}
}
static gboolean
keyboard_stretching (NautilusIconContainer *container,
GdkEventKey *event)
{
NautilusIcon *icon;
guint size;
icon = container->details->stretch_icon;
if (icon == NULL || !icon->is_selected) {
return FALSE;
}
icon_get_size (container, icon, &size);
switch (event->keyval) {
case GDK_equal:
case GDK_plus:
case GDK_KP_Add:
icon_set_size (container, icon, size + 5, FALSE, FALSE);
break;
case GDK_minus:
case GDK_KP_Subtract:
icon_set_size (container, icon, size - 5, FALSE, FALSE);
break;
case GDK_0:
case GDK_KP_0:
nautilus_icon_container_move_icon (container, icon,
icon->x, icon->y,
1.0, 1.0,
FALSE, TRUE, TRUE);
break;
}
return TRUE;
}
static void
ungrab_stretch_icon (NautilusIconContainer *container)
{
......@@ -3416,7 +3473,7 @@ end_stretching (NautilusIconContainer *container,
redo_layout (container);
}
static void
static gboolean
undo_stretching (NautilusIconContainer *container)
{
NautilusIcon *stretched_icon;
......@@ -3424,7 +3481,7 @@ undo_stretching (NautilusIconContainer *container)
stretched_icon = container->details->stretch_icon;
if (stretched_icon == NULL) {
return;
return FALSE;
}
if (container->details->drag_state == DRAG_STATE_STRETCH) {
......@@ -3446,6 +3503,8 @@ undo_stretching (NautilusIconContainer *container)
container->details->stretch_icon = NULL;
emit_stretch_ended (container, stretched_icon);
redo_layout (container);
return TRUE;
}
static gboolean
......@@ -4179,9 +4238,19 @@ key_press_event (GtkWidget *widget,
handled = TRUE;
break;
case GDK_Escape:
undo_stretching (container);
handled = TRUE;
case GDK_Escape:
handled = undo_stretching (container);
break;
case GDK_plus:
case GDK_minus:
case GDK_equal:
case GDK_KP_Add:
case GDK_KP_Subtract:
case GDK_0:
case GDK_KP_0:
if (event->state & GDK_CONTROL_MASK) {
handled = keyboard_stretching (container, event);
}
break;
case GDK_F10:
/* handle Ctrl+F10 because we want to display the
......
......@@ -1546,10 +1546,7 @@ zoom_level_changed_callback (NautilusView *view,
action = gtk_action_group_get_action (window->details->main_action_group,
NAUTILUS_ACTION_ZOOM_NORMAL);
gtk_action_set_visible (action, supports_zooming);
gtk_action_set_sensitive (action,
TRUE);
/* FIXME bugzilla.gnome.org 43442: Desensitize "Zoom Normal"? */
gtk_action_set_sensitive (action, supports_zooming);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment