PATCH: ellipse.c : keep aspect ration / circle. Was : Re: PATCH: ellipse.c : central connection point
- From: Grégoire Dooms <dooms info ucl ac be>
- To: dia-list gnome org
- Subject: PATCH: ellipse.c : keep aspect ration / circle. Was : Re: PATCH: ellipse.c : central connection point
- Date: Sun, 14 Mar 2004 15:38:30 +0100
Lars Clausen wrote:
Ensuring a circle is a different matter, and also a concern for the
box. There's actually three possibilities: Circle, keep aspect ratio,
and free resizing. These could be implemented with a drop-down menu in
the properties (compare the FS - Flow and Standard - Image objects for
implementation).
I wouldn't mind an implementation for the circle/aspect/resize part,
though I think a meta key for that is overkill -- we don't have too many
metakeys, and I would like to save them for things that are a) common to
a number of objects, and b) something you want to turn on and off on a
whim.
Attached is an implementation of the keep aspect ratio / circle part.
It is implemented in a manner similar to image.c
It did not use a dropdown menu in the UI but two booleans: keep_aspect
and one_one_aspect.
I also attached a patch to the fr.po file relating to a new string in
the UI:
"Circle aspect ratio (1:1)"
I submitted those patches in bugzilla : BUG 137156
Best regards,
--
Grégoire Dooms.
Index: ellipse.c
===================================================================
RCS file: /cvs/gnome/dia/objects/standard/ellipse.c,v
retrieving revision 1.36
diff -c -r1.36 ellipse.c
*** ellipse.c 5 Mar 2004 20:38:08 -0000 1.36
--- ellipse.c 14 Mar 2004 14:27:37 -0000
***************
*** 51,63 ****
Color border_color;
Color inner_color;
gboolean show_background;
LineStyle line_style;
real dashlength;
};
static struct _EllipseProperties {
gboolean show_background;
! } default_properties = { TRUE };
static real ellipse_distance_from(Ellipse *ellipse, Point *point);
static void ellipse_select(Ellipse *ellipse, Point *clicked_point,
--- 51,67 ----
Color border_color;
Color inner_color;
gboolean show_background;
+ gboolean keep_aspect;
+ gboolean one_one_aspect;
LineStyle line_style;
real dashlength;
};
static struct _EllipseProperties {
+ gboolean keep_aspect;
+ gboolean one_one_aspect;
gboolean show_background;
! } default_properties = { FALSE, FALSE, TRUE };
static real ellipse_distance_from(Ellipse *ellipse, Point *point);
static void ellipse_select(Ellipse *ellipse, Point *clicked_point,
***************
*** 125,130 ****
--- 129,138 ----
PROP_STD_FILL_COLOUR,
PROP_STD_SHOW_BACKGROUND,
PROP_STD_LINE_STYLE,
+ { "keep_aspect", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE,
+ N_("Keep aspect ratio"), NULL, NULL},
+ { "one_one_aspect", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE,
+ N_("Circle aspect ratio (1:1)"), NULL, NULL},
PROP_DESC_END
};
***************
*** 142,147 ****
--- 150,157 ----
{ "line_colour", PROP_TYPE_COLOUR, offsetof(Ellipse, border_color) },
{ "fill_colour", PROP_TYPE_COLOUR, offsetof(Ellipse, inner_color) },
{ "show_background", PROP_TYPE_BOOL, offsetof(Ellipse, show_background) },
+ { "keep_aspect", PROP_TYPE_BOOL, offsetof(Ellipse, keep_aspect) },
+ { "one_one_aspect", PROP_TYPE_BOOL, offsetof(Ellipse, one_one_aspect) },
{ "line_style", PROP_TYPE_LINESTYLE,
offsetof(Ellipse, line_style), offsetof(Ellipse, dashlength) },
{ NULL, 0, 0 }
***************
*** 157,164 ****
--- 167,176 ----
static void
ellipse_set_props(Ellipse *ellipse, GPtrArray *props)
{
+
object_set_props_from_offsets(&ellipse->element.object,
ellipse_offsets, props);
+
ellipse_update_data(ellipse);
}
***************
*** 202,217 ****
corner_to.y = elem->corner.y + delta.y;
return ellipse_move(ellipse, &corner_to);
} else {
! Point center;
! center.x = elem->corner.x + elem->width/2;
! center.y = elem->corner.y + elem->height/2;
! Point opposite_to;
! opposite_to.x = center.x - (to->x-center.x);
! opposite_to.y = center.y - (to->y-center.y);
- element_move_handle(&ellipse->element, handle->id, to, cp, reason, modifiers);
- element_move_handle(&ellipse->element, 7-handle->id, &opposite_to, cp, reason, modifiers);
-
ellipse_update_data(ellipse);
return NULL;
--- 214,274 ----
corner_to.y = elem->corner.y + delta.y;
return ellipse_move(ellipse, &corner_to);
} else {
! if (ellipse->keep_aspect == TRUE){
! float width, height;
! float new_width, new_height;
! float to_width, aspect_width;
! width = ellipse->element.width;
! height = ellipse->element.height;
! Point center;
! center.x = elem->corner.x + width/2;
! center.y = elem->corner.y + height/2;
! switch (handle->id) {
! case HANDLE_RESIZE_E:
! case HANDLE_RESIZE_W:
! new_width = 2 * fabsf(to->x - center.x);
! new_height = new_width / width * height;
! break;
! case HANDLE_RESIZE_N:
! case HANDLE_RESIZE_S:
! new_height = 2 * fabsf(to->y - center.y);
! new_width = new_height / height * width;
! break;
! case HANDLE_RESIZE_NW:
! case HANDLE_RESIZE_NE:
! case HANDLE_RESIZE_SW:
! case HANDLE_RESIZE_SE:
! to_width = 2 * fabsf(to->x - center.x);
! aspect_width = 2 * fabsf(to->y - center.y) / height * width;
! new_width = to_width < aspect_width ? to_width : aspect_width;
! new_height = new_width / width * height;
! break;
! default:
! new_width = width;
! new_height = height;
! break;
! }
!
! Point nw_to, se_to;
! nw_to.x = center.x - new_width/2;
! nw_to.y = center.y - new_height/2;
! se_to.x = center.x + new_width/2;
! se_to.y = center.y + new_height/2;
!
! element_move_handle(&ellipse->element, HANDLE_RESIZE_NW, &nw_to, cp, reason, modifiers);
! element_move_handle(&ellipse->element, HANDLE_RESIZE_SE, &se_to, cp, reason, modifiers);
! } else {
! Point center;
! center.x = elem->corner.x + elem->width/2;
! center.y = elem->corner.y + elem->height/2;
! Point opposite_to;
! opposite_to.x = center.x - (to->x-center.x);
! opposite_to.y = center.y - (to->y-center.y);
!
! element_move_handle(&ellipse->element, handle->id, to, cp, reason, modifiers);
! element_move_handle(&ellipse->element, 7-handle->id, &opposite_to, cp, reason, modifiers);
! }
ellipse_update_data(ellipse);
return NULL;
***************
*** 269,274 ****
--- 326,343 ----
Object *obj = &elem->object;
Point center;
real half_x, half_y;
+
+ /* handle circle implies keep_aspect */
+ if (ellipse->one_one_aspect == TRUE)
+ ellipse->keep_aspect = TRUE;
+ if (ellipse->keep_aspect == FALSE)
+ ellipse->one_one_aspect = FALSE;
+
+ /* handle circle implies height=width */
+ if (ellipse->one_one_aspect == TRUE){
+ float size = elem->height < elem->width ? elem->height : elem->width;
+ elem->height = elem->width = size;
+ }
center.x = elem->corner.x + elem->width / 2.0;
center.y = elem->corner.y + elem->height / 2.0;
***************
*** 347,352 ****
--- 416,423 ----
attributes_get_default_line_style(&ellipse->line_style,
&ellipse->dashlength);
ellipse->show_background = default_properties.show_background;
+ ellipse->keep_aspect = default_properties.keep_aspect;
+ ellipse->one_one_aspect = default_properties.one_one_aspect;
element_init(elem, 9, 9);
***************
*** 395,400 ****
--- 466,473 ----
newellipse->inner_color = ellipse->inner_color;
newellipse->dashlength = ellipse->dashlength;
newellipse->show_background = ellipse->show_background;
+ newellipse->keep_aspect = ellipse->keep_aspect;
+ newellipse->one_one_aspect = ellipse->one_one_aspect;
newellipse->line_style = ellipse->line_style;
for (i=0;i<9;i++) {
***************
*** 430,435 ****
--- 503,516 ----
data_add_boolean(new_attribute(obj_node, "show_background"),
ellipse->show_background);
+ if (ellipse->keep_aspect)
+ data_add_boolean(new_attribute(obj_node, "keep_aspect"),
+ ellipse->keep_aspect);
+
+ if (ellipse->one_one_aspect)
+ data_add_boolean(new_attribute(obj_node, "one_one_aspect"),
+ ellipse->one_one_aspect);
+
if (ellipse->line_style != LINESTYLE_SOLID) {
data_add_enum(new_attribute(obj_node, "line_style"),
ellipse->line_style);
***************
*** 477,482 ****
--- 558,573 ----
if (attr != NULL)
ellipse->show_background = data_boolean(attribute_first_data(attr));
+ ellipse->keep_aspect = FALSE;
+ attr = object_find_attribute(obj_node, "keep_aspect");
+ if (attr != NULL)
+ ellipse->keep_aspect = data_boolean(attribute_first_data(attr));
+
+ ellipse->one_one_aspect = FALSE;
+ attr = object_find_attribute(obj_node, "one_one_aspect");
+ if (attr != NULL)
+ ellipse->one_one_aspect = data_boolean(attribute_first_data(attr));
+
ellipse->line_style = LINESTYLE_SOLID;
attr = object_find_attribute(obj_node, "line_style");
if (attr != NULL)
Index: fr.po
===================================================================
RCS file: /cvs/gnome/dia/po/fr.po,v
retrieving revision 1.87
diff -c -r1.87 fr.po
*** fr.po 7 Mar 2004 11:11:20 -0000 1.87
--- fr.po 14 Mar 2004 14:30:45 -0000
***************
*** 4337,4342 ****
--- 4337,4346 ----
msgid "Cusp control"
msgstr "Contrôle « Cusp »"
+ #: objects/standard/ellipse.c:135
+ msgid "Circle aspect ratio (1:1)"
+ msgstr "Proportions de cercle (1:1)"
+
#: objects/standard/image.c:130
msgid "Image file"
msgstr "Fichier image :"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]