Exemplo n.º 1
0
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;
}
Exemplo n.º 2
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_WHEN_NEEDED;

  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;
}
Exemplo n.º 3
0
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 = &umlobject_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;
}
Exemplo n.º 4
0
static DiaObject *
pgram_create(Point *startpoint,
	   void *user_data,
	   Handle **handle1,
	   Handle **handle2)
{
  Pgram *pgram;
  Element *elem;
  DiaObject *obj;
  Point p;
  int i;
  DiaFont *font = NULL;
  real font_height;

  init_default_values();

  pgram = g_malloc0(sizeof(Pgram));
  elem = &pgram->element;
  obj = &elem->object;
  
  obj->type = &pgram_type;

  obj->ops = &pgram_ops;

  elem->corner = *startpoint;
  elem->width = DEFAULT_WIDTH;
  elem->height = DEFAULT_WIDTH;

  pgram->border_width =  attributes_get_default_linewidth();
  pgram->border_color = attributes_get_foreground();
  pgram->inner_color = attributes_get_background();
  pgram->show_background = default_properties.show_background;
  attributes_get_default_line_style(&pgram->line_style, &pgram->dashlength);
  pgram->shear_angle = default_properties.shear_angle;
  pgram->shear_grad = tan(M_PI/2.0 - M_PI/180.0 * pgram->shear_angle);

  pgram->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;
  pgram->text = new_text("", font, font_height, &p, &pgram->border_color,
			 ALIGN_CENTER);
  dia_font_unref(font);
  
  /* new default: let the user decide the size */
  pgram->text_fitting = TEXTFIT_ALWAYS;

  element_init(elem, 8, NUM_CONNECTIONS);

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

  pgram_update_data(pgram, ANCHOR_MIDDLE, ANCHOR_MIDDLE);

  *handle1 = NULL;
  *handle2 = obj->handles[7];  
  return &pgram->element.object;
}
Exemplo n.º 5
0
/*! 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;
}