Source

clutter-ocaml / src / ml_actor.c

Full commit
#include "wrappers.h"
#include "clutter_tags.h"
#include "ml_actor.h"


// ClutterActorBox
#define ClutterActorBox_val(val) ((ClutterActorBox *)Pointer_val(val))
#define Val_ClutterActorBox(val) (Val_pointer(val))
//FIXME: Make_Val_final_pointer(ClutterActorBox, Ignore, free, 1);
Make_Extractor (clutter_actorbox_get, ClutterActorBox_val, x1, Val_long)
Make_Extractor (clutter_actorbox_get, ClutterActorBox_val, y1, Val_long)
Make_Extractor (clutter_actorbox_get, ClutterActorBox_val, x2, Val_long)
Make_Extractor (clutter_actorbox_get, ClutterActorBox_val, y2, Val_long)
CAMLprim value ml_clutter_actorbox_new(value x1, value y1, value x2, value y2) {
  CAMLparam4(x1,y1,x2,y2);
  ClutterActorBox *b = malloc(sizeof(ClutterActorBox));
  b->x1 = Int_val(x1);
  b->y1 = Int_val(y1);
  b->x2 = Int_val(x2);
  b->y2 = Int_val(y2);
  CAMLreturn(Val_ClutterActorBox(b));
}

// Actor
// FIXME: deal with this stupic ompare thing
static int ml_custom_compare_actor(value v1, value v2) \
{ return v1 == v2 ? 0 : 1; }

static struct custom_operations ml_clutter_actor_ops = {
  "ClutterActor",
  custom_finalize_default,
  ml_custom_compare_actor,
  custom_hash_default,
  custom_serialize_default,
  custom_deserialize_default
};

value Val_ClutterActor_ (ClutterActor *t, gboolean ref)
{ 
  ClutterActor **p;
  value ret; 
  if (t == NULL) ml_raise_null_pointer(); 
  ret = alloc_custom (&ml_clutter_actor_ops, sizeof t, 
		      100, 1000);
  p = Data_custom_val (ret);
  *p = ref ? g_object_ref (t) : t;
  return ret; 
}

void ml_clutter_actor_callback (ClutterActor *a, gpointer data)
{
  value val, *clos = (value*)data;
  val = Val_ClutterActor(a);
  callback_exn (*clos, val);
  ml_global_root_destroy(clos);
}

#define Val_ClutterVertex(v,result) result = caml_alloc(3,0);	\
  Store_field( result, 0, Val_int( v.x)); \
  Store_field( result, 1, Val_int( v.y)); \
  Store_field( result, 2, Val_int( v.z));

