diff options
author | Ramiro Estrugo <ramiro@src.gnome.org> | 2001-02-15 15:45:43 +0000 |
---|---|---|
committer | Ramiro Estrugo <ramiro@src.gnome.org> | 2001-02-15 15:45:43 +0000 |
commit | 88ebb708e8d205717caaf11b4bcfbe912439de17 (patch) | |
tree | ad377ae16dc25c74103e147bac054caba287cb9d | |
parent | 7c5e694d36ab3436bf0b6a130bb66b37094077af (diff) | |
download | nautilus-88ebb708e8d205717caaf11b4bcfbe912439de17.tar.gz |
reviewed by: Darin Adler <darin@eazel.com>
Except for the self checks code.
Change code that used a ArtIRect as a "frame" to use
NautilusDimensions instead. Change all foo_frame functions to
foo_dimensions.
* libnautilus-extensions/nautilus-art-extensions.h:
Add a new structure to represent dimensions using signed integers.
Retire nautilus_art_ipoint_assign.
* libnautilus-extensions/nautilus-art-extensions.c:
(nautilus_dimensions_empty): New function to check for empty
dimensions.
(nautilus_art_irect_assign_dimensions): New function to assign
dimensions to a rectangle.
(nautilus_self_check_art_extensions): New self checks.
* libnautilus-extensions/nautilus-art-gtk-extensions.h:
* libnautilus-extensions/nautilus-art-gtk-extensions.c:
(nautilus_gdk_rectangle_to_art_irect),
(nautilus_screen_get_dimensions), (nautilus_gdk_window_get_bounds),
(nautilus_gdk_window_get_screen_relative_bounds),
(nautilus_gtk_widget_get_bounds),
(nautilus_gtk_widget_get_dimensions),
(nautilus_gdk_window_clip_dirty_area_to_screen),
(nautilus_art_irect_to_gdk_rectangle),
(nautilus_gdk_window_get_dimensions): New function to get
the dimensions of a GdkWindow.
Update for frame to dimensions changes. Change functions names to
lose the "irect" sub-prefix.
* libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h:
* libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c:
(nautilus_gdk_pixbuf_get_dimensions),
(nautilus_gdk_pixbuf_fill_rectangle_with_color),
(nautilus_gdk_pixbuf_draw_to_drawable),
(nautilus_gdk_pixbuf_draw_to_pixbuf),
(nautilus_gdk_pixbuf_draw_to_pixbuf_alpha),
(nautilus_gdk_pixbuf_new_from_pixbuf_sub_area),
(pixbuf_draw_tiled), (nautilus_gdk_pixbuf_draw_to_pixbuf_tiled),
(nautilus_gdk_pixbuf_draw_to_drawable_tiled),
(nautilus_gdk_pixbuf_intersect): New functions
(nautilus_self_check_gdk_pixbuf_extensions): New self checks.
Update for frame vs dimenensions changes. Simplify clipping code
by using nautilus_gdk_pixbuf_intersect. Move
nautilus_gdk_window_get_dimensions to
nautilus_gdk_window_get_dimensions in art-gtk-extensions.
* libnautilus-extensions/nautilus-debug-drawing.c:
(debug_pixbuf_viewer_size_request),
(nautilus_debug_pixbuf_draw_point),
(nautilus_debug_pixbuf_draw_rectangle),
(nautilus_debug_pixbuf_draw_rectangle_inset):
Update for frame vs dimenensions changes.
* libnautilus-extensions/nautilus-clickable-image.c:
(label_handle_motion):
Update for art-gtk extensions changes.
* libnautilus-extensions/nautilus-glyph.h:
* libnautilus-extensions/nautilus-glyph.c: (nautilus_glyph_new):
Change order of parameters to match NautilusScalalbleFont.
(nautilus_glyph_get_dimensions), (nautilus_glyph_draw_to_pixbuf):
Update for frame vs dimenensions changes.
* libnautilus-extensions/nautilus-lib-self-check-functions.h:
New declaration for art_extensions and gdk_pixbuf_extensions.
* libnautilus-extensions/nautilus-self-checks.c:
(nautilus_check_rectangle_result),
(nautilus_check_dimensions_result):
* libnautilus-extensions/nautilus-self-checks.h:
Add support for checking functions that return rectangles and
dimensions.
* libnautilus-extensions/nautilus-scalable-font.h:
* libnautilus-extensions/nautilus-scalable-font.c:
(nautilus_scalable_font_measure_text): Return
NautilusDimensions instead of using pointer parameters.
(nautilus_scalable_font_text_width): Simplify by calling
scalable_font_measure_text.
(nautilus_scalable_font_draw_text),
(nautilus_scalable_font_measure_text_lines),
(nautilus_scalable_font_draw_text_lines_with_dimensions),
(nautilus_scalable_font_draw_text_lines):
Update for frame vs dimenensions changes. Use NautilusDimensions
arrays instead of individial width and height arrays. Change all
function signatures to pass in only a font_size instead of both
font_width and font_height. Simplifies using these a bit.
(nautilus_scalable_font_largest_fitting_font_size): Fix bug where
we were always using the wrong font size to compute the largest
fitting font.
* libnautilus-extensions/nautilus-icon-factory.c: (embed_text):
Update for scalable font font_size api changes.
* libnautilus-extensions/nautilus-image-table.c:
(image_table_clear_dirty_areas):
Update for frame vs dimenensions changes.
* libnautilus-extensions/nautilus-image.c:
(nautilus_image_size_request), (image_get_pixbuf_dimensions),
(image_get_pixbuf_bounds), (image_get_tile_dimensions):
Update for frame vs dimenensions changes.
* libnautilus-extensions/nautilus-label.h:
* libnautilus-extensions/nautilus-label.c:
(nautilus_label_initialize_class), (nautilus_label_set_arg),
(nautilus_label_get_arg), (nautilus_label_size_request),
(nautilus_label_size_allocate), (label_composite_pixbuf_callback),
(label_draw_text_to_pixbuf): Fix a type. Was using [x,x] instead
of [x,y] to render the string.
(label_get_text_dimensions), (label_get_text_bounds),
(label_get_tile_dimensions), (label_line_geometries_clear),
(label_line_geometries_recompute),
Update for frame vs dimenensions changes. Make the
'smooth_line_wrap' attribute an int instead of a guint. Use an
array of NautilusDimensions to store text lines geometries instead
of separete width and height arrays.
(label_get_default_line_wrap_width),
(nautilus_label_set_smooth_line_wrap_width),
(nautilus_label_get_smooth_line_wrap_width):
Change signature to return an int instead of a guint.
* libnautilus-extensions/nautilus-labeled-image.c:
(nautilus_labeled_image_size_request),
(labeled_image_get_image_dimensions),
(labeled_image_get_label_dimensions),
(labeled_image_get_image_bounds_fill),
(nautilus_labeled_image_get_image_bounds),
(labeled_image_get_label_bounds_fill),
(nautilus_labeled_image_get_label_bounds),
(labeled_image_get_content_dimensions),
(labeled_image_get_content_bounds):
Update for frame vs dimenensions changes.
* libnautilus-extensions/nautilus-smooth-widget.h:
* libnautilus-extensions/nautilus-smooth-widget.c:
(smooth_widget_paint_tile_transparent),
(nautilus_smooth_widget_get_preferred_dimensions):
Update for frame vs dimenensions changes.
* libnautilus-extensions/nautilus-tabs.c: (measure_tab_name),
(draw_tab_label):
Update for font api changes.
* libnautilus-extensions/nautilus-text-layout.c:
(nautilus_text_layout_new), (nautilus_text_layout_paint):
Update for frame vs dimenensions changes.
* libnautilus-extensions/nautilus-wrap-table.c:
(nautilus_wrap_table_size_request), (wrap_table_layout),
(wrap_table_art_irect_max_dimensions),
(wrap_table_get_max_child_dimensions),
(wrap_table_get_content_dimensions):
Update for frame vs dimenensions changes.
* src/nautilus-about.c: (draw_aa_string):
Update for frame vs dimenensions changes.
* src/nautilus-sidebar-tabs.c: (draw_one_tab_plain),
(draw_one_tab_themed), (get_tab_width):
Update for frame vs dimenensions changes.
* test/test-nautilus-font-simple.c: (main):
* test/test-nautilus-font.c: (main):
* test/test-nautilus-glyph-simple.c: (glyph_new):
* test/test-nautilus-glyph.c: (glyph_new), (main):
* test/test-nautilus-pixbuf-tile.c:
* test/test.c: (test_pixbuf_draw_rectangle_tiled):
Update test for frame vs dimenensions changes and font api
changes.
63 files changed, 2504 insertions, 1965 deletions
@@ -1,3 +1,178 @@ +2001-02-15 Ramiro Estrugo <ramiro@eazel.com> + + reviewed by: Darin Adler <darin@eazel.com> + Except for the self checks code. + + Change code that used a ArtIRect as a "frame" to use + NautilusDimensions instead. Change all foo_frame functions to + foo_dimensions. + + * libnautilus-extensions/nautilus-art-extensions.h: + Add a new structure to represent dimensions using signed integers. + Retire nautilus_art_ipoint_assign. + * libnautilus-extensions/nautilus-art-extensions.c: + (nautilus_dimensions_empty): New function to check for empty + dimensions. + (nautilus_art_irect_assign_dimensions): New function to assign + dimensions to a rectangle. + (nautilus_self_check_art_extensions): New self checks. + + * libnautilus-extensions/nautilus-art-gtk-extensions.h: + * libnautilus-extensions/nautilus-art-gtk-extensions.c: + (nautilus_gdk_rectangle_to_art_irect), + (nautilus_screen_get_dimensions), (nautilus_gdk_window_get_bounds), + (nautilus_gdk_window_get_screen_relative_bounds), + (nautilus_gtk_widget_get_bounds), + (nautilus_gtk_widget_get_dimensions), + (nautilus_gdk_window_clip_dirty_area_to_screen), + (nautilus_art_irect_to_gdk_rectangle), + (nautilus_gdk_window_get_dimensions): New function to get + the dimensions of a GdkWindow. + Update for frame to dimensions changes. Change functions names to + lose the "irect" sub-prefix. + + * libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h: + * libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c: + (nautilus_gdk_pixbuf_get_dimensions), + (nautilus_gdk_pixbuf_fill_rectangle_with_color), + (nautilus_gdk_pixbuf_draw_to_drawable), + (nautilus_gdk_pixbuf_draw_to_pixbuf), + (nautilus_gdk_pixbuf_draw_to_pixbuf_alpha), + (nautilus_gdk_pixbuf_new_from_pixbuf_sub_area), + (pixbuf_draw_tiled), (nautilus_gdk_pixbuf_draw_to_pixbuf_tiled), + (nautilus_gdk_pixbuf_draw_to_drawable_tiled), + (nautilus_gdk_pixbuf_intersect): New functions + (nautilus_self_check_gdk_pixbuf_extensions): New self checks. + Update for frame vs dimenensions changes. Simplify clipping code + by using nautilus_gdk_pixbuf_intersect. Move + nautilus_gdk_window_get_dimensions to + nautilus_gdk_window_get_dimensions in art-gtk-extensions. + + * libnautilus-extensions/nautilus-debug-drawing.c: + (debug_pixbuf_viewer_size_request), + (nautilus_debug_pixbuf_draw_point), + (nautilus_debug_pixbuf_draw_rectangle), + (nautilus_debug_pixbuf_draw_rectangle_inset): + Update for frame vs dimenensions changes. + + * libnautilus-extensions/nautilus-clickable-image.c: + (label_handle_motion): + Update for art-gtk extensions changes. + + * libnautilus-extensions/nautilus-glyph.h: + * libnautilus-extensions/nautilus-glyph.c: (nautilus_glyph_new): + Change order of parameters to match NautilusScalalbleFont. + (nautilus_glyph_get_dimensions), (nautilus_glyph_draw_to_pixbuf): + Update for frame vs dimenensions changes. + + * libnautilus-extensions/nautilus-lib-self-check-functions.h: + New declaration for art_extensions and gdk_pixbuf_extensions. + + * libnautilus-extensions/nautilus-self-checks.c: + (nautilus_check_rectangle_result), + (nautilus_check_dimensions_result): + * libnautilus-extensions/nautilus-self-checks.h: + Add support for checking functions that return rectangles and + dimensions. + + * libnautilus-extensions/nautilus-scalable-font.h: + * libnautilus-extensions/nautilus-scalable-font.c: + (nautilus_scalable_font_measure_text): Return + NautilusDimensions instead of using pointer parameters. + (nautilus_scalable_font_text_width): Simplify by calling + scalable_font_measure_text. + (nautilus_scalable_font_draw_text), + (nautilus_scalable_font_measure_text_lines), + (nautilus_scalable_font_draw_text_lines_with_dimensions), + (nautilus_scalable_font_draw_text_lines): + Update for frame vs dimenensions changes. Use NautilusDimensions + arrays instead of individial width and height arrays. Change all + function signatures to pass in only a font_size instead of both + font_width and font_height. Simplifies using these a bit. + (nautilus_scalable_font_largest_fitting_font_size): Fix bug where + we were always using the wrong font size to compute the largest + fitting font. + + * libnautilus-extensions/nautilus-icon-factory.c: (embed_text): + Update for scalable font font_size api changes. + + * libnautilus-extensions/nautilus-image-table.c: + (image_table_clear_dirty_areas): + Update for frame vs dimenensions changes. + + * libnautilus-extensions/nautilus-image.c: + (nautilus_image_size_request), (image_get_pixbuf_dimensions), + (image_get_pixbuf_bounds), (image_get_tile_dimensions): + Update for frame vs dimenensions changes. + + * libnautilus-extensions/nautilus-label.h: + * libnautilus-extensions/nautilus-label.c: + (nautilus_label_initialize_class), (nautilus_label_set_arg), + (nautilus_label_get_arg), (nautilus_label_size_request), + (nautilus_label_size_allocate), (label_composite_pixbuf_callback), + (label_draw_text_to_pixbuf): Fix a type. Was using [x,x] instead + of [x,y] to render the string. + (label_get_text_dimensions), (label_get_text_bounds), + (label_get_tile_dimensions), (label_line_geometries_clear), + (label_line_geometries_recompute), + Update for frame vs dimenensions changes. Make the + 'smooth_line_wrap' attribute an int instead of a guint. Use an + array of NautilusDimensions to store text lines geometries instead + of separete width and height arrays. + (label_get_default_line_wrap_width), + (nautilus_label_set_smooth_line_wrap_width), + (nautilus_label_get_smooth_line_wrap_width): + Change signature to return an int instead of a guint. + + * libnautilus-extensions/nautilus-labeled-image.c: + (nautilus_labeled_image_size_request), + (labeled_image_get_image_dimensions), + (labeled_image_get_label_dimensions), + (labeled_image_get_image_bounds_fill), + (nautilus_labeled_image_get_image_bounds), + (labeled_image_get_label_bounds_fill), + (nautilus_labeled_image_get_label_bounds), + (labeled_image_get_content_dimensions), + (labeled_image_get_content_bounds): + Update for frame vs dimenensions changes. + + * libnautilus-extensions/nautilus-smooth-widget.h: + * libnautilus-extensions/nautilus-smooth-widget.c: + (smooth_widget_paint_tile_transparent), + (nautilus_smooth_widget_get_preferred_dimensions): + Update for frame vs dimenensions changes. + + * libnautilus-extensions/nautilus-tabs.c: (measure_tab_name), + (draw_tab_label): + Update for font api changes. + + * libnautilus-extensions/nautilus-text-layout.c: + (nautilus_text_layout_new), (nautilus_text_layout_paint): + Update for frame vs dimenensions changes. + + * libnautilus-extensions/nautilus-wrap-table.c: + (nautilus_wrap_table_size_request), (wrap_table_layout), + (wrap_table_art_irect_max_dimensions), + (wrap_table_get_max_child_dimensions), + (wrap_table_get_content_dimensions): + Update for frame vs dimenensions changes. + + * src/nautilus-about.c: (draw_aa_string): + Update for frame vs dimenensions changes. + + * src/nautilus-sidebar-tabs.c: (draw_one_tab_plain), + (draw_one_tab_themed), (get_tab_width): + Update for frame vs dimenensions changes. + + * test/test-nautilus-font-simple.c: (main): + * test/test-nautilus-font.c: (main): + * test/test-nautilus-glyph-simple.c: (glyph_new): + * test/test-nautilus-glyph.c: (glyph_new), (main): + * test/test-nautilus-pixbuf-tile.c: + * test/test.c: (test_pixbuf_draw_rectangle_tiled): + Update test for frame vs dimenensions changes and font api + changes. + 2001-02-14 Mike Fleming <mfleming@eazel.com> * components/mozilla/mozilla-preferences.cpp: diff --git a/libnautilus-extensions/nautilus-art-extensions.c b/libnautilus-extensions/nautilus-art-extensions.c index 9cec8a717..41c975797 100644 --- a/libnautilus-extensions/nautilus-art-extensions.c +++ b/libnautilus-extensions/nautilus-art-extensions.c @@ -26,10 +26,12 @@ #include <config.h> #include "nautilus-art-extensions.h" +#include "nautilus-lib-self-check-functions.h" #include <math.h> ArtIRect NAUTILUS_ART_IRECT_EMPTY = { 0, 0, 0, 0 }; NautilusArtIPoint NAUTILUS_ART_IPOINT_ZERO = { 0, 0 }; +NautilusDimensions NAUTILUS_DIMENSIONS_EMPTY = { 0, 0 }; gboolean nautilus_art_irect_contains_irect (const ArtIRect *outer_rect, @@ -122,17 +124,6 @@ nautilus_art_irect_assign (ArtIRect *rect, rect->y1 = rect->y0 + height; } -void -nautilus_art_ipoint_assign (NautilusArtIPoint *point, - int x, - int y) -{ - g_return_if_fail (point != NULL); - - point->x = x; - point->y = y; -} - /** * nautilus_art_irect_get_width: * @@ -214,3 +205,143 @@ nautilus_art_irect_align (const ArtIRect *container, return aligned; } + +/** + * nautilus_dimensions_empty: + * + * @dimensions: A NautilusDimensions structure. + * + * Returns: Whether the dimensions are empty. + */ +gboolean +nautilus_dimensions_empty (const NautilusDimensions *dimensions) +{ + g_return_val_if_fail (dimensions != NULL, TRUE); + + return dimensions->width <= 0 || dimensions->height <= 0; +} + +/** + * nautilus_art_irect_assign_dimensions: + * + * @x: X coodinate for resulting rectangle. + * @y: Y coodinate for resulting rectangle. + * @dimensions: A NautilusDimensions structure for the rect's width and height. + * + * Returns: An ArtIRect with the given coordinates and dimensions. + */ +ArtIRect +nautilus_art_irect_assign_dimensions (int x, + int y, + const NautilusDimensions *dimensions) +{ + ArtIRect rectangle; + + g_return_val_if_fail (dimensions != NULL, NAUTILUS_ART_IRECT_EMPTY); + + rectangle.x0 = x; + rectangle.y0 = y; + rectangle.x1 = rectangle.x0 + dimensions->width; + rectangle.y1 = rectangle.y0 + dimensions->height; + + return rectangle; +} + +#if !defined (NAUTILUS_OMIT_SELF_CHECK) + +void +nautilus_self_check_art_extensions (void) +{ + ArtIRect one; + ArtIRect two; + ArtIRect empty_rect = NAUTILUS_ART_IRECT_EMPTY; + ArtIRect inside; + ArtIRect outside; + ArtIRect container; + NautilusDimensions empty_dimensions = NAUTILUS_DIMENSIONS_EMPTY; + NautilusDimensions dim1; + + nautilus_art_irect_assign (&one, 10, 10, 20, 20); + nautilus_art_irect_assign (&two, 10, 10, 20, 20); + nautilus_art_irect_assign (&inside, 11, 11, 18, 18); + nautilus_art_irect_assign (&outside, 31, 31, 10, 10); + nautilus_art_irect_assign (&container, 0, 0, 100, 100); + + /* nautilus_art_irect_equal */ + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_equal (&one, &two), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_equal (&one, &empty_rect), FALSE); + + /* nautilus_art_irect_hits_irect */ + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_hits_irect (&one, &two), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_hits_irect (&one, &inside), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_hits_irect (&one, &outside), FALSE); + + /* nautilus_art_irect_contains_point */ + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 9, 9), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 9, 10), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 10, 9), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 10, 10), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 11, 10), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 10, 11), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 11, 11), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 30, 30), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 29, 30), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 30, 29), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 31, 31), FALSE); + + /* nautilus_art_irect_get_width */ + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_width (&one), 20); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_width (&empty_rect), 0); + + /* nautilus_art_irect_get_height */ + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_height (&one), 20); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_height (&empty_rect), 0); + + /* nautilus_art_irect_align */ + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&empty_rect, 1, 1, 0.0, 0.0), 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 0, 0, 0.0, 0.0), 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 0, 0.0, 0.0), 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 0, 9, 0.0, 0.0), 0, 0, 0, 0); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.0, 0.0), 0, 0, 10, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 1.0, 0.0), 90, 0, 100, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.0, 1.0), 0, 90, 10, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 1.0, 1.0), 90, 90, 100, 100); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.0, 0.0), 0, 0, 9, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 1.0, 0.0), 91, 0, 100, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.0, 1.0), 0, 91, 9, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 1.0, 1.0), 91, 91, 100, 100); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.5, 0.0), 45, 0, 55, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.5, 0.0), 45, 0, 55, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.0, 0.5), 0, 45, 10, 55); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.5, 0.5), 45, 45, 55, 55); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.5, 0.0), 46, 0, 55, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.5, 0.0), 46, 0, 55, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.0, 0.5), 0, 46, 9, 55); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.5, 0.5), 46, 46, 55, 55); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 120, 120, 0.0, 0.0), 0, 0, 120, 120); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 120, 120, 0.5, 0.5), -10, -10, 110, 110); + + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_dimensions_empty (&empty_dimensions), TRUE); + + dim1.width = 10; dim1.height = 10; + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_dimensions_empty (&dim1), FALSE); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (0, 0, &dim1), 0, 0, 10, 10); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (1, 1, &dim1), 1, 1, 11, 11); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-1, 1, &dim1), -1, 1, 9, 11); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (1, -1, &dim1), 1, -1, 11, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-1, -1, &dim1), -1, -1, 9, 9); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (2, 2, &dim1), 2, 2, 12, 12); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-2, 2, &dim1), -2, 2, 8, 12); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (2, -2, &dim1), 2, -2, 12, 8); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-2, -2, &dim1), -2, -2, 8, 8); +} + +#endif /* !NAUTILUS_OMIT_SELF_CHECK */ diff --git a/libnautilus-extensions/nautilus-art-extensions.h b/libnautilus-extensions/nautilus-art-extensions.h index b47f2d7ed..e5838e6fd 100644 --- a/libnautilus-extensions/nautilus-art-extensions.h +++ b/libnautilus-extensions/nautilus-art-extensions.h @@ -37,36 +37,45 @@ typedef struct { int y; } NautilusArtIPoint; +typedef struct { + int width; + int height; +} NautilusDimensions; + extern ArtIRect NAUTILUS_ART_IRECT_EMPTY; extern NautilusArtIPoint NAUTILUS_ART_IPOINT_ZERO; +extern NautilusDimensions NAUTILUS_DIMENSIONS_EMPTY; /* More functions for ArtIRect and ArtDRect. */ -gboolean nautilus_art_irect_equal (const ArtIRect *rect_a, - const ArtIRect *rect_b); -gboolean nautilus_art_drect_equal (const ArtDRect *rect_a, - const ArtDRect *rect_b); -gboolean nautilus_art_irect_hits_irect (const ArtIRect *rect_a, - const ArtIRect *rect_b); -gboolean nautilus_art_irect_contains_irect (const ArtIRect *outer_rect, - const ArtIRect *inner_rect); -gboolean nautilus_art_irect_contains_point (const ArtIRect *outer_rect, - int x, - int y); -void nautilus_art_irect_assign (ArtIRect *rect, - int x, - int y, - int width, - int height); -void nautilus_art_ipoint_assign (NautilusArtIPoint *point, - int x, - int y); -int nautilus_art_irect_get_width (const ArtIRect *rect); -int nautilus_art_irect_get_height (const ArtIRect *rect); -ArtIRect nautilus_art_irect_align (const ArtIRect *container, - int aligned_width, - int aligned_height, - float x_alignment, - float y_alignment); +gboolean nautilus_art_irect_equal (const ArtIRect *rect_a, + const ArtIRect *rect_b); +gboolean nautilus_art_drect_equal (const ArtDRect *rect_a, + const ArtDRect *rect_b); +gboolean nautilus_art_irect_hits_irect (const ArtIRect *rect_a, + const ArtIRect *rect_b); +gboolean nautilus_art_irect_contains_irect (const ArtIRect *outer_rect, + const ArtIRect *inner_rect); +gboolean nautilus_art_irect_contains_point (const ArtIRect *outer_rect, + int x, + int y); +void nautilus_art_irect_assign (ArtIRect *rect, + int x, + int y, + int width, + int height); +int nautilus_art_irect_get_width (const ArtIRect *rect); +int nautilus_art_irect_get_height (const ArtIRect *rect); +ArtIRect nautilus_art_irect_align (const ArtIRect *container, + int aligned_width, + int aligned_height, + float x_alignment, + float y_alignment); +/* NautilusDimensions functions. */ +gboolean nautilus_dimensions_empty (const NautilusDimensions *dimensions); +ArtIRect nautilus_art_irect_assign_dimensions (int x, + int y, + const NautilusDimensions *dimensions); + END_GNOME_DECLS #endif /* NAUTILUS_ART_EXTENSIONS_H */ diff --git a/libnautilus-extensions/nautilus-art-gtk-extensions.c b/libnautilus-extensions/nautilus-art-gtk-extensions.c index 74ccb5878..3b5814131 100644 --- a/libnautilus-extensions/nautilus-art-gtk-extensions.c +++ b/libnautilus-extensions/nautilus-art-gtk-extensions.c @@ -27,7 +27,7 @@ #include "nautilus-art-gtk-extensions.h" /** - * nautilus_irect_assign_gdk_rectangle: + * nautilus_gdk_rectangle_to_art_irect: * @gdk_rectangle: The source GdkRectangle. * * Return value: An ArtIRect representation of the GdkRectangle. @@ -38,7 +38,7 @@ * in GtkWidget's. */ ArtIRect -nautilus_irect_assign_gdk_rectangle (const GdkRectangle *gdk_rectangle) +nautilus_gdk_rectangle_to_art_irect (const GdkRectangle *gdk_rectangle) { ArtIRect irect; @@ -53,29 +53,27 @@ nautilus_irect_assign_gdk_rectangle (const GdkRectangle *gdk_rectangle) } /** - * nautilus_irect_screen_get_frame: + * nautilus_screen_get_dimensions: * - * Return value: An ArtIRect representing the screen frame. + * Return value: The screen dimensions. * */ -ArtIRect -nautilus_irect_screen_get_frame (void) +NautilusDimensions +nautilus_screen_get_dimensions (void) { - ArtIRect screen_frame; + NautilusDimensions screen_dimensions; - screen_frame.x0 = 0; - screen_frame.y0 = 0; - screen_frame.x1 = gdk_screen_width (); - screen_frame.y1 = gdk_screen_width (); + screen_dimensions.width = gdk_screen_width (); + screen_dimensions.height = gdk_screen_width (); - g_assert (screen_frame.x1 > 0); - g_assert (screen_frame.y1 > 0); + g_assert (screen_dimensions.width > 0); + g_assert (screen_dimensions.height > 0); - return screen_frame; + return screen_dimensions; } /** - * nautilus_irect_gdk_window_get_bounds: + * nautilus_gdk_window_get_bounds: * @gdk_window: The source GdkWindow. * * Return value: An ArtIRect representation of the given GdkWindow's geometry @@ -83,7 +81,7 @@ nautilus_irect_screen_get_frame (void) * */ ArtIRect -nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window) +nautilus_gdk_window_get_bounds (const GdkWindow *gdk_window) { ArtIRect bounds; int width; @@ -101,7 +99,7 @@ nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window) } /** - * nautilus_irect_gdk_window_get_bounds: + * nautilus_gdk_window_get_bounds: * @gdk_window: The source GdkWindow. * * Return value: An ArtIRect representation of the given GdkWindow's geometry @@ -109,7 +107,7 @@ nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window) * */ ArtIRect -nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window) +nautilus_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window) { ArtIRect screen_bounds; int width; @@ -132,7 +130,7 @@ nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_windo } /** - * nautilus_irect_gtk_widget_get_bounds: + * nautilus_gtk_widget_get_bounds: * @gtk_widget: The source GtkWidget. * * Return value: An ArtIRect representation of the given GtkWidget's geometry @@ -140,7 +138,7 @@ nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_windo * */ ArtIRect -nautilus_irect_gtk_widget_get_bounds (const GtkWidget *gtk_widget) +nautilus_gtk_widget_get_bounds (const GtkWidget *gtk_widget) { ArtIRect bounds; @@ -156,30 +154,27 @@ nautilus_irect_gtk_widget_get_bounds (const GtkWidget *gtk_widget) } /** - * nautilus_irect_gtk_widget_get_frame: + * nautilus_gtk_widget_get_dimensions: * @gtk_widget: The source GtkWidget. * * Return value: An ArtIRect representation of the given GtkWidget's dimensions. * */ -ArtIRect -nautilus_irect_gtk_widget_get_frame (const GtkWidget *gtk_widget) +NautilusDimensions +nautilus_gtk_widget_get_dimensions (const GtkWidget *gtk_widget) { - ArtIRect frame; + NautilusDimensions dimensions; - g_return_val_if_fail (GTK_IS_WIDGET (gtk_widget), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (GTK_IS_WIDGET (gtk_widget), NAUTILUS_DIMENSIONS_EMPTY); - nautilus_art_irect_assign (&frame, - 0, - 0, - (int) gtk_widget->allocation.width, - (int) gtk_widget->allocation.height); + dimensions.width = (int) gtk_widget->allocation.width; + dimensions.height = (int) gtk_widget->allocation.height; - return frame; + return dimensions; } /** - * nautilus_irect_gdk_window_clip_dirty_area_to_screen: + * nautilus_gdk_window_clip_dirty_area_to_screen: * @gdk_window: The GdkWindow that the damage occured on. * @dirty_area: The dirty area as an ArtIRect. * @@ -189,11 +184,11 @@ nautilus_irect_gtk_widget_get_frame (const GtkWidget *gtk_widget) * It also ensures that any drawing that the widget does is actually onscreen. */ ArtIRect -nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, - const ArtIRect *dirty_area) +nautilus_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, + const ArtIRect *dirty_area) { ArtIRect clipped; - ArtIRect screen_frame; + NautilusDimensions screen_dimensions; ArtIRect bounds; ArtIRect screen_relative_bounds; int dirty_width; @@ -208,9 +203,9 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window g_return_val_if_fail (dirty_width > 0, NAUTILUS_ART_IRECT_EMPTY); g_return_val_if_fail (dirty_height > 0, NAUTILUS_ART_IRECT_EMPTY); - screen_frame = nautilus_irect_screen_get_frame (); - bounds = nautilus_irect_gdk_window_get_bounds (gdk_window); - screen_relative_bounds = nautilus_irect_gdk_window_get_screen_relative_bounds (gdk_window); + screen_dimensions = nautilus_screen_get_dimensions (); + bounds = nautilus_gdk_window_get_bounds (gdk_window); + screen_relative_bounds = nautilus_gdk_window_get_screen_relative_bounds (gdk_window); /* Window is obscured by left edge of screen */ if ((screen_relative_bounds.x0 + dirty_area->x0) < 0) { @@ -223,11 +218,11 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window } /* Window is obscured by right edge of screen */ - if (screen_relative_bounds.x1 > screen_frame.x1) { + if (screen_relative_bounds.x1 > screen_dimensions.width) { int obscured_width; obscured_width = - screen_relative_bounds.x0 + dirty_area->x0 + dirty_width - screen_frame.x1; + screen_relative_bounds.x0 + dirty_area->x0 + dirty_width - screen_dimensions.width; if (obscured_width > 0) { clipped.x1 -= obscured_width; @@ -245,11 +240,11 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window } /* Window is obscured by bottom edge of screen */ - if (screen_relative_bounds.y1 > screen_frame.y1) { + if (screen_relative_bounds.y1 > screen_dimensions.height) { int obscured_height; obscured_height = - screen_relative_bounds.y0 + dirty_area->y0 + dirty_height - screen_frame.y1; + screen_relative_bounds.y0 + dirty_area->y0 + dirty_height - screen_dimensions.height; if (obscured_height > 0) { clipped.y1 -= obscured_height; @@ -264,7 +259,7 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window } GdkRectangle -nautilus_gdk_rectangle_assign_irect (const ArtIRect *irect) +nautilus_art_irect_to_gdk_rectangle (const ArtIRect *irect) { GdkRectangle gdk_rect; @@ -282,3 +277,16 @@ nautilus_gdk_rectangle_assign_irect (const ArtIRect *irect) return gdk_rect; } + +NautilusDimensions +nautilus_gdk_window_get_dimensions (const GdkWindow *gdk_window) +{ + NautilusDimensions dimensions; + + g_return_val_if_fail (gdk_window != NULL, NAUTILUS_DIMENSIONS_EMPTY); + + gdk_window_get_size ((GdkWindow *) gdk_window, &dimensions.width, &dimensions.height); + + return dimensions; +} + diff --git a/libnautilus-extensions/nautilus-art-gtk-extensions.h b/libnautilus-extensions/nautilus-art-gtk-extensions.h index 0bc2578a6..808185fa6 100644 --- a/libnautilus-extensions/nautilus-art-gtk-extensions.h +++ b/libnautilus-extensions/nautilus-art-gtk-extensions.h @@ -23,10 +23,10 @@ */ /* The following functions accept gtk/gdk structures and - * return their bounds/frames as ArtIRects, where: + * return their bounds and dimensions, where: * * bounds: The (x,y) and (width, height) of something. - * frame: The (width, height) of something. + * dimensions: The (width, height) of something. * * These are very useful in code that uses libart functions * to do operations on ArtIRects (such as intersection) @@ -41,16 +41,28 @@ BEGIN_GNOME_DECLS -GdkRectangle nautilus_gdk_rectangle_assign_irect (const ArtIRect *irect); -ArtIRect nautilus_irect_assign_gdk_rectangle (const GdkRectangle *gdk_rectangle); -ArtIRect nautilus_irect_screen_get_frame (void); -ArtIRect nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window); -ArtIRect nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window); -ArtIRect nautilus_irect_gtk_widget_get_bounds (const GtkWidget *gtk_widget); -ArtIRect nautilus_irect_gtk_widget_get_frame (const GtkWidget *gtk_widget); -ArtIRect nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, +/* Convert between GdkRectangle and ArtIRect and back */ +GdkRectangle nautilus_art_irect_to_gdk_rectangle (const ArtIRect *irect); +ArtIRect nautilus_gdk_rectangle_to_art_irect (const GdkRectangle *gdk_rectangle); +NautilusDimensions nautilus_screen_get_dimensions (void); + +/* GdkWindow parent-relative bounds */ +ArtIRect nautilus_gdk_window_get_bounds (const GdkWindow *gdk_window); + +/* GdkWindow dimensions */ +NautilusDimensions nautilus_gdk_window_get_dimensions (const GdkWindow *gdk_window); + +/* GdkWindow screen parent-relative bounds */ +ArtIRect nautilus_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window); + +/* Clip a dirty area (from exposures) to the on screen parts of a GdkWindow */ +ArtIRect nautilus_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, const ArtIRect *dirty_area); +/* GtkWidget bounds and dimensions */ +ArtIRect nautilus_gtk_widget_get_bounds (const GtkWidget *gtk_widget); +NautilusDimensions nautilus_gtk_widget_get_dimensions (const GtkWidget *gtk_widget); + END_GNOME_DECLS #endif /* NAUTILUS_ART_GTK_EXTENSIONS_H */ diff --git a/libnautilus-extensions/nautilus-clickable-image.c b/libnautilus-extensions/nautilus-clickable-image.c index 801e54ca4..b5330e44c 100644 --- a/libnautilus-extensions/nautilus-clickable-image.c +++ b/libnautilus-extensions/nautilus-clickable-image.c @@ -276,7 +276,7 @@ label_handle_motion (NautilusClickableImage *clickable_image, g_return_if_fail (NAUTILUS_IS_CLICKABLE_IMAGE (clickable_image)); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (clickable_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (clickable_image)); if (nautilus_art_irect_contains_point (&bounds, x, y)) { /* Inside */ diff --git a/libnautilus-extensions/nautilus-debug-drawing.c b/libnautilus-extensions/nautilus-debug-drawing.c index a280da17f..728f77788 100644 --- a/libnautilus-extensions/nautilus-debug-drawing.c +++ b/libnautilus-extensions/nautilus-debug-drawing.c @@ -119,19 +119,19 @@ static void debug_pixbuf_viewer_size_request (GtkWidget *widget, GtkRequisition *requisition) { DebugPixbufViewer *viewer; - ArtIRect frame; + NautilusDimensions dimensions; g_return_if_fail (DEBUG_IS_PIXBUF_VIEWER (widget)); g_return_if_fail (requisition != NULL); viewer = DEBUG_PIXBUF_VIEWER (widget); - frame = (viewer->pixbuf != NULL) ? - nautilus_gdk_pixbuf_get_frame (viewer->pixbuf) : - NAUTILUS_ART_IRECT_EMPTY; + dimensions = (viewer->pixbuf != NULL) ? + nautilus_gdk_pixbuf_get_dimensions (viewer->pixbuf) : + NAUTILUS_DIMENSIONS_EMPTY; - requisition->width = MAX (2, frame.x1); - requisition->height = MAX (2, frame.y1); + requisition->width = MAX (2, dimensions.width); + requisition->height = MAX (2, dimensions.height); } static int @@ -159,8 +159,8 @@ debug_pixbuf_viewer_expose_event (GtkWidget *widget, GdkEventExpose *event) bounds.y1 = bounds.y0 + gdk_pixbuf_get_height (viewer->pixbuf); /* Clip the dirty area to the screen; bail if no work to do */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); - clipped_dirty_area = nautilus_irect_gdk_window_clip_dirty_area_to_screen (event->window, + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); + clipped_dirty_area = nautilus_gdk_window_clip_dirty_area_to_screen (event->window, &dirty_area); if (!art_irect_empty (&clipped_dirty_area)) { ArtIRect clipped_bounds; @@ -363,7 +363,7 @@ nautilus_debug_pixbuf_draw_point (GdkPixbuf *pixbuf, guint32 color, int opacity) { - ArtIRect frame; + NautilusDimensions dimensions; guchar *pixels; gboolean has_alpha; guint pixel_offset; @@ -378,10 +378,10 @@ nautilus_debug_pixbuf_draw_point (GdkPixbuf *pixbuf, g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); - g_return_if_fail (x >= 0 && x < frame.x1); - g_return_if_fail (y >= 0 && y < frame.y1); + g_return_if_fail (x >= 0 && x < dimensions.width); + g_return_if_fail (y >= 0 && y < dimensions.height); pixels = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); @@ -414,7 +414,7 @@ nautilus_debug_pixbuf_draw_rectangle (GdkPixbuf *pixbuf, guint32 color, int opacity) { - ArtIRect frame; + NautilusDimensions dimensions; int x; int y; @@ -422,7 +422,7 @@ nautilus_debug_pixbuf_draw_rectangle (GdkPixbuf *pixbuf, g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); if (x0 == -1) { x0 = 0; @@ -433,19 +433,19 @@ nautilus_debug_pixbuf_draw_rectangle (GdkPixbuf *pixbuf, } if (x1 == -1) { - x1 = frame.x1 - 1; + x1 = dimensions.width - 1; } if (y1 == -1) { - y1 = frame.y1 - 1; + y1 = dimensions.height - 1; } g_return_if_fail (x1 > x0); g_return_if_fail (y1 > y0); - g_return_if_fail (x0 >= 0 && x0 < frame.x1); - g_return_if_fail (y0 >= 0 && y0 < frame.y1); - g_return_if_fail (x1 >= 0 && x1 < frame.x1); - g_return_if_fail (y1 >= 0 && y1 < frame.y1); + g_return_if_fail (x0 >= 0 && x0 < dimensions.width); + g_return_if_fail (y0 >= 0 && y0 < dimensions.height); + g_return_if_fail (x1 >= 0 && x1 < dimensions.width); + g_return_if_fail (y1 >= 0 && y1 < dimensions.height); if (filled) { for (y = y0; y <= y1; y++) { @@ -479,13 +479,13 @@ nautilus_debug_pixbuf_draw_rectangle_inset (GdkPixbuf *pixbuf, int opacity, int inset) { - ArtIRect frame; + NautilusDimensions dimensions; g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); if (x0 == -1) { x0 = 0; @@ -496,11 +496,11 @@ nautilus_debug_pixbuf_draw_rectangle_inset (GdkPixbuf *pixbuf, } if (x1 == -1) { - x1 = frame.x1 - 1; + x1 = dimensions.width - 1; } if (y1 == -1) { - y1 = frame.y1 - 1; + y1 = dimensions.height - 1; } x0 += inset; diff --git a/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c b/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c index 413eebfb6..1be64a8a3 100644 --- a/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c +++ b/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c @@ -29,6 +29,9 @@ #include "nautilus-gdk-extensions.h" #include "nautilus-glib-extensions.h" #include "nautilus-string.h" +#include "nautilus-art-gtk-extensions.h" +#include "nautilus-lib-self-check-functions.h" +#include "nautilus-debug-drawing.h" #include <gdk-pixbuf/gdk-pixbuf-loader.h> #include <gdk/gdkx.h> #include <gdk/gdkprivate.h> @@ -388,28 +391,25 @@ nautilus_gdk_pixbuf_is_valid (const GdkPixbuf *pixbuf) } /** - * nautilus_gdk_pixbuf_get_frame: + * nautilus_gdk_pixbuf_get_dimensions: * @pixbuf: A GdkPixbuf * - * Return value: A ArtIRect representing the dimensions of the - * pixbuf. + * Return value: The dimensions of the pixbuf as a NautilusDimensions. * * This function is useful in code that uses libart rect * intersection routines. */ -ArtIRect -nautilus_gdk_pixbuf_get_frame (const GdkPixbuf *pixbuf) +NautilusDimensions +nautilus_gdk_pixbuf_get_dimensions (const GdkPixbuf *pixbuf) { - ArtIRect frame; + NautilusDimensions dimensions; - g_return_val_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf), NAUTILUS_DIMENSIONS_EMPTY); - frame.x0 = 0; - frame.y0 = 0; - frame.x1 = gdk_pixbuf_get_width (pixbuf); - frame.y1 = gdk_pixbuf_get_height (pixbuf); + dimensions.width = gdk_pixbuf_get_width (pixbuf); + dimensions.height = gdk_pixbuf_get_height (pixbuf); - return frame; + return dimensions; } /** @@ -427,7 +427,6 @@ nautilus_gdk_pixbuf_fill_rectangle_with_color (GdkPixbuf *pixbuf, const ArtIRect *area, guint32 color) { - ArtIRect frame; ArtIRect target; guchar red; guchar green; @@ -443,26 +442,15 @@ nautilus_gdk_pixbuf_fill_rectangle_with_color (GdkPixbuf *pixbuf, g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + target = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, area); + if (art_irect_empty (&target)) { + return; + } pixels = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); pixel_offset = has_alpha ? 4 : 3; - - /* If an area is given, make sure its clipped to the pixbuf frame */ - if (area != NULL) { - - art_irect_intersect (&target, area, &frame); - - if (art_irect_empty (&target)) { - return; - } - /* If no area is given, then use the whole pixbuf frame */ - } else { - target = frame; - } - red = NAUTILUS_RGBA_COLOR_GET_R (color); green = NAUTILUS_RGBA_COLOR_GET_G (color); blue = NAUTILUS_RGBA_COLOR_GET_B (color); @@ -614,20 +602,6 @@ nautilus_gdk_pixbuf_unref_if_not_null (GdkPixbuf *pixbuf_or_null) } } -static ArtIRect -nautilus_gdk_window_get_frame (const GdkWindow *window) -{ - ArtIRect frame; - - g_return_val_if_fail (window != NULL, NAUTILUS_ART_IRECT_EMPTY); - - frame.x0 = 0; - frame.y0 = 0; - gdk_window_get_size ((GdkWindow *) window, &frame.x1, &frame.y1); - - return frame; -} - void nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, GdkDrawable *drawable, @@ -639,10 +613,9 @@ nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, GdkPixbufAlphaMode alpha_compositing_mode, int alpha_threshold) { - ArtIRect frame; + NautilusDimensions dimensions; ArtIRect target; ArtIRect source; - ArtIRect destination_frame; int target_width; int target_height; int source_width; @@ -659,29 +632,31 @@ nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, g_return_if_fail (alpha_compositing_mode >= GDK_PIXBUF_ALPHA_BILEVEL); g_return_if_fail (alpha_compositing_mode <= GDK_PIXBUF_ALPHA_FULL); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - destination_frame = nautilus_gdk_window_get_frame (drawable); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); g_return_if_fail (source_x >= 0); g_return_if_fail (source_y >= 0); - g_return_if_fail (source_x < (frame.x1 - frame.x0)); - g_return_if_fail (source_y < (frame.y1 - frame.y0)); - - /* Clip the destination area to the destination pixbuf frame */ - art_irect_intersect (&target, destination_area, &destination_frame); + g_return_if_fail (source_x < dimensions.width); + g_return_if_fail (source_y < dimensions.height); + + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (pixbuf, + destination_area->x0, + destination_area->y0, + destination_area); if (art_irect_empty (&target)) { - return; - } + return; + } /* Assign the source area */ nautilus_art_irect_assign (&source, source_x, source_y, - frame.x1 - frame.x0 - source_x, - frame.y1 - frame.y0 - source_y); + dimensions.width - source_x, + dimensions.height - source_y); /* Adjust the target width if the source area is smaller than the - * source pixbuf frame */ + * source pixbuf dimensions */ target_width = target.x1 - target.x0; target_height = target.y1 - target.y0; source_width = source.x1 - source.x0; @@ -718,7 +693,6 @@ nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, 0, 0); } - } /** @@ -749,10 +723,9 @@ nautilus_gdk_pixbuf_draw_to_pixbuf (const GdkPixbuf *pixbuf, int source_y, const ArtIRect *destination_area) { - ArtIRect frame; + NautilusDimensions dimensions; ArtIRect target; ArtIRect source; - ArtIRect destination_frame; int target_width; int target_height; int source_width; @@ -764,16 +737,15 @@ nautilus_gdk_pixbuf_draw_to_pixbuf (const GdkPixbuf *pixbuf, g_return_if_fail (destination_area->x1 > destination_area->x0); g_return_if_fail (destination_area->y1 > destination_area->y0); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - destination_frame = nautilus_gdk_pixbuf_get_frame (destination_pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); g_return_if_fail (source_x >= 0); g_return_if_fail (source_y >= 0); - g_return_if_fail (source_x < (frame.x1 - frame.x0)); - g_return_if_fail (source_y < (frame.y1 - frame.y0)); + g_return_if_fail (source_x < dimensions.width); + g_return_if_fail (source_y < dimensions.height); - /* Clip the destination area to the destination pixbuf frame */ - art_irect_intersect (&target, destination_area, &destination_frame); + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (destination_pixbuf, 0, 0, destination_area); if (art_irect_empty (&target)) { return; } @@ -782,11 +754,11 @@ nautilus_gdk_pixbuf_draw_to_pixbuf (const GdkPixbuf *pixbuf, nautilus_art_irect_assign (&source, source_x, source_y, - frame.x1 - frame.x0 - source_x, - frame.y1 - frame.y0 - source_y); + dimensions.width - source_x, + dimensions.height - source_y); /* Adjust the target width if the source area is smaller than the - * source pixbuf frame */ + * source pixbuf dimensions */ target_width = target.x1 - target.x0; target_height = target.y1 - target.y0; source_width = source.x1 - source.x0; @@ -840,10 +812,9 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, int opacity, GdkInterpType interpolation_mode) { - ArtIRect frame; + NautilusDimensions dimensions; ArtIRect target; ArtIRect source; - ArtIRect destination_frame; int target_width; int target_height; int source_width; @@ -859,17 +830,17 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, g_return_if_fail (interpolation_mode >= GDK_INTERP_NEAREST); g_return_if_fail (interpolation_mode <= GDK_INTERP_HYPER); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - destination_frame = nautilus_gdk_pixbuf_get_frame (destination_pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); g_return_if_fail (source_x >= 0); g_return_if_fail (source_y >= 0); - g_return_if_fail (source_x < (frame.x1 - frame.x0)); - g_return_if_fail (source_y < (frame.y1 - frame.y0)); + g_return_if_fail (source_x < dimensions.width); + g_return_if_fail (source_y < dimensions.height); - /* Clip the destination area to the destination pixbuf frame */ - art_irect_intersect (&target, destination_area, &destination_frame); - if (art_irect_empty (&target)) { + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (destination_pixbuf, 0, 0, destination_area); + if (art_irect_empty (&target)) { return; } @@ -877,11 +848,11 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, nautilus_art_irect_assign (&source, source_x, source_y, - frame.x1 - frame.x0 - source_x, - frame.y1 - frame.y0 - source_y); + dimensions.width - source_x, + dimensions.height - source_y); /* Adjust the target width if the source area is smaller than the - * source pixbuf frame */ + * source pixbuf dimensions */ target_width = target.x1 - target.x0; target_height = target.y1 - target.y0; source_width = source.x1 - source.x0; @@ -898,8 +869,8 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, int width; int height; - width = frame.x1 - frame.x0 - source.x0; - height = frame.y1 - frame.y0 - source.y0; + width = dimensions.width - source.x0; + height = dimensions.height - source.y0; area.x0 = source.x0; area.y0 = source.y0; @@ -957,7 +928,6 @@ nautilus_gdk_pixbuf_new_from_pixbuf_sub_area (GdkPixbuf *pixbuf, const ArtIRect *area) { GdkPixbuf *sub_pixbuf; - ArtIRect frame; ArtIRect target; guchar *pixels; @@ -966,10 +936,9 @@ nautilus_gdk_pixbuf_new_from_pixbuf_sub_area (GdkPixbuf *pixbuf, g_return_val_if_fail (area->x1 > area->x0, NULL); g_return_val_if_fail (area->y1 > area->y0, NULL); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - - art_irect_intersect (&target, area, &frame); - if (art_irect_empty (&target)) { + /* Clip the pixbuf by the given area; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, area); + if (art_irect_empty (&target)) { return NULL; } @@ -1077,7 +1046,7 @@ typedef void (* DrawPixbufTileCallback) (const GdkPixbuf *pixbuf, /* The shared tiliing implementation */ static void pixbuf_draw_tiled (const GdkPixbuf *pixbuf, - const ArtIRect *destination_frame, + const NautilusDimensions *destination_dimensions, const ArtIRect *destination_area, int tile_width, int tile_height, @@ -1095,34 +1064,41 @@ pixbuf_draw_tiled (const GdkPixbuf *pixbuf, int num_above; g_return_if_fail (pixbuf != NULL); - g_return_if_fail (destination_frame != NULL); + g_return_if_fail (destination_dimensions != NULL); g_return_if_fail (tile_width > 0); g_return_if_fail (tile_height > 0); g_return_if_fail (tile_width <= gdk_pixbuf_get_width (pixbuf)); g_return_if_fail (tile_height <= gdk_pixbuf_get_height (pixbuf)); g_return_if_fail (callback != NULL); + /* FIXME: This is confusing. Instead of passing in the destination_dimensions + * I should just pass in the destination pixbuf, so that we can use + * nautilus_gdk_pixbuf_intersect directly on that. + */ + + /* Clip the destination area to the destination pixbuf; bail if no work */ if (destination_area != NULL) { - art_irect_intersect (&target, destination_area, destination_frame); + ArtIRect tmp; + tmp = nautilus_art_irect_assign_dimensions (0, 0, destination_dimensions); + art_irect_intersect (&target, destination_area, &tmp); + if (art_irect_empty (&target)) { return; } } else { - target = *destination_frame; + target = nautilus_art_irect_assign_dimensions (0, 0, destination_dimensions); } /* The number of tiles left and above the target area */ num_left = (target.x0 - tile_origin_x) / tile_width; num_above = (target.y0 - tile_origin_y) / tile_height; - nautilus_art_ipoint_assign (&min_point, - tile_origin_x - tile_width + (num_left * tile_width), - tile_origin_y - tile_height + (num_above * tile_height)); + min_point.x = tile_origin_x - tile_width + (num_left * tile_width); + min_point.y = tile_origin_y - tile_height + (num_above * tile_height); - nautilus_art_ipoint_assign (&max_point, - (target.x1 + 2 * tile_width), - (target.y1 + 2 * tile_height)); + max_point.x = (target.x1 + 2 * tile_width); + max_point.y = (target.y1 + 2 * tile_height); for (y = min_point.y; y <= max_point.y; y += tile_height) { for (x = min_point.x; x <= max_point.x; x += tile_width) { @@ -1236,7 +1212,7 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (const GdkPixbuf *pixbuf, GdkInterpType interpolation_mode) { PixbufTileData pixbuf_tile_data; - ArtIRect destination_frame; + NautilusDimensions destination_dimensions; g_return_if_fail (nautilus_gdk_pixbuf_is_valid (destination_pixbuf)); g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); @@ -1249,14 +1225,14 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (const GdkPixbuf *pixbuf, g_return_if_fail (interpolation_mode >= GDK_INTERP_NEAREST); g_return_if_fail (interpolation_mode <= GDK_INTERP_HYPER); - destination_frame = nautilus_gdk_pixbuf_get_frame (destination_pixbuf); + destination_dimensions = nautilus_gdk_pixbuf_get_dimensions (destination_pixbuf); pixbuf_tile_data.destination_pixbuf = destination_pixbuf; pixbuf_tile_data.opacity = opacity; pixbuf_tile_data.interpolation_mode = interpolation_mode; pixbuf_draw_tiled (pixbuf, - &destination_frame, + &destination_dimensions, destination_area, tile_width, tile_height, @@ -1298,7 +1274,7 @@ nautilus_gdk_pixbuf_draw_to_drawable_tiled (const GdkPixbuf *pixbuf, int alpha_threshold) { DrawableTileData drawable_tile_data; - ArtIRect destination_frame; + NautilusDimensions destination_dimensions; g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); g_return_if_fail (drawable != NULL); @@ -1311,7 +1287,7 @@ nautilus_gdk_pixbuf_draw_to_drawable_tiled (const GdkPixbuf *pixbuf, g_return_if_fail (alpha_compositing_mode >= GDK_PIXBUF_ALPHA_BILEVEL); g_return_if_fail (alpha_compositing_mode <= GDK_PIXBUF_ALPHA_FULL); - destination_frame = nautilus_gdk_window_get_frame (drawable); + destination_dimensions = nautilus_gdk_window_get_dimensions (drawable); drawable_tile_data.drawable = drawable; drawable_tile_data.gc = gc; @@ -1320,7 +1296,7 @@ nautilus_gdk_pixbuf_draw_to_drawable_tiled (const GdkPixbuf *pixbuf, drawable_tile_data.alpha_threshold = alpha_threshold; pixbuf_draw_tiled (pixbuf, - &destination_frame, + &destination_dimensions, destination_area, tile_width, tile_height, @@ -1500,3 +1476,107 @@ nautilus_gdk_pixbuf_get_from_window_safe (GdkWindow *window, return pixbuf; } + +/** + * nautilus_gdk_pixbuf_intersect: + * @pixbuf: A GdkPixbuf. + * @pixbuf_x: X coordinate of pixbuf. + * @pixbuf_y: Y coordinate of pixbuf. + * @rectangle: An ArtIRect or NULL. + * + * Return value: The intersection of the pixbuf and the given rectangle. + * + * If &rectangle is NULL, then the resulting rectangle is a rectangle at + * the given orign with the pixbuf's dimensions. + * + */ +ArtIRect +nautilus_gdk_pixbuf_intersect (const GdkPixbuf *pixbuf, + int pixbuf_x, + int pixbuf_y, + const ArtIRect *rectangle) +{ + ArtIRect intersection; + ArtIRect bounds; + NautilusDimensions dimensions; + + g_return_val_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf), NAUTILUS_ART_IRECT_EMPTY); + + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); + bounds = nautilus_art_irect_assign_dimensions (pixbuf_x, pixbuf_y, &dimensions); + + if (rectangle == NULL) { + return bounds; + } + + art_irect_intersect (&intersection, rectangle, &bounds); + + /* In theory, this is not needed because a rectangle is empty + * regardless of how MUCH negative the dimensions are. + * However, to make debugging and self checks simpler, we + * consistenly return a standard empty rectangle. + */ + if (art_irect_empty (&intersection)) { + return NAUTILUS_ART_IRECT_EMPTY; + } + + return intersection; +} + +#if !defined (NAUTILUS_OMIT_SELF_CHECK) + +void +nautilus_self_check_gdk_pixbuf_extensions (void) +{ + GdkPixbuf *pixbuf; + ArtIRect clip_area; + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 100); + + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gdk_pixbuf_is_valid (pixbuf), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gdk_pixbuf_is_valid (NULL), FALSE); + + NAUTILUS_CHECK_DIMENSIONS_RESULT (nautilus_gdk_pixbuf_get_dimensions (pixbuf), 100, 100); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, NULL), 0, 0, 100, 100); + + nautilus_art_irect_assign (&clip_area, 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 0, 0, 100, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 100, 100); + + nautilus_art_irect_assign (&clip_area, -10, -10, 100, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 90, 90); + + nautilus_art_irect_assign (&clip_area, -10, -10, 110, 110); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 100, 100); + + nautilus_art_irect_assign (&clip_area, 0, 0, 99, 99); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 99, 99); + + nautilus_art_irect_assign (&clip_area, 0, 0, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 1, 1); + + nautilus_art_irect_assign (&clip_area, -1, -1, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, -1, -1, 2, 2); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 1, 1); + + nautilus_art_irect_assign (&clip_area, 100, 100, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 101, 101, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 80, 0, 100, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 80, 0, 100, 100); + + gdk_pixbuf_unref (pixbuf); +} + +#endif /* !NAUTILUS_OMIT_SELF_CHECK */ diff --git a/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h b/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h index 0ab53e970..8106c74bc 100644 --- a/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h +++ b/libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h @@ -163,7 +163,13 @@ GdkPixbuf * nautilus_gdk_pixbuf_get_from_window_safe (GdkWind /* Determine whether a pixbuf is valid or not */ gboolean nautilus_gdk_pixbuf_is_valid (const GdkPixbuf *pixbuf); -/* Access the dimensions of a pixbuf as a ArtIRect frame. */ -ArtIRect nautilus_gdk_pixbuf_get_frame (const GdkPixbuf *pixbuf); +/* Access the dimensions of a pixbuf. */ +NautilusDimensions nautilus_gdk_pixbuf_get_dimensions (const GdkPixbuf *pixbuf); + +/* Return the intersection of the pixbuf with the given rectangle. */ +ArtIRect nautilus_gdk_pixbuf_intersect (const GdkPixbuf *pixbuf, + int pixbuf_x, + int pixbuf_y, + const ArtIRect *rectangle); #endif /* NAUTILUS_GDK_PIXBUF_EXTENSIONS_H */ diff --git a/libnautilus-extensions/nautilus-glyph.c b/libnautilus-extensions/nautilus-glyph.c index 5abe4de14..b913a9c52 100644 --- a/libnautilus-extensions/nautilus-glyph.c +++ b/libnautilus-extensions/nautilus-glyph.c @@ -54,9 +54,9 @@ struct NautilusGlyph */ NautilusGlyph * nautilus_glyph_new (const NautilusScalableFont *font, + guint font_size, const char *text, - guint text_length, - guint font_size) + guint text_length) { NautilusGlyph *glyph; RsvgFTGlyph *rsvg_glyph; @@ -133,25 +133,23 @@ nautilus_glyph_get_height (const NautilusGlyph *glyph) } /** - * nautilus_glyph_get_frame: + * nautilus_glyph_get_dimensions: * @glyph: A NautilusGlyph. * - * Returns: An ArtIRect representing the frame occupied by the glyph. + * Returns: An ArtIRect representing the dimensions occupied by the glyph. */ -ArtIRect -nautilus_glyph_get_frame (const NautilusGlyph *glyph) +NautilusDimensions +nautilus_glyph_get_dimensions (const NautilusGlyph *glyph) { - ArtIRect glyph_frame; + NautilusDimensions glyph_dimensions; - g_return_val_if_fail (glyph != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (glyph->rsvg_glyph != NULL, NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (glyph != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (glyph->rsvg_glyph != NULL, NAUTILUS_DIMENSIONS_EMPTY); - glyph_frame.x0 = 0; - glyph_frame.y0 = 0; - glyph_frame.x1 = glyph->rsvg_glyph->width; - glyph_frame.y1 = glyph->rsvg_glyph->height; + glyph_dimensions.width = glyph->rsvg_glyph->width; + glyph_dimensions.height = glyph->rsvg_glyph->height; - return glyph_frame; + return glyph_dimensions; } /* FIXME bugzilla.eazel.com xxxx: We should really use libart @@ -213,13 +211,12 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, guchar *pixbuf_pixels; guint pixbuf_pixel_offset; gboolean pixbuf_has_alpha; - ArtIRect pixbuf_frame; - ArtIRect pixbuf_clip_area; + ArtIRect target; guchar *pixbuf_x_offset; guchar *pixbuf_y_offset; int glyph_rowstride; const guchar *glyph_buffer; - ArtIRect glyph_frame; + NautilusDimensions glyph_dimensions; ArtIRect glyph_bounds; const guchar *glyph_x_offset; const guchar *glyph_y_offset; @@ -239,33 +236,20 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, g_return_if_fail (glyph->rsvg_glyph->height > 0); g_return_if_fail (glyph->rsvg_glyph->rowstride > 0); g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); + g_return_if_fail (destination_x >= 0 && destination_x < gdk_pixbuf_get_width (pixbuf)); + g_return_if_fail (destination_y >= 0 && destination_y < gdk_pixbuf_get_height (pixbuf)); /* FIXME bugzilla.eazel.com xxxx: We currently dont handle opacities * other than 0xFF. */ g_return_if_fail (opacity == NAUTILUS_OPACITY_FULLY_OPAQUE); - - pixbuf_frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - - /* Make sure destination coordinates lie within the pixbuf */ - g_return_if_fail (destination_x >= 0 && destination_x <= pixbuf_frame.x1); - g_return_if_fail (destination_y >= 0 && destination_y <= pixbuf_frame.y1); - /* If a clip area is given, make sure its not empty */ - if (clip_area != NULL) { - g_return_if_fail (clip_area != NULL); - g_return_if_fail (!art_irect_empty (clip_area)); - - /* Clip the clip_area to the pixbuf's area; bail of no work */ - art_irect_intersect (&pixbuf_clip_area, clip_area, &pixbuf_frame); - if (art_irect_empty (&pixbuf_clip_area)) { - return; - } - /* If no clip area is given, use the whole pixbuf */ - } else { - pixbuf_clip_area = pixbuf_frame; + /* Clip the pixbuf to the clip area; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, clip_area); + if (art_irect_empty (&target)) { + return; } - - glyph_frame = nautilus_glyph_get_frame (glyph); + + glyph_dimensions = nautilus_glyph_get_dimensions (glyph); glyph_rowstride = glyph->rsvg_glyph->rowstride; glyph_buffer = glyph->rsvg_glyph->buf; @@ -278,15 +262,15 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, nautilus_art_irect_assign (&glyph_bounds, destination_x, destination_y, - glyph_frame.x1, - glyph_frame.y1); + glyph_dimensions.width, + glyph_dimensions.height); /* * Determine the actual render area. The render area is * the area of the glyph bounds that lies within the pixbuf * clip area; bail if no work. */ - art_irect_intersect (&render_area, &pixbuf_clip_area, &glyph_bounds); + art_irect_intersect (&render_area, &target, &glyph_bounds); if (art_irect_empty (&render_area)) { return; } @@ -294,10 +278,10 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, /* Debug code to be yanked real soon */ if (0) nautilus_debug_pixbuf_draw_rectangle_inset (pixbuf, FALSE, - pixbuf_clip_area.x0, - pixbuf_clip_area.y0, - pixbuf_clip_area.x1, - pixbuf_clip_area.y1, + target.x0, + target.y0, + target.x1, + target.y1, NAUTILUS_RGBA_COLOR_OPAQUE_GREEN, NAUTILUS_OPACITY_FULLY_OPAQUE, 0); @@ -358,12 +342,12 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, */ /* Iterate vertically */ - for (y = render_area.y0 ; y <= render_area.y1; y++) { + for (y = render_area.y0 ; y < render_area.y1; y++) { pixbuf_x_offset = pixbuf_y_offset; glyph_x_offset = glyph_y_offset; /* Iterate horizontally */ - for (x = render_area.x0 ; x <= render_area.x1; x++) { + for (x = render_area.x0 ; x < render_area.x1; x++) { const guchar point_opacity = *glyph_x_offset; /* Optimize the common fully opaque case */ diff --git a/libnautilus-extensions/nautilus-glyph.h b/libnautilus-extensions/nautilus-glyph.h index 92e76297e..ab942897b 100644 --- a/libnautilus-extensions/nautilus-glyph.h +++ b/libnautilus-extensions/nautilus-glyph.h @@ -29,26 +29,27 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <libart_lgpl/art_rect.h> #include <libnautilus-extensions/nautilus-scalable-font.h> +#include <libnautilus-extensions/nautilus-art-extensions.h> BEGIN_GNOME_DECLS typedef struct NautilusGlyph NautilusGlyph; -NautilusGlyph *nautilus_glyph_new (const NautilusScalableFont *font, - const char *text, - guint text_length, - guint font_size); -void nautilus_glyph_free (NautilusGlyph *glyph); -int nautilus_glyph_get_width (const NautilusGlyph *glyph); -int nautilus_glyph_get_height (const NautilusGlyph *glyph); -ArtIRect nautilus_glyph_get_frame (const NautilusGlyph *glyph); -void nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, - GdkPixbuf *pixbuf, - int destination_x, - int destination_y, - const ArtIRect *clip_area, - guint32 color, - int opacity); +NautilusGlyph * nautilus_glyph_new (const NautilusScalableFont *font, + guint font_size, + const char *text, + guint text_length); +void nautilus_glyph_free (NautilusGlyph *glyph); +int nautilus_glyph_get_width (const NautilusGlyph *glyph); +int nautilus_glyph_get_height (const NautilusGlyph *glyph); +NautilusDimensions nautilus_glyph_get_dimensions (const NautilusGlyph *glyph); +void nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, + GdkPixbuf *pixbuf, + int destination_x, + int destination_y, + const ArtIRect *clip_area, + guint32 color, + int opacity); END_GNOME_DECLS diff --git a/libnautilus-extensions/nautilus-icon-factory.c b/libnautilus-extensions/nautilus-icon-factory.c index 5d447a02d..409ef7d0e 100644 --- a/libnautilus-extensions/nautilus-icon-factory.c +++ b/libnautilus-extensions/nautilus-icon-factory.c @@ -2404,7 +2404,6 @@ embed_text (GdkPixbuf *pixbuf_without_text, embedded_text_rect->y0, embedded_text_rect, EMBEDDED_TEXT_FONT_SIZE, - EMBEDDED_TEXT_FONT_SIZE, text, GTK_JUSTIFY_LEFT, EMBEDDED_TEXT_LINE_OFFSET, diff --git a/libnautilus-extensions/nautilus-image-table.c b/libnautilus-extensions/nautilus-image-table.c index 69b8e64f0..610bf3d06 100644 --- a/libnautilus-extensions/nautilus-image-table.c +++ b/libnautilus-extensions/nautilus-image-table.c @@ -401,7 +401,8 @@ image_table_clear_dirty_areas (NautilusImageTable *image_table) { GtkWidget *widget; NautilusRegion *region; - ArtIRect bounds; + NautilusDimensions dimensions; + ArtIRect whole_region; GdkGC *gc; g_return_if_fail (NAUTILUS_IS_WRAP_TABLE (image_table)); @@ -409,10 +410,11 @@ image_table_clear_dirty_areas (NautilusImageTable *image_table) widget = GTK_WIDGET (image_table); - bounds = nautilus_irect_gtk_widget_get_frame (widget->parent); + dimensions = nautilus_gtk_widget_get_dimensions (widget->parent); + whole_region = nautilus_art_irect_assign_dimensions (0, 0, &dimensions); region = nautilus_region_new (); - nautilus_region_add_rectangle (region, &bounds); + nautilus_region_add_rectangle (region, &whole_region); gc = image_table_peek_clear_gc (image_table); @@ -423,10 +425,10 @@ image_table_clear_dirty_areas (NautilusImageTable *image_table) gdk_draw_rectangle (widget->window, gc, TRUE, - bounds.x0, - bounds.y0, - bounds.x1 - bounds.x0, - bounds.y1 - bounds.y0); + 0, + 0, + dimensions.width, + dimensions.height); nautilus_region_free (region); } @@ -558,7 +560,7 @@ ancestor_leave_notify_event (GtkWidget *widget, g_return_val_if_fail (NAUTILUS_IS_IMAGE_TABLE (event_data), FALSE); g_return_val_if_fail (event != NULL, FALSE); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (event_data)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (event_data)); if (nautilus_art_irect_contains_point (&bounds, event->x, event->y)) { x = event->x; diff --git a/libnautilus-extensions/nautilus-image.c b/libnautilus-extensions/nautilus-image.c index 173b1d340..36251e4ee 100644 --- a/libnautilus-extensions/nautilus-image.c +++ b/libnautilus-extensions/nautilus-image.c @@ -86,30 +86,30 @@ struct _NautilusImageDetails }; /* GtkObjectClass methods */ -static void nautilus_image_initialize_class (NautilusImageClass *image_class); -static void nautilus_image_initialize (NautilusImage *image); -static void nautilus_image_destroy (GtkObject *object); -static void nautilus_image_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_image_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_image_initialize_class (NautilusImageClass *image_class); +static void nautilus_image_initialize (NautilusImage *image); +static void nautilus_image_destroy (GtkObject *object); +static void nautilus_image_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_image_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_image_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int nautilus_image_expose_event (GtkWidget *widget, - GdkEventExpose *event); +static void nautilus_image_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static int nautilus_image_expose_event (GtkWidget *widget, + GdkEventExpose *event); /* NautilusImage signals */ -static void nautilus_image_set_is_smooth_signal (GtkWidget *widget, - gboolean is_smooth); +static void nautilus_image_set_is_smooth_signal (GtkWidget *widget, + gboolean is_smooth); /* Private NautilusImage methods */ -static ArtIRect image_get_pixbuf_frame (const NautilusImage *image); -static ArtIRect image_get_pixbuf_bounds (const NautilusImage *image); -static ArtIRect image_get_tile_frame (const NautilusImage *image); -static gboolean image_is_smooth (const NautilusImage *image); +static NautilusDimensions image_get_pixbuf_dimensions (const NautilusImage *image); +static ArtIRect image_get_pixbuf_bounds (const NautilusImage *image); +static NautilusDimensions image_get_tile_dimensions (const NautilusImage *image); +static gboolean image_is_smooth (const NautilusImage *image); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusImage, nautilus_image, GTK_TYPE_MISC) @@ -364,24 +364,24 @@ nautilus_image_size_request (GtkWidget *widget, { NautilusImage *image; - ArtIRect pixbuf_frame; - ArtIRect tile_frame; - ArtIRect preferred_frame; - + NautilusDimensions pixbuf_dimensions; + NautilusDimensions tile_dimensions; + NautilusDimensions preferred_dimensions; + g_return_if_fail (NAUTILUS_IS_IMAGE (widget)); g_return_if_fail (requisition != NULL); - + image = NAUTILUS_IMAGE (widget); - pixbuf_frame = image_get_pixbuf_frame (image); - tile_frame = image_get_tile_frame (image); - preferred_frame = nautilus_smooth_widget_get_preferred_frame (widget, - &pixbuf_frame, - &tile_frame, - image->details->tile_width, - image->details->tile_height); - requisition->width = preferred_frame.x1; - requisition->height = preferred_frame.y1; + pixbuf_dimensions = image_get_pixbuf_dimensions (image); + tile_dimensions = image_get_tile_dimensions (image); + preferred_dimensions = nautilus_smooth_widget_get_preferred_dimensions (widget, + &pixbuf_dimensions, + &tile_dimensions, + image->details->tile_width, + image->details->tile_height); + requisition->width = preferred_dimensions.width; + requisition->height = preferred_dimensions.height; } static void @@ -475,8 +475,8 @@ nautilus_image_expose_event (GtkWidget *widget, } /* Clip the dirty area to the screen */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); - screen_dirty_area = nautilus_irect_gdk_window_clip_dirty_area_to_screen (event->window, + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); + screen_dirty_area = nautilus_gdk_window_clip_dirty_area_to_screen (event->window, &dirty_area); /* Nothing to do */ if (art_irect_empty (&screen_dirty_area)) { @@ -515,68 +515,64 @@ nautilus_image_set_is_smooth_signal (GtkWidget *widget, } /* Private NautilusImage methods */ -static ArtIRect -image_get_pixbuf_frame (const NautilusImage *image) +static NautilusDimensions +image_get_pixbuf_dimensions (const NautilusImage *image) { - ArtIRect pixbuf_frame; + NautilusDimensions pixbuf_dimensions; - g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_DIMENSIONS_EMPTY); if (!image->details->pixbuf) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } - pixbuf_frame.x0 = 0; - pixbuf_frame.y0 = 0; - pixbuf_frame.x1 = gdk_pixbuf_get_width (image->details->pixbuf); - pixbuf_frame.y1 = gdk_pixbuf_get_height (image->details->pixbuf); + pixbuf_dimensions.width = gdk_pixbuf_get_width (image->details->pixbuf); + pixbuf_dimensions.height = gdk_pixbuf_get_height (image->details->pixbuf); - return pixbuf_frame; + return pixbuf_dimensions; } static ArtIRect image_get_pixbuf_bounds (const NautilusImage *image) { - ArtIRect pixbuf_frame; + NautilusDimensions pixbuf_dimensions; ArtIRect pixbuf_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY); - pixbuf_frame = image_get_pixbuf_frame (image); + pixbuf_dimensions = image_get_pixbuf_dimensions (image); - if (art_irect_empty (&pixbuf_frame)) { + if (nautilus_dimensions_empty (&pixbuf_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (image)); pixbuf_bounds = nautilus_art_irect_align (&bounds, - pixbuf_frame.x1, - pixbuf_frame.y1, + pixbuf_dimensions.width, + pixbuf_dimensions.height, GTK_MISC (image)->xalign, GTK_MISC (image)->yalign); return pixbuf_bounds; } -static ArtIRect -image_get_tile_frame (const NautilusImage *image) +static NautilusDimensions +image_get_tile_dimensions (const NautilusImage *image) { - ArtIRect tile_frame; + NautilusDimensions tile_dimensions; - g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_DIMENSIONS_EMPTY); if (!image->details->tile_pixbuf) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } + + tile_dimensions.width = gdk_pixbuf_get_width (image->details->tile_pixbuf); + tile_dimensions.height = gdk_pixbuf_get_height (image->details->tile_pixbuf); - tile_frame.x0 = 0; - tile_frame.y0 = 0; - tile_frame.x1 = gdk_pixbuf_get_width (image->details->tile_pixbuf); - tile_frame.y1 = gdk_pixbuf_get_height (image->details->tile_pixbuf); - - return tile_frame; + return tile_dimensions; } gboolean diff --git a/libnautilus-extensions/nautilus-label.c b/libnautilus-extensions/nautilus-label.c index 3629b17e9..520eeee3d 100644 --- a/libnautilus-extensions/nautilus-label.c +++ b/libnautilus-extensions/nautilus-label.c @@ -108,15 +108,14 @@ struct _NautilusLabelDetails guint32 smooth_text_color; guint smooth_drop_shadow_offset; guint32 smooth_drop_shadow_color; - guint smooth_line_wrap_width; + int smooth_line_wrap_width; gboolean adjust_wrap_on_resize; /* Text */ int text_opacity; /* Text lines */ - int *text_line_widths; - int *text_line_heights; + NautilusDimensions *text_line_dimensions; int num_text_lines; int max_text_line_width; int total_text_line_height; @@ -133,46 +132,46 @@ struct _NautilusLabelDetails }; /* GtkObjectClass methods */ -static void nautilus_label_initialize_class (NautilusLabelClass *label_class); -static void nautilus_label_initialize (NautilusLabel *label); -static void nautilus_label_destroy (GtkObject *object); -static void nautilus_label_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_label_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_label_initialize_class (NautilusLabelClass *label_class); +static void nautilus_label_initialize (NautilusLabel *label); +static void nautilus_label_destroy (GtkObject *object); +static void nautilus_label_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_label_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_label_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void nautilus_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static int nautilus_label_expose_event (GtkWidget *widget, - GdkEventExpose *event); +static void nautilus_label_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static void nautilus_label_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static int nautilus_label_expose_event (GtkWidget *widget, + GdkEventExpose *event); /* NautilusLabel signals */ -static void nautilus_label_set_is_smooth_signal (GtkWidget *widget, - gboolean is_smooth); +static void nautilus_label_set_is_smooth_signal (GtkWidget *widget, + gboolean is_smooth); /* Private NautilusLabel things */ -const char * label_peek_text (const NautilusLabel *label); -static void label_line_geometries_recompute (NautilusLabel *label); -static void label_line_geometries_clear (NautilusLabel *label); -static guint label_get_empty_line_height (const NautilusLabel *label); -static guint label_get_total_text_and_line_offset_height (const NautilusLabel *label); -static ArtIRect label_get_text_bounds (const NautilusLabel *label); -static ArtIRect label_get_text_frame (const NautilusLabel *label); -static ArtIRect label_get_tile_frame (const NautilusLabel *label); -static void label_draw_text_to_pixbuf (NautilusLabel *label, - GdkPixbuf *pixbuf, - const ArtIRect *destination_area, - int x, - int y); -static guint label_get_default_line_wrap_width (const NautilusLabel *label); -static void label_solid_cache_pixbuf_clear (NautilusLabel *label); -static gboolean label_can_cache_contents (const NautilusLabel *label); -static gboolean label_is_smooth (const NautilusLabel *label); +const char * label_peek_text (const NautilusLabel *label); +static void label_line_geometries_recompute (NautilusLabel *label); +static void label_line_geometries_clear (NautilusLabel *label); +static guint label_get_empty_line_height (const NautilusLabel *label); +static guint label_get_total_text_and_line_offset_height (const NautilusLabel *label); +static ArtIRect label_get_text_bounds (const NautilusLabel *label); +static NautilusDimensions label_get_text_dimensions (const NautilusLabel *label); +static NautilusDimensions label_get_tile_dimensions (const NautilusLabel *label); +static void label_draw_text_to_pixbuf (NautilusLabel *label, + GdkPixbuf *pixbuf, + const ArtIRect *destination_area, + int x, + int y); +static int label_get_default_line_wrap_width (const NautilusLabel *label); +static void label_solid_cache_pixbuf_clear (NautilusLabel *label); +static gboolean label_can_cache_contents (const NautilusLabel *label); +static gboolean label_is_smooth (const NautilusLabel *label); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabel, nautilus_label, GTK_TYPE_LABEL) @@ -288,7 +287,7 @@ nautilus_label_initialize_class (NautilusLabelClass *label_class) GTK_ARG_READWRITE, ARG_SMOOTH_DROP_SHADOW_COLOR); gtk_object_add_arg_type ("NautilusLabel::smooth_line_wrap_width", - GTK_TYPE_UINT, + GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_SMOOTH_LINE_WRAP_WIDTH); @@ -429,7 +428,7 @@ nautilus_label_set_arg (GtkObject *object, break; case ARG_SMOOTH_LINE_WRAP_WIDTH: - nautilus_label_set_smooth_line_wrap_width (label, GTK_VALUE_UINT (*arg)); + nautilus_label_set_smooth_line_wrap_width (label, GTK_VALUE_INT (*arg)); break; case ARG_ADJUST_WRAP_ON_RESIZE: @@ -524,7 +523,7 @@ nautilus_label_get_arg (GtkObject *object, break; case ARG_SMOOTH_LINE_WRAP_WIDTH: - GTK_VALUE_UINT (*arg) = nautilus_label_get_smooth_line_wrap_width (label); + GTK_VALUE_INT (*arg) = nautilus_label_get_smooth_line_wrap_width (label); break; case ARG_ADJUST_WRAP_ON_RESIZE: @@ -543,10 +542,10 @@ nautilus_label_size_request (GtkWidget *widget, { NautilusLabel *label; - ArtIRect text_frame; - ArtIRect tile_frame; - ArtIRect preferred_frame; - + NautilusDimensions text_dimensions; + NautilusDimensions tile_dimensions; + NautilusDimensions preferred_dimensions; + g_return_if_fail (NAUTILUS_IS_LABEL (widget)); g_return_if_fail (requisition != NULL); @@ -557,16 +556,16 @@ nautilus_label_size_request (GtkWidget *widget, return; } - text_frame = label_get_text_frame (label); - tile_frame = label_get_tile_frame (label); + text_dimensions = label_get_text_dimensions (label); + tile_dimensions = label_get_tile_dimensions (label); - preferred_frame = nautilus_smooth_widget_get_preferred_frame (widget, - &text_frame, - &tile_frame, - label->details->tile_width, - label->details->tile_height); - requisition->width = preferred_frame.x1; - requisition->height = preferred_frame.y1; + preferred_dimensions = nautilus_smooth_widget_get_preferred_dimensions (widget, + &text_dimensions, + &tile_dimensions, + label->details->tile_width, + label->details->tile_height); + requisition->width = preferred_dimensions.width; + requisition->height = preferred_dimensions.height; } static void @@ -584,7 +583,7 @@ nautilus_label_size_allocate (GtkWidget *widget, NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, size_allocate, (widget, allocation)); if (label->details->adjust_wrap_on_resize) { - label->details->smooth_line_wrap_width = allocation->width; + label->details->smooth_line_wrap_width = (int) allocation->width; label_line_geometries_recompute (label); } } @@ -626,13 +625,14 @@ label_composite_pixbuf_callback (GtkWidget *widget, gpointer callback_data) { NautilusLabel *label; - ArtIRect text_frame; + NautilusDimensions text_dimensions; ArtIRect text_bounds; ArtIRect workaround_buffer_area; GdkPixbuf *pixbuf; GdkEventExpose *event; ArtIRect text_dirty_area; ArtIRect dirty_area; + ArtIRect tmp; g_return_if_fail (NAUTILUS_IS_LABEL (widget)); g_return_if_fail (GTK_WIDGET_REALIZED (widget)); @@ -642,27 +642,29 @@ label_composite_pixbuf_callback (GtkWidget *widget, label = NAUTILUS_LABEL (widget); event = (GdkEventExpose *) callback_data; - text_frame = label_get_text_frame (label); + text_dimensions = label_get_text_dimensions (label); text_bounds = label_get_text_bounds (label); - g_return_if_fail (!art_irect_empty (&text_frame)); + g_return_if_fail (!nautilus_dimensions_empty (&text_dimensions)); /* Optimize the case where the background is solid */ if (label_can_cache_contents (label)) { if (label->details->solid_cache_pixbuf == NULL) { + ArtIRect tmp; label->details->solid_cache_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, - text_frame.x1, - text_frame.y1); + text_dimensions.width, + text_dimensions.height); nautilus_gdk_pixbuf_fill_rectangle_with_color (label->details->solid_cache_pixbuf, NULL, label->details->solid_background_color); + tmp = nautilus_art_irect_assign_dimensions (0, 0, &text_dimensions); label_draw_text_to_pixbuf (label, label->details->solid_cache_pixbuf, - &text_frame, + &tmp, 0, 0); } @@ -681,7 +683,7 @@ label_composite_pixbuf_callback (GtkWidget *widget, * content dirty rectangle. We compute it now to workaround * bug 2784. See fixme below. */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); art_irect_intersect (&text_dirty_area, &text_bounds, &dirty_area); /* FIXME bugzilla.eazel.com 2784: @@ -691,7 +693,7 @@ label_composite_pixbuf_callback (GtkWidget *widget, * that prevents clipping from happening when drawing smooth * text. */ - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, text_frame.x1, text_frame.y1); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, text_dimensions.width, text_dimensions.height); /* Copy the dirty bits out of the destination to our temporary buffer */ workaround_buffer_area.x0 = text_dirty_area.x0 - text_bounds.x0; @@ -709,9 +711,10 @@ label_composite_pixbuf_callback (GtkWidget *widget, * bug 2784 is fixed, we can simply pass this function a * clip rectangle and lose the temporary buffer code above */ + tmp = nautilus_art_irect_assign_dimensions (0, 0, &text_dimensions); label_draw_text_to_pixbuf (label, pixbuf, - &text_frame, + &tmp, 0, 0); @@ -758,7 +761,7 @@ nautilus_label_expose_event (GtkWidget *widget, * expose event so that we feed the exact exposure area * to GtkLabel's expose_event. */ - widget_bounds = nautilus_irect_gtk_widget_get_bounds (widget); + widget_bounds = nautilus_gtk_widget_get_bounds (widget); smooth_text_bounds = label_get_text_bounds (label); tile_bounds = nautilus_smooth_widget_get_tile_bounds (widget, label->details->tile_pixbuf, @@ -771,8 +774,8 @@ nautilus_label_expose_event (GtkWidget *widget, } /* Clip the dirty area to the screen */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); - screen_dirty_area = nautilus_irect_gdk_window_clip_dirty_area_to_screen (event->window, + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); + screen_dirty_area = nautilus_gdk_window_clip_dirty_area_to_screen (event->window, &dirty_area); /* Make sure the area is screen visible before painting */ @@ -816,17 +819,17 @@ label_draw_text_to_pixbuf (NautilusLabel *label, int x, int y) { - ArtIRect pixbuf_frame; + NautilusDimensions pixbuf_dimensions; g_return_if_fail (NAUTILUS_IS_LABEL (label)); g_return_if_fail (destination_area != NULL); g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); g_return_if_fail (!art_irect_empty (destination_area)); - pixbuf_frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + pixbuf_dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); - g_return_if_fail (pixbuf_frame.x1 >= (destination_area->x1 - destination_area->x0)); - g_return_if_fail (pixbuf_frame.y1 >= (destination_area->y1 - destination_area->y0)); + g_return_if_fail (pixbuf_dimensions.width >= (destination_area->x1 - destination_area->x0)); + g_return_if_fail (pixbuf_dimensions.height >= (destination_area->y1 - destination_area->y0)); /* Line wrapping */ if (nautilus_label_get_wrap (label)) { @@ -863,14 +866,12 @@ label_draw_text_to_pixbuf (NautilusLabel *label, label->details->smooth_font, pixbuf, x + label->details->smooth_drop_shadow_offset, - x + label->details->smooth_drop_shadow_offset, + y + label->details->smooth_drop_shadow_offset, destination_area, label->details->smooth_font_size, - label->details->smooth_font_size, label_peek_text (label), label->details->num_text_lines, - label->details->text_line_widths, - label->details->text_line_heights, + label->details->text_line_dimensions, nautilus_label_get_text_justify (label), LINE_OFFSET, label_get_empty_line_height (label), @@ -885,11 +886,9 @@ label_draw_text_to_pixbuf (NautilusLabel *label, y, destination_area, label->details->smooth_font_size, - label->details->smooth_font_size, label_peek_text (label), label->details->num_text_lines, - label->details->text_line_widths, - label->details->text_line_heights, + label->details->text_line_dimensions, nautilus_label_get_text_justify (label), LINE_OFFSET, label_get_empty_line_height (label), @@ -898,66 +897,58 @@ label_draw_text_to_pixbuf (NautilusLabel *label, } } -static guint +static int label_get_default_line_wrap_width (const NautilusLabel *label) { - guint width; - guint height; - g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0); - nautilus_scalable_font_measure_text (label->details->smooth_font, - label->details->smooth_font_size, - label->details->smooth_font_size, - DEFAULT_LINE_WRAP_WIDTH_TEXT, - strlen (DEFAULT_LINE_WRAP_WIDTH_TEXT), - &width, - &height); - - return width; + return nautilus_scalable_font_text_width (label->details->smooth_font, + label->details->smooth_font_size, + DEFAULT_LINE_WRAP_WIDTH_TEXT, + strlen (DEFAULT_LINE_WRAP_WIDTH_TEXT)); } -static ArtIRect -label_get_text_frame (const NautilusLabel *label) +static NautilusDimensions +label_get_text_dimensions (const NautilusLabel *label) { - ArtIRect text_frame; + NautilusDimensions text_dimensions; - g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_DIMENSIONS_EMPTY); - text_frame = NAUTILUS_ART_IRECT_EMPTY; + text_dimensions = NAUTILUS_DIMENSIONS_EMPTY; if (label->details->num_text_lines > 0) { - text_frame.x1 = + text_dimensions.width = label->details->max_text_line_width + label->details->smooth_drop_shadow_offset; - text_frame.y1 = label_get_total_text_and_line_offset_height (label) + text_dimensions.height = label_get_total_text_and_line_offset_height (label) + label->details->smooth_drop_shadow_offset; } - - return text_frame; + + return text_dimensions; } static ArtIRect label_get_text_bounds (const NautilusLabel *label) { - ArtIRect text_frame; + NautilusDimensions text_dimensions; ArtIRect text_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_ART_IRECT_EMPTY); - text_frame = label_get_text_frame (label); + text_dimensions = label_get_text_dimensions (label); - if (art_irect_empty (&text_frame)) { + if (nautilus_dimensions_empty (&text_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (label)); - + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (label)); + text_bounds = nautilus_art_irect_align (&bounds, - text_frame.x1, - text_frame.y1, + text_dimensions.width, + text_dimensions.height, GTK_MISC (label)->xalign, GTK_MISC (label)->yalign); @@ -965,23 +956,21 @@ label_get_text_bounds (const NautilusLabel *label) return text_bounds; } -static ArtIRect -label_get_tile_frame (const NautilusLabel *label) +static NautilusDimensions +label_get_tile_dimensions (const NautilusLabel *label) { - ArtIRect tile_frame; + NautilusDimensions tile_dimensions; - g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_DIMENSIONS_EMPTY); if (!label->details->tile_pixbuf) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } + + tile_dimensions.width = gdk_pixbuf_get_width (label->details->tile_pixbuf); + tile_dimensions.height = gdk_pixbuf_get_height (label->details->tile_pixbuf); - tile_frame.x0 = 0; - tile_frame.y0 = 0; - tile_frame.x1 = gdk_pixbuf_get_width (label->details->tile_pixbuf); - tile_frame.y1 = gdk_pixbuf_get_height (label->details->tile_pixbuf); - - return tile_frame; + return tile_dimensions; } static void @@ -1041,10 +1030,8 @@ label_line_geometries_clear (NautilusLabel *label) { g_return_if_fail (NAUTILUS_IS_LABEL (label)); - g_free (label->details->text_line_widths); - g_free (label->details->text_line_heights); - label->details->text_line_widths = NULL; - label->details->text_line_heights = NULL; + g_free (label->details->text_line_dimensions); + label->details->text_line_dimensions = NULL; if (label->details->text_layouts != NULL) { int i; @@ -1110,26 +1097,22 @@ label_line_geometries_recompute (NautilusLabel *label) label->details->total_text_line_height += label->details->text_layouts[i]->height; - if (label->details->text_layouts[i]->width > label->details->max_text_line_width) { - label->details->max_text_line_width = label->details->text_layouts[i]->width; - } + label->details->max_text_line_width = MAX (label->details->max_text_line_width, + label->details->text_layouts[i]->width); } g_strfreev (pieces); } /* No line wrapping */ else { - label->details->text_line_widths = g_new (guint, label->details->num_text_lines); - label->details->text_line_heights = g_new (guint, label->details->num_text_lines); + label->details->text_line_dimensions = g_new (NautilusDimensions, label->details->num_text_lines); nautilus_scalable_font_measure_text_lines (label->details->smooth_font, label->details->smooth_font_size, - label->details->smooth_font_size, text, label->details->num_text_lines, label_get_empty_line_height (label), - label->details->text_line_widths, - label->details->text_line_heights, + label->details->text_line_dimensions, &label->details->max_text_line_width, &label->details->total_text_line_height); } @@ -1567,7 +1550,7 @@ nautilus_label_get_solid_background_color (const NautilusLabel *label) */ void nautilus_label_set_smooth_line_wrap_width (NautilusLabel *label, - guint line_wrap_width) + int line_wrap_width) { g_return_if_fail (NAUTILUS_IS_LABEL (label)); @@ -1590,7 +1573,7 @@ nautilus_label_set_smooth_line_wrap_width (NautilusLabel *label, * Return value: A boolean value indicating whether the label * is currently line wrapping text. */ -guint +int nautilus_label_get_smooth_line_wrap_width (const NautilusLabel *label) { g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE); diff --git a/libnautilus-extensions/nautilus-label.h b/libnautilus-extensions/nautilus-label.h index af6e4f367..b7d3cda15 100644 --- a/libnautilus-extensions/nautilus-label.h +++ b/libnautilus-extensions/nautilus-label.h @@ -88,8 +88,8 @@ void nautilus_label_set_smooth_drop_shadow_color (Naut guint32 color); guint32 nautilus_label_get_smooth_drop_shadow_color (const NautilusLabel *label); void nautilus_label_set_smooth_line_wrap_width (NautilusLabel *label, - guint line_wrap_width); -guint nautilus_label_get_smooth_line_wrap_width (const NautilusLabel *label); + int line_wrap_width); +int nautilus_label_get_smooth_line_wrap_width (const NautilusLabel *label); void nautilus_label_set_text (NautilusLabel *label, const char *text); char* nautilus_label_get_text (const NautilusLabel *label); diff --git a/libnautilus-extensions/nautilus-labeled-image.c b/libnautilus-extensions/nautilus-labeled-image.c index c53d59e4d..6aa2dea22 100644 --- a/libnautilus-extensions/nautilus-labeled-image.c +++ b/libnautilus-extensions/nautilus-labeled-image.c @@ -78,45 +78,45 @@ struct _NautilusLabeledImageDetails }; /* GtkObjectClass methods */ -static void nautilus_labeled_image_initialize_class (NautilusLabeledImageClass *labeled_image_class); -static void nautilus_labeled_image_initialize (NautilusLabeledImage *image); -static void nautilus_labeled_image_destroy (GtkObject *object); -static void nautilus_labeled_image_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_labeled_image_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_labeled_image_initialize_class (NautilusLabeledImageClass *labeled_image_class); +static void nautilus_labeled_image_initialize (NautilusLabeledImage *image); +static void nautilus_labeled_image_destroy (GtkObject *object); +static void nautilus_labeled_image_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_labeled_image_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_labeled_image_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int nautilus_labeled_image_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void nautilus_labeled_image_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void nautilus_labeled_image_map (GtkWidget *widget); -static void nautilus_labeled_image_unmap (GtkWidget *widget); +static void nautilus_labeled_image_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static int nautilus_labeled_image_expose_event (GtkWidget *widget, + GdkEventExpose *event); +static void nautilus_labeled_image_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static void nautilus_labeled_image_map (GtkWidget *widget); +static void nautilus_labeled_image_unmap (GtkWidget *widget); /* GtkContainerClass methods */ -static void nautilus_labeled_image_add (GtkContainer *container, - GtkWidget *widget); -static void nautilus_labeled_image_remove (GtkContainer *container, - GtkWidget *widget); -static void nautilus_labeled_image_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); +static void nautilus_labeled_image_add (GtkContainer *container, + GtkWidget *widget); +static void nautilus_labeled_image_remove (GtkContainer *container, + GtkWidget *widget); +static void nautilus_labeled_image_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data); /* Private NautilusLabeledImage methods */ -static ArtIRect labeled_image_get_image_frame (const NautilusLabeledImage *labeled_image); -static ArtIRect labeled_image_get_label_frame (const NautilusLabeledImage *labeled_image); -static void labeled_image_ensure_label (NautilusLabeledImage *labeled_image); -static void labeled_image_ensure_image (NautilusLabeledImage *labeled_image); -static ArtIRect labeled_image_get_content_bounds (const NautilusLabeledImage *labeled_image); -static ArtIRect labeled_image_get_content_frame (const NautilusLabeledImage *labeled_image); -static void labeled_image_update_alignments (NautilusLabeledImage *labeled_image); -static gboolean labeled_image_show_label (const NautilusLabeledImage *labeled_image); -static gboolean labeled_image_show_image (const NautilusLabeledImage *labeled_image); +static NautilusDimensions labeled_image_get_image_dimensions (const NautilusLabeledImage *labeled_image); +static NautilusDimensions labeled_image_get_label_dimensions (const NautilusLabeledImage *labeled_image); +static void labeled_image_ensure_label (NautilusLabeledImage *labeled_image); +static void labeled_image_ensure_image (NautilusLabeledImage *labeled_image); +static ArtIRect labeled_image_get_content_bounds (const NautilusLabeledImage *labeled_image); +static NautilusDimensions labeled_image_get_content_dimensions (const NautilusLabeledImage *labeled_image); +static void labeled_image_update_alignments (NautilusLabeledImage *labeled_image); +static gboolean labeled_image_show_label (const NautilusLabeledImage *labeled_image); +static gboolean labeled_image_show_image (const NautilusLabeledImage *labeled_image); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabeledImage, nautilus_labeled_image, GTK_TYPE_CONTAINER) @@ -354,21 +354,21 @@ nautilus_labeled_image_size_request (GtkWidget *widget, GtkRequisition *requisition) { NautilusLabeledImage *labeled_image; - ArtIRect content_frame; + NautilusDimensions content_dimensions; g_return_if_fail (NAUTILUS_IS_LABELED_IMAGE (widget)); g_return_if_fail (requisition != NULL); labeled_image = NAUTILUS_LABELED_IMAGE (widget); - content_frame = labeled_image_get_content_frame (labeled_image); + content_dimensions = labeled_image_get_content_dimensions (labeled_image); requisition->width = - MAX (1, content_frame.x1) + + MAX (1, content_dimensions.width) + 2 * labeled_image->details->x_padding; requisition->height = - MAX (1, content_frame.y1) + + MAX (1, content_dimensions.height) + 2 * labeled_image->details->y_padding; } @@ -583,68 +583,64 @@ nautilus_labeled_image_forall (GtkContainer *container, } /* Private NautilusLabeledImage methods */ -static ArtIRect -labeled_image_get_image_frame (const NautilusLabeledImage *labeled_image) +static NautilusDimensions +labeled_image_get_image_dimensions (const NautilusLabeledImage *labeled_image) { - ArtIRect image_frame; + NautilusDimensions image_dimensions; GtkRequisition image_requisition; - g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_DIMENSIONS_EMPTY); if (!labeled_image_show_image (labeled_image)) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } - + gtk_widget_size_request (labeled_image->details->image, &image_requisition); - image_frame.x0 = 0; - image_frame.y0 = 0; - image_frame.x1 = (int) image_requisition.width; - image_frame.y1 = (int) image_requisition.height; + image_dimensions.width = (int) image_requisition.width; + image_dimensions.height = (int) image_requisition.height; - return image_frame; + return image_dimensions; } -static ArtIRect -labeled_image_get_label_frame (const NautilusLabeledImage *labeled_image) +static NautilusDimensions +labeled_image_get_label_dimensions (const NautilusLabeledImage *labeled_image) { - ArtIRect label_frame; + NautilusDimensions label_dimensions; GtkRequisition label_requisition; - g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_DIMENSIONS_EMPTY); if (!labeled_image_show_label (labeled_image)) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } - + gtk_widget_size_request (labeled_image->details->label, &label_requisition); - label_frame.x0 = 0; - label_frame.y0 = 0; - label_frame.x1 = (int) label_requisition.width; - label_frame.y1 = (int) label_requisition.height; + label_dimensions.width = (int) label_requisition.width; + label_dimensions.height = (int) label_requisition.height; - return label_frame; + return label_dimensions; } static ArtIRect labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) { ArtIRect image_bounds; - ArtIRect image_frame; + NautilusDimensions image_dimensions; ArtIRect content_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); - image_frame = labeled_image_get_image_frame (labeled_image); + image_dimensions = labeled_image_get_image_dimensions (labeled_image); - if (art_irect_empty (&image_frame)) { + if (nautilus_dimensions_empty (&image_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } content_bounds = labeled_image_get_content_bounds (labeled_image); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); if (!labeled_image_show_label (labeled_image)) { image_bounds = bounds; @@ -652,7 +648,7 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) switch (labeled_image->details->label_position) { case GTK_POS_LEFT: image_bounds.y0 = bounds.y0; - image_bounds.x0 = content_bounds.x1 - image_frame.x1; + image_bounds.x0 = content_bounds.x1 - image_dimensions.width; image_bounds.y1 = bounds.y1; image_bounds.x1 = bounds.x1; break; @@ -661,12 +657,12 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) image_bounds.y0 = bounds.y0; image_bounds.x0 = bounds.x0; image_bounds.y1 = bounds.y1; - image_bounds.x1 = content_bounds.x0 + image_frame.x1; + image_bounds.x1 = content_bounds.x0 + image_dimensions.width; break; case GTK_POS_TOP: image_bounds.x0 = bounds.x0; - image_bounds.y0 = content_bounds.y1 - image_frame.y1; + image_bounds.y0 = content_bounds.y1 - image_dimensions.height; image_bounds.x1 = bounds.x1; image_bounds.y1 = bounds.y1; break; @@ -675,7 +671,7 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) image_bounds.x0 = bounds.x0; image_bounds.y0 = bounds.y0; image_bounds.x1 = bounds.x1; - image_bounds.y1 = content_bounds.y0 + image_frame.y1; + image_bounds.y1 = content_bounds.y0 + image_dimensions.height; break; } } @@ -686,7 +682,7 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) ArtIRect nautilus_labeled_image_get_image_bounds (const NautilusLabeledImage *labeled_image) { - ArtIRect image_frame; + NautilusDimensions image_dimensions; ArtIRect image_bounds; ArtIRect content_bounds; @@ -696,9 +692,9 @@ nautilus_labeled_image_get_image_bounds (const NautilusLabeledImage *labeled_ima return labeled_image_get_image_bounds_fill (labeled_image); } - image_frame = labeled_image_get_image_frame (labeled_image); + image_dimensions = labeled_image_get_image_dimensions (labeled_image); - if (art_irect_empty (&image_frame)) { + if (nautilus_dimensions_empty (&image_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } @@ -707,44 +703,44 @@ nautilus_labeled_image_get_image_bounds (const NautilusLabeledImage *labeled_ima if (!labeled_image_show_label (labeled_image)) { image_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - image_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - image_dimensions.width) / 2; image_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - image_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - image_dimensions.height) / 2; } else { switch (labeled_image->details->label_position) { case GTK_POS_LEFT: - image_bounds.x0 = content_bounds.x1 - image_frame.x1; + image_bounds.x0 = content_bounds.x1 - image_dimensions.width; image_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - image_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - image_dimensions.height) / 2; break; case GTK_POS_RIGHT: image_bounds.x0 = content_bounds.x0; image_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - image_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - image_dimensions.height) / 2; break; case GTK_POS_TOP: image_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - image_frame.x1) / 2; - image_bounds.y0 = content_bounds.y1 - image_frame.y1; + (nautilus_art_irect_get_width (&content_bounds) - image_dimensions.width) / 2; + image_bounds.y0 = content_bounds.y1 - image_dimensions.height; break; case GTK_POS_BOTTOM: image_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - image_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - image_dimensions.width) / 2; image_bounds.y0 = content_bounds.y0; break; } } - image_bounds.x1 = image_bounds.x0 + image_frame.x1; - image_bounds.y1 = image_bounds.y0 + image_frame.y1; + image_bounds.x1 = image_bounds.x0 + image_dimensions.width; + image_bounds.y1 = image_bounds.y0 + image_dimensions.height; return image_bounds; } @@ -753,20 +749,20 @@ static ArtIRect labeled_image_get_label_bounds_fill (const NautilusLabeledImage *labeled_image) { ArtIRect label_bounds; - ArtIRect label_frame; + NautilusDimensions label_dimensions; ArtIRect content_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); - label_frame = labeled_image_get_label_frame (labeled_image); + label_dimensions = labeled_image_get_label_dimensions (labeled_image); - if (art_irect_empty (&label_frame)) { + if (nautilus_dimensions_empty (&label_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } content_bounds = labeled_image_get_content_bounds (labeled_image); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); /* Only the label is shown */ if (!labeled_image_show_image (labeled_image)) { @@ -778,12 +774,12 @@ labeled_image_get_label_bounds_fill (const NautilusLabeledImage *labeled_image) label_bounds.y0 = bounds.y0; label_bounds.x0 = bounds.x0; label_bounds.y1 = bounds.y1; - label_bounds.x1 = content_bounds.x0 + label_frame.x1; + label_bounds.x1 = content_bounds.x0 + label_dimensions.width; break; case GTK_POS_RIGHT: label_bounds.y0 = bounds.y0; - label_bounds.x0 = content_bounds.x1 - label_frame.x1; + label_bounds.x0 = content_bounds.x1 - label_dimensions.width; label_bounds.y1 = bounds.y1; label_bounds.x1 = bounds.x1; break; @@ -792,12 +788,12 @@ labeled_image_get_label_bounds_fill (const NautilusLabeledImage *labeled_image) label_bounds.x0 = bounds.x0; label_bounds.y0 = bounds.y0; label_bounds.x1 = bounds.x1; - label_bounds.y1 = content_bounds.y0 + label_frame.y1; + label_bounds.y1 = content_bounds.y0 + label_dimensions.height; break; case GTK_POS_BOTTOM: label_bounds.x0 = bounds.x0; - label_bounds.y0 = content_bounds.y1 - label_frame.y1; + label_bounds.y0 = content_bounds.y1 - label_dimensions.height; label_bounds.x1 = bounds.x1; label_bounds.y1 = bounds.y1; break; @@ -811,7 +807,7 @@ ArtIRect nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_image) { ArtIRect label_bounds; - ArtIRect label_frame; + NautilusDimensions label_dimensions; ArtIRect content_bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); @@ -820,9 +816,9 @@ nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_ima return labeled_image_get_label_bounds_fill (labeled_image); } - label_frame = labeled_image_get_label_frame (labeled_image); + label_dimensions = labeled_image_get_label_dimensions (labeled_image); - if (art_irect_empty (&label_frame)) { + if (nautilus_dimensions_empty (&label_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } @@ -832,10 +828,10 @@ nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_ima if (!labeled_image_show_image (labeled_image)) { label_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - label_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - label_dimensions.width) / 2; label_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - label_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - label_dimensions.height) / 2; /* Both label and image are shown */ } else { switch (labeled_image->details->label_position) { @@ -843,34 +839,34 @@ nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_ima label_bounds.x0 = content_bounds.x0; label_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - label_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - label_dimensions.height) / 2; break; case GTK_POS_RIGHT: - label_bounds.x0 = content_bounds.x1 - label_frame.x1; + label_bounds.x0 = content_bounds.x1 - label_dimensions.width; label_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - label_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - label_dimensions.height) / 2; break; case GTK_POS_TOP: label_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - label_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - label_dimensions.width) / 2; label_bounds.y0 = content_bounds.y0; break; case GTK_POS_BOTTOM: label_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - label_frame.x1) / 2; - label_bounds.y0 = content_bounds.y1 - label_frame.y1; + (nautilus_art_irect_get_width (&content_bounds) - label_dimensions.width) / 2; + label_bounds.y0 = content_bounds.y1 - label_dimensions.height; break; } } - label_bounds.x1 = label_bounds.x0 + label_frame.x1; - label_bounds.y1 = label_bounds.y0 + label_frame.y1; + label_bounds.x1 = label_bounds.x0 + label_dimensions.width; + label_bounds.y1 = label_bounds.y0 + label_dimensions.height; return label_bounds; } @@ -969,64 +965,67 @@ labeled_image_update_alignments (NautilusLabeledImage *labeled_image) } } -static ArtIRect -labeled_image_get_content_frame (const NautilusLabeledImage *labeled_image) +static NautilusDimensions +labeled_image_get_content_dimensions (const NautilusLabeledImage *labeled_image) { - ArtIRect image_frame; - ArtIRect label_frame; - ArtIRect content_frame; + NautilusDimensions image_dimensions; + NautilusDimensions label_dimensions; + NautilusDimensions content_dimensions; - g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_DIMENSIONS_EMPTY); - image_frame = labeled_image_get_image_frame (labeled_image); - label_frame = labeled_image_get_label_frame (labeled_image); + image_dimensions = labeled_image_get_image_dimensions (labeled_image); + label_dimensions = labeled_image_get_label_dimensions (labeled_image); - content_frame = NAUTILUS_ART_IRECT_EMPTY; + content_dimensions = NAUTILUS_DIMENSIONS_EMPTY; /* Both shown */ - if (!art_irect_empty (&image_frame) && !art_irect_empty (&label_frame)) { - content_frame.x1 = image_frame.x1 + labeled_image->details->spacing + label_frame.x1; + if (!nautilus_dimensions_empty (&image_dimensions) && !nautilus_dimensions_empty (&label_dimensions)) { + content_dimensions.width = + image_dimensions.width + labeled_image->details->spacing + label_dimensions.width; switch (labeled_image->details->label_position) { case GTK_POS_LEFT: case GTK_POS_RIGHT: - content_frame.x1 = image_frame.x1 + labeled_image->details->spacing + label_frame.x1; - content_frame.y1 = MAX (image_frame.y1, label_frame.y1); + content_dimensions.width = + image_dimensions.width + labeled_image->details->spacing + label_dimensions.width; + content_dimensions.height = MAX (image_dimensions.height, label_dimensions.height); break; case GTK_POS_TOP: case GTK_POS_BOTTOM: - content_frame.x1 = MAX (image_frame.x1, label_frame.x1); - content_frame.y1 = image_frame.y1 + labeled_image->details->spacing + label_frame.y1; + content_dimensions.width = MAX (image_dimensions.width, label_dimensions.width); + content_dimensions.height = + image_dimensions.height + labeled_image->details->spacing + label_dimensions.height; break; } /* Only image shown */ - } else if (!art_irect_empty (&image_frame)) { - content_frame.x1 = image_frame.x1; - content_frame.y1 = image_frame.y1; + } else if (!nautilus_dimensions_empty (&image_dimensions)) { + content_dimensions.width = image_dimensions.width; + content_dimensions.height = image_dimensions.height; /* Only label shown */ } else { - content_frame.x1 = label_frame.x1; - content_frame.y1 = label_frame.y1; + content_dimensions.width = label_dimensions.width; + content_dimensions.height = label_dimensions.height; } - return content_frame; + return content_dimensions; } static ArtIRect labeled_image_get_content_bounds (const NautilusLabeledImage *labeled_image) { - ArtIRect content_frame; + NautilusDimensions content_dimensions; ArtIRect content_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); - content_frame = labeled_image_get_content_frame (labeled_image); + content_dimensions = labeled_image_get_content_dimensions (labeled_image); content_bounds = nautilus_art_irect_align (&bounds, - content_frame.x1, - content_frame.y1, + content_dimensions.width, + content_dimensions.height, labeled_image->details->x_alignment, labeled_image->details->y_alignment); @@ -1647,7 +1646,7 @@ button_leave_callback (GtkWidget *widget, const int fudge = 4; ArtIRect bounds; - bounds = nautilus_irect_gtk_widget_get_bounds (widget); + bounds = nautilus_gtk_widget_get_bounds (widget); bounds.x0 -= fudge; bounds.y0 -= fudge; diff --git a/libnautilus-extensions/nautilus-lib-self-check-functions.h b/libnautilus-extensions/nautilus-lib-self-check-functions.h index 9e711a4c7..f1bdf9ea1 100644 --- a/libnautilus-extensions/nautilus-lib-self-check-functions.h +++ b/libnautilus-extensions/nautilus-lib-self-check-functions.h @@ -45,6 +45,8 @@ void nautilus_run_lib_self_checks (void); macro (nautilus_self_check_preferences) \ macro (nautilus_self_check_scalable_font) \ macro (nautilus_self_check_string_map) \ + macro (nautilus_self_check_art_extensions) \ + macro (nautilus_self_check_gdk_pixbuf_extensions) \ macro (nautilus_self_check_glib_extensions) \ macro (nautilus_self_check_gdk_extensions) \ macro (nautilus_self_check_gdk_font_extensions) \ diff --git a/libnautilus-extensions/nautilus-region.c b/libnautilus-extensions/nautilus-region.c index 2ab4da988..0ff4f044b 100644 --- a/libnautilus-extensions/nautilus-region.c +++ b/libnautilus-extensions/nautilus-region.c @@ -68,7 +68,7 @@ gdk_region_new_from_irect (const ArtIRect *art_rect) g_return_val_if_fail (art_rect != NULL, NULL); - gdk_rect = nautilus_gdk_rectangle_assign_irect (art_rect); + gdk_rect = nautilus_art_irect_to_gdk_rectangle (art_rect); empty_region = gdk_region_new (); region = gdk_region_union_with_rect (empty_region, &gdk_rect); gdk_region_destroy (empty_region); diff --git a/libnautilus-extensions/nautilus-scalable-font.c b/libnautilus-extensions/nautilus-scalable-font.c index 7780dfe4a..b20fefbbc 100644 --- a/libnautilus-extensions/nautilus-scalable-font.c +++ b/libnautilus-extensions/nautilus-scalable-font.c @@ -651,33 +651,25 @@ nautilus_scalable_font_make_bold (NautilusScalableFont *font) return bold_font; } -void -nautilus_scalable_font_measure_text (const NautilusScalableFont *font, - int font_width, - int font_height, +NautilusDimensions +nautilus_scalable_font_measure_text (const NautilusScalableFont *font, + int font_size, const char *text, - guint text_length, - int *text_width_out, - int *text_height_out) + guint text_length) { + NautilusDimensions dimensions; double affine[6]; int glyph_xy[2]; - unsigned int dimensions[2]; - - g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); - g_return_if_fail (text_width_out != NULL); - g_return_if_fail (text_height_out != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + unsigned int tmp[2]; - *text_width_out = 0; - *text_height_out = 0; + g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (font_size > 0, NAUTILUS_DIMENSIONS_EMPTY); if (text == NULL || text[0] == '\0' || text_length == 0) { - return; + return NAUTILUS_DIMENSIONS_EMPTY; } - g_return_if_fail (text_length <= strlen (text)); + g_return_val_if_fail (text_length <= strlen (text), NAUTILUS_DIMENSIONS_EMPTY); art_affine_identity (affine); @@ -685,29 +677,28 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font, font->detail->font_handle, text, text_length, - font_width, - font_height, + font_size, + font_size, affine, glyph_xy, - dimensions); + tmp); + + dimensions.width = tmp[0]; + dimensions.height = tmp[1]; - *text_width_out = dimensions[0]; - *text_height_out = dimensions[1]; + return dimensions; } int nautilus_scalable_font_text_width (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint text_length) { - int text_width = 0; - int text_height = 0; + NautilusDimensions dimensions; g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0); - g_return_val_if_fail (font_width > 0, 0); - g_return_val_if_fail (font_height > 0, 0); + g_return_val_if_fail (font_size > 0, 0); if (text == NULL || text[0] == '\0' || text_length == 0) { return 0; @@ -715,15 +706,9 @@ nautilus_scalable_font_text_width (const NautilusScalableFont *font, g_return_val_if_fail (text_length <= strlen (text), 0); - nautilus_scalable_font_measure_text (font, - font_width, - font_height, - text, - text_length, - &text_width, - &text_height); + dimensions = nautilus_scalable_font_measure_text (font, font_size, text, text_length); - return text_width; + return dimensions.width; } void @@ -732,8 +717,7 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint text_length, guint32 color, @@ -747,8 +731,7 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); g_return_if_fail (destination_pixbuf != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -770,8 +753,8 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, font->detail->font_handle, text, text_length, - font_width, - font_height, + font_size, + font_size, affine, glyph_xy); g_assert (glyph != NULL); @@ -846,17 +829,15 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, } rsvg_ft_glyph_unref (glyph); - } +} void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, double empty_line_height, - int text_line_widths[], - int text_line_heights[], + NautilusDimensions text_line_dimensions[], int *max_width_out, int *total_height_out) { @@ -864,11 +845,9 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, const char *line; g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (text != NULL); - g_return_if_fail (text_line_widths != NULL); - g_return_if_fail (text_line_heights != NULL); + g_return_if_fail (text_line_dimensions != NULL); g_return_if_fail (num_text_lines > 0); g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1)); @@ -904,17 +883,14 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, /* Deal with empty lines */ if (length == 0) { - text_line_widths[i] = 0; - text_line_heights[i] = empty_line_height; + text_line_dimensions[i].width = 0; + text_line_dimensions[i].height = empty_line_height; } else { - nautilus_scalable_font_measure_text (font, - font_width, - font_height, - line, - length, - &text_line_widths[i], - &text_line_heights[i]); + text_line_dimensions[i] = nautilus_scalable_font_measure_text (font, + font_size, + line, + length); } if (next_new_line != NULL) { @@ -926,12 +902,12 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, /* Keep track of total height */ if (total_height_out != NULL) { - *total_height_out += text_line_heights[i]; + *total_height_out += text_line_dimensions[i].height; } /* Keep track of max width */ - if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) { - *max_width_out = text_line_widths[i]; + if (max_width_out != NULL) { + *max_width_out = MAX (*max_width_out, text_line_dimensions[i].width); } } } @@ -942,12 +918,10 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, - const int *text_line_widths, - const int *text_line_heights, + const NautilusDimensions *text_line_dimensions, GtkJustification justification, int line_offset, double empty_line_height, @@ -962,15 +936,13 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); g_return_if_fail (destination_pixbuf != NULL); g_return_if_fail (clip_area != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL); g_return_if_fail (clip_area->x1 > clip_area->x0); g_return_if_fail (clip_area->y1 > clip_area->y0); g_return_if_fail (num_text_lines > 0); g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1)); - g_return_if_fail (text_line_widths != NULL); - g_return_if_fail (text_line_widths != NULL); + g_return_if_fail (text_line_dimensions != NULL); g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -1001,7 +973,7 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo /* Deal with empty lines */ if (length == 0) { - y += (line_offset + text_line_heights[i]); + y += (line_offset + text_line_dimensions[i].height); } else { int text_x; @@ -1014,16 +986,16 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo case GTK_JUSTIFY_CENTER: case GTK_JUSTIFY_FILL: - if (text_line_widths[i] <= available_width) { - text_x = x + ((available_width - text_line_widths[i]) / 2); + if (text_line_dimensions[i].width <= available_width) { + text_x = x + ((available_width - text_line_dimensions[i].width) / 2); } else { - text_x = x - ((text_line_widths[i] - available_width) / 2); + text_x = x - ((text_line_dimensions[i].width - available_width) / 2); } break; case GTK_JUSTIFY_RIGHT: - text_x = x + available_width - text_line_widths[i]; + text_x = x + available_width - text_line_dimensions[i].width; break; default: @@ -1038,14 +1010,13 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo text_x, text_y, clip_area, - font_width, - font_height, + font_size, line, length, color, opacity); - y += (line_offset + text_line_heights[i]); + y += (line_offset + text_line_dimensions[i].height); } if (next_new_line != NULL) { @@ -1063,8 +1034,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, GtkJustification justification, int line_offset, @@ -1073,14 +1043,12 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, int opacity) { guint num_text_lines; - int *text_line_widths; - int *text_line_heights; + NautilusDimensions *text_line_dimensions; g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); g_return_if_fail (destination_pixbuf != NULL); g_return_if_fail (clip_area != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL); g_return_if_fail (clip_area->x1 > clip_area->x0); g_return_if_fail (clip_area->y1 > clip_area->y0); @@ -1097,17 +1065,14 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, */ num_text_lines = nautilus_str_count_characters (text, '\n') + 1; - text_line_widths = g_new (int, num_text_lines); - text_line_heights = g_new (int, num_text_lines); + text_line_dimensions = g_new (NautilusDimensions, num_text_lines); nautilus_scalable_font_measure_text_lines (font, - font_width, - font_height, + font_size, text, num_text_lines, empty_line_height, - text_line_widths, - text_line_heights, + text_line_dimensions, NULL, NULL); @@ -1116,20 +1081,17 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, x, y, clip_area, - font_width, - font_height, + font_size, text, num_text_lines, - text_line_widths, - text_line_heights, + text_line_dimensions, justification, line_offset, empty_line_height, color, opacity); - g_free (text_line_widths); - g_free (text_line_heights); + g_free (text_line_dimensions); } /** @@ -1170,20 +1132,16 @@ nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *fo g_assert (longest_string != NULL); nautilus_string_list_free (tokenized_string); longest_string_length = strlen (longest_string); - - for (i = maximum_acceptable_font_size; i >= minimum_acceptable_font_size; i--) { - int text_width; - int text_height; - nautilus_scalable_font_measure_text (font, - minimum_acceptable_font_size, - minimum_acceptable_font_size, - longest_string, - longest_string_length, - &text_width, - &text_height); + for (i = maximum_acceptable_font_size; i >= minimum_acceptable_font_size; i--) { + int width; + + width = nautilus_scalable_font_text_width (font, + i, + longest_string, + longest_string_length); - if (text_width <= available_width) { + if (width <= available_width) { g_free (longest_string); return i; } diff --git a/libnautilus-extensions/nautilus-scalable-font.h b/libnautilus-extensions/nautilus-scalable-font.h index cbef1e42e..61b36ed90 100644 --- a/libnautilus-extensions/nautilus-scalable-font.h +++ b/libnautilus-extensions/nautilus-scalable-font.h @@ -44,6 +44,7 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <libgnome/gnome-defs.h> #include <libnautilus-extensions/nautilus-string-list.h> +#include <libnautilus-extensions/nautilus-art-extensions.h> #include <libart_lgpl/art_rect.h> BEGIN_GNOME_DECLS @@ -77,16 +78,12 @@ NautilusScalableFont *nautilus_scalable_font_new (c const char *weight, const char *slant, const char *set_width); -void nautilus_scalable_font_measure_text (const NautilusScalableFont *font, - int font_width, - int font_height, +NautilusDimensions nautilus_scalable_font_measure_text (const NautilusScalableFont *font, + int font_size, const char *text, - guint text_length, - int *text_width_out, - int *text_height_out); + guint text_length); int nautilus_scalable_font_text_width (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint text_length); void nautilus_scalable_font_draw_text (const NautilusScalableFont *font, @@ -94,20 +91,17 @@ void nautilus_scalable_font_draw_text (c int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint text_length, guint32 color, int opacity); void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, double empty_line_height, - int text_line_widths[], - int text_line_heights[], + NautilusDimensions text_line_dimensions[], int *max_width_out, int *total_height_out); void nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFont *font, @@ -115,12 +109,10 @@ void nautilus_scalable_font_draw_text_lines_with_dimensions (c int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, - const int *text_line_widths, - const int *text_line_heights, + const NautilusDimensions *text_line_dimensions, GtkJustification justification, int line_offset, double empty_line_height, @@ -131,8 +123,7 @@ void nautilus_scalable_font_draw_text_lines (c int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, GtkJustification justification, int line_offset, diff --git a/libnautilus-extensions/nautilus-self-checks.c b/libnautilus-extensions/nautilus-self-checks.c index d0a5cc526..4adb11d05 100644 --- a/libnautilus-extensions/nautilus-self-checks.c +++ b/libnautilus-extensions/nautilus-self-checks.c @@ -106,6 +106,48 @@ nautilus_check_boolean_result (gboolean result, gboolean expected) } void +nautilus_check_rectangle_result (ArtIRect result, + int expected_x0, + int expected_y0, + int expected_x1, + int expected_y1) +{ + if (result.x0 != expected_x0 + || result.y0 != expected_y0 + || result.x1 != expected_x1 + || result.y1 != expected_y1) { + nautilus_report_check_failure (g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d", + result.x0, + result.y0, + result.x1, + result.y1), + g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d", + expected_x0, + expected_y0, + expected_x1, + expected_y1)); + } + nautilus_after_check (); +} + +void +nautilus_check_dimensions_result (NautilusDimensions result, + int expected_width, + int expected_height) +{ + if (result.width != expected_width + || result.height != expected_height) { + nautilus_report_check_failure (g_strdup_printf ("width=%d, height=%d", + result.width, + result.height), + g_strdup_printf ("width=%d, height=%d", + expected_width, + expected_height)); + } + nautilus_after_check (); +} + +void nautilus_check_integer_result (long result, long expected) { if (result != expected) { diff --git a/libnautilus-extensions/nautilus-self-checks.h b/libnautilus-extensions/nautilus-self-checks.h index 289af4e40..73ff7e5c3 100644 --- a/libnautilus-extensions/nautilus-self-checks.h +++ b/libnautilus-extensions/nautilus-self-checks.h @@ -26,6 +26,7 @@ #define NAUTILUS_SELF_CHECKS_H #include <glib.h> +#include <libnautilus-extensions/nautilus-art-extensions.h> #define NAUTILUS_CHECK_RESULT(type, expression, expected_value) \ G_STMT_START { \ @@ -39,22 +40,37 @@ G_STMT_START { \ NAUTILUS_CHECK_RESULT(integer, expression, expected_value) #define NAUTILUS_CHECK_STRING_RESULT(expression, expected_value) \ NAUTILUS_CHECK_RESULT(string, expression, expected_value) +#define NAUTILUS_CHECK_RECTANGLE_RESULT(expression, expected_x0, expected_y0, expected_x1, expected_y1) \ +G_STMT_START { \ + nautilus_before_check (#expression, __FILE__, __LINE__); \ + nautilus_check_rectangle_result (expression, expected_x0, expected_y0, expected_x1, expected_y1); \ +} G_STMT_END +#define NAUTILUS_CHECK_DIMENSIONS_RESULT(expression, expected_width, expected_height) \ +G_STMT_START { \ + nautilus_before_check (#expression, __FILE__, __LINE__); \ + nautilus_check_dimensions_result (expression, expected_width, expected_height); \ +} G_STMT_END void nautilus_exit_if_self_checks_failed (void); - -void nautilus_before_check_function (const char *name); +void nautilus_before_check_function (const char *name); void nautilus_after_check_function (void); - -void nautilus_before_check (const char *expression, - const char *file_name, - int line_number); - -void nautilus_check_boolean_result (gboolean result, - gboolean expected_value); -void nautilus_check_integer_result (long result, - long expected_value); -void nautilus_check_string_result (char *result, - const char *expected_value); +void nautilus_before_check (const char *expression, + const char *file_name, + int line_number); +void nautilus_check_boolean_result (gboolean result, + gboolean expected_value); +void nautilus_check_integer_result (long result, + long expected_value); +void nautilus_check_rectangle_result (ArtIRect result, + int expected_x0, + int expected_y0, + int expected_x1, + int expected_y1); +void nautilus_check_dimensions_result (NautilusDimensions result, + int expected_width, + int expected_height); +void nautilus_check_string_result (char *result, + const char *expected_value); #define NAUTILUS_SELF_CHECK_FUNCTION_PROTOTYPE(function) \ void function (void); diff --git a/libnautilus-extensions/nautilus-smooth-widget.c b/libnautilus-extensions/nautilus-smooth-widget.c index 28b7ba72a..4b6229422 100644 --- a/libnautilus-extensions/nautilus-smooth-widget.c +++ b/libnautilus-extensions/nautilus-smooth-widget.c @@ -385,7 +385,7 @@ smooth_widget_paint_tile_transparent (GtkWidget *widget, const NautilusArtIPoint *tile_origin, const ArtIRect *dirty_area) { - ArtIRect buffer_frame; + NautilusDimensions buffer_dimensions; ArtIRect tile_dirty_area; ArtIRect tile_area; GdkPixbuf *buffer; @@ -416,9 +416,9 @@ smooth_widget_paint_tile_transparent (GtkWidget *widget, g_return_if_fail (nautilus_gdk_pixbuf_is_valid (buffer)); - buffer_frame = nautilus_gdk_pixbuf_get_frame (buffer); + buffer_dimensions = nautilus_gdk_pixbuf_get_dimensions (buffer); - nautilus_art_irect_assign (&tile_area, 0, 0, buffer_frame.x1, buffer_frame.y1); + nautilus_art_irect_assign (&tile_area, 0, 0, buffer_dimensions.width, buffer_dimensions.height); /* Composite the tile into the buffer */ nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (tile_pixbuf, @@ -948,50 +948,47 @@ nautilus_smooth_widget_get_tile_bounds (const GtkWidget *widget, } /* Clip the tile bounds to the widget bounds */ - bounds = nautilus_irect_gtk_widget_get_bounds (widget); + bounds = nautilus_gtk_widget_get_bounds (widget); art_irect_intersect (&clipped_tile_bounds, &tile_bounds, &bounds); return tile_bounds; } -ArtIRect -nautilus_smooth_widget_get_preferred_frame (const GtkWidget *widget, - const ArtIRect *content_frame, - const ArtIRect *tile_frame, - int tile_width, - int tile_height) +NautilusDimensions +nautilus_smooth_widget_get_preferred_dimensions (const GtkWidget *widget, + const NautilusDimensions *content_dimensions, + const NautilusDimensions *tile_dimensions, + int tile_width, + int tile_height) { - ArtIRect preferred_frame; + NautilusDimensions preferred_dimensions; - g_return_val_if_fail (widget_is_smooth (widget), NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (content_frame != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (tile_frame != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (tile_width >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (tile_height >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (widget_is_smooth (widget), NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (content_dimensions != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (tile_dimensions != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (tile_width >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (tile_height >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_DIMENSIONS_EMPTY); if (tile_width == NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP) { - tile_width = tile_frame->x1; + tile_width = tile_dimensions->width; } else { tile_width = 0; } if (tile_height == NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP) { - tile_height = tile_frame->y1; + tile_height = tile_dimensions->height; } else { tile_height = 0; } - nautilus_art_irect_assign (&preferred_frame, - 0, - 0, - MAX (content_frame->x1, tile_width) + (2 * GTK_MISC (widget)->xpad), - MAX (content_frame->y1, tile_height) + (2 * GTK_MISC (widget)->ypad)); + preferred_dimensions.width = MAX (content_dimensions->width, tile_width) + (2 * GTK_MISC (widget)->xpad); + preferred_dimensions.height = MAX (content_dimensions->height, tile_height) + (2 * GTK_MISC (widget)->ypad); - /* Make sure the frame is not zero. Gtk goes berserk with zero size widget */ - preferred_frame.x1 = MAX (preferred_frame.x1, 2); - preferred_frame.y1 = MAX (preferred_frame.y1, 2); + /* Make sure the dimensions is not zero. Gtk goes berserk with zero size widget */ + preferred_dimensions.width = MAX (preferred_dimensions.width, 2); + preferred_dimensions.height = MAX (preferred_dimensions.height, 2); - return preferred_frame; + return preferred_dimensions; } void diff --git a/libnautilus-extensions/nautilus-smooth-widget.h b/libnautilus-extensions/nautilus-smooth-widget.h index 007f8769c..7661a586f 100644 --- a/libnautilus-extensions/nautilus-smooth-widget.h +++ b/libnautilus-extensions/nautilus-smooth-widget.h @@ -84,33 +84,33 @@ typedef void (* NautilusSmoothCompositeCallback) (GtkWidget *widget, int opacity, gpointer callback_data); -void nautilus_smooth_widget_register (GtkWidget *widget); -void nautilus_smooth_widget_paint (GtkWidget *widget, - GdkGC *gc, - gboolean is_smooth, - NautilusSmoothBackgroundMode background_mode, - guint32 solid_background_color, - const GdkPixbuf *tile_pixbuf, - const ArtIRect *tile_bounds, - int tile_opacity, - NautilusSmoothTileMode tile_mode_vertical, - NautilusSmoothTileMode tile_mode_horizontal, - const ArtIRect *content_bounds, - int content_opacity, - const ArtIRect *dirty_area, - NautilusSmoothPaintOpaqueCallback paint_callback, - NautilusSmoothCompositeCallback composite_callback, - gpointer callback_data); -ArtIRect nautilus_smooth_widget_get_tile_bounds (const GtkWidget *widget, - const GdkPixbuf *tile_pixbuf, - int tile_width, - int tile_height); -ArtIRect nautilus_smooth_widget_get_preferred_frame (const GtkWidget *widget, - const ArtIRect *content_frame, - const ArtIRect *tile_frame, - int tile_width, - int tile_height); -void nautilus_smooth_widget_register_type (GtkType type); +void nautilus_smooth_widget_register (GtkWidget *widget); +void nautilus_smooth_widget_paint (GtkWidget *widget, + GdkGC *gc, + gboolean is_smooth, + NautilusSmoothBackgroundMode background_mode, + guint32 solid_background_color, + const GdkPixbuf *tile_pixbuf, + const ArtIRect *tile_bounds, + int tile_opacity, + NautilusSmoothTileMode tile_mode_vertical, + NautilusSmoothTileMode tile_mode_horizontal, + const ArtIRect *content_bounds, + int content_opacity, + const ArtIRect *dirty_area, + NautilusSmoothPaintOpaqueCallback paint_callback, + NautilusSmoothCompositeCallback composite_callback, + gpointer callback_data); +ArtIRect nautilus_smooth_widget_get_tile_bounds (const GtkWidget *widget, + const GdkPixbuf *tile_pixbuf, + int tile_width, + int tile_height); +NautilusDimensions nautilus_smooth_widget_get_preferred_dimensions (const GtkWidget *widget, + const NautilusDimensions *content_dimensions, + const NautilusDimensions *tile_dimensions, + int tile_width, + int tile_height); +void nautilus_smooth_widget_register_type (GtkType type); END_GNOME_DECLS diff --git a/libnautilus-extensions/nautilus-tabs.c b/libnautilus-extensions/nautilus-tabs.c index c81714bf1..4cbefc11d 100644 --- a/libnautilus-extensions/nautilus-tabs.c +++ b/libnautilus-extensions/nautilus-tabs.c @@ -481,15 +481,10 @@ allocate_cleared_pixbuf (int width, int height) static int measure_tab_name (NautilusTabs *tabs, const char *tab_name) { - int name_width, name_height; - nautilus_scalable_font_measure_text (tabs->details->tab_font, - tabs->details->font_size, - tabs->details->font_size, - tab_name, - strlen (tab_name), - &name_width, - &name_height); - return name_width; + return nautilus_scalable_font_text_width (tabs->details->tab_font, + tabs->details->font_size, + tab_name, + strlen (tab_name)); } /* utility to draw the tab label */ @@ -505,7 +500,7 @@ draw_tab_label (NautilusTabs *tabs, GdkPixbuf *tab_pixbuf, int x_pos, const char nautilus_scalable_font_draw_text (tabs->details->tab_font, tab_pixbuf, text_x, text_y, NULL, - tabs->details->font_size, tabs->details->font_size, + tabs->details->font_size, label, strlen (label), NAUTILUS_RGB_COLOR_BLACK, NAUTILUS_OPACITY_FULLY_OPAQUE); text_x -= 1; @@ -524,7 +519,7 @@ draw_tab_label (NautilusTabs *tabs, GdkPixbuf *tab_pixbuf, int x_pos, const char nautilus_scalable_font_draw_text (tabs->details->tab_font, tab_pixbuf, text_x, text_y, NULL, - tabs->details->font_size, tabs->details->font_size, + tabs->details->font_size, label, strlen (label), text_color, NAUTILUS_OPACITY_FULLY_OPAQUE); diff --git a/libnautilus-extensions/nautilus-text-layout.c b/libnautilus-extensions/nautilus-text-layout.c index 2c54607eb..d76a1e678 100644 --- a/libnautilus-extensions/nautilus-text-layout.c +++ b/libnautilus-extensions/nautilus-text-layout.c @@ -153,7 +153,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, if (word_end < row_end) word_end++; - if (nautilus_scalable_font_text_width (font, font_size, font_size, text_iter, word_end - text_iter) > max_width) { + if (nautilus_scalable_font_text_width (font, font_size, text_iter, word_end - text_iter) > max_width) { if (word_start == text_iter) { if (confine) { /* We must force-split the word. Look for a proper @@ -163,7 +163,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, w_len = word_end - word_start; for (i = 1; i < w_len; i++) { - w = nautilus_scalable_font_text_width (font, font_size, font_size, word_start, i); + w = nautilus_scalable_font_text_width (font, font_size, word_start, i); if (w > max_width) { if (i == 1) /* Shit, not even a single character fits */ @@ -180,7 +180,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, row = g_new (NautilusTextLayoutRow, 1); row->text = sub_text; row->text_length = i - 1; - row->width = nautilus_scalable_font_text_width (font, font_size, font_size, + row->width = nautilus_scalable_font_text_width (font, font_size, sub_text, strlen (sub_text)); @@ -198,7 +198,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, continue; } else - max_width = nautilus_scalable_font_text_width (font, font_size, font_size, word_start, word_end - word_start); + max_width = nautilus_scalable_font_text_width (font, font_size, word_start, word_end - word_start); continue; /* Retry split */ } else { @@ -232,7 +232,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, row = g_new (NautilusTextLayoutRow, 1); row->text = sub_text; row->text_length = sub_len; - row->width = nautilus_scalable_font_text_width (font, font_size, font_size, sub_text, sub_len); + row->width = nautilus_scalable_font_text_width (font, font_size, sub_text, sub_len); text_layout->rows = g_list_append (text_layout->rows, row); @@ -318,7 +318,6 @@ nautilus_text_layout_paint (const NautilusTextLayout *text_layout, y, NULL, text_layout->font_size, - text_layout->font_size, row->text, row->text_length, color, diff --git a/libnautilus-extensions/nautilus-wrap-table.c b/libnautilus-extensions/nautilus-wrap-table.c index 8a2c62353..82bfa9990 100644 --- a/libnautilus-extensions/nautilus-wrap-table.c +++ b/libnautilus-extensions/nautilus-wrap-table.c @@ -57,48 +57,48 @@ struct NautilusWrapTableDetails }; /* GtkObjectClass methods */ -static void nautilus_wrap_table_initialize_class (NautilusWrapTableClass *wrap_table_class); -static void nautilus_wrap_table_initialize (NautilusWrapTable *wrap); -static void nautilus_wrap_table_destroy (GtkObject *object); -static void nautilus_wrap_table_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_wrap_table_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_wrap_table_initialize_class (NautilusWrapTableClass *wrap_table_class); +static void nautilus_wrap_table_initialize (NautilusWrapTable *wrap); +static void nautilus_wrap_table_destroy (GtkObject *object); +static void nautilus_wrap_table_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_wrap_table_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_wrap_table_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int nautilus_wrap_table_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void nautilus_wrap_table_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void nautilus_wrap_table_map (GtkWidget *widget); -static void nautilus_wrap_table_unmap (GtkWidget *widget); +static void nautilus_wrap_table_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static int nautilus_wrap_table_expose_event (GtkWidget *widget, + GdkEventExpose *event); +static void nautilus_wrap_table_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static void nautilus_wrap_table_map (GtkWidget *widget); +static void nautilus_wrap_table_unmap (GtkWidget *widget); /* GtkContainerClass methods */ -static void nautilus_wrap_table_add (GtkContainer *container, - GtkWidget *widget); -static void nautilus_wrap_table_remove (GtkContainer *container, - GtkWidget *widget); -static void nautilus_wrap_table_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static GtkType nautilus_wrap_table_child_type (GtkContainer *container); +static void nautilus_wrap_table_add (GtkContainer *container, + GtkWidget *widget); +static void nautilus_wrap_table_remove (GtkContainer *container, + GtkWidget *widget); +static void nautilus_wrap_table_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data); +static GtkType nautilus_wrap_table_child_type (GtkContainer *container); /* Private NautilusWrapTable methods */ -static ArtIRect wrap_table_art_irect_max_frame (const ArtIRect *one, - const ArtIRect *two); -static ArtIRect wrap_table_get_max_child_frame (const NautilusWrapTable *wrap_table); -static ArtIRect wrap_table_get_content_frame (const NautilusWrapTable *wrap_table); -static ArtIRect wrap_table_get_content_bounds (const NautilusWrapTable *wrap_table); -static NautilusArtIPoint wrap_table_get_scroll_offset (const NautilusWrapTable *wrap_table); -static GtkWidget * wrap_table_find_child_at_point (const NautilusWrapTable *wrap_table, - int x, - int y); -static void wrap_table_layout (NautilusWrapTable *wrap_table); +static NautilusDimensions wrap_table_art_irect_max_dimensions (const NautilusDimensions *one, + const NautilusDimensions *two); +static NautilusDimensions wrap_table_get_max_child_dimensions (const NautilusWrapTable *wrap_table); +static NautilusDimensions wrap_table_get_content_dimensions (const NautilusWrapTable *wrap_table); +static ArtIRect wrap_table_get_content_bounds (const NautilusWrapTable *wrap_table); +static NautilusArtIPoint wrap_table_get_scroll_offset (const NautilusWrapTable *wrap_table); +static GtkWidget * wrap_table_find_child_at_point (const NautilusWrapTable *wrap_table, + int x, + int y); +static void wrap_table_layout (NautilusWrapTable *wrap_table); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusWrapTable, nautilus_wrap_table, GTK_TYPE_CONTAINER) @@ -265,18 +265,18 @@ nautilus_wrap_table_size_request (GtkWidget *widget, GtkRequisition *requisition) { NautilusWrapTable *wrap_table; - ArtIRect content_frame; + NautilusDimensions content_dimensions; g_return_if_fail (NAUTILUS_IS_WRAP_TABLE (widget)); g_return_if_fail (requisition != NULL); wrap_table = NAUTILUS_WRAP_TABLE (widget); - content_frame = wrap_table_get_content_frame (wrap_table); + content_dimensions = wrap_table_get_content_dimensions (wrap_table); /* The -1 tells Satan to use as much space as is available */ requisition->width = -1; - requisition->height = content_frame.y1 + GTK_CONTAINER (widget)->border_width * 2; + requisition->height = content_dimensions.height + GTK_CONTAINER (widget)->border_width * 2; } static void @@ -456,12 +456,12 @@ wrap_table_layout (NautilusWrapTable *wrap_table) { GList *iterator; NautilusArtIPoint pos; - ArtIRect max_child_frame; + NautilusDimensions max_child_dimensions; ArtIRect content_bounds; g_return_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table)); - max_child_frame = wrap_table_get_max_child_frame (wrap_table); + max_child_dimensions = wrap_table_get_max_child_dimensions (wrap_table); content_bounds = wrap_table_get_content_bounds (wrap_table); pos.x = content_bounds.x0; pos.y = content_bounds.y0; @@ -477,16 +477,16 @@ wrap_table_layout (NautilusWrapTable *wrap_table) if (wrap_table->details->homogeneous) { item_allocation.x = pos.x; item_allocation.y = pos.y; - item_allocation.width = max_child_frame.x1; - item_allocation.height = max_child_frame.y1; + item_allocation.width = max_child_dimensions.width; + item_allocation.height = max_child_dimensions.height; - if ((pos.x + max_child_frame.x1) > content_bounds.x1) { - pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_frame.x1; - pos.y += (max_child_frame.y1 + wrap_table->details->y_spacing); + if ((pos.x + max_child_dimensions.width) > content_bounds.x1) { + pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_dimensions.width; + pos.y += (max_child_dimensions.height + wrap_table->details->y_spacing); item_allocation.x = content_bounds.x0; item_allocation.y = pos.y; } else { - pos.x += (wrap_table->details->x_spacing + max_child_frame.x1); + pos.x += (wrap_table->details->x_spacing + max_child_dimensions.width); } } else { GtkRequisition item_requisition; @@ -498,34 +498,34 @@ wrap_table_layout (NautilusWrapTable *wrap_table) item_allocation.width = item_requisition.width; item_allocation.height = item_requisition.height; - g_assert (item_allocation.width <= max_child_frame.x1); - g_assert (item_allocation.height <= max_child_frame.y1); + g_assert (item_allocation.width <= max_child_dimensions.width); + g_assert (item_allocation.height <= max_child_dimensions.height); - if ((pos.x + max_child_frame.x1) > content_bounds.x1) { - pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_frame.x1; - pos.y += (max_child_frame.y1 + wrap_table->details->y_spacing); + if ((pos.x + max_child_dimensions.width) > content_bounds.x1) { + pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_dimensions.width; + pos.y += (max_child_dimensions.height + wrap_table->details->y_spacing); item_allocation.x = content_bounds.x0; item_allocation.y = pos.y; } else { - pos.x += (wrap_table->details->x_spacing + max_child_frame.x1); + pos.x += (wrap_table->details->x_spacing + max_child_dimensions.width); } switch (wrap_table->details->x_justification) { case NAUTILUS_JUSTIFICATION_MIDDLE: - item_allocation.x += (max_child_frame.x1 - (int) item_allocation.width) / 2; + item_allocation.x += (max_child_dimensions.width - (int) item_allocation.width) / 2; break; case NAUTILUS_JUSTIFICATION_END: - item_allocation.x += (max_child_frame.x1 - (int) item_allocation.width); + item_allocation.x += (max_child_dimensions.width - (int) item_allocation.width); break; default: } switch (wrap_table->details->y_justification) { case NAUTILUS_JUSTIFICATION_MIDDLE: - item_allocation.y += (max_child_frame.y1 - (int) item_allocation.height) / 2; + item_allocation.y += (max_child_dimensions.height - (int) item_allocation.height) / 2; break; case NAUTILUS_JUSTIFICATION_END: - item_allocation.y += (max_child_frame.y1 - (int) item_allocation.height); + item_allocation.y += (max_child_dimensions.height - (int) item_allocation.height); break; default: } @@ -536,36 +536,30 @@ wrap_table_layout (NautilusWrapTable *wrap_table) } } -static ArtIRect -wrap_table_art_irect_max_frame (const ArtIRect *one, - const ArtIRect *two) +static NautilusDimensions +wrap_table_art_irect_max_dimensions (const NautilusDimensions *one, + const NautilusDimensions *two) { - ArtIRect max; + NautilusDimensions max_dimensions; - g_return_val_if_fail (one != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (two != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (one->x0 == 0, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (one->y0 == 0, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (two->x0 == 0, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (two->y0 == 0, NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (one != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (two != NULL, NAUTILUS_DIMENSIONS_EMPTY); - max.x0 = 0; - max.y0 = 0; - max.x1 = MAX (one->x1, two->x1); - max.y1 = MAX (one->y1, two->y1); + max_dimensions.width = MAX (one->width, two->width); + max_dimensions.height = MAX (one->height, two->height); - return max; + return max_dimensions; } -static ArtIRect -wrap_table_get_max_child_frame (const NautilusWrapTable *wrap_table) +static NautilusDimensions +wrap_table_get_max_child_dimensions (const NautilusWrapTable *wrap_table) { - ArtIRect max; + NautilusDimensions max_dimensions; GList *iterator; - g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_DIMENSIONS_EMPTY); - max = NAUTILUS_ART_IRECT_EMPTY; + max_dimensions = NAUTILUS_DIMENSIONS_EMPTY; for (iterator = wrap_table->details->items; iterator; iterator = iterator->next) { GtkWidget *child; @@ -574,20 +568,18 @@ wrap_table_get_max_child_frame (const NautilusWrapTable *wrap_table) if (GTK_WIDGET_VISIBLE (child)) { GtkRequisition child_requisition; - ArtIRect child_frame; + NautilusDimensions child_dimensions; gtk_widget_size_request (child, &child_requisition); - child_frame.x0 = 0; - child_frame.y0 = 0; - child_frame.x1 = child_requisition.width; - child_frame.y1 = child_requisition.height; + child_dimensions.width = (int) child_requisition.width; + child_dimensions.height = (int) child_requisition.height; - max = wrap_table_art_irect_max_frame (&child_frame, &max); + max_dimensions = wrap_table_art_irect_max_dimensions (&child_dimensions, &max_dimensions); } } - return max; + return max_dimensions; } static int @@ -607,33 +599,33 @@ wrap_table_get_num_fitting (int available, return num; } -static ArtIRect -wrap_table_get_content_frame (const NautilusWrapTable *wrap_table) +static NautilusDimensions +wrap_table_get_content_dimensions (const NautilusWrapTable *wrap_table) { - ArtIRect content_frame; + NautilusDimensions content_dimensions; guint num_children; - g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_DIMENSIONS_EMPTY); - content_frame = NAUTILUS_ART_IRECT_EMPTY; + content_dimensions = NAUTILUS_DIMENSIONS_EMPTY; num_children = g_list_length (wrap_table->details->items); if (num_children > 0) { - ArtIRect max_child_frame; - ArtIRect frame; + NautilusDimensions max_child_dimensions; + NautilusDimensions dimensions; int num_cols; int num_rows; - frame = nautilus_irect_gtk_widget_get_frame (GTK_WIDGET (wrap_table)); - max_child_frame = wrap_table_get_max_child_frame (wrap_table); + dimensions = nautilus_gtk_widget_get_dimensions (GTK_WIDGET (wrap_table)); + max_child_dimensions = wrap_table_get_max_child_dimensions (wrap_table); - max_child_frame.x1 = MAX (max_child_frame.x1, 1); - max_child_frame.y1 = MAX (max_child_frame.y1, 1); + max_child_dimensions.width = MAX (max_child_dimensions.width, 1); + max_child_dimensions.height = MAX (max_child_dimensions.height, 1); - num_cols = wrap_table_get_num_fitting (frame.x1, + num_cols = wrap_table_get_num_fitting (dimensions.width, wrap_table->details->x_spacing, - max_child_frame.x1); + max_child_dimensions.width); num_rows = num_children / num_cols; num_rows = MAX (num_rows, 1); @@ -641,11 +633,11 @@ wrap_table_get_content_frame (const NautilusWrapTable *wrap_table) num_rows++; } - content_frame.x1 = frame.x1; - content_frame.y1 = num_rows * max_child_frame.y1; + content_dimensions.width = dimensions.width; + content_dimensions.height = num_rows * max_child_dimensions.height; } - return content_frame; + return content_dimensions; } static ArtIRect @@ -655,7 +647,7 @@ wrap_table_get_content_bounds (const NautilusWrapTable *wrap_table) g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_ART_IRECT_EMPTY); - content_bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (wrap_table)); + content_bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (wrap_table)); content_bounds.x0 += GTK_CONTAINER (wrap_table)->border_width; content_bounds.y0 += GTK_CONTAINER (wrap_table)->border_width; @@ -707,7 +699,7 @@ wrap_table_find_child_at_point (const NautilusWrapTable *wrap_table, if (GTK_WIDGET_VISIBLE (child)) { ArtIRect child_bounds; - child_bounds = nautilus_irect_gtk_widget_get_bounds (child); + child_bounds = nautilus_gtk_widget_get_bounds (child); if (nautilus_art_irect_contains_point (&child_bounds, x, y)) { return child; diff --git a/libnautilus-private/nautilus-art-extensions.c b/libnautilus-private/nautilus-art-extensions.c index 9cec8a717..41c975797 100644 --- a/libnautilus-private/nautilus-art-extensions.c +++ b/libnautilus-private/nautilus-art-extensions.c @@ -26,10 +26,12 @@ #include <config.h> #include "nautilus-art-extensions.h" +#include "nautilus-lib-self-check-functions.h" #include <math.h> ArtIRect NAUTILUS_ART_IRECT_EMPTY = { 0, 0, 0, 0 }; NautilusArtIPoint NAUTILUS_ART_IPOINT_ZERO = { 0, 0 }; +NautilusDimensions NAUTILUS_DIMENSIONS_EMPTY = { 0, 0 }; gboolean nautilus_art_irect_contains_irect (const ArtIRect *outer_rect, @@ -122,17 +124,6 @@ nautilus_art_irect_assign (ArtIRect *rect, rect->y1 = rect->y0 + height; } -void -nautilus_art_ipoint_assign (NautilusArtIPoint *point, - int x, - int y) -{ - g_return_if_fail (point != NULL); - - point->x = x; - point->y = y; -} - /** * nautilus_art_irect_get_width: * @@ -214,3 +205,143 @@ nautilus_art_irect_align (const ArtIRect *container, return aligned; } + +/** + * nautilus_dimensions_empty: + * + * @dimensions: A NautilusDimensions structure. + * + * Returns: Whether the dimensions are empty. + */ +gboolean +nautilus_dimensions_empty (const NautilusDimensions *dimensions) +{ + g_return_val_if_fail (dimensions != NULL, TRUE); + + return dimensions->width <= 0 || dimensions->height <= 0; +} + +/** + * nautilus_art_irect_assign_dimensions: + * + * @x: X coodinate for resulting rectangle. + * @y: Y coodinate for resulting rectangle. + * @dimensions: A NautilusDimensions structure for the rect's width and height. + * + * Returns: An ArtIRect with the given coordinates and dimensions. + */ +ArtIRect +nautilus_art_irect_assign_dimensions (int x, + int y, + const NautilusDimensions *dimensions) +{ + ArtIRect rectangle; + + g_return_val_if_fail (dimensions != NULL, NAUTILUS_ART_IRECT_EMPTY); + + rectangle.x0 = x; + rectangle.y0 = y; + rectangle.x1 = rectangle.x0 + dimensions->width; + rectangle.y1 = rectangle.y0 + dimensions->height; + + return rectangle; +} + +#if !defined (NAUTILUS_OMIT_SELF_CHECK) + +void +nautilus_self_check_art_extensions (void) +{ + ArtIRect one; + ArtIRect two; + ArtIRect empty_rect = NAUTILUS_ART_IRECT_EMPTY; + ArtIRect inside; + ArtIRect outside; + ArtIRect container; + NautilusDimensions empty_dimensions = NAUTILUS_DIMENSIONS_EMPTY; + NautilusDimensions dim1; + + nautilus_art_irect_assign (&one, 10, 10, 20, 20); + nautilus_art_irect_assign (&two, 10, 10, 20, 20); + nautilus_art_irect_assign (&inside, 11, 11, 18, 18); + nautilus_art_irect_assign (&outside, 31, 31, 10, 10); + nautilus_art_irect_assign (&container, 0, 0, 100, 100); + + /* nautilus_art_irect_equal */ + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_equal (&one, &two), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_equal (&one, &empty_rect), FALSE); + + /* nautilus_art_irect_hits_irect */ + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_hits_irect (&one, &two), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_hits_irect (&one, &inside), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_hits_irect (&one, &outside), FALSE); + + /* nautilus_art_irect_contains_point */ + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 9, 9), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 9, 10), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 10, 9), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 10, 10), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 11, 10), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 10, 11), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 11, 11), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 30, 30), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 29, 30), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 30, 29), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_art_irect_contains_point (&one, 31, 31), FALSE); + + /* nautilus_art_irect_get_width */ + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_width (&one), 20); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_width (&empty_rect), 0); + + /* nautilus_art_irect_get_height */ + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_height (&one), 20); + NAUTILUS_CHECK_INTEGER_RESULT (nautilus_art_irect_get_height (&empty_rect), 0); + + /* nautilus_art_irect_align */ + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&empty_rect, 1, 1, 0.0, 0.0), 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 0, 0, 0.0, 0.0), 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 0, 0.0, 0.0), 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 0, 9, 0.0, 0.0), 0, 0, 0, 0); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.0, 0.0), 0, 0, 10, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 1.0, 0.0), 90, 0, 100, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.0, 1.0), 0, 90, 10, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 1.0, 1.0), 90, 90, 100, 100); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.0, 0.0), 0, 0, 9, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 1.0, 0.0), 91, 0, 100, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.0, 1.0), 0, 91, 9, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 1.0, 1.0), 91, 91, 100, 100); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.5, 0.0), 45, 0, 55, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.5, 0.0), 45, 0, 55, 10); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.0, 0.5), 0, 45, 10, 55); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 10, 10, 0.5, 0.5), 45, 45, 55, 55); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.5, 0.0), 46, 0, 55, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.5, 0.0), 46, 0, 55, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.0, 0.5), 0, 46, 9, 55); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 9, 9, 0.5, 0.5), 46, 46, 55, 55); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 120, 120, 0.0, 0.0), 0, 0, 120, 120); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_align (&container, 120, 120, 0.5, 0.5), -10, -10, 110, 110); + + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_dimensions_empty (&empty_dimensions), TRUE); + + dim1.width = 10; dim1.height = 10; + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_dimensions_empty (&dim1), FALSE); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (0, 0, &dim1), 0, 0, 10, 10); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (1, 1, &dim1), 1, 1, 11, 11); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-1, 1, &dim1), -1, 1, 9, 11); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (1, -1, &dim1), 1, -1, 11, 9); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-1, -1, &dim1), -1, -1, 9, 9); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (2, 2, &dim1), 2, 2, 12, 12); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-2, 2, &dim1), -2, 2, 8, 12); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (2, -2, &dim1), 2, -2, 12, 8); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_art_irect_assign_dimensions (-2, -2, &dim1), -2, -2, 8, 8); +} + +#endif /* !NAUTILUS_OMIT_SELF_CHECK */ diff --git a/libnautilus-private/nautilus-art-extensions.h b/libnautilus-private/nautilus-art-extensions.h index b47f2d7ed..e5838e6fd 100644 --- a/libnautilus-private/nautilus-art-extensions.h +++ b/libnautilus-private/nautilus-art-extensions.h @@ -37,36 +37,45 @@ typedef struct { int y; } NautilusArtIPoint; +typedef struct { + int width; + int height; +} NautilusDimensions; + extern ArtIRect NAUTILUS_ART_IRECT_EMPTY; extern NautilusArtIPoint NAUTILUS_ART_IPOINT_ZERO; +extern NautilusDimensions NAUTILUS_DIMENSIONS_EMPTY; /* More functions for ArtIRect and ArtDRect. */ -gboolean nautilus_art_irect_equal (const ArtIRect *rect_a, - const ArtIRect *rect_b); -gboolean nautilus_art_drect_equal (const ArtDRect *rect_a, - const ArtDRect *rect_b); -gboolean nautilus_art_irect_hits_irect (const ArtIRect *rect_a, - const ArtIRect *rect_b); -gboolean nautilus_art_irect_contains_irect (const ArtIRect *outer_rect, - const ArtIRect *inner_rect); -gboolean nautilus_art_irect_contains_point (const ArtIRect *outer_rect, - int x, - int y); -void nautilus_art_irect_assign (ArtIRect *rect, - int x, - int y, - int width, - int height); -void nautilus_art_ipoint_assign (NautilusArtIPoint *point, - int x, - int y); -int nautilus_art_irect_get_width (const ArtIRect *rect); -int nautilus_art_irect_get_height (const ArtIRect *rect); -ArtIRect nautilus_art_irect_align (const ArtIRect *container, - int aligned_width, - int aligned_height, - float x_alignment, - float y_alignment); +gboolean nautilus_art_irect_equal (const ArtIRect *rect_a, + const ArtIRect *rect_b); +gboolean nautilus_art_drect_equal (const ArtDRect *rect_a, + const ArtDRect *rect_b); +gboolean nautilus_art_irect_hits_irect (const ArtIRect *rect_a, + const ArtIRect *rect_b); +gboolean nautilus_art_irect_contains_irect (const ArtIRect *outer_rect, + const ArtIRect *inner_rect); +gboolean nautilus_art_irect_contains_point (const ArtIRect *outer_rect, + int x, + int y); +void nautilus_art_irect_assign (ArtIRect *rect, + int x, + int y, + int width, + int height); +int nautilus_art_irect_get_width (const ArtIRect *rect); +int nautilus_art_irect_get_height (const ArtIRect *rect); +ArtIRect nautilus_art_irect_align (const ArtIRect *container, + int aligned_width, + int aligned_height, + float x_alignment, + float y_alignment); +/* NautilusDimensions functions. */ +gboolean nautilus_dimensions_empty (const NautilusDimensions *dimensions); +ArtIRect nautilus_art_irect_assign_dimensions (int x, + int y, + const NautilusDimensions *dimensions); + END_GNOME_DECLS #endif /* NAUTILUS_ART_EXTENSIONS_H */ diff --git a/libnautilus-private/nautilus-art-gtk-extensions.c b/libnautilus-private/nautilus-art-gtk-extensions.c index 74ccb5878..3b5814131 100644 --- a/libnautilus-private/nautilus-art-gtk-extensions.c +++ b/libnautilus-private/nautilus-art-gtk-extensions.c @@ -27,7 +27,7 @@ #include "nautilus-art-gtk-extensions.h" /** - * nautilus_irect_assign_gdk_rectangle: + * nautilus_gdk_rectangle_to_art_irect: * @gdk_rectangle: The source GdkRectangle. * * Return value: An ArtIRect representation of the GdkRectangle. @@ -38,7 +38,7 @@ * in GtkWidget's. */ ArtIRect -nautilus_irect_assign_gdk_rectangle (const GdkRectangle *gdk_rectangle) +nautilus_gdk_rectangle_to_art_irect (const GdkRectangle *gdk_rectangle) { ArtIRect irect; @@ -53,29 +53,27 @@ nautilus_irect_assign_gdk_rectangle (const GdkRectangle *gdk_rectangle) } /** - * nautilus_irect_screen_get_frame: + * nautilus_screen_get_dimensions: * - * Return value: An ArtIRect representing the screen frame. + * Return value: The screen dimensions. * */ -ArtIRect -nautilus_irect_screen_get_frame (void) +NautilusDimensions +nautilus_screen_get_dimensions (void) { - ArtIRect screen_frame; + NautilusDimensions screen_dimensions; - screen_frame.x0 = 0; - screen_frame.y0 = 0; - screen_frame.x1 = gdk_screen_width (); - screen_frame.y1 = gdk_screen_width (); + screen_dimensions.width = gdk_screen_width (); + screen_dimensions.height = gdk_screen_width (); - g_assert (screen_frame.x1 > 0); - g_assert (screen_frame.y1 > 0); + g_assert (screen_dimensions.width > 0); + g_assert (screen_dimensions.height > 0); - return screen_frame; + return screen_dimensions; } /** - * nautilus_irect_gdk_window_get_bounds: + * nautilus_gdk_window_get_bounds: * @gdk_window: The source GdkWindow. * * Return value: An ArtIRect representation of the given GdkWindow's geometry @@ -83,7 +81,7 @@ nautilus_irect_screen_get_frame (void) * */ ArtIRect -nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window) +nautilus_gdk_window_get_bounds (const GdkWindow *gdk_window) { ArtIRect bounds; int width; @@ -101,7 +99,7 @@ nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window) } /** - * nautilus_irect_gdk_window_get_bounds: + * nautilus_gdk_window_get_bounds: * @gdk_window: The source GdkWindow. * * Return value: An ArtIRect representation of the given GdkWindow's geometry @@ -109,7 +107,7 @@ nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window) * */ ArtIRect -nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window) +nautilus_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window) { ArtIRect screen_bounds; int width; @@ -132,7 +130,7 @@ nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_windo } /** - * nautilus_irect_gtk_widget_get_bounds: + * nautilus_gtk_widget_get_bounds: * @gtk_widget: The source GtkWidget. * * Return value: An ArtIRect representation of the given GtkWidget's geometry @@ -140,7 +138,7 @@ nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_windo * */ ArtIRect -nautilus_irect_gtk_widget_get_bounds (const GtkWidget *gtk_widget) +nautilus_gtk_widget_get_bounds (const GtkWidget *gtk_widget) { ArtIRect bounds; @@ -156,30 +154,27 @@ nautilus_irect_gtk_widget_get_bounds (const GtkWidget *gtk_widget) } /** - * nautilus_irect_gtk_widget_get_frame: + * nautilus_gtk_widget_get_dimensions: * @gtk_widget: The source GtkWidget. * * Return value: An ArtIRect representation of the given GtkWidget's dimensions. * */ -ArtIRect -nautilus_irect_gtk_widget_get_frame (const GtkWidget *gtk_widget) +NautilusDimensions +nautilus_gtk_widget_get_dimensions (const GtkWidget *gtk_widget) { - ArtIRect frame; + NautilusDimensions dimensions; - g_return_val_if_fail (GTK_IS_WIDGET (gtk_widget), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (GTK_IS_WIDGET (gtk_widget), NAUTILUS_DIMENSIONS_EMPTY); - nautilus_art_irect_assign (&frame, - 0, - 0, - (int) gtk_widget->allocation.width, - (int) gtk_widget->allocation.height); + dimensions.width = (int) gtk_widget->allocation.width; + dimensions.height = (int) gtk_widget->allocation.height; - return frame; + return dimensions; } /** - * nautilus_irect_gdk_window_clip_dirty_area_to_screen: + * nautilus_gdk_window_clip_dirty_area_to_screen: * @gdk_window: The GdkWindow that the damage occured on. * @dirty_area: The dirty area as an ArtIRect. * @@ -189,11 +184,11 @@ nautilus_irect_gtk_widget_get_frame (const GtkWidget *gtk_widget) * It also ensures that any drawing that the widget does is actually onscreen. */ ArtIRect -nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, - const ArtIRect *dirty_area) +nautilus_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, + const ArtIRect *dirty_area) { ArtIRect clipped; - ArtIRect screen_frame; + NautilusDimensions screen_dimensions; ArtIRect bounds; ArtIRect screen_relative_bounds; int dirty_width; @@ -208,9 +203,9 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window g_return_val_if_fail (dirty_width > 0, NAUTILUS_ART_IRECT_EMPTY); g_return_val_if_fail (dirty_height > 0, NAUTILUS_ART_IRECT_EMPTY); - screen_frame = nautilus_irect_screen_get_frame (); - bounds = nautilus_irect_gdk_window_get_bounds (gdk_window); - screen_relative_bounds = nautilus_irect_gdk_window_get_screen_relative_bounds (gdk_window); + screen_dimensions = nautilus_screen_get_dimensions (); + bounds = nautilus_gdk_window_get_bounds (gdk_window); + screen_relative_bounds = nautilus_gdk_window_get_screen_relative_bounds (gdk_window); /* Window is obscured by left edge of screen */ if ((screen_relative_bounds.x0 + dirty_area->x0) < 0) { @@ -223,11 +218,11 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window } /* Window is obscured by right edge of screen */ - if (screen_relative_bounds.x1 > screen_frame.x1) { + if (screen_relative_bounds.x1 > screen_dimensions.width) { int obscured_width; obscured_width = - screen_relative_bounds.x0 + dirty_area->x0 + dirty_width - screen_frame.x1; + screen_relative_bounds.x0 + dirty_area->x0 + dirty_width - screen_dimensions.width; if (obscured_width > 0) { clipped.x1 -= obscured_width; @@ -245,11 +240,11 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window } /* Window is obscured by bottom edge of screen */ - if (screen_relative_bounds.y1 > screen_frame.y1) { + if (screen_relative_bounds.y1 > screen_dimensions.height) { int obscured_height; obscured_height = - screen_relative_bounds.y0 + dirty_area->y0 + dirty_height - screen_frame.y1; + screen_relative_bounds.y0 + dirty_area->y0 + dirty_height - screen_dimensions.height; if (obscured_height > 0) { clipped.y1 -= obscured_height; @@ -264,7 +259,7 @@ nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window } GdkRectangle -nautilus_gdk_rectangle_assign_irect (const ArtIRect *irect) +nautilus_art_irect_to_gdk_rectangle (const ArtIRect *irect) { GdkRectangle gdk_rect; @@ -282,3 +277,16 @@ nautilus_gdk_rectangle_assign_irect (const ArtIRect *irect) return gdk_rect; } + +NautilusDimensions +nautilus_gdk_window_get_dimensions (const GdkWindow *gdk_window) +{ + NautilusDimensions dimensions; + + g_return_val_if_fail (gdk_window != NULL, NAUTILUS_DIMENSIONS_EMPTY); + + gdk_window_get_size ((GdkWindow *) gdk_window, &dimensions.width, &dimensions.height); + + return dimensions; +} + diff --git a/libnautilus-private/nautilus-art-gtk-extensions.h b/libnautilus-private/nautilus-art-gtk-extensions.h index 0bc2578a6..808185fa6 100644 --- a/libnautilus-private/nautilus-art-gtk-extensions.h +++ b/libnautilus-private/nautilus-art-gtk-extensions.h @@ -23,10 +23,10 @@ */ /* The following functions accept gtk/gdk structures and - * return their bounds/frames as ArtIRects, where: + * return their bounds and dimensions, where: * * bounds: The (x,y) and (width, height) of something. - * frame: The (width, height) of something. + * dimensions: The (width, height) of something. * * These are very useful in code that uses libart functions * to do operations on ArtIRects (such as intersection) @@ -41,16 +41,28 @@ BEGIN_GNOME_DECLS -GdkRectangle nautilus_gdk_rectangle_assign_irect (const ArtIRect *irect); -ArtIRect nautilus_irect_assign_gdk_rectangle (const GdkRectangle *gdk_rectangle); -ArtIRect nautilus_irect_screen_get_frame (void); -ArtIRect nautilus_irect_gdk_window_get_bounds (const GdkWindow *gdk_window); -ArtIRect nautilus_irect_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window); -ArtIRect nautilus_irect_gtk_widget_get_bounds (const GtkWidget *gtk_widget); -ArtIRect nautilus_irect_gtk_widget_get_frame (const GtkWidget *gtk_widget); -ArtIRect nautilus_irect_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, +/* Convert between GdkRectangle and ArtIRect and back */ +GdkRectangle nautilus_art_irect_to_gdk_rectangle (const ArtIRect *irect); +ArtIRect nautilus_gdk_rectangle_to_art_irect (const GdkRectangle *gdk_rectangle); +NautilusDimensions nautilus_screen_get_dimensions (void); + +/* GdkWindow parent-relative bounds */ +ArtIRect nautilus_gdk_window_get_bounds (const GdkWindow *gdk_window); + +/* GdkWindow dimensions */ +NautilusDimensions nautilus_gdk_window_get_dimensions (const GdkWindow *gdk_window); + +/* GdkWindow screen parent-relative bounds */ +ArtIRect nautilus_gdk_window_get_screen_relative_bounds (const GdkWindow *gdk_window); + +/* Clip a dirty area (from exposures) to the on screen parts of a GdkWindow */ +ArtIRect nautilus_gdk_window_clip_dirty_area_to_screen (const GdkWindow *gdk_window, const ArtIRect *dirty_area); +/* GtkWidget bounds and dimensions */ +ArtIRect nautilus_gtk_widget_get_bounds (const GtkWidget *gtk_widget); +NautilusDimensions nautilus_gtk_widget_get_dimensions (const GtkWidget *gtk_widget); + END_GNOME_DECLS #endif /* NAUTILUS_ART_GTK_EXTENSIONS_H */ diff --git a/libnautilus-private/nautilus-clickable-image.c b/libnautilus-private/nautilus-clickable-image.c index 801e54ca4..b5330e44c 100644 --- a/libnautilus-private/nautilus-clickable-image.c +++ b/libnautilus-private/nautilus-clickable-image.c @@ -276,7 +276,7 @@ label_handle_motion (NautilusClickableImage *clickable_image, g_return_if_fail (NAUTILUS_IS_CLICKABLE_IMAGE (clickable_image)); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (clickable_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (clickable_image)); if (nautilus_art_irect_contains_point (&bounds, x, y)) { /* Inside */ diff --git a/libnautilus-private/nautilus-debug-drawing.c b/libnautilus-private/nautilus-debug-drawing.c index a280da17f..728f77788 100644 --- a/libnautilus-private/nautilus-debug-drawing.c +++ b/libnautilus-private/nautilus-debug-drawing.c @@ -119,19 +119,19 @@ static void debug_pixbuf_viewer_size_request (GtkWidget *widget, GtkRequisition *requisition) { DebugPixbufViewer *viewer; - ArtIRect frame; + NautilusDimensions dimensions; g_return_if_fail (DEBUG_IS_PIXBUF_VIEWER (widget)); g_return_if_fail (requisition != NULL); viewer = DEBUG_PIXBUF_VIEWER (widget); - frame = (viewer->pixbuf != NULL) ? - nautilus_gdk_pixbuf_get_frame (viewer->pixbuf) : - NAUTILUS_ART_IRECT_EMPTY; + dimensions = (viewer->pixbuf != NULL) ? + nautilus_gdk_pixbuf_get_dimensions (viewer->pixbuf) : + NAUTILUS_DIMENSIONS_EMPTY; - requisition->width = MAX (2, frame.x1); - requisition->height = MAX (2, frame.y1); + requisition->width = MAX (2, dimensions.width); + requisition->height = MAX (2, dimensions.height); } static int @@ -159,8 +159,8 @@ debug_pixbuf_viewer_expose_event (GtkWidget *widget, GdkEventExpose *event) bounds.y1 = bounds.y0 + gdk_pixbuf_get_height (viewer->pixbuf); /* Clip the dirty area to the screen; bail if no work to do */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); - clipped_dirty_area = nautilus_irect_gdk_window_clip_dirty_area_to_screen (event->window, + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); + clipped_dirty_area = nautilus_gdk_window_clip_dirty_area_to_screen (event->window, &dirty_area); if (!art_irect_empty (&clipped_dirty_area)) { ArtIRect clipped_bounds; @@ -363,7 +363,7 @@ nautilus_debug_pixbuf_draw_point (GdkPixbuf *pixbuf, guint32 color, int opacity) { - ArtIRect frame; + NautilusDimensions dimensions; guchar *pixels; gboolean has_alpha; guint pixel_offset; @@ -378,10 +378,10 @@ nautilus_debug_pixbuf_draw_point (GdkPixbuf *pixbuf, g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); - g_return_if_fail (x >= 0 && x < frame.x1); - g_return_if_fail (y >= 0 && y < frame.y1); + g_return_if_fail (x >= 0 && x < dimensions.width); + g_return_if_fail (y >= 0 && y < dimensions.height); pixels = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); @@ -414,7 +414,7 @@ nautilus_debug_pixbuf_draw_rectangle (GdkPixbuf *pixbuf, guint32 color, int opacity) { - ArtIRect frame; + NautilusDimensions dimensions; int x; int y; @@ -422,7 +422,7 @@ nautilus_debug_pixbuf_draw_rectangle (GdkPixbuf *pixbuf, g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); if (x0 == -1) { x0 = 0; @@ -433,19 +433,19 @@ nautilus_debug_pixbuf_draw_rectangle (GdkPixbuf *pixbuf, } if (x1 == -1) { - x1 = frame.x1 - 1; + x1 = dimensions.width - 1; } if (y1 == -1) { - y1 = frame.y1 - 1; + y1 = dimensions.height - 1; } g_return_if_fail (x1 > x0); g_return_if_fail (y1 > y0); - g_return_if_fail (x0 >= 0 && x0 < frame.x1); - g_return_if_fail (y0 >= 0 && y0 < frame.y1); - g_return_if_fail (x1 >= 0 && x1 < frame.x1); - g_return_if_fail (y1 >= 0 && y1 < frame.y1); + g_return_if_fail (x0 >= 0 && x0 < dimensions.width); + g_return_if_fail (y0 >= 0 && y0 < dimensions.height); + g_return_if_fail (x1 >= 0 && x1 < dimensions.width); + g_return_if_fail (y1 >= 0 && y1 < dimensions.height); if (filled) { for (y = y0; y <= y1; y++) { @@ -479,13 +479,13 @@ nautilus_debug_pixbuf_draw_rectangle_inset (GdkPixbuf *pixbuf, int opacity, int inset) { - ArtIRect frame; + NautilusDimensions dimensions; g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); if (x0 == -1) { x0 = 0; @@ -496,11 +496,11 @@ nautilus_debug_pixbuf_draw_rectangle_inset (GdkPixbuf *pixbuf, } if (x1 == -1) { - x1 = frame.x1 - 1; + x1 = dimensions.width - 1; } if (y1 == -1) { - y1 = frame.y1 - 1; + y1 = dimensions.height - 1; } x0 += inset; diff --git a/libnautilus-private/nautilus-gdk-pixbuf-extensions.c b/libnautilus-private/nautilus-gdk-pixbuf-extensions.c index 413eebfb6..1be64a8a3 100644 --- a/libnautilus-private/nautilus-gdk-pixbuf-extensions.c +++ b/libnautilus-private/nautilus-gdk-pixbuf-extensions.c @@ -29,6 +29,9 @@ #include "nautilus-gdk-extensions.h" #include "nautilus-glib-extensions.h" #include "nautilus-string.h" +#include "nautilus-art-gtk-extensions.h" +#include "nautilus-lib-self-check-functions.h" +#include "nautilus-debug-drawing.h" #include <gdk-pixbuf/gdk-pixbuf-loader.h> #include <gdk/gdkx.h> #include <gdk/gdkprivate.h> @@ -388,28 +391,25 @@ nautilus_gdk_pixbuf_is_valid (const GdkPixbuf *pixbuf) } /** - * nautilus_gdk_pixbuf_get_frame: + * nautilus_gdk_pixbuf_get_dimensions: * @pixbuf: A GdkPixbuf * - * Return value: A ArtIRect representing the dimensions of the - * pixbuf. + * Return value: The dimensions of the pixbuf as a NautilusDimensions. * * This function is useful in code that uses libart rect * intersection routines. */ -ArtIRect -nautilus_gdk_pixbuf_get_frame (const GdkPixbuf *pixbuf) +NautilusDimensions +nautilus_gdk_pixbuf_get_dimensions (const GdkPixbuf *pixbuf) { - ArtIRect frame; + NautilusDimensions dimensions; - g_return_val_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf), NAUTILUS_DIMENSIONS_EMPTY); - frame.x0 = 0; - frame.y0 = 0; - frame.x1 = gdk_pixbuf_get_width (pixbuf); - frame.y1 = gdk_pixbuf_get_height (pixbuf); + dimensions.width = gdk_pixbuf_get_width (pixbuf); + dimensions.height = gdk_pixbuf_get_height (pixbuf); - return frame; + return dimensions; } /** @@ -427,7 +427,6 @@ nautilus_gdk_pixbuf_fill_rectangle_with_color (GdkPixbuf *pixbuf, const ArtIRect *area, guint32 color) { - ArtIRect frame; ArtIRect target; guchar red; guchar green; @@ -443,26 +442,15 @@ nautilus_gdk_pixbuf_fill_rectangle_with_color (GdkPixbuf *pixbuf, g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + target = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, area); + if (art_irect_empty (&target)) { + return; + } pixels = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); pixel_offset = has_alpha ? 4 : 3; - - /* If an area is given, make sure its clipped to the pixbuf frame */ - if (area != NULL) { - - art_irect_intersect (&target, area, &frame); - - if (art_irect_empty (&target)) { - return; - } - /* If no area is given, then use the whole pixbuf frame */ - } else { - target = frame; - } - red = NAUTILUS_RGBA_COLOR_GET_R (color); green = NAUTILUS_RGBA_COLOR_GET_G (color); blue = NAUTILUS_RGBA_COLOR_GET_B (color); @@ -614,20 +602,6 @@ nautilus_gdk_pixbuf_unref_if_not_null (GdkPixbuf *pixbuf_or_null) } } -static ArtIRect -nautilus_gdk_window_get_frame (const GdkWindow *window) -{ - ArtIRect frame; - - g_return_val_if_fail (window != NULL, NAUTILUS_ART_IRECT_EMPTY); - - frame.x0 = 0; - frame.y0 = 0; - gdk_window_get_size ((GdkWindow *) window, &frame.x1, &frame.y1); - - return frame; -} - void nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, GdkDrawable *drawable, @@ -639,10 +613,9 @@ nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, GdkPixbufAlphaMode alpha_compositing_mode, int alpha_threshold) { - ArtIRect frame; + NautilusDimensions dimensions; ArtIRect target; ArtIRect source; - ArtIRect destination_frame; int target_width; int target_height; int source_width; @@ -659,29 +632,31 @@ nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, g_return_if_fail (alpha_compositing_mode >= GDK_PIXBUF_ALPHA_BILEVEL); g_return_if_fail (alpha_compositing_mode <= GDK_PIXBUF_ALPHA_FULL); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - destination_frame = nautilus_gdk_window_get_frame (drawable); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); g_return_if_fail (source_x >= 0); g_return_if_fail (source_y >= 0); - g_return_if_fail (source_x < (frame.x1 - frame.x0)); - g_return_if_fail (source_y < (frame.y1 - frame.y0)); - - /* Clip the destination area to the destination pixbuf frame */ - art_irect_intersect (&target, destination_area, &destination_frame); + g_return_if_fail (source_x < dimensions.width); + g_return_if_fail (source_y < dimensions.height); + + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (pixbuf, + destination_area->x0, + destination_area->y0, + destination_area); if (art_irect_empty (&target)) { - return; - } + return; + } /* Assign the source area */ nautilus_art_irect_assign (&source, source_x, source_y, - frame.x1 - frame.x0 - source_x, - frame.y1 - frame.y0 - source_y); + dimensions.width - source_x, + dimensions.height - source_y); /* Adjust the target width if the source area is smaller than the - * source pixbuf frame */ + * source pixbuf dimensions */ target_width = target.x1 - target.x0; target_height = target.y1 - target.y0; source_width = source.x1 - source.x0; @@ -718,7 +693,6 @@ nautilus_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, 0, 0); } - } /** @@ -749,10 +723,9 @@ nautilus_gdk_pixbuf_draw_to_pixbuf (const GdkPixbuf *pixbuf, int source_y, const ArtIRect *destination_area) { - ArtIRect frame; + NautilusDimensions dimensions; ArtIRect target; ArtIRect source; - ArtIRect destination_frame; int target_width; int target_height; int source_width; @@ -764,16 +737,15 @@ nautilus_gdk_pixbuf_draw_to_pixbuf (const GdkPixbuf *pixbuf, g_return_if_fail (destination_area->x1 > destination_area->x0); g_return_if_fail (destination_area->y1 > destination_area->y0); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - destination_frame = nautilus_gdk_pixbuf_get_frame (destination_pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); g_return_if_fail (source_x >= 0); g_return_if_fail (source_y >= 0); - g_return_if_fail (source_x < (frame.x1 - frame.x0)); - g_return_if_fail (source_y < (frame.y1 - frame.y0)); + g_return_if_fail (source_x < dimensions.width); + g_return_if_fail (source_y < dimensions.height); - /* Clip the destination area to the destination pixbuf frame */ - art_irect_intersect (&target, destination_area, &destination_frame); + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (destination_pixbuf, 0, 0, destination_area); if (art_irect_empty (&target)) { return; } @@ -782,11 +754,11 @@ nautilus_gdk_pixbuf_draw_to_pixbuf (const GdkPixbuf *pixbuf, nautilus_art_irect_assign (&source, source_x, source_y, - frame.x1 - frame.x0 - source_x, - frame.y1 - frame.y0 - source_y); + dimensions.width - source_x, + dimensions.height - source_y); /* Adjust the target width if the source area is smaller than the - * source pixbuf frame */ + * source pixbuf dimensions */ target_width = target.x1 - target.x0; target_height = target.y1 - target.y0; source_width = source.x1 - source.x0; @@ -840,10 +812,9 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, int opacity, GdkInterpType interpolation_mode) { - ArtIRect frame; + NautilusDimensions dimensions; ArtIRect target; ArtIRect source; - ArtIRect destination_frame; int target_width; int target_height; int source_width; @@ -859,17 +830,17 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, g_return_if_fail (interpolation_mode >= GDK_INTERP_NEAREST); g_return_if_fail (interpolation_mode <= GDK_INTERP_HYPER); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - destination_frame = nautilus_gdk_pixbuf_get_frame (destination_pixbuf); + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); g_return_if_fail (source_x >= 0); g_return_if_fail (source_y >= 0); - g_return_if_fail (source_x < (frame.x1 - frame.x0)); - g_return_if_fail (source_y < (frame.y1 - frame.y0)); + g_return_if_fail (source_x < dimensions.width); + g_return_if_fail (source_y < dimensions.height); - /* Clip the destination area to the destination pixbuf frame */ - art_irect_intersect (&target, destination_area, &destination_frame); - if (art_irect_empty (&target)) { + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + /* Clip the destination area to the pixbuf dimensions; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (destination_pixbuf, 0, 0, destination_area); + if (art_irect_empty (&target)) { return; } @@ -877,11 +848,11 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, nautilus_art_irect_assign (&source, source_x, source_y, - frame.x1 - frame.x0 - source_x, - frame.y1 - frame.y0 - source_y); + dimensions.width - source_x, + dimensions.height - source_y); /* Adjust the target width if the source area is smaller than the - * source pixbuf frame */ + * source pixbuf dimensions */ target_width = target.x1 - target.x0; target_height = target.y1 - target.y0; source_width = source.x1 - source.x0; @@ -898,8 +869,8 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_alpha (const GdkPixbuf *pixbuf, int width; int height; - width = frame.x1 - frame.x0 - source.x0; - height = frame.y1 - frame.y0 - source.y0; + width = dimensions.width - source.x0; + height = dimensions.height - source.y0; area.x0 = source.x0; area.y0 = source.y0; @@ -957,7 +928,6 @@ nautilus_gdk_pixbuf_new_from_pixbuf_sub_area (GdkPixbuf *pixbuf, const ArtIRect *area) { GdkPixbuf *sub_pixbuf; - ArtIRect frame; ArtIRect target; guchar *pixels; @@ -966,10 +936,9 @@ nautilus_gdk_pixbuf_new_from_pixbuf_sub_area (GdkPixbuf *pixbuf, g_return_val_if_fail (area->x1 > area->x0, NULL); g_return_val_if_fail (area->y1 > area->y0, NULL); - frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - - art_irect_intersect (&target, area, &frame); - if (art_irect_empty (&target)) { + /* Clip the pixbuf by the given area; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, area); + if (art_irect_empty (&target)) { return NULL; } @@ -1077,7 +1046,7 @@ typedef void (* DrawPixbufTileCallback) (const GdkPixbuf *pixbuf, /* The shared tiliing implementation */ static void pixbuf_draw_tiled (const GdkPixbuf *pixbuf, - const ArtIRect *destination_frame, + const NautilusDimensions *destination_dimensions, const ArtIRect *destination_area, int tile_width, int tile_height, @@ -1095,34 +1064,41 @@ pixbuf_draw_tiled (const GdkPixbuf *pixbuf, int num_above; g_return_if_fail (pixbuf != NULL); - g_return_if_fail (destination_frame != NULL); + g_return_if_fail (destination_dimensions != NULL); g_return_if_fail (tile_width > 0); g_return_if_fail (tile_height > 0); g_return_if_fail (tile_width <= gdk_pixbuf_get_width (pixbuf)); g_return_if_fail (tile_height <= gdk_pixbuf_get_height (pixbuf)); g_return_if_fail (callback != NULL); + /* FIXME: This is confusing. Instead of passing in the destination_dimensions + * I should just pass in the destination pixbuf, so that we can use + * nautilus_gdk_pixbuf_intersect directly on that. + */ + + /* Clip the destination area to the destination pixbuf; bail if no work */ if (destination_area != NULL) { - art_irect_intersect (&target, destination_area, destination_frame); + ArtIRect tmp; + tmp = nautilus_art_irect_assign_dimensions (0, 0, destination_dimensions); + art_irect_intersect (&target, destination_area, &tmp); + if (art_irect_empty (&target)) { return; } } else { - target = *destination_frame; + target = nautilus_art_irect_assign_dimensions (0, 0, destination_dimensions); } /* The number of tiles left and above the target area */ num_left = (target.x0 - tile_origin_x) / tile_width; num_above = (target.y0 - tile_origin_y) / tile_height; - nautilus_art_ipoint_assign (&min_point, - tile_origin_x - tile_width + (num_left * tile_width), - tile_origin_y - tile_height + (num_above * tile_height)); + min_point.x = tile_origin_x - tile_width + (num_left * tile_width); + min_point.y = tile_origin_y - tile_height + (num_above * tile_height); - nautilus_art_ipoint_assign (&max_point, - (target.x1 + 2 * tile_width), - (target.y1 + 2 * tile_height)); + max_point.x = (target.x1 + 2 * tile_width); + max_point.y = (target.y1 + 2 * tile_height); for (y = min_point.y; y <= max_point.y; y += tile_height) { for (x = min_point.x; x <= max_point.x; x += tile_width) { @@ -1236,7 +1212,7 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (const GdkPixbuf *pixbuf, GdkInterpType interpolation_mode) { PixbufTileData pixbuf_tile_data; - ArtIRect destination_frame; + NautilusDimensions destination_dimensions; g_return_if_fail (nautilus_gdk_pixbuf_is_valid (destination_pixbuf)); g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); @@ -1249,14 +1225,14 @@ nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (const GdkPixbuf *pixbuf, g_return_if_fail (interpolation_mode >= GDK_INTERP_NEAREST); g_return_if_fail (interpolation_mode <= GDK_INTERP_HYPER); - destination_frame = nautilus_gdk_pixbuf_get_frame (destination_pixbuf); + destination_dimensions = nautilus_gdk_pixbuf_get_dimensions (destination_pixbuf); pixbuf_tile_data.destination_pixbuf = destination_pixbuf; pixbuf_tile_data.opacity = opacity; pixbuf_tile_data.interpolation_mode = interpolation_mode; pixbuf_draw_tiled (pixbuf, - &destination_frame, + &destination_dimensions, destination_area, tile_width, tile_height, @@ -1298,7 +1274,7 @@ nautilus_gdk_pixbuf_draw_to_drawable_tiled (const GdkPixbuf *pixbuf, int alpha_threshold) { DrawableTileData drawable_tile_data; - ArtIRect destination_frame; + NautilusDimensions destination_dimensions; g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); g_return_if_fail (drawable != NULL); @@ -1311,7 +1287,7 @@ nautilus_gdk_pixbuf_draw_to_drawable_tiled (const GdkPixbuf *pixbuf, g_return_if_fail (alpha_compositing_mode >= GDK_PIXBUF_ALPHA_BILEVEL); g_return_if_fail (alpha_compositing_mode <= GDK_PIXBUF_ALPHA_FULL); - destination_frame = nautilus_gdk_window_get_frame (drawable); + destination_dimensions = nautilus_gdk_window_get_dimensions (drawable); drawable_tile_data.drawable = drawable; drawable_tile_data.gc = gc; @@ -1320,7 +1296,7 @@ nautilus_gdk_pixbuf_draw_to_drawable_tiled (const GdkPixbuf *pixbuf, drawable_tile_data.alpha_threshold = alpha_threshold; pixbuf_draw_tiled (pixbuf, - &destination_frame, + &destination_dimensions, destination_area, tile_width, tile_height, @@ -1500,3 +1476,107 @@ nautilus_gdk_pixbuf_get_from_window_safe (GdkWindow *window, return pixbuf; } + +/** + * nautilus_gdk_pixbuf_intersect: + * @pixbuf: A GdkPixbuf. + * @pixbuf_x: X coordinate of pixbuf. + * @pixbuf_y: Y coordinate of pixbuf. + * @rectangle: An ArtIRect or NULL. + * + * Return value: The intersection of the pixbuf and the given rectangle. + * + * If &rectangle is NULL, then the resulting rectangle is a rectangle at + * the given orign with the pixbuf's dimensions. + * + */ +ArtIRect +nautilus_gdk_pixbuf_intersect (const GdkPixbuf *pixbuf, + int pixbuf_x, + int pixbuf_y, + const ArtIRect *rectangle) +{ + ArtIRect intersection; + ArtIRect bounds; + NautilusDimensions dimensions; + + g_return_val_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf), NAUTILUS_ART_IRECT_EMPTY); + + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); + bounds = nautilus_art_irect_assign_dimensions (pixbuf_x, pixbuf_y, &dimensions); + + if (rectangle == NULL) { + return bounds; + } + + art_irect_intersect (&intersection, rectangle, &bounds); + + /* In theory, this is not needed because a rectangle is empty + * regardless of how MUCH negative the dimensions are. + * However, to make debugging and self checks simpler, we + * consistenly return a standard empty rectangle. + */ + if (art_irect_empty (&intersection)) { + return NAUTILUS_ART_IRECT_EMPTY; + } + + return intersection; +} + +#if !defined (NAUTILUS_OMIT_SELF_CHECK) + +void +nautilus_self_check_gdk_pixbuf_extensions (void) +{ + GdkPixbuf *pixbuf; + ArtIRect clip_area; + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 100); + + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gdk_pixbuf_is_valid (pixbuf), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gdk_pixbuf_is_valid (NULL), FALSE); + + NAUTILUS_CHECK_DIMENSIONS_RESULT (nautilus_gdk_pixbuf_get_dimensions (pixbuf), 100, 100); + + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, NULL), 0, 0, 100, 100); + + nautilus_art_irect_assign (&clip_area, 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 0, 0, 0, 0); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 0, 0, 100, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 100, 100); + + nautilus_art_irect_assign (&clip_area, -10, -10, 100, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 90, 90); + + nautilus_art_irect_assign (&clip_area, -10, -10, 110, 110); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 100, 100); + + nautilus_art_irect_assign (&clip_area, 0, 0, 99, 99); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 99, 99); + + nautilus_art_irect_assign (&clip_area, 0, 0, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 1, 1); + + nautilus_art_irect_assign (&clip_area, -1, -1, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, -1, -1, 2, 2); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 1, 1); + + nautilus_art_irect_assign (&clip_area, 100, 100, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 101, 101, 1, 1); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 0, 0, 0, 0); + + nautilus_art_irect_assign (&clip_area, 80, 0, 100, 100); + NAUTILUS_CHECK_RECTANGLE_RESULT (nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, &clip_area), 80, 0, 100, 100); + + gdk_pixbuf_unref (pixbuf); +} + +#endif /* !NAUTILUS_OMIT_SELF_CHECK */ diff --git a/libnautilus-private/nautilus-gdk-pixbuf-extensions.h b/libnautilus-private/nautilus-gdk-pixbuf-extensions.h index 0ab53e970..8106c74bc 100644 --- a/libnautilus-private/nautilus-gdk-pixbuf-extensions.h +++ b/libnautilus-private/nautilus-gdk-pixbuf-extensions.h @@ -163,7 +163,13 @@ GdkPixbuf * nautilus_gdk_pixbuf_get_from_window_safe (GdkWind /* Determine whether a pixbuf is valid or not */ gboolean nautilus_gdk_pixbuf_is_valid (const GdkPixbuf *pixbuf); -/* Access the dimensions of a pixbuf as a ArtIRect frame. */ -ArtIRect nautilus_gdk_pixbuf_get_frame (const GdkPixbuf *pixbuf); +/* Access the dimensions of a pixbuf. */ +NautilusDimensions nautilus_gdk_pixbuf_get_dimensions (const GdkPixbuf *pixbuf); + +/* Return the intersection of the pixbuf with the given rectangle. */ +ArtIRect nautilus_gdk_pixbuf_intersect (const GdkPixbuf *pixbuf, + int pixbuf_x, + int pixbuf_y, + const ArtIRect *rectangle); #endif /* NAUTILUS_GDK_PIXBUF_EXTENSIONS_H */ diff --git a/libnautilus-private/nautilus-glyph.c b/libnautilus-private/nautilus-glyph.c index 5abe4de14..b913a9c52 100644 --- a/libnautilus-private/nautilus-glyph.c +++ b/libnautilus-private/nautilus-glyph.c @@ -54,9 +54,9 @@ struct NautilusGlyph */ NautilusGlyph * nautilus_glyph_new (const NautilusScalableFont *font, + guint font_size, const char *text, - guint text_length, - guint font_size) + guint text_length) { NautilusGlyph *glyph; RsvgFTGlyph *rsvg_glyph; @@ -133,25 +133,23 @@ nautilus_glyph_get_height (const NautilusGlyph *glyph) } /** - * nautilus_glyph_get_frame: + * nautilus_glyph_get_dimensions: * @glyph: A NautilusGlyph. * - * Returns: An ArtIRect representing the frame occupied by the glyph. + * Returns: An ArtIRect representing the dimensions occupied by the glyph. */ -ArtIRect -nautilus_glyph_get_frame (const NautilusGlyph *glyph) +NautilusDimensions +nautilus_glyph_get_dimensions (const NautilusGlyph *glyph) { - ArtIRect glyph_frame; + NautilusDimensions glyph_dimensions; - g_return_val_if_fail (glyph != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (glyph->rsvg_glyph != NULL, NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (glyph != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (glyph->rsvg_glyph != NULL, NAUTILUS_DIMENSIONS_EMPTY); - glyph_frame.x0 = 0; - glyph_frame.y0 = 0; - glyph_frame.x1 = glyph->rsvg_glyph->width; - glyph_frame.y1 = glyph->rsvg_glyph->height; + glyph_dimensions.width = glyph->rsvg_glyph->width; + glyph_dimensions.height = glyph->rsvg_glyph->height; - return glyph_frame; + return glyph_dimensions; } /* FIXME bugzilla.eazel.com xxxx: We should really use libart @@ -213,13 +211,12 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, guchar *pixbuf_pixels; guint pixbuf_pixel_offset; gboolean pixbuf_has_alpha; - ArtIRect pixbuf_frame; - ArtIRect pixbuf_clip_area; + ArtIRect target; guchar *pixbuf_x_offset; guchar *pixbuf_y_offset; int glyph_rowstride; const guchar *glyph_buffer; - ArtIRect glyph_frame; + NautilusDimensions glyph_dimensions; ArtIRect glyph_bounds; const guchar *glyph_x_offset; const guchar *glyph_y_offset; @@ -239,33 +236,20 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, g_return_if_fail (glyph->rsvg_glyph->height > 0); g_return_if_fail (glyph->rsvg_glyph->rowstride > 0); g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); + g_return_if_fail (destination_x >= 0 && destination_x < gdk_pixbuf_get_width (pixbuf)); + g_return_if_fail (destination_y >= 0 && destination_y < gdk_pixbuf_get_height (pixbuf)); /* FIXME bugzilla.eazel.com xxxx: We currently dont handle opacities * other than 0xFF. */ g_return_if_fail (opacity == NAUTILUS_OPACITY_FULLY_OPAQUE); - - pixbuf_frame = nautilus_gdk_pixbuf_get_frame (pixbuf); - - /* Make sure destination coordinates lie within the pixbuf */ - g_return_if_fail (destination_x >= 0 && destination_x <= pixbuf_frame.x1); - g_return_if_fail (destination_y >= 0 && destination_y <= pixbuf_frame.y1); - /* If a clip area is given, make sure its not empty */ - if (clip_area != NULL) { - g_return_if_fail (clip_area != NULL); - g_return_if_fail (!art_irect_empty (clip_area)); - - /* Clip the clip_area to the pixbuf's area; bail of no work */ - art_irect_intersect (&pixbuf_clip_area, clip_area, &pixbuf_frame); - if (art_irect_empty (&pixbuf_clip_area)) { - return; - } - /* If no clip area is given, use the whole pixbuf */ - } else { - pixbuf_clip_area = pixbuf_frame; + /* Clip the pixbuf to the clip area; bail if no work */ + target = nautilus_gdk_pixbuf_intersect (pixbuf, 0, 0, clip_area); + if (art_irect_empty (&target)) { + return; } - - glyph_frame = nautilus_glyph_get_frame (glyph); + + glyph_dimensions = nautilus_glyph_get_dimensions (glyph); glyph_rowstride = glyph->rsvg_glyph->rowstride; glyph_buffer = glyph->rsvg_glyph->buf; @@ -278,15 +262,15 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, nautilus_art_irect_assign (&glyph_bounds, destination_x, destination_y, - glyph_frame.x1, - glyph_frame.y1); + glyph_dimensions.width, + glyph_dimensions.height); /* * Determine the actual render area. The render area is * the area of the glyph bounds that lies within the pixbuf * clip area; bail if no work. */ - art_irect_intersect (&render_area, &pixbuf_clip_area, &glyph_bounds); + art_irect_intersect (&render_area, &target, &glyph_bounds); if (art_irect_empty (&render_area)) { return; } @@ -294,10 +278,10 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, /* Debug code to be yanked real soon */ if (0) nautilus_debug_pixbuf_draw_rectangle_inset (pixbuf, FALSE, - pixbuf_clip_area.x0, - pixbuf_clip_area.y0, - pixbuf_clip_area.x1, - pixbuf_clip_area.y1, + target.x0, + target.y0, + target.x1, + target.y1, NAUTILUS_RGBA_COLOR_OPAQUE_GREEN, NAUTILUS_OPACITY_FULLY_OPAQUE, 0); @@ -358,12 +342,12 @@ nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, */ /* Iterate vertically */ - for (y = render_area.y0 ; y <= render_area.y1; y++) { + for (y = render_area.y0 ; y < render_area.y1; y++) { pixbuf_x_offset = pixbuf_y_offset; glyph_x_offset = glyph_y_offset; /* Iterate horizontally */ - for (x = render_area.x0 ; x <= render_area.x1; x++) { + for (x = render_area.x0 ; x < render_area.x1; x++) { const guchar point_opacity = *glyph_x_offset; /* Optimize the common fully opaque case */ diff --git a/libnautilus-private/nautilus-glyph.h b/libnautilus-private/nautilus-glyph.h index 92e76297e..ab942897b 100644 --- a/libnautilus-private/nautilus-glyph.h +++ b/libnautilus-private/nautilus-glyph.h @@ -29,26 +29,27 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <libart_lgpl/art_rect.h> #include <libnautilus-extensions/nautilus-scalable-font.h> +#include <libnautilus-extensions/nautilus-art-extensions.h> BEGIN_GNOME_DECLS typedef struct NautilusGlyph NautilusGlyph; -NautilusGlyph *nautilus_glyph_new (const NautilusScalableFont *font, - const char *text, - guint text_length, - guint font_size); -void nautilus_glyph_free (NautilusGlyph *glyph); -int nautilus_glyph_get_width (const NautilusGlyph *glyph); -int nautilus_glyph_get_height (const NautilusGlyph *glyph); -ArtIRect nautilus_glyph_get_frame (const NautilusGlyph *glyph); -void nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, - GdkPixbuf *pixbuf, - int destination_x, - int destination_y, - const ArtIRect *clip_area, - guint32 color, - int opacity); +NautilusGlyph * nautilus_glyph_new (const NautilusScalableFont *font, + guint font_size, + const char *text, + guint text_length); +void nautilus_glyph_free (NautilusGlyph *glyph); +int nautilus_glyph_get_width (const NautilusGlyph *glyph); +int nautilus_glyph_get_height (const NautilusGlyph *glyph); +NautilusDimensions nautilus_glyph_get_dimensions (const NautilusGlyph *glyph); +void nautilus_glyph_draw_to_pixbuf (const NautilusGlyph *glyph, + GdkPixbuf *pixbuf, + int destination_x, + int destination_y, + const ArtIRect *clip_area, + guint32 color, + int opacity); END_GNOME_DECLS diff --git a/libnautilus-private/nautilus-icon-factory.c b/libnautilus-private/nautilus-icon-factory.c index 5d447a02d..409ef7d0e 100644 --- a/libnautilus-private/nautilus-icon-factory.c +++ b/libnautilus-private/nautilus-icon-factory.c @@ -2404,7 +2404,6 @@ embed_text (GdkPixbuf *pixbuf_without_text, embedded_text_rect->y0, embedded_text_rect, EMBEDDED_TEXT_FONT_SIZE, - EMBEDDED_TEXT_FONT_SIZE, text, GTK_JUSTIFY_LEFT, EMBEDDED_TEXT_LINE_OFFSET, diff --git a/libnautilus-private/nautilus-image-table.c b/libnautilus-private/nautilus-image-table.c index 69b8e64f0..610bf3d06 100644 --- a/libnautilus-private/nautilus-image-table.c +++ b/libnautilus-private/nautilus-image-table.c @@ -401,7 +401,8 @@ image_table_clear_dirty_areas (NautilusImageTable *image_table) { GtkWidget *widget; NautilusRegion *region; - ArtIRect bounds; + NautilusDimensions dimensions; + ArtIRect whole_region; GdkGC *gc; g_return_if_fail (NAUTILUS_IS_WRAP_TABLE (image_table)); @@ -409,10 +410,11 @@ image_table_clear_dirty_areas (NautilusImageTable *image_table) widget = GTK_WIDGET (image_table); - bounds = nautilus_irect_gtk_widget_get_frame (widget->parent); + dimensions = nautilus_gtk_widget_get_dimensions (widget->parent); + whole_region = nautilus_art_irect_assign_dimensions (0, 0, &dimensions); region = nautilus_region_new (); - nautilus_region_add_rectangle (region, &bounds); + nautilus_region_add_rectangle (region, &whole_region); gc = image_table_peek_clear_gc (image_table); @@ -423,10 +425,10 @@ image_table_clear_dirty_areas (NautilusImageTable *image_table) gdk_draw_rectangle (widget->window, gc, TRUE, - bounds.x0, - bounds.y0, - bounds.x1 - bounds.x0, - bounds.y1 - bounds.y0); + 0, + 0, + dimensions.width, + dimensions.height); nautilus_region_free (region); } @@ -558,7 +560,7 @@ ancestor_leave_notify_event (GtkWidget *widget, g_return_val_if_fail (NAUTILUS_IS_IMAGE_TABLE (event_data), FALSE); g_return_val_if_fail (event != NULL, FALSE); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (event_data)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (event_data)); if (nautilus_art_irect_contains_point (&bounds, event->x, event->y)) { x = event->x; diff --git a/libnautilus-private/nautilus-image.c b/libnautilus-private/nautilus-image.c index 173b1d340..36251e4ee 100644 --- a/libnautilus-private/nautilus-image.c +++ b/libnautilus-private/nautilus-image.c @@ -86,30 +86,30 @@ struct _NautilusImageDetails }; /* GtkObjectClass methods */ -static void nautilus_image_initialize_class (NautilusImageClass *image_class); -static void nautilus_image_initialize (NautilusImage *image); -static void nautilus_image_destroy (GtkObject *object); -static void nautilus_image_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_image_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_image_initialize_class (NautilusImageClass *image_class); +static void nautilus_image_initialize (NautilusImage *image); +static void nautilus_image_destroy (GtkObject *object); +static void nautilus_image_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_image_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_image_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int nautilus_image_expose_event (GtkWidget *widget, - GdkEventExpose *event); +static void nautilus_image_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static int nautilus_image_expose_event (GtkWidget *widget, + GdkEventExpose *event); /* NautilusImage signals */ -static void nautilus_image_set_is_smooth_signal (GtkWidget *widget, - gboolean is_smooth); +static void nautilus_image_set_is_smooth_signal (GtkWidget *widget, + gboolean is_smooth); /* Private NautilusImage methods */ -static ArtIRect image_get_pixbuf_frame (const NautilusImage *image); -static ArtIRect image_get_pixbuf_bounds (const NautilusImage *image); -static ArtIRect image_get_tile_frame (const NautilusImage *image); -static gboolean image_is_smooth (const NautilusImage *image); +static NautilusDimensions image_get_pixbuf_dimensions (const NautilusImage *image); +static ArtIRect image_get_pixbuf_bounds (const NautilusImage *image); +static NautilusDimensions image_get_tile_dimensions (const NautilusImage *image); +static gboolean image_is_smooth (const NautilusImage *image); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusImage, nautilus_image, GTK_TYPE_MISC) @@ -364,24 +364,24 @@ nautilus_image_size_request (GtkWidget *widget, { NautilusImage *image; - ArtIRect pixbuf_frame; - ArtIRect tile_frame; - ArtIRect preferred_frame; - + NautilusDimensions pixbuf_dimensions; + NautilusDimensions tile_dimensions; + NautilusDimensions preferred_dimensions; + g_return_if_fail (NAUTILUS_IS_IMAGE (widget)); g_return_if_fail (requisition != NULL); - + image = NAUTILUS_IMAGE (widget); - pixbuf_frame = image_get_pixbuf_frame (image); - tile_frame = image_get_tile_frame (image); - preferred_frame = nautilus_smooth_widget_get_preferred_frame (widget, - &pixbuf_frame, - &tile_frame, - image->details->tile_width, - image->details->tile_height); - requisition->width = preferred_frame.x1; - requisition->height = preferred_frame.y1; + pixbuf_dimensions = image_get_pixbuf_dimensions (image); + tile_dimensions = image_get_tile_dimensions (image); + preferred_dimensions = nautilus_smooth_widget_get_preferred_dimensions (widget, + &pixbuf_dimensions, + &tile_dimensions, + image->details->tile_width, + image->details->tile_height); + requisition->width = preferred_dimensions.width; + requisition->height = preferred_dimensions.height; } static void @@ -475,8 +475,8 @@ nautilus_image_expose_event (GtkWidget *widget, } /* Clip the dirty area to the screen */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); - screen_dirty_area = nautilus_irect_gdk_window_clip_dirty_area_to_screen (event->window, + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); + screen_dirty_area = nautilus_gdk_window_clip_dirty_area_to_screen (event->window, &dirty_area); /* Nothing to do */ if (art_irect_empty (&screen_dirty_area)) { @@ -515,68 +515,64 @@ nautilus_image_set_is_smooth_signal (GtkWidget *widget, } /* Private NautilusImage methods */ -static ArtIRect -image_get_pixbuf_frame (const NautilusImage *image) +static NautilusDimensions +image_get_pixbuf_dimensions (const NautilusImage *image) { - ArtIRect pixbuf_frame; + NautilusDimensions pixbuf_dimensions; - g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_DIMENSIONS_EMPTY); if (!image->details->pixbuf) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } - pixbuf_frame.x0 = 0; - pixbuf_frame.y0 = 0; - pixbuf_frame.x1 = gdk_pixbuf_get_width (image->details->pixbuf); - pixbuf_frame.y1 = gdk_pixbuf_get_height (image->details->pixbuf); + pixbuf_dimensions.width = gdk_pixbuf_get_width (image->details->pixbuf); + pixbuf_dimensions.height = gdk_pixbuf_get_height (image->details->pixbuf); - return pixbuf_frame; + return pixbuf_dimensions; } static ArtIRect image_get_pixbuf_bounds (const NautilusImage *image) { - ArtIRect pixbuf_frame; + NautilusDimensions pixbuf_dimensions; ArtIRect pixbuf_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY); - pixbuf_frame = image_get_pixbuf_frame (image); + pixbuf_dimensions = image_get_pixbuf_dimensions (image); - if (art_irect_empty (&pixbuf_frame)) { + if (nautilus_dimensions_empty (&pixbuf_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (image)); pixbuf_bounds = nautilus_art_irect_align (&bounds, - pixbuf_frame.x1, - pixbuf_frame.y1, + pixbuf_dimensions.width, + pixbuf_dimensions.height, GTK_MISC (image)->xalign, GTK_MISC (image)->yalign); return pixbuf_bounds; } -static ArtIRect -image_get_tile_frame (const NautilusImage *image) +static NautilusDimensions +image_get_tile_dimensions (const NautilusImage *image) { - ArtIRect tile_frame; + NautilusDimensions tile_dimensions; - g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NAUTILUS_DIMENSIONS_EMPTY); if (!image->details->tile_pixbuf) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } + + tile_dimensions.width = gdk_pixbuf_get_width (image->details->tile_pixbuf); + tile_dimensions.height = gdk_pixbuf_get_height (image->details->tile_pixbuf); - tile_frame.x0 = 0; - tile_frame.y0 = 0; - tile_frame.x1 = gdk_pixbuf_get_width (image->details->tile_pixbuf); - tile_frame.y1 = gdk_pixbuf_get_height (image->details->tile_pixbuf); - - return tile_frame; + return tile_dimensions; } gboolean diff --git a/libnautilus-private/nautilus-label.c b/libnautilus-private/nautilus-label.c index 3629b17e9..520eeee3d 100644 --- a/libnautilus-private/nautilus-label.c +++ b/libnautilus-private/nautilus-label.c @@ -108,15 +108,14 @@ struct _NautilusLabelDetails guint32 smooth_text_color; guint smooth_drop_shadow_offset; guint32 smooth_drop_shadow_color; - guint smooth_line_wrap_width; + int smooth_line_wrap_width; gboolean adjust_wrap_on_resize; /* Text */ int text_opacity; /* Text lines */ - int *text_line_widths; - int *text_line_heights; + NautilusDimensions *text_line_dimensions; int num_text_lines; int max_text_line_width; int total_text_line_height; @@ -133,46 +132,46 @@ struct _NautilusLabelDetails }; /* GtkObjectClass methods */ -static void nautilus_label_initialize_class (NautilusLabelClass *label_class); -static void nautilus_label_initialize (NautilusLabel *label); -static void nautilus_label_destroy (GtkObject *object); -static void nautilus_label_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_label_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_label_initialize_class (NautilusLabelClass *label_class); +static void nautilus_label_initialize (NautilusLabel *label); +static void nautilus_label_destroy (GtkObject *object); +static void nautilus_label_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_label_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_label_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void nautilus_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static int nautilus_label_expose_event (GtkWidget *widget, - GdkEventExpose *event); +static void nautilus_label_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static void nautilus_label_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static int nautilus_label_expose_event (GtkWidget *widget, + GdkEventExpose *event); /* NautilusLabel signals */ -static void nautilus_label_set_is_smooth_signal (GtkWidget *widget, - gboolean is_smooth); +static void nautilus_label_set_is_smooth_signal (GtkWidget *widget, + gboolean is_smooth); /* Private NautilusLabel things */ -const char * label_peek_text (const NautilusLabel *label); -static void label_line_geometries_recompute (NautilusLabel *label); -static void label_line_geometries_clear (NautilusLabel *label); -static guint label_get_empty_line_height (const NautilusLabel *label); -static guint label_get_total_text_and_line_offset_height (const NautilusLabel *label); -static ArtIRect label_get_text_bounds (const NautilusLabel *label); -static ArtIRect label_get_text_frame (const NautilusLabel *label); -static ArtIRect label_get_tile_frame (const NautilusLabel *label); -static void label_draw_text_to_pixbuf (NautilusLabel *label, - GdkPixbuf *pixbuf, - const ArtIRect *destination_area, - int x, - int y); -static guint label_get_default_line_wrap_width (const NautilusLabel *label); -static void label_solid_cache_pixbuf_clear (NautilusLabel *label); -static gboolean label_can_cache_contents (const NautilusLabel *label); -static gboolean label_is_smooth (const NautilusLabel *label); +const char * label_peek_text (const NautilusLabel *label); +static void label_line_geometries_recompute (NautilusLabel *label); +static void label_line_geometries_clear (NautilusLabel *label); +static guint label_get_empty_line_height (const NautilusLabel *label); +static guint label_get_total_text_and_line_offset_height (const NautilusLabel *label); +static ArtIRect label_get_text_bounds (const NautilusLabel *label); +static NautilusDimensions label_get_text_dimensions (const NautilusLabel *label); +static NautilusDimensions label_get_tile_dimensions (const NautilusLabel *label); +static void label_draw_text_to_pixbuf (NautilusLabel *label, + GdkPixbuf *pixbuf, + const ArtIRect *destination_area, + int x, + int y); +static int label_get_default_line_wrap_width (const NautilusLabel *label); +static void label_solid_cache_pixbuf_clear (NautilusLabel *label); +static gboolean label_can_cache_contents (const NautilusLabel *label); +static gboolean label_is_smooth (const NautilusLabel *label); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabel, nautilus_label, GTK_TYPE_LABEL) @@ -288,7 +287,7 @@ nautilus_label_initialize_class (NautilusLabelClass *label_class) GTK_ARG_READWRITE, ARG_SMOOTH_DROP_SHADOW_COLOR); gtk_object_add_arg_type ("NautilusLabel::smooth_line_wrap_width", - GTK_TYPE_UINT, + GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_SMOOTH_LINE_WRAP_WIDTH); @@ -429,7 +428,7 @@ nautilus_label_set_arg (GtkObject *object, break; case ARG_SMOOTH_LINE_WRAP_WIDTH: - nautilus_label_set_smooth_line_wrap_width (label, GTK_VALUE_UINT (*arg)); + nautilus_label_set_smooth_line_wrap_width (label, GTK_VALUE_INT (*arg)); break; case ARG_ADJUST_WRAP_ON_RESIZE: @@ -524,7 +523,7 @@ nautilus_label_get_arg (GtkObject *object, break; case ARG_SMOOTH_LINE_WRAP_WIDTH: - GTK_VALUE_UINT (*arg) = nautilus_label_get_smooth_line_wrap_width (label); + GTK_VALUE_INT (*arg) = nautilus_label_get_smooth_line_wrap_width (label); break; case ARG_ADJUST_WRAP_ON_RESIZE: @@ -543,10 +542,10 @@ nautilus_label_size_request (GtkWidget *widget, { NautilusLabel *label; - ArtIRect text_frame; - ArtIRect tile_frame; - ArtIRect preferred_frame; - + NautilusDimensions text_dimensions; + NautilusDimensions tile_dimensions; + NautilusDimensions preferred_dimensions; + g_return_if_fail (NAUTILUS_IS_LABEL (widget)); g_return_if_fail (requisition != NULL); @@ -557,16 +556,16 @@ nautilus_label_size_request (GtkWidget *widget, return; } - text_frame = label_get_text_frame (label); - tile_frame = label_get_tile_frame (label); + text_dimensions = label_get_text_dimensions (label); + tile_dimensions = label_get_tile_dimensions (label); - preferred_frame = nautilus_smooth_widget_get_preferred_frame (widget, - &text_frame, - &tile_frame, - label->details->tile_width, - label->details->tile_height); - requisition->width = preferred_frame.x1; - requisition->height = preferred_frame.y1; + preferred_dimensions = nautilus_smooth_widget_get_preferred_dimensions (widget, + &text_dimensions, + &tile_dimensions, + label->details->tile_width, + label->details->tile_height); + requisition->width = preferred_dimensions.width; + requisition->height = preferred_dimensions.height; } static void @@ -584,7 +583,7 @@ nautilus_label_size_allocate (GtkWidget *widget, NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, size_allocate, (widget, allocation)); if (label->details->adjust_wrap_on_resize) { - label->details->smooth_line_wrap_width = allocation->width; + label->details->smooth_line_wrap_width = (int) allocation->width; label_line_geometries_recompute (label); } } @@ -626,13 +625,14 @@ label_composite_pixbuf_callback (GtkWidget *widget, gpointer callback_data) { NautilusLabel *label; - ArtIRect text_frame; + NautilusDimensions text_dimensions; ArtIRect text_bounds; ArtIRect workaround_buffer_area; GdkPixbuf *pixbuf; GdkEventExpose *event; ArtIRect text_dirty_area; ArtIRect dirty_area; + ArtIRect tmp; g_return_if_fail (NAUTILUS_IS_LABEL (widget)); g_return_if_fail (GTK_WIDGET_REALIZED (widget)); @@ -642,27 +642,29 @@ label_composite_pixbuf_callback (GtkWidget *widget, label = NAUTILUS_LABEL (widget); event = (GdkEventExpose *) callback_data; - text_frame = label_get_text_frame (label); + text_dimensions = label_get_text_dimensions (label); text_bounds = label_get_text_bounds (label); - g_return_if_fail (!art_irect_empty (&text_frame)); + g_return_if_fail (!nautilus_dimensions_empty (&text_dimensions)); /* Optimize the case where the background is solid */ if (label_can_cache_contents (label)) { if (label->details->solid_cache_pixbuf == NULL) { + ArtIRect tmp; label->details->solid_cache_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, - text_frame.x1, - text_frame.y1); + text_dimensions.width, + text_dimensions.height); nautilus_gdk_pixbuf_fill_rectangle_with_color (label->details->solid_cache_pixbuf, NULL, label->details->solid_background_color); + tmp = nautilus_art_irect_assign_dimensions (0, 0, &text_dimensions); label_draw_text_to_pixbuf (label, label->details->solid_cache_pixbuf, - &text_frame, + &tmp, 0, 0); } @@ -681,7 +683,7 @@ label_composite_pixbuf_callback (GtkWidget *widget, * content dirty rectangle. We compute it now to workaround * bug 2784. See fixme below. */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); art_irect_intersect (&text_dirty_area, &text_bounds, &dirty_area); /* FIXME bugzilla.eazel.com 2784: @@ -691,7 +693,7 @@ label_composite_pixbuf_callback (GtkWidget *widget, * that prevents clipping from happening when drawing smooth * text. */ - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, text_frame.x1, text_frame.y1); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, text_dimensions.width, text_dimensions.height); /* Copy the dirty bits out of the destination to our temporary buffer */ workaround_buffer_area.x0 = text_dirty_area.x0 - text_bounds.x0; @@ -709,9 +711,10 @@ label_composite_pixbuf_callback (GtkWidget *widget, * bug 2784 is fixed, we can simply pass this function a * clip rectangle and lose the temporary buffer code above */ + tmp = nautilus_art_irect_assign_dimensions (0, 0, &text_dimensions); label_draw_text_to_pixbuf (label, pixbuf, - &text_frame, + &tmp, 0, 0); @@ -758,7 +761,7 @@ nautilus_label_expose_event (GtkWidget *widget, * expose event so that we feed the exact exposure area * to GtkLabel's expose_event. */ - widget_bounds = nautilus_irect_gtk_widget_get_bounds (widget); + widget_bounds = nautilus_gtk_widget_get_bounds (widget); smooth_text_bounds = label_get_text_bounds (label); tile_bounds = nautilus_smooth_widget_get_tile_bounds (widget, label->details->tile_pixbuf, @@ -771,8 +774,8 @@ nautilus_label_expose_event (GtkWidget *widget, } /* Clip the dirty area to the screen */ - dirty_area = nautilus_irect_assign_gdk_rectangle (&event->area); - screen_dirty_area = nautilus_irect_gdk_window_clip_dirty_area_to_screen (event->window, + dirty_area = nautilus_gdk_rectangle_to_art_irect (&event->area); + screen_dirty_area = nautilus_gdk_window_clip_dirty_area_to_screen (event->window, &dirty_area); /* Make sure the area is screen visible before painting */ @@ -816,17 +819,17 @@ label_draw_text_to_pixbuf (NautilusLabel *label, int x, int y) { - ArtIRect pixbuf_frame; + NautilusDimensions pixbuf_dimensions; g_return_if_fail (NAUTILUS_IS_LABEL (label)); g_return_if_fail (destination_area != NULL); g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf)); g_return_if_fail (!art_irect_empty (destination_area)); - pixbuf_frame = nautilus_gdk_pixbuf_get_frame (pixbuf); + pixbuf_dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); - g_return_if_fail (pixbuf_frame.x1 >= (destination_area->x1 - destination_area->x0)); - g_return_if_fail (pixbuf_frame.y1 >= (destination_area->y1 - destination_area->y0)); + g_return_if_fail (pixbuf_dimensions.width >= (destination_area->x1 - destination_area->x0)); + g_return_if_fail (pixbuf_dimensions.height >= (destination_area->y1 - destination_area->y0)); /* Line wrapping */ if (nautilus_label_get_wrap (label)) { @@ -863,14 +866,12 @@ label_draw_text_to_pixbuf (NautilusLabel *label, label->details->smooth_font, pixbuf, x + label->details->smooth_drop_shadow_offset, - x + label->details->smooth_drop_shadow_offset, + y + label->details->smooth_drop_shadow_offset, destination_area, label->details->smooth_font_size, - label->details->smooth_font_size, label_peek_text (label), label->details->num_text_lines, - label->details->text_line_widths, - label->details->text_line_heights, + label->details->text_line_dimensions, nautilus_label_get_text_justify (label), LINE_OFFSET, label_get_empty_line_height (label), @@ -885,11 +886,9 @@ label_draw_text_to_pixbuf (NautilusLabel *label, y, destination_area, label->details->smooth_font_size, - label->details->smooth_font_size, label_peek_text (label), label->details->num_text_lines, - label->details->text_line_widths, - label->details->text_line_heights, + label->details->text_line_dimensions, nautilus_label_get_text_justify (label), LINE_OFFSET, label_get_empty_line_height (label), @@ -898,66 +897,58 @@ label_draw_text_to_pixbuf (NautilusLabel *label, } } -static guint +static int label_get_default_line_wrap_width (const NautilusLabel *label) { - guint width; - guint height; - g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0); - nautilus_scalable_font_measure_text (label->details->smooth_font, - label->details->smooth_font_size, - label->details->smooth_font_size, - DEFAULT_LINE_WRAP_WIDTH_TEXT, - strlen (DEFAULT_LINE_WRAP_WIDTH_TEXT), - &width, - &height); - - return width; + return nautilus_scalable_font_text_width (label->details->smooth_font, + label->details->smooth_font_size, + DEFAULT_LINE_WRAP_WIDTH_TEXT, + strlen (DEFAULT_LINE_WRAP_WIDTH_TEXT)); } -static ArtIRect -label_get_text_frame (const NautilusLabel *label) +static NautilusDimensions +label_get_text_dimensions (const NautilusLabel *label) { - ArtIRect text_frame; + NautilusDimensions text_dimensions; - g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_DIMENSIONS_EMPTY); - text_frame = NAUTILUS_ART_IRECT_EMPTY; + text_dimensions = NAUTILUS_DIMENSIONS_EMPTY; if (label->details->num_text_lines > 0) { - text_frame.x1 = + text_dimensions.width = label->details->max_text_line_width + label->details->smooth_drop_shadow_offset; - text_frame.y1 = label_get_total_text_and_line_offset_height (label) + text_dimensions.height = label_get_total_text_and_line_offset_height (label) + label->details->smooth_drop_shadow_offset; } - - return text_frame; + + return text_dimensions; } static ArtIRect label_get_text_bounds (const NautilusLabel *label) { - ArtIRect text_frame; + NautilusDimensions text_dimensions; ArtIRect text_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_ART_IRECT_EMPTY); - text_frame = label_get_text_frame (label); + text_dimensions = label_get_text_dimensions (label); - if (art_irect_empty (&text_frame)) { + if (nautilus_dimensions_empty (&text_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (label)); - + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (label)); + text_bounds = nautilus_art_irect_align (&bounds, - text_frame.x1, - text_frame.y1, + text_dimensions.width, + text_dimensions.height, GTK_MISC (label)->xalign, GTK_MISC (label)->yalign); @@ -965,23 +956,21 @@ label_get_text_bounds (const NautilusLabel *label) return text_bounds; } -static ArtIRect -label_get_tile_frame (const NautilusLabel *label) +static NautilusDimensions +label_get_tile_dimensions (const NautilusLabel *label) { - ArtIRect tile_frame; + NautilusDimensions tile_dimensions; - g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NAUTILUS_DIMENSIONS_EMPTY); if (!label->details->tile_pixbuf) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } + + tile_dimensions.width = gdk_pixbuf_get_width (label->details->tile_pixbuf); + tile_dimensions.height = gdk_pixbuf_get_height (label->details->tile_pixbuf); - tile_frame.x0 = 0; - tile_frame.y0 = 0; - tile_frame.x1 = gdk_pixbuf_get_width (label->details->tile_pixbuf); - tile_frame.y1 = gdk_pixbuf_get_height (label->details->tile_pixbuf); - - return tile_frame; + return tile_dimensions; } static void @@ -1041,10 +1030,8 @@ label_line_geometries_clear (NautilusLabel *label) { g_return_if_fail (NAUTILUS_IS_LABEL (label)); - g_free (label->details->text_line_widths); - g_free (label->details->text_line_heights); - label->details->text_line_widths = NULL; - label->details->text_line_heights = NULL; + g_free (label->details->text_line_dimensions); + label->details->text_line_dimensions = NULL; if (label->details->text_layouts != NULL) { int i; @@ -1110,26 +1097,22 @@ label_line_geometries_recompute (NautilusLabel *label) label->details->total_text_line_height += label->details->text_layouts[i]->height; - if (label->details->text_layouts[i]->width > label->details->max_text_line_width) { - label->details->max_text_line_width = label->details->text_layouts[i]->width; - } + label->details->max_text_line_width = MAX (label->details->max_text_line_width, + label->details->text_layouts[i]->width); } g_strfreev (pieces); } /* No line wrapping */ else { - label->details->text_line_widths = g_new (guint, label->details->num_text_lines); - label->details->text_line_heights = g_new (guint, label->details->num_text_lines); + label->details->text_line_dimensions = g_new (NautilusDimensions, label->details->num_text_lines); nautilus_scalable_font_measure_text_lines (label->details->smooth_font, label->details->smooth_font_size, - label->details->smooth_font_size, text, label->details->num_text_lines, label_get_empty_line_height (label), - label->details->text_line_widths, - label->details->text_line_heights, + label->details->text_line_dimensions, &label->details->max_text_line_width, &label->details->total_text_line_height); } @@ -1567,7 +1550,7 @@ nautilus_label_get_solid_background_color (const NautilusLabel *label) */ void nautilus_label_set_smooth_line_wrap_width (NautilusLabel *label, - guint line_wrap_width) + int line_wrap_width) { g_return_if_fail (NAUTILUS_IS_LABEL (label)); @@ -1590,7 +1573,7 @@ nautilus_label_set_smooth_line_wrap_width (NautilusLabel *label, * Return value: A boolean value indicating whether the label * is currently line wrapping text. */ -guint +int nautilus_label_get_smooth_line_wrap_width (const NautilusLabel *label) { g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE); diff --git a/libnautilus-private/nautilus-label.h b/libnautilus-private/nautilus-label.h index af6e4f367..b7d3cda15 100644 --- a/libnautilus-private/nautilus-label.h +++ b/libnautilus-private/nautilus-label.h @@ -88,8 +88,8 @@ void nautilus_label_set_smooth_drop_shadow_color (Naut guint32 color); guint32 nautilus_label_get_smooth_drop_shadow_color (const NautilusLabel *label); void nautilus_label_set_smooth_line_wrap_width (NautilusLabel *label, - guint line_wrap_width); -guint nautilus_label_get_smooth_line_wrap_width (const NautilusLabel *label); + int line_wrap_width); +int nautilus_label_get_smooth_line_wrap_width (const NautilusLabel *label); void nautilus_label_set_text (NautilusLabel *label, const char *text); char* nautilus_label_get_text (const NautilusLabel *label); diff --git a/libnautilus-private/nautilus-labeled-image.c b/libnautilus-private/nautilus-labeled-image.c index c53d59e4d..6aa2dea22 100644 --- a/libnautilus-private/nautilus-labeled-image.c +++ b/libnautilus-private/nautilus-labeled-image.c @@ -78,45 +78,45 @@ struct _NautilusLabeledImageDetails }; /* GtkObjectClass methods */ -static void nautilus_labeled_image_initialize_class (NautilusLabeledImageClass *labeled_image_class); -static void nautilus_labeled_image_initialize (NautilusLabeledImage *image); -static void nautilus_labeled_image_destroy (GtkObject *object); -static void nautilus_labeled_image_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_labeled_image_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_labeled_image_initialize_class (NautilusLabeledImageClass *labeled_image_class); +static void nautilus_labeled_image_initialize (NautilusLabeledImage *image); +static void nautilus_labeled_image_destroy (GtkObject *object); +static void nautilus_labeled_image_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_labeled_image_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_labeled_image_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int nautilus_labeled_image_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void nautilus_labeled_image_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void nautilus_labeled_image_map (GtkWidget *widget); -static void nautilus_labeled_image_unmap (GtkWidget *widget); +static void nautilus_labeled_image_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static int nautilus_labeled_image_expose_event (GtkWidget *widget, + GdkEventExpose *event); +static void nautilus_labeled_image_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static void nautilus_labeled_image_map (GtkWidget *widget); +static void nautilus_labeled_image_unmap (GtkWidget *widget); /* GtkContainerClass methods */ -static void nautilus_labeled_image_add (GtkContainer *container, - GtkWidget *widget); -static void nautilus_labeled_image_remove (GtkContainer *container, - GtkWidget *widget); -static void nautilus_labeled_image_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); +static void nautilus_labeled_image_add (GtkContainer *container, + GtkWidget *widget); +static void nautilus_labeled_image_remove (GtkContainer *container, + GtkWidget *widget); +static void nautilus_labeled_image_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data); /* Private NautilusLabeledImage methods */ -static ArtIRect labeled_image_get_image_frame (const NautilusLabeledImage *labeled_image); -static ArtIRect labeled_image_get_label_frame (const NautilusLabeledImage *labeled_image); -static void labeled_image_ensure_label (NautilusLabeledImage *labeled_image); -static void labeled_image_ensure_image (NautilusLabeledImage *labeled_image); -static ArtIRect labeled_image_get_content_bounds (const NautilusLabeledImage *labeled_image); -static ArtIRect labeled_image_get_content_frame (const NautilusLabeledImage *labeled_image); -static void labeled_image_update_alignments (NautilusLabeledImage *labeled_image); -static gboolean labeled_image_show_label (const NautilusLabeledImage *labeled_image); -static gboolean labeled_image_show_image (const NautilusLabeledImage *labeled_image); +static NautilusDimensions labeled_image_get_image_dimensions (const NautilusLabeledImage *labeled_image); +static NautilusDimensions labeled_image_get_label_dimensions (const NautilusLabeledImage *labeled_image); +static void labeled_image_ensure_label (NautilusLabeledImage *labeled_image); +static void labeled_image_ensure_image (NautilusLabeledImage *labeled_image); +static ArtIRect labeled_image_get_content_bounds (const NautilusLabeledImage *labeled_image); +static NautilusDimensions labeled_image_get_content_dimensions (const NautilusLabeledImage *labeled_image); +static void labeled_image_update_alignments (NautilusLabeledImage *labeled_image); +static gboolean labeled_image_show_label (const NautilusLabeledImage *labeled_image); +static gboolean labeled_image_show_image (const NautilusLabeledImage *labeled_image); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabeledImage, nautilus_labeled_image, GTK_TYPE_CONTAINER) @@ -354,21 +354,21 @@ nautilus_labeled_image_size_request (GtkWidget *widget, GtkRequisition *requisition) { NautilusLabeledImage *labeled_image; - ArtIRect content_frame; + NautilusDimensions content_dimensions; g_return_if_fail (NAUTILUS_IS_LABELED_IMAGE (widget)); g_return_if_fail (requisition != NULL); labeled_image = NAUTILUS_LABELED_IMAGE (widget); - content_frame = labeled_image_get_content_frame (labeled_image); + content_dimensions = labeled_image_get_content_dimensions (labeled_image); requisition->width = - MAX (1, content_frame.x1) + + MAX (1, content_dimensions.width) + 2 * labeled_image->details->x_padding; requisition->height = - MAX (1, content_frame.y1) + + MAX (1, content_dimensions.height) + 2 * labeled_image->details->y_padding; } @@ -583,68 +583,64 @@ nautilus_labeled_image_forall (GtkContainer *container, } /* Private NautilusLabeledImage methods */ -static ArtIRect -labeled_image_get_image_frame (const NautilusLabeledImage *labeled_image) +static NautilusDimensions +labeled_image_get_image_dimensions (const NautilusLabeledImage *labeled_image) { - ArtIRect image_frame; + NautilusDimensions image_dimensions; GtkRequisition image_requisition; - g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_DIMENSIONS_EMPTY); if (!labeled_image_show_image (labeled_image)) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } - + gtk_widget_size_request (labeled_image->details->image, &image_requisition); - image_frame.x0 = 0; - image_frame.y0 = 0; - image_frame.x1 = (int) image_requisition.width; - image_frame.y1 = (int) image_requisition.height; + image_dimensions.width = (int) image_requisition.width; + image_dimensions.height = (int) image_requisition.height; - return image_frame; + return image_dimensions; } -static ArtIRect -labeled_image_get_label_frame (const NautilusLabeledImage *labeled_image) +static NautilusDimensions +labeled_image_get_label_dimensions (const NautilusLabeledImage *labeled_image) { - ArtIRect label_frame; + NautilusDimensions label_dimensions; GtkRequisition label_requisition; - g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_DIMENSIONS_EMPTY); if (!labeled_image_show_label (labeled_image)) { - return NAUTILUS_ART_IRECT_EMPTY; + return NAUTILUS_DIMENSIONS_EMPTY; } - + gtk_widget_size_request (labeled_image->details->label, &label_requisition); - label_frame.x0 = 0; - label_frame.y0 = 0; - label_frame.x1 = (int) label_requisition.width; - label_frame.y1 = (int) label_requisition.height; + label_dimensions.width = (int) label_requisition.width; + label_dimensions.height = (int) label_requisition.height; - return label_frame; + return label_dimensions; } static ArtIRect labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) { ArtIRect image_bounds; - ArtIRect image_frame; + NautilusDimensions image_dimensions; ArtIRect content_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); - image_frame = labeled_image_get_image_frame (labeled_image); + image_dimensions = labeled_image_get_image_dimensions (labeled_image); - if (art_irect_empty (&image_frame)) { + if (nautilus_dimensions_empty (&image_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } content_bounds = labeled_image_get_content_bounds (labeled_image); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); if (!labeled_image_show_label (labeled_image)) { image_bounds = bounds; @@ -652,7 +648,7 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) switch (labeled_image->details->label_position) { case GTK_POS_LEFT: image_bounds.y0 = bounds.y0; - image_bounds.x0 = content_bounds.x1 - image_frame.x1; + image_bounds.x0 = content_bounds.x1 - image_dimensions.width; image_bounds.y1 = bounds.y1; image_bounds.x1 = bounds.x1; break; @@ -661,12 +657,12 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) image_bounds.y0 = bounds.y0; image_bounds.x0 = bounds.x0; image_bounds.y1 = bounds.y1; - image_bounds.x1 = content_bounds.x0 + image_frame.x1; + image_bounds.x1 = content_bounds.x0 + image_dimensions.width; break; case GTK_POS_TOP: image_bounds.x0 = bounds.x0; - image_bounds.y0 = content_bounds.y1 - image_frame.y1; + image_bounds.y0 = content_bounds.y1 - image_dimensions.height; image_bounds.x1 = bounds.x1; image_bounds.y1 = bounds.y1; break; @@ -675,7 +671,7 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) image_bounds.x0 = bounds.x0; image_bounds.y0 = bounds.y0; image_bounds.x1 = bounds.x1; - image_bounds.y1 = content_bounds.y0 + image_frame.y1; + image_bounds.y1 = content_bounds.y0 + image_dimensions.height; break; } } @@ -686,7 +682,7 @@ labeled_image_get_image_bounds_fill (const NautilusLabeledImage *labeled_image) ArtIRect nautilus_labeled_image_get_image_bounds (const NautilusLabeledImage *labeled_image) { - ArtIRect image_frame; + NautilusDimensions image_dimensions; ArtIRect image_bounds; ArtIRect content_bounds; @@ -696,9 +692,9 @@ nautilus_labeled_image_get_image_bounds (const NautilusLabeledImage *labeled_ima return labeled_image_get_image_bounds_fill (labeled_image); } - image_frame = labeled_image_get_image_frame (labeled_image); + image_dimensions = labeled_image_get_image_dimensions (labeled_image); - if (art_irect_empty (&image_frame)) { + if (nautilus_dimensions_empty (&image_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } @@ -707,44 +703,44 @@ nautilus_labeled_image_get_image_bounds (const NautilusLabeledImage *labeled_ima if (!labeled_image_show_label (labeled_image)) { image_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - image_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - image_dimensions.width) / 2; image_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - image_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - image_dimensions.height) / 2; } else { switch (labeled_image->details->label_position) { case GTK_POS_LEFT: - image_bounds.x0 = content_bounds.x1 - image_frame.x1; + image_bounds.x0 = content_bounds.x1 - image_dimensions.width; image_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - image_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - image_dimensions.height) / 2; break; case GTK_POS_RIGHT: image_bounds.x0 = content_bounds.x0; image_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - image_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - image_dimensions.height) / 2; break; case GTK_POS_TOP: image_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - image_frame.x1) / 2; - image_bounds.y0 = content_bounds.y1 - image_frame.y1; + (nautilus_art_irect_get_width (&content_bounds) - image_dimensions.width) / 2; + image_bounds.y0 = content_bounds.y1 - image_dimensions.height; break; case GTK_POS_BOTTOM: image_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - image_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - image_dimensions.width) / 2; image_bounds.y0 = content_bounds.y0; break; } } - image_bounds.x1 = image_bounds.x0 + image_frame.x1; - image_bounds.y1 = image_bounds.y0 + image_frame.y1; + image_bounds.x1 = image_bounds.x0 + image_dimensions.width; + image_bounds.y1 = image_bounds.y0 + image_dimensions.height; return image_bounds; } @@ -753,20 +749,20 @@ static ArtIRect labeled_image_get_label_bounds_fill (const NautilusLabeledImage *labeled_image) { ArtIRect label_bounds; - ArtIRect label_frame; + NautilusDimensions label_dimensions; ArtIRect content_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); - label_frame = labeled_image_get_label_frame (labeled_image); + label_dimensions = labeled_image_get_label_dimensions (labeled_image); - if (art_irect_empty (&label_frame)) { + if (nautilus_dimensions_empty (&label_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } content_bounds = labeled_image_get_content_bounds (labeled_image); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); /* Only the label is shown */ if (!labeled_image_show_image (labeled_image)) { @@ -778,12 +774,12 @@ labeled_image_get_label_bounds_fill (const NautilusLabeledImage *labeled_image) label_bounds.y0 = bounds.y0; label_bounds.x0 = bounds.x0; label_bounds.y1 = bounds.y1; - label_bounds.x1 = content_bounds.x0 + label_frame.x1; + label_bounds.x1 = content_bounds.x0 + label_dimensions.width; break; case GTK_POS_RIGHT: label_bounds.y0 = bounds.y0; - label_bounds.x0 = content_bounds.x1 - label_frame.x1; + label_bounds.x0 = content_bounds.x1 - label_dimensions.width; label_bounds.y1 = bounds.y1; label_bounds.x1 = bounds.x1; break; @@ -792,12 +788,12 @@ labeled_image_get_label_bounds_fill (const NautilusLabeledImage *labeled_image) label_bounds.x0 = bounds.x0; label_bounds.y0 = bounds.y0; label_bounds.x1 = bounds.x1; - label_bounds.y1 = content_bounds.y0 + label_frame.y1; + label_bounds.y1 = content_bounds.y0 + label_dimensions.height; break; case GTK_POS_BOTTOM: label_bounds.x0 = bounds.x0; - label_bounds.y0 = content_bounds.y1 - label_frame.y1; + label_bounds.y0 = content_bounds.y1 - label_dimensions.height; label_bounds.x1 = bounds.x1; label_bounds.y1 = bounds.y1; break; @@ -811,7 +807,7 @@ ArtIRect nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_image) { ArtIRect label_bounds; - ArtIRect label_frame; + NautilusDimensions label_dimensions; ArtIRect content_bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); @@ -820,9 +816,9 @@ nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_ima return labeled_image_get_label_bounds_fill (labeled_image); } - label_frame = labeled_image_get_label_frame (labeled_image); + label_dimensions = labeled_image_get_label_dimensions (labeled_image); - if (art_irect_empty (&label_frame)) { + if (nautilus_dimensions_empty (&label_dimensions)) { return NAUTILUS_ART_IRECT_EMPTY; } @@ -832,10 +828,10 @@ nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_ima if (!labeled_image_show_image (labeled_image)) { label_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - label_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - label_dimensions.width) / 2; label_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - label_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - label_dimensions.height) / 2; /* Both label and image are shown */ } else { switch (labeled_image->details->label_position) { @@ -843,34 +839,34 @@ nautilus_labeled_image_get_label_bounds (const NautilusLabeledImage *labeled_ima label_bounds.x0 = content_bounds.x0; label_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - label_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - label_dimensions.height) / 2; break; case GTK_POS_RIGHT: - label_bounds.x0 = content_bounds.x1 - label_frame.x1; + label_bounds.x0 = content_bounds.x1 - label_dimensions.width; label_bounds.y0 = content_bounds.y0 + - (nautilus_art_irect_get_height (&content_bounds) - label_frame.y1) / 2; + (nautilus_art_irect_get_height (&content_bounds) - label_dimensions.height) / 2; break; case GTK_POS_TOP: label_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - label_frame.x1) / 2; + (nautilus_art_irect_get_width (&content_bounds) - label_dimensions.width) / 2; label_bounds.y0 = content_bounds.y0; break; case GTK_POS_BOTTOM: label_bounds.x0 = content_bounds.x0 + - (nautilus_art_irect_get_width (&content_bounds) - label_frame.x1) / 2; - label_bounds.y0 = content_bounds.y1 - label_frame.y1; + (nautilus_art_irect_get_width (&content_bounds) - label_dimensions.width) / 2; + label_bounds.y0 = content_bounds.y1 - label_dimensions.height; break; } } - label_bounds.x1 = label_bounds.x0 + label_frame.x1; - label_bounds.y1 = label_bounds.y0 + label_frame.y1; + label_bounds.x1 = label_bounds.x0 + label_dimensions.width; + label_bounds.y1 = label_bounds.y0 + label_dimensions.height; return label_bounds; } @@ -969,64 +965,67 @@ labeled_image_update_alignments (NautilusLabeledImage *labeled_image) } } -static ArtIRect -labeled_image_get_content_frame (const NautilusLabeledImage *labeled_image) +static NautilusDimensions +labeled_image_get_content_dimensions (const NautilusLabeledImage *labeled_image) { - ArtIRect image_frame; - ArtIRect label_frame; - ArtIRect content_frame; + NautilusDimensions image_dimensions; + NautilusDimensions label_dimensions; + NautilusDimensions content_dimensions; - g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_DIMENSIONS_EMPTY); - image_frame = labeled_image_get_image_frame (labeled_image); - label_frame = labeled_image_get_label_frame (labeled_image); + image_dimensions = labeled_image_get_image_dimensions (labeled_image); + label_dimensions = labeled_image_get_label_dimensions (labeled_image); - content_frame = NAUTILUS_ART_IRECT_EMPTY; + content_dimensions = NAUTILUS_DIMENSIONS_EMPTY; /* Both shown */ - if (!art_irect_empty (&image_frame) && !art_irect_empty (&label_frame)) { - content_frame.x1 = image_frame.x1 + labeled_image->details->spacing + label_frame.x1; + if (!nautilus_dimensions_empty (&image_dimensions) && !nautilus_dimensions_empty (&label_dimensions)) { + content_dimensions.width = + image_dimensions.width + labeled_image->details->spacing + label_dimensions.width; switch (labeled_image->details->label_position) { case GTK_POS_LEFT: case GTK_POS_RIGHT: - content_frame.x1 = image_frame.x1 + labeled_image->details->spacing + label_frame.x1; - content_frame.y1 = MAX (image_frame.y1, label_frame.y1); + content_dimensions.width = + image_dimensions.width + labeled_image->details->spacing + label_dimensions.width; + content_dimensions.height = MAX (image_dimensions.height, label_dimensions.height); break; case GTK_POS_TOP: case GTK_POS_BOTTOM: - content_frame.x1 = MAX (image_frame.x1, label_frame.x1); - content_frame.y1 = image_frame.y1 + labeled_image->details->spacing + label_frame.y1; + content_dimensions.width = MAX (image_dimensions.width, label_dimensions.width); + content_dimensions.height = + image_dimensions.height + labeled_image->details->spacing + label_dimensions.height; break; } /* Only image shown */ - } else if (!art_irect_empty (&image_frame)) { - content_frame.x1 = image_frame.x1; - content_frame.y1 = image_frame.y1; + } else if (!nautilus_dimensions_empty (&image_dimensions)) { + content_dimensions.width = image_dimensions.width; + content_dimensions.height = image_dimensions.height; /* Only label shown */ } else { - content_frame.x1 = label_frame.x1; - content_frame.y1 = label_frame.y1; + content_dimensions.width = label_dimensions.width; + content_dimensions.height = label_dimensions.height; } - return content_frame; + return content_dimensions; } static ArtIRect labeled_image_get_content_bounds (const NautilusLabeledImage *labeled_image) { - ArtIRect content_frame; + NautilusDimensions content_dimensions; ArtIRect content_bounds; ArtIRect bounds; g_return_val_if_fail (NAUTILUS_IS_LABELED_IMAGE (labeled_image), NAUTILUS_ART_IRECT_EMPTY); - bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); + bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (labeled_image)); - content_frame = labeled_image_get_content_frame (labeled_image); + content_dimensions = labeled_image_get_content_dimensions (labeled_image); content_bounds = nautilus_art_irect_align (&bounds, - content_frame.x1, - content_frame.y1, + content_dimensions.width, + content_dimensions.height, labeled_image->details->x_alignment, labeled_image->details->y_alignment); @@ -1647,7 +1646,7 @@ button_leave_callback (GtkWidget *widget, const int fudge = 4; ArtIRect bounds; - bounds = nautilus_irect_gtk_widget_get_bounds (widget); + bounds = nautilus_gtk_widget_get_bounds (widget); bounds.x0 -= fudge; bounds.y0 -= fudge; diff --git a/libnautilus-private/nautilus-lib-self-check-functions.h b/libnautilus-private/nautilus-lib-self-check-functions.h index 9e711a4c7..f1bdf9ea1 100644 --- a/libnautilus-private/nautilus-lib-self-check-functions.h +++ b/libnautilus-private/nautilus-lib-self-check-functions.h @@ -45,6 +45,8 @@ void nautilus_run_lib_self_checks (void); macro (nautilus_self_check_preferences) \ macro (nautilus_self_check_scalable_font) \ macro (nautilus_self_check_string_map) \ + macro (nautilus_self_check_art_extensions) \ + macro (nautilus_self_check_gdk_pixbuf_extensions) \ macro (nautilus_self_check_glib_extensions) \ macro (nautilus_self_check_gdk_extensions) \ macro (nautilus_self_check_gdk_font_extensions) \ diff --git a/libnautilus-private/nautilus-region.c b/libnautilus-private/nautilus-region.c index 2ab4da988..0ff4f044b 100644 --- a/libnautilus-private/nautilus-region.c +++ b/libnautilus-private/nautilus-region.c @@ -68,7 +68,7 @@ gdk_region_new_from_irect (const ArtIRect *art_rect) g_return_val_if_fail (art_rect != NULL, NULL); - gdk_rect = nautilus_gdk_rectangle_assign_irect (art_rect); + gdk_rect = nautilus_art_irect_to_gdk_rectangle (art_rect); empty_region = gdk_region_new (); region = gdk_region_union_with_rect (empty_region, &gdk_rect); gdk_region_destroy (empty_region); diff --git a/libnautilus-private/nautilus-scalable-font.c b/libnautilus-private/nautilus-scalable-font.c index 7780dfe4a..b20fefbbc 100644 --- a/libnautilus-private/nautilus-scalable-font.c +++ b/libnautilus-private/nautilus-scalable-font.c @@ -651,33 +651,25 @@ nautilus_scalable_font_make_bold (NautilusScalableFont *font) return bold_font; } -void -nautilus_scalable_font_measure_text (const NautilusScalableFont *font, - int font_width, - int font_height, +NautilusDimensions +nautilus_scalable_font_measure_text (const NautilusScalableFont *font, + int font_size, const char *text, - guint text_length, - int *text_width_out, - int *text_height_out) + guint text_length) { + NautilusDimensions dimensions; double affine[6]; int glyph_xy[2]; - unsigned int dimensions[2]; - - g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); - g_return_if_fail (text_width_out != NULL); - g_return_if_fail (text_height_out != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + unsigned int tmp[2]; - *text_width_out = 0; - *text_height_out = 0; + g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (font_size > 0, NAUTILUS_DIMENSIONS_EMPTY); if (text == NULL || text[0] == '\0' || text_length == 0) { - return; + return NAUTILUS_DIMENSIONS_EMPTY; } - g_return_if_fail (text_length <= strlen (text)); + g_return_val_if_fail (text_length <= strlen (text), NAUTILUS_DIMENSIONS_EMPTY); art_affine_identity (affine); @@ -685,29 +677,28 @@ nautilus_scalable_font_measure_text (const NautilusScalableFont *font, font->detail->font_handle, text, text_length, - font_width, - font_height, + font_size, + font_size, affine, glyph_xy, - dimensions); + tmp); + + dimensions.width = tmp[0]; + dimensions.height = tmp[1]; - *text_width_out = dimensions[0]; - *text_height_out = dimensions[1]; + return dimensions; } int nautilus_scalable_font_text_width (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint text_length) { - int text_width = 0; - int text_height = 0; + NautilusDimensions dimensions; g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0); - g_return_val_if_fail (font_width > 0, 0); - g_return_val_if_fail (font_height > 0, 0); + g_return_val_if_fail (font_size > 0, 0); if (text == NULL || text[0] == '\0' || text_length == 0) { return 0; @@ -715,15 +706,9 @@ nautilus_scalable_font_text_width (const NautilusScalableFont *font, g_return_val_if_fail (text_length <= strlen (text), 0); - nautilus_scalable_font_measure_text (font, - font_width, - font_height, - text, - text_length, - &text_width, - &text_height); + dimensions = nautilus_scalable_font_measure_text (font, font_size, text, text_length); - return text_width; + return dimensions.width; } void @@ -732,8 +717,7 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint text_length, guint32 color, @@ -747,8 +731,7 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); g_return_if_fail (destination_pixbuf != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -770,8 +753,8 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, font->detail->font_handle, text, text_length, - font_width, - font_height, + font_size, + font_size, affine, glyph_xy); g_assert (glyph != NULL); @@ -846,17 +829,15 @@ nautilus_scalable_font_draw_text (const NautilusScalableFont *font, } rsvg_ft_glyph_unref (glyph); - } +} void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, double empty_line_height, - int text_line_widths[], - int text_line_heights[], + NautilusDimensions text_line_dimensions[], int *max_width_out, int *total_height_out) { @@ -864,11 +845,9 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, const char *line; g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (text != NULL); - g_return_if_fail (text_line_widths != NULL); - g_return_if_fail (text_line_heights != NULL); + g_return_if_fail (text_line_dimensions != NULL); g_return_if_fail (num_text_lines > 0); g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1)); @@ -904,17 +883,14 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, /* Deal with empty lines */ if (length == 0) { - text_line_widths[i] = 0; - text_line_heights[i] = empty_line_height; + text_line_dimensions[i].width = 0; + text_line_dimensions[i].height = empty_line_height; } else { - nautilus_scalable_font_measure_text (font, - font_width, - font_height, - line, - length, - &text_line_widths[i], - &text_line_heights[i]); + text_line_dimensions[i] = nautilus_scalable_font_measure_text (font, + font_size, + line, + length); } if (next_new_line != NULL) { @@ -926,12 +902,12 @@ nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, /* Keep track of total height */ if (total_height_out != NULL) { - *total_height_out += text_line_heights[i]; + *total_height_out += text_line_dimensions[i].height; } /* Keep track of max width */ - if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) { - *max_width_out = text_line_widths[i]; + if (max_width_out != NULL) { + *max_width_out = MAX (*max_width_out, text_line_dimensions[i].width); } } } @@ -942,12 +918,10 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, - const int *text_line_widths, - const int *text_line_heights, + const NautilusDimensions *text_line_dimensions, GtkJustification justification, int line_offset, double empty_line_height, @@ -962,15 +936,13 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); g_return_if_fail (destination_pixbuf != NULL); g_return_if_fail (clip_area != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL); g_return_if_fail (clip_area->x1 > clip_area->x0); g_return_if_fail (clip_area->y1 > clip_area->y0); g_return_if_fail (num_text_lines > 0); g_return_if_fail (num_text_lines <= (nautilus_str_count_characters (text, '\n') + 1)); - g_return_if_fail (text_line_widths != NULL); - g_return_if_fail (text_line_widths != NULL); + g_return_if_fail (text_line_dimensions != NULL); g_return_if_fail (opacity >= NAUTILUS_OPACITY_FULLY_TRANSPARENT); g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -1001,7 +973,7 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo /* Deal with empty lines */ if (length == 0) { - y += (line_offset + text_line_heights[i]); + y += (line_offset + text_line_dimensions[i].height); } else { int text_x; @@ -1014,16 +986,16 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo case GTK_JUSTIFY_CENTER: case GTK_JUSTIFY_FILL: - if (text_line_widths[i] <= available_width) { - text_x = x + ((available_width - text_line_widths[i]) / 2); + if (text_line_dimensions[i].width <= available_width) { + text_x = x + ((available_width - text_line_dimensions[i].width) / 2); } else { - text_x = x - ((text_line_widths[i] - available_width) / 2); + text_x = x - ((text_line_dimensions[i].width - available_width) / 2); } break; case GTK_JUSTIFY_RIGHT: - text_x = x + available_width - text_line_widths[i]; + text_x = x + available_width - text_line_dimensions[i].width; break; default: @@ -1038,14 +1010,13 @@ nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFo text_x, text_y, clip_area, - font_width, - font_height, + font_size, line, length, color, opacity); - y += (line_offset + text_line_heights[i]); + y += (line_offset + text_line_dimensions[i].height); } if (next_new_line != NULL) { @@ -1063,8 +1034,7 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, GtkJustification justification, int line_offset, @@ -1073,14 +1043,12 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, int opacity) { guint num_text_lines; - int *text_line_widths; - int *text_line_heights; + NautilusDimensions *text_line_dimensions; g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font)); g_return_if_fail (destination_pixbuf != NULL); g_return_if_fail (clip_area != NULL); - g_return_if_fail (font_width > 0); - g_return_if_fail (font_height > 0); + g_return_if_fail (font_size > 0); g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL); g_return_if_fail (clip_area->x1 > clip_area->x0); g_return_if_fail (clip_area->y1 > clip_area->y0); @@ -1097,17 +1065,14 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, */ num_text_lines = nautilus_str_count_characters (text, '\n') + 1; - text_line_widths = g_new (int, num_text_lines); - text_line_heights = g_new (int, num_text_lines); + text_line_dimensions = g_new (NautilusDimensions, num_text_lines); nautilus_scalable_font_measure_text_lines (font, - font_width, - font_height, + font_size, text, num_text_lines, empty_line_height, - text_line_widths, - text_line_heights, + text_line_dimensions, NULL, NULL); @@ -1116,20 +1081,17 @@ nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font, x, y, clip_area, - font_width, - font_height, + font_size, text, num_text_lines, - text_line_widths, - text_line_heights, + text_line_dimensions, justification, line_offset, empty_line_height, color, opacity); - g_free (text_line_widths); - g_free (text_line_heights); + g_free (text_line_dimensions); } /** @@ -1170,20 +1132,16 @@ nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *fo g_assert (longest_string != NULL); nautilus_string_list_free (tokenized_string); longest_string_length = strlen (longest_string); - - for (i = maximum_acceptable_font_size; i >= minimum_acceptable_font_size; i--) { - int text_width; - int text_height; - nautilus_scalable_font_measure_text (font, - minimum_acceptable_font_size, - minimum_acceptable_font_size, - longest_string, - longest_string_length, - &text_width, - &text_height); + for (i = maximum_acceptable_font_size; i >= minimum_acceptable_font_size; i--) { + int width; + + width = nautilus_scalable_font_text_width (font, + i, + longest_string, + longest_string_length); - if (text_width <= available_width) { + if (width <= available_width) { g_free (longest_string); return i; } diff --git a/libnautilus-private/nautilus-scalable-font.h b/libnautilus-private/nautilus-scalable-font.h index cbef1e42e..61b36ed90 100644 --- a/libnautilus-private/nautilus-scalable-font.h +++ b/libnautilus-private/nautilus-scalable-font.h @@ -44,6 +44,7 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <libgnome/gnome-defs.h> #include <libnautilus-extensions/nautilus-string-list.h> +#include <libnautilus-extensions/nautilus-art-extensions.h> #include <libart_lgpl/art_rect.h> BEGIN_GNOME_DECLS @@ -77,16 +78,12 @@ NautilusScalableFont *nautilus_scalable_font_new (c const char *weight, const char *slant, const char *set_width); -void nautilus_scalable_font_measure_text (const NautilusScalableFont *font, - int font_width, - int font_height, +NautilusDimensions nautilus_scalable_font_measure_text (const NautilusScalableFont *font, + int font_size, const char *text, - guint text_length, - int *text_width_out, - int *text_height_out); + guint text_length); int nautilus_scalable_font_text_width (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint text_length); void nautilus_scalable_font_draw_text (const NautilusScalableFont *font, @@ -94,20 +91,17 @@ void nautilus_scalable_font_draw_text (c int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint text_length, guint32 color, int opacity); void nautilus_scalable_font_measure_text_lines (const NautilusScalableFont *font, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, double empty_line_height, - int text_line_widths[], - int text_line_heights[], + NautilusDimensions text_line_dimensions[], int *max_width_out, int *total_height_out); void nautilus_scalable_font_draw_text_lines_with_dimensions (const NautilusScalableFont *font, @@ -115,12 +109,10 @@ void nautilus_scalable_font_draw_text_lines_with_dimensions (c int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, guint num_text_lines, - const int *text_line_widths, - const int *text_line_heights, + const NautilusDimensions *text_line_dimensions, GtkJustification justification, int line_offset, double empty_line_height, @@ -131,8 +123,7 @@ void nautilus_scalable_font_draw_text_lines (c int x, int y, const ArtIRect *clip_area, - int font_width, - int font_height, + int font_size, const char *text, GtkJustification justification, int line_offset, diff --git a/libnautilus-private/nautilus-self-checks.c b/libnautilus-private/nautilus-self-checks.c index d0a5cc526..4adb11d05 100644 --- a/libnautilus-private/nautilus-self-checks.c +++ b/libnautilus-private/nautilus-self-checks.c @@ -106,6 +106,48 @@ nautilus_check_boolean_result (gboolean result, gboolean expected) } void +nautilus_check_rectangle_result (ArtIRect result, + int expected_x0, + int expected_y0, + int expected_x1, + int expected_y1) +{ + if (result.x0 != expected_x0 + || result.y0 != expected_y0 + || result.x1 != expected_x1 + || result.y1 != expected_y1) { + nautilus_report_check_failure (g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d", + result.x0, + result.y0, + result.x1, + result.y1), + g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d", + expected_x0, + expected_y0, + expected_x1, + expected_y1)); + } + nautilus_after_check (); +} + +void +nautilus_check_dimensions_result (NautilusDimensions result, + int expected_width, + int expected_height) +{ + if (result.width != expected_width + || result.height != expected_height) { + nautilus_report_check_failure (g_strdup_printf ("width=%d, height=%d", + result.width, + result.height), + g_strdup_printf ("width=%d, height=%d", + expected_width, + expected_height)); + } + nautilus_after_check (); +} + +void nautilus_check_integer_result (long result, long expected) { if (result != expected) { diff --git a/libnautilus-private/nautilus-self-checks.h b/libnautilus-private/nautilus-self-checks.h index 289af4e40..73ff7e5c3 100644 --- a/libnautilus-private/nautilus-self-checks.h +++ b/libnautilus-private/nautilus-self-checks.h @@ -26,6 +26,7 @@ #define NAUTILUS_SELF_CHECKS_H #include <glib.h> +#include <libnautilus-extensions/nautilus-art-extensions.h> #define NAUTILUS_CHECK_RESULT(type, expression, expected_value) \ G_STMT_START { \ @@ -39,22 +40,37 @@ G_STMT_START { \ NAUTILUS_CHECK_RESULT(integer, expression, expected_value) #define NAUTILUS_CHECK_STRING_RESULT(expression, expected_value) \ NAUTILUS_CHECK_RESULT(string, expression, expected_value) +#define NAUTILUS_CHECK_RECTANGLE_RESULT(expression, expected_x0, expected_y0, expected_x1, expected_y1) \ +G_STMT_START { \ + nautilus_before_check (#expression, __FILE__, __LINE__); \ + nautilus_check_rectangle_result (expression, expected_x0, expected_y0, expected_x1, expected_y1); \ +} G_STMT_END +#define NAUTILUS_CHECK_DIMENSIONS_RESULT(expression, expected_width, expected_height) \ +G_STMT_START { \ + nautilus_before_check (#expression, __FILE__, __LINE__); \ + nautilus_check_dimensions_result (expression, expected_width, expected_height); \ +} G_STMT_END void nautilus_exit_if_self_checks_failed (void); - -void nautilus_before_check_function (const char *name); +void nautilus_before_check_function (const char *name); void nautilus_after_check_function (void); - -void nautilus_before_check (const char *expression, - const char *file_name, - int line_number); - -void nautilus_check_boolean_result (gboolean result, - gboolean expected_value); -void nautilus_check_integer_result (long result, - long expected_value); -void nautilus_check_string_result (char *result, - const char *expected_value); +void nautilus_before_check (const char *expression, + const char *file_name, + int line_number); +void nautilus_check_boolean_result (gboolean result, + gboolean expected_value); +void nautilus_check_integer_result (long result, + long expected_value); +void nautilus_check_rectangle_result (ArtIRect result, + int expected_x0, + int expected_y0, + int expected_x1, + int expected_y1); +void nautilus_check_dimensions_result (NautilusDimensions result, + int expected_width, + int expected_height); +void nautilus_check_string_result (char *result, + const char *expected_value); #define NAUTILUS_SELF_CHECK_FUNCTION_PROTOTYPE(function) \ void function (void); diff --git a/libnautilus-private/nautilus-smooth-widget.c b/libnautilus-private/nautilus-smooth-widget.c index 28b7ba72a..4b6229422 100644 --- a/libnautilus-private/nautilus-smooth-widget.c +++ b/libnautilus-private/nautilus-smooth-widget.c @@ -385,7 +385,7 @@ smooth_widget_paint_tile_transparent (GtkWidget *widget, const NautilusArtIPoint *tile_origin, const ArtIRect *dirty_area) { - ArtIRect buffer_frame; + NautilusDimensions buffer_dimensions; ArtIRect tile_dirty_area; ArtIRect tile_area; GdkPixbuf *buffer; @@ -416,9 +416,9 @@ smooth_widget_paint_tile_transparent (GtkWidget *widget, g_return_if_fail (nautilus_gdk_pixbuf_is_valid (buffer)); - buffer_frame = nautilus_gdk_pixbuf_get_frame (buffer); + buffer_dimensions = nautilus_gdk_pixbuf_get_dimensions (buffer); - nautilus_art_irect_assign (&tile_area, 0, 0, buffer_frame.x1, buffer_frame.y1); + nautilus_art_irect_assign (&tile_area, 0, 0, buffer_dimensions.width, buffer_dimensions.height); /* Composite the tile into the buffer */ nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (tile_pixbuf, @@ -948,50 +948,47 @@ nautilus_smooth_widget_get_tile_bounds (const GtkWidget *widget, } /* Clip the tile bounds to the widget bounds */ - bounds = nautilus_irect_gtk_widget_get_bounds (widget); + bounds = nautilus_gtk_widget_get_bounds (widget); art_irect_intersect (&clipped_tile_bounds, &tile_bounds, &bounds); return tile_bounds; } -ArtIRect -nautilus_smooth_widget_get_preferred_frame (const GtkWidget *widget, - const ArtIRect *content_frame, - const ArtIRect *tile_frame, - int tile_width, - int tile_height) +NautilusDimensions +nautilus_smooth_widget_get_preferred_dimensions (const GtkWidget *widget, + const NautilusDimensions *content_dimensions, + const NautilusDimensions *tile_dimensions, + int tile_width, + int tile_height) { - ArtIRect preferred_frame; + NautilusDimensions preferred_dimensions; - g_return_val_if_fail (widget_is_smooth (widget), NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (content_frame != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (tile_frame != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (tile_width >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (tile_height >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (widget_is_smooth (widget), NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (content_dimensions != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (tile_dimensions != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (tile_width >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (tile_height >= NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP, NAUTILUS_DIMENSIONS_EMPTY); if (tile_width == NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP) { - tile_width = tile_frame->x1; + tile_width = tile_dimensions->width; } else { tile_width = 0; } if (tile_height == NAUTILUS_SMOOTH_TILE_EXTENT_ONE_STEP) { - tile_height = tile_frame->y1; + tile_height = tile_dimensions->height; } else { tile_height = 0; } - nautilus_art_irect_assign (&preferred_frame, - 0, - 0, - MAX (content_frame->x1, tile_width) + (2 * GTK_MISC (widget)->xpad), - MAX (content_frame->y1, tile_height) + (2 * GTK_MISC (widget)->ypad)); + preferred_dimensions.width = MAX (content_dimensions->width, tile_width) + (2 * GTK_MISC (widget)->xpad); + preferred_dimensions.height = MAX (content_dimensions->height, tile_height) + (2 * GTK_MISC (widget)->ypad); - /* Make sure the frame is not zero. Gtk goes berserk with zero size widget */ - preferred_frame.x1 = MAX (preferred_frame.x1, 2); - preferred_frame.y1 = MAX (preferred_frame.y1, 2); + /* Make sure the dimensions is not zero. Gtk goes berserk with zero size widget */ + preferred_dimensions.width = MAX (preferred_dimensions.width, 2); + preferred_dimensions.height = MAX (preferred_dimensions.height, 2); - return preferred_frame; + return preferred_dimensions; } void diff --git a/libnautilus-private/nautilus-smooth-widget.h b/libnautilus-private/nautilus-smooth-widget.h index 007f8769c..7661a586f 100644 --- a/libnautilus-private/nautilus-smooth-widget.h +++ b/libnautilus-private/nautilus-smooth-widget.h @@ -84,33 +84,33 @@ typedef void (* NautilusSmoothCompositeCallback) (GtkWidget *widget, int opacity, gpointer callback_data); -void nautilus_smooth_widget_register (GtkWidget *widget); -void nautilus_smooth_widget_paint (GtkWidget *widget, - GdkGC *gc, - gboolean is_smooth, - NautilusSmoothBackgroundMode background_mode, - guint32 solid_background_color, - const GdkPixbuf *tile_pixbuf, - const ArtIRect *tile_bounds, - int tile_opacity, - NautilusSmoothTileMode tile_mode_vertical, - NautilusSmoothTileMode tile_mode_horizontal, - const ArtIRect *content_bounds, - int content_opacity, - const ArtIRect *dirty_area, - NautilusSmoothPaintOpaqueCallback paint_callback, - NautilusSmoothCompositeCallback composite_callback, - gpointer callback_data); -ArtIRect nautilus_smooth_widget_get_tile_bounds (const GtkWidget *widget, - const GdkPixbuf *tile_pixbuf, - int tile_width, - int tile_height); -ArtIRect nautilus_smooth_widget_get_preferred_frame (const GtkWidget *widget, - const ArtIRect *content_frame, - const ArtIRect *tile_frame, - int tile_width, - int tile_height); -void nautilus_smooth_widget_register_type (GtkType type); +void nautilus_smooth_widget_register (GtkWidget *widget); +void nautilus_smooth_widget_paint (GtkWidget *widget, + GdkGC *gc, + gboolean is_smooth, + NautilusSmoothBackgroundMode background_mode, + guint32 solid_background_color, + const GdkPixbuf *tile_pixbuf, + const ArtIRect *tile_bounds, + int tile_opacity, + NautilusSmoothTileMode tile_mode_vertical, + NautilusSmoothTileMode tile_mode_horizontal, + const ArtIRect *content_bounds, + int content_opacity, + const ArtIRect *dirty_area, + NautilusSmoothPaintOpaqueCallback paint_callback, + NautilusSmoothCompositeCallback composite_callback, + gpointer callback_data); +ArtIRect nautilus_smooth_widget_get_tile_bounds (const GtkWidget *widget, + const GdkPixbuf *tile_pixbuf, + int tile_width, + int tile_height); +NautilusDimensions nautilus_smooth_widget_get_preferred_dimensions (const GtkWidget *widget, + const NautilusDimensions *content_dimensions, + const NautilusDimensions *tile_dimensions, + int tile_width, + int tile_height); +void nautilus_smooth_widget_register_type (GtkType type); END_GNOME_DECLS diff --git a/libnautilus-private/nautilus-tabs.c b/libnautilus-private/nautilus-tabs.c index c81714bf1..4cbefc11d 100644 --- a/libnautilus-private/nautilus-tabs.c +++ b/libnautilus-private/nautilus-tabs.c @@ -481,15 +481,10 @@ allocate_cleared_pixbuf (int width, int height) static int measure_tab_name (NautilusTabs *tabs, const char *tab_name) { - int name_width, name_height; - nautilus_scalable_font_measure_text (tabs->details->tab_font, - tabs->details->font_size, - tabs->details->font_size, - tab_name, - strlen (tab_name), - &name_width, - &name_height); - return name_width; + return nautilus_scalable_font_text_width (tabs->details->tab_font, + tabs->details->font_size, + tab_name, + strlen (tab_name)); } /* utility to draw the tab label */ @@ -505,7 +500,7 @@ draw_tab_label (NautilusTabs *tabs, GdkPixbuf *tab_pixbuf, int x_pos, const char nautilus_scalable_font_draw_text (tabs->details->tab_font, tab_pixbuf, text_x, text_y, NULL, - tabs->details->font_size, tabs->details->font_size, + tabs->details->font_size, label, strlen (label), NAUTILUS_RGB_COLOR_BLACK, NAUTILUS_OPACITY_FULLY_OPAQUE); text_x -= 1; @@ -524,7 +519,7 @@ draw_tab_label (NautilusTabs *tabs, GdkPixbuf *tab_pixbuf, int x_pos, const char nautilus_scalable_font_draw_text (tabs->details->tab_font, tab_pixbuf, text_x, text_y, NULL, - tabs->details->font_size, tabs->details->font_size, + tabs->details->font_size, label, strlen (label), text_color, NAUTILUS_OPACITY_FULLY_OPAQUE); diff --git a/libnautilus-private/nautilus-text-layout.c b/libnautilus-private/nautilus-text-layout.c index 2c54607eb..d76a1e678 100644 --- a/libnautilus-private/nautilus-text-layout.c +++ b/libnautilus-private/nautilus-text-layout.c @@ -153,7 +153,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, if (word_end < row_end) word_end++; - if (nautilus_scalable_font_text_width (font, font_size, font_size, text_iter, word_end - text_iter) > max_width) { + if (nautilus_scalable_font_text_width (font, font_size, text_iter, word_end - text_iter) > max_width) { if (word_start == text_iter) { if (confine) { /* We must force-split the word. Look for a proper @@ -163,7 +163,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, w_len = word_end - word_start; for (i = 1; i < w_len; i++) { - w = nautilus_scalable_font_text_width (font, font_size, font_size, word_start, i); + w = nautilus_scalable_font_text_width (font, font_size, word_start, i); if (w > max_width) { if (i == 1) /* Shit, not even a single character fits */ @@ -180,7 +180,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, row = g_new (NautilusTextLayoutRow, 1); row->text = sub_text; row->text_length = i - 1; - row->width = nautilus_scalable_font_text_width (font, font_size, font_size, + row->width = nautilus_scalable_font_text_width (font, font_size, sub_text, strlen (sub_text)); @@ -198,7 +198,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, continue; } else - max_width = nautilus_scalable_font_text_width (font, font_size, font_size, word_start, word_end - word_start); + max_width = nautilus_scalable_font_text_width (font, font_size, word_start, word_end - word_start); continue; /* Retry split */ } else { @@ -232,7 +232,7 @@ nautilus_text_layout_new (const NautilusScalableFont *font, row = g_new (NautilusTextLayoutRow, 1); row->text = sub_text; row->text_length = sub_len; - row->width = nautilus_scalable_font_text_width (font, font_size, font_size, sub_text, sub_len); + row->width = nautilus_scalable_font_text_width (font, font_size, sub_text, sub_len); text_layout->rows = g_list_append (text_layout->rows, row); @@ -318,7 +318,6 @@ nautilus_text_layout_paint (const NautilusTextLayout *text_layout, y, NULL, text_layout->font_size, - text_layout->font_size, row->text, row->text_length, color, diff --git a/libnautilus-private/nautilus-wrap-table.c b/libnautilus-private/nautilus-wrap-table.c index 8a2c62353..82bfa9990 100644 --- a/libnautilus-private/nautilus-wrap-table.c +++ b/libnautilus-private/nautilus-wrap-table.c @@ -57,48 +57,48 @@ struct NautilusWrapTableDetails }; /* GtkObjectClass methods */ -static void nautilus_wrap_table_initialize_class (NautilusWrapTableClass *wrap_table_class); -static void nautilus_wrap_table_initialize (NautilusWrapTable *wrap); -static void nautilus_wrap_table_destroy (GtkObject *object); -static void nautilus_wrap_table_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void nautilus_wrap_table_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); +static void nautilus_wrap_table_initialize_class (NautilusWrapTableClass *wrap_table_class); +static void nautilus_wrap_table_initialize (NautilusWrapTable *wrap); +static void nautilus_wrap_table_destroy (GtkObject *object); +static void nautilus_wrap_table_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void nautilus_wrap_table_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); /* GtkWidgetClass methods */ -static void nautilus_wrap_table_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int nautilus_wrap_table_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void nautilus_wrap_table_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void nautilus_wrap_table_map (GtkWidget *widget); -static void nautilus_wrap_table_unmap (GtkWidget *widget); +static void nautilus_wrap_table_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static int nautilus_wrap_table_expose_event (GtkWidget *widget, + GdkEventExpose *event); +static void nautilus_wrap_table_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static void nautilus_wrap_table_map (GtkWidget *widget); +static void nautilus_wrap_table_unmap (GtkWidget *widget); /* GtkContainerClass methods */ -static void nautilus_wrap_table_add (GtkContainer *container, - GtkWidget *widget); -static void nautilus_wrap_table_remove (GtkContainer *container, - GtkWidget *widget); -static void nautilus_wrap_table_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static GtkType nautilus_wrap_table_child_type (GtkContainer *container); +static void nautilus_wrap_table_add (GtkContainer *container, + GtkWidget *widget); +static void nautilus_wrap_table_remove (GtkContainer *container, + GtkWidget *widget); +static void nautilus_wrap_table_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data); +static GtkType nautilus_wrap_table_child_type (GtkContainer *container); /* Private NautilusWrapTable methods */ -static ArtIRect wrap_table_art_irect_max_frame (const ArtIRect *one, - const ArtIRect *two); -static ArtIRect wrap_table_get_max_child_frame (const NautilusWrapTable *wrap_table); -static ArtIRect wrap_table_get_content_frame (const NautilusWrapTable *wrap_table); -static ArtIRect wrap_table_get_content_bounds (const NautilusWrapTable *wrap_table); -static NautilusArtIPoint wrap_table_get_scroll_offset (const NautilusWrapTable *wrap_table); -static GtkWidget * wrap_table_find_child_at_point (const NautilusWrapTable *wrap_table, - int x, - int y); -static void wrap_table_layout (NautilusWrapTable *wrap_table); +static NautilusDimensions wrap_table_art_irect_max_dimensions (const NautilusDimensions *one, + const NautilusDimensions *two); +static NautilusDimensions wrap_table_get_max_child_dimensions (const NautilusWrapTable *wrap_table); +static NautilusDimensions wrap_table_get_content_dimensions (const NautilusWrapTable *wrap_table); +static ArtIRect wrap_table_get_content_bounds (const NautilusWrapTable *wrap_table); +static NautilusArtIPoint wrap_table_get_scroll_offset (const NautilusWrapTable *wrap_table); +static GtkWidget * wrap_table_find_child_at_point (const NautilusWrapTable *wrap_table, + int x, + int y); +static void wrap_table_layout (NautilusWrapTable *wrap_table); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusWrapTable, nautilus_wrap_table, GTK_TYPE_CONTAINER) @@ -265,18 +265,18 @@ nautilus_wrap_table_size_request (GtkWidget *widget, GtkRequisition *requisition) { NautilusWrapTable *wrap_table; - ArtIRect content_frame; + NautilusDimensions content_dimensions; g_return_if_fail (NAUTILUS_IS_WRAP_TABLE (widget)); g_return_if_fail (requisition != NULL); wrap_table = NAUTILUS_WRAP_TABLE (widget); - content_frame = wrap_table_get_content_frame (wrap_table); + content_dimensions = wrap_table_get_content_dimensions (wrap_table); /* The -1 tells Satan to use as much space as is available */ requisition->width = -1; - requisition->height = content_frame.y1 + GTK_CONTAINER (widget)->border_width * 2; + requisition->height = content_dimensions.height + GTK_CONTAINER (widget)->border_width * 2; } static void @@ -456,12 +456,12 @@ wrap_table_layout (NautilusWrapTable *wrap_table) { GList *iterator; NautilusArtIPoint pos; - ArtIRect max_child_frame; + NautilusDimensions max_child_dimensions; ArtIRect content_bounds; g_return_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table)); - max_child_frame = wrap_table_get_max_child_frame (wrap_table); + max_child_dimensions = wrap_table_get_max_child_dimensions (wrap_table); content_bounds = wrap_table_get_content_bounds (wrap_table); pos.x = content_bounds.x0; pos.y = content_bounds.y0; @@ -477,16 +477,16 @@ wrap_table_layout (NautilusWrapTable *wrap_table) if (wrap_table->details->homogeneous) { item_allocation.x = pos.x; item_allocation.y = pos.y; - item_allocation.width = max_child_frame.x1; - item_allocation.height = max_child_frame.y1; + item_allocation.width = max_child_dimensions.width; + item_allocation.height = max_child_dimensions.height; - if ((pos.x + max_child_frame.x1) > content_bounds.x1) { - pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_frame.x1; - pos.y += (max_child_frame.y1 + wrap_table->details->y_spacing); + if ((pos.x + max_child_dimensions.width) > content_bounds.x1) { + pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_dimensions.width; + pos.y += (max_child_dimensions.height + wrap_table->details->y_spacing); item_allocation.x = content_bounds.x0; item_allocation.y = pos.y; } else { - pos.x += (wrap_table->details->x_spacing + max_child_frame.x1); + pos.x += (wrap_table->details->x_spacing + max_child_dimensions.width); } } else { GtkRequisition item_requisition; @@ -498,34 +498,34 @@ wrap_table_layout (NautilusWrapTable *wrap_table) item_allocation.width = item_requisition.width; item_allocation.height = item_requisition.height; - g_assert (item_allocation.width <= max_child_frame.x1); - g_assert (item_allocation.height <= max_child_frame.y1); + g_assert (item_allocation.width <= max_child_dimensions.width); + g_assert (item_allocation.height <= max_child_dimensions.height); - if ((pos.x + max_child_frame.x1) > content_bounds.x1) { - pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_frame.x1; - pos.y += (max_child_frame.y1 + wrap_table->details->y_spacing); + if ((pos.x + max_child_dimensions.width) > content_bounds.x1) { + pos.x = content_bounds.x0 + wrap_table->details->x_spacing + max_child_dimensions.width; + pos.y += (max_child_dimensions.height + wrap_table->details->y_spacing); item_allocation.x = content_bounds.x0; item_allocation.y = pos.y; } else { - pos.x += (wrap_table->details->x_spacing + max_child_frame.x1); + pos.x += (wrap_table->details->x_spacing + max_child_dimensions.width); } switch (wrap_table->details->x_justification) { case NAUTILUS_JUSTIFICATION_MIDDLE: - item_allocation.x += (max_child_frame.x1 - (int) item_allocation.width) / 2; + item_allocation.x += (max_child_dimensions.width - (int) item_allocation.width) / 2; break; case NAUTILUS_JUSTIFICATION_END: - item_allocation.x += (max_child_frame.x1 - (int) item_allocation.width); + item_allocation.x += (max_child_dimensions.width - (int) item_allocation.width); break; default: } switch (wrap_table->details->y_justification) { case NAUTILUS_JUSTIFICATION_MIDDLE: - item_allocation.y += (max_child_frame.y1 - (int) item_allocation.height) / 2; + item_allocation.y += (max_child_dimensions.height - (int) item_allocation.height) / 2; break; case NAUTILUS_JUSTIFICATION_END: - item_allocation.y += (max_child_frame.y1 - (int) item_allocation.height); + item_allocation.y += (max_child_dimensions.height - (int) item_allocation.height); break; default: } @@ -536,36 +536,30 @@ wrap_table_layout (NautilusWrapTable *wrap_table) } } -static ArtIRect -wrap_table_art_irect_max_frame (const ArtIRect *one, - const ArtIRect *two) +static NautilusDimensions +wrap_table_art_irect_max_dimensions (const NautilusDimensions *one, + const NautilusDimensions *two) { - ArtIRect max; + NautilusDimensions max_dimensions; - g_return_val_if_fail (one != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (two != NULL, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (one->x0 == 0, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (one->y0 == 0, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (two->x0 == 0, NAUTILUS_ART_IRECT_EMPTY); - g_return_val_if_fail (two->y0 == 0, NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (one != NULL, NAUTILUS_DIMENSIONS_EMPTY); + g_return_val_if_fail (two != NULL, NAUTILUS_DIMENSIONS_EMPTY); - max.x0 = 0; - max.y0 = 0; - max.x1 = MAX (one->x1, two->x1); - max.y1 = MAX (one->y1, two->y1); + max_dimensions.width = MAX (one->width, two->width); + max_dimensions.height = MAX (one->height, two->height); - return max; + return max_dimensions; } -static ArtIRect -wrap_table_get_max_child_frame (const NautilusWrapTable *wrap_table) +static NautilusDimensions +wrap_table_get_max_child_dimensions (const NautilusWrapTable *wrap_table) { - ArtIRect max; + NautilusDimensions max_dimensions; GList *iterator; - g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_DIMENSIONS_EMPTY); - max = NAUTILUS_ART_IRECT_EMPTY; + max_dimensions = NAUTILUS_DIMENSIONS_EMPTY; for (iterator = wrap_table->details->items; iterator; iterator = iterator->next) { GtkWidget *child; @@ -574,20 +568,18 @@ wrap_table_get_max_child_frame (const NautilusWrapTable *wrap_table) if (GTK_WIDGET_VISIBLE (child)) { GtkRequisition child_requisition; - ArtIRect child_frame; + NautilusDimensions child_dimensions; gtk_widget_size_request (child, &child_requisition); - child_frame.x0 = 0; - child_frame.y0 = 0; - child_frame.x1 = child_requisition.width; - child_frame.y1 = child_requisition.height; + child_dimensions.width = (int) child_requisition.width; + child_dimensions.height = (int) child_requisition.height; - max = wrap_table_art_irect_max_frame (&child_frame, &max); + max_dimensions = wrap_table_art_irect_max_dimensions (&child_dimensions, &max_dimensions); } } - return max; + return max_dimensions; } static int @@ -607,33 +599,33 @@ wrap_table_get_num_fitting (int available, return num; } -static ArtIRect -wrap_table_get_content_frame (const NautilusWrapTable *wrap_table) +static NautilusDimensions +wrap_table_get_content_dimensions (const NautilusWrapTable *wrap_table) { - ArtIRect content_frame; + NautilusDimensions content_dimensions; guint num_children; - g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_ART_IRECT_EMPTY); + g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_DIMENSIONS_EMPTY); - content_frame = NAUTILUS_ART_IRECT_EMPTY; + content_dimensions = NAUTILUS_DIMENSIONS_EMPTY; num_children = g_list_length (wrap_table->details->items); if (num_children > 0) { - ArtIRect max_child_frame; - ArtIRect frame; + NautilusDimensions max_child_dimensions; + NautilusDimensions dimensions; int num_cols; int num_rows; - frame = nautilus_irect_gtk_widget_get_frame (GTK_WIDGET (wrap_table)); - max_child_frame = wrap_table_get_max_child_frame (wrap_table); + dimensions = nautilus_gtk_widget_get_dimensions (GTK_WIDGET (wrap_table)); + max_child_dimensions = wrap_table_get_max_child_dimensions (wrap_table); - max_child_frame.x1 = MAX (max_child_frame.x1, 1); - max_child_frame.y1 = MAX (max_child_frame.y1, 1); + max_child_dimensions.width = MAX (max_child_dimensions.width, 1); + max_child_dimensions.height = MAX (max_child_dimensions.height, 1); - num_cols = wrap_table_get_num_fitting (frame.x1, + num_cols = wrap_table_get_num_fitting (dimensions.width, wrap_table->details->x_spacing, - max_child_frame.x1); + max_child_dimensions.width); num_rows = num_children / num_cols; num_rows = MAX (num_rows, 1); @@ -641,11 +633,11 @@ wrap_table_get_content_frame (const NautilusWrapTable *wrap_table) num_rows++; } - content_frame.x1 = frame.x1; - content_frame.y1 = num_rows * max_child_frame.y1; + content_dimensions.width = dimensions.width; + content_dimensions.height = num_rows * max_child_dimensions.height; } - return content_frame; + return content_dimensions; } static ArtIRect @@ -655,7 +647,7 @@ wrap_table_get_content_bounds (const NautilusWrapTable *wrap_table) g_return_val_if_fail (NAUTILUS_IS_WRAP_TABLE (wrap_table), NAUTILUS_ART_IRECT_EMPTY); - content_bounds = nautilus_irect_gtk_widget_get_bounds (GTK_WIDGET (wrap_table)); + content_bounds = nautilus_gtk_widget_get_bounds (GTK_WIDGET (wrap_table)); content_bounds.x0 += GTK_CONTAINER (wrap_table)->border_width; content_bounds.y0 += GTK_CONTAINER (wrap_table)->border_width; @@ -707,7 +699,7 @@ wrap_table_find_child_at_point (const NautilusWrapTable *wrap_table, if (GTK_WIDGET_VISIBLE (child)) { ArtIRect child_bounds; - child_bounds = nautilus_irect_gtk_widget_get_bounds (child); + child_bounds = nautilus_gtk_widget_get_bounds (child); if (nautilus_art_irect_contains_point (&child_bounds, x, y)) { return child; diff --git a/src/nautilus-about.c b/src/nautilus-about.c index 89784fcf8..c3ddfadc3 100644 --- a/src/nautilus-about.c +++ b/src/nautilus-about.c @@ -240,13 +240,13 @@ draw_aa_string (NautilusScalableFont *font, nautilus_scalable_font_draw_text (font, pixbuf, x_pos + shadow_offset, y_pos + shadow_offset, NULL, - font_size, font_size, + font_size, text, strlen (text), shadow_color, NAUTILUS_OPACITY_FULLY_OPAQUE); } nautilus_scalable_font_draw_text (font, pixbuf, x_pos, y_pos, NULL, - font_size, font_size, + font_size, text, strlen (text), color, NAUTILUS_OPACITY_FULLY_OPAQUE); } diff --git a/src/nautilus-sidebar-tabs.c b/src/nautilus-sidebar-tabs.c index c9b5e0d49..5cf51e9c5 100644 --- a/src/nautilus-sidebar-tabs.c +++ b/src/nautilus-sidebar-tabs.c @@ -484,26 +484,23 @@ static int draw_one_tab_plain (NautilusSidebarTabs *sidebar_tabs, GdkGC *gc, char *tab_name, int x, int y, gboolean prelight_flag, GdkRectangle *tab_rect) { - int tab_bottom; - int tab_right; - int name_width, name_height; - int total_width; - GtkWidget *widget; - GdkPixbuf *temp_pixbuf; - GdkColor *foreground_color; + int tab_bottom; + int tab_right; + NautilusDimensions name_dimensions; + int total_width; + GtkWidget *widget; + GdkPixbuf *temp_pixbuf; + GdkColor *foreground_color; g_assert (NAUTILUS_IS_SIDEBAR_TABS (sidebar_tabs)); /* measure the name and compute the bounding box */ - nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, - sidebar_tabs->details->font_size, - sidebar_tabs->details->font_size, - tab_name, - strlen (tab_name), - &name_width, - &name_height); + name_dimensions = nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, + sidebar_tabs->details->font_size, + tab_name, + strlen (tab_name)); - total_width = name_width + 2*TAB_MARGIN; + total_width = name_dimensions.width + 2 * TAB_MARGIN; widget = GTK_WIDGET (sidebar_tabs); @@ -538,14 +535,14 @@ draw_one_tab_plain (NautilusSidebarTabs *sidebar_tabs, GdkGC *gc, gdk_draw_line(widget->window, gc, x + 2, y + 2, x + 2, y + sidebar_tabs->details->tab_height - 1); /* allocate the pixbuf and fill it with the background color */ - temp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, name_width + 1, name_height + 1); + temp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, name_dimensions.width + 1, name_dimensions.height + 1); nautilus_gdk_pixbuf_fill_rectangle_with_color (temp_pixbuf, NULL, nautilus_gdk_color_to_rgb (foreground_color)); /* draw the name into the pixbuf using anti-aliased text */ nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, temp_pixbuf, 1, 1, NULL, - sidebar_tabs->details->font_size, sidebar_tabs->details->font_size, + sidebar_tabs->details->font_size, tab_name, strlen (tab_name), prelight_flag ? NAUTILUS_RGB_COLOR_WHITE : NAUTILUS_RGB_COLOR_BLACK, NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -553,7 +550,7 @@ draw_one_tab_plain (NautilusSidebarTabs *sidebar_tabs, GdkGC *gc, nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, temp_pixbuf, 0, 0, NULL, - sidebar_tabs->details->font_size, sidebar_tabs->details->font_size, + sidebar_tabs->details->font_size, tab_name, strlen (tab_name), prelight_flag ? NAUTILUS_RGB_COLOR_BLACK : NAUTILUS_RGB_COLOR_WHITE, NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -564,7 +561,7 @@ draw_one_tab_plain (NautilusSidebarTabs *sidebar_tabs, GdkGC *gc, widget->window, 0, 0, x + TAB_MARGIN, y + 5, - name_width + 1, name_height + 1, + name_dimensions.width + 1, name_dimensions.height + 1, GDK_PIXBUF_ALPHA_BILEVEL, 128, GDK_RGB_DITHER_MAX, 0, 0); @@ -574,12 +571,12 @@ draw_one_tab_plain (NautilusSidebarTabs *sidebar_tabs, GdkGC *gc, /* draw the bottom lines */ tab_bottom = y + sidebar_tabs->details->tab_height - 1; gdk_gc_set_foreground (gc, &sidebar_tabs->details->line_color); - tab_right = x + 2*TAB_MARGIN + name_width; + tab_right = x + 2*TAB_MARGIN + name_dimensions.width; gdk_gc_set_foreground (gc, &sidebar_tabs->details->line_color); gdk_draw_line(widget->window, gc, tab_right, tab_bottom, widget->parent->allocation.width, tab_bottom); gdk_draw_line(widget->window, gc, 0, tab_bottom, x, tab_bottom); - return name_width + 2*TAB_MARGIN; + return name_dimensions.width + 2 * TAB_MARGIN; } /* utility to draw a single tab piece into a pixbuf */ @@ -647,7 +644,7 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf, GdkRectangle *tab_rect) { GtkWidget *widget; - int name_width, name_height; + NautilusDimensions name_dimensions; int piece_width, tab_width; int current_pos, right_edge_pos; int text_x_pos, left_width; @@ -667,13 +664,10 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf, } /* measure the size of the name */ - nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, - sidebar_tabs->details->font_size, - sidebar_tabs->details->font_size, - tab_name, - strlen (tab_name), - &name_width, - &name_height); + name_dimensions = nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, + sidebar_tabs->details->font_size, + tab_name, + strlen (tab_name)); /* draw the left edge piece */ current_pos = x - widget->allocation.x; @@ -685,7 +679,7 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf, /* draw the middle portion in a loop */ text_x_pos = current_pos; - right_edge_pos = current_pos + name_width; + right_edge_pos = current_pos + name_dimensions.width; while (current_pos < right_edge_pos) { piece_width = draw_tab_piece_aa (sidebar_tabs, tab_pixbuf, current_pos, y - widget->allocation.y, right_edge_pos, TAB_NORMAL_FILL + highlight_offset); @@ -704,7 +698,7 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf, nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, tab_pixbuf, text_x, text_y, NULL, - sidebar_tabs->details->font_size, sidebar_tabs->details->font_size, + sidebar_tabs->details->font_size, tab_name, strlen (tab_name), NAUTILUS_RGB_COLOR_BLACK, NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -714,7 +708,7 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf, nautilus_scalable_font_draw_text (sidebar_tabs->details->tab_font, tab_pixbuf, text_x, text_y, NULL, - sidebar_tabs->details->font_size, sidebar_tabs->details->font_size, + sidebar_tabs->details->font_size, tab_name, strlen (tab_name), NAUTILUS_RGB_COLOR_WHITE, NAUTILUS_OPACITY_FULLY_OPAQUE); @@ -729,7 +723,7 @@ draw_one_tab_themed (NautilusSidebarTabs *sidebar_tabs, GdkPixbuf *tab_pixbuf, } /* return the total tab width */ - tab_width = left_width + name_width; + tab_width = left_width + name_dimensions.width; return tab_width; } @@ -754,30 +748,29 @@ get_text_offset (void) static int get_tab_width (NautilusSidebarTabs *sidebar_tabs, TabItem *this_tab, gboolean is_themed, gboolean first_flag) { - int edge_width, name_width, name_height; + int edge_width; + NautilusDimensions name_dimensions; if (this_tab == NULL) return 0; if (is_themed) { - if (first_flag) + if (first_flag) { edge_width = gdk_pixbuf_get_width (sidebar_tabs->details->tab_piece_images[TAB_NORMAL_LEFT]); - else + } else { edge_width = 0; - nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, - sidebar_tabs->details->font_size, - sidebar_tabs->details->font_size, - this_tab->tab_text, - strlen (this_tab->tab_text), - &name_width, - &name_height); + } + + name_dimensions = nautilus_scalable_font_measure_text (sidebar_tabs->details->tab_font, + sidebar_tabs->details->font_size, + this_tab->tab_text, + strlen (this_tab->tab_text)); } else { edge_width = 2 * TAB_MARGIN; - name_width = gdk_string_width(GTK_WIDGET (sidebar_tabs)->style->font, this_tab->tab_text); + name_dimensions.width = gdk_string_width (GTK_WIDGET (sidebar_tabs)->style->font, this_tab->tab_text); } - return name_width + edge_width; - + return name_dimensions.width + edge_width; } /* fill the canvas buffer with a tiled pixmap */ diff --git a/test/test-nautilus-font-simple.c b/test/test-nautilus-font-simple.c index c7bab0fe7..ee0e7a691 100644 --- a/test/test-nautilus-font-simple.c +++ b/test/test-nautilus-font-simple.c @@ -31,7 +31,6 @@ main (int argc, char* argv[]) 100, NULL, 80, - 80, "Something", strlen ("Something"), NAUTILUS_RGBA_COLOR_OPAQUE_BLUE, diff --git a/test/test-nautilus-font.c b/test/test-nautilus-font.c index 43c2b476f..7ac8647a7 100644 --- a/test/test-nautilus-font.c +++ b/test/test-nautilus-font.c @@ -16,16 +16,15 @@ main (int argc, char* argv[]) ArtIRect multi_lines_area; const char *text = "\nLine Two\n\nLine Four\n\n\nLine Seven"; - const guint font_width = 48; - const guint font_height = 48; + const guint font_size = 48; const guint pixbuf_width = 500; const guint pixbuf_height = 700; const guint line_offset = 2; - const guint empty_line_height = font_height; + const guint empty_line_height = font_size; const int multi_line_x = 10; const int multi_line_y = 10; - g_print ("font_height = %d, empty_line_height = %d\n", font_height, empty_line_height); + g_print ("font_size = %d, empty_line_height = %d\n", font_size, empty_line_height); gtk_init (&argc, &argv); gdk_rgb_init (); @@ -48,25 +47,21 @@ main (int argc, char* argv[]) /* Measure some text lines */ { - guint num_text_lines; - guint *text_line_widths; - guint *text_line_heights; - guint max_width_out; - guint total_height_out; - + guint num_text_lines; + NautilusDimensions *text_line_dimensions; + guint max_width_out; + guint total_height_out; + num_text_lines = nautilus_str_count_characters (text, '\n') + 1; - text_line_widths = g_new (guint, num_text_lines); - text_line_heights = g_new (guint, num_text_lines); + text_line_dimensions = g_new (NautilusDimensions, num_text_lines); nautilus_scalable_font_measure_text_lines (font, - font_width, - font_height, + font_size, text, num_text_lines, empty_line_height, - text_line_widths, - text_line_heights, + text_line_dimensions, &max_width_out, &total_height_out); @@ -78,9 +73,7 @@ main (int argc, char* argv[]) max_width_out, total_height_out); - - g_free (text_line_widths); - g_free (text_line_heights); + g_free (text_line_dimensions); } clip_area.x0 = 300; @@ -121,8 +114,7 @@ main (int argc, char* argv[]) multi_line_x, multi_line_y, &whole_area, - font_width, - font_height, + font_size, text, GTK_JUSTIFY_LEFT, line_offset, @@ -143,7 +135,6 @@ main (int argc, char* argv[]) clip_area.y0, NULL, 80, - 80, "Something", strlen ("Something"), NAUTILUS_RGBA_COLOR_OPAQUE_BLUE, diff --git a/test/test-nautilus-glyph-simple.c b/test/test-nautilus-glyph-simple.c index 2c8ed8039..3b00261fc 100644 --- a/test/test-nautilus-glyph-simple.c +++ b/test/test-nautilus-glyph-simple.c @@ -19,7 +19,7 @@ glyph_new (const char *text, int font_size) font = nautilus_scalable_font_get_default_font (); g_return_val_if_fail (font != NULL, NULL); - glyph = nautilus_glyph_new (font, text, strlen (text), font_size); + glyph = nautilus_glyph_new (font, font_size, text, strlen (text)); g_return_val_if_fail (glyph != NULL, NULL); gtk_object_unref (GTK_OBJECT (font)); diff --git a/test/test-nautilus-glyph.c b/test/test-nautilus-glyph.c index a845c42e8..4f159485d 100644 --- a/test/test-nautilus-glyph.c +++ b/test/test-nautilus-glyph.c @@ -19,7 +19,7 @@ glyph_new (const char *text, int font_size) font = nautilus_scalable_font_get_default_font (); g_return_val_if_fail (font != NULL, NULL); - glyph = nautilus_glyph_new (font, text, strlen (text), font_size); + glyph = nautilus_glyph_new (font, font_size, text, strlen (text)); g_return_val_if_fail (glyph != NULL, NULL); gtk_object_unref (GTK_OBJECT (font)); @@ -27,30 +27,6 @@ glyph_new (const char *text, int font_size) return glyph; } -// static GdkPixbuf * -// glyph_pixbuf_new (const char *text, -// int font_size, -// guint32 text_color) -// { -// NautilusGlyph *glyph; -// GdkPixbuf *pixbuf; - -// g_return_val_if_fail (text != NULL, NULL); -// g_return_val_if_fail (text[0] != '\0', NULL); -// g_return_val_if_fail (font_size >= 5, NULL); -// g_return_val_if_fail (font_size <= 200, NULL); - -// glyph = glyph_new (text, font_size); -// g_return_val_if_fail (glyph != NULL, NULL); - -// pixbuf = nautilus_glyph_as_alpha_pixbuf (glyph, text_color); -// g_return_val_if_fail (pixbuf != NULL, NULL); - -// nautilus_glyph_free (glyph); - -// return pixbuf; -// } - int main (int argc, char* argv[]) { @@ -131,7 +107,6 @@ main (int argc, char* argv[]) y + font_size + 4, NULL, font_size, - font_size, text, strlen (text), NAUTILUS_RGBA_COLOR_OPAQUE_RED, diff --git a/test/test-nautilus-pixbuf-tile.c b/test/test-nautilus-pixbuf-tile.c index 14fe33810..51dc6e99a 100644 --- a/test/test-nautilus-pixbuf-tile.c +++ b/test/test-nautilus-pixbuf-tile.c @@ -38,7 +38,7 @@ pixbuf_drawing_area_expose_event (GtkWidget *widget, NAUTILUS_OPACITY_FULLY_OPAQUE, GDK_INTERP_NEAREST); - dest = nautilus_irect_gtk_widget_get_bounds (widget); + dest = nautilus_gtk_widget_get_bounds (widget); nautilus_gdk_pixbuf_draw_to_drawable (buffer, widget->window, widget->style->white_gc, @@ -76,7 +76,7 @@ drawable_drawing_area_expose_event (GtkWidget *widget, g_assert (tile != NULL); } - dest = nautilus_irect_gtk_widget_get_bounds (widget); + dest = nautilus_gtk_widget_get_bounds (widget); nautilus_gdk_pixbuf_draw_to_drawable_tiled (tile, widget->window, widget->style->white_gc, diff --git a/test/test.c b/test/test.c index c32b84313..6b8e79d3e 100644 --- a/test/test.c +++ b/test/test.c @@ -333,7 +333,9 @@ test_pixbuf_draw_rectangle_tiled (GdkPixbuf *pixbuf, g_return_if_fail (tile_pixbuf != NULL); if (x0 == -1 && y0 == -1 && x1 == -1 && y1 == -1) { - area = nautilus_gdk_pixbuf_get_frame (pixbuf); + NautilusDimensions dimensions; + dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf); + area = nautilus_art_irect_assign_dimensions (0, 0, &dimensions); } else { g_return_if_fail (x0 >= 0); g_return_if_fail (y0 >= 0); |