/** * gimp_canvas_draw_points: * @canvas: a #GimpCanvas widget * @style: one of the enumerated #GimpCanvasStyle's. * @points: an array of GdkPoint x-y pairs. * @num_points: the number of points in the array * * Draws a set of one-pixel points at the locations given in the * @points argument, in the specified style. **/ void gimp_canvas_draw_points (GimpCanvas *canvas, GimpCanvasStyle style, GdkPoint *points, gint num_points) { if (! gimp_canvas_ensure_style (canvas, style)) return; gdk_draw_points (GTK_WIDGET (canvas)->window, canvas->gc[style], points, num_points); }
static VALUE rg_draw_points(VALUE self, VALUE rbgc, VALUE rbpoints) { GdkDrawable *drawable = _SELF(self); GdkGC *gc = GDK_GC(RVAL2GOBJ(rbgc)); long n; GdkPoint *points = RVAL2GDKPOINTS(rbpoints, &n); gdk_draw_points(drawable, gc, points, n); g_free(points); return self; }
static void ghid_draw_grid (void) { static GdkPoint *points = 0; static int npoints = 0; int x1, y1, x2, y2, n, i; double x, y; if (!Settings.DrawGrid) return; if (Vz (PCB->Grid) < MIN_GRID_DISTANCE) return; if (!gport->grid_gc) { if (gdk_color_parse (Settings.GridColor, &gport->grid_color)) { gport->grid_color.red ^= gport->bg_color.red; gport->grid_color.green ^= gport->bg_color.green; gport->grid_color.blue ^= gport->bg_color.blue; gdk_color_alloc (gport->colormap, &gport->grid_color); } gport->grid_gc = gdk_gc_new (gport->drawable); gdk_gc_set_function (gport->grid_gc, GDK_XOR); gdk_gc_set_foreground (gport->grid_gc, &gport->grid_color); } x1 = GRIDFIT_X (SIDE_X (gport->view_x0), PCB->Grid); y1 = GRIDFIT_Y (SIDE_Y (gport->view_y0), PCB->Grid); x2 = GRIDFIT_X (SIDE_X (gport->view_x0 + gport->view_width - 1), PCB->Grid); y2 = GRIDFIT_Y (SIDE_Y (gport->view_y0 + gport->view_height - 1), PCB->Grid); if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; } if (Vx (x1) < 0) x1 += PCB->Grid; if (Vy (y1) < 0) y1 += PCB->Grid; if (Vx (x2) >= gport->width) x2 -= PCB->Grid; if (Vy (y2) >= gport->height) y2 -= PCB->Grid; n = (int) ((x2 - x1) / PCB->Grid + 0.5) + 1; if (n > npoints) { npoints = n + 10; points = (GdkPoint *)realloc (points, npoints * sizeof (GdkPoint)); } n = 0; for (x = x1; x <= x2; x += PCB->Grid) { points[n].x = Vx (x); n++; } if (n == 0) return; for (y = y1; y <= y2; y += PCB->Grid) { int vy = Vy (y); for (i = 0; i < n; i++) points[i].y = vy; gdk_draw_points (gport->drawable, gport->grid_gc, points, n); } }
static void ghid_draw_grid (void) { static GdkPoint *points = 0; static int npoints = 0; Coord x1, y1, x2, y2, x, y; int n, i; render_priv *priv = gport->render_priv; if (!Settings.DrawGrid) return; if (Vz (PCB->Grid) < MIN_GRID_DISTANCE) return; if (!priv->grid_gc) { if (gdk_color_parse (Settings.GridColor, &gport->grid_color)) { gport->grid_color.red ^= gport->bg_color.red; gport->grid_color.green ^= gport->bg_color.green; gport->grid_color.blue ^= gport->bg_color.blue; gdk_color_alloc (gport->colormap, &gport->grid_color); } priv->grid_gc = gdk_gc_new (gport->drawable); gdk_gc_set_function (priv->grid_gc, GDK_XOR); gdk_gc_set_foreground (priv->grid_gc, &gport->grid_color); gdk_gc_set_clip_origin (priv->grid_gc, 0, 0); set_clip (priv, priv->grid_gc); } x1 = GridFit (SIDE_X (gport->view.x0), PCB->Grid, PCB->GridOffsetX); y1 = GridFit (SIDE_Y (gport->view.y0), PCB->Grid, PCB->GridOffsetY); x2 = GridFit (SIDE_X (gport->view.x0 + gport->view.width - 1), PCB->Grid, PCB->GridOffsetX); y2 = GridFit (SIDE_Y (gport->view.y0 + gport->view.height - 1), PCB->Grid, PCB->GridOffsetY); if (x1 > x2) { Coord tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { Coord tmp = y1; y1 = y2; y2 = tmp; } if (Vx (x1) < 0) x1 += PCB->Grid; if (Vy (y1) < 0) y1 += PCB->Grid; if (Vx (x2) >= gport->width) x2 -= PCB->Grid; if (Vy (y2) >= gport->height) y2 -= PCB->Grid; n = (x2 - x1) / PCB->Grid + 1; if (n > npoints) { npoints = n + 10; points = (GdkPoint *)realloc (points, npoints * sizeof (GdkPoint)); } n = 0; for (x = x1; x <= x2; x += PCB->Grid) { points[n].x = Vx (x); n++; } if (n == 0) return; for (y = y1; y <= y2; y += PCB->Grid) { for (i = 0; i < n; i++) points[i].y = Vy (y); gdk_draw_points (gport->drawable, priv->grid_gc, points, n); } }
/** @brief "expose-event"/"draw" signal callback @param widget where the signal was initiated @param cr pointer to cairo data OR event pointer to event data @param rt pointer to runtime data @return FALSE always */ static gboolean _e2_gesture_dialog_exposed_cb (GtkWidget *widget, #ifdef USE_GTK3_0 cairo_t *cr, #else GdkEventExpose *event, #endif E2_GestureDialogRuntime *rt) { //this arrives third during dialog creation, and also later printd (DEBUG, "drawing area exposed"); NEEDCLOSEBGL #ifdef USE_GTK2_18 if (gtk_widget_get_visible (widget)) #else if (GTK_WIDGET_VISIBLE (widget)) #endif { guint indx; gpointer points_array; GdkPoint *pd; #ifndef USE_GTK3_0 if (rt->gc == NULL) { GtkStyle *style = gtk_widget_get_style (widget); rt->gc = style->black_gc; } #endif gint npoints = stroke_get_count (rt->handle); if (npoints == 0) { if (rt->sequence != NULL) { printd (DEBUG, "recontruct stroke from runtime content"); stroke_fake (rt->handle, rt->sequence); npoints = stroke_replay (rt->handle, &points_array); } else { const gchar *sequence = gtk_entry_get_text (GTK_ENTRY (rt->entry)); if (*sequence != '\0') { printd (DEBUG, "recontruct stroke from entry content"); stroke_fake (rt->handle, sequence); npoints = stroke_replay (rt->handle, &points_array); } } if (npoints > 0) { #ifdef USE_GTK3_0 _e2_gesture_dialog_cairo_setup (cr, widget); for (pd = (GdkPoint *)points_array, indx = 0; indx < npoints; pd++, indx++) cairo_line_to (cr, (gdouble)pd->x, (gdouble)pd->y); cairo_stroke (cr); #else GtkAllocation alloc; # ifdef USE_GTK2_18 gtk_widget_get_allocation (widget, &alloc); # else alloc = widget->allocation; # endif stroke_get_scale (rt->handle, &alloc.x, &alloc.y); gfloat xfactor = (gfloat)alloc.width / alloc.x; gfloat yfactor = (gfloat)alloc.height / alloc.y; if (xfactor == 1. && yfactor == 1.) { //CHECKME what's happening here? gdk_draw_points (GDK_DRAWABLE (event->window), rt->gc, (GdkPoint *)points_array, npoints); } else { for (pd = (GdkPoint *)points_array, indx = 0; indx < npoints; pd++, indx++) { pd->x *= xfactor; pd->y *= yfactor; } gdk_draw_lines (GDK_DRAWABLE (event->window), rt->gc, (GdkPoint *)points_array, npoints); } #endif free (points_array); //not g_free() stroke_clear (rt->handle); } } else { npoints = stroke_replay (rt->handle, &points_array); printd (DEBUG, "exposure - redraw existing stroke with %d points", npoints); #ifdef USE_GTK3_0 _e2_gesture_dialog_cairo_setup (cr, widget); for (pd = (GdkPoint *)points_array, indx = 0; indx < npoints; pd++, indx++) cairo_line_to (cr, (gdouble)pd->x, (gdouble)pd->y); cairo_stroke (cr); #else gdk_draw_points (GDK_DRAWABLE (event->window), rt->gc, (GdkPoint *)points_array, npoints); #endif free (points_array); //not g_free() } } NEEDOPENBGL return FALSE; }
//----------------------------------------------------------------------------- // plot_area tylko dla wydajnosci void t_display_draw_plot(T_Display *w, T_Plot *p, GdkRegion *plot_area) { if (p->visible == FALSE) return ; GdkGC *gc ; GdkPoint *points ; gint npoints ; unsigned int i ; int wys = w->canvas->allocation.height ; npoints = p->points->len ; //printf ("t_display_draw_plot: GArray size %d\n", p->points->len) ; if (npoints > 0) { points = g_malloc(npoints*sizeof(GdkPoint)) ; // oblicz wspolrzedne pikseli for (i=0;i<npoints;i++) { points[i].x = time_to_pixel_x( g_array_index(p->points, T_Sample, i).czas, w) ; points[i].y = wys - temp_to_pixel_y( g_array_index(p->points, T_Sample, i).wartosc, w) ; } ; // ustaw wlasciwy kolor i ogranicz obszar rysowania charakterystyk gc = gdk_gc_new (GTK_LAYOUT(w->canvas)->bin_window); gdk_gc_set_rgb_fg_color(gc,&(p->color)) ; gdk_gc_set_clip_region(gc,plot_area) ; if (p->style == LINES) gdk_draw_lines (GTK_LAYOUT(w->canvas)->bin_window, gc, points, npoints) ; else if (p->style == POINTS) { gdk_draw_points (GTK_LAYOUT(w->canvas)->bin_window, gc, points, npoints) ; } else if (p->style == DIAMONDS) { GdkPoint p_diam[4] ; for (i=0;i<npoints;i++) { p_diam[0].x = points[i].x - 3 ; p_diam[0].y = points[i].y ; // lewy p_diam[1].x = points[i].x ; p_diam[1].y = points[i].y -3 ; // gorny p_diam[2].x = points[i].x + 3 ; p_diam[2].y = points[i].y ; // prawy p_diam[3].x = points[i].x ; p_diam[3].y = points[i].y +3 ; // dolny gdk_draw_polygon (GTK_LAYOUT(w->canvas)->bin_window, gc, FALSE, p_diam, 4); } ; } ; g_object_unref(gc) ; g_free(points) ; } ; } ;