Exemple #1
0
void ui_common_draw_view_axis(GnomeCanvas * canvas, gint row, gint column, 
			      AmitkView view, AmitkLayout layout, 
			      gint axis_width, gint axis_height) {

  const gchar * x_axis_label;
  gdouble x_axis_label_x_location;
  gdouble x_axis_label_y_location;
  GtkAnchorType x_axis_label_anchor;
  GnomeCanvasPoints * x_axis_line_points;

  const gchar * y_axis_label;
  gdouble y_axis_label_x_location;
  gdouble y_axis_label_y_location;
  GtkAnchorType y_axis_label_anchor;
  GnomeCanvasPoints * y_axis_line_points;

  x_axis_line_points = gnome_canvas_points_new(2);
  x_axis_line_points->coords[0] = column*axis_width + AXIS_MARGIN; /* x1 */

  y_axis_line_points = gnome_canvas_points_new(2);
  y_axis_line_points->coords[0] = column*axis_width + AXIS_MARGIN; /* x1 */

  switch(view) {
  case AMITK_VIEW_CORONAL:
    /* the x axis */
    x_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
    x_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    x_axis_line_points->coords[3] = row*axis_height + AXIS_HEADER; /* y2 */

    /* the x label */
    x_axis_label = amitk_axis_get_name(AMITK_AXIS_X);
    x_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    x_axis_label_y_location = row*axis_height + AXIS_HEADER+AXIS_TEXT_MARGIN;
    x_axis_label_anchor = GTK_ANCHOR_NORTH_EAST;
    
    /* the z axis */
    y_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
    y_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    y_axis_line_points->coords[3] = row*axis_height + axis_height-AXIS_MARGIN; /* y2 */
    
    /* the z label */
    y_axis_label = amitk_axis_get_name(AMITK_AXIS_Z);
    y_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
    y_axis_label_y_location = row*axis_height + axis_height-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    y_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;
    break;
  case AMITK_VIEW_SAGITTAL:
    /* the y axis */
      x_axis_line_points->coords[3] = row*axis_height + AXIS_HEADER; /* y2 */
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      x_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
      x_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    } else { /* AMITK_LAYOUT_LINEAR */ 
      x_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
      x_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    }
    
    /* the y label */
    x_axis_label = amitk_axis_get_name(AMITK_AXIS_Y);
    x_axis_label_y_location = row*axis_height + AXIS_HEADER+AXIS_TEXT_MARGIN;
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      x_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
      x_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;
    } else {/* AMITK_LAYOUT_LINEAR */
      x_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
      x_axis_label_anchor = GTK_ANCHOR_NORTH_EAST;
    }
    
    /* the z axis */
    y_axis_line_points->coords[3] = row*axis_height + axis_height-AXIS_MARGIN; /* y2 */
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      y_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
      y_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    } else { /* AMITK_LAYOUT_LINEAR */ 
      y_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
      y_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    }
    
    /* the z label */
    y_axis_label = amitk_axis_get_name(AMITK_AXIS_Z);
    y_axis_label_y_location = row*axis_height + axis_height-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      y_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
      y_axis_label_anchor = GTK_ANCHOR_SOUTH_EAST;
    } else {
      y_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
      y_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;
    }
    break;
  case AMITK_VIEW_TRANSVERSE:
  default:
    /* the x axis */
    x_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
    x_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    x_axis_line_points->coords[3] = row*axis_height + axis_height-AXIS_MARGIN; /* y2 */
  
    /* the x label */
    x_axis_label = amitk_axis_get_name(AMITK_AXIS_X);
    x_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    x_axis_label_y_location = row*axis_height + axis_height-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    x_axis_label_anchor = GTK_ANCHOR_SOUTH_EAST;

    /* the y axis */
    y_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
    y_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    y_axis_line_points->coords[3] = row*axis_height + AXIS_HEADER; /* y2 */

    /* the y label */
    y_axis_label = amitk_axis_get_name(AMITK_AXIS_Y);
    y_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
    y_axis_label_y_location = row*axis_height + AXIS_HEADER+AXIS_TEXT_MARGIN;
    y_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;

    break;
  }

  /* the view label */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_text_get_type(),
			"anchor", GTK_ANCHOR_NORTH, "text", amitk_view_get_name(view),
			"x", (gdouble) (column+0.5)*axis_width,
			"y", (gdouble) (row+0.5)*axis_height, 
			"fill_color", "black", 
			"font_desc", amitk_fixed_font_desc, NULL);

  /* the x axis */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_line_get_type(),
			"points", x_axis_line_points, "fill_color", "black",
			"width_pixels", 3, "last_arrowhead", TRUE, 
			"arrow_shape_a", (gdouble) AXIS_ARROW_LENGTH,
			"arrow_shape_b", (gdouble) AXIS_ARROW_EDGE,
			"arrow_shape_c", (gdouble) AXIS_ARROW_WIDTH,
			NULL);

  /* the x label */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_text_get_type(),
			"anchor", x_axis_label_anchor,"text", x_axis_label,
			"x", x_axis_label_x_location, "y", x_axis_label_y_location,
			"fill_color", "black", "font_desc", amitk_fixed_font_desc, NULL); 

  /* the y axis */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_line_get_type(),
			"points", y_axis_line_points, "fill_color", "black",
			"width_pixels", 3, "last_arrowhead", TRUE, 
			"arrow_shape_a", (gdouble) AXIS_ARROW_LENGTH,
			"arrow_shape_b", (gdouble) AXIS_ARROW_EDGE,
			"arrow_shape_c", (gdouble) AXIS_ARROW_WIDTH,
			NULL);

  gnome_canvas_points_unref(x_axis_line_points);
  gnome_canvas_points_unref(y_axis_line_points);

  /* the y label */
  gnome_canvas_item_new(gnome_canvas_root(canvas),gnome_canvas_text_get_type(),
			"anchor", y_axis_label_anchor, "text", y_axis_label,
			"x", y_axis_label_x_location,"y", y_axis_label_y_location,
			"fill_color", "black", "font_desc", amitk_fixed_font_desc, NULL); 

  return;
}
/* so much gayness in here, either I suck or gnome-canvas does; most
 * likely, we both do */
