+
+/*****************************************************************************/
+/* Is object located at coordinates. */
+/*****************************************************************************/
+gboolean
+gl_label_object_is_located_at (glLabelObject *object,
+ cairo_t *cr,
+ gdouble x_pixels,
+ gdouble y_pixels)
+{
+ gboolean ret_val = FALSE;
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gdouble x, y;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ g_return_val_if_fail (object && GL_IS_LABEL_OBJECT (object), FALSE);
+
+ if ( GL_LABEL_OBJECT_GET_CLASS(object)->draw_object != NULL )
+ {
+
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+
+ cairo_save (cr);
+
+ cairo_translate (cr, x0, y0);
+ cairo_transform (cr, &matrix);
+
+ x = x_pixels;
+ y = y_pixels;
+ cairo_device_to_user (cr, &x, &y);
+
+ ret_val = GL_LABEL_OBJECT_GET_CLASS(object)->object_at (object, cr, x, y);
+
+ cairo_restore (cr);
+ }
+
+ gl_debug (DEBUG_LABEL, "END");
+
+ return ret_val;
+}
+
+
+/*****************************************************************************/
+/* Draw object handles */
+/*****************************************************************************/
+void
+gl_label_object_draw_handles (glLabelObject *object,
+ cairo_t *cr)
+{
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+ if ( GL_LABEL_OBJECT_GET_CLASS(object)->draw_object != NULL )
+ {
+
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+
+ cairo_save (cr);
+
+ cairo_translate (cr, x0, y0);
+ cairo_transform (cr, &matrix);
+
+ GL_LABEL_OBJECT_GET_CLASS(object)->draw_handles (object, cr);
+
+ cairo_restore (cr);
+ }
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Draw individual handle */
+/*--------------------------------------------------------------------------*/
+static void
+draw_handle (cairo_t *cr,
+ glLabelObject *object,
+ gdouble x_handle,
+ gdouble y_handle)
+{
+ gdouble scale_x, scale_y;
+
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ cairo_save (cr);
+
+ cairo_translate (cr, x_handle, y_handle);
+
+ scale_x = 1.0;
+ scale_y = 1.0;
+ cairo_device_to_user_distance (cr, &scale_x, &scale_y);
+ cairo_scale (cr, scale_x, scale_y);
+
+ cairo_rectangle (cr,
+ -HANDLE_PIXELS/2.0, -HANDLE_PIXELS/2.0,
+ HANDLE_PIXELS, HANDLE_PIXELS);
+
+ cairo_set_source_rgba (cr, HANDLE_FILL_RGBA_ARGS);
+ cairo_fill_preserve (cr);
+
+ cairo_set_line_width (cr, HANDLE_OUTLINE_WIDTH_PIXELS);
+ cairo_set_source_rgba (cr, HANDLE_OUTLINE_RGBA_ARGS);
+ cairo_stroke (cr);
+
+ cairo_restore (cr);
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Create handle path */
+/*--------------------------------------------------------------------------*/
+static void
+create_handle_path (cairo_t *cr,
+ glLabelObject *object,
+ gdouble x_handle,
+ gdouble y_handle)
+{
+ gdouble scale_x, scale_y;
+
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ cairo_save (cr);
+
+ cairo_translate (cr, x_handle, y_handle);
+
+ scale_x = 1.0;
+ scale_y = 1.0;
+ cairo_device_to_user_distance (cr, &scale_x, &scale_y);
+ cairo_scale (cr, scale_x, scale_y);
+
+ cairo_rectangle (cr,
+ -HANDLE_PIXELS/2.0, -HANDLE_PIXELS/2.0,
+ HANDLE_PIXELS, HANDLE_PIXELS);
+
+ cairo_restore (cr);
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+
+/*****************************************************************************/
+/* Draw box style handles. */
+/*****************************************************************************/
+void
+gl_label_object_draw_handles_box (glLabelObject *object,
+ cairo_t *cr)
+{
+ gdouble w, h;
+
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
+
+ /* North */
+ draw_handle (cr, object, w/2, 0);
+
+ /* North East */
+ draw_handle (cr, object, w, 0);
+
+ /* East */
+ draw_handle (cr, object, w, h/2);
+
+ /* South East */
+ draw_handle (cr, object, w, h);
+
+ /* South */
+ draw_handle (cr, object, w/2, h);
+
+ /* South West */
+ draw_handle (cr, object, 0, h);
+
+ /* West */
+ draw_handle (cr, object, 0, h/2);
+
+ /* North West */
+ draw_handle (cr, object, 0, 0);
+}
+
+
+/*****************************************************************************/
+/* Draw line style handles. */
+/*****************************************************************************/
+void
+gl_label_object_draw_handles_line (glLabelObject *object,
+ cairo_t *cr)
+{
+ gdouble w, h;
+
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
+
+ /* P2 */
+ draw_handle (cr, object, w, h);
+
+ /* P1 */
+ draw_handle (cr, object, 0, 0);
+}
+
+
+/*****************************************************************************/
+/* Get handle at given coordinates, if any. */
+/*****************************************************************************/
+glLabelObjectHandle
+gl_label_object_handle_at (glLabelObject *object,
+ cairo_t *cr,
+ gdouble x_pixels,
+ gdouble y_pixels)
+{
+ glLabelObjectHandle handle = GL_LABEL_OBJECT_HANDLE_NONE;
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gdouble x, y;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ g_return_val_if_fail (object && GL_IS_LABEL_OBJECT (object), handle);
+
+ if ( GL_LABEL_OBJECT_GET_CLASS(object)->draw_object != NULL )
+ {
+
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+
+ cairo_save (cr);
+
+ cairo_translate (cr, x0, y0);
+ cairo_transform (cr, &matrix);
+
+ x = x_pixels;
+ y = y_pixels;
+ cairo_device_to_user (cr, &x, &y);
+
+ handle = GL_LABEL_OBJECT_GET_CLASS(object)->handle_at (object, cr, x, y);
+
+ cairo_restore (cr);
+ }
+
+ gl_debug (DEBUG_LABEL, "END");
+
+ return handle;
+}
+
+
+/*****************************************************************************/
+/* Get handle at given coordinates for box style handles, if any. */
+/*****************************************************************************/
+glLabelObjectHandle
+gl_label_object_box_handle_at (glLabelObject *object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ gdouble w, h;
+
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
+
+ /* South East */
+ create_handle_path (cr, object, w, h);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_SE;
+ }
+
+ /* South West */
+ create_handle_path (cr, object, 0, h);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_SW;
+ }
+
+ /* North East */
+ create_handle_path (cr, object, w, 0);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_NE;
+ }
+
+ /* North West */
+ create_handle_path (cr, object, 0, 0);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_NW;
+ }
+
+ /* East */
+ create_handle_path (cr, object, w, h/2);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_E;
+ }
+
+ /* South */
+ create_handle_path (cr, object, w/2, h);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_S;
+ }
+
+ /* West */
+ create_handle_path (cr, object, 0, h/2);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_W;
+ }
+
+ /* North */
+ create_handle_path (cr, object, w/2, 0);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_N;
+ }
+
+ return GL_LABEL_OBJECT_HANDLE_NONE;
+}
+
+
+/*****************************************************************************/
+/* Get handle at given coordinates for line style handles, if any. */
+/*****************************************************************************/
+glLabelObjectHandle
+gl_label_object_line_handle_at (glLabelObject *object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ gdouble w, h;
+
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
+
+ /* P2 */
+ create_handle_path (cr, object, w, h);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_P2;
+ }
+
+ /* P1 */
+ create_handle_path (cr, object, 0, h);
+ if (cairo_in_fill (cr, x, y))
+ {
+ return GL_LABEL_OBJECT_HANDLE_P1;
+ }
+
+ return GL_LABEL_OBJECT_HANDLE_NONE;
+}
+
+
+
+
+/*
+ * Local Variables: -- emacs
+ * mode: C -- emacs
+ * c-basic-offset: 8 -- emacs
+ * tab-width: 8 -- emacs
+ * indent-tabs-mode: nil -- emacs
+ * End: -- emacs
+ */