static void ellipse_set_props(Ellipse *ellipse, GPtrArray *props) { object_set_props_from_offsets(&ellipse->element.object, ellipse_offsets,props); ellipse_update_data(ellipse, ANCHOR_MIDDLE, ANCHOR_MIDDLE); }
static void aspect_change_apply(struct AspectChange *change, DiaObject *obj) { Ellipse *ellipse = (Ellipse*)obj; ellipse->aspect = change->new_type; ellipse_update_data(ellipse); }
static ObjectChange* ellipse_move(Ellipse *ellipse, Point *to) { ellipse->element.corner = *to; ellipse_update_data(ellipse); return NULL; }
static void aspect_change_revert(struct AspectChange *change, DiaObject *obj) { Ellipse *ellipse = (Ellipse*)obj; ellipse->aspect = change->old_type; ellipse->element.corner = change->topleft; ellipse->element.width = change->width; ellipse->element.height = change->height; ellipse_update_data(ellipse); }
static DiaObject * ellipse_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Ellipse *ellipse; Element *elem; DiaObject *obj; int i; ellipse = g_malloc0(sizeof(Ellipse)); elem = &ellipse->element; obj = &elem->object; obj->type = &ellipse_type; obj->ops = &ellipse_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; ellipse->border_width = attributes_get_default_linewidth(); ellipse->border_color = attributes_get_foreground(); ellipse->inner_color = attributes_get_background(); attributes_get_default_line_style(&ellipse->line_style, &ellipse->dashlength); ellipse->show_background = default_properties.show_background; ellipse->aspect = default_properties.aspect; element_init(elem, 9, 9); obj->handles[8] = &ellipse->center_handle; obj->handles[8]->id = HANDLE_CUSTOM1; obj->handles[8]->type = HANDLE_MAJOR_CONTROL; obj->handles[8]->connected_to = NULL; obj->handles[8]->connect_type = HANDLE_NONCONNECTABLE; for (i=0;i<9;i++) { obj->connections[i] = &ellipse->connections[i]; ellipse->connections[i].object = obj; ellipse->connections[i].connected = NULL; } ellipse->connections[8].flags = CP_FLAGS_MAIN; ellipse_update_data(ellipse); *handle1 = NULL; *handle2 = obj->handles[7]; return &ellipse->element.object; }
static ObjectChange* ellipse_move_handle(Ellipse *ellipse, Handle *handle, Point *to, ConnectionPoint *cp, HandleMoveReason reason, ModifierKeys modifiers) { AnchorShape horiz = ANCHOR_MIDDLE, vert = ANCHOR_MIDDLE; Point corner; real width, height; assert(ellipse!=NULL); assert(handle!=NULL); assert(to!=NULL); /* remember ... */ corner = ellipse->element.corner; width = ellipse->element.width; height = ellipse->element.height; element_move_handle(&ellipse->element, handle->id, to, cp, reason, modifiers); switch (handle->id) { case HANDLE_RESIZE_NW: horiz = ANCHOR_END; vert = ANCHOR_END; break; case HANDLE_RESIZE_N: vert = ANCHOR_END; break; case HANDLE_RESIZE_NE: horiz = ANCHOR_START; vert = ANCHOR_END; break; case HANDLE_RESIZE_E: horiz = ANCHOR_START; break; case HANDLE_RESIZE_SE: horiz = ANCHOR_START; vert = ANCHOR_START; break; case HANDLE_RESIZE_S: vert = ANCHOR_START; break; case HANDLE_RESIZE_SW: horiz = ANCHOR_END; vert = ANCHOR_START; break; case HANDLE_RESIZE_W: horiz = ANCHOR_END; break; default: break; } ellipse_update_data(ellipse, horiz, vert); if (width != ellipse->element.width && height != ellipse->element.height) return element_change_new (&corner, width, height, &ellipse->element); return NULL; }
static DiaObject * ellipse_load(ObjectNode obj_node, int version,DiaContext *ctx) { Ellipse *ellipse; Element *elem; DiaObject *obj; int i; AttributeNode attr; ellipse = g_malloc0(sizeof(Ellipse)); elem = &ellipse->element; obj = &elem->object; obj->type = &fc_ellipse_type; obj->ops = &ellipse_ops; element_load(elem, obj_node, ctx); ellipse->border_width = 0.1; attr = object_find_attribute(obj_node, "border_width"); if (attr != NULL) ellipse->border_width = data_real(attribute_first_data(attr), ctx); ellipse->border_color = color_black; attr = object_find_attribute(obj_node, "border_color"); if (attr != NULL) data_color(attribute_first_data(attr), &ellipse->border_color, ctx); ellipse->inner_color = color_white; attr = object_find_attribute(obj_node, "inner_color"); if (attr != NULL) data_color(attribute_first_data(attr), &ellipse->inner_color, ctx); ellipse->show_background = TRUE; attr = object_find_attribute(obj_node, "show_background"); if (attr != NULL) ellipse->show_background = data_boolean( attribute_first_data(attr), ctx); ellipse->line_style = LINESTYLE_SOLID; attr = object_find_attribute(obj_node, "line_style"); if (attr != NULL) ellipse->line_style = data_enum(attribute_first_data(attr), ctx); ellipse->dashlength = DEFAULT_LINESTYLE_DASHLEN; attr = object_find_attribute(obj_node, "dashlength"); if (attr != NULL) ellipse->dashlength = data_real(attribute_first_data(attr), ctx); ellipse->padding = default_properties.padding; attr = object_find_attribute(obj_node, "padding"); if (attr != NULL) ellipse->padding = data_real(attribute_first_data(attr), ctx); ellipse->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) ellipse->text = data_text(attribute_first_data(attr), ctx); else ellipse->text = new_text_default(&obj->position, &ellipse->border_color, ALIGN_CENTER); /* old default: only growth, manual shrink */ ellipse->text_fitting = TEXTFIT_WHEN_NEEDED; attr = object_find_attribute(obj_node, PROP_STDNAME_TEXT_FITTING); if (attr != NULL) ellipse->text_fitting = data_enum(attribute_first_data(attr), ctx); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &ellipse->connections[i]; ellipse->connections[i].object = obj; ellipse->connections[i].connected = NULL; ellipse->connections[i].flags = 0; } ellipse->connections[16].flags = CP_FLAGS_MAIN; ellipse_update_data(ellipse, ANCHOR_MIDDLE, ANCHOR_MIDDLE); return &ellipse->element.object; }
static DiaObject * ellipse_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Ellipse *ellipse; Element *elem; DiaObject *obj; Point p; int i; DiaFont *font = NULL; real font_height; init_default_values(); ellipse = g_malloc0(sizeof(Ellipse)); elem = &ellipse->element; obj = &elem->object; obj->type = &fc_ellipse_type; obj->ops = &ellipse_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; ellipse->border_width = attributes_get_default_linewidth(); ellipse->border_color = attributes_get_foreground(); ellipse->inner_color = attributes_get_background(); ellipse->show_background = default_properties.show_background; attributes_get_default_line_style(&ellipse->line_style,&ellipse->dashlength); ellipse->padding = default_properties.padding; attributes_get_default_font(&font, &font_height); p = *startpoint; p.x += elem->width / 2.0; p.y += elem->height / 2.0 + font_height / 2; ellipse->text = new_text("", font, font_height, &p, &ellipse->border_color, ALIGN_CENTER); dia_font_unref(font); /* new default: let the user decide the size? */ ellipse->text_fitting = TEXTFIT_ALWAYS; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &ellipse->connections[i]; ellipse->connections[i].object = obj; ellipse->connections[i].connected = NULL; ellipse->connections[i].flags = 0; } ellipse->connections[16].flags = CP_FLAGS_MAIN; ellipse_update_data(ellipse, ANCHOR_MIDDLE, ANCHOR_MIDDLE); *handle1 = NULL; *handle2 = obj->handles[7]; return &ellipse->element.object; }
static DiaObject *ellipse_load(ObjectNode obj_node, int version, DiaContext *ctx) { Ellipse *ellipse; Element *elem; DiaObject *obj; int i; AttributeNode attr; ellipse = g_malloc0(sizeof(Ellipse)); elem = &ellipse->element; obj = &elem->object; obj->type = &ellipse_type; obj->ops = &ellipse_ops; element_load(elem, obj_node, ctx); ellipse->border_width = 0.1; attr = object_find_attribute(obj_node, "border_width"); if (attr != NULL) ellipse->border_width = data_real(attribute_first_data(attr), ctx); ellipse->border_color = color_black; attr = object_find_attribute(obj_node, "border_color"); if (attr != NULL) data_color(attribute_first_data(attr), &ellipse->border_color, ctx); ellipse->inner_color = color_white; attr = object_find_attribute(obj_node, "inner_color"); if (attr != NULL) data_color(attribute_first_data(attr), &ellipse->inner_color, ctx); ellipse->show_background = TRUE; attr = object_find_attribute(obj_node, "show_background"); if (attr != NULL) ellipse->show_background = data_boolean(attribute_first_data(attr), ctx); ellipse->aspect = FREE_ASPECT; attr = object_find_attribute(obj_node, "aspect"); if (attr != NULL) ellipse->aspect = data_enum(attribute_first_data(attr), ctx); ellipse->line_style = LINESTYLE_SOLID; attr = object_find_attribute(obj_node, "line_style"); if (attr != NULL) ellipse->line_style = data_enum(attribute_first_data(attr), ctx); ellipse->dashlength = DEFAULT_LINESTYLE_DASHLEN; attr = object_find_attribute(obj_node, "dashlength"); if (attr != NULL) ellipse->dashlength = data_real(attribute_first_data(attr), ctx); attr = object_find_attribute(obj_node, "pattern"); if (attr != NULL) ellipse->pattern = data_pattern(attribute_first_data(attr), ctx); element_init(elem, 9, 9); obj->handles[8] = &ellipse->center_handle; obj->handles[8]->id = HANDLE_CUSTOM1; obj->handles[8]->type = HANDLE_MAJOR_CONTROL; obj->handles[8]->connected_to = NULL; obj->handles[8]->connect_type = HANDLE_NONCONNECTABLE; for (i=0;i<9;i++) { obj->connections[i] = &ellipse->connections[i]; ellipse->connections[i].object = obj; ellipse->connections[i].connected = NULL; } ellipse->connections[8].flags = CP_FLAGS_MAIN; ellipse_update_data(ellipse); return &ellipse->element.object; }
static ObjectChange* ellipse_move_handle(Ellipse *ellipse, Handle *handle, Point *to, ConnectionPoint *cp, HandleMoveReason reason, ModifierKeys modifiers) { Element *elem = &ellipse->element; Point nw_to, se_to; assert(ellipse!=NULL); assert(handle!=NULL); assert(to!=NULL); assert(handle->id < 8 || handle->id == HANDLE_CUSTOM1); if (handle->id == HANDLE_CUSTOM1) { Point delta, corner_to; delta.x = to->x - (elem->corner.x + elem->width/2); delta.y = to->y - (elem->corner.y + elem->height/2); corner_to.x = elem->corner.x + delta.x; corner_to.y = elem->corner.y + delta.y; return ellipse_move(ellipse, &corner_to); } else { if (ellipse->aspect != FREE_ASPECT){ float width, height; float new_width, new_height; float to_width, aspect_width; Point center; width = ellipse->element.width; height = ellipse->element.height; 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 * fabs(to->x - center.x); new_height = new_width / width * height; break; case HANDLE_RESIZE_N: case HANDLE_RESIZE_S: new_height = 2 * fabs(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 * fabs(to->x - center.x); aspect_width = 2 * fabs(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; } 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; Point opposite_to; center.x = elem->corner.x + elem->width/2; center.y = elem->corner.y + elem->height/2; 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); /* this second move screws the intended object size, e.g. from dot2dia.py * but without it the 'centered' behaviour during edit is screwed */ element_move_handle(&ellipse->element, 7-handle->id, &opposite_to, cp, reason, modifiers); } ellipse_update_data(ellipse); return NULL; } }