[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

How to use the PointArray property



Hallo,

I had this question back in May, but most developers were
busy with the transition to GTK2, so I send it again:

I'm writing a new plugin for dia.  I have defined a type
'Condition' derived from 'Connection', which has two
"normal" handles, and more handles can be added and removed
by the user via the object menu.  This is similar to
network/bus.c, but I like to save the positions of the
additional handles without custom code.  Instead I like to
use the PointArray property.  The idea is to save the point
positions when saving and creating the Handle objects
accordingly, because all user-created handles are identical,
except the ->pos.

Now my questions:

- Can I save handle positions that way or do have I to write
  custom code for saving (in XML) the handle positions?

- Are the types etc. correct?

- Is there an example for using the PointArray property? (I
  didn't find a dia plugin for that purpose, and
  network/bus.c uses custom code instead.  Why?)

Here is an excerpt from my code, maybe someone can check it?
(I will give my code to the GNU community under GPL when
it's ready.)

Thanks in advance!

#include "prop_geomtypes.h"

typedef struct _Condition {
  Connection connection;
  ...
  GArray *handles;
  GArray *handle_points;
} Condition;

static PropDescription condition_props[] = {
  CONNECTION_COMMON_PROPERTIES,
  ...
  { "handle_points", PROP_TYPE_POINTARRAY, 0, NULL, NULL },
  PROP_DESC_END
};

static PropOffset condition_offsets[] = {
  CONNECTION_COMMON_PROPERTIES_OFFSETS,
  ...
  { "handle_points", PROP_TYPE_POINTARRAY, offsetof(Condition, handle_points)},
  {NULL}
};

static Object *
condition_create(Point *startpoint,
                 void *user_data,
                 Handle **handle1,
                 Handle **handle2)
{
  Condition *condition;
  Connection *conn;
  Object *obj;
  Point p;
  Handle *handle;

  condition = g_new0(Condition, 1);
  conn = &condition->connection;
  obj = &conn->object;
  conn->endpoints[0] = conn->endpoints[1] = *startpoint;
  conn->endpoints[1].x += CONDITION_WIDTH;
  
  obj->type = &condition_type;
  obj->ops = &condition_ops;

  connection_init(conn, 2, 0);

  condition->handles = g_array_new(FALSE, TRUE, sizeof(Handle));
  condition->handle_points = g_array_new(FALSE, TRUE, sizeof(Point));

  condition_update_data(condition);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  obj->handles[0]->connect_type = HANDLE_NONCONNECTABLE;
  obj->handles[1]->connect_type = HANDLE_NONCONNECTABLE;

  handle = g_new0(Handle, 1);
  handle->id = HANDLE_CONDITION;
  handle->type = HANDLE_MINOR_CONTROL;
  handle->connect_type = HANDLE_CONNECTABLE_NOBREAK;
  handle->connected_to = NULL;
  handle->pos = *startpoint;
  handle->pos.x = (conn->endpoints[0].x + conn->endpoints[1].x)/2.0;
  handle->pos.y = conn->endpoints[0].y;
  g_array_append_val(condition->handles, *handle);
  object_add_handle(&condition->connection.object, handle);

  return &condition->connection.object;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK