Esempio n. 1
0
static gboolean key_press_cb(GnomeCanvasItem* item, GdkEvent* event, _Key* key)
{
    switch (event->type)
    {
    case GDK_BUTTON_PRESS:
    	if((key->keyboard->hold == 1 && key->hold == 0) || key->keyboard->hold == 0){
        	gnome_canvas_item_show(key->on);
        	gnome_canvas_item_show(key->shad);
        	key->hold = 1;
        	g_signal_emit(key->keyboard, signals[KEY_PRESSED], 0, key->index);
    	} else if (key->keyboard->hold == 1 && key->hold == 1) key->hold = 0;
        break;
    case GDK_BUTTON_RELEASE:
    	if((key->keyboard->hold == 1 && key->hold == 0) || key->keyboard->hold == 0){
        	gnome_canvas_item_hide(key->on);
        	gnome_canvas_item_hide(key->shad);
        	g_signal_emit(key->keyboard, signals[KEY_RELEASED], 0, key->index);
    	}
        break;
    case GDK_ENTER_NOTIFY:
        gnome_canvas_item_show(key->pre);
        break;
    case GDK_LEAVE_NOTIFY:
        gnome_canvas_item_hide(key->pre);
        break;
    default:
        break;
    }
    
    return FALSE;
}
Esempio n. 2
0
void
ghack_map_print_glyph(GtkObject *win, guint x, guint y, GdkImlibImage *im,
                      gpointer data)
{
    GnomeCanvasGroup *group;
    int i = y * COLNO + x;
    int glyph = glyph_at(x, y);
    GnomeCanvasImage *canvas_image = GNOME_CANVAS_IMAGE(ghack_map.map[i]);

    group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas));

    gnome_canvas_item_set(GNOME_CANVAS_ITEM(canvas_image), "image", im, NULL);
    gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image));

    canvas_image = GNOME_CANVAS_IMAGE(ghack_map.overlay[i]);

    if (x == u.ux && y == u.uy)
        ghack_map_cliparound(NULL, x, y, NULL);

    if (glyph_is_pet(glyph)
#ifdef TEXTCOLOR
            && iflags.hilite_pet
#endif
       ) {
        gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(canvas_image));
        gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image));
    } else {
        gnome_canvas_item_hide(GNOME_CANVAS_ITEM(canvas_image));
    }
}
Esempio n. 3
0
gboolean phat_keyboard_key_press(PhatKeyboard* keyboard, gint key)
{
	if((keyboard->hold == 1 && keyboard->keys[key].hold == 0) || keyboard->hold == 0){
		gnome_canvas_item_show(keyboard->keys[key].on);
		gnome_canvas_item_show(keyboard->keys[key].shad);
		keyboard->keys[key].hold = 1;
		g_signal_emit(keyboard, signals[KEY_PRESSED], 0, keyboard->keys[key].index);
	} else if (keyboard->hold == 1 && keyboard->keys[key].hold == 1) keyboard->keys[key].hold = 0;
	
    return TRUE;
}
Esempio n. 4
0
static void
selection_changed(WireItem *item, gboolean select, gpointer user_data)
{
	g_object_ref(G_OBJECT(item));
	if (select) {
		gtk_idle_add ((gpointer) select_idle_callback, item);
		gnome_canvas_item_show (GNOME_CANVAS_ITEM (item->priv->resize1));
		gnome_canvas_item_show (GNOME_CANVAS_ITEM (item->priv->resize2));
	} else {
		gtk_idle_add ((gpointer) deselect_idle_callback, item);
		gnome_canvas_item_hide (GNOME_CANVAS_ITEM (item->priv->resize1));
		gnome_canvas_item_hide (GNOME_CANVAS_ITEM (item->priv->resize2));
	}
}
Esempio n. 5
0
void
ghack_map_cursor_to(GtkWidget *win, int x, int y, gpointer data)
{
    GnomeCanvasGroup *group;
    static GnomeCanvasRE *cursor = NULL;

    double x1, y1, x2, y2;
    float hp;
    guint r, g, b;

    x1 = x * ghack_glyph_width() - 1;
    y1 = y * ghack_glyph_height() - 1;
    x2 = x1 + ghack_glyph_width() + 2;
    y2 = y1 + ghack_glyph_height() + 2;
    hp = u.mtimedone ? (u.mhmax ? (float) u.mh / u.mhmax : 1)
         : (u.uhpmax ? (float) u.uhp / u.uhpmax : 1);

    r = 255;
    g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255 * 2 * (hp - 0.25) : 0);
    b = (hp >= 0.75) ? 255 * 4 * (hp - 0.75)
        : (hp >= 0.25 ? 0 : 255 * 4 * (0.25 - hp));

    group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas));

    if (!cursor) {
        cursor = GNOME_CANVAS_RE(gnome_canvas_item_new(
                                     group, gnome_canvas_rect_get_type(), "width_units", 1.0, NULL));
    }
    gnome_canvas_item_set(GNOME_CANVAS_ITEM(cursor), "outline_color_rgba",
                          GNOME_CANVAS_COLOR(r, g, b), "x1", x1, "y1", y1,
                          "x2", x2, "y2", y2, NULL);

    gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(cursor));
    gnome_canvas_item_show(GNOME_CANVAS_ITEM(cursor));
}
Esempio n. 6
0
static int itemShow( Tcl_Interp *interp, int objc, Tcl_Obj * const objv[], 
      CanvasParams *param, GPtrArray *items )
{
   guint k;
   int   on = 1;

   if( objc > 4 )
   {
      Tcl_WrongNumArgs( interp, 3, objv, "?on?" );
      return TCL_ERROR;
   }
   if( objc == 4 )
   {
      if( Tcl_GetBooleanFromObj( interp, objv[3], &on ) != TCL_OK )
         return TCL_ERROR;
   }

   if( items != NULL )
   {
      for( k = 0; k < items->len; ++k )
      {
         Gnocl_CanvasItemInfo *info = GET_INFO( items, k );
         if( on )
            gnome_canvas_item_show( info->item );
         else
            gnome_canvas_item_hide( info->item );
      }
   }

   return TCL_OK;
}
Esempio n. 7
0
static void
relation_arrow_predecessor_visibility_changed (PlannerGanttRow      *row,
					       gboolean              visible,
					       PlannerRelationArrow *arrow)
{
	arrow->priv->predecessor_visible = visible;

	if (!visible) {
		gnome_canvas_item_hide (GNOME_CANVAS_ITEM (arrow));
	} else if (arrow->priv->successor_visible) {
		gnome_canvas_item_show (GNOME_CANVAS_ITEM (arrow));
	}
}
Esempio n. 8
0
/* given the src and dst node centers, plus a size, draws a triangle in the 
 * specified color on the provided canvas item*/
