Example #1
0
File: aadlbox.c Project: UIKit0/dia
ObjectChange*
aadlbox_move(Aadlbox *aadlbox, Point *to)
{
  Point p, delta;
  DiaObject *obj = &aadlbox->element.object;
  int i;

  delta = *to;
  point_sub(&delta, &obj->position);
  
  /* update ports position */
  for (i=0;i<aadlbox->num_ports;i++) {
    point_add(&aadlbox->ports[i]->handle->pos, &delta);
  }

  /* update connection points position */
  for (i=0;i<aadlbox->num_connections;i++) {
    point_add(&aadlbox->connections[i]->pos, &delta);
  }
  
  
  aadlbox->element.corner = *to;

  p = *to;
  p.x += AADLBOX_TEXT_MARGIN;
  p.y += aadlbox->name->ascent + AADLBOX_TEXT_MARGIN;

  aadlbox_update_data(aadlbox);

  return NULL;
}
Example #2
0
File: aadlbox.c Project: UIKit0/dia
static void
aadlbox_change_revert(struct PointChange *change, DiaObject *obj)
{
 
  switch (change->type) {
  case TYPE_ADD_POINT:
    aadlbox_remove_port((Aadlbox *)obj, change->port);
    break;

  case TYPE_REMOVE_POINT:
    aadlbox_add_port((Aadlbox *)obj, &change->point, change->port);
    break;
  
  case TYPE_ADD_CONNECTION:
    aadlbox_remove_connection((Aadlbox *)obj, change->connection);
    break;
    
  case TYPE_REMOVE_CONNECTION: ;
    aadlbox_add_connection((Aadlbox *)obj, &change->point, change->connection);
    break;
  }
  
  aadlbox_update_data((Aadlbox *)obj);
  change->applied = 0;
}
Example #3
0
File: aadlbox.c Project: UIKit0/dia
void
aadlbox_set_props(Aadlbox *aadlbox, GPtrArray *props)
{
  object_set_props_from_offsets(&aadlbox->element.object,
                                aadlbox_offsets,props);
  aadlbox_update_data(aadlbox);
}
Example #4
0
void
aadlbox_set_props(Aadlbox *aadlbox, GPtrArray *props)
{
  object_set_props_from_offsets(&aadlbox->element.object,
                                aadlbox_offsets,props);
  apply_textattr_properties(props,aadlbox->name,"name",&aadlbox->attrs);
  aadlbox_update_data(aadlbox);
}
Example #5
0
File: aadlbox.c Project: UIKit0/dia
ObjectChange *
aadlbox_add_connection_callback (DiaObject *obj, Point *clicked, gpointer data)
{
  Aadlbox *aadlbox = (Aadlbox *) obj;
  ConnectionPoint *connection;

  connection = g_new0(ConnectionPoint,1);

  aadlbox_add_connection(aadlbox, clicked, connection);
  aadlbox_update_data(aadlbox);
  
  return aadlbox_create_change(aadlbox, TYPE_ADD_CONNECTION, clicked,connection);
}
Example #6
0
File: aadlbox.c Project: UIKit0/dia
ObjectChange *
aadlbox_add_port_callback (DiaObject *obj, Point *clicked, gpointer data)
{
  Aadlbox *aadlbox = (Aadlbox *) obj;
  Aadl_type type = *((Aadl_type *) data);
  Aadlport *port;

  port = new_port(type, "");
  aadlbox_add_port(aadlbox, clicked, port);
  aadlbox_update_data(aadlbox);

  return aadlbox_create_change(aadlbox, TYPE_ADD_POINT, clicked, port);
}
Example #7
0
File: aadlbox.c Project: UIKit0/dia
ObjectChange *
aadlbox_delete_port_callback (DiaObject *obj, Point *clicked, gpointer data)
{
  Aadlbox *aadlbox = (Aadlbox *) obj;
  Aadlport *port;
  int port_num;
  Point p;

  port_num = aadlbox_point_near_port(aadlbox, clicked);

  port = aadlbox->ports[port_num];
  p = port->handle->pos;

  aadlbox_remove_port(aadlbox, port );
  aadlbox_update_data(aadlbox);

  return aadlbox_create_change(aadlbox, TYPE_REMOVE_POINT, &p, port);
}
Example #8
0
File: aadlbox.c Project: UIKit0/dia
ObjectChange *
aadlbox_delete_connection_callback (DiaObject *obj, Point *clicked, 
				    gpointer data)
{
  Aadlbox *aadlbox = (Aadlbox *) obj;
  ConnectionPoint *connection;
  int connection_num;
  Point p;

  connection_num = aadlbox_point_near_connection(aadlbox, clicked);

  connection = aadlbox->connections[connection_num];
  p = connection->pos;

  aadlbox_remove_connection(aadlbox, connection );
  aadlbox_update_data(aadlbox);

  return aadlbox_create_change(aadlbox, TYPE_REMOVE_CONNECTION, &p, connection);
}
Example #9
0
/** *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;
}
Example #10
0
File: aadlbox.c Project: UIKit0/dia
ObjectChange*
aadlbox_move_handle(Aadlbox *aadlbox, Handle *handle,
		 Point *to, ConnectionPoint *cp,
		 HandleMoveReason reason, ModifierKeys modifiers)
{
  assert(aadlbox!=NULL);
  assert(handle!=NULL);
  assert(to!=NULL);
  
  if (handle->id < 8) {   /* box resizing */
    
    Element *element = &aadlbox->element;
    Point oldcorner, newcorner;
    real oldw, neww, oldh, newh;
    real w_factor, h_factor;
    Aadlport *p;
    ConnectionPoint *c;
    int i;
    
    point_copy(&oldcorner, &element->corner);
    oldw = element->width;
    oldh = element->height;
        
    element_move_handle( &aadlbox->element, handle->id, to, cp,
			 reason, modifiers);
    
    point_copy(&newcorner, &element->corner);
    neww = element->width;
    newh = element->height;
    
    /* update ports positions proportionally */
    for (i=0; i < aadlbox->num_ports; i++)
    {
      p = aadlbox->ports[i];

      w_factor = (p->handle->pos.x - oldcorner.x) / oldw; 
      h_factor = (p->handle->pos.y - oldcorner.y) / oldh;
      
      p->handle->pos.x = newcorner.x + w_factor * neww;
      p->handle->pos.y = newcorner.y + h_factor * newh;
    }

    /* update connection points proportionally */
    for (i=0; i < aadlbox->num_connections; i++)
    {
      c = aadlbox->connections[i];
      
      w_factor = (c->pos.x - oldcorner.x) / oldw; 
      h_factor = (c->pos.y - oldcorner.y) / oldh;
      
      c->pos.x = newcorner.x + w_factor * neww;
      c->pos.y = newcorner.y + h_factor * newh;
    }
    
  }

  else {    /* port handles */

    handle->pos.x = to->x;
    handle->pos.y = to->y;
  }
  
  aadlbox_update_data(aadlbox);
  
  /* FIXME !!  Should I free the given structures (to, ...) ? */
  return NULL;
}