static void draw_ping_graph (Netinfo *netinfo) { cairo_t *cr; GtkStyle *style; GtkWidget *widget; PangoLayout *layout; gint ntodisplay = 5; gint rangemin, rangemax; PingGraphBarData *bar_data; gdouble max; gint width, height; gint font_height, offset; gint bar_height, separator_height; gdouble scale_factor; gint line1h, line2h; gint index; gint step, x, h; gchar *tmpstr; widget = netinfo->graph; cr = gdk_cairo_create (gtk_widget_get_window(widget)); style = gtk_widget_get_style(widget); rangemax = packets_transmitted; rangemin = MAX (0, rangemax - ntodisplay); bar_data = g_newa (PingGraphBarData, ntodisplay); max = get_bar_data (netinfo, bar_data, ntodisplay, rangemin, rangemax); /* Created up here so we can get the geometry info. */ layout = gtk_widget_create_pango_layout (widget, _("Time (ms):")); /* We guess that the first label is representative. */ pango_layout_get_pixel_size (layout, NULL, &font_height); width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); offset = 0.05*height; bar_height = height - 2.5*font_height - offset; scale_factor = bar_height / max; separator_height = bar_height + offset; line1h = bar_height + 0.125*font_height + offset; line2h = bar_height + 1.25*font_height + offset; gtk_paint_box (style, cr, GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_IN, widget, NULL, 0, 0, width, height); gtk_paint_layout (style, cr, GTK_STATE_NORMAL, TRUE, widget, NULL, 0.02*width, line1h, layout); g_object_unref (layout); layout = gtk_widget_create_pango_layout (widget, _("Seq. No.:")); gtk_paint_layout (style, cr, GTK_STATE_NORMAL, TRUE, widget, NULL, 0.02*width, line2h, layout); g_object_unref (layout); gtk_paint_hline (style, cr, GTK_STATE_NORMAL, widget, NULL, 0.02*width, 0.98*width, separator_height); index = 0; step = width / (ntodisplay + 1.0); for (x = 1.5*step; x < width; x += step) { if (bar_data[index].valid) { h = scale_factor*bar_data[index].value; gtk_paint_flat_box (style, cr, GTK_STATE_SELECTED, GTK_SHADOW_ETCHED_IN, widget, NULL, x - 0.4*step, offset + bar_height - h, 0.8*step, h); tmpstr = g_strdup_printf ("%.2f", bar_data[index].value); } else { tmpstr = g_strdup ("-"); } draw_centered_text (widget, cr, x, line1h, tmpstr); g_free (tmpstr); if (index + rangemin + 1 <= rangemax) { tmpstr = g_strdup_printf ("%d", index + rangemin + 1); } else { tmpstr = g_strdup ("-"); } draw_centered_text (widget, cr, x, line2h, tmpstr); g_free (tmpstr); index++; } cairo_destroy (cr); }
static void gtk_tearoff_menu_item_paint (GtkWidget *widget, GdkRectangle *area) { GtkMenuItem *menu_item; GtkShadowType shadow_type; gint width, height; gint x, y; gint right_max; GtkArrowType arrow_type; GtkTextDirection direction; if (GTK_WIDGET_DRAWABLE (widget)) { menu_item = GTK_MENU_ITEM (widget); direction = gtk_widget_get_direction (widget); x = widget->allocation.x + GTK_CONTAINER (menu_item)->border_width; y = widget->allocation.y + GTK_CONTAINER (menu_item)->border_width; width = widget->allocation.width - GTK_CONTAINER (menu_item)->border_width * 2; height = widget->allocation.height - GTK_CONTAINER (menu_item)->border_width * 2; right_max = x + width; if (widget->state == GTK_STATE_PRELIGHT) { gint selected_shadow_type; gtk_widget_style_get (widget, "selected-shadow-type", &selected_shadow_type, NULL); gtk_paint_box (widget->style, widget->window, GTK_STATE_PRELIGHT, selected_shadow_type, area, widget, "menuitem", x, y, width, height); } else gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height); if (GTK_IS_MENU (widget->parent) && GTK_MENU (widget->parent)->torn_off) { gint arrow_x; if (widget->state == GTK_STATE_PRELIGHT) shadow_type = GTK_SHADOW_IN; else shadow_type = GTK_SHADOW_OUT; if (menu_item->toggle_size > ARROW_SIZE) { if (direction == GTK_TEXT_DIR_LTR) { arrow_x = x + (menu_item->toggle_size - ARROW_SIZE)/2; arrow_type = GTK_ARROW_LEFT; } else { arrow_x = x + width - menu_item->toggle_size + (menu_item->toggle_size - ARROW_SIZE)/2; arrow_type = GTK_ARROW_RIGHT; } x += menu_item->toggle_size + BORDER_SPACING; } else { if (direction == GTK_TEXT_DIR_LTR) { arrow_x = ARROW_SIZE / 2; arrow_type = GTK_ARROW_LEFT; } else { arrow_x = x + width - 2 * ARROW_SIZE + ARROW_SIZE / 2; arrow_type = GTK_ARROW_RIGHT; } x += 2 * ARROW_SIZE; } gtk_paint_arrow (widget->style, widget->window, widget->state, shadow_type, NULL, widget, "tearoffmenuitem", arrow_type, FALSE, arrow_x, y + height / 2 - 5, ARROW_SIZE, ARROW_SIZE); } while (x < right_max) { gint x1, x2; if (direction == GTK_TEXT_DIR_LTR) { x1 = x; x2 = MIN (x + TEAR_LENGTH, right_max); } else { x1 = right_max - x; x2 = MAX (right_max - x - TEAR_LENGTH, 0); } gtk_paint_hline (widget->style, widget->window, GTK_STATE_NORMAL, NULL, widget, "tearoffmenuitem", x1, x2, y + (height - widget->style->ythickness) / 2); x += 2 * TEAR_LENGTH; } } }
static void run_functions (Test *test) { GtkStyle *style = window->style; GdkWindow *mywindow = window->window; if (widgets[test->widget]) { style = widgets[test->widget]->style; mywindow = widgets[test->widget]->window; } if (test->function & FUNCTION_ARROW) gtk_paint_arrow (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, test->arrow_type, test->fill, 0, 0, 10, 10); if (test->function & FUNCTION_BOX) gtk_paint_box (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10); if (test->function & FUNCTION_SHADOW) gtk_paint_shadow (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10); if (test->function & FUNCTION_BOX_GAP) gtk_paint_box_gap (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10, test->gap_side, 0, 100); if (test->function & FUNCTION_SHADOW_GAP) gtk_paint_shadow_gap (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10, test->gap_side, 0, 100); if (test->function & FUNCTION_CHECK) gtk_paint_check (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10); if (test->function & FUNCTION_EXPANDER) gtk_paint_expander (style, mywindow, test->state, NULL, widgets[test->widget], test->detail, 10, 10, test->expander_style); if (test->function & FUNCTION_EXTENSION) gtk_paint_extension (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10, test->gap_side); if (test->function & FUNCTION_FLAT_BOX) gtk_paint_flat_box (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10); if (test->function & FUNCTION_FOCUS) gtk_paint_focus (style, mywindow, test->state, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10); if (test->function & FUNCTION_HANDLE) gtk_paint_handle (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10, test->orientation); if (test->function & FUNCTION_OPTION) gtk_paint_option (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10); if (test->function & FUNCTION_RESIZE_GRIP) gtk_paint_resize_grip (style, mywindow, test->state, NULL, widgets[test->widget], test->detail, test->edge, 0, 0, 10, 10); if (test->function & FUNCTION_SLIDER) gtk_paint_slider (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10, test->orientation); if (test->function & FUNCTION_TAB) gtk_paint_tab (style, mywindow, test->state, test->shadow, NULL, widgets[test->widget], test->detail, 0, 0, 10, 10); if (test->function & FUNCTION_HLINE) gtk_paint_hline (style, mywindow, test->state, NULL, widgets[test->widget], test->detail, 1, 10, 4); if (test->function & FUNCTION_VLINE) gtk_paint_vline (style, mywindow, test->state, NULL, widgets[test->widget], test->detail, 1, 10, 4); }
/* TODO remove redundant code */ static void i7_cell_renderer_transcript_render(GtkCellRenderer *self, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { I7_CELL_RENDERER_TRANSCRIPT_USE_PRIVATE; int x, y, width, height; unsigned xpad, ypad, transcript_width; GtkStateType state; cairo_t *cr; PangoRectangle command_rect; PangoLayout *layout; GtkStyle *style = gtk_widget_get_style(widget); /* Get the size we calculated earlier and then take the padding into account */ g_object_get(self, "xpad", &xpad, "ypad", &ypad, NULL); gtk_cell_renderer_get_size(self, widget, cell_area, &x, &y, &width, &height); x += cell_area->x + (int)xpad; y += cell_area->y + (int)ypad; width -= (int)xpad * 2; height -= (int)ypad * 2; /* Decide what state to draw the widget components in */ switch(flags) { case GTK_CELL_RENDERER_PRELIT: state = GTK_STATE_PRELIGHT; break; case GTK_CELL_RENDERER_INSENSITIVE: state = GTK_STATE_INSENSITIVE; break; default: state = GTK_STATE_NORMAL; } /* Get a cairo context to draw the rectangles on directly; use GTK themed drawing to draw everything else */ cr = gdk_cairo_create(GDK_DRAWABLE(window)); /* Draw the command */ layout = gtk_widget_create_pango_layout(widget, priv->command); pango_layout_get_pixel_extents(layout, NULL, &command_rect); set_rgb_style(cr, STYLE_COMMAND); cairo_rectangle(cr, (double)x, (double)y, (double)width, (double)(command_rect.height + priv->text_padding * 2)); cairo_fill(cr); gtk_paint_layout(style, window, state, TRUE, cell_area, widget, NULL, x + priv->text_padding, y + priv->text_padding, layout); g_object_unref(layout); /* Draw the transcript text */ transcript_width = priv->default_width / 2 - xpad; if(priv->changed) set_rgb_style(cr, STYLE_CHANGED); else set_rgb_style(cr, STYLE_UNCHANGED); cairo_rectangle(cr, (double)x, (double)(y + command_rect.height + priv->text_padding * 2), (double)(width / 2), (double)(height - command_rect.height - priv->text_padding * 2)); cairo_fill(cr); layout = gtk_widget_create_pango_layout(widget, NULL); pango_layout_set_markup(layout, priv->transcript_text, -1); pango_layout_set_width(layout, (int)(transcript_width - priv->text_padding * 2) * PANGO_SCALE); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); gtk_paint_layout(style, window, state, TRUE, cell_area, widget, NULL, x + (int)priv->text_padding, y + command_rect.height + (int)priv->text_padding * 3, layout); g_object_unref(layout); /* Draw the expected text */ switch(priv->match_type) { case CANT_COMPARE: set_rgb_style(cr, STYLE_NO_EXPECTED); break; case NO_MATCH: set_rgb_style(cr, STYLE_NO_MATCH); break; case NEAR_MATCH: set_rgb_style(cr, STYLE_NEAR_MATCH); break; case EXACT_MATCH: default: set_rgb_style(cr, STYLE_EXACT_MATCH); break; } cairo_rectangle(cr, (double)(x + width / 2), (double)(y + command_rect.height + priv->text_padding * 2), (double)(width / 2), (double)(height - command_rect.height - priv->text_padding * 2)); cairo_fill(cr); layout = gtk_widget_create_pango_layout(widget, NULL); pango_layout_set_markup(layout, priv->expected_text, -1); pango_layout_set_width(layout, (int)(transcript_width - priv->text_padding * 2) * PANGO_SCALE); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); gtk_paint_layout(style, window, state, TRUE, cell_area, widget, NULL, x + width / 2 + (int)priv->text_padding, y + command_rect.height + (int)priv->text_padding * 3, layout); g_object_unref(layout); /* Draw some lines */ gtk_paint_hline(style, window, state, cell_area, widget, NULL, x, x + width, y + command_rect.height + priv->text_padding * 2); gtk_paint_vline(style, window, state, cell_area, widget, NULL, y + command_rect.height + priv->text_padding * 2, y + height, x + width / 2); /* Draw a border around the highlighted node */ if(priv->current) { cairo_set_line_width(cr, 4.0); set_rgb_style(cr, STYLE_HIGHLIGHT); cairo_rectangle(cr, (double)x + 2.0, (double)y + 2.0, (double)width - 4.0, (double)height - 4.0); cairo_stroke(cr); } /* Draw a border around the active node */ if(priv->played) { cairo_set_line_width(cr, 2.0); set_rgb_style(cr, STYLE_ACTIVE); cairo_rectangle(cr, (double)x + 1.0, (double)y + 1.0, (double)width - 2.0, (double)height - 2.0); cairo_stroke(cr); } cairo_destroy(cr); }