Ejemplo 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;
}
Ejemplo n.º 2
0
gboolean phat_keyboard_key_release(PhatKeyboard* keyboard, gint key)
{
	if((keyboard->hold == 1 && keyboard->keys[key].hold == 0) || keyboard->hold == 0){
		gnome_canvas_item_hide(keyboard->keys[key].on);
		gnome_canvas_item_hide(keyboard->keys[key].shad);
		keyboard->keys[key].hold = 0;
		g_signal_emit(keyboard, signals[KEY_RELEASED], 0, keyboard->keys[key].index);
	}

    return TRUE;
}
Ejemplo n.º 3
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));
	}
}
Ejemplo n.º 4
0
void
ghack_map_clear(GtkWidget *win, gpointer data)
{
    int i;

    for (i = 0; i < ROWNO * COLNO; i++) {
        if (GNOME_IS_CANVAS_IMAGE(ghack_map.map[i])) {
            gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.map[i]));
        }
        if (GNOME_IS_CANVAS_IMAGE(ghack_map.overlay[i])) {
            gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.overlay[i]));
        }
    }
    gnome_canvas_update_now(GNOME_CANVAS(ghack_map.canvas));
}
Ejemplo n.º 5
0
/* Hide the userlist if there are no users displayed */
void
greeter_item_ulist_check_show_userlist (void)
{
	/*
	 * If there are no users,
	 * then hide the rectangle used to contain the userlist.  The
	 * userlist-rect id allows a rectangle to be defined with alpha
	 * behind the userlist that also goes away when the list is empty.
	 */
	if (num_users == 0) {

		GreeterItemInfo *urinfo = greeter_lookup_id ("userlist-rect");

		if (user_list != NULL)
			gtk_widget_hide (user_list);

		if (urinfo) {
			GnomeCanvasItem *item;

			if (urinfo->group_item != NULL)
				item = GNOME_CANVAS_ITEM (urinfo->group_item);
			else
				item = urinfo->item;

			gnome_canvas_item_hide (item);
		}
	}
}
Ejemplo n.º 6
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));
    }
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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));
	}
}
Ejemplo 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);
    }
}
Ejemplo n.º 10
0
static void midi_section_init(MidiSection* self)
{
    MidiSectionPrivate* p = MIDI_SECTION_GET_PRIVATE(self);
    GtkBox* box = GTK_BOX(self);
    GtkWidget* pad;
    GtkWidget* view;
    GtkWidget* scroll;
    GnomeCanvas* canvas;
    GnomeCanvasPoints* points;
    int x1, x2, y1, y2;

    p->patch = -1;
    p->ignore = FALSE;
    x1 = 0;
    y1 = 0;
    x2 = (PHIN_KEYBOARD_KEY_WIDTH * MIDI_NOTES);
    y2 = HEIGHT;

    /* adjustment */
    p->adj = (GtkAdjustment*) gtk_adjustment_new(0, 0, 0, 0, 0, 0);

    /* viewport */
    view = gtk_viewport_new(p->adj, NULL);
    gtk_box_pack_start(box, view, FALSE, FALSE, 0);
    gtk_viewport_set_shadow_type(GTK_VIEWPORT(view), GTK_SHADOW_NONE);
    gtk_widget_set_size_request(view, 0, y2);
    gtk_widget_show(view);

    /* canvas */
    canvas = (GnomeCanvas*) gnome_canvas_new();
    gtk_widget_set_size_request(GTK_WIDGET(canvas), x2,	y2);
    gnome_canvas_set_scroll_region(canvas, 0, 0, x2 - 1, y2 -1);
    gtk_container_add(GTK_CONTAINER(view), GTK_WIDGET(canvas));
    g_signal_connect(G_OBJECT(canvas), "event",
		     G_CALLBACK(range_cb), (gpointer)p);
    gtk_widget_show(GTK_WIDGET(canvas));

    /* range display backdrop */
    gnome_canvas_item_new(gnome_canvas_root(canvas),
			  gnome_canvas_rect_get_type(),
			  "x1", (gdouble)0,
			  "y1", (gdouble)0,
			  "x2", (gdouble)x2,
			  "y2", (gdouble)y2,
			  "fill-color-rgba", BG_COLOR,
			  NULL);
    /* range */
    p->range = gnome_canvas_item_new(gnome_canvas_root(canvas),
					gnome_canvas_rect_get_type(),
					"x1", (gdouble)x1,
					"y1", (gdouble)y1,
					"x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH,
					"y2", (gdouble)y2,
					"fill-color-rgba", RANGE_COLOR,
					"outline-color", "black",
					NULL);
    gnome_canvas_item_hide(p->range);
    
    /* range root note */
    p->note = gnome_canvas_item_new(gnome_canvas_root(canvas),
				       gnome_canvas_rect_get_type(),
				       "x1", (gdouble)x1,
				       "y1", (gdouble)y1,
				       "x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH,
				       "y2", (gdouble)y2,
				       "fill-color-rgba", NOTE_COLOR,
				       "outline-color", "black",
				       NULL);
    gnome_canvas_item_hide(p->note);

    p->canvas = canvas;

    /* range display border */
    points = gnome_canvas_points_new(4);

    points->coords[0] = x1;
    points->coords[1] = y2;
    points->coords[2] = x1;
    points->coords[3] = y1;
    points->coords[4] = x2-1;
    points->coords[5] = y1;
    points->coords[6] = x2-1;
    points->coords[7] = y2;

    gnome_canvas_item_new(gnome_canvas_root(canvas),
			  gnome_canvas_line_get_type(),
			  "points", points,
			  "width-units", (gdouble)1,
			  "fill-color-rgba", 0,
			  NULL);
    gnome_canvas_points_unref(points);


    /* keyboard */
    p->keyboard = phin_hkeyboard_new(p->adj, MIDI_NOTES, TRUE);
    gtk_box_pack_start(box, p->keyboard, FALSE, FALSE, 0);
    gtk_widget_show(p->keyboard);

    /* vpad */
    pad = gui_vpad_new(GUI_SCROLLSPACE);
    gtk_box_pack_start(box, pad, FALSE, FALSE, 0);
    gtk_widget_show(pad);

    /* scrollbar */
    scroll = gtk_hscrollbar_new(p->adj);
    gtk_box_pack_start(box, scroll, FALSE, FALSE, 0);
    gtk_widget_show(scroll);

    /* done */
    connect(p);
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
WireItem *
wire_item_new (Sheet *sheet, Wire *wire)
{
	WireItem *item;
	GnomeCanvasPoints *points;
	WireItemPriv *priv;
	SheetPos start_pos, length;

	g_return_val_if_fail (sheet != NULL, NULL);
	g_return_val_if_fail (IS_SHEET (sheet), NULL);

	//g_object_ref (G_OBJECT(wire));
	/* XXX Ver si hay equivalente gtk_object_sink (GTK_OBJECT (wire)); */

	wire_get_pos_and_length (wire, &start_pos, &length);

	/*
	 * Because of the GnomeCanvasGroup inheritance, a small hack is needed
	 * here. The group starts at the startpoint of the wire, and the line
	 * goes from (0,0) to (length.x, length.y).
	 */
	item = WIRE_ITEM (gnome_canvas_item_new (
		sheet->object_group,
		wire_item_get_type (),
		"data", wire,
		"x", (double) start_pos.x,
		"y", (double) start_pos.y,
		NULL));

	priv = item->priv;

	priv->resize1 = GNOME_CANVAS_RECT (gnome_canvas_item_new (
		GNOME_CANVAS_GROUP (item),
		gnome_canvas_rect_get_type (),
		"x1", -RESIZER_SIZE,
		"y1", -RESIZER_SIZE,
		"x2", RESIZER_SIZE,
		"y2", RESIZER_SIZE,
		"fill_color", "red",
		"fill_color_rgba", 0x3cb37180,
		"outline_color", "blue",
		"width_pixels", 1,
		NULL));

	priv->resize2 = GNOME_CANVAS_RECT (gnome_canvas_item_new (
		GNOME_CANVAS_GROUP (item),
		gnome_canvas_rect_get_type (),
		"x1", length.x-RESIZER_SIZE,
		"y1", length.y-RESIZER_SIZE,
		"x2", length.x+RESIZER_SIZE,
		"y2", length.y+RESIZER_SIZE,
		"fill_color", "red",
		"fill_color_rgba", 0x3cb37180,
		"outline_color", "blue",
		"width_pixels", 1,
		NULL));
	gnome_canvas_item_hide (GNOME_CANVAS_ITEM (priv->resize1));
	gnome_canvas_item_hide (GNOME_CANVAS_ITEM (priv->resize2));

	points = gnome_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	priv->line = GNOME_CANVAS_LINE (gnome_canvas_item_new (
		GNOME_CANVAS_GROUP (item),
		gnome_canvas_line_get_type (),
		"points", points,
		"fill_color", "blue",
		"width_pixels", 1,
		NULL));

	gnome_canvas_points_free (points);

	g_signal_connect_object(G_OBJECT(wire),	"rotated",
		G_CALLBACK(wire_rotated_callback), G_OBJECT(item), 0);
	g_signal_connect_object(G_OBJECT(wire), "flipped",
		G_CALLBACK(wire_flipped_callback), G_OBJECT(item), 0);
	g_signal_connect_object(G_OBJECT(wire), "moved",
		G_CALLBACK(wire_moved_callback),  G_OBJECT(item), 0);

	g_signal_connect (G_OBJECT (wire), "changed", G_CALLBACK (wire_changed_callback), item);
	g_signal_connect (G_OBJECT (wire), "delete", G_CALLBACK (wire_delete_callback), item);
	wire_update_bbox (wire);

	return item;
}
Ejemplo n.º 13
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 */
Ejemplo n.º 14
0
/* Checks if there is a canvas_node per each node. If not, one canvas_node
 * must be created and initiated */
static gint
check_new_node (node_t * node, GtkWidget * canvas)
{
  canvas_node_t *new_canvas_node;
  GnomeCanvasGroup *group;

  if (!node)
    return FALSE;

  if (display_node (node) && !g_tree_lookup (canvas_nodes, &node->node_id))
    {
      new_canvas_node = g_malloc (sizeof (canvas_node_t));
      g_assert(new_canvas_node);
      
      new_canvas_node->canvas_node_id = node->node_id;

      /* Create a new group to hold the node and its labels */
      group = gnome_canvas_root (GNOME_CANVAS (canvas));
      group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (group,
							 GNOME_TYPE_CANVAS_GROUP,
							 "x", 100.0, 
                                                         "y", 100.0, NULL));
      addref_canvas_obj(G_OBJECT (group));
      new_canvas_node->group_item = group;

      new_canvas_node->node_item
	= gnome_canvas_item_new (group,
				 GNOME_TYPE_CANVAS_ELLIPSE,
				 "x1", 0.0,
				 "x2", 0.0,
				 "y1", 0.0,
				 "y2", 0.0,
				 "fill_color", "white",
				 "outline_color", "black",
				 "width_pixels", 0, NULL);
      addref_canvas_obj(G_OBJECT (new_canvas_node->node_item));

      new_canvas_node->text_item =
	gnome_canvas_item_new (group, GNOME_TYPE_CANVAS_TEXT,
			       "text", node->name->str,
			       "x", 0.0,
			       "y", 0.0,
			       "anchor", GTK_ANCHOR_CENTER,
			       "font", pref.fontname,
			       "fill_color", pref.text_color, NULL);
      addref_canvas_obj(G_OBJECT (new_canvas_node->text_item));

      gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM
				      (new_canvas_node->text_item));
      g_signal_connect (G_OBJECT (new_canvas_node->group_item), "event",
			(GtkSignalFunc) node_item_event, new_canvas_node);

      if (!new_canvas_node->node_item || !new_canvas_node->text_item)
        g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, _("Canvas node null"));
      
      /*
       * We hide them until we are sure that they will get a proper position
       * in reposition_nodes
       */
      gnome_canvas_item_hide (new_canvas_node->node_item);
      gnome_canvas_item_hide (new_canvas_node->text_item);

      new_canvas_node->is_new = TRUE;
      new_canvas_node->shown = TRUE;

      g_tree_insert (canvas_nodes,
		     &new_canvas_node->canvas_node_id, new_canvas_node);
      g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
	     _("Creating canvas_node: %s. Number of nodes %d"),
	     node->name->str, g_tree_nnodes (canvas_nodes));

      need_reposition = TRUE;
    }

  return FALSE;			/* False to keep on traversing */
}				/* check_new_node */
Ejemplo n.º 15
0
/* - calls update_links, so that the related link updates its average
 *   traffic and main protocol, and old links are deleted
 * - caculates link size and color fading */
