//----------------------------------------------------------------------------- void t_display_rysuj_siatke_czas (T_Display *w) { int wys ; char ctmp [20] ; wys = w->canvas->allocation.height ; // kolor siatki i opisow GdkGC *gc = gdk_gc_new (GTK_LAYOUT(w->canvas)->bin_window); GdkColor color ; color.red = 0; color.green = 40000; color.blue = 0; gdk_gc_set_rgb_fg_color(gc,&color) ; time_t hours = w->last_time - w->last_time % w->time_step ; int dzialka_godz = w->time_step / 3600 ; //printf ("%d %d %d\n",hours, dzialka_godz, w->last_time % w->time_step) ; if (w->time_step > 60*60) { // dla dzialki powyzej godziny utrzymac polnoc :) hours = full_hour(w->last_time) ; while ( ((get_hour(hours) % dzialka_godz) != 0) && (hours > (w->last_time - w->time_range)) ) { hours -= 3600 ; // czasami nie pokazuje najpozniejszej godziny dla dzialki 3h // pewnie przez jakies dziwne zjawiska z czasem (lata przestepne ?) } ; } ; //printf ("%d\n",hours) ; int x_hours ; PangoLayout *etykieta ; int et_szer, et_wys ; int label_x, label_y ; while (hours > (w->last_time - w->time_range)) { x_hours = time_to_pixel_x(hours, w) ; //snprintf (&(ctmp[0]), 20, "%.2d:%.2d", get_hour(hours), get_minute(hours)) ; gen_time_label_string(&(ctmp[0]), 20, hours, w) ; etykieta = gtk_widget_create_pango_layout (w->canvas,ctmp); pango_layout_get_pixel_size (etykieta, &et_szer, &et_wys) ; label_x = x_hours-et_szer/2 ; label_y = et_wys+LABEL_MARGIN/2 ; PangoMatrix matrix = PANGO_MATRIX_INIT; if (w->x_labels_vert == TRUE) { pango_matrix_rotate (&matrix, 90.); label_x = x_hours - (et_wys)/2 ; label_y = et_szer + LABEL_MARGIN ; } ; pango_context_set_matrix (pango_layout_get_context(etykieta), &matrix); pango_layout_context_changed(etykieta) ; // rysowanie dzialek i etykiet gdk_draw_layout (GTK_LAYOUT(w->canvas)->bin_window, //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)], gc, label_x, wys-label_y - w->legend_height, etykieta) ; gdk_draw_line (GTK_LAYOUT(w->canvas)->bin_window, //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)], gc, x_hours,wys-w->y_pixel_offset,x_hours,wys-wys) ; // pogrubienie wybranych dzialek if ((get_seconds(hours) == 0) && (get_minute(hours) == 0) && (get_hour(hours) == 0) ) { gdk_draw_line (GTK_LAYOUT(w->canvas)->bin_window, //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)], gc, x_hours+1,wys-w->y_pixel_offset,x_hours+1,wys-wys) ; } ; g_object_unref(etykieta) ; hours -= w->time_step ; } ; g_object_unref(gc) ; } ;
/** * gwy_graph_label_draw_on_drawable: * @label: graph label * @drawable: the #GdkDrawable * @gc: Graphics context. * It is modified by this function unpredictably. * @layout: pango layout * @x: x position where label is to be drawn * @y: y position where label is to be drawn * @width: width of the label * @height: hieght of the label * * draws a graph label on a drawable **/ void gwy_graph_label_draw_on_drawable(GwyGraphLabel *label, GdkDrawable *drawable, GdkGC *gc, PangoLayout *layout, gint x, gint y, gint width, gint height) { gint ypos, winheight, winwidth, winx, winy, frame_off; gint i, nc; GwyGraphCurveModel *curvemodel; GwyGraphModel *model; PangoRectangle rect; GdkColor fg = { 0, 0, 0, 0 }; GdkColor color = { 0, 65535, 65535, 65535 }; if (!label->graph_model) return; model = GWY_GRAPH_MODEL(label->graph_model); pango_layout_set_font_description(layout, label->font_desc); frame_off = model->label_frame_thickness/2; ypos = 5 + frame_off; gdk_gc_set_rgb_fg_color(gc, &color); gdk_draw_rectangle(drawable, gc, TRUE, x, y, width, height); gdk_gc_set_rgb_fg_color(gc, &fg); winx = x; winy = y; winwidth = width; winheight = height; nc = gwy_graph_model_get_n_curves(model); for (i = 0; i < nc; i++) { curvemodel = gwy_graph_model_get_curve(model, i); pango_layout_set_markup(layout, curvemodel->description->str, curvemodel->description->len); pango_layout_get_pixel_extents(layout, NULL, &rect); if (model->label_reverse) gdk_draw_layout(drawable, gc, winx + winwidth - rect.width - 25 - frame_off, winy + ypos, layout); else gdk_draw_layout(drawable, gc, winx + 25 + frame_off, winy + ypos, layout); g_array_index(label->samplepos, gint, i) = ypos; if (curvemodel->mode == GWY_GRAPH_CURVE_LINE || curvemodel->mode == GWY_GRAPH_CURVE_LINE_POINTS) { if (model->label_reverse) gwy_graph_draw_line(drawable, gc, winx + winwidth - 20 - frame_off, winy + ypos + rect.height/2, winx + winwidth - 5, winy + ypos + rect.height/2, curvemodel->line_style, curvemodel->line_width, &(curvemodel->color)); else gwy_graph_draw_line(drawable, gc, winx + 5 + frame_off, winy + ypos + rect.height/2, winx + 20 + frame_off, winy + ypos + rect.height/2, curvemodel->line_style, curvemodel->line_width, &(curvemodel->color)); } if (curvemodel->mode == GWY_GRAPH_CURVE_POINTS || curvemodel->mode == GWY_GRAPH_CURVE_LINE_POINTS) { if (model->label_reverse) gwy_graph_draw_point(drawable, gc, winx + winwidth - 13 - frame_off, winy + ypos + rect.height/2, curvemodel->point_type, curvemodel->point_size, &(curvemodel->color)); else gwy_graph_draw_point(drawable, gc, winx + 12 + frame_off, winy + ypos + rect.height/2, curvemodel->point_type, curvemodel->point_size, &(curvemodel->color)); } gdk_gc_set_rgb_fg_color(gc, &fg); ypos += rect.height + 5; } if (model->label_frame_thickness > 0) { gdk_gc_set_line_attributes(gc, model->label_frame_thickness, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER); gdk_draw_line(drawable, gc, winx + model->label_frame_thickness/2, winy + model->label_frame_thickness/2, winx + winwidth - model->label_frame_thickness/2 - 1, winy + model->label_frame_thickness/2); gdk_draw_line(drawable, gc, winx + model->label_frame_thickness/2, winy + winheight - model->label_frame_thickness/2 - 1, winx + winwidth - model->label_frame_thickness/2 - 1, winy + winheight - model->label_frame_thickness/2 - 1); gdk_draw_line(drawable, gc, winx + model->label_frame_thickness/2, winy + model->label_frame_thickness/2, winx + model->label_frame_thickness/2, winy + winheight - model->label_frame_thickness/2 - 1); gdk_draw_line(drawable, gc, winx + winwidth - model->label_frame_thickness/2 - 1, winy + model->label_frame_thickness/2, winx + winwidth - model->label_frame_thickness/2 - 1, winy + winheight - model->label_frame_thickness/2 - 1); } }
static void pad_area_annotate_stroke (PadArea *area, GList *stroke, gint index) { GdkPoint *cur, *old; /* Annotate the stroke with the stroke number - the algorithm * for placing the digit is pretty simple. The text is inscribed * in a circle tangent to the stroke. The circle will be above * and/or to the left of the line */ if (stroke) { old = (GdkPoint *)stroke->data; do { cur = (GdkPoint *)stroke->data; stroke = stroke->next; } while (stroke && abs(cur->x - old->x) < 5 && abs (cur->y - old->y) < 5); if (stroke) { char buffer[16]; PangoLayout *layout; int swidth, sheight; gint16 x, y; double r; double dx = cur->x - old->x; double dy = cur->y - old->y; double dl = sqrt(dx*dx+dy*dy); int sign = (dy <= dx) ? 1 : -1; GdkRectangle update_area; sprintf (buffer, "%d", index); layout = gtk_widget_create_pango_layout (GTK_WIDGET(area->widget), buffer); pango_layout_get_pixel_size (layout, &swidth, &sheight); r = sqrt(swidth*swidth + sheight*sheight); x = 0.5 + old->x + 0.5*r*dx/dl + sign * 0.5*r*dy/dl; y = 0.5 + old->y + 0.5*r*dy/dl - sign * 0.5*r*dx/dl; x -= swidth/2; y -= sheight/2; update_area.x = x; update_area.y = y; update_area.width = swidth; update_area.height = sheight; x = CLAMP (x, 0, area->widget->allocation.width - swidth); y = CLAMP (y, 0, area->widget->allocation.height - sheight); gdk_draw_layout (area->pixmap, area->widget->style->black_gc, x, y, layout); g_object_unref (layout); gdk_window_invalidate_rect (area->widget->window, &update_area, FALSE); } } }
static void gnc_header_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) { GncHeader *header = GNC_HEADER(item); SheetBlockStyle *style = header->style; Table *table = header->sheet->table; VirtualLocation virt_loc; VirtualCell *vcell; CellDimensions *cd; GdkColor *bg_color; int xpaint, ypaint; const char *text; CellBlock *cb; guint32 argb, color_type; int i, j; int w, h; PangoLayout *layout; virt_loc.vcell_loc.virt_row = 0; virt_loc.vcell_loc.virt_col = 0; virt_loc.phys_row_offset = 0; virt_loc.phys_col_offset = 0; if (header->sheet->use_theme_colors) { color_type = gnc_table_get_gtkrc_bg_color (table, virt_loc, NULL); bg_color = get_gtkrc_color(header->sheet, color_type); } else { argb = gnc_table_get_bg_color (table, virt_loc, NULL); bg_color = gnucash_color_argb_to_gdk (argb); } h = style->dimensions->height; h *= header->num_phys_rows; h /= header->style->nrows; gdk_gc_set_foreground (header->gc, bg_color); gdk_draw_rectangle (drawable, header->gc, TRUE, 0, 0, style->dimensions->width, h); gdk_gc_set_line_attributes (header->gc, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gdk_gc_set_foreground (header->gc, &gn_black); gdk_draw_rectangle (drawable, header->gc, FALSE, -x, -y, style->dimensions->width, h); gdk_draw_line (drawable, header->gc, 0, h + 1, style->dimensions->width, h + 1); gdk_gc_set_line_attributes (header->gc, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gdk_gc_set_background (header->gc, &gn_white); gdk_gc_set_foreground (header->gc, &gn_black); /*font = gnucash_register_font;*/ vcell = gnc_table_get_virtual_cell (table, table->current_cursor_loc.vcell_loc); cb = vcell ? vcell->cellblock : NULL; ypaint = -y; h = 0; for (i = 0; i < style->nrows; i++) { xpaint = -x; virt_loc.phys_row_offset = i; /* TODO: This routine is duplicated in several places. Can we abstract at least the cell drawing routine? That way we'll be sure everything is drawn consistently, and cut down on maintenance issues. */ for (j = 0; j < style->ncols; j++) { /* gint x_offset, y_offset;*/ GdkRectangle rect; BasicCell *cell; virt_loc.phys_col_offset = j; cd = gnucash_style_get_cell_dimensions (style, i, j); if (header->in_resize && (j == header->resize_col)) w = header->resize_col_width; else w = cd->pixel_width; cell = gnc_cellblock_get_cell (cb, i, j); if (!cell || !cell->cell_name) { xpaint += w; continue; } h = cd->pixel_height; gdk_draw_rectangle (drawable, header->gc, FALSE, xpaint, ypaint, w, h); virt_loc.vcell_loc = table->current_cursor_loc.vcell_loc; text = gnc_table_get_label (table, virt_loc); if (!text) text = ""; layout = gtk_widget_create_pango_layout (GTK_WIDGET (header->sheet), text); /*y_offset = ((h / 2) + (((font->ascent + font->descent) / 2) - font->descent)); y_offset++;*/ switch (gnc_table_get_align (table, virt_loc)) { default: case CELL_ALIGN_LEFT: pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT); break; case CELL_ALIGN_RIGHT: pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT); break; case CELL_ALIGN_CENTER: pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); break; } rect.x = xpaint + CELL_HPADDING; rect.y = ypaint + 1; rect.width = MAX (0, w - (2 * CELL_HPADDING)); rect.height = h - 2; gdk_gc_set_clip_rectangle (header->gc, &rect); gdk_draw_layout (drawable, header->gc, xpaint + CELL_HPADDING, ypaint + 1, layout); g_object_unref (layout); gdk_gc_set_clip_rectangle (header->gc, NULL); xpaint += w; } ypaint += h; } }
/* Draw method handler for the icon text item */ static void mate_icon_text_item_draw (MateCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) { GtkWidget *widget; GtkStyle *style; int xofs, yofs; int text_xofs, text_yofs; int w, h; MateIconTextItem *iti; MateIconTextItemPrivate *priv; GtkStateType state; widget = GTK_WIDGET (item->canvas); iti = MATE_ICON_TEXT_ITEM (item); priv = iti->_priv; style = GTK_WIDGET (MATE_CANVAS_ITEM (iti)->canvas)->style; w = priv->layout_width + 2 * MARGIN_X; h = priv->layout_height + 2 * MARGIN_Y; xofs = item->x1 - x; yofs = item->y1 - y; text_xofs = xofs - (iti->width - priv->layout_width - 2 * MARGIN_X) / 2; text_yofs = yofs + MARGIN_Y; if (iti->selected && GTK_WIDGET_HAS_FOCUS (widget)) state = GTK_STATE_SELECTED; else if (iti->selected) state = GTK_STATE_ACTIVE; else state = GTK_STATE_NORMAL; if (iti->selected && !iti->editing) gdk_draw_rectangle (drawable, style->base_gc[state], TRUE, xofs + 1, yofs + 1, w - 2, h - 2); if (GTK_WIDGET_HAS_FOCUS (widget) && iti->focused && ! iti->editing) { GdkRectangle r; r.x = xofs; r.y = yofs; r.width = w - 1; r.height = h - 1; gtk_paint_focus (style, drawable, iti->selected ? GTK_STATE_SELECTED: GTK_STATE_NORMAL, &r, widget, NULL, xofs, yofs, w - 1, h - 1); #if 0 gtk_draw_focus (style, drawable, xofs, yofs, w - 1, h - 1); #endif } if (iti->editing) { /* FIXME: are these the right graphics contexts? */ gdk_draw_rectangle (drawable, style->base_gc[GTK_STATE_NORMAL], TRUE, xofs, yofs, w - 1, h - 1); gdk_draw_rectangle (drawable, style->fg_gc[GTK_STATE_NORMAL], FALSE, xofs, yofs, w - 1, h - 1); } gdk_draw_layout (drawable, style->text_gc[iti->editing ? GTK_STATE_NORMAL : state], text_xofs, text_yofs, priv->layout); if (iti->editing) { int range[2]; if (gtk_editable_get_selection_bounds (GTK_EDITABLE (priv->entry), &range[0], &range[1])) { GdkRegion *clip_region; GdkColor *selection_color, *text_color; guint8 state; range[0] = g_utf8_offset_to_pointer (GTK_ENTRY (priv->entry)->text, range[0]) - GTK_ENTRY (priv->entry)->text; range[1] = g_utf8_offset_to_pointer (GTK_ENTRY (priv->entry)->text, range[1]) - GTK_ENTRY (priv->entry)->text; state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; selection_color = &widget->style->base[state]; text_color = &widget->style->text[state]; clip_region = gdk_pango_layout_get_clip_region (priv->layout, text_xofs, text_yofs, range, 1); gdk_gc_set_clip_region (widget->style->black_gc, clip_region); gdk_draw_layout_with_colors (drawable, widget->style->black_gc, text_xofs, text_yofs, priv->layout, text_color, selection_color); gdk_gc_set_clip_region (widget->style->black_gc, NULL); gdk_region_destroy (clip_region); } else { iti_draw_cursor (iti, drawable, text_xofs, text_yofs); } } }
static void gimv_zalbum_draw_string (GtkWidget *widget, GimvZAlbumCell *cell, const gchar *string, gint x, gint y, gint max_width, gint max_height, gint center) { gchar buffer[STRING_BUFFER_SIZE]; gint x_pad, y_pad; gint width = 0, height = 0, str_height, len; PangoLayout *layout; gint vpad = LABEL_VPADDING; if (!string || !*string) return; layout = gtk_widget_create_pango_layout (widget, "(NULL)"); pango_layout_get_pixel_size (layout, &width, &height); str_height = height; pango_layout_set_text (layout, string, -1); pango_layout_get_pixel_size (layout, &width, &height); len = strlen(string); strncpy (buffer, string, MIN (len, STRING_BUFFER_SIZE)); buffer[MIN (len, STRING_BUFFER_SIZE - 1)] = '\0'; x_pad = (max_width - width) / 2; if (x_pad < 0) { make_string (layout, max_width, buffer, STRING_BUFFER_SIZE); } else { gint len = MIN (strlen (string), STRING_BUFFER_SIZE - 1); strncpy (buffer, string, len); buffer[len] = '\0'; } pango_layout_set_text (layout, buffer, -1); pango_layout_get_pixel_size (layout, &width, &height); x_pad = (max_width - width) / 2; if (!center) x_pad = 0; if (GIMV_ZALBUM (widget)->label_pos == GIMV_ZALBUM_CELL_LABEL_TOP || GIMV_ZALBUM (widget)->label_pos == GIMV_ZALBUM_CELL_LABEL_BOTTOM) { vpad /= 2; } if (height < max_height) { y_pad = (max_height - height) / 2 + vpad; } else { y_pad = vpad; } gdk_draw_layout (widget->window, widget->style->fg_gc[CELL_STATE(cell)], x + x_pad, y + y_pad - str_height, layout); g_object_unref (layout); }
void maluj_mape( GtkWidget *widget ) { EXIT_DATA *e; char buf[ 16 ]; int d; if ( !GDK_IS_DRAWABLE( dmapa.pixmap ) ) return; gdk_draw_rectangle( dmapa.pixmap, widget->style->dark_gc[ 0 ], TRUE, 0, 0, widget->allocation.width, widget->allocation.height ); gdk_draw_rectangle( dmapa.pixmap, widget->style->mid_gc[ 0 ], TRUE, prostokaty[ 10 ].x, prostokaty[ 10 ].y, 80, 80 ); gdk_draw_rectangle( dmapa.pixmap, widget->style->black_gc, FALSE, prostokaty[ 10 ].x, prostokaty[ 10 ].y, 80, 80 ); sprintf( buf, "#%d", dmapa.room->vnum ); pango_layout_set_text( dmapa.layout, buf, -1 ); gdk_draw_layout( dmapa.pixmap, widget->style->black_gc, prostokaty[ 10 ].x + 3, prostokaty[ 10 ].y + 1, dmapa.layout ); pango_layout_set_text( dmapa.layout, pols_z_lac_len( dmapa.room->name, 10 ), -1 ); gdk_draw_layout( dmapa.pixmap, widget->style->black_gc, prostokaty[ 10 ].x + 3, prostokaty[ 10 ].y + 14, dmapa.layout ); for ( d = 0; d < 10; d++ ) { gdk_draw_rectangle( dmapa.pixmap, widget->style->white_gc, TRUE, prostokaty[ d ].x, prostokaty[ d ].y, 80, 80 ); pango_layout_set_text( dmapa.layout, kierunki[ d ].skrot, -1 ); gdk_draw_layout( dmapa.pixmap, widget->style->black_gc, prostokaty[ d ].x, prostokaty[ d ].y - 14, dmapa.layout ); if ( ( e = dmapa.room->exit[ d ] ) ) { gdk_draw_rectangle( dmapa.pixmap, widget->style->white_gc, TRUE, prostokaty[ d ].x, prostokaty[ d ].y, 80, 80 ); if ( e->to_room ) { sprintf( buf, "#%d", e->to_room->vnum ); pango_layout_set_text( dmapa.layout, buf, -1 ); gdk_draw_layout( dmapa.pixmap, widget->style->black_gc, prostokaty[ d ].x + 3, prostokaty[ d ].y + 1, dmapa.layout ); pango_layout_set_text( dmapa.layout, pols_z_lac_len( e->to_room->name, 10 ), -1 ); gdk_draw_layout( dmapa.pixmap, widget->style->black_gc, prostokaty[ d ].x + 3, prostokaty[ d ].y + 14, dmapa.layout ); } else { pango_layout_set_text( dmapa.layout, "(brak)", -1 ); gdk_draw_layout( dmapa.pixmap, widget->style->black_gc, prostokaty[ d ].x + 3, prostokaty[ d ].y + 1, dmapa.layout ); } } else gdk_draw_rectangle( dmapa.pixmap, widget->style->dark_gc[ 0 ], TRUE, prostokaty[ d ].x, prostokaty[ d ].y, 80, 80 ); gdk_draw_rectangle( dmapa.pixmap, widget->style->black_gc, FALSE, prostokaty[ d ].x, prostokaty[ d ].y, 80, 80 ); } /* wymuszenie odswiezenia calego GtkDrawable */ gtk_widget_queue_draw_area( widget, 0, 0, widget->allocation.width, widget->allocation.height ); return; }
static void gtk_shruler_draw_ticks(GtkRuler *ruler) { GtkWidget *widget; GdkGC *gc, *bg_gc; gint i; gint width, height; gint xthickness; gint ythickness; gint pos; g_return_if_fail (ruler != NULL); g_return_if_fail (GTK_IS_HRULER (ruler)); if (!GTK_WIDGET_DRAWABLE (ruler)) return; widget = GTK_WIDGET (ruler); gc = widget->style->fg_gc[GTK_STATE_NORMAL]; bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL]; xthickness = widget->style->xthickness; ythickness = widget->style->ythickness; width = widget->allocation.width; height = widget->allocation.height - ythickness * 2; gtk_paint_box (widget->style, ruler->backing_store, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, widget, "hruler", 0, 0, widget->allocation.width, widget->allocation.height); #if 0 gdk_draw_line (ruler->backing_store, gc, xthickness, height + ythickness, widget->allocation.width - xthickness, height + ythickness); #endif /* assume ruler->max_size has the char width */ /* i is increment of char_width, pos is label number * y position is based on height of widget itself */ for ( pos = GTK_SHRULER(ruler)->start_pos, i = 0; pos < widget->allocation.width - xthickness; pos += ruler->max_size, i++ ) { gint length = height / 8; if ( i % 10 == 0 ) length = ( 2 * height / 3 ); else if ( i % 5 == 0 ) length = ( height / 3 ); gdk_draw_line(ruler->backing_store, gc, pos, height + ythickness, pos, height - length); if ( i % 10 == 0 ) { gchar buf[8]; PangoLayout *layout; /* draw label */ g_snprintf(buf, sizeof buf, "%d", i); layout = gtk_widget_create_pango_layout (GTK_WIDGET(ruler), buf); gdk_draw_layout(ruler->backing_store, gc, pos + 2, 0, layout); g_object_unref(layout); } } }
void vik_viewport_draw_layout ( VikViewport *vvp, GdkGC *gc, gint x, gint y, PangoLayout *layout ) { if ( x > -100 && x < vvp->width + 100 && y > -100 && y < vvp->height + 100 ) gdk_draw_layout ( vvp->scr_buffer, gc, x, y, layout ); }
static void update_pixmap(LmplayerLyricWidgetDa *lyric) { GList *iter; LyricLine *line; GdkGC *gc; PangoContext *context; PangoLayout *layout; LmplayerLyricWidgetDaPrivate *priv = lyric->priv; gint n; if(priv->loaded == FALSE) return; //FIXME: if(priv->lines == NULL) return; //gint real_width = priv->da_width; //gint real_height = priv->da_height; //gdk_drawable_get_size(priv->da->window, &real_width, &real_height); //if(!(priv->changed) || (real_width == priv->da_width && real_height == priv->da_height)) if(!priv->changed && !priv->da_size_changed) { g_print("no changed\n"); return; } if(priv->pixmap != NULL) { gdk_pixmap_unref(priv->pixmap); } n = g_list_length(priv->lines); priv->da_height = (n + 4) * priv->inter; priv->pixmap = gdk_pixmap_new(priv->da->window, priv->da_width, priv->da_height, -1); if(priv->pixmap == NULL) return; gc = gdk_gc_new(priv->da->window); gdk_gc_set_rgb_fg_color(gc, &priv->bg); gdk_draw_rectangle(priv->pixmap, gc, TRUE, 0, 0, priv->da_width, priv->da_height); context = gtk_widget_get_pango_context(priv->da); layout = pango_layout_new(context); pango_layout_set_width(layout, priv->da_width * PANGO_SCALE); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); gdk_gc_set_rgb_fg_color(gc, &priv->fg); for(iter = priv->lines; iter; iter = iter->next) { line = (LyricLine*)iter->data; if(line->text == NULL) continue; pango_layout_set_text(layout, line->text, -1); gdk_draw_layout(priv->pixmap, gc, line->x, line->y, layout); } priv->changed = FALSE; gtk_widget_set_size_request(priv->da, priv->da_width, priv->da_height); }
static void lmplayer_lyric_widget_da_set_current_second(LmplayerLyricWidget *lyric, gint sec) { gint w, h; gint n; gboolean find = FALSE; GList *iter = NULL; LyricLine *line = NULL; g_return_if_fail(LMPLAYER_IS_LYRIC_WIDGET_DA(lyric)); g_return_if_fail(sec >= 0); LmplayerLyricWidgetDaPrivate *priv = LMPLAYER_LYRIC_WIDGET_DA(lyric)->priv; if(priv->current_second == sec) return; priv->current_second = sec; gtk_widget_get_size_request(GTK_WIDGET(lyric), &w, &h); for(iter = priv->lines, n = 0; iter; iter = iter->next, ++n) { line = iter->data; if(line && line->sec == sec) { find = TRUE; break; } else if(line && line->sec > sec) { find = FALSE; break; } find = FALSE; } if(find && line) { if(line->text != NULL) { gdk_gc_set_rgb_fg_color(priv->da_gc, &priv->current); pango_layout_set_text(priv->pango_layout, line->text, -1); pango_layout_set_width(priv->pango_layout, priv->da_width * PANGO_SCALE); pango_layout_set_alignment(priv->pango_layout, PANGO_ALIGN_CENTER); // 注意:这里是在da上直接绘,而不是在pixmap上 gdk_draw_layout(priv->da->window, priv->da_gc, line->x, line->y, priv->pango_layout); //gdk_draw_layout(priv->pixmap, priv->da_gc, line->x, line->y, priv->pango_layout); } gtk_layout_move(GTK_LAYOUT(lyric), priv->alignment, 0, h / 2 - line->y); if(n > 0) { line = (LyricLine*)g_list_nth_data(priv->lines, n - 1); if(line->text != NULL) { gdk_gc_set_rgb_fg_color(priv->da_gc, &priv->fg); pango_layout_set_text(priv->pango_layout, line->text, -1); pango_layout_set_width(priv->pango_layout, priv->da_width * PANGO_SCALE); pango_layout_set_alignment(priv->pango_layout, PANGO_ALIGN_CENTER); // 注意:这里是在da上直接绘,而不是在pixmap上 gdk_draw_layout(priv->da->window, priv->da_gc, line->x, line->y, priv->pango_layout); //gdk_draw_layout(priv->pixmap, priv->da_gc, line->x, line->y, priv->pango_layout); } } } }
/*----------------------------------------------------------------------------*/ void viewPaintScore(GtkWidget* widget, int p) { /* display the score */ //g_message("in viewPaintScore"); int r, c; char out[16]; out[0] = 0; int middle = m_ScoreRect[p].x+m_ScoreRect[p].width/2; int xpos = 0; strcpy(out, "Score"); PangoLayout* pl = gtk_widget_create_pango_layout(widget, out); int width = pango_layout_get_width(pl); //printf("width=%d\n", width); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+5, pl); g_object_unref(pl); if (gameEngineData[p].m_Score == 0) { strcpy(out, " "); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+25, pl); g_object_unref(pl); } sprintf(out, " %d ", (int)gameEngineData[p].m_Score); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+25, pl); g_object_unref(pl); strcpy(out, "Level"); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+45, pl); g_object_unref(pl); sprintf(out, " %d ", gameEngineData[p].m_Level); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+65, pl); g_object_unref(pl); strcpy(out, "Lines"); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+85, pl); g_object_unref(pl); sprintf(out, " %d ", gameEngineData[p].m_Lines); pl = gtk_widget_create_pango_layout(widget, out); width = pango_layout_get_width(pl); xpos = middle - width/2; gdk_draw_layout(pixmap, lightGreyGC, xpos, m_ScoreRect[p].y+105, pl); g_object_unref(pl); /* display the preview */ GdkRectangle rect; int icolor; int bs = 10; if (GameGetPreview(&gameEngineData[p], &icolor)) { rect.x = m_ScoreRect[p].x+16; rect.y = m_ScoreRect[p].y+130; rect.width = 1 + (bs+2)*4; rect.height = 1 + (bs+2)*4; viewPaintBlackBlock(widget, &rect); unsigned long pv = GameGetPreview(&gameEngineData[p], &icolor); icolor++; unsigned long mask; for (r=0; r<5; r++) { for (c=0; c<5; c++) { rect.x = m_ScoreRect[p].x+16+c*bs+1; rect.y = m_ScoreRect[p].y+130+r*bs+1; rect.width = bs-2; rect.height = bs-2; mask = 0x80000000>>(r*5+c); if (pv&mask) { switch (userData.m_PieceStyle) { case 0: viewPaintFlatBlock(widget, (char)icolor, &rect); break; case 1: viewPaint3DBlock(widget, (char)icolor, &rect); break; case 2: viewPaintPyrimidBlock(widget, (char)icolor, &rect); break; } } else viewPaintBlackBlock(widget, &rect); } } }
G_MODULE_EXPORT gboolean display_show(NOTIFICATION_INFO* ni) { DISPLAY_INFO* di = g_new0(DISPLAY_INFO, 1); if (!di) { perror("g_new0"); return FALSE; } di->ni = ni; notifications = g_list_append(notifications, di); di->popup = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_title(GTK_WINDOW(di->popup), "growl-for-linux"); gtk_window_set_resizable(GTK_WINDOW(di->popup), TRUE); gtk_window_set_decorated(GTK_WINDOW(di->popup), FALSE); gtk_window_set_keep_above(GTK_WINDOW(di->popup), TRUE); gtk_widget_modify_bg(di->popup, GTK_STATE_NORMAL, colors + (rand() % lengthof(available_colors))); gtk_window_stick(GTK_WINDOW(di->popup)); GtkWidget* ebox = gtk_event_box_new(); gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE); gtk_container_add(GTK_CONTAINER(di->popup), ebox); GtkWidget* fixed = gtk_fixed_new(); gtk_container_set_border_width(GTK_CONTAINER(fixed), 0); gtk_container_add(GTK_CONTAINER(ebox), fixed); GtkWidget* image = NULL; if (di->ni->icon && *di->ni->icon) { GdkPixbuf* pixbuf; if (di->ni->local) { gchar* newurl = g_filename_from_uri(di->ni->icon, NULL, NULL); GError* error = NULL; pixbuf = gdk_pixbuf_new_from_file(newurl ? newurl : di->ni->icon, &error); g_free(newurl); } else { pixbuf = pixbuf_from_url(di->ni->icon, NULL); } if (pixbuf) { GdkPixbuf* tmp = gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_TILES); if (tmp) { g_object_unref(pixbuf); pixbuf = tmp; } image = gtk_image_new_from_pixbuf(pixbuf); gtk_container_add(GTK_CONTAINER(fixed), image); g_object_unref(pixbuf); } } PangoContext* context = gtk_widget_get_pango_context(di->popup) ; PangoLayout* layout = pango_layout_new(context); gchar* text = g_strconcat(di->ni->title, "\n", di->ni->text, NULL); pango_layout_set_text(layout, text, -1); g_free(text); pango_layout_set_font_description(layout, font_sans20_desc); pango_layout_get_pixel_size(layout, &di->width, &di->height); di->x = screen_rect.width; di->y = screen_rect.y + rand() % (screen_rect.height - di->height); di->width += 32 + 5; if (image) gtk_fixed_move(GTK_FIXED(fixed), image, 0, di->height / 2 - 16); GdkBitmap* bitmap = gdk_pixmap_new(di->popup->window, di->width, di->height, 1); GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(bitmap)); GdkColormap* colormap = gdk_colormap_get_system(); gdk_gc_set_colormap(gc, colormap); gdk_colormap_alloc_color(colormap, color_black, TRUE, TRUE); gdk_gc_set_foreground (gc, color_black); gdk_draw_rectangle(bitmap, gc, TRUE, 0, 0, di->width, di->height); gdk_colormap_alloc_color(colormap, color_white, TRUE, TRUE); gdk_gc_set_foreground (gc, color_white); if (image) gdk_draw_rectangle(bitmap, gc, TRUE, 0, di->height / 2 - 16, 32, 32); gdk_draw_layout(bitmap, gc, 32 + 5, 0, layout); g_signal_connect(G_OBJECT(ebox), "button-press-event", G_CALLBACK(display_clicked), di); g_signal_connect(G_OBJECT(ebox), "enter-notify-event", G_CALLBACK(display_enter), di); g_signal_connect(G_OBJECT(ebox), "leave-notify-event", G_CALLBACK(display_leave), di); gtk_window_move(GTK_WINDOW(di->popup), di->x, di->y); gtk_widget_show_all(di->popup); gtk_widget_set_size_request(fixed, di->width, di->height); gdk_window_set_back_pixmap(di->popup->window, NULL, FALSE); gdk_window_shape_combine_mask(di->popup->window, bitmap, 0, 0); g_object_unref(gc); g_object_unref(layout); g_object_unref(context); g_object_unref(bitmap); g_object_ref(di->popup); g_timeout_add(100, display_animation_func, di); return FALSE; }
//------------------------------------------------------------------------------ // // Temperatura // //----------------------------------------------------------------------------- void t_display_rysuj_siatke_temp (T_Display *w) { int i_tmp ; int tmp_pixel ; int wys = w->canvas->allocation.height ; char ctmp [16] ; PangoLayout *etykieta ; int et_szer, et_wys ; int label_x, label_y ; PangoMatrix matrix = PANGO_MATRIX_INIT; // kolor siatki i opisow GdkGC *gc = gdk_gc_new (GTK_LAYOUT(w->canvas)->bin_window); GdkColor color ; color.red = 0; color.green = 40000; color.blue = 0; gdk_gc_set_rgb_fg_color(gc,&color) ; // najwyzsza wartosc dzialki i_tmp = w->temp_max - (w->temp_max % w->temp_step) ; while (i_tmp >= w->temp_min) { tmp_pixel = temp_to_pixel_y(i_tmp,w) ; // rysuj dzialke gdk_draw_line (GTK_LAYOUT(w->canvas)->bin_window, //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)], gc, w->x_pixel_offset, wys - tmp_pixel, w->canvas->allocation.width, wys- tmp_pixel); if (i_tmp == 0) { // ewentualne pogrubienie, tylko dla 0 stopni gdk_draw_line (GTK_LAYOUT(w->canvas)->bin_window, //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)], gc, w->x_pixel_offset, wys - tmp_pixel-1, w->canvas->allocation.width, wys- tmp_pixel-1); } ; // etykieta snprintf (&(ctmp[0]), 16, "%d", i_tmp) ; etykieta = gtk_widget_create_pango_layout (w->canvas,ctmp); pango_context_set_matrix (pango_layout_get_context(etykieta), &matrix); pango_layout_context_changed(etykieta) ; pango_layout_get_pixel_size (etykieta, &et_szer, &et_wys) ; label_x = LABEL_MARGIN ; label_y = tmp_pixel + (et_wys)/2 ; gdk_draw_layout (GTK_LAYOUT(w->canvas)->bin_window, //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)], gc, label_x, wys-label_y, etykieta) ; g_object_unref(etykieta) ; i_tmp -= w->temp_step ; } ; g_object_unref(gc) ; } ;
void iupdrvDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, int w, int h, long color, const char* font, int flags, double text_orientation) { PangoLayout* fontlayout = (PangoLayout*)iupgtkGetPangoLayout(font); PangoAlignment alignment = PANGO_ALIGN_LEFT; GdkColor c; PangoContext* fontcontext = NULL; int layout_w = w, layout_h = h; int layout_center = flags & IUP_DRAW_LAYOUTCENTER; if (text_orientation && layout_center) iupDrawGetTextInnerBounds(w, h, text_orientation, &layout_w, &layout_h); iupgdkColorSet(&c, color); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &c); text = iupgtkStrConvertToSystemLen(text, &len); pango_layout_set_text(fontlayout, text, len); if (flags & IUP_DRAW_RIGHT) alignment = PANGO_ALIGN_RIGHT; else if (flags & IUP_DRAW_CENTER) alignment = PANGO_ALIGN_CENTER; if (flags & IUP_DRAW_WRAP) { pango_layout_set_width(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_w)); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,2,0) pango_layout_set_height(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_h)); #endif #endif } else if (flags & IUP_DRAW_ELLIPSIS) { pango_layout_set_width(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_w)); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,2,0) pango_layout_set_height(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_h)); #endif #endif pango_layout_set_ellipsize(fontlayout, PANGO_ELLIPSIZE_END); } pango_layout_set_alignment(fontlayout, alignment); if (flags & IUP_DRAW_CLIP) { GdkRectangle rect; rect.x = x; rect.y = y; rect.width = w; rect.height = h; gdk_gc_set_clip_rectangle(dc->pixmap_gc, &rect); } if (text_orientation) { PangoRectangle rect; PangoMatrix fontmatrix = PANGO_MATRIX_INIT; fontcontext = pango_layout_get_context(fontlayout); pango_matrix_rotate(&fontmatrix, text_orientation); pango_context_set_matrix(fontcontext, &fontmatrix); pango_layout_context_changed(fontlayout); pango_layout_get_pixel_extents(fontlayout, NULL, &rect); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,16,0) pango_matrix_transform_pixel_rectangle(&fontmatrix, &rect); #endif #endif /* Adjust the position considering the Pango rectangle transformed */ if (layout_center) { x += (w - rect.width) / 2; y += (h - rect.height) / 2; } else { x += (int)rect.x; y += (int)rect.y; } } gdk_draw_layout(dc->pixmap, dc->pixmap_gc, x, y, fontlayout); /* restore settings */ if ((flags & IUP_DRAW_WRAP) || (flags & IUP_DRAW_ELLIPSIS)) { pango_layout_set_width(fontlayout, -1); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,2,0) pango_layout_set_height(fontlayout, -1); #endif #endif } if (flags & IUP_DRAW_ELLIPSIS) pango_layout_set_ellipsize(fontlayout, PANGO_ELLIPSIZE_NONE); if (flags & IUP_DRAW_CLIP) gdk_gc_set_clip_region(dc->pixmap_gc, NULL); if (text_orientation) pango_context_set_matrix(fontcontext, NULL); }
static void gwy_color_axis_draw_label(GtkWidget *widget) { GwyColorAxis *axis; PangoLayout *layout; GwySIValueFormat *format = NULL; GString *strmin, *strmax; GdkGC *mygc; PangoRectangle rect; gwy_debug(""); mygc = gdk_gc_new(widget->window); axis = GWY_COLOR_AXIS(widget); /*compute minimum and maximum numbers*/ strmax = g_string_new(" "); if (axis->max == 0) { if (axis->min == 0) g_string_printf(strmax, "0.0"); else { format = gwy_si_unit_get_format(axis->siunit, axis->max, NULL); g_string_printf(strmax, "0.0 "); g_string_append(strmax, format->units); } } else { format = gwy_si_unit_get_format(axis->siunit, axis->max, NULL); g_string_printf(strmax, "%3.1f ", axis->max/format->magnitude); g_string_append(strmax, format->units); } strmin = g_string_new(" "); if (axis->min == 0) { if (axis->max == 0) g_string_printf(strmin, "0.0"); else { format = gwy_si_unit_get_format(axis->siunit, axis->max, format); g_string_printf(strmin, "0.0 "); g_string_append(strmin, format->units); } } else { /*yes, realy axis->max*/ format = gwy_si_unit_get_format(axis->siunit, axis->max, format); g_string_printf(strmin, "%3.1f ", axis->min/format->magnitude); g_string_append(strmin, format->units); } if (axis->orientation == GTK_ORIENTATION_VERTICAL) { /*draw frame around axis*/ gdk_draw_rectangle(widget->window, mygc, 0, 0, 0, widget->allocation.width - axis->par.textarea, widget->allocation.height - 1); gdk_draw_line(widget->window, mygc, widget->allocation.width - axis->par.textarea, 0, widget->allocation.width - axis->par.textarea + axis->par.tick_length, 0); gdk_draw_line(widget->window, mygc, widget->allocation.width - axis->par.textarea, widget->allocation.height/2, widget->allocation.width - axis->par.textarea + axis->par.tick_length, widget->allocation.height/2); gdk_draw_line(widget->window, mygc, widget->allocation.width - axis->par.textarea, widget->allocation.height - 1, widget->allocation.width - axis->par.textarea + axis->par.tick_length, widget->allocation.height - 1); /*draw text*/ layout = gtk_widget_create_pango_layout(widget, ""); pango_layout_set_font_description(layout, axis->par.font); pango_layout_set_markup(layout, strmax->str, strmax->len); pango_layout_get_pixel_extents(layout, NULL, &rect); gdk_draw_layout(widget->window, mygc, widget->allocation.width - axis->par.textarea + 2, 2, layout); pango_layout_set_markup(layout, strmin->str, strmin->len); pango_layout_get_pixel_extents(layout, NULL, &rect); gdk_draw_layout(widget->window, mygc, widget->allocation.width - axis->par.textarea + 2, widget->allocation.height - rect.height - 2, layout); } else { /*draw frame around axis*/ gdk_draw_rectangle(widget->window, mygc, FALSE, 0, axis->par.textarea, widget->allocation.width - 1, widget->allocation.height - 1); gdk_draw_line(widget->window, mygc, 0, axis->par.textarea - axis->par.tick_length, 0, axis->par.textarea); gdk_draw_line(widget->window, mygc, widget->allocation.width/2, axis->par.textarea - axis->par.tick_length, widget->allocation.width/2, axis->par.textarea); gdk_draw_line(widget->window, mygc, widget->allocation.width - 1, axis->par.textarea - axis->par.tick_length, widget->allocation.width - 1, axis->par.textarea); /*draw text*/ layout = gtk_widget_create_pango_layout(widget, ""); pango_layout_set_font_description(layout, axis->par.font); pango_layout_set_markup(layout, strmin->str, strmin->len); pango_layout_get_pixel_extents(layout, NULL, &rect); gdk_draw_layout(widget->window, mygc, 2, axis->par.textarea - rect.height - 2, layout); pango_layout_set_markup(layout, strmax->str, strmax->len); pango_layout_get_pixel_extents(layout, NULL, &rect); gdk_draw_layout(widget->window, mygc, widget->allocation.width - rect.width - 2, axis->par.textarea - rect.height - 2, layout); } g_object_unref(mygc); g_object_unref(layout); if (format) gwy_si_unit_value_format_free(format); g_string_free(strmin, TRUE); g_string_free(strmax, TRUE); }
static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len) { PangoFontMetrics* metrics; int w, h, desc, dir = -1; int ox = x, oy = y; pango_layout_set_text(ctxcanvas->fontlayout, sStrConvertToUTF8(ctxcanvas, s, len), -1); pango_layout_get_pixel_size(ctxcanvas->fontlayout, &w, &h); metrics = pango_context_get_metrics(ctxcanvas->fontcontext, ctxcanvas->fontdesc, pango_context_get_language(ctxcanvas->fontcontext)); desc = (((pango_font_metrics_get_descent(metrics)) + PANGO_SCALE/2) / PANGO_SCALE); switch (ctxcanvas->canvas->text_alignment) { case CD_BASE_RIGHT: case CD_NORTH_EAST: case CD_EAST: case CD_SOUTH_EAST: x = x - w; break; case CD_BASE_CENTER: case CD_CENTER: case CD_NORTH: case CD_SOUTH: x = x - w/2; break; case CD_BASE_LEFT: case CD_NORTH_WEST: case CD_WEST: case CD_SOUTH_WEST: x = x; break; } if (ctxcanvas->canvas->invert_yaxis) dir = 1; switch (ctxcanvas->canvas->text_alignment) { case CD_BASE_LEFT: case CD_BASE_CENTER: case CD_BASE_RIGHT: y = y - (dir*h - desc); break; case CD_SOUTH_EAST: case CD_SOUTH_WEST: case CD_SOUTH: y = y - (dir*h); break; case CD_NORTH_EAST: case CD_NORTH: case CD_NORTH_WEST: y = y; break; case CD_CENTER: case CD_EAST: case CD_WEST: y = y - (dir*(h/2)); break; } if(!ctxcanvas->canvas->use_matrix) { ctxcanvas->fontmatrix.xx = 1; ctxcanvas->fontmatrix.xy = 0; ctxcanvas->fontmatrix.yx = 0; ctxcanvas->fontmatrix.yy = 1; ctxcanvas->fontmatrix.x0 = 0; ctxcanvas->fontmatrix.y0 = 0; } if (ctxcanvas->canvas->use_matrix || ctxcanvas->canvas->text_orientation) { PangoRectangle rect; double angle = ctxcanvas->canvas->text_orientation; if (ctxcanvas->canvas->text_orientation) pango_matrix_rotate(&ctxcanvas->fontmatrix, angle); pango_context_set_matrix (ctxcanvas->fontcontext, &ctxcanvas->fontmatrix); pango_layout_context_changed (ctxcanvas->fontlayout); pango_layout_get_pixel_extents(ctxcanvas->fontlayout, NULL, &rect); #if PANGO_VERSION_CHECK(1,16,0) pango_matrix_transform_pixel_rectangle(&ctxcanvas->fontmatrix, &rect); #endif if (ctxcanvas->canvas->text_orientation) { double cos_angle = cos(angle*CD_DEG2RAD); double sin_angle = sin(angle*CD_DEG2RAD); cdRotatePoint(ctxcanvas->canvas, x, y, ox, oy, &x, &y, sin_angle, cos_angle); } if (ctxcanvas->canvas->use_matrix) cdMatrixTransformPoint(ctxcanvas->xmatrix, x, y, &x, &y); /* Defines the new position (X,Y), considering the Pango rectangle transformed */ x += (int)rect.x; y += (int)rect.y; } cdgdkCheckSolidStyle(ctxcanvas, 1); if (ctxcanvas->canvas->new_region) { GdkRegion *rgn; gint *idx; gint range; pango_layout_line_get_x_ranges(pango_layout_get_line(ctxcanvas->fontlayout, 0), 0, len, &idx, &range); /* TODO: this is only the bounding box of the layout, not the text itself, must transform the text into a polygon. */ rgn = gdk_pango_layout_get_clip_region(ctxcanvas->fontlayout, x, y, idx, range); sCombineRegion(ctxcanvas, rgn); } else gdk_draw_layout(ctxcanvas->wnd, ctxcanvas->gc, x, y, ctxcanvas->fontlayout); pango_context_set_matrix(ctxcanvas->fontcontext, NULL); cdgdkCheckSolidStyle(ctxcanvas, 0); pango_font_metrics_unref(metrics); }
static void sctp_graph_draw(struct sctp_udata *u_data) { int length, lwidth; guint32 distance=5, i, e, sec, w, start, a, j, b; gint label_width, label_height; char label_string[15]; gfloat dis; gboolean write_label = FALSE; PangoLayout *layout; if (u_data->io->x1_tmp_sec == 0 && u_data->io->x1_tmp_usec == 0) u_data->io->offset = 0; else u_data->io->offset = 5; if (u_data->io->x2_tmp_sec - u_data->io->x1_tmp_sec > 1500) { u_data->io->min_x=u_data->io->x1_tmp_sec; u_data->io->max_x=u_data->io->x2_tmp_sec; u_data->io->uoff = TRUE; } else { u_data->io->min_x=((guint32) (u_data->io->x1_tmp_sec*1000000.0))+u_data->io->x1_tmp_usec; u_data->io->max_x=((guint32) (u_data->io->x2_tmp_sec*1000000.0))+u_data->io->x2_tmp_usec; u_data->io->uoff = FALSE; } u_data->io->tmp_width = u_data->io->max_x - u_data->io->min_x; if (u_data->dir == 1) { if (u_data->io->tmp == FALSE) { if (u_data->assoc->sort_tsn1 != NULL) u_data->io->max_y = u_data->io->tmp_max_tsn1 - u_data->io->tmp_min_tsn1; else u_data->io->max_y = 0; u_data->io->min_y = 0; } else { u_data->io->max_y = u_data->io->tmp_max_tsn1; u_data->io->min_y = u_data->io->tmp_min_tsn1; } } else if (u_data->dir == 2) { if (u_data->io->tmp == FALSE) { if (u_data->assoc->tsn2 != NULL) u_data->io->max_y = u_data->io->tmp_max_tsn2 - u_data->io->tmp_min_tsn2; else u_data->io->max_y = 0; u_data->io->min_y = 0; } else { u_data->io->max_y = u_data->io->tmp_max_tsn2; u_data->io->min_y = u_data->io->tmp_min_tsn2; } } gdk_draw_rectangle(u_data->io->pixmap, u_data->io->draw_area->style->white_gc, TRUE, 0, 0, u_data->io->draw_area->allocation.width, u_data->io->draw_area->allocation.height); distance = 5; /* x_axis */ gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, LEFT_BORDER+u_data->io->offset,u_data->io->pixmap_height - BOTTOM_BORDER, u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset, u_data->io->pixmap_height - BOTTOM_BORDER); gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset, u_data->io->pixmap_height - BOTTOM_BORDER, u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset - 5, u_data->io->pixmap_height - BOTTOM_BORDER - 5); gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset, u_data->io->pixmap_height - BOTTOM_BORDER, u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset - 5, u_data->io->pixmap_height - BOTTOM_BORDER + 5); u_data->io->axis_width = u_data->io->pixmap_width - LEFT_BORDER - RIGHT_BORDER - u_data->io->offset; if(u_data->io->tmp_width>0){ u_data->io->x_interval = (float)((u_data->io->axis_width*1.0)/u_data->io->tmp_width); /*distance in pixels between 2 data points*/ } else { u_data->io->x_interval = (float)(u_data->io->axis_width); } e=0; if (u_data->io->x_interval < 1) { dis = 1 / u_data->io->x_interval; while (dis >1) { dis /= 10; e++; } distance = 1; for (i=0; i<=e+1; i++) distance *= 10; } else distance = 5; g_snprintf(label_string, sizeof(label_string), "%d", 0); memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15); layout = gtk_widget_create_pango_layout(u_data->io->draw_area, label_string); pango_layout_get_pixel_size(layout, &label_width, &label_height); if (u_data->io->x1_tmp_usec == 0) sec = u_data->io->x1_tmp_sec; else sec = u_data->io->x1_tmp_sec+1; if (u_data->io->offset != 0) { g_snprintf(label_string, sizeof(label_string), "%u", u_data->io->x1_tmp_sec); memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); pango_layout_set_text(layout, label_string, -1); pango_layout_get_pixel_size(layout, &lwidth, NULL); gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, LEFT_BORDER - 25, u_data->io->pixmap_height - BOTTOM_BORDER + 20, layout); } w = (guint32)(500 / (guint32)(distance * u_data->io->x_interval)); if (w == 0) w = 1; if (w == 4 || w==3 || w==2) { w = 5; a = distance / 10; b = (guint32)((u_data->io->min_x/100000))%10; /* start for labels*/ } else { a = distance / 5; b = 0; } if (!u_data->io->uoff) { if (a>=1000000) { start=u_data->io->min_x/1000000*1000000; if (a==1000000) b = 0; } else { start=u_data->io->min_x/100000; if (start%2!=0) start--; start*=100000; b = (guint32)((start/100000))%10; } } else { start = u_data->io->min_x; if (start%2!=0) start--; b = 0; } for (i=start, j=b; i<=u_data->io->max_x; i+=a, j++) { if (!u_data->io->uoff) if (i >= u_data->io->min_x && i % 1000000 != 0) { length = 5; g_snprintf(label_string, sizeof(label_string), "%d", i%1000000); if (j % w == 0) { length = 10; memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); pango_layout_set_text(layout, label_string, -1); pango_layout_get_pixel_size(layout, &lwidth, NULL); gdk_draw_layout(u_data->io->pixmap, u_data->io->draw_area->style->black_gc, (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval - lwidth / 2), u_data->io->pixmap_height - BOTTOM_BORDER + 10, layout); } gdk_draw_line(u_data->io->pixmap, u_data->io->draw_area->style->black_gc, (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), u_data->io->pixmap_height - BOTTOM_BORDER, (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), u_data->io->pixmap_height - BOTTOM_BORDER + length); } if (!u_data->io->uoff) { if (i%1000000==0 && j%w==0) { sec=i/1000000; write_label = TRUE; } } else { if (j%w == 0) { sec = i; write_label = TRUE; } } if (write_label) { gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), u_data->io->pixmap_height - BOTTOM_BORDER, (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), u_data->io->pixmap_height - BOTTOM_BORDER + 10); g_snprintf(label_string, sizeof(label_string), "%d", sec); memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); pango_layout_set_text(layout, label_string, -1); pango_layout_get_pixel_size(layout, &lwidth, NULL); gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval-10), u_data->io->pixmap_height - BOTTOM_BORDER + 20, layout); write_label = FALSE; } } g_strlcpy(label_string, "sec", sizeof(label_string)); memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); pango_layout_set_text(layout, label_string, -1); pango_layout_get_pixel_size(layout, &lwidth, NULL); gdk_draw_layout(u_data->io->pixmap, u_data->io->draw_area->style->black_gc, u_data->io->pixmap_width - RIGHT_BORDER - 10, u_data->io->pixmap_height - BOTTOM_BORDER + 30, layout); distance = 5; /* y-axis */ gdk_draw_line(u_data->io->pixmap, u_data->io->draw_area->style->black_gc, LEFT_BORDER,TOP_BORDER - u_data->io->offset, LEFT_BORDER, u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset); gdk_draw_line(u_data->io->pixmap, u_data->io->draw_area->style->black_gc, LEFT_BORDER, TOP_BORDER - u_data->io->offset, LEFT_BORDER - 5, TOP_BORDER - u_data->io->offset + 5); gdk_draw_line(u_data->io->pixmap, u_data->io->draw_area->style->black_gc, LEFT_BORDER, TOP_BORDER - u_data->io->offset, LEFT_BORDER + 5, TOP_BORDER - u_data->io->offset + 5); u_data->io->y_interval = (float)(((u_data->io->pixmap_height - TOP_BORDER - BOTTOM_BORDER) * 1.0)/(u_data->io->max_y - u_data->io->min_y)); e = 0; if (u_data->io->y_interval < 1) { dis = 1 / u_data->io->y_interval; while (dis > 1) { dis /= 10; e++; } distance = 1; for (i=0; i<=e; i++) distance = distance * 10; } else if (u_data->io->y_interval<2) distance = 10; if (u_data->io->max_y > 0) { for (i=u_data->io->min_y/distance*distance; i<=u_data->io->max_y; i+=distance/5) { if (i >= u_data->io->min_y) { length = 5; g_snprintf(label_string, sizeof(label_string), "%d", i); if (i%distance == 0 || (distance <= 5 && u_data->io->y_interval > 10)) { length = 10; memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); pango_layout_set_text(layout, label_string, -1); pango_layout_get_pixel_size(layout, &lwidth, NULL); gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, LEFT_BORDER - length - lwidth - 5, (guint32)(u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset - (i - u_data->io->min_y) * u_data->io->y_interval - 3), layout); } gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, LEFT_BORDER - length, (guint32)(u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset - (i - u_data->io->min_y) * u_data->io->y_interval), LEFT_BORDER, (guint32)(u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset - (i - u_data->io->min_y) * u_data->io->y_interval)); } } } else simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No Data Chunks sent"); }
void _HYConsoleWindow::_PaintStatusBar(Ptr,bool force) { if (GTK_WIDGET_MAPPED (theWindow)) { _Parameter vL; checkParameter (VerbosityLevelString, vL, 0.0); if (vL<-0.5 && !force) { clock_t curMeasure = clock(); _Parameter diff = 1.0/CLOCKS_PER_SEC*(curMeasure-lastMeasure); if (diff < -vL) { return; } lastMeasure = curMeasure; } if (!stripedFillGC) { SetUpStatusBarStuff (theWindow); } GdkRectangle wRC = {0,0,theWindow->allocation.width,HY_SCROLLER_WIDTH}, w2RC; if (!_hyConsoleWindowGC) { _hyConsoleWindowGC = gdk_gc_new (theWindow->window); gdk_gc_set_tile (_hyConsoleWindowGC, stripedFill); gdk_gc_set_line_attributes(_hyConsoleWindowGC,1,GDK_LINE_SOLID,GDK_CAP_NOT_LAST,GDK_JOIN_MITER); _hyConsoleLayout = pango_layout_new (screenPContext); pango_layout_set_width (_hyConsoleLayout, -1); statusBarBold = pango_font_description_new (); statusBarNormal = pango_font_description_new (); _HYFont consoleFont = {_HY_MONO_FONT,9,HY_FONT_PLAIN}; HYFont2PangoFontDesc (consoleFont,statusBarNormal); consoleFont.style = HY_FONT_BOLD; HYFont2PangoFontDesc (consoleFont,statusBarBold); } GdkPixmap * offBitmap = gdk_pixmap_new (theWindow->window, wRC.width, wRC.height,-1); if (offBitmap) { gdk_gc_set_fill (_hyConsoleWindowGC,GDK_TILED); gdk_draw_rectangle (offBitmap,_hyConsoleWindowGC,true,-1,-1,wRC.width+2,wRC.height+2); gdk_gc_set_fill (_hyConsoleWindowGC,GDK_SOLID); gdk_gc_set_foreground (_hyConsoleWindowGC,&_BLACKBRUSH_); gdk_draw_line(offBitmap,_hyConsoleWindowGC,0,0,wRC.width,0); pango_layout_set_font_description(_hyConsoleLayout,statusBarNormal); pango_layout_set_text(_hyConsoleLayout,fileName.getStr(),fileName.sLength); gdk_draw_layout(offBitmap,_hyConsoleWindowGC,33,wRC.height-13,_hyConsoleLayout); if (inputStatus == 1) { pango_layout_set_text(_hyConsoleLayout,cInput.getStr(),cInput.sLength); } else { pango_layout_set_text(_hyConsoleLayout,action.getStr(),action.sLength); } gdk_draw_layout(offBitmap,_hyConsoleWindowGC,193,wRC.height-13,_hyConsoleLayout); gdk_gc_set_foreground (_hyConsoleWindowGC,&_DARKGREYBRUSH_); gdk_draw_rectangle (offBitmap,_hyConsoleWindowGC,true,0,1,30,wRC.height-1); gdk_draw_rectangle (offBitmap,_hyConsoleWindowGC,true,150,1,40,wRC.height-1); gdk_draw_rectangle (offBitmap,_hyConsoleWindowGC,true,wRC.width-55,1,55,wRC.height-1); gdk_gc_set_foreground (_hyConsoleWindowGC,&_WHITEBRUSH_); pango_layout_set_font_description(_hyConsoleLayout,statusBarBold); pango_layout_set_text(_hyConsoleLayout,cState.getStr(),cState.sLength); gdk_draw_layout(offBitmap,_hyConsoleWindowGC,3,wRC.height-13,_hyConsoleLayout); pango_layout_set_text(_hyConsoleLayout,cTask.getStr(),cTask.sLength); gdk_draw_layout(offBitmap,_hyConsoleWindowGC,151,wRC.height-13,_hyConsoleLayout); pango_layout_set_font_description(_hyConsoleLayout,statusBarNormal); pango_layout_set_text(_hyConsoleLayout,timer.getStr(),timer.sLength); gdk_draw_layout(offBitmap,_hyConsoleWindowGC,wRC.width-53,wRC.height-13,_hyConsoleLayout); if (percentDone>0 || percentDone == -HY_SL_DONE) { GdkColor blackBrush = HYColorToGDKColor((_HYColor) { 80,80,80 }), orangeBrush = HYColorToGDKColor((_HYColor) { 255,153,102 }); gdk_gc_set_foreground (_hyConsoleWindowGC,&orangeBrush); gdk_draw_rectangle (offBitmap,_hyConsoleWindowGC,true,wRC.width-135,wRC.height-14,(percentDone>=0?percentDone:100.)*0.75,12); gdk_gc_set_foreground (_hyConsoleWindowGC,&blackBrush); gdk_draw_rectangle (offBitmap,_hyConsoleWindowGC,false,wRC.width-135,wRC.height-14,75,12); //gdk_gc_set_foreground (_hyConsoleWindowGC,&_WHITEBRUSH_); _String pLine; if (percentDone>=0) { pLine = _String(percentDone)&"%"; } else { pLine = "DONE"; } pango_layout_set_text(_hyConsoleLayout,pLine.getStr(),pLine.sLength); gdk_draw_layout(offBitmap,_hyConsoleWindowGC,wRC.width-107,wRC.height-13,_hyConsoleLayout); } } gdk_draw_drawable (theWindow->window, _hyConsoleWindowGC, offBitmap, 0, 0, theWindow->allocation.x, theWindow->allocation.y+theWindow->allocation.height-wRC.height, -1, -1); g_object_unref (offBitmap); } }
/*! \brief draw_infotext() draws the static textual data for the trace on the left hand side of the logviewer */ G_MODULE_EXPORT void draw_infotext(void) { /* Draws the textual (static) info on the left side of the window..*/ gint name_x = 0; gint name_y = 0; gint text_border = 10; gint info_ctr = 0; gint h = 0; gint i = 0; gint width = 0; gint height = 0; gint max = 0; Viewable_Value *v_value = NULL; PangoLayout *layout; GdkPixmap *pixmap = lv_data->pixmap; GtkAllocation allocation; gtk_widget_get_allocation(lv_data->darea,&allocation); h = allocation.height; gdk_draw_rectangle(pixmap, gtk_widget_get_style(lv_data->darea)->black_gc, TRUE, 0,0, lv_data->info_width,h); if (!lv_data->font_desc) { lv_data->font_desc = pango_font_description_from_string("courier"); pango_font_description_set_size(lv_data->font_desc,(10)*PANGO_SCALE); } if (!lv_data->highlight_gc) lv_data->highlight_gc = initialize_gc(lv_data->pixmap,HIGHLIGHT); lv_data->spread = (GINT)((float)h/(float)lv_data->active_traces); name_x = text_border; layout = gtk_widget_create_pango_layout(lv_data->darea,NULL); for (i=0;i<lv_data->active_traces;i++) { v_value = (Viewable_Value *)g_list_nth_data(lv_data->tlist,i); info_ctr = (lv_data->spread * (i+1))- (lv_data->spread/2); pango_layout_set_markup(layout,v_value->vname,-1); pango_layout_set_font_description(layout,lv_data->font_desc); pango_layout_get_pixel_size(layout,&width,&height); name_y = info_ctr - height - 2; if (width > max) max = width; gdk_draw_layout(pixmap,v_value->trace_gc,name_x,name_y,layout); } lv_data->info_width = max + (text_border * 2.5); for (i=0;i<lv_data->active_traces;i++) { gdk_draw_rectangle(pixmap, gtk_widget_get_style(lv_data->darea)->white_gc, FALSE, 0,i*lv_data->spread, lv_data->info_width-1,lv_data->spread); } }
/* Redraw the contents of the lcd display. * note: start BORDER pixels down and to the right. * TODO: we could be smart and only redraw what has changed. * This does this work correctly with varriable sized fonts. */ void drawStackLCD(){ int i; int curPos; int strt, stop; GdkGC *drawgc; #ifdef USE_PANGO PangoRectangle rect; int pango_pos; #endif /* draw the stack */ for(i=0; i<lcdHeight; i++){ /* draw the first unhighlighted section of the line */ strt = 0; if(dataSelected == DATA_SELECTED && i>=hiY1 && i<=hiY2){ stop = hiX1; if(stop > lcdWidth) stop = lcdWidth; } else { stop = lcdWidth; } if(stop-strt){ #ifdef USE_PANGO pango_layout_index_to_pos(pango_layout, strt, &rect); pango_pos = rect.x / PANGO_SCALE; gdk_window_clear_area(lcdDA->window, pango_pos + BORDER, i*fontH + BORDER, 2*fontW*(stop-strt), fontH); pango_layout_set_text(pango_layout, &lcdText[i][strt], stop-strt); gdk_draw_layout(lcdDA->window, lcdGC, pango_pos + BORDER + SHIFT, i*fontH + BORDER, pango_layout); #else gdk_window_clear_area(lcdDA->window, strt*fontW + BORDER, i*fontH + BORDER, fontW*(stop-strt), fontH); gdk_draw_text(lcdDA->window, lcdFont, lcdGC, strt*fontW + BORDER, (i+1)*fontH - fontD + BORDER, &lcdText[i][strt], stop-strt); #endif } /* draw the highlighted section of the line */ if(dataSelected == DATA_SELECTED && i>=hiY1 && i<=hiY2){ strt = hiX1; if(strt > lcdWidth) strt = lcdWidth; stop = hiX2+1; if(stop > lcdWidth) stop = lcdWidth; if(stop-strt){ #ifdef USE_PANGO pango_layout_index_to_pos(pango_layout, strt, &rect); pango_pos = rect.x / PANGO_SCALE; gdk_window_clear_area(lcdDA->window, pango_pos + BORDER, i*fontH + BORDER, 2*fontW*(stop-strt), fontH); gdk_draw_rectangle(lcdDA->window, lcdGC, TRUE, pango_pos + BORDER + SHIFT, i*fontH + BORDER, fontW*(stop-strt), fontH); pango_layout_set_text(pango_layout, &lcdText[i][strt], stop-strt); gdk_draw_layout(lcdDA->window, lcdHighlightGC, strt*fontW + BORDER + SHIFT, i*fontH + BORDER, pango_layout); #else gdk_draw_rectangle(lcdDA->window, lcdGC, TRUE, strt*fontW + BORDER, i*fontH + BORDER, fontW*(stop-strt), fontH); gdk_draw_text(lcdDA->window, lcdFont, lcdHighlightGC, strt*fontW + BORDER, (i+1)*fontH - fontD + BORDER, &lcdText[i][strt], stop-strt); #endif } } /* draw the last unhighlighted section of the line */ stop = lcdWidth; if(dataSelected == DATA_SELECTED && i>=hiY1 && i<=hiY2){ strt = hiX2+1; if(strt > lcdWidth) strt = lcdWidth; } else { strt = lcdWidth; } if(stop-strt){ #ifdef USE_PANGO pango_layout_index_to_pos(pango_layout, strt, &rect); pango_pos = rect.x / PANGO_SCALE; gdk_window_clear_area(lcdDA->window, pango_pos + BORDER, i*fontH + BORDER, 2*fontW*(stop-strt), fontH); pango_layout_set_text(pango_layout, &lcdText[i][strt], stop-strt); gdk_draw_layout(lcdDA->window, lcdGC, pango_pos + BORDER + SHIFT, i*fontH + BORDER, pango_layout); #else gdk_window_clear_area(lcdDA->window, strt*fontW + BORDER, i*fontH + BORDER, fontW*(stop-strt), fontH); gdk_draw_text(lcdDA->window, lcdFont, lcdGC, strt*fontW + BORDER, (i+1)*fontH - fontD + BORDER, &lcdText[i][strt], stop-strt); #endif } } /* draw the cursor */ if(isEditingEditor()){ curPos = cursorPosEditor(); if(curPos > lcdWidth){ curPos = lcdWidth; } if(dataSelected == DATA_SELECTED && curPos>=hiX1 && curPos<=hiX2 && lcdHeight-1>=hiY1 && lcdHeight-1<=hiY2) { drawgc = lcdHighlightGC; } else { drawgc = lcdGC; } /* hack: draw a white line to erase any old cursor in position 0. XDrawImageString dosen't cover this up like it does with an old cursor in any other position */ if(!(dataSelected == DATA_SELECTED && 0==hiX1 && lcdHeight-1>=hiY1 && lcdHeight-1<=hiY2)) { gdk_draw_line(lcdDA->window, lcdHighlightGC, BORDER + SHIFT, (lcdHeight-1) * fontH + BORDER, BORDER + SHIFT, lcdHeight * fontH - 1 + BORDER); } /* draw the cursor */ #ifdef USE_PANGO pango_layout_index_to_pos(pango_layout, curPos, &rect); pango_pos = rect.x / PANGO_SCALE + SHIFT + BORDER; gdk_draw_line(lcdDA->window, drawgc, pango_pos, (lcdHeight-1) * fontH + BORDER, pango_pos, lcdHeight * fontH - 1 + BORDER); /* Flush GDK display, seems to be needed in certain environments */ gdk_flush(); } else { pango_layout_index_to_pos(pango_layout, strt, &rect); pango_pos = rect.x / PANGO_SCALE + SHIFT + BORDER; if (pango_pos > lcdDA->allocation.width - BORDER && lcdWidth > 6) { lcdWidth -= 1; clearLCDwindow(); calcStackLCD(); drawStackLCD(); } } #else gdk_draw_line(lcdDA->window, drawgc, fontW * curPos + SHIFT + BORDER, (lcdHeight-1) * fontH + BORDER, fontW * curPos + SHIFT + BORDER, lcdHeight * fontH - 1 + BORDER); }
void draw_waveform(int chan_num, int highlight) { scope_data_t *dptr; int start, end, n, sample_len; scope_disp_t *disp; scope_chan_t *chan; double xscale, xoffset; double yscale, yfoffset, ypoffset, fy; hal_type_t type; int x1, y1, x2, y2, miny, maxy, midx, ct, pn; GdkPoint *points; int first=1; scope_horiz_t *horiz = &(ctrl_usr->horiz); cursor_valid = 0; disp = &(ctrl_usr->disp); chan = &(ctrl_usr->chan[chan_num - 1]); /* calculate a bunch of local vars */ sample_len = ctrl_shm->sample_len; xscale = disp->pixels_per_sample; xoffset = disp->horiz_offset; miny = -disp->height; maxy = 2 * disp->height; type = chan->data_type; yscale = disp->height / (-10.0 * chan->scale); yfoffset = chan->vert_offset; ypoffset = chan->position * disp->height; /* point to first sample in the record for this channel */ dptr = ctrl_usr->disp_buf + ctrl_usr->vert.data_offset[chan_num - 1]; /* point to first one that gets displayed */ start = disp->start_sample; end = disp->end_sample; ct = end - start + 1; points = alloca(2 * ct * sizeof(GdkPoint)); pn = 0; n = start; dptr += n * sample_len; /* set color to draw */ if (highlight) { gdk_gc_set_foreground(disp->context, &(disp->color_selected[chan_num-1])); } else { gdk_gc_set_foreground(disp->context, &(disp->color_normal[chan_num-1])); } x1 = y1 = 0; while (n <= end) { /* calc x coordinate of this point */ x2 = (n * xscale) - xoffset; /* calc y coordinate of this point */ switch (type) { case HAL_BIT: if (dptr->d_u8) { fy = 1.0; } else { fy = 0.0; }; break; case HAL_FLOAT: fy = dptr->d_real; break; case HAL_S32: fy = dptr->d_s32; break; case HAL_U32: fy = dptr->d_u32; break; default: fy = 0.0; break; } y2 = ((fy - yfoffset) * yscale) + ypoffset; if (y2 < miny) { y2 = miny; } else if (y2 > maxy) { y2 = maxy; } x1 = COORDINATE_CLIP(x1); x2 = COORDINATE_CLIP(x2); y1 = COORDINATE_CLIP(y1); y2 = COORDINATE_CLIP(y2); /* don't draw segment ending at first point */ if (n > start) { if(pn == 0) { points[pn].x = x1; points[pn].y = y1; pn++; } if(xscale < 1) { if(points[pn-1].x != x2 || points[pn-1].y != y2) { points[pn].x = x2; points[pn].y = y2; pn++; } } else { #if defined(DRAW_SMOOTH) /* this is a smoothed line display */ points[pn].x = x2; points[pn].y = y2; pn++; #elif defined(DRAW_STEPPED) /* this is a stepped one */ points[pn].x = x1; points[pn].y = y2; pn++; points[pn].x = x2; points[pn].y = y2; pn++; #else /* this is halfway between the two extremes */ midx = (x1 + x2) / 2; if(midx != x2) { points[pn].x = midx; points[pn].y = y2; pn++; } points[pn].x = x2; points[pn].y = y2; pn++; #endif } if(first && highlight && DRAWING && x2 >= motion_x) { first = 0; gdk_draw_arc(disp->win, disp->context, TRUE, x2-3, y2-3, 7, 7, 0, 360*64); cursor_value = fy; cursor_time = (n - ctrl_shm->pre_trig)*horiz->sample_period; cursor_valid = 1; } } /* end of this segment is start of next one */ x1 = x2; y1 = y2; /* point to next sample */ dptr += sample_len; n++; } if(pn) { lines(chan_num, points, pn); if(DRAWING) { PangoLayout *p; int y = points[0].y; char scale[HAL_NAME_LEN]; char buffer[2 * HAL_NAME_LEN]; int h; PangoRectangle r; format_scale_value(scale, sizeof(scale), chan->scale); snprintf(buffer, sizeof(buffer), "%s\n%s", chan->name, scale); p=gtk_widget_create_pango_layout(disp->drawing, buffer); pango_layout_get_extents(p, NULL, &r); h = PANGO_PIXELS(r.height); if(y < 0 || y+h > disp->height) // if the first sample isn't visible, try the zero value y = (0-yfoffset) * yscale + ypoffset; if(y < 0 || y+h > disp->height) // if that's not visible either, try the offset value y = ypoffset; conflict_avoid(&y, h); gdk_draw_layout(disp->win, disp->context, 5, y, p); g_object_unref(p); } } }
/** Draw a TextLine object. * @param object The renderer object to use for transform and output * @param text_line The TextLine to render, including font and height. * @param pos The position to render it at. * @param color The color to render it with. */ static void draw_text_line (DiaRenderer *object, TextLine *text_line, Point *pos, Alignment alignment, Color *color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkColor gdkcolor; int x,y; Point start_pos; PangoLayout* layout = NULL; const gchar *text = text_line_get_string(text_line); int height_pixels; real font_height = text_line_get_height(text_line); real scale = dia_transform_length(renderer->transform, 1.0); if (text == NULL || *text == '\0') return; /* Don't render empty strings. */ point_copy(&start_pos,pos); renderer_color_convert(renderer, color, &gdkcolor); height_pixels = dia_transform_length(renderer->transform, font_height); if (height_pixels < 2) { /* "Greeking" instead of making tiny font */ int width_pixels = dia_transform_length(renderer->transform, text_line_get_width(text_line)); gdk_gc_set_foreground(renderer->gc, &gdkcolor); gdk_gc_set_dashes(renderer->gc, 0, (gint8*)"\1\2", 2); dia_transform_coords(renderer->transform, start_pos.x, start_pos.y, &x, &y); gdk_draw_line(renderer->pixmap, renderer->gc, x, y, x + width_pixels, y); return; } else { start_pos.y -= text_line_get_ascent(text_line); start_pos.x -= text_line_get_alignment_adjustment (text_line, alignment); dia_transform_coords(renderer->transform, start_pos.x, start_pos.y, &x, &y); layout = dia_font_build_layout(text, text_line->font, dia_transform_length(renderer->transform, text_line->height)/20.0); #if defined(PANGO_VERSION_ENCODE) # if (PANGO_VERSION >= PANGO_VERSION_ENCODE(1,16,0)) /* I'd say the former Pango API was broken, i.e. leaky */ # define HAVE_pango_layout_get_line_readonly # endif #endif text_line_adjust_layout_line (text_line, #if defined(HAVE_pango_layout_get_line_readonly) pango_layout_get_line_readonly(layout, 0), #else pango_layout_get_line(layout, 0), #endif scale/20.0); if (renderer->highlight_color != NULL) { draw_highlighted_string(renderer, layout, x, y, &gdkcolor); } else { #if defined HAVE_FREETYPE { FT_Bitmap ftbitmap; int width, height; GdkPixbuf *rgba = NULL; width = dia_transform_length(renderer->transform, text_line_get_width(text_line)); height = dia_transform_length(renderer->transform, text_line_get_height(text_line)); if (width > 0) { int stride; guchar* pixels; int i,j; guint8 *graybitmap; initialize_ft_bitmap(&ftbitmap, width, height); pango_ft2_render_layout(&ftbitmap, layout, 0, 0); graybitmap = ftbitmap.buffer; rgba = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); stride = gdk_pixbuf_get_rowstride(rgba); pixels = gdk_pixbuf_get_pixels(rgba); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { pixels[i*stride+j*4] = gdkcolor.red>>8; pixels[i*stride+j*4+1] = gdkcolor.green>>8; pixels[i*stride+j*4+2] = gdkcolor.blue>>8; pixels[i*stride+j*4+3] = graybitmap[i*ftbitmap.pitch+j]; } } g_free(graybitmap); gdk_draw_pixbuf(renderer->pixmap, renderer->gc, rgba, 0, 0, x, y, width, height, GDK_RGB_DITHER_NONE, 0, 0); g_object_unref(G_OBJECT(rgba)); } } #else gdk_gc_set_foreground(renderer->gc, &gdkcolor); gdk_draw_layout(renderer->pixmap, renderer->gc, x, y, layout); #endif } /* !higlight_color */ g_object_unref(G_OBJECT(layout)); } /* !greeking */
/* Do the Pango text rendering. If called when pixmap is bg_text_layer, | it is a background draw. But if called from push_decal_pixmaps() it is | considered a push operation because it is being done whenever any panel | decals or krells are modified. In this case, Pango does the pixel pushing | instead of gkrellm as was done in pre 2.2.0. */ static void panel_draw_decal_text_list(GdkPixmap *pixmap, GkrellmDecal *d) { PangoLayout *layout; GdkRectangle rect; GList *list; GkrellmText *tx; GkrellmTextstyle *ts; gchar *s; gint x, y; layout = gtk_widget_create_pango_layout(gkrellm_get_top_window(), NULL); rect.x = d->x; rect.y = d->y; rect.width = d->w; rect.height = d->h; gdk_gc_set_clip_rectangle(_GK.text_GC, &rect); for (list = d->text_list; list; list = list->next) { tx = (GkrellmText *) list->data; if (!*tx->text) continue; ts = &tx->text_style; pango_layout_set_font_description(layout, ts->font); x = tx->x_off; y = tx->y_off; if (d->flags & DF_SCROLL_TEXT_DIVERTED) { if (d->flags & DF_SCROLL_TEXT_CENTER) pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); if (d->flags & DF_SCROLL_TEXT_H_LOOP) { x %= d->scroll_width; if (x > 0) x -= d->scroll_width; s = g_strconcat(tx->text, tx->text, NULL); if (d->flags & DF_TEXT_USE_MARKUP) pango_layout_set_markup(layout, s, strlen(s)); else pango_layout_set_text(layout, s, strlen(s)); g_free(s); } else if (d->flags & DF_SCROLL_TEXT_V_LOOP) { y %= d->scroll_height + d->y_ink; if (y > 0) y -= d->scroll_height + d->y_ink; s = g_strconcat(tx->text, "\n", tx->text, NULL); if (d->flags & DF_TEXT_USE_MARKUP) pango_layout_set_markup(layout, s, strlen(s)); else pango_layout_set_text(layout, s, strlen(s)); g_free(s); } else { if (d->flags & DF_TEXT_USE_MARKUP) pango_layout_set_markup(layout, tx->text,strlen(tx->text)); else pango_layout_set_text(layout, tx->text, strlen(tx->text)); } } else { if (d->flags & DF_TEXT_USE_MARKUP) pango_layout_set_markup(layout, tx->text, strlen(tx->text)); else pango_layout_set_text(layout, tx->text, strlen(tx->text)); } x += d->x; y += d->y; if (ts->effect) { gdk_gc_set_foreground(_GK.text_GC, &ts->shadow_color); gdk_draw_layout_with_colors(pixmap, _GK.text_GC, x + 1, y + 1, layout, &ts->shadow_color, NULL); } gdk_gc_set_foreground(_GK.text_GC, &ts->color); gdk_draw_layout(pixmap, _GK.text_GC, x, y, layout); } gdk_gc_set_clip_rectangle(_GK.text_GC, NULL); g_object_unref(layout); }
/* Smith.c: Routines for plotting Smith charts */ void gtk_graph_smith_plot_axes(GtkGraph *graph) { gint i ; gint x, y, w, h; gfloat ri[] = {0.2, 0.5, 1.0, 2.0, 5.0}, rxl[]={0.20, 0.5, 1, 2, 5}, coeff1, r, store, arc_angle; gfloat yend, xend; // The x and y co-ordinates of the end of the reactance lines gchar label[10]; gint text_width, text_height; gint xpos = 0, ypos = 0; // X and Y co-ordinate locations of radial labels PangoFontDescription *fontdesc = NULL; PangoLayout *layout = NULL; g_return_if_fail (graph != NULL); g_return_if_fail (GTK_IS_GRAPH (graph)); g_return_if_fail (GTK_WIDGET_REALIZED (graph)); g_return_if_fail (graph->graph_type == SMITH); fontdesc = pango_font_description_from_string("Sans 10"); layout = gtk_widget_create_pango_layout(GTK_WIDGET(graph), NULL); pango_layout_set_font_description(layout, fontdesc); /* Plot the concentric grid */ centre_x = user_origin_x + user_width / 2; centre_y = user_origin_y + user_width / 2; gdk_draw_arc(buffer, Gridcontext, FALSE, centre_x - graph->dependant->scale_factor, centre_y - graph->dependant->scale_factor, 2.0 * graph->dependant->scale_factor, 2.0 * graph->dependant->scale_factor, 0, 23040); for (i = 0 ; i < 5 ; i++) { /* Draw the circles of Constant Resistance */ coeff1 = ri[i] / (1.0+ri[i]); r = 1.0 / (ri[i] + 1.0); x = centre_x + (gint)((coeff1 - r) * graph->dependant->scale_factor); y = centre_y - (gint) (r * graph->dependant->scale_factor); w = 2.0 * r * graph->dependant->scale_factor; h = 2.0 * r * graph->dependant->scale_factor; gdk_draw_arc(buffer, Gridcontext, FALSE, x, y, w, h, 0, 23039); g_snprintf(label, 10, "%.0f", ri[i] * graph->smith_Z0); pango_layout_set_text(layout, label, -1); pango_layout_get_pixel_size(layout, &text_width, &text_height); xpos = x - text_width / 2; ypos = centre_y ; gdk_draw_layout(buffer, BandWcontext, xpos, ypos, layout); /* Draw the circles of Constant Reactance */ r = 1.0 / rxl[i]; x = centre_x + (gint) ((1 - r) * graph->dependant->scale_factor); w = 2.0 * r * graph->dependant->scale_factor; h = 2.0 * r * graph->dependant->scale_factor; /* Now Label the Constant Reactance curves */ g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0); pango_layout_set_text(layout, label, -1); pango_layout_get_pixel_size(layout, &text_width, &text_height); store = 2.0 * r/(r*r + 1); yend = store * (gfloat)(graph->dependant->scale_factor); xend = sqrt(1 - store*store) * (gfloat)(graph->dependant->scale_factor); switch(i) { case 0: case 1: g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0); pango_layout_set_text(layout, label, -1); pango_layout_get_pixel_size(layout, &text_width, &text_height); ypos = centre_y - (gint)yend; xpos = centre_x - (gint)xend; gdk_draw_layout(buffer, BandWcontext, xpos - text_width, ypos - text_height, layout); g_snprintf(label, 10, "-j%0.f", rxl[i]*graph->smith_Z0); pango_layout_set_text(layout, label, -1); ypos = centre_y + (gint)yend; gdk_draw_layout(buffer, BandWcontext, xpos - text_width, ypos, layout); arc_angle = atan((gfloat)(centre_x + graph->dependant->scale_factor - xpos)/(gfloat)((centre_y + r * graph->dependant->scale_factor)-ypos)) *180.0 / 3.141592654; gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y, w, h, 5760, (gint)(arc_angle * 64.0)); // Capacitive Circles gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y - (gint) ((2 *r) * graph->dependant->scale_factor), w, h, 17280 - (gint) (arc_angle*64.0), (gint) (arc_angle*64.0)); // Inductive Circles break; case 2: g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0); pango_layout_set_text(layout, label, -1); pango_layout_get_pixel_size(layout, &text_width, &text_height); ypos = centre_y - (gint)yend; xpos = centre_x - (gint)xend; gdk_draw_layout(buffer, BandWcontext, xpos - text_width/2, ypos - text_height, layout); g_snprintf(label, 10, "-j%0.f", rxl[i]*graph->smith_Z0); pango_layout_set_text(layout, label, -1); ypos = centre_y + yend; gdk_draw_layout(buffer, BandWcontext, xpos - text_width/2, ypos, layout); arc_angle = atan((gfloat)(centre_x + graph->dependant->scale_factor - xpos)/(gfloat)(ypos - (centre_y + r * graph->dependant->scale_factor))) *180.0 / 3.141592654; gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y, w, h, 5760, (gint) (arc_angle*64.0)); // Capacitive Circles gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y - (gint) ((2 *r) * graph->dependant->scale_factor), w, h, 17280 - (gint) (arc_angle*64.0), (gint) (arc_angle*64.0)); // Inductive Circles break; case 3: case 4: g_snprintf(label, 10, "+j%0.f", rxl[i]*graph->smith_Z0); pango_layout_set_text(layout, label, -1); pango_layout_get_pixel_size(layout, &text_width, &text_height); ypos = centre_y - (gint)yend; xpos = centre_x + (gint)xend; gdk_draw_layout(buffer, BandWcontext, xpos, ypos - text_height, layout); g_snprintf(label, 10, "-j%0.f", rxl[i]*graph->smith_Z0); pango_layout_set_text(layout, label, -1); ypos = centre_y + (gint)yend; gdk_draw_layout(buffer, BandWcontext, xpos, ypos, layout); arc_angle = atan((gfloat)(centre_x + graph->dependant->scale_factor - xpos)/(gfloat)(ypos - (centre_y + r * graph->dependant->scale_factor))) *180.0 / 3.141592654; gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y, w, h, 5760, 11520 - (gint) (arc_angle*64.0)); // Capacitive Circles gdk_draw_arc(buffer, Gridcontext, FALSE, x, centre_y - (gint) ((2 *r) * graph->dependant->scale_factor), w, h, 5760 + (gint) (arc_angle*64.0), 11520 - (gint) (arc_angle*64.0)); // Inductive Circles break; } } /* Draw the Real Axis */ gdk_draw_line(buffer, Gridcontext, centre_x - user_width/2, centre_y, centre_x + user_width/2, centre_y); g_snprintf(label, 10, "+inf"); pango_layout_set_text(layout, label, -1); pango_layout_get_pixel_size(layout, &text_width, &text_height); xpos = centre_x + user_width/2.0 - text_width/2 ; ypos = centre_y ; gdk_draw_layout(buffer, BandWcontext, xpos, ypos, layout); pango_font_description_free(fontdesc); g_object_unref(layout); }
void osd_wp() { PangoContext *context = NULL; PangoLayout *layout = NULL; PangoFontDescription *desc = NULL; GdkColor color; GdkGC *gc; gchar *buffer; static gchar distunit[3]; static int width = 0, height = 0; float distance; double unit_conv = 1; printf("** %s(): \n",__PRETTY_FUNCTION__); if(gpsdata && mouse_dx == 0 && mouse_dy == 0) { switch (global_speed_unit) { case 0: unit_conv = 1.0; g_sprintf(distunit, "%s", "km"); break; case 1 : unit_conv = 1.0 / 1.609344; g_sprintf(distunit, "%s", "m"); break; case 2 : unit_conv = 1.0 / 1.852; g_sprintf(distunit, "%s", "NM"); break; } distance = get_distance(deg2rad(gpsdata->fix.latitude), deg2rad(gpsdata->fix.longitude), global_wp.lat,global_wp.lon); buffer = g_strdup_printf("%.3f\n%.1f°", distance*unit_conv, rad2deg(gpsdata->fix.bearing)); context = gtk_widget_get_pango_context (map_drawable); layout = pango_layout_new (context); desc = pango_font_description_new(); pango_font_description_set_size (desc, 12 * PANGO_SCALE); pango_layout_set_font_description (layout, desc); pango_layout_set_text (layout, buffer, strlen(buffer)); gc = gdk_gc_new (map_drawable->window); color.red = 0; color.green = 0; color.blue = 0; gdk_gc_set_rgb_fg_color (gc, &color); gdk_draw_drawable ( map_drawable->window, map_drawable->style->fg_gc[GTK_WIDGET_STATE (map_drawable)], pixmap, global_drawingarea_width - width - 10, global_drawingarea_height - height - 10, global_drawingarea_width - width - 10, global_drawingarea_height - height - 10, width+10,height+10); pango_layout_get_pixel_size(layout, &width, &height); gdk_draw_layout(map_drawable->window, gc, global_drawingarea_width - width - 10, global_drawingarea_height - height -10, layout); g_free(buffer); pango_font_description_free (desc); g_object_unref (layout); g_object_unref (gc); } }
static gboolean video_area_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { GthMediaViewerPage *self = user_data; if (event->count > 0) return FALSE; if (self->priv->xwin_assigned && self->priv->has_video) return FALSE; if (self->priv->icon == NULL) { char *type; GIcon *icon; int size; type = NULL; if (self->priv->file_data != NULL) type = g_content_type_from_mime_type (gth_file_data_get_mime_type (self->priv->file_data)); if (type == NULL) type = g_content_type_from_mime_type ("text/plain"); icon = g_content_type_get_icon (type); size = widget->allocation.width; if (size > widget->allocation.height) size = widget->allocation.height; size = size / 3; self->priv->icon = _g_icon_get_pixbuf (icon, size, gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget))); g_object_unref (icon); g_free (type); } gdk_draw_rectangle (gtk_widget_get_window (widget), self->priv->has_video ? widget->style->black_gc : widget->style->text_gc[GTK_WIDGET_STATE (widget)], TRUE, event->area.x, event->area.y, event->area.width, event->area.height); if (self->priv->icon != NULL) { int icon_w, icon_h; int icon_x, icon_y; PangoRectangle logical_rect; int x, y; icon_w = gdk_pixbuf_get_width (self->priv->icon); icon_h = gdk_pixbuf_get_height (self->priv->icon); pango_layout_set_width (self->priv->caption_layout, PANGO_SCALE * (icon_w * 3 / 2)); pango_layout_get_extents (self->priv->caption_layout, NULL, &logical_rect); icon_x = (widget->allocation.width - icon_w) / 2; x = (widget->allocation.width - PANGO_PIXELS (logical_rect.width)) / 2 + PANGO_PIXELS (logical_rect.x); icon_y = (widget->allocation.height - (icon_h + PANGO_PIXELS (logical_rect.height))) / 2; y = icon_y + icon_h; gdk_draw_pixbuf (gtk_widget_get_window (widget), widget->style->base_gc[GTK_WIDGET_STATE (widget)], self->priv->icon, 0, 0, icon_x, icon_y, icon_w, icon_h, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_draw_layout (gtk_widget_get_window (widget), widget->style->base_gc[GTK_WIDGET_STATE (widget)], x, y, self->priv->caption_layout); } return FALSE; }
static void table_show_player_box(int player, int write_to_screen) { int x, y, w, h; const char *name = player_names[player]; const char *message = player_messages[player]; int string_y; int max_width = 0; static PangoLayout *layout = NULL; PangoRectangle rect; GdkGC *gc = table_style->fg_gc[GTK_WIDGET_STATE(table)]; static int max_height = 0; assert(table_ready); if (!layout) { /* This variable is static so we only allocate it once. */ layout = pango_layout_new(gdk_pango_context_get()); } pango_layout_set_font_description(layout, table_style->font_desc); get_text_box_pos(player, &x, &y); x++; y++; /* Clear the text box */ gdk_draw_rectangle(table_buf, table_style->bg_gc[GTK_WIDGET_STATE(table)], TRUE, x, y, TEXT_BOX_WIDTH - 1, TEXT_BOX_WIDTH - 1); x += XWIDTH; y += XWIDTH; w = h = TEXT_WIDTH; string_y = y; /* The y values we're going to draw at. */ /* Draw the name. */ if (name) { assert(strchr(name, '\n') == NULL); pango_layout_set_text(layout, name, -1); pango_layout_get_pixel_extents(layout, NULL, &rect); max_width = MAX(max_width, rect.width); max_height = MAX(max_height, rect.height); gdk_draw_layout(table_buf, gc, x + (w - rect.width) / 2, string_y, layout); string_y += max_height + 5; } /* Draw player message. */ if (message) { char *my_message = ggz_strdup(message); char *next = my_message; /* This is so ugly!! Is there no better way?? */ do { char *next_after_this = strchr(next, '\n'); if (next_after_this) { *next_after_this = '\0'; next_after_this++; } string_y += 3; pango_layout_set_text(layout, next, -1); pango_layout_get_pixel_extents(layout, NULL, &rect); max_height = MAX(max_height, rect.height); max_width = MAX(max_width, rect.width); gdk_draw_layout(table_buf, gc, x + 3, string_y, layout); string_y += rect.height; next = next_after_this; } while (next && *next); ggz_free(my_message); } /* FIXME: we shouldn't call table_setup() from *within* the drawing code */ if (set_min_text_width(string_y - y) || set_min_text_width(max_width)) { table_setup(); } if (write_to_screen) table_show_table(x, y, TEXT_BOX_WIDTH - 1, TEXT_BOX_WIDTH - 1); }
static gint gtk_databox_label_write_at (GdkPixmap *pixmap, PangoLayout *pl, GdkGC *gc, GtkDataboxCoord coord, GtkDataboxTextPosition position, gint distance, gboolean boxed) { gint hdist_text; gint vdist_text; gint hdist_box; gint vdist_box; gint width; gint height; gint offset = (boxed) ? 2 : 0; pango_layout_get_pixel_size (pl, &width, &height); switch (position) { case GTK_DATABOX_TEXT_N: hdist_text = - width/2; vdist_text = - distance - offset - height; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; case GTK_DATABOX_TEXT_NE: hdist_text = + distance + offset; vdist_text = - distance - offset - height; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; case GTK_DATABOX_TEXT_E: hdist_text = + distance + offset; vdist_text = - height/2; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; case GTK_DATABOX_TEXT_SE: hdist_text = + distance + offset; vdist_text = + distance + offset; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; case GTK_DATABOX_TEXT_S: hdist_text = - width/2; vdist_text = + distance + offset; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; case GTK_DATABOX_TEXT_SW: hdist_text = - distance - offset - width; vdist_text = + distance + offset; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; case GTK_DATABOX_TEXT_W: hdist_text = - distance - offset - width; vdist_text = - height/2; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; case GTK_DATABOX_TEXT_NW: hdist_text = - distance - offset - width; vdist_text = - distance - offset - height; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; break; default: hdist_text = - width/2; vdist_text = - height/2; hdist_box = hdist_text - offset; vdist_box = vdist_text - offset; } gdk_draw_layout (pixmap, gc, coord.x + hdist_text, coord.y + vdist_text, pl); if (boxed) gdk_draw_rectangle(pixmap, gc, FALSE, coord.x + hdist_box, coord.y + vdist_box, width + 3, height + 3); return (0); }
//__________________________________________________________________ void _HYButtonBar::_DisplayToolTip (void) { // TBI int h = _FindClickedButton (saveMousePosV,saveMousePosH); if ( h>=0 && h<toolTips.lLength) { _String* toolTip = (_String*)toolTips(h); if (toolTip->sLength) { GdkColor toolTipColor = HYColorToGDKColor((_HYColor) { 0xFF,0xCC,0x66 }); int bL, bT; GetButtonLoc (h,bL,bT,false); PangoLayout * ttText = pango_layout_new (screenPContext); PangoFontDescription * ttFont = pango_font_description_new(); HYFont2PangoFontDesc(_hyttDisplayFont,ttFont); pango_layout_set_font_description (ttText, ttFont); pango_layout_set_width(ttText, -1); pango_layout_set_text (ttText, toolTip->sData, toolTip->sLength); PangoRectangle extents; pango_layout_get_pixel_extents (ttText,&extents,nil); toolTipBounds.y = bT - 16; toolTipBounds.height = 16; if (toolTipBounds.y<0) { toolTipBounds.y = bT+buttonDim+1; } h = extents.width + 4; toolTipBounds.x = bL+(buttonDim-h-1)/2; if (toolTipBounds.x<=0) { toolTipBounds.x = 1; } toolTipBounds.width = h+2; h = toolTipBounds.x+toolTipBounds.width-parentWindow->allocation.width; if (h>0) { if (h>=toolTipBounds.x) { h = toolTipBounds.x-1; } toolTipBounds.x -= h; } toolTipBounds.x += parentWindow->allocation.x; toolTipBounds.y += parentWindow->allocation.y; gdk_gc_set_foreground(bbGC,&toolTipColor); gdk_draw_rectangle(parentWindow->window,bbGC,true,toolTipBounds.x, toolTipBounds.y, toolTipBounds.width, toolTipBounds.height); toolTipColor = HYColorToGDKColor((_HYColor) { 0,0,0 }); gdk_gc_set_foreground(bbGC,&toolTipColor); gdk_draw_rectangle(parentWindow->window,bbGC,false,toolTipBounds.x, toolTipBounds.y, toolTipBounds.width, toolTipBounds.height); gdk_gc_set_clip_rectangle (bbGC, &toolTipBounds); gdk_draw_layout (parentWindow->window, bbGC, toolTipBounds.x+3, toolTipBounds.y+3, ttText); gdk_gc_set_clip_rectangle (bbGC, nil); pango_font_description_free (ttFont); g_object_unref (ttText); } } }