static void draw_oneside_link(double xs, double ys, double xd, double yd,
                              const basic_stats_t *link_stats, 
                              guint32 scaledColor, GnomeCanvasItem *item)
{
  GnomeCanvasPoints *points;
  gdouble versorx, versory, modulus, link_size;

  link_size = get_link_size(link_stats) / 2;

  /* limit the maximum size to avoid overload */
  if (link_size > MAX_LINK_SIZE)
    link_size = MAX_LINK_SIZE; 

  versorx = -(yd - ys);
  versory = xd - xs;
  modulus = sqrt (pow (versorx, 2) + pow (versory, 2));
  if (modulus == 0)
    {
      link_size = 0;
      modulus = 1;
    }

  points = gnome_canvas_points_new (3);
  points->coords[0] = xd;
  points->coords[1] = yd;
  points->coords[2] = xs + versorx * link_size / modulus;
  points->coords[3] = ys + versory * link_size / modulus;
  points->coords[4] = xs - versorx * link_size / modulus;
  points->coords[5] = ys - versory * link_size / modulus;

  gnome_canvas_item_set (item, 
                          "points", points,
                          "fill_color_rgba", scaledColor, NULL);

  /* If we got this far, the link can be shown. Make sure it is */
  gnome_canvas_item_show (item);
  gnome_canvas_points_unref (points);
}
Esempio n. 9
0
void midi_section_set_patch(MidiSection* self, int patch)
{
    MidiSectionPrivate* p = MIDI_SECTION_GET_PRIVATE(self);
    int note;
    int lower;
    int upper;

    p->patch = patch;

    if (patch < 0)
    {
        set_sensitive(p, FALSE);
        gnome_canvas_item_hide(p->note);
        gnome_canvas_item_hide(p->range);

        if (p->ignore)
            p->ignore = FALSE;
        else
            gtk_adjustment_set_value(p->adj,
                (0.5 * gtk_adjustment_get_upper(p->adj)
                    - gtk_adjustment_get_page_size(p->adj) / 2));
    }
    else
    {

        set_sensitive(p, TRUE);

        note =  patch_get_root_note(patch);
        lower = patch_get_lower_note(patch);
        upper = patch_get_upper_note(patch);

        block(p);

        gnome_canvas_item_set(p->note, "x1",
                (gdouble)(note * PHIN_KEYBOARD_KEY_WIDTH - 1), NULL);
        gnome_canvas_item_set(p->note, "x2",
                (gdouble)(note * PHIN_KEYBOARD_KEY_WIDTH
                               + PHIN_KEYBOARD_KEY_WIDTH - 1), NULL);
        gnome_canvas_item_show(p->note);

        gnome_canvas_item_set(p->range, "x1",
                (gdouble) (lower * PHIN_KEYBOARD_KEY_WIDTH - 1), NULL);
        gnome_canvas_item_set(p->range, "x2",
                (gdouble) (upper * PHIN_KEYBOARD_KEY_WIDTH
                                 + PHIN_KEYBOARD_KEY_WIDTH - 1), NULL);
        if (lower != upper)
            gnome_canvas_item_show(p->range);
        else
            gnome_canvas_item_hide(p->range);

        /* scroll the keyboard to show the root note */
        if (p->ignore)
            p->ignore = FALSE;
        else
            gtk_adjustment_set_value(p->adj,
                ((note + 1.0) / MIDI_NOTES)
                    * gtk_adjustment_get_upper(p->adj)
                    - gtk_adjustment_get_page_size(p->adj) / 2);

        unblock(p);
    }
}
Esempio n. 10
0
static gboolean range_cb(GnomeCanvasItem* item, GdkEvent* event,
                                                MidiSectionPrivate* p)
{
    (void)item;
    int clicked;
    int note;
    int lower;
    int upper;
    gboolean change_range = FALSE;
    PatchList* list;

    /* a ghetto form of set-insensitive */
    if (p->patch < 0)
        return FALSE;

    if (event->type != GDK_BUTTON_PRESS)
        return FALSE;

    list = gui_get_patch_list();

    clicked = event->button.x / PHIN_KEYBOARD_KEY_WIDTH;
    note =  patch_get_root_note(p->patch);
    lower = patch_get_lower_note(p->patch);
    upper = patch_get_upper_note(p->patch);

    /* process the click */
    if (event->button.button == 1)
    {
        lower = clicked;
        change_range = TRUE;
    }
    else if (event->button.button == 2)
    {
        note = clicked;
    }
    else if (event->button.button == 3)
    {
        upper = clicked;
        change_range = TRUE;
    }

    /* clamp the parameters */
    if (note < lower)
        lower = note;

    if (note > upper)
        upper = note;

    /* if the range is off, and a range adjusting button wasn't
     * pressed, then clamp the range down to nothing (which will
     * result in it remaining disabled) */
    if (!change_range && lower == upper)
        lower = upper = note;

    /* reposition note */
    gnome_canvas_item_set(p->note, "x1",
                    (gdouble)(note * PHIN_KEYBOARD_KEY_WIDTH - 1),  NULL);
    gnome_canvas_item_set(p->note, "x2",
                    (gdouble) (note * PHIN_KEYBOARD_KEY_WIDTH
                                    + PHIN_KEYBOARD_KEY_WIDTH - 1), NULL);

    /* reposition range */
    gnome_canvas_item_set(p->range, "x1",
                    (gdouble)(lower * PHIN_KEYBOARD_KEY_WIDTH - 1), NULL);
    gnome_canvas_item_set(p->range, "x2",
                    (gdouble)(upper * PHIN_KEYBOARD_KEY_WIDTH
                                    + PHIN_KEYBOARD_KEY_WIDTH - 1), NULL);

    /* apply changes */
    patch_set_root_note(p->patch, note);
    patch_set_lower_note(p->patch, lower);
    patch_set_upper_note(p->patch, upper);

    if (lower == upper)
        gnome_canvas_item_hide(p->range);
    else
        gnome_canvas_item_show(p->range);

    /* we might have moved this patch around relative to the list;
     * update the list and try to keep this patch selected */
    p->ignore = TRUE;
    patch_list_update(list, patch_list_get_current_patch(list),
                                                        PATCH_LIST_PATCH);

    return FALSE;
}
Esempio n. 11
0
/* TODO I think I should update all links as well, so as not having
 * stale graphics if the diagram has been resized */
