summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas James Alexander Thurman <tthurman@src.gnome.org>2006-05-01 23:28:45 +0000
committerThomas James Alexander Thurman <tthurman@src.gnome.org>2006-05-01 23:28:45 +0000
commit910753a905b66a91733a02b382ee79aef3d503d4 (patch)
tree59ed3a0f3b50f47f0cf74fc3f0bedfca617a9905
parente0d076a4fdf43dab7b0284614339812db4b2e6b5 (diff)
downloadmetacity-910753a905b66a91733a02b382ee79aef3d503d4.tar.gz
#113162: corner rounding can be for any amount
-rw-r--r--src/frames.c147
-rw-r--r--src/theme-parser.c59
-rw-r--r--src/theme.c16
-rw-r--r--src/theme.h17
4 files changed, 123 insertions, 116 deletions
diff --git a/src/frames.c b/src/frames.c
index 51cbe8b8..9f45f1dc 100644
--- a/src/frames.c
+++ b/src/frames.c
@@ -22,6 +22,7 @@
*/
#include <config.h>
+#include <math.h>
#include "boxes.h"
#include "frames.h"
#include "util.h"
@@ -753,10 +754,10 @@ meta_frames_apply_shapes (MetaFrames *frames,
meta_frames_calc_geometry (frames, frame, &fgeom);
- if (!(fgeom.top_left_corner_rounded ||
- fgeom.top_right_corner_rounded ||
- fgeom.bottom_left_corner_rounded ||
- fgeom.bottom_right_corner_rounded ||
+ if (!(fgeom.top_left_corner_rounded_radius!=0 ||
+ fgeom.top_right_corner_rounded_radius!=0 ||
+ fgeom.bottom_left_corner_rounded_radius!=0 ||
+ fgeom.bottom_right_corner_rounded_radius!=0 ||
window_has_shape))
{
if (frame->shape_applied)
@@ -781,102 +782,72 @@ meta_frames_apply_shapes (MetaFrames *frames,
corners_xregion = XCreateRegion ();
- if (fgeom.top_left_corner_rounded)
+ if (fgeom.top_left_corner_rounded_radius != 0)
{
- xrect.x = 0;
- xrect.y = 0;
- xrect.width = 5;
- xrect.height = 1;
-
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ const int radius = fgeom.top_left_corner_rounded_radius;
+ int i;
- xrect.y = 1;
- xrect.width = 3;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = 2;
- xrect.width = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = 3;
- xrect.width = 1;
- xrect.height = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ for (i=0; i<radius; i++)
+ {
+ const int width = 1 + (radius - sqrt(radius*radius - (radius-i)*(radius-i)));
+ xrect.x = 0;
+ xrect.y = i;
+ xrect.width = width;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
}
- if (fgeom.top_right_corner_rounded)
+ if (fgeom.top_right_corner_rounded_radius != 0)
{
- xrect.x = new_window_width - 5;
- xrect.y = 0;
- xrect.width = 5;
- xrect.height = 1;
-
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ const int radius = fgeom.top_right_corner_rounded_radius;
+ int i;
- xrect.y = 1;
- xrect.x = new_window_width - 3;
- xrect.width = 3;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = 2;
- xrect.x = new_window_width - 2;
- xrect.width = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = 3;
- xrect.x = new_window_width - 1;
- xrect.width = 1;
- xrect.height = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ for (i=0; i<radius; i++)
+ {
+ const int width = 1 + (radius - sqrt(radius*radius - (radius-i)*(radius-i)));
+ xrect.x = new_window_width - width;
+ xrect.y = i;
+ xrect.width = width;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
}
- if (fgeom.bottom_left_corner_rounded)
+ if (fgeom.bottom_left_corner_rounded_radius != 0)
{
- xrect.x = 0;
- xrect.y = new_window_height - 1;
- xrect.width = 5;
- xrect.height = 1;
-
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = new_window_height - 2;
- xrect.width = 3;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = new_window_height - 3;
- xrect.width = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = new_window_height - 5;
- xrect.width = 1;
- xrect.height = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ const int radius = fgeom.bottom_left_corner_rounded_radius;
+ int i;
+
+ for (i=0; i<radius; i++)
+ {
+ const int width = 1 + (radius - sqrt(radius*radius - (radius-i)*(radius-i)));
+ xrect.x = 0;
+ xrect.y = new_window_height - i;
+ xrect.width = width;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
}
- if (fgeom.bottom_right_corner_rounded)
+ if (fgeom.bottom_right_corner_rounded_radius != 0)
{
- xrect.x = new_window_width - 5;
- xrect.y = new_window_height - 1;
- xrect.width = 5;
- xrect.height = 1;
-
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = new_window_height - 2;
- xrect.x = new_window_width - 3;
- xrect.width = 3;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = new_window_height - 3;
- xrect.x = new_window_width - 2;
- xrect.width = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
-
- xrect.y = new_window_height - 5;
- xrect.x = new_window_width - 1;
- xrect.width = 1;
- xrect.height = 2;
- XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ const int radius = fgeom.bottom_right_corner_rounded_radius;
+ int i;
+
+ for (i=0; i<radius; i++)
+ {
+ const int width = 1 + (radius - sqrt(radius*radius - (radius-i)*(radius-i)));
+ xrect.x = new_window_width - width;
+ xrect.y = new_window_height - i;
+ xrect.width = width;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
}
window_xregion = XCreateRegion ();
diff --git a/src/theme-parser.c b/src/theme-parser.c
index 68efd898..dfbb05d8 100644
--- a/src/theme-parser.c
+++ b/src/theme-parser.c
@@ -574,6 +574,41 @@ parse_boolean (const char *str,
}
static gboolean
+parse_rounding (const char *str,
+ guint *val,
+ GMarkupParseContext *context,
+ MetaTheme *theme,
+ GError **error)
+{
+ if (strcmp ("true", str) == 0)
+ *val = 5; /* historical "true" value */
+ else if (strcmp ("false", str) == 0)
+ *val = 0;
+ else
+ {
+ int tmp;
+ gboolean result;
+ if (!META_THEME_ALLOWS (theme, META_THEME_VARIED_ROUND_CORNERS))
+ {
+ /* Not known in this version, so bail. */
+ set_error (error, context, G_MARKUP_ERROR,
+ G_MARKUP_ERROR_PARSE,
+ _("Boolean values must be \"true\" or \"false\" not \"%s\""),
+ str);
+ return FALSE;
+ }
+
+ result = parse_positive_integer (str, &tmp, context, theme, error);
+
+ *val = tmp;
+
+ return result;
+ }
+
+ return TRUE;
+}
+
+static gboolean
parse_angle (const char *str,
double *val,
GMarkupParseContext *context,
@@ -799,10 +834,10 @@ parse_toplevel_element (GMarkupParseContext *context,
const char *rounded_bottom_left = NULL;
const char *rounded_bottom_right = NULL;
gboolean has_title_val;
- gboolean rounded_top_left_val;
- gboolean rounded_top_right_val;
- gboolean rounded_bottom_left_val;
- gboolean rounded_bottom_right_val;
+ guint rounded_top_left_val;
+ guint rounded_top_right_val;
+ guint rounded_bottom_left_val;
+ guint rounded_bottom_right_val;
double title_scale_val;
MetaFrameLayout *parent_layout;
@@ -834,13 +869,13 @@ parse_toplevel_element (GMarkupParseContext *context,
rounded_bottom_left_val = FALSE;
rounded_bottom_right_val = FALSE;
- if (rounded_top_left && !parse_boolean (rounded_top_left, &rounded_top_left_val, context, error))
+ if (rounded_top_left && !parse_rounding (rounded_top_left, &rounded_top_left_val, context, info->theme, error))
return;
- if (rounded_top_right && !parse_boolean (rounded_top_right, &rounded_top_right_val, context, error))
+ if (rounded_top_right && !parse_rounding (rounded_top_right, &rounded_top_right_val, context, info->theme, error))
return;
- if (rounded_bottom_left && !parse_boolean (rounded_bottom_left, &rounded_bottom_left_val, context, error))
+ if (rounded_bottom_left && !parse_rounding (rounded_bottom_left, &rounded_bottom_left_val, context, info->theme, error))
return;
- if (rounded_bottom_right && !parse_boolean (rounded_bottom_right, &rounded_bottom_right_val, context, error))
+ if (rounded_bottom_right && !parse_rounding (rounded_bottom_right, &rounded_bottom_right_val, context, info->theme, error))
return;
title_scale_val = 1.0;
@@ -882,16 +917,16 @@ parse_toplevel_element (GMarkupParseContext *context,
info->layout->title_scale = title_scale_val;
if (rounded_top_left)
- info->layout->top_left_corner_rounded = rounded_top_left_val;
+ info->layout->top_left_corner_rounded_radius = rounded_top_left_val;
if (rounded_top_right)
- info->layout->top_right_corner_rounded = rounded_top_right_val;
+ info->layout->top_right_corner_rounded_radius = rounded_top_right_val;
if (rounded_bottom_left)
- info->layout->bottom_left_corner_rounded = rounded_bottom_left_val;
+ info->layout->bottom_left_corner_rounded_radius = rounded_bottom_left_val;
if (rounded_bottom_right)
- info->layout->bottom_right_corner_rounded = rounded_bottom_right_val;
+ info->layout->bottom_right_corner_rounded_radius = rounded_bottom_right_val;
meta_theme_insert_layout (info->theme, name, info->layout);
diff --git a/src/theme.c b/src/theme.c
index b0cff5ba..a9755759 100644
--- a/src/theme.c
+++ b/src/theme.c
@@ -759,20 +759,20 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
else
min_size_for_rounding = 5;
- fgeom->top_left_corner_rounded = FALSE;
- fgeom->top_right_corner_rounded = FALSE;
- fgeom->bottom_left_corner_rounded = FALSE;
- fgeom->bottom_right_corner_rounded = FALSE;
+ fgeom->top_left_corner_rounded_radius = 0;
+ fgeom->top_right_corner_rounded_radius = 0;
+ fgeom->bottom_left_corner_rounded_radius = 0;
+ fgeom->bottom_right_corner_rounded_radius = 0;
if (fgeom->top_height + fgeom->left_width >= min_size_for_rounding)
- fgeom->top_left_corner_rounded = layout->top_left_corner_rounded;
+ fgeom->top_left_corner_rounded_radius = layout->top_left_corner_rounded_radius;
if (fgeom->top_height + fgeom->right_width >= min_size_for_rounding)
- fgeom->top_right_corner_rounded = layout->top_right_corner_rounded;
+ fgeom->top_right_corner_rounded_radius = layout->top_right_corner_rounded_radius;
if (fgeom->bottom_height + fgeom->left_width >= min_size_for_rounding)
- fgeom->bottom_left_corner_rounded = layout->bottom_left_corner_rounded;
+ fgeom->bottom_left_corner_rounded_radius = layout->bottom_left_corner_rounded_radius;
if (fgeom->bottom_height + fgeom->right_width >= min_size_for_rounding)
- fgeom->bottom_right_corner_rounded = layout->bottom_right_corner_rounded;
+ fgeom->bottom_right_corner_rounded_radius = layout->bottom_right_corner_rounded_radius;
}
MetaGradientSpec*
diff --git a/src/theme.h b/src/theme.h
index d6ccf181..aef47a83 100644
--- a/src/theme.h
+++ b/src/theme.h
@@ -98,10 +98,10 @@ struct _MetaFrameLayout
guint has_title : 1;
/* Round corners */
- guint top_left_corner_rounded : 1;
- guint top_right_corner_rounded : 1;
- guint bottom_left_corner_rounded : 1;
- guint bottom_right_corner_rounded : 1;
+ guint top_left_corner_rounded_radius;
+ guint top_right_corner_rounded_radius;
+ guint bottom_left_corner_rounded_radius;
+ guint bottom_right_corner_rounded_radius;
};
/* Calculated actual geometry of the frame */
@@ -148,10 +148,10 @@ struct _MetaFrameGeometry
/* End of button rects (if changed adjust memset hack) */
/* Round corners */
- guint top_left_corner_rounded : 1;
- guint top_right_corner_rounded : 1;
- guint bottom_left_corner_rounded : 1;
- guint bottom_right_corner_rounded : 1;
+ guint top_left_corner_rounded_radius;
+ guint top_right_corner_rounded_radius;
+ guint bottom_left_corner_rounded_radius;
+ guint bottom_right_corner_rounded_radius;
};
typedef enum
@@ -857,5 +857,6 @@ guint meta_theme_earliest_version_with_button (MetaButtonType type);
/* What version of the theme file format were various features introduced in? */
#define META_THEME_UBIQUITOUS_CONSTANTS 2
+#define META_THEME_VARIED_ROUND_CORNERS 2
#endif