1. Reid van Melle
  2. clutter-ocaml

Source

clutter-ocaml / src / ml_actor.c

#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))
//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);
}

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);
  result = caml_alloc(3,0);
  Store_field(result, 0, Val_int(vertex.x));
  Store_field(result, 1, Val_int(vertex.y));
  Store_field(result, 2, Val_int(vertex.z));
  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));
}

/** 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);
}

ML_1(clutter_actor_raise_top, ClutterActor_val, Unit)
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_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_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)