added attach point attribute to the icon canvas item, and used it to

added attach point attribute to the icon canvas item, and used
	it to derive the emblem positions if present.  Tweaked the
	emblem positions in the xml file.  Cleaned up the attach point
	stuff in the icon factory.
This commit is contained in:
Andy Hertzfeld 2000-08-02 08:11:46 +00:00
parent 7194d8e885
commit cbf4c2dcc1
15 changed files with 180 additions and 30 deletions

View file

@ -1,3 +1,31 @@
2000-08-02 Andy Hertzfeld <andy@eazel.com>
this almost completes the emblem attach point stuff, at least for the eazel theme,
but there's still some tweaking left to do
* libnautilus-extensions/nautilus-icon-canvas-item.c,h:
(nautilus_icon_canvas_item_destroy),
(nautilus_icon_canvas_item_set_attach_points),
(emblem_layout_reset), (emblem_layout_next):
added an attach_points attribute, and used it to determine the
emblem positions if set
* libnautilus-extensions/nautilus-icon-container.c:
(nautilus_icon_container_update_icon):
get the emblem attach points from the icon factory, and tell the
canvas item about them.
* libnautilus-extensions/nautilus-icon-factory.c,h:
(parse_attach_points), (get_themed_icon_file_path),
(load_specific_image), (get_image_from_cache),
(nautilus_icon_factory_get_pixbuf_for_icon):
cleaned up and debugged the attach point handling
* icons/eazel/Makefile.am:
* icons/eazel/i-directory-accept.xml:
* icons/eazel/i-directory.xml:
set the emblem positions of folders in the eazel theme
2000-08-02 Ramiro Estrugo <ramiro@eazel.com>
* components/mozilla/mozilla-preferences.cpp:

View file

@ -36,6 +36,7 @@ eazel_DATA = \
i-directory-accept-aa.png \
i-directory.png \
i-directory-aa.png \
i-directory-accept.xml \
i-directory.xml \
i-regular-12.png \
i-regular-12-aa.png \

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ICON_SET>
<ICON SIZE="24" ATTACH_POINTS="12,11|25,0|25,12|25,24"/>
<ICON SIZE="36" ATTACH_POINTS="18,17|38,0|38,20|38,40"/>
<ICON SIZE="48" ATTACH_POINTS="28,25|50,0|50,24|50,48"/>
<ICON SIZE="72" ATTACH_POINTS="33,31|76,0|76,32|76,64"/>
<ICON SIZE="96" ATTACH_POINTS="48,45|100,0|100,48|100,96"/>
</ICON_SET>

View file

@ -1,7 +1,8 @@
<?xml version="1.0"?>
<ICON_SET>
<ICON SIZE="36" ATTACH_POINTS="16,16|38,0|38,20|38,40"/>
<ICON SIZE="48" ATTACH_POINTS="24,24|50,0|50,20|50,40"/>
<ICON SIZE="72" ATTACH_POINTS="32,32|76,0|76,20|76,40"/>
<ICON SIZE="96" ATTACH_POINTS="48,48|100,0|100,20|100,40"/>
<ICON SIZE="24" ATTACH_POINTS="12,11|25,0|25,12|25,24"/>
<ICON SIZE="36" ATTACH_POINTS="18,17|38,0|38,20|38,40"/>
<ICON SIZE="48" ATTACH_POINTS="24,21|50,0|50,24|50,48"/>
<ICON SIZE="72" ATTACH_POINTS="33,31|76,0|76,32|76,64"/>
<ICON SIZE="96" ATTACH_POINTS="48,45|100,0|100,48|100,96"/>
</ICON_SET>

View file