static gint
canvas_link_update(link_id_t * link_id, canvas_link_t * canvas_link,
		     GList **delete_list)
{
  const link_t *link;
  const canvas_node_t *canvas_dst;
  const canvas_node_t *canvas_src;
  guint32 scaledColor;
  double xs, ys, xd, yd, scale;

  /* We used to run update_link here, but that was a major performance penalty, 
   * and now it is done in update_diagram */
  link = links_catalog_find(link_id);
  if (!link)
    {
      *delete_list = g_list_prepend( *delete_list, link_id);
      g_my_debug ("Queing canvas link to remove.");
      return FALSE;
    }

  /* If either source or destination has disappeared, we hide the link
   * until it can be show again */

  /* We get coords for the destination node */
  canvas_dst = g_tree_lookup (canvas_nodes, &link_id->dst);
  if (!canvas_dst || !canvas_dst->shown)
    {
      gnome_canvas_item_hide (canvas_link->src_item);
      gnome_canvas_item_hide (canvas_link->dst_item);
      return FALSE;
    }

  /* We get coords from source node */
  canvas_src = g_tree_lookup (canvas_nodes, &link_id->src);
  if (!canvas_src || !canvas_src->shown)
    {
      gnome_canvas_item_hide (canvas_link->src_item);
      gnome_canvas_item_hide (canvas_link->dst_item);
      return FALSE;
    }

  /* What if there never is a protocol?
   * I have to initialize canvas_link->color to a known value */
  if (link->main_prot[pref.stack_level])
    {
      double diffms;
      canvas_link->color = protohash_color(link->main_prot[pref.stack_level]);

      /* scale color down to 10% at link timeout */
      diffms = substract_times_ms(&appdata.now, &link->link_stats.stats.last_time);
      scale = pow(0.10, diffms / pref.gui_link_timeout_time);

      scaledColor =
        (((int) (scale * canvas_link->color.red) & 0xFF00) << 16) |
        (((int) (scale * canvas_link->color.green) & 0xFF00) << 8) |
        ((int) (scale * canvas_link->color.blue) & 0xFF00) | 0xFF;
    }
  else
    {
      guint32 black = 0x000000ff;
      scaledColor = black;
    }

  /* retrieve coordinates of node centers */
  g_object_get (G_OBJECT (canvas_src->group_item), "x", &xs, "y", &ys, NULL);
  g_object_get (G_OBJECT (canvas_dst->group_item), "x", &xd, "y", &yd, NULL);

  /* first draw triangle for src->dst */
  draw_oneside_link(xs, ys, xd, yd, &(link->link_stats.stats_out), scaledColor, 
                    canvas_link->src_item);

  /* then draw triangle for dst->src */
  draw_oneside_link(xd, yd, xs, ys, &(link->link_stats.stats_in), scaledColor, 
                    canvas_link->dst_item);

  return FALSE;

}				/* update_canvas_links */
Ejemplo n.º 16
0
/* 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);
    }
}