static gint
reposition_canvas_nodes (guint8 * ether_addr, canvas_node_t * canvas_node,
			 GtkWidget * canvas)
{
  static gfloat angle = 0.0;
  static guint node_i = 0, n_nodes = 0;
  gdouble x = 0, y = 0, xmin, ymin, xmax, ymax, text_compensation = 50;
  gdouble x_rad_max, y_rad_max;
  gdouble oddAngle = angle;

  if (!canvas_node->shown)
    {
      gnome_canvas_item_hide (canvas_node->node_item);
      gnome_canvas_item_hide (canvas_node->text_item);
      return FALSE;
    }

  gnome_canvas_get_scroll_region (GNOME_CANVAS (canvas),
				  &xmin, &ymin, &xmax, &ymax);
  if (!n_nodes)
      n_nodes = node_i = displayed_nodes;

  xmin += text_compensation;
  xmax -= text_compensation;	/* Reduce the drawable area so that
				 * the node name is not lost
				 * TODO: Need a function to calculate
				 * text_compensation depending on font size */
  x_rad_max = 0.9 * (xmax - xmin) / 2;
  y_rad_max = 0.9 * (ymax - ymin) / 2;

  /* TODO I've done all the stationary changes in a hurry
   * I should review it an tidy up all this stuff */
  if (pref.stationary)
    {
      if (canvas_node->is_new)
	{
	  static guint count = 0, base = 1;
	  gdouble angle = 0;

	  if (count == 0)
	    {
	      angle = M_PI * 2.0f;
	      count++;
	    }
	  else
	    {

	      if (count > 2 * base)
		{
		  base *= 2;
		  count = 1;
		}
	      angle = M_PI * (gdouble) count / ((gdouble) base);
	      count += 2;
	    }
	  x = x_rad_max * cos (angle);
	  y = y_rad_max * sin (angle);
	}

    }
  else
    {

      if (n_nodes % 2 == 0)	/* spacing is better when n_nodes is odd and Y is linear */
	oddAngle = (angle * n_nodes) / (n_nodes + 1);
      if (n_nodes > 7)
	{
	  x = x_rad_max * cos (oddAngle);
	  y = y_rad_max * asin (sin (oddAngle)) / (M_PI / 2);
	}
      else
	{
	  x = x_rad_max * cos (angle);
	  y = y_rad_max * sin (angle);
	}
    }

  if (!pref.stationary || canvas_node->is_new)
    {
      gnome_canvas_item_set (GNOME_CANVAS_ITEM (canvas_node->group_item),
			     "x", x, "y", y, NULL);
      canvas_node->is_new = FALSE;
    }

  if (need_font_refresh)
    {
      /* We update the text font */
      gnome_canvas_item_set (canvas_node->text_item, 
                             "font", pref.fontname, 
                             "fill_color", pref.text_color, 
                             NULL);
    }
  
  if (pref.diagram_only)
    {
      gnome_canvas_item_hide (canvas_node->text_item);
    }
  else
    {
      gnome_canvas_item_show (canvas_node->text_item);
      gnome_canvas_item_request_update (canvas_node->text_item);
    }

  gnome_canvas_item_show (canvas_node->node_item);
  gnome_canvas_item_request_update (canvas_node->node_item);

  node_i--;

  if (node_i)
    angle += 2 * M_PI / n_nodes;
  else
    {
      angle = 0.0;
      n_nodes = 0;
    }

  return FALSE;
}				/* reposition_canvas_nodes */