@ -46,6 +46,7 @@
#include "nautilus-gnome-extensions.h"
#include "nautilus-graphic-effects.h"
#include "nautilus-file-utilities.h"
#include "nautilus-icon-factory.h"
#define STRETCH_HANDLE_THICKNESS 5
#define EMBLEM_SPACING 2
@ -59,6 +60,7 @@ struct NautilusIconCanvasItemDetails {
char *editable_text; /* Text that can be modified by a renaming function */
char *additional_text; /* Text that cannot be modifed, such as file size, etc. */
GdkFont *font;
EmblemAttachPoints *attach_pointer;
/* Size of the text at current font. */
int text_width;
@ -101,6 +103,7 @@ typedef struct {
ArtIRect icon_rect;
RectangleSide side;
int position;
int index;
GList *emblem;
} EmblemLayout;
@ -269,6 +272,8 @@ nautilus_icon_canvas_item_destroy (GtkObject *object)
nautilus_gdk_pixbuf_list_free (details->emblem_pixbufs);
g_free (details->editable_text);
g_free (details->additional_text);
g_free (details->attach_pointer);
if (details->font != NULL) {
gdk_font_unref (details->font);
}
@ -473,6 +478,19 @@ nautilus_icon_canvas_item_set_emblems (NautilusIconCanvasItem *item,
gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (item));
}
void
nautilus_icon_canvas_item_set_attach_points (NautilusIconCanvasItem *item,
EmblemAttachPoints *attach_points)
{
g_free (item->details->attach_pointer);
item->details->attach_pointer = NULL;
if (attach_points && attach_points->has_attach_points) {
item->details->attach_pointer = g_new0 (EmblemAttachPoints, 1);
*item->details->attach_pointer = *attach_points;
}
}
/* Recomputes the bounding box of a icon canvas item.
* This is a generic implementation that could be used for any canvas item
* class, it has no assumptions about how the item is used.
@ -854,6 +872,7 @@ emblem_layout_reset (EmblemLayout *layout, NautilusIconCanvasItem *icon_item, co
layout->icon_rect = *icon_rect;
layout->side = RIGHT_SIDE;
layout->position = 0;
layout->index = 0;
layout->emblem = icon_item->details->emblem_pixbufs;
}
@ -864,7 +883,8 @@ emblem_layout_next (EmblemLayout *layout,
{
GdkPixbuf *pixbuf;
int width, height, x, y;
EmblemAttachPoints *attach_info ;
/* Check if we have layed out all of the pixbufs. */
if (layout->emblem == NULL) {
return FALSE;
@ -875,10 +895,31 @@ emblem_layout_next (EmblemLayout *layout,
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
/* handle the case of just one emblem by centering it in the icon */
/* Advance to the next emblem. */
layout->emblem = layout->emblem->next;
if (layout->icon_item->details->attach_pointer) {
if (layout->index >= MAX_ATTACH_POINTS)
return FALSE;
attach_info = layout->icon_item->details->attach_pointer;
x = layout->icon_rect.x0 + attach_info->attach_points[layout->index].x;
y = layout->icon_rect.y0 + attach_info->attach_points[layout->index].y;
layout->index += 1;
/* Return the rectangle and pixbuf. */
*emblem_pixbuf = pixbuf;
emblem_rect->x0 = x - width / 2;
emblem_rect->y0 = y - height / 2;
emblem_rect->x1 = emblem_rect->x0 + width;
emblem_rect->y1 = emblem_rect->y0 + height;
return TRUE;
}
for (;;) {
/* Find the side to lay out along. */

View file

@ -28,6 +28,7 @@
#include <libgnome/gnome-defs.h>
#include <libgnomeui/gnome-canvas.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "nautilus-icon-factory.h"
BEGIN_GNOME_DECLS
@ -70,6 +71,8 @@ void nautilus_icon_canvas_item_set_emblems (NautilusIconCanv
GList *emblem_pixbufs);
void nautilus_icon_canvas_item_set_show_stretch_handles (NautilusIconCanvasItem *item,
gboolean show_stretch_handles);
void nautilus_icon_canvas_item_set_attach_points (NautilusIconCanvasItem *item,
EmblemAttachPoints *attach_points);
double nautilus_icon_canvas_item_get_max_text_width (NautilusIconCanvasItem *item);
const char *nautilus_icon_canvas_item_get_editable_text (NautilusIconCanvasItem *icon_item);
void nautilus_icon_canvas_item_set_renaming (NautilusIconCanvasItem *icon_item,

View file

@ -2784,7 +2784,7 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
max_image_size * icon->scale_x,
max_image_size * icon->scale_y,
&attach_points);
nautilus_scalable_icon_unref (scalable_icon);
emblem_pixbufs = NULL;
@ -2810,7 +2810,7 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
icon->data,
&editable_text,
&additional_text);
font = details->label_font[details->zoom_level];
gnome_canvas_item_set (GNOME_CANVAS_ITEM (icon->item),
@ -2821,6 +2821,7 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
NULL);
nautilus_icon_canvas_item_set_image (icon->item, pixbuf);
nautilus_icon_canvas_item_set_attach_points (icon->item, &attach_points);
nautilus_icon_canvas_item_set_emblems (icon->item, emblem_pixbufs);
/* Let the pixbufs go. */

View file

@ -191,7 +191,7 @@ typedef struct {
typedef struct {
ArtIRect text_rect;
gboolean has_attach_points;
GdkPoint attach_points[8];
GdkPoint attach_points[MAX_ATTACH_POINTS];
} IconInfo;
/* The key to a hash table that holds the scaled icons as pixbufs.
@ -584,7 +584,7 @@ parse_attach_points (IconInfo *icon_info, const char* attach_point_string)
/* split the attach point string into a string array, then process
each point with sscanf in a loop */
point_array = g_strsplit (attach_point_string, "|", 8);
point_array = g_strsplit (attach_point_string, "|", MAX_ATTACH_POINTS);
for (index = 0; (text_piece = point_array[index]) != NULL; index++) {
if (sscanf (text_piece, " %d , %d , %*s", &x_offset, &y_offset) == 2) {
@ -624,6 +624,10 @@ get_themed_icon_file_path (const char *theme_name,
themed_icon_name = g_strconcat (theme_name, "/", icon_name, NULL);
}
if (icon_info != NULL) {
icon_info->has_attach_points = FALSE;
}
include_size = icon_size != NAUTILUS_ICON_SIZE_STANDARD;
factory = (NautilusIconFactory*) nautilus_icon_factory_get();
@ -680,8 +684,6 @@ get_themed_icon_file_path (const char *theme_name,
node = nautilus_xml_get_root_child_by_name_and_property
(doc, "ICON", "SIZE", size_as_string);
g_free (size_as_string);
icon_info->has_attach_points = FALSE;
property = xmlGetProp (node, "EMBEDDED_TEXT_RECTANGLE");
if (property != NULL) {
@ -702,7 +704,10 @@ get_themed_icon_file_path (const char *theme_name,
icon_info->has_attach_points = TRUE;
parse_attach_points (icon_info, property);
xmlFree (property);
}
} else {
icon_info->has_attach_points = FALSE;
}
xmlFreeDoc (doc);
}
@ -1559,7 +1564,8 @@ load_specific_image (NautilusScalableIcon *scalable_icon,
/* Custom icon. */
memset (&icon_info->text_rect, 0, sizeof (icon_info->text_rect));
icon_info->has_attach_points = FALSE;
/* FIXME bugzilla.eazel.com 643: we can't load svgs asynchronously, so this
* only works for local files
*/
@ -1927,6 +1933,8 @@ get_image_from_cache (NautilusScalableIcon *scalable_icon,
gboolean got_custom_image;
IconInfo key_icon_info;
key_icon_info.has_attach_points = FALSE;
/* Not in the table, so load the image. */
/* If we're picky, then we want the image only if this exact
* nominal size is available.
@ -1994,7 +2002,7 @@ get_image_from_cache (NautilusScalableIcon *scalable_icon,
g_hash_table_insert (hash_table, key, image);
}
/* Return the text rect if the caller asked for it. */
/* Return the icon info if the caller asked for it. */
if (icon_info != NULL) {
*icon_info = key->icon_info;
}
@ -2032,7 +2040,7 @@ nautilus_icon_factory_get_pixbuf_for_icon (NautilusScalableIcon *scalable_icon,
&icon_info);
if (attach_data != NULL) {
attach_data->has_attach_points = icon_info.has_attach_points;
for (index = 0; index < 8; index++) {
for (index = 0; index < MAX_ATTACH_POINTS; index++) {
attach_data->attach_points[index] = icon_info.attach_points[index];
}
}

View file

@ -77,9 +77,12 @@ typedef enum {
typedef struct NautilusScalableIcon NautilusScalableIcon;
/* here's a structure to hold the emblem attach points */
#define MAX_ATTACH_POINTS 8
typedef struct {
gboolean has_attach_points;
GdkPoint attach_points[8];
GdkPoint attach_points[MAX_ATTACH_POINTS];
} EmblemAttachPoints;
/* Instead of a class declaration here, I will just document

View file

@ -46,6 +46,7 @@
#include "nautilus-gnome-extensions.h"
#include "nautilus-graphic-effects.h"
#include "nautilus-file-utilities.h"
#include "nautilus-icon-factory.h"
#define STRETCH_HANDLE_THICKNESS 5
#define EMBLEM_SPACING 2
@ -59,6 +60,7 @@ struct NautilusIconCanvasItemDetails {
char *editable_text; /* Text that can be modified by a renaming function */
char *additional_text; /* Text that cannot be modifed, such as file size, etc. */
GdkFont *font;
EmblemAttachPoints *attach_pointer;
/* Size of the text at current font. */
int text_width;
@ -101,6 +103,7 @@ typedef struct {
ArtIRect icon_rect;
RectangleSide side;
int position;
int index;
GList *emblem;
} EmblemLayout;
@ -269,6 +272,8 @@ nautilus_icon_canvas_item_destroy (GtkObject *object)
nautilus_gdk_pixbuf_list_free (details->emblem_pixbufs);
g_free (details->editable_text);
g_free (details->additional_text);
g_free (details->attach_pointer);
if (details->font != NULL) {
gdk_font_unref (details->font);
}
@ -473,6 +478,19 @@ nautilus_icon_canvas_item_set_emblems (NautilusIconCanvasItem *item,
gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (item));
}
void
nautilus_icon_canvas_item_set_attach_points (NautilusIconCanvasItem *item,
EmblemAttachPoints *attach_points)
{
g_free (item->details->attach_pointer);
item->details->attach_pointer = NULL;
if (attach_points && attach_points->has_attach_points) {
item->details->attach_pointer = g_new0 (EmblemAttachPoints, 1);
*item->details->attach_pointer = *attach_points;
}
}
/* Recomputes the bounding box of a icon canvas item.
* This is a generic implementation that could be used for any canvas item
* class, it has no assumptions about how the item is used.
@ -854,6 +872,7 @@ emblem_layout_reset (EmblemLayout *layout, NautilusIconCanvasItem *icon_item, co
layout->icon_rect = *icon_rect;
layout->side = RIGHT_SIDE;
layout->position = 0;
layout->index = 0;
layout->emblem = icon_item->details->emblem_pixbufs;
}
@ -864,7 +883,8 @@ emblem_layout_next (EmblemLayout *layout,
{
GdkPixbuf *pixbuf;
int width, height, x, y;
EmblemAttachPoints *attach_info ;
/* Check if we have layed out all of the pixbufs. */
if (layout->emblem == NULL) {
return FALSE;
@ -875,10 +895,31 @@ emblem_layout_next (EmblemLayout *layout,
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
/* handle the case of just one emblem by centering it in the icon */
/* Advance to the next emblem. */
layout->emblem = layout->emblem->next;
if (layout->icon_item->details->attach_pointer) {
if (layout->index >= MAX_ATTACH_POINTS)
return FALSE;
attach_info = layout->icon_item->details->attach_pointer;
x = layout->icon_rect.x0 + attach_info->attach_points[layout->index].x;
y = layout->icon_rect.y0 + attach_info->attach_points[layout->index].y;
layout->index += 1;
/* Return the rectangle and pixbuf. */
*emblem_pixbuf = pixbuf;
emblem_rect->x0 = x - width / 2;
emblem_rect->y0 = y - height / 2;
emblem_rect->x1 = emblem_rect->x0 + width;
emblem_rect->y1 = emblem_rect->y0 + height;
return TRUE;
}
for (;;) {
/* Find the side to lay out along. */

View file

@ -28,6 +28,7 @@
#include <libgnome/gnome-defs.h>
#include <libgnomeui/gnome-canvas.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "nautilus-icon-factory.h"
BEGIN_GNOME_DECLS
@ -70,6 +71,8 @@ void nautilus_icon_canvas_item_set_emblems (NautilusIconCanv
GList *emblem_pixbufs);
void nautilus_icon_canvas_item_set_show_stretch_handles (NautilusIconCanvasItem *item,
gboolean show_stretch_handles);
void nautilus_icon_canvas_item_set_attach_points (NautilusIconCanvasItem *item,
EmblemAttachPoints *attach_points);
double nautilus_icon_canvas_item_get_max_text_width (NautilusIconCanvasItem *item);
const char *nautilus_icon_canvas_item_get_editable_text (NautilusIconCanvasItem *icon_item);
void nautilus_icon_canvas_item_set_renaming (NautilusIconCanvasItem *icon_item,

View file

@ -2784,7 +2784,7 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
max_image_size * icon->scale_x,
max_image_size * icon->scale_y,
&attach_points);
nautilus_scalable_icon_unref (scalable_icon);
emblem_pixbufs = NULL;
@ -2810,7 +2810,7 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
icon->data,
&editable_text,
&additional_text);
font = details->label_font[details->zoom_level];
gnome_canvas_item_set (GNOME_CANVAS_ITEM (icon->item),
@ -2821,6 +2821,7 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
NULL);
nautilus_icon_canvas_item_set_image (icon->item, pixbuf);
nautilus_icon_canvas_item_set_attach_points (icon->item, &attach_points);
nautilus_icon_canvas_item_set_emblems (icon->item, emblem_pixbufs);
/* Let the pixbufs go. */

View file

@ -191,7 +191,7 @@ typedef struct {
typedef struct {
ArtIRect text_rect;
gboolean has_attach_points;
GdkPoint attach_points[8];
GdkPoint attach_points[MAX_ATTACH_POINTS];
} IconInfo;
/* The key to a hash table that holds the scaled icons as pixbufs.
@ -584,7 +584,7 @@ parse_attach_points (IconInfo *icon_info, const char* attach_point_string)
/* split the attach point string into a string array, then process
each point with sscanf in a loop */
point_array = g_strsplit (attach_point_string, "|", 8);
point_array = g_strsplit (attach_point_string, "|", MAX_ATTACH_POINTS);
for (index = 0; (text_piece = point_array[index]) != NULL; index++) {
if (sscanf (text_piece, " %d , %d , %*s", &x_offset, &y_offset) == 2) {
@ -624,6 +624,10 @@ get_themed_icon_file_path (const char *theme_name,
themed_icon_name = g_strconcat (theme_name, "/", icon_name, NULL);
}
if (icon_info != NULL) {
icon_info->has_attach_points = FALSE;
}
include_size = icon_size != NAUTILUS_ICON_SIZE_STANDARD;
factory = (NautilusIconFactory*) nautilus_icon_factory_get();
@ -680,8 +684,6 @@ get_themed_icon_file_path (const char *theme_name,
node = nautilus_xml_get_root_child_by_name_and_property
(doc, "ICON", "SIZE", size_as_string);
g_free (size_as_string);
icon_info->has_attach_points = FALSE;
property = xmlGetProp (node, "EMBEDDED_TEXT_RECTANGLE");
if (property != NULL) {
@ -702,7 +704,10 @@ get_themed_icon_file_path (const char *theme_name,
icon_info->has_attach_points = TRUE;
parse_attach_points (icon_info, property);
xmlFree (property);
}
} else {
icon_info->has_attach_points = FALSE;
}
xmlFreeDoc (doc);
}
@ -1559,7 +1564,8 @@ load_specific_image (NautilusScalableIcon *scalable_icon,
/* Custom icon. */
memset (&icon_info->text_rect, 0, sizeof (icon_info->text_rect));
icon_info->has_attach_points = FALSE;
/* FIXME bugzilla.eazel.com 643: we can't load svgs asynchronously, so this
* only works for local files
*/
@ -1927,6 +1933,8 @@ get_image_from_cache (NautilusScalableIcon *scalable_icon,
gboolean got_custom_image;
IconInfo key_icon_info;
key_icon_info.has_attach_points = FALSE;
/* Not in the table, so load the image. */
/* If we're picky, then we want the image only if this exact
* nominal size is available.
@ -1994,7 +2002,7 @@ get_image_from_cache (NautilusScalableIcon *scalable_icon,
g_hash_table_insert (hash_table, key, image);
}
/* Return the text rect if the caller asked for it. */
/* Return the icon info if the caller asked for it. */
if (icon_info != NULL) {
*icon_info = key->icon_info;
}
@ -2032,7 +2040,7 @@ nautilus_icon_factory_get_pixbuf_for_icon (NautilusScalableIcon *scalable_icon,
&icon_info);
if (attach_data != NULL) {
attach_data->has_attach_points = icon_info.has_attach_points;
for (index = 0; index < 8; index++) {
for (index = 0; index < MAX_ATTACH_POINTS; index++) {
attach_data->attach_points[index] = icon_info.attach_points[index];
}
}

View file

@ -77,9 +77,12 @@ typedef enum {
typedef struct NautilusScalableIcon NautilusScalableIcon;
/* here's a structure to hold the emblem attach points */
#define MAX_ATTACH_POINTS 8
typedef struct {
gboolean has_attach_points;
GdkPoint attach_points[8];
GdkPoint attach_points[MAX_ATTACH_POINTS];
} EmblemAttachPoints;
/* Instead of a class declaration here, I will just document