Exemple #1
0
static DiaObject *
image_create(Point *startpoint,
	     void *user_data,
	     Handle **handle1,
	     Handle **handle2)
{
  Image *image;
  Element *elem;
  DiaObject *obj;
  int i;

  image = g_malloc0(sizeof(Image));
  elem = &image->element;
  obj = &elem->object;
  
  obj->type = &image_type;
  obj->ops = &image_ops;

  elem->corner = *startpoint;
  elem->width = DEFAULT_WIDTH;
  elem->height = DEFAULT_HEIGHT;
    
  image->border_width =  attributes_get_default_linewidth();
  image->border_color = attributes_get_foreground();
  attributes_get_default_line_style(&image->line_style,
				    &image->dashlength);
  
  element_init(elem, 8, NUM_CONNECTIONS);

  for (i=0; i<NUM_CONNECTIONS; i++) {
    obj->connections[i] = &image->connections[i];
    image->connections[i].object = obj;
    image->connections[i].connected = NULL;
  }
  image->connections[8].flags = CP_FLAGS_MAIN;

  if (strcmp(default_properties.file, "")) {
    image->file = g_strdup(default_properties.file);
    image->image = dia_image_load(image->file);

    if (image->image) {
      elem->width = (elem->width*(float)dia_image_width(image->image))/
	(float)dia_image_height(image->image);
    }
  } else {
    image->file = g_strdup("");
    image->image = NULL;
  }

  image->draw_border = default_properties.draw_border;
  image->keep_aspect = default_properties.keep_aspect;

  image_update_data(image);
  
  *handle1 = NULL;
  *handle2 = obj->handles[7];  
  return &image->element.object;
}
Exemple #2
0
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;
}
Exemple #3
0
/** user_data is a struct polyline_create_data, containing an array of 
    points and a count.
    If user_data is NULL, the startpoint is used and a 1x1 line is created.
    Otherwise, the startpoint is ignored.
*/
static DiaObject *
polyline_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Polyline *polyline;
  PolyConn *poly;
  DiaObject *obj;
  Point defaultlen = { 1.0, 1.0 };

  /*polyline_init_defaults();*/
  polyline = g_malloc0(sizeof(Polyline));
  poly = &polyline->poly;
  obj = &poly->object;
  
  obj->type = &polyline_type;
  obj->ops = &polyline_ops;

  if (user_data == NULL) {
    polyconn_init(poly, 2);

    poly->points[0] = *startpoint;
    poly->points[1] = *startpoint;

    point_add(&poly->points[1], &defaultlen);

    *handle1 = poly->object.handles[0];
    *handle2 = poly->object.handles[1];
  } else {
    MultipointCreateData *pcd = (MultipointCreateData *)user_data;

    polyconn_init(poly, pcd->num_points);

    /* Handles are set up by polyconn_init and polyconn_update_data */
    polyconn_set_points(poly, pcd->num_points, pcd->points);

    *handle1 = poly->object.handles[0];
    *handle2 = poly->object.handles[pcd->num_points-1];
  }


  polyline->line_width =  attributes_get_default_linewidth();
  polyline->line_color = attributes_get_foreground();
  attributes_get_default_line_style(&polyline->line_style,
				    &polyline->dashlength);
  polyline->line_join = LINEJOIN_MITER;
  polyline->line_caps = LINECAPS_BUTT;
  polyline->start_arrow = attributes_get_default_start_arrow();
  polyline->end_arrow = attributes_get_default_end_arrow();
  polyline->corner_radius = 0.0;

  polyline_update_data(polyline);

  return &polyline->poly.object;
}
Exemple #4
0
static DiaObject *
bezierline_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Bezierline *bezierline;
  BezierConn *bez;
  DiaObject *obj;
  Point defaultlen = { .3, .3 };

  bezierline = g_new0(Bezierline, 1);
  bezierline->bez.object.enclosing_box = g_new0 (Rectangle, 1);
  bez = &bezierline->bez;
  obj = &bez->object;

  obj->type = &bezierline_type;
  obj->ops = &bezierline_ops;

  if (user_data == NULL) {
    bezierconn_init(bez, 2);

    bez->bezier.points[0].p1 = *startpoint;
    bez->bezier.points[1].p1 = *startpoint;
    point_add(&bez->bezier.points[1].p1, &defaultlen);
    bez->bezier.points[1].p2 = bez->bezier.points[1].p1;
    point_add(&bez->bezier.points[1].p2, &defaultlen);
    bez->bezier.points[1].p3 = bez->bezier.points[1].p2;
    point_add(&bez->bezier.points[1].p3, &defaultlen);
  } else {
    BezierCreateData *bcd = (BezierCreateData*)user_data;

    bezierconn_init(bez, bcd->num_points);
    beziercommon_set_points (&bez->bezier, bcd->num_points, bcd->points);
  }

  bezierline->line_width =  attributes_get_default_linewidth();
  bezierline->line_color = attributes_get_foreground();
  attributes_get_default_line_style(&bezierline->line_style,
				    &bezierline->dashlength);
  bezierline->line_join = LINEJOIN_MITER;
  bezierline->line_caps = LINECAPS_BUTT;
  bezierline->start_arrow = attributes_get_default_start_arrow();
  bezierline->end_arrow = attributes_get_default_end_arrow();

  *handle1 = bez->object.handles[0];
  *handle2 = bez->object.handles[3];

  bezierline_update_data(bezierline);

  return &bezierline->bez.object;
}
Exemple #5
0
static DiaObject *
radiocell_create(Point *startpoint,
		 void *user_data,
		 Handle **handle1,
		 Handle **handle2)
{
  RadioCell *radiocell;
  PolyShape *poly;
  DiaObject *obj;
  DiaFont *font;
  int i = 0;

  radiocell = g_new0(RadioCell, 1);
  poly = &radiocell->poly;
  obj = &poly->object;
  obj->type = &radiocell_type;
  obj->ops = &radiocell_ops;

  radiocell->radius = 4.;

  /* do not use default_properties.show_background here */
  radiocell->show_background = FALSE;
  radiocell->fill_colour = color_white;
  radiocell->line_colour = color_black;
  radiocell->line_width = RADIOCELL_LINEWIDTH;
  attributes_get_default_line_style(&radiocell->line_style,
				    &radiocell->dashlength);

  font = dia_font_new_from_style(DIA_FONT_MONOSPACE, RADIOCELL_FONTHEIGHT);
  radiocell->text = new_text("", font, RADIOCELL_FONTHEIGHT, startpoint,
			     &color_black, ALIGN_CENTER);
  dia_font_unref(font);

  polyshape_init(poly, 6);

  radiocell->center = *startpoint;
  /* rather broken but otherwise we will always calculate from unitialized data
   * see polyshape_update_data() */
  poly->points[0].y = startpoint->y;
  poly->points[0].x = startpoint->x - radiocell->radius;
  poly->points[3].x = startpoint->x + radiocell->radius;

  radiocell_update_data(radiocell);
  *handle1 = poly->object.handles[0];
  *handle2 = poly->object.handles[2];

  for (i=0;i<6;i++) {
    poly->object.handles[i]->id = HANDLE_CUSTOM1 + i;
  }

  return &radiocell->poly.object;
}
Exemple #6
0
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;
}
Exemple #7
0
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;
}
Exemple #8
0
static DiaObject *
zigzagline_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Zigzagline *zigzagline;
  OrthConn *orth;
  DiaObject *obj;
  Point dummy = {0, 0};

  /*zigzagline_init_defaults();*/
  zigzagline = g_malloc0(sizeof(Zigzagline));
  orth = &zigzagline->orth;
  obj = &orth->object;
  
  obj->type = &zigzagline_type;
  obj->ops = &zigzagline_ops;

  if (startpoint)
    orthconn_init(orth, startpoint);
  else
    orthconn_init(orth, &dummy);

  if (user_data) {
    MultipointCreateData *pcd = (MultipointCreateData *)user_data;
    orthconn_set_points (orth, pcd->num_points, pcd->points);
  }

  zigzagline->line_width =  attributes_get_default_linewidth();
  zigzagline->line_color = attributes_get_foreground();
  attributes_get_default_line_style(&zigzagline->line_style,
				    &zigzagline->dashlength);
  zigzagline->line_join = LINEJOIN_MITER;
  zigzagline->line_caps = LINECAPS_BUTT;
  zigzagline->start_arrow = attributes_get_default_start_arrow();
  zigzagline->end_arrow = attributes_get_default_end_arrow();
  zigzagline->corner_radius = 0.0;

  *handle1 = orth->handles[0];
  *handle2 = orth->handles[orth->numpoints-2];

  zigzagline_update_data(zigzagline);

  return &zigzagline->orth.object;
}
Exemple #9
0
static Object *
arc_create(Point *startpoint,
	   void *user_data,
	   Handle **handle1,
	   Handle **handle2)
{
  Arc *arc;
  Connection *conn;
  Object *obj;
  Point defaultlen = { 1.0, 1.0 };

  /*arc_init_defaults();*/

  arc = g_malloc(sizeof(Arc));

  arc->line_width =  attributes_get_default_linewidth();
  arc->curve_distance = 1.0;
  arc->arc_color = attributes_get_foreground(); 
  attributes_get_default_line_style(&arc->line_style, &arc->dashlength);
  arc->start_arrow = attributes_get_default_start_arrow();
  arc->end_arrow = attributes_get_default_end_arrow();

  conn = &arc->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  point_add(&conn->endpoints[1], &defaultlen);
 
  obj = (Object *) arc;
  
  obj->type = &arc_type;;
  obj->ops = &arc_ops;
  
  connection_init(conn, 3, 0);

  obj->handles[2] = &arc->middle_handle;
  arc->middle_handle.id = HANDLE_MIDDLE;
  arc->middle_handle.type = HANDLE_MINOR_CONTROL;
  arc->middle_handle.connect_type = HANDLE_NONCONNECTABLE;
  arc->middle_handle.connected_to = NULL;

  arc_update_data(arc);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return (Object *)arc;
}
Exemple #10
0
static DiaObject *
line_create(Point *startpoint,
	    void *user_data,
	    Handle **handle1,
	    Handle **handle2)
{
  Line *line;
  Connection *conn;
  DiaObject *obj;
  Point defaultlen = { 1.0, 1.0 };

  line_init_defaults();

  line = g_malloc0(sizeof(Line));

  line->line_width = attributes_get_default_linewidth();
  line->line_color = attributes_get_foreground();
  line->absolute_start_gap = default_properties.absolute_start_gap;
  line->absolute_end_gap = default_properties.absolute_end_gap;
    
  conn = &line->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  point_add(&conn->endpoints[1], &defaultlen);
 
  obj = &conn->object;
  
  obj->type = &line_type;
  obj->ops = &line_ops;

  connection_init(conn, 2, 0);
  
  line->cpl = connpointline_create(obj,1);

  attributes_get_default_line_style(&line->line_style, &line->dashlength);
  line->line_caps = LINECAPS_BUTT;
  line->start_arrow = attributes_get_default_start_arrow();
  line->end_arrow = attributes_get_default_end_arrow();
  line_update_data(line);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return &line->connection.object;
}
Exemple #11
0
static Object *
line_create(Point *startpoint,
	    void *user_data,
	    Handle **handle1,
	    Handle **handle2)
{
  Line *line;
  Connection *conn;
  Object *obj;
  Point defaultlen = { 1.0, 1.0 };

  /*line_init_defaults();*/

  line = g_malloc(sizeof(Line));

  line->line_width = attributes_get_default_linewidth();
  line->line_color = attributes_get_foreground();
  
  conn = &line->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  point_add(&conn->endpoints[1], &defaultlen);
 
  obj = (Object *) line;
  
  obj->type = &line_type;
  obj->ops = &line_ops;

  connection_init(conn, 2, 1);

  obj->connections[0] = &line->middle_point;
  line->middle_point.object = obj;
  line->middle_point.connected = NULL;
  attributes_get_default_line_style(&line->line_style, &line->dashlength);
  line->start_arrow = attributes_get_default_start_arrow();
  line->end_arrow = attributes_get_default_end_arrow();
  line_update_data(line);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return (Object *)line;
}
Exemple #12
0
static Object *
bezierline_create(Point *startpoint,
                  void *user_data,
                  Handle **handle1,
                  Handle **handle2)
{
    Bezierline *bezierline;
    BezierConn *bez;
    Object *obj;
    Point defaultlen = { .3, .3 };

    /*bezierline_init_defaults();*/
    bezierline = g_new(Bezierline, 1);
    bez = &bezierline->bez;
    obj = (Object *) bezierline;

    obj->type = &bezierline_type;
    obj->ops = &bezierline_ops;

    bezierconn_init(bez);

    bez->points[0].p1 = *startpoint;
    bez->points[1].p1 = *startpoint;
    point_add(&bez->points[1].p1, &defaultlen);
    bez->points[1].p2 = bez->points[1].p1;
    point_add(&bez->points[1].p2, &defaultlen);
    bez->points[1].p3 = bez->points[1].p2;
    point_add(&bez->points[1].p3, &defaultlen);

    bezierline_update_data(bezierline);

    bezierline->line_width =  attributes_get_default_linewidth();
    bezierline->line_color = attributes_get_foreground();
    attributes_get_default_line_style(&bezierline->line_style,
                                      &bezierline->dashlength);
    bezierline->start_arrow = attributes_get_default_start_arrow();
    bezierline->end_arrow = attributes_get_default_end_arrow();

    *handle1 = bez->object.handles[0];
    *handle2 = bez->object.handles[3];
    return (Object *)bezierline;
}
Exemple #13
0
static DiaObject *
arc_create(Point *startpoint,
           void *user_data,
           Handle **handle1,
           Handle **handle2)
{
    Arc *arc;
    Connection *conn;
    DiaObject *obj;
    Point defaultlen = { 1.0, 1.0 };

    arc = g_malloc0(sizeof(Arc));

    arc->line_width =  attributes_get_default_linewidth();
    arc->curve_distance = 1.0;
    arc->arc_color = attributes_get_foreground();
    attributes_get_default_line_style(&arc->line_style, &arc->dashlength);
    arc->line_caps = LINECAPS_BUTT;
    arc->start_arrow = attributes_get_default_start_arrow();
    arc->end_arrow = attributes_get_default_end_arrow();

    conn = &arc->connection;
    conn->endpoints[0] = *startpoint;
    conn->endpoints[1] = *startpoint;
    point_add(&conn->endpoints[1], &defaultlen);

    obj = &conn->object;

    obj->type = &arc_type;;
    obj->ops = &arc_ops;

    connection_init(conn, 4, 0);

    _arc_setup_handles (arc);

    arc_update_data(arc);

    *handle1 = obj->handles[0];
    *handle2 = obj->handles[1];
    return &arc->connection.object;
}
Exemple #14
0
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;
}