/*! Factory function - create default object */ static DiaObject * outline_create (Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Outline *outline; DiaObject *obj; outline = g_new0 (Outline,1); obj = &outline->object; obj->type = &outline_type; obj->ops = &outline_ops; object_init (obj, NUM_HANDLES, 0); obj->position = *startpoint; outline_init_handles (outline); attributes_get_default_font (&outline->font, &outline->font_height); outline->line_width = 0; /* Not: attributes_get_default_linewidth(); it looks ugly */ outline->line_color = attributes_get_foreground(); outline->fill_color = attributes_get_background(); outline->show_background = FALSE; outline->name = g_strdup ("?"); outline->rotation = 0; *handle1 = outline->object.handles[0]; *handle2 = outline->object.handles[1]; outline_update_data (outline); return obj; }
static DiaPattern * _create_preset_pattern (guint n) { DiaPattern *pat; Color color; g_return_val_if_fail (n < G_N_ELEMENTS (_pattern_presets), NULL); switch (_pattern_presets[n].type) { case DIA_LINEAR_GRADIENT: pat = dia_pattern_new (_pattern_presets[n].type, 0, 0.0, 0.0); if (_pattern_presets[n].flags != 0) dia_pattern_set_point (pat, _pattern_presets[n].flags & LEFT ? 1.0 : 0.0, _pattern_presets[n].flags & DOWN ? 1.0 : 0.0); break; case DIA_RADIAL_GRADIENT: pat = dia_pattern_new (_pattern_presets[n].type, 0, 0.5, 0.5); dia_pattern_set_radius (pat, 0.5); /* set the focal point to the center */ dia_pattern_set_point (pat, 0.5, 0.5); break; default : g_assert_not_reached (); } color = attributes_get_background (); dia_pattern_add_color (pat, 0.0, &color); color = attributes_get_foreground (); dia_pattern_add_color (pat, 1.0, &color); return pat; }
DiaOutputDev::DiaOutputDev (DiagramData *_dia, int _n) : dia(_dia), stroke_color(attributes_get_foreground ()), line_width(attributes_get_default_linewidth()), // favoring member intitialization list over attributes_get_default_line_style() line_style(LINESTYLE_SOLID), dash_length(1.0), line_join(LINEJOIN_MITER), line_caps(LINECAPS_PROJECTING), fill_color(attributes_get_background ()), alignment(ALIGN_LEFT), scale(2.54/72.0), objects(NULL), pageNum(0), page_width(1.0), page_height(1.0), num_pages(_n), font_map_hits(0), pattern(NULL) { font_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)dia_font_unref); matrix.xx = matrix.yy = 1.0; matrix.yx = matrix.xy = 0.0; matrix.x0 = matrix.y0 = 0.0; image_cache = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)g_object_unref); }
static DiaObject * component_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Component *cmp; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; cmp = g_malloc0(sizeof(Component)); elem = &cmp->element; obj = &elem->object; obj->type = &component_type; obj->ops = &component_ops; obj->flags |= DIA_OBJECT_CAN_PARENT; elem->corner = *startpoint; cmp->line_color = attributes_get_foreground(); cmp->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); p = *startpoint; p.x += COMPONENT_CWIDTH + COMPONENT_MARGIN_X; p.y += 2*COMPONENT_CHEIGHT; cmp->text = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); text_get_attributes(cmp->text,&cmp->attrs); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &cmp->connections[i]; cmp->connections[i].object = obj; cmp->connections[i].connected = NULL; } cmp->connections[10].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = COMPONENT_BORDERWIDTH/2.0; cmp->stereotype = NULL; cmp->st_stereotype = NULL; component_update_data(cmp); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &cmp->element.object; }
static DiaObject * attribute_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Attribute *attribute; Element *elem; DiaObject *obj; int i; attribute = g_malloc0(sizeof(Attribute)); elem = &attribute->element; obj = &elem->object; obj->type = &attribute_type; obj->ops = &attribute_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; attribute->border_width = attributes_get_default_linewidth(); attribute->border_color = attributes_get_foreground(); attribute->inner_color = attributes_get_background(); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &attribute->connections[i]; attribute->connections[i].object = obj; attribute->connections[i].connected = NULL; } attribute->connections[8].flags = CP_FLAGS_MAIN; attribute->key = FALSE; attribute->weakkey = FALSE; attribute->derived = FALSE; attribute->multivalue = FALSE; attribute->font = dia_font_new_from_style(DIA_FONT_MONOSPACE,FONT_HEIGHT); attribute->font_height = FONT_HEIGHT; attribute->name = g_strdup(_("Attribute")); attribute->name_width = dia_font_string_width(attribute->name, attribute->font, attribute->font_height); attribute_update_data(attribute); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = obj->handles[0]; return &attribute->element.object; }
static DiaObject * beziergon_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Beziergon *beziergon; BezierShape *bez; DiaObject *obj; Point defaultx = { 1.0, 0.0 }; Point defaulty = { 0.0, 1.0 }; beziergon = g_new0(Beziergon, 1); bez = &beziergon->bezier; obj = &bez->object; obj->type = &beziergon_type; obj->ops = &beziergon_ops; if (user_data == NULL) { beziershape_init(bez, 3); bez->bezier.points[0].p1 = *startpoint; bez->bezier.points[0].p3 = *startpoint; bez->bezier.points[2].p3 = *startpoint; bez->bezier.points[1].p1 = *startpoint; point_add(&bez->bezier.points[1].p1, &defaultx); bez->bezier.points[2].p2 = *startpoint; point_sub(&bez->bezier.points[2].p2, &defaultx); bez->bezier.points[1].p3 = *startpoint; point_add(&bez->bezier.points[1].p3, &defaulty); bez->bezier.points[1].p2 = bez->bezier.points[1].p3; point_add(&bez->bezier.points[1].p2, &defaultx); bez->bezier.points[2].p1 = bez->bezier.points[1].p3; point_sub(&bez->bezier.points[2].p1, &defaultx); } else { BezierCreateData *bcd = (BezierCreateData*)user_data; beziershape_init(bez, bcd->num_points); beziercommon_set_points (&bez->bezier, bcd->num_points, bcd->points); } beziergon->line_width = attributes_get_default_linewidth(); beziergon->line_color = attributes_get_foreground(); beziergon->inner_color = attributes_get_background(); attributes_get_default_line_style(&beziergon->line_style, &beziergon->dashlength); beziergon->line_join = LINEJOIN_MITER; beziergon->show_background = default_properties.show_background; beziergon_update_data(beziergon); *handle1 = bez->object.handles[5]; *handle2 = bez->object.handles[2]; return &beziergon->bezier.object; }
static DiaObject * grid_object_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Grid_Object *grid_object; Element *elem; DiaObject *obj; unsigned i; grid_object = g_new0(Grid_Object,1); elem = &(grid_object->element); obj = &(grid_object->element.object); obj->type = &grid_object_type; obj->ops = &grid_object_ops; elem->corner = *startpoint; elem->width = 4.0; elem->height = 4.0; element_init(elem, 8, 9); grid_object->border_color = attributes_get_foreground(); grid_object->border_line_width = attributes_get_default_linewidth(); grid_object->inner_color = attributes_get_background(); grid_object->show_background = TRUE; grid_object->grid_rows = 3; grid_object->grid_cols = 4; grid_object->gridline_color.red = 0.5; grid_object->gridline_color.green = 0.5; grid_object->gridline_color.blue = 0.5; grid_object->gridline_color.alpha = 1.0; grid_object->gridline_width = attributes_get_default_linewidth(); for (i = 0; i < 9; ++i) { obj->connections[i] = &grid_object->base_cps[i]; grid_object->base_cps[i].object = obj; grid_object->base_cps[i].connected = NULL; } grid_object->base_cps[8].flags = CP_FLAGS_MAIN; grid_object->cells_rows = 0; grid_object->cells_cols = 0; grid_object->cells = NULL; grid_object_reallocate_cells(grid_object); grid_object_update_data(grid_object); *handle1 = NULL; *handle2 = obj->handles[7]; return &grid_object->element.object; }
static DiaObject * usecase_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Usecase *usecase; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; usecase = g_malloc0(sizeof(Usecase)); elem = &usecase->element; obj = &elem->object; obj->type = &usecase_type; obj->ops = &usecase_ops; elem->corner = *startpoint; elem->width = USECASE_WIDTH; elem->height = USECASE_HEIGHT; usecase->line_width = attributes_get_default_linewidth(); usecase->line_color = attributes_get_foreground(); usecase->fill_color = attributes_get_background(); font = dia_font_new_from_style(DIA_FONT_SANS, 0.8); p = *startpoint; p.x += USECASE_WIDTH/2.0; p.y += USECASE_HEIGHT/2.0; usecase->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER); dia_font_unref(font); usecase->text_outside = 0; usecase->collaboration = 0; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &usecase->connections[i]; usecase->connections[i].object = obj; usecase->connections[i].connected = NULL; } usecase->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = 0.0; usecase_update_data(usecase); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &usecase->element.object; }
static DiaObject * textobj_load(ObjectNode obj_node, int version, DiaContext *ctx) { Textobj *textobj; DiaObject *obj; AttributeNode attr; Point startpoint = {0.0, 0.0}; textobj = g_malloc0(sizeof(Textobj)); obj = &textobj->object; obj->type = &textobj_type; obj->ops = &textobj_ops; object_load(obj, obj_node, ctx); attr = object_find_attribute(obj_node, "text"); if (attr != NULL) { textobj->text = data_text(attribute_first_data(attr), ctx); } else { DiaFont* font = dia_font_new_from_style(DIA_FONT_MONOSPACE,1.0); textobj->text = new_text("", font, 1.0, &startpoint, &color_black, ALIGN_CENTER); dia_font_unref(font); } attr = object_find_attribute(obj_node, "valign"); if (attr != NULL) textobj->vert_align = data_enum(attribute_first_data(attr), ctx); else if (version == 0) { textobj->vert_align = VALIGN_FIRST_LINE; } /* default visibility must be off to keep compatibility */ textobj->fill_color = attributes_get_background(); attr = object_find_attribute(obj_node, "fill_color"); if (attr) data_color(attribute_first_data(attr), &textobj->fill_color, ctx); attr = object_find_attribute(obj_node, "show_background"); if (attr) textobj->show_background = data_boolean(attribute_first_data(attr), ctx); else textobj->show_background = FALSE; object_init(obj, 1, 0); obj->handles[0] = &textobj->text_handle; textobj->text_handle.id = HANDLE_TEXT; textobj->text_handle.type = HANDLE_MAJOR_CONTROL; textobj->text_handle.connect_type = HANDLE_CONNECTABLE; textobj->text_handle.connected_to = NULL; textobj_update_data(textobj); return &textobj->object; }
static DiaObject * note_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Note *note; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; note = g_malloc0(sizeof(Note)); elem = ¬e->element; obj = &elem->object; obj->type = ¬e_type; obj->ops = ¬e_ops; elem->corner = *startpoint; note->line_width = attributes_get_default_linewidth(); note->line_color = attributes_get_foreground(); note->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_MONOSPACE, 0.8); p = *startpoint; p.x += note->line_width/2.0 + NOTE_MARGIN_X; p.y += note->line_width/2.0 + NOTE_CORNER + dia_font_ascent("A",font, 0.8); note->text = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = ¬e->connections[i]; note->connections[i].object = obj; note->connections[i].connected = NULL; } note->connections[NUM_CONNECTIONS-1].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = note->line_width/2.0; note_update_data(note); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return ¬e->element.object; }
static DiaObject * largepackage_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { LargePackage *pkg; Element *elem; DiaObject *obj; int i; pkg = g_malloc0(sizeof(LargePackage)); elem = &pkg->element; obj = &elem->object; obj->type = &largepackage_type; obj->ops = &largepackage_ops; obj->flags |= DIA_OBJECT_CAN_PARENT; elem->corner = *startpoint; element_init(elem, 8, NUM_CONNECTIONS); elem->width = 4.0; elem->height = 4.0; pkg->line_width = attributes_get_default_linewidth(); pkg->text_color = color_black; pkg->line_color = attributes_get_foreground(); pkg->fill_color = attributes_get_background(); pkg->font = dia_font_new_from_style(DIA_FONT_MONOSPACE, LARGEPACKAGE_FONTHEIGHT); pkg->stereotype = NULL; pkg->st_stereotype = NULL; pkg->name = g_strdup(""); pkg->topwidth = 2.0; pkg->topheight = LARGEPACKAGE_FONTHEIGHT*2 + 0.1*2; for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &pkg->connections[i]; pkg->connections[i].object = obj; pkg->connections[i].connected = NULL; } pkg->connections[8].flags = CP_FLAGS_MAIN; pkg->element.extra_spacing.border_trans = pkg->line_width/2.0; largepackage_update_data(pkg); *handle1 = NULL; *handle2 = obj->handles[7]; return &pkg->element.object; }
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 DiaObject * state_create_activity(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { State *state; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; state = g_malloc0(sizeof(State)); elem = &state->element; obj = &elem->object; obj->type = &activity_type; obj->ops = &state_ops; elem->corner = *startpoint; elem->width = STATE_WIDTH; elem->height = STATE_HEIGHT; state->line_color = attributes_get_foreground(); state->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); p = *startpoint; p.x += STATE_WIDTH/2.0; p.y += STATE_HEIGHT/2.0; state->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER); text_get_attributes(state->text,&state->attrs); element_init(elem, 8, 8); for (i=0;i<8;i++) { obj->connections[i] = &state->connections[i]; state->connections[i].object = obj; state->connections[i].connected = NULL; } elem->extra_spacing.border_trans = 0.0; state_update_data(state); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &state->element.object;; }
static DiaObject * textobj_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Textobj *textobj; DiaObject *obj; Color col; DiaFont *font = NULL; real font_height; textobj = g_malloc0(sizeof(Textobj)); obj = &textobj->object; obj->enclosing_box = g_new0 (Rectangle, 1); obj->type = &textobj_type; obj->ops = &textobj_ops; col = attributes_get_foreground(); attributes_get_default_font(&font, &font_height); textobj->text = new_text("", font, font_height, startpoint, &col, default_properties.alignment ); /* need to initialize to object.position as well, it is used update data */ obj->position = *startpoint; dia_font_unref(font); textobj->vert_align = default_properties.vert_align; /* default visibility must be off to keep compatibility */ textobj->fill_color = attributes_get_background(); textobj->show_background = FALSE; object_init(obj, 1, 0); obj->handles[0] = &textobj->text_handle; textobj->text_handle.id = HANDLE_TEXT; textobj->text_handle.type = HANDLE_MAJOR_CONTROL; textobj->text_handle.connect_type = HANDLE_CONNECTABLE; textobj->text_handle.connected_to = NULL; /* no margin till Dia 0.98 */ textobj->margin = 0.0; textobj_update_data(textobj); *handle1 = NULL; *handle2 = obj->handles[0]; return &textobj->object; }
static DiaObject *node_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Node *node; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; node = g_malloc0(sizeof(Node)); /* old defaults */ node->line_width = 0.1; elem = &node->element; obj = &elem->object; obj->type = &node_type; obj->ops = &node_ops; elem->corner = *startpoint; node->line_color = attributes_get_foreground(); node->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); /* The text position is recalculated later */ p.x = 0.0; p.y = 0.0; node->name = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &node->connections[i]; node->connections[i].object = obj; node->connections[i].connected = NULL; } node->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = node->line_width/2.0; node_update_data(node); *handle1 = NULL; *handle2 = obj->handles[7]; return &node->element.object; }
static DiaObject * box_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Box *box; Element *elem; DiaObject *obj; int i; box = g_malloc0(sizeof(Box)); elem = &box->element; obj = &elem->object; obj->type = &box_type; obj->ops = &box_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; box->border_width = attributes_get_default_linewidth(); box->border_color = attributes_get_foreground(); box->inner_color = attributes_get_background(); attributes_get_default_line_style(&box->line_style, &box->dashlength); box->line_join = LINEJOIN_MITER; /* For non-default objects, this is overridden by the default */ box->show_background = default_properties.show_background; box->corner_radius = default_properties.corner_radius; box->aspect = default_properties.aspect; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &box->connections[i]; box->connections[i].object = obj; box->connections[i].connected = NULL; } box->connections[8].flags = CP_FLAGS_MAIN; box_update_data(box); *handle1 = NULL; *handle2 = obj->handles[7]; return &box->element.object; }
static DiaObject * state_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { State *state; Element *elem; DiaObject *obj; Point p; int i; state = g_malloc0(sizeof(State)); elem = &state->element; obj = &elem->object; obj->type = &state_term_type; obj->ops = &state_ops; elem->corner = *startpoint; elem->width = STATE_WIDTH; elem->height = STATE_HEIGHT; p = *startpoint; p.x += STATE_WIDTH/2.0; p.y += STATE_HEIGHT/2.0; state->line_color = attributes_get_foreground(); state->fill_color = attributes_get_background(); state->is_final = 0; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &state->connections[i]; state->connections[i].object = obj; state->connections[i].connected = NULL; } state->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = 0.0; state_update_data(state); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &state->element.object; }
/** *NOT A CALLBACK* Caller must set: - obj->type --------------- - obj->ops */ DiaObject *aadlbox_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Aadlbox *aadlbox; Element *elem; DiaObject *obj; Point p; DiaFont *font; aadlbox = g_malloc0(sizeof(Aadlbox)); elem = &aadlbox->element; obj = &elem->object; obj->flags |= DIA_OBJECT_CAN_PARENT; elem->corner = *startpoint; aadlbox->specific = (Aadlbox_specific *) user_data; aadlbox->num_ports = 0; aadlbox->ports = NULL; aadlbox->line_color = attributes_get_foreground(); aadlbox->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); /* The text position is recalculated later */ p.x = 0.0; p.y = 0.0; aadlbox->name = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); text_get_attributes(aadlbox->name,&aadlbox->attrs); dia_font_unref(font); element_init(elem, 8, 0); /* 8 handles and 0 connection */ elem->extra_spacing.border_trans = AADLBOX_BORDERWIDTH/2.0; aadlbox_update_data(aadlbox); *handle1 = NULL; *handle2 = obj->handles[7]; return &aadlbox->element.object; }
static DiaObject * branch_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Branch *branch; Element *elem; DiaObject *obj; int i; branch = g_malloc0(sizeof(Branch)); elem = &branch->element; obj = &elem->object; obj->type = &branch_type; obj->ops = &branch_ops; elem->corner = *startpoint; element_init(elem, 8, NUM_CONNECTIONS); branch->line_color = attributes_get_foreground(); branch->fill_color = attributes_get_background(); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &branch->connections[i]; branch->connections[i].object = obj; branch->connections[i].connected = NULL; } elem->extra_spacing.border_trans = BRANCH_BORDERWIDTH / 2.0; branch_update_data(branch); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &branch->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 * analog_clock_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Analog_Clock *analog_clock; Element *elem; DiaObject *obj; unsigned i; analog_clock = g_new0(Analog_Clock,1); elem = &(analog_clock->element); obj = &(analog_clock->element.object); obj->type = &analog_clock_type; obj->ops = &analog_clock_ops; elem->corner = *startpoint; elem->width = 4.0; elem->height = 4.0; element_init(elem, 8, 16); analog_clock->border_color = attributes_get_foreground(); analog_clock->border_line_width = attributes_get_default_linewidth(); analog_clock->inner_color = attributes_get_background(); analog_clock->show_background = TRUE; analog_clock->arrow_color.red = 0.0; analog_clock->arrow_color.green = 0.0; analog_clock->arrow_color.blue = 0.5; analog_clock->arrow_color.alpha = 1.0; analog_clock->arrow_line_width = attributes_get_default_linewidth(); analog_clock->sec_arrow_color.red = 1.0; analog_clock->sec_arrow_color.green = 0.0; analog_clock->sec_arrow_color.blue = 0.0; analog_clock->sec_arrow_color.alpha = 1.0; analog_clock->sec_arrow_line_width = attributes_get_default_linewidth()/3; analog_clock->show_ticks = TRUE; for (i = 0; i < 12; ++i) { obj->connections[i] = &analog_clock->hours[i]; analog_clock->hours[i].object = obj; analog_clock->hours[i].connected = NULL; } obj->connections[12] = &analog_clock->hour_tip; analog_clock->hour_tip.object = obj; analog_clock->hour_tip.connected = NULL; obj->connections[13] = &analog_clock->min_tip; analog_clock->min_tip.object = obj; analog_clock->min_tip.connected = NULL; obj->connections[14] = &analog_clock->sec_tip; analog_clock->sec_tip.object = obj; analog_clock->sec_tip.connected = NULL; obj->connections[15] = &analog_clock->center_cp; analog_clock->center_cp.object = obj; analog_clock->center_cp.connected = NULL; analog_clock->center_cp.flags = CP_FLAGS_MAIN; analog_clock->hours[0].directions = DIR_NORTH; analog_clock->hours[1].directions = DIR_NORTH|DIR_EAST; analog_clock->hours[2].directions = DIR_NORTH|DIR_EAST; analog_clock->hours[3].directions = DIR_EAST; analog_clock->hours[4].directions = DIR_EAST|DIR_SOUTH; analog_clock->hours[5].directions = DIR_EAST|DIR_SOUTH; analog_clock->hours[6].directions = DIR_SOUTH; analog_clock->hours[7].directions = DIR_SOUTH|DIR_WEST; analog_clock->hours[8].directions = DIR_SOUTH|DIR_WEST; analog_clock->hours[9].directions = DIR_WEST; analog_clock->hours[10].directions = DIR_WEST|DIR_NORTH; analog_clock->hours[11].directions = DIR_WEST|DIR_NORTH; analog_clock->center_cp.directions = DIR_ALL; analog_clock_update_data(analog_clock); *handle1 = NULL; *handle2 = obj->handles[7]; /* We are an animated object -- special case ! */ dynobj_list_add_object(&analog_clock->element.object,1000); return &analog_clock->element.object; }
static DiaObject * classicon_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Classicon *cicon; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; cicon = g_malloc0(sizeof(Classicon)); /* old default */ cicon->line_width = 0.1; elem = &cicon->element; obj = &elem->object; obj->type = &classicon_type; obj->ops = &classicon_ops; elem->corner = *startpoint; cicon->line_color = attributes_get_foreground(); cicon->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); cicon->stereotype = 0; cicon->is_object = 0; /* The text position is recalculated later */ p.x = 0.0; p.y = 0.0; cicon->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &cicon->connections[i]; cicon->connections[i].object = obj; cicon->connections[i].connected = NULL; } cicon->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = 0.0; classicon_update_data(cicon); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &cicon->element.object; }
static DiaObject * lifeline_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Lifeline *lifeline; Connection *conn; DiaObject *obj; int i; lifeline = g_malloc0(sizeof(Lifeline)); lifeline->cp_distance = LIFELINE_CP_DEFAULT_DISTANCE; conn = &lifeline->connection; conn->endpoints[0] = *startpoint; conn->endpoints[0].x += LIFELINE_WIDTH/2; conn->endpoints[1] = conn->endpoints[0]; conn->endpoints[1].y = conn->endpoints[0].y + 6.0*lifeline->cp_distance; obj = &conn->object; obj->type = &lifeline_type; obj->ops = &lifeline_ops; connection_init(conn, LIFELINE_NUM_HANDLES, LIFELINE_NUM_STD_CPS); lifeline->line_color = attributes_get_foreground(); lifeline->fill_color = attributes_get_background(); /* _relative_ from conn->endpoints[0].y */ lifeline->rtop = lifeline->cp_distance; lifeline->draw_focuscontrol = 1; lifeline->draw_cross = 0; lifeline->boxbot_handle.id = HANDLE_BOXBOT; lifeline->boxbot_handle.type = HANDLE_MINOR_CONTROL; lifeline->boxbot_handle.connect_type = HANDLE_NONCONNECTABLE; lifeline->boxbot_handle.connected_to = NULL; obj->handles[2] = &lifeline->boxbot_handle; lifeline->boxtop_handle.id = HANDLE_BOXTOP; lifeline->boxtop_handle.type = HANDLE_MINOR_CONTROL; lifeline->boxtop_handle.connect_type = HANDLE_NONCONNECTABLE; lifeline->boxtop_handle.connected_to = NULL; obj->handles[3] = &lifeline->boxtop_handle; lifeline->boxmid_handle.id = HANDLE_BOXMID; lifeline->boxmid_handle.type = HANDLE_MINOR_CONTROL; lifeline->boxmid_handle.connect_type = HANDLE_NONCONNECTABLE; lifeline->boxmid_handle.connected_to = NULL; obj->handles[4] = &lifeline->boxmid_handle; /* Only the start point should be connectable */ obj->handles[1]->connect_type = HANDLE_NONCONNECTABLE; /* Connection points */ for (i=0;i<LIFELINE_NUM_STD_CPS;i++) { obj->connections[i] = &lifeline->connections[i]; lifeline->connections[i].object = obj; lifeline->connections[i].connected = NULL; } /* **must** be the same init order as in the property descriptors */ lifeline->northwest = connpointline_create(obj, 1); lifeline->southwest = connpointline_create(obj, 1); lifeline->northeast = connpointline_create(obj, 1); lifeline->southeast = connpointline_create(obj, 1); lifeline_update_data(lifeline); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &lifeline->connection.object; }
static void color_area_draw () { Color col; GdkColor *win_bg; GdkColor fg, bg, bd; gint rect_w, rect_h; gint width, height; gint def_width, def_height; gint swap_width, swap_height; GdkColor mask_pattern; /* Check we haven't gotten initial expose yet, * no point in drawing anything */ if (!color_area_pixmap || !color_area_gc) return; gdk_drawable_get_size (color_area_pixmap, &width, &height); win_bg = &(color_area->style->bg[GTK_STATE_NORMAL]); col = attributes_get_foreground(); color_convert(&col, &fg); col = attributes_get_background(); color_convert(&col, &bg); bd = color_gdk_black; rect_w = width * 0.65; rect_h = height * 0.65; /* initialize the mask to transparent */ mask_pattern.pixel = 0; gdk_gc_set_foreground (mask_gc, &mask_pattern); gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, 0, 0, -1, -1); /* set the mask's gc to opaque */ mask_pattern.pixel = 1; gdk_gc_set_foreground (mask_gc, &mask_pattern); gdk_gc_set_foreground (color_area_gc, win_bg); gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1, 0, 0, width, height); gdk_gc_set_foreground (color_area_gc, &bg); gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1, (width - rect_w), (height - rect_h), rect_w, rect_h); gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, (width - rect_w), (height - rect_h), rect_w, rect_h); if (active_color == FOREGROUND) gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, color_area, NULL, (width - rect_w), (height - rect_h), rect_w, rect_h); else gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, color_area, NULL, (width - rect_w), (height - rect_h), rect_w, rect_h); gdk_gc_set_foreground (color_area_gc, &fg); gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1, 0, 0, rect_w, rect_h); gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, 0, 0, rect_w, rect_h); if (active_color == FOREGROUND) gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, color_area, NULL, 0, 0, rect_w, rect_h); else gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, color_area, NULL, 0, 0, rect_w, rect_h); /* draw the default pixmap */ gdk_drawable_get_size (default_pixmap, &def_width, &def_height); gdk_draw_drawable (color_area_pixmap, color_area_gc, default_pixmap, 0, 0, 0, height - def_height, def_width, def_height); gdk_draw_drawable (color_area_mask, mask_gc, default_mask, 0, 0, 0, height - def_height, def_width, def_height); /* draw the swap pixmap */ gdk_drawable_get_size (swap_pixmap, &swap_width, &swap_height); gdk_draw_drawable (color_area_pixmap, color_area_gc, swap_pixmap, 0, 0, width - swap_width, 0, swap_width, swap_height); gdk_draw_drawable (color_area_mask, mask_gc, swap_mask, 0, 0, width - swap_width, 0, swap_width, swap_height); /* draw the widget */ gdk_gc_set_clip_mask (color_area_gc, color_area_mask); gdk_gc_set_clip_origin (color_area_gc, 0, 0); gdk_draw_drawable (color_area->window, color_area_gc, color_area_pixmap, 0, 0, 0, 0, width, height); /* reset the clip mask */ gdk_gc_set_clip_mask (color_area_gc, NULL); }
static void color_area_edit (void) { Color col; GtkWidget *window; GdkColor color; if (!color_select_active) { stored_foreground = attributes_get_foreground(); stored_background = attributes_get_background(); } if (active_color == FOREGROUND) { col = attributes_get_foreground(); edit_color = FOREGROUND; } else { col = attributes_get_background(); edit_color = BACKGROUND; } if (! color_select) { window = color_select = gtk_color_selection_dialog_new(edit_color==FOREGROUND? _("Select foreground color"): _("Select background color")); color_select_active = 1; gtk_color_selection_set_has_palette ( GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (window)->colorsel), TRUE); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK(color_selection_delete), window); g_signal_connect (GTK_OBJECT (window), "destroy", G_CALLBACK(color_selection_destroy), window); g_signal_connect ( G_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->colorsel), "color_changed", G_CALLBACK(color_selection_changed), window); g_signal_connect ( G_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->ok_button), "clicked", G_CALLBACK(color_selection_ok), window); g_signal_connect ( G_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->cancel_button), "clicked", G_CALLBACK(color_selection_cancel), window); /* Make sure window is shown before setting its colors: */ gtk_widget_show_now (color_select); } else { gtk_window_set_title(GTK_WINDOW(color_select), edit_color==FOREGROUND? _("Select foreground color"): _("Select background color")); if (! color_select_active) { gtk_widget_show (color_select); } } DIA_COLOR_TO_GDK(col, color); gtk_color_selection_set_current_color( GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (color_select)->colorsel), &color); }
static DiaObject * objet_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Objet *ob; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; ob = g_malloc0(sizeof(Objet)); elem = &ob->element; obj = &elem->object; obj->type = ¨object_type; obj->ops = &objet_ops; elem->corner = *startpoint; ob->text_attrs.color = color_black; ob->line_width = attributes_get_default_linewidth(); ob->line_color = attributes_get_foreground(); ob->fill_color = attributes_get_background(); font = dia_font_new_from_style(DIA_FONT_SANS, 0.8); ob->show_attributes = FALSE; ob->is_active = FALSE; ob->is_multiple = FALSE; ob->exstate = NULL; ob->stereotype = NULL; ob->st_stereotype = NULL; /* The text position is recalculated later */ p.x = 0.0; p.y = 0.0; ob->attributes = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); ob->attrib = NULL; ob->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER); text_get_attributes(ob->text,&ob->text_attrs); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &ob->connections[i]; ob->connections[i].object = obj; ob->connections[i].connected = NULL; } ob->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = ob->line_width/2.0; objet_update_data(ob); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &ob->element.object; }
/*! Factory function - create default object */ static DiaObject * stdpath_create (Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { StdPath *stdpath; DiaObject *obj; Point sp = {0, 0}; stdpath = g_new0 (StdPath,1); obj = &stdpath->object; obj->type = &stdpath_type; obj->ops = &stdpath_ops; object_init (obj, NUM_HANDLES, 0); stdpath_init_handles (stdpath); if (startpoint) sp = *startpoint; if (user_data == NULL) { /* just to have something to play with <bezpoint type="moveto" p1="0,1"/> <bezpoint type="curveto" p1="0,0" p2="2,2" p3="2,1"/> <bezpoint type="curveto" p1="2,0" p2="0,2" p3="0,1"/> */ BezPoint *bp; stdpath->num_points = 3; bp = stdpath->points = g_new (BezPoint, 3); bp[0].type = BEZ_MOVE_TO; bp[0].p1.x = sp.x + 0; bp[0].p1.y = sp.y + 1; bp[0].p3 = bp[0].p2 = bp[0].p1; /* not strictly necessary */ bp[1].type = BEZ_CURVE_TO; bp[1].p1 = sp; bp[1].p2.x = sp.x + 2; bp[1].p2.y = sp.y + 2; bp[1].p3.x = sp.x + 2; bp[1].p3.y = sp.y + 1; bp[2].type = BEZ_CURVE_TO; bp[2].p1.x = sp.x + 2; bp[2].p1.y = sp.y + 0; bp[2].p2.x = sp.x + 0; bp[2].p2.y = sp.y + 2; bp[2].p3.x = sp.x + 0; bp[2].p3.y = sp.y + 1; } else { BezierCreateData *bcd = (BezierCreateData*)user_data; if (bcd->num_points < 2) { g_warning ("'Standard - Path' needs at least two points"); /* this is a stress test - object might not be setup completely */ object_destroy (obj); g_free (stdpath); return NULL; } stdpath->num_points = bcd->num_points; stdpath->points = g_memdup(bcd->points, bcd->num_points * sizeof(BezPoint)); } stdpath->stroke_or_fill = PDO_STROKE; /* default: stroke only */ stdpath->line_width = attributes_get_default_linewidth(); stdpath->line_color = attributes_get_foreground(); stdpath->fill_color = attributes_get_background(); *handle1 = stdpath->object.handles[0]; *handle2 = stdpath->object.handles[7]; stdpath_update_data (stdpath); return obj; }