static void draw_key(PhatKeyboard* self, gint index, gint pos, guint bg,
                     guint hi, guint low, guint pre, guint on, guint shad)
{
    _Key* key = &self->keys[index];
    GnomeCanvasPoints* points;
    gint x1;
    gint y1;
    gint x2;
    gint y2;

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        x1 = 0;
        y1 = pos + 1;           /* teh gayz0r */
        x2 = PHAT_KEYBOARD_KEY_LENGTH - 1;
        y2 = pos - PHAT_KEYBOARD_KEY_WIDTH + 1;
    }
    else
    {
        x1 = pos + PHAT_KEYBOARD_KEY_WIDTH - 1;
        y1 = 0;
        x2 = pos;
        y2 = PHAT_KEYBOARD_KEY_LENGTH - 1;
    }
    
    /* key group */
    key->group = (GnomeCanvasGroup*) gnome_canvas_item_new(gnome_canvas_root(self->canvas),
                                                           gnome_canvas_group_get_type(),
                                                           NULL);
    g_signal_connect(G_OBJECT(key->group), "event",
                     G_CALLBACK(key_press_cb), (gpointer)key);
    key->index = index;
    key->hold = 0;
    key->keyboard = self;
    
    /* draw main key rect */
    gnome_canvas_item_new(key->group,
                          gnome_canvas_rect_get_type(),
                          "x1", (gdouble)x1,
                          "y1", (gdouble)y1,
                          "x2", (gdouble)x2,
                          "y2", (gdouble)y2,
                          "fill-color-rgba", bg,
                          NULL);

    
    /* draw prelight rect */
    key->pre = gnome_canvas_item_new(key->group,
                                     gnome_canvas_rect_get_type(),
                                     "x1", (gdouble)x1,
                                     "y1", (gdouble)y1,
                                     "x2", (gdouble)x2,
                                     "y2", (gdouble)y2,
                                     "fill-color-rgba", pre,
                                     NULL);
    gnome_canvas_item_hide(key->pre);
    
    /* draw key highlight */
    points = gnome_canvas_points_new(3);

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        points->coords[0] = x1+1;
        points->coords[1] = y1;
        points->coords[2] = x1+1;
        points->coords[3] = y2+1;
        points->coords[4] = x2;
        points->coords[5] = y2+1;
    }
    else
    {
        points->coords[0] = x1;
        points->coords[1] = y1+1;
        points->coords[2] = x2;
        points->coords[3] = y1+1;
        points->coords[4] = x2;
        points->coords[5] = y2;
    }

    gnome_canvas_item_new(key->group,
                          gnome_canvas_line_get_type(),
                          "points", points,
                          "width-units", (gdouble)1,
                          "fill-color-rgba", hi,
                          NULL);

    gnome_canvas_points_unref(points);
                        
    /* draw key border */
    points = gnome_canvas_points_new(4);
    
    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        points->coords[0] = x1;
        points->coords[1] = y1;
        points->coords[2] = x1;
        points->coords[3] = y2;
        points->coords[4] = x2;
        points->coords[5] = y2;
        points->coords[6] = x2;
        points->coords[7] = y1;
    }
    else
    {
        points->coords[0] = x2;
        points->coords[1] = y1;
        points->coords[2] = x1;
        points->coords[3] = y1;
        points->coords[4] = x1;
        points->coords[5] = y2;
        points->coords[6] = x2;
        points->coords[7] = y2;
    }

    gnome_canvas_item_new(key->group,
                          gnome_canvas_line_get_type(),
                          "points", points,
                          "width-units", (gdouble)1,
                          "fill-color-rgba", low,
                          NULL);
    
    gnome_canvas_points_unref(points);

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        /* draw active rect */
        key->on = gnome_canvas_item_new(key->group,
                                        gnome_canvas_rect_get_type(),
                                        "x1", (gdouble)x1+1,
                                        "y1", (gdouble)y1,
                                        "x2", (gdouble)x2,
                                        "y2", (gdouble)y2+1,
                                        "fill-color-rgba", on,
                                        NULL);
    }
    else
    {
        /* draw active rect */
        key->on = gnome_canvas_item_new(key->group,
                                        gnome_canvas_rect_get_type(),
                                        "x1", (gdouble)x1,
                                        "y1", (gdouble)y1+1,
                                        "x2", (gdouble)x2,
                                        "y2", (gdouble)y2,
                                        "fill-color-rgba", on,
                                        NULL);
    }
    
    gnome_canvas_item_hide(key->on);
    
    /* draw active shadow */
    points = gnome_canvas_points_new(6);

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        points->coords[0] = x1+1;
        points->coords[1] = y1;
    
        points->coords[2] = x1+1;
        points->coords[3] = y2+1;
    
        points->coords[4] = x2;
        points->coords[5] = y2+1;
    
        points->coords[6] = x2;
        points->coords[7] = y2 + 3;
    
        points->coords[8] = x1 + 3;
        points->coords[9] = y2 + 3;
    
        points->coords[10] = x1 + 3;
        points->coords[11] = y1;
    }
    else
    {
        points->coords[0] = x1;
        points->coords[1] = y1 + 1;
    
        points->coords[2] = x2;
        points->coords[3] = y1 + 1;
    
        points->coords[4] = x2;
        points->coords[5] = y2;
    
        points->coords[6] = x2 + 2;
        points->coords[7] = y2;
    
        points->coords[8] = x2 + 2;
        points->coords[9] = y1 + 3;
    
        points->coords[10] = x1;
        points->coords[11] = y1 + 3;
    }
        
    
    key->shad = gnome_canvas_item_new(key->group,
                                      gnome_canvas_polygon_get_type(),
                                      "points", points,
                                      "fill-color-rgba", shad,
                                      NULL);
    gnome_canvas_item_hide(key->shad);
    gnome_canvas_points_unref(points);

    /* draw label if applicable */
    if (self->label && (index % 12) == 0)
    {
        gchar* s = g_strdup_printf("%d", index / 12 + 1);

        if (self->orientation == GTK_ORIENTATION_VERTICAL)
        {
            gnome_canvas_item_new(key->group,
                                  gnome_canvas_text_get_type(),
                                  "text", s,
                                  "x", (gdouble)(x2 - 2),
                                  "y", (gdouble)(y1 - (PHAT_KEYBOARD_KEY_WIDTH / 2)),
                                  "anchor", GTK_ANCHOR_EAST,
                                  "fill-color-rgba", (gint)KEY_TEXT_BG,
                                  "font", "sans",
                                  "size-points", (gdouble)TEXT_POINTS,
                                  NULL);
        }
        else
        {
            gnome_canvas_item_new(key->group,
                                  gnome_canvas_text_get_type(),
                                  "text", s,
                                  "x", (gdouble)(x1 - (PHAT_KEYBOARD_KEY_WIDTH / 2)),
                                  "y", (gdouble)(y2 - 2),
                                  "anchor", GTK_ANCHOR_SOUTH,
                                  "fill-color-rgba", (gint)KEY_TEXT_BG,
                                  "font", "sans",
                                  "size-points", (gdouble)TEXT_POINTS,
                                  "justification", GTK_JUSTIFY_CENTER,
                                  NULL);
        }
    
        g_free(s);
    }
}