]> Pileus Git - grits/blobdiff - src/objects/grits-object.h
Add grits_object_destroy functions and fix memory leaks
[grits] / src / objects / grits-object.h
index 7073576d1e58b4c8ee9f1d78136a4d1b5dc1b63f..2c11cd3ba1751d9d64a35ef42ad0e4eaa4d18e7d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #define GRITS_SKIP_CENTER  (1<<2)
 #define GRITS_SKIP_STATE   (1<<3)
 
+/* Mouse move threshold for clicking */
+#define GRITS_CLICK_THRESHOLD 8
+
 /* Picking states */
 typedef struct {
        guint picked   : 1;
        guint selected : 1;
-       guint clicking : 1;
+       guint clicking : 6;
 } GritsState;
 
 typedef struct _GritsObject      GritsObject;
@@ -57,6 +60,7 @@ struct _GritsObject {
        guint32      skip;   // Bit mask of safe operations
 
        GritsState   state;  // Internal, used for picking
+       GdkCursor   *cursor; // Internal, cached cursor
 };
 
 struct _GritsObjectClass {
@@ -76,10 +80,9 @@ void grits_object_draw(GritsObject *object, GritsOpenGL *opengl);
 void grits_object_hide(GritsObject *object, gboolean hidden);
 
 /* Interal, used by grits_opengl */
-void grits_object_pick_begin(GritsObject *object, GritsOpenGL *opengl);
-void grits_object_pick_pointer(GritsObject *object, double x, double y);
-void grits_object_pick_end(GritsObject *object);
-void grits_object_event(GritsObject *object, GdkEvent *event);
+void grits_object_pick(GritsObject *object, GritsOpenGL *opengl);
+gboolean grits_object_set_pointer(GritsObject *object, GdkEvent *event, gboolean selected);
+gboolean grits_object_event(GritsObject *object, GdkEvent *event);
 
 /**
  * grits_object_queue_draw:
@@ -89,6 +92,39 @@ void grits_object_event(GritsObject *object, GdkEvent *event);
  */
 void grits_object_queue_draw(GritsObject *object);
 
+/**
+ * grits_object_set_cursor:
+ * @object: The #GritsObject to set the cursor for
+ * @cursor: The cursor to use when the object is hovered over
+ *
+ * Causes the cursor to use a particular icon when located over a given object
+ */
+void grits_object_set_cursor(GritsObject *object, GdkCursorType cursor);
+
+/**
+ * grits_object_destroy:
+ * @object: The #GritsObject to destroy
+ *
+ * Removes the widget from it's current viewer (if it has one) and decrements
+ * it's reference count.
+ */
+void grits_object_destroy(GritsObject *object);
+
+/**
+ * grits_object_destroy_pointer:
+ * @object: The pointer to the #GritsObject to destroy
+ *
+ * This functions the same as grits_object_destroy, except that the location of
+ * the object is set to null before proceeding.
+ */
+#define grits_object_destroy_pointer(object) ({           \
+       if (*object) {                                    \
+               GritsObject *tmp = GRITS_OBJECT(*object); \
+               *object = NULL;                           \
+               grits_object_destroy(tmp);                \
+       }                                                 \
+})
+
 /**
  * grits_object_center:
  * @object: The #GritsObject to get the center of