CAMLprim value ml_clutter_actor_get_abs_allocation_vertices(value _a) {
  CAMLparam1(_a);
  CAMLlocal5(result,v1,v2,v3,v4);
  ClutterActor* a = ClutterActor_val(_a);
  ClutterVertex    v[4];  
  clutter_actor_get_abs_allocation_vertices (a, v);
  result = caml_alloc(4,0);
  v1 = caml_alloc(3,0);
  v2 = caml_alloc(3,0);
  v3 = caml_alloc(3,0);
  v4 = caml_alloc(3,0);
  value*          values[4] = {&v1,&v2,&v3,&v4};
  Store_field(result, 0, v1);
  Store_field(result, 1, v2);
  Store_field(result, 2, v3);
  Store_field(result, 3, v4);
  int i;
  for (i=0; i<4; i++) {
    Store_field(*values[i], 0, Val_int(v[i].x));
    Store_field(*values[i], 1, Val_int(v[i].y));
    Store_field(*values[i], 2, Val_int(v[i].z));
  }
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_transform_stage_point(value _a, value _x,
						      value _y)
{
  CAMLparam3(_a, _x, _y);
  CAMLlocal1(result);
  ClutterActor* a = ClutterActor_val(_a);
  result = caml_alloc(3,0);
  ClutterUnit x_out, y_out;
  gboolean success = clutter_actor_transform_stage_point
    (a, Int_val(_x), Int_val(_y), &x_out, &y_out);
  Store_field(result, 0, Val_bool(success));
  Store_field(result, 1, Val_int(x_out));
  Store_field(result, 2, Val_int(y_out));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_apply_transform_to_point(value _a, value _point) {
  CAMLparam2(_a, _point);
  CAMLlocal1(result);
  ClutterActor* a = ClutterActor_val(_a);
  ClutterVertex point = { Triple(_point, Int_val, Int_val, Int_val) };
  ClutterVertex vertex;
  clutter_actor_apply_transform_to_point(a, &point, &vertex);
  Val_ClutterVertex(vertex, result);
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_allocation_box(value _a) {
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor* a = ClutterActor_val(_a);
  ClutterActorBox* b = malloc(sizeof(ClutterActorBox));
  clutter_actor_get_allocation_box(a, b);
  CAMLreturn(Val_ClutterActorBox(b));
}

CAMLprim value ml_clutter_actor_get_allocation_vertices(value _a, value _anc)
{
  CAMLparam2(_a, _anc);
  CAMLlocal5(result,v1,v2,v3,v4);
  ClutterActor* a = ClutterActor_val(_a);
  ClutterActor* ancestor = Option_val(_anc, ClutterActor_val, NULL);
  ClutterVertex    v[4];  
  clutter_actor_get_allocation_vertices (a, ancestor, v);
  result = caml_alloc(4,0);
  v1 = caml_alloc(3,0);
  v2 = caml_alloc(3,0);
  v3 = caml_alloc(3,0);
  v4 = caml_alloc(3,0);
  value*          values[4] = {&v1,&v2,&v3,&v4};
  Store_field(result, 0, v1);
  Store_field(result, 1, v2);
  Store_field(result, 2, v3);
  Store_field(result, 3, v4);
  int i;
  for (i=0; i<4; i++) {
    Store_field(*values[i], 0, Val_int(v[i].x));
    Store_field(*values[i], 1, Val_int(v[i].y));
    Store_field(*values[i], 2, Val_int(v[i].z));
  }
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_anchor_point(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  gint anchor_x, anchor_y;
  clutter_actor_get_anchor_point(a, &anchor_x, &anchor_y);
  result = caml_alloc(2,0);
  Store_field(result, 0, Val_int(anchor_x));
  Store_field(result, 1, Val_int(anchor_y));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_position(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  gint x, y;
  clutter_actor_get_position(a, &x, &y);
  result = caml_alloc(2,0);
  Store_field(result, 0, Val_int(x));
  Store_field(result, 1, Val_int(y));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_transformed_position(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  gint x, y;
  clutter_actor_get_transformed_position(a, &x, &y);
  result = caml_alloc(2,0);
  Store_field(result, 0, Val_int(x));
  Store_field(result, 1, Val_int(y));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_transformed_size(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  guint width, height;
  clutter_actor_get_transformed_size(a, &width, &height);
  result = caml_alloc(2,0);
  Store_field(result, 0, Val_int(width));
  Store_field(result, 1, Val_int(height));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_preferred_size(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterUnit m,n,o,p;
  clutter_actor_get_preferred_size(a, &m, &n, &o, &p);
  result = caml_alloc(4,0);
  Store_field(result, 0, Val_int(m));
  Store_field(result, 1, Val_int(n));
  Store_field(result, 2, Val_int(o));
  Store_field(result, 3, Val_int(p));  
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_preferred_width(value _a, value _h)
{
  CAMLparam2(_a, _h);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterUnit h = Int_val(_h);
  ClutterUnit m,n;
  clutter_actor_get_preferred_width(a,h,&m,&n);
  result = caml_alloc(2,0);
  Store_field(result, 0, Val_int(m));
  Store_field(result, 1, Val_int(n));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_preferred_height(value _a, value _w)
{
  CAMLparam2(_a, _w);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterUnit w = Int_val(_w);
  ClutterUnit m,n;
  clutter_actor_get_preferred_height(a,w,&m,&n);
  result = caml_alloc(2,0);
  Store_field(result, 0, Val_int(m));
  Store_field(result, 1, Val_int(n));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_rotation(value _a, value _axis)
{
  CAMLparam1(_a);
  CAMLlocal2(result, v_angle);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterRotateAxis axis = Rotate_axis_type_val(_axis);
  gint x,y,z;
  gdouble angle = clutter_actor_get_rotation(a, axis, &x, &y, &z);
  v_angle = caml_copy_double(angle);
  result = caml_alloc(4,0);
  Store_field(result, 0, v_angle);
  Store_field(result, 1, Val_int(x));
  Store_field(result, 2, Val_int(y));
  Store_field(result, 3, Val_int(z));  
  CAMLreturn(result);
}

/** Geometry object */
Make_Val_final_pointer(ClutterGeometry, Ignore, free, 5)
CAMLprim value ml_clutter_geometry_create(value _geom)
{
  CAMLparam1(_geom);
  ClutterGeometry *geom = malloc(sizeof(ClutterGeometry));
  geom->x = Int_val(Field(_geom,0));
  geom->y = Int_val(Field(_geom,1));
  geom->width = Int_val(Field(_geom,2));
  geom->height = Int_val(Field(_geom,3));
  CAMLreturn(Val_ClutterGeometry(geom));
}

CAMLprim value ml_clutter_geometry_get(value _geom)
{
  CAMLparam1(_geom);
  CAMLlocal1(result);
  ClutterGeometry *geom = Pointer_val(_geom);
  result = caml_alloc(4,0);
  Store_field(result, 0, Val_int(geom->x));
  Store_field(result, 1, Val_int(geom->y));
  Store_field(result, 2, Val_int(geom->width));
  Store_field(result, 3, Val_int(geom->height));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_geometry(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterGeometry *geom = malloc(sizeof(ClutterGeometry));
  clutter_actor_get_geometry(a, geom);
  result = caml_alloc(4,0);
  Store_field(result, 0, Val_int(geom->x));
  Store_field(result, 1, Val_int(geom->y));
  Store_field(result, 2, Val_int(geom->width));
  Store_field(result, 3, Val_int(geom->height));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_set_geometry(value _a, value _geom)
{
  CAMLparam2(_a, _geom);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterGeometry geom;
  geom.x = Int_val(Field(_geom,0));
  geom.y = Int_val(Field(_geom,1));
  geom.width = Int_val(Field(_geom,2));
  geom.height = Int_val(Field(_geom,3));
  clutter_actor_set_geometry(a, &geom);
  CAMLreturn(Val_unit);
}

CAMLprim value ml_clutter_actor_apply_relative_transform_to_point(value _a, value _ancestor, value _point)
{
  CAMLparam3(_a, _ancestor, _point);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterActor *ancestor = Option_val(_ancestor, ClutterActor_val, NULL);
  ClutterVertex point = { Triple(_point, Int_val, Int_val, Int_val) };
  ClutterVertex vertex;
  clutter_actor_apply_relative_transform_to_point(a, ancestor, &point, &vertex);
  Val_ClutterVertex(vertex, result);
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_allocation_coords(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  gint x1, x2, y1, y2;
  clutter_actor_get_allocation_coords(a, &x1, &y1, &x2, &y2);
  result = caml_alloc(4,0);
  Store_field(result, 0, Val_int(x1));
  Store_field(result, 1, Val_int(y1));
  Store_field(result, 2, Val_int(x2));
  Store_field(result, 3, Val_int(x2));
  CAMLreturn(result);
}

CAMLprim value ml_clutter_actor_get_allocation_geometry(value _a)
{
  CAMLparam1(_a);
  CAMLlocal1(result);
  ClutterActor *a = ClutterActor_val(_a);
  ClutterGeometry g;
  clutter_actor_get_allocation_geometry(a, &g);
  result = caml_alloc(4,0);
  Store_field(result, 0, Val_int(g.x));
  Store_field(result, 1, Val_int(g.y));
  Store_field(result, 2, Val_int(g.width));
  Store_field(result, 3, Val_int(g.height));
  CAMLreturn(result);
}


ML_3(clutter_actor_event, ClutterActor_val, Pointer_val, Bool_val, Val_bool)
ML_1(clutter_actor_get_paint_opacity, ClutterActor_val, Val_int)
ML_1(clutter_actor_get_gid, ClutterActor_val, Val_int)
ML_2(clutter_actor_set_parent, ClutterActor_val, ClutterActor_val, Unit)
ML_2(clutter_actor_reparent, ClutterActor_val, ClutterActor_val, Unit)
ML_1(clutter_actor_raise_top, ClutterActor_val, Unit)
ML_1(clutter_actor_lower_bottom, ClutterActor_val, Unit)
ML_2(clutter_actor_raise, ClutterActor_val, ClutterActor_val, Unit)
ML_2(clutter_actor_lower, ClutterActor_val, ClutterActor_val, Unit)
ML_1(clutter_actor_remove_clip, ClutterActor_val, Unit)
ML_1(clutter_actor_is_scaled, ClutterActor_val, Val_bool)
ML_1(clutter_actor_is_rotated, ClutterActor_val, Val_bool)
ML_1(clutter_actor_show_all, ClutterActor_val, Unit)
ML_1(clutter_actor_show, ClutterActor_val, Unit)
ML_3(clutter_actor_set_scale, ClutterActor_val, Double_val, Double_val, Unit)
ML_3(clutter_actor_allocate, ClutterActor_val, ClutterActorBox_val, Bool_val, Unit)
ML_2(clutter_actor_allocate_preferred_size, ClutterActor_val, Bool_val, Unit)
ML_3(clutter_actor_move_by, ClutterActor_val, Int_val, Int_val, Unit)

ML_1(clutter_actor_get_width, ClutterActor_val, Val_int)
ML_1(clutter_actor_get_height, ClutterActor_val, Val_int)
ML_2(clutter_actor_set_anchor_point_from_gravity,  ClutterActor_val,
     Gravity_type_val, Unit)
ML_3(clutter_actor_set_anchor_point, ClutterActor_val, Int_val, Int_val, Unit)
ML_2(clutter_actor_move_anchor_point_from_gravity,  ClutterActor_val,
     Gravity_type_val, Unit)
ML_3(clutter_actor_move_anchor_point, ClutterActor_val, Int_val, Int_val, Unit)
ML_1(clutter_actor_hide, ClutterActor_val, Unit)
ML_1(clutter_actor_hide_all, ClutterActor_val, Unit)
ML_1(clutter_actor_realize, ClutterActor_val, Unit)
ML_1(clutter_actor_unrealize, ClutterActor_val, Unit)
ML_1(clutter_actor_get_parent, ClutterActor_val, Val_ClutterActor)
ML_1(clutter_actor_paint, ClutterActor_val, Unit)
ML_1(clutter_actor_destroy, ClutterActor_val, Unit)
ML_1(clutter_actor_queue_redraw, ClutterActor_val, Unit)
ML_1(clutter_actor_queue_relayout, ClutterActor_val, Unit)
ML_3(clutter_actor_set_size, ClutterActor_val, Int_val, Int_val, Unit)
ML_3(clutter_actor_set_position, ClutterActor_val, Int_val, Int_val, Unit)
ML_6(clutter_actor_set_rotation, ClutterActor_val, Rotate_axis_type_val, Float_val, Int_val, Int_val, Int_val, Unit)
ML_bc6(ml_clutter_actor_set_rotation)