static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) { if (gr->mode == draw_mode_begin || gr->mode == draw_mode_end) gdk_draw_lines(gr->drawable, gc->gc, (GdkPoint *)p, count); if (gr->mode == draw_mode_end || gr->mode == draw_mode_cursor) gdk_draw_lines(gr->widget->window, gc->gc, (GdkPoint *)p, count); }
static gboolean paint_ui(GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { GdkGC *gc; IBusHandwriteEngine * engine; LineStroke cl; int i; MatchedChar * matched; engine = (IBusHandwriteEngine *) (user_data); gc = gdk_gc_new(widget->window); gdk_draw_rectangle(widget->window, gc,0,0,0,199,199); gdk_draw_rectangle(widget->window, gc,0,200,0,399,199); puts(__func__); //已经录入的笔画 for (i = 0; i < engine->engine->strokes->len ; i++ ) { printf("drawing %d th line, total %d\n",i,engine->engine->strokes->len); cl = g_array_index(engine->engine->strokes,LineStroke,i); gdk_draw_lines(widget->window, gc, cl.points,cl.segments ); } //当下笔画 if ( engine->currentstroke.segments && engine->currentstroke.points ) gdk_draw_lines(widget->window, gc, engine->currentstroke.points, engine->currentstroke.segments); int munber = ibus_handwrite_recog_getmatch(engine->engine,&matched,0); //画10个侯选字 for (i = 0; i < munber ; ++i) { char drawtext[32]={0}; sprintf(drawtext,"%d.%s",i,matched[i].chr); PangoLayout * layout = gtk_widget_create_pango_layout(widget,drawtext); gdk_draw_layout(widget->window, gc, (i % 5) * 40 + 3, 205 + (20 * (i / 5)), layout); g_object_unref(layout); } g_object_unref(gc); return TRUE; }
/************************************************************************** Draws a rectangle with top left corner at (canvas_x, canvas_y), and width 'w' and height 'h'. It is drawn using the 'selection_gc' context, so the pixel combining function is XOR. This means that drawing twice in the same place will restore the image to its original state. NB: A side effect of this function is to set the 'selection_gc' color to COLOR_MAPVIEW_SELECTION. **************************************************************************/ void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h) { GdkPoint points[5]; struct color *pcolor; if (w == 0 || h == 0) { return; } pcolor = get_color(tileset, COLOR_MAPVIEW_SELECTION); if (!pcolor) { return; } /* gdk_draw_rectangle() must start top-left.. */ points[0].x = canvas_x; points[0].y = canvas_y; points[1].x = canvas_x + w; points[1].y = canvas_y; points[2].x = canvas_x + w; points[2].y = canvas_y + h; points[3].x = canvas_x; points[3].y = canvas_y + h; points[4].x = canvas_x; points[4].y = canvas_y; gdk_gc_set_foreground(selection_gc, &pcolor->color); gdk_draw_lines(map_canvas->window, selection_gc, points, ARRAY_SIZE(points)); }
void gtk_graph_smith_plot_traces(GtkGraph *graph) { gint i, n; GtkGraphTrace *tmp; gfloat CA, CB, CC, CD; GdkPoint *pts = 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); tmp = graph->traces; for (n = 0 ; n < graph->num_traces ; n++) { /* Make sure that there is some data in the trace */ if (tmp->Xdata == NULL || tmp->Ydata == NULL) continue; /* Assign the storage for the co-ordinates of each data point */ pts = (GdkPoint *) g_malloc ((tmp->num_points) * sizeof(GdkPoint)); /* The Xdata array contains the resistance whilst the Ydata array has the reactance */ CA = tmp->Xdata[0] - graph->smith_Z0; CB = tmp->Ydata[0]; CC = tmp->Xdata[0] + graph->smith_Z0; CD = tmp->Ydata[0]; pts[0].x = centre_x + (CA*CC + CB*CD)/(CC*CC + CD*CD) * graph->dependant->scale_factor; pts[0].y = centre_y - (CB*CC - CA*CD)/(CC*CC + CD*CD) * graph->dependant->scale_factor; for (i = 1 ; i < tmp->num_points ; i++) { CA = tmp->Xdata[i] - graph->smith_Z0; CB = tmp->Ydata[i]; CC = tmp->Xdata[i] + graph->smith_Z0; CD = tmp->Ydata[i]; pts[i].x = centre_x + (CA*CC + CB*CD)/(CC*CC + CD*CD) * graph->dependant->scale_factor; pts[i].y = centre_y - (CB*CC - CA*CD)/(CC*CC + CD*CD) * graph->dependant->scale_factor; } gdk_draw_lines (buffer, tmp->format->line_gc, pts, tmp->num_points);/* Draw the lines */ for (i = 1 ; i < tmp->num_points ; i++)/* and then draw the markers */ if (tmp->format->marker_type != GTK_GRAPH_MARKER_NONE) { gdk_gc_set_clip_origin(tmp->format->marker_gc, pts[i].x-5, pts[i].y-5); gdk_draw_pixmap(buffer, tmp->format->marker_gc, tmp->format->marker, 0, 0, pts[i].x-5, pts[i].y-5, -1, -1); } g_free(pts);// Free up all storage after use tmp = tmp->next;// and then move onto the next trace } }
void ink_draw_line (int x0, int y0, int x1, int y1) { GdkPoint points[2]; points[0].x=(gint)x0; points[0].y=(gint)y0; points[1].x=(gint)x1; points[1].y=(gint)y1; gdk_draw_lines(pCurrDrawable,pCurrGDKGC,points,2); }
void gpk_graph_draw(GtkWidget *widget, /* plot on this widged */ int n, /* number of data points */ gdouble *xcord, gdouble *ycord, /* data */ gdouble xmn,gdouble ymn, /* coordinates of corners */ gdouble xmx,gdouble ymx, int clear, /* clear old plot first */ char *title, /* add a title (only if clear=1) */ GdkColor *color) { GdkPixmap **ppixmap; GdkPoint *points; int i; gint16 width,height; GdkFont *fixed_font; GdkGC *gc; gc = gdk_gc_new(widget->window); gdk_gc_set_foreground(gc, color); if ((ppixmap=findpixmap(widget))) { width = widget->allocation.width; height = widget->allocation.height; if (clear) { /* white background */ gdk_draw_rectangle (*ppixmap, widget->style->white_gc, TRUE,0, 0,width,height); /* title */ #ifdef _WIN32 fixed_font = gdk_font_load ("-misc-fixed-large-r-*-*-*-100-*-*-*-*-*-*"); #else fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-100-*-*-*-*-iso8859-1"); #endif gdk_draw_text (*ppixmap,fixed_font, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], 0,10,title,strlen(title)); } points = g_malloc(n*sizeof(GdkPoint)); for (i=0; i<n ; i++) { points[i].x =.5+ ((xcord[i]-xmn)*(width-1)/(xmx-xmn)); points[i].y =.5+ ((ycord[i]-ymx)*(height-1)/(ymn-ymx)); } gdk_draw_lines(*ppixmap,gc,points,n); g_free(points); gpk_redraw(*ppixmap,widget); } gdk_gc_destroy(gc); }
/** * gimp_canvas_draw_lines: * @canvas: a #GimpCanvas widget * @style: one of the enumerated #GimpCanvasStyle's. * @points: a #GdkPoint array. * @num_points: the number of points in the array. * * Draws a set of lines connecting the specified points, in the * specified style. **/ void gimp_canvas_draw_lines (GimpCanvas *canvas, GimpCanvasStyle style, GdkPoint *points, gint num_points) { if (! gimp_canvas_ensure_style (canvas, style)) return; gdk_draw_lines (GTK_WIDGET (canvas)->window, canvas->gc[style], points, num_points); }
static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n) { int i; if (mode != CD_BEZIER && mode != CD_PATH) { for (i = 0; i < n; i++) { if (ctxcanvas->canvas->use_matrix) cdMatrixTransformPoint(ctxcanvas->xmatrix, poly[i].x, poly[i].y, &(poly[i].x), &(poly[i].y)); } } switch( mode ) { case CD_FILL: if (ctxcanvas->canvas->new_region) { GdkRegion* rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE); sCombineRegion(ctxcanvas, rgn); } else gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, TRUE, (GdkPoint*)poly, n); break; case CD_CLOSED_LINES: cdgdkCheckSolidStyle(ctxcanvas, 1); gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, FALSE, (GdkPoint*)poly, n); cdgdkCheckSolidStyle(ctxcanvas, 0); break; case CD_OPEN_LINES: cdgdkCheckSolidStyle(ctxcanvas, 1); gdk_draw_lines(ctxcanvas->wnd, ctxcanvas->gc, (GdkPoint*)poly, n); cdgdkCheckSolidStyle(ctxcanvas, 0); break; case CD_CLIP: ctxcanvas->clip_rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE); if (ctxcanvas->canvas->clip_mode == CD_CLIPPOLYGON) cdclip(ctxcanvas, CD_CLIPPOLYGON); break; case CD_BEZIER: cdSimPolyBezier(ctxcanvas->canvas, poly, n); break; case CD_PATH: cdSimPolyPath(ctxcanvas->canvas, poly, n); break; } }
void draw_samples() { GdkGC* gc; if(spectrum->window) { gc=gdk_gc_new(spectrum->window); gdk_gc_copy(gc,spectrum->style->black_gc); gdk_draw_rectangle(spectrum_pixmap,gc,TRUE,0,0,WIDTH,HEIGHT); gdk_gc_set_rgb_fg_color(gc,&plot_color); gdk_draw_lines(spectrum_pixmap,gc,iq_points,WIDTH); gtk_widget_queue_draw(spectrum); g_object_unref(gc); } }
gboolean expose_event_cb(GtkWidget *widget, GdkEventExpose *event, gpointer ptr) { UNUSED(ptr); UNUSED(event); int w = widget->allocation.width; int h = widget->allocation.height; gdk_draw_rectangle(widget->window, widget->style->black_gc, true, 0, 0, w, h); gdk_draw_lines(widget->window, widget->style->white_gc, scope_points, SCOPE_WIDTH); return true; }
static VALUE rg_draw_lines(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_lines(drawable, gc, points, n); g_free(points); return self; }
static void gdk_trace_line(HosPainterGdk *self, struct hos_point* points, const gint n_point, gint lvl, gboolean closed) { HosPainter *painter = HOS_PAINTER(self); /* * The next assertion would be nice, but would require * either breaking into the painter's structure (grokking out * the adjustment) or creating a selector for the painter's * n_lvl; does not seem worth it to be able to do this * assertion. */ /* assert(lvl < painter->n_lvl); */ /* set color */ { GdkColor *color = contour_get_color(painter->contour, lvl); /* FIXME adjustable linewidth, etc. */ gdk_gc_set_rgb_fg_color(self->gc, color); gdk_gc_set_line_attributes(self->gc, painter->contour->line_width, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER); } { GdkPoint gdk_points[n_point]; guint i; /* * Points must be copied from a glib-style array to a * C-style array for use in gdk_draw_lines. */ for (i = 0; i < n_point; ++i) { gdk_points[i].x = points[i].x; gdk_points[i].y = points[i].y; } if (closed) gdk_draw_polygon(self->drawable, self->gc, FALSE, gdk_points, n_point); else gdk_draw_lines(self->drawable, self->gc, gdk_points, n_point); } }
void iupdrvDrawPolygon(IdrawCanvas* dc, int* points, int count, long color, int style, int line_width) { GdkColor c; iupgdkColorSet(&c, color); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &c); if (style != IUP_DRAW_FILL) { iDrawSetLineWidth(dc, line_width); iDrawSetLineStyle(dc, style); } if (style == IUP_DRAW_FILL) gdk_draw_polygon(dc->pixmap, dc->pixmap_gc, TRUE, (GdkPoint*)points, count); else gdk_draw_lines(dc->pixmap, dc->pixmap_gc, (GdkPoint*)points, count); }
// Completely redraw the graph widget void graph_redraw(PluginData *pd) { GtkStyle *graph_style = gtk_widget_get_style (pd->graph); // clear the pixmap gdk_draw_rectangle (pd->graph_pixmap, graph_style->light_gc[GTK_STATE_NORMAL], TRUE, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT); // histogram for (int i=0; i<GRAPH_WIDTH; i++) { gdk_draw_line (pd->graph_pixmap, graph_style->mid_gc[GTK_STATE_NORMAL], i, GRAPH_HEIGHT * (1.0-pd->histogram[i]), i, GRAPH_HEIGHT); } // horizontal lines gdk_draw_line (pd->graph_pixmap, graph_style->dark_gc[GTK_STATE_NORMAL], 0, GRAPH_HEIGHT-1, GRAPH_WIDTH, GRAPH_HEIGHT-1); for (int i = 1; i < 10; i++) { int y = value_to_graph(i/2.0); gdk_draw_line (pd->graph_pixmap, graph_style->dark_gc[GTK_STATE_NORMAL], 0, y, GRAPH_WIDTH, y); } gdk_draw_line (pd->graph_pixmap, graph_style->dark_gc[GTK_STATE_NORMAL], 0, 0, GRAPH_WIDTH, 0); // vertical lines for (int i = 0; i < 10; i++) { int x = dist_to_graph(i)*GRAPH_WIDTH; gdk_draw_line (pd->graph_pixmap, graph_style->dark_gc[GTK_STATE_NORMAL], x, 0, x, GRAPH_HEIGHT); x = dist_to_graph(10*i)*GRAPH_WIDTH; gdk_draw_line (pd->graph_pixmap, graph_style->dark_gc[GTK_STATE_NORMAL], x, 0, x, GRAPH_HEIGHT); } gdk_draw_line (pd->graph_pixmap, graph_style->dark_gc[GTK_STATE_NORMAL], GRAPH_WIDTH-1, 0, GRAPH_WIDTH-1, GRAPH_HEIGHT); // wavelet marks float diagonal = sqrt(pd->image_width*pd->image_width + pd->image_height*pd->image_height)/2; for (int i = 0; i < WAVELET_DEPTH; i++) { int x = CLAMPED(dist_to_graph(scale_to_dist(i, diagonal))*GRAPH_WIDTH, 0, GRAPH_WIDTH-1); gdk_draw_line (pd->graph_pixmap, graph_style->text_gc[GTK_STATE_NORMAL], x, GRAPH_HEIGHT/2 - 2, x, GRAPH_HEIGHT/2 + 2); } // user curve gdk_draw_lines (pd->graph_pixmap, graph_style->text_gc[GTK_STATE_NORMAL], pd->curve_user.points, GRAPH_WIDTH); // user points for (int i = 0; i < pd->curve_user.count; i++) { gdk_draw_arc(pd->graph_pixmap, graph_style->text_gc[GTK_STATE_NORMAL], FALSE, pd->curve_user.user_points[i].x-GRAPH_HOTSPOT-1, pd->curve_user.user_points[i].y-GRAPH_HOTSPOT-1, GRAPH_HOTSPOT*2+1, GRAPH_HOTSPOT*2+1, 0, 64*360); } gdk_draw_drawable (pd->graph->window, graph_style->text_gc[GTK_STATE_NORMAL], pd->graph_pixmap, 0, 0, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT); }
static void draw(Scope *scope) { guint segcnt, i; GdkPoint pt[SCOPE_WIDTH+1]; GdkSegment seg[100], *segp; GtkWidget *widget; GtkAllocation allocation; GtkStyle *style; widget = GTK_WIDGET(scope); g_return_if_fail(gtk_widget_is_drawable(widget)); g_return_if_fail(scope->pixmap); gtk_widget_get_allocation(widget, &allocation); style = gtk_widget_get_style(widget); /* calculate grid segments */ for (segp = seg, segcnt = i = 0; i < SCOPE_WIDTH; i += SCOPE_WIDTH/8) { segp->x1 = segp->x2 = i; segp->y1 = SCOPE_HEIGHT/2-5; segp->y2 = SCOPE_HEIGHT/2+5; segp++; segcnt++; } segp->y1 = segp->y2 = SCOPE_HEIGHT/2; segp->x1 = 0; segp->x2 = SCOPE_WIDTH-1; segp++; segcnt++; /* copy data points */ for (i = 0; i < SCOPE_WIDTH; i++) { pt[i].x = i; pt[i].y = ((32767-(int)scope->y[i])*SCOPE_HEIGHT) >> 16; } /* clear window */ gdk_draw_rectangle(scope->pixmap, style->base_gc[gtk_widget_get_state(widget)], TRUE, 0, 0, allocation.width, allocation.height); /* draw grid */ gdk_draw_segments(scope->pixmap, scope->grid_gc, seg, segcnt); /* draw trace */ gdk_draw_lines(scope->pixmap, scope->trace_gc, pt, SCOPE_WIDTH); /* draw to screen */ gdk_draw_drawable(gtk_widget_get_window(widget), style->base_gc[gtk_widget_get_state(widget)], scope->pixmap, 0, 0, 0, 0, allocation.width, allocation.height); }
/* affiche flfigpetite dans le pixmap */ void tandrawfloat (GdkPixmap *pixmap, gboolean isoutline){ tanflfig *flfig=&flfigpetite; double dx,dy; GdkPoint pnts[PIECENBR*(PNTNBRMAX+1)]; int flpntnbr; int flpiecenbr; int i,j; tanfpnt *figfpnts; double zoom; tanpolytype polytype; if (isoutline){ zoom = widgetgrande->allocation.width*figgrande.zoom; dx=dxout; dy=dyout; } else{ zoom = widgetpetite->allocation.width*figpetite.zoom; dx=dxpetite; dy=dypetite; } flpiecenbr = flfig->flpiecenbr; for (i = 0; i<flpiecenbr; i++){ figfpnts = flfig->flpieces[i].flpnts; flpntnbr = flfig->flpieces[i].flpntnbr; polytype = flfig->flpieces[i].polytype; for (j = 0; j<flpntnbr; j++){ pnts[j].x = (gint16)(zoom*(figfpnts[j].posx-dx)+ARON); pnts[j].y = (gint16)(zoom*(figfpnts[j].posy-dy)+ARON); } if (isoutline){ pnts[flpntnbr] = pnts[0]; gdk_draw_lines(pixmap, tabgc[GCPIECEHLP], pnts, flpntnbr+1); } else { gdk_draw_polygon(pixmap, (polytype==TAN_POLYON) ? ( figpetite.reussi ? tabgc[GCPETITECHK] : tabgc[GCPETITEBG] ) : tabgc[GCPETITEFG], TRUE, pnts, flpntnbr); } } }
void lines(int chan_num, GdkPoint points[], gint npoints) { double dist; scope_disp_t *disp = &(ctrl_usr->disp); if(DRAWING) { gdk_draw_lines(disp->win, disp->context, points, npoints); } else { int x1 = points[0].x, y1 = points[0].y, x2, y2, i; for(i=1; i<npoints; i++) { x2 = points[i].x; y2 = points[i].y; dist = distance_point_line(select_x, select_y, x1, y1, x2, y2); if(dist < min_dist) { min_dist = dist; target = chan_num; } x1 = x2; y1 = y2; } } }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawPolyline (JNIEnv *env, jobject obj, jintArray xpoints, jintArray ypoints, jint npoints) { struct graphics *g; GdkPoint *points; g = (struct graphics *) NSA_GET_PTR (env, obj); points = translate_points (env, xpoints, ypoints, npoints, g->x_offset, g->y_offset); gdk_threads_enter (); gdk_draw_lines (g->drawable, g->gc, points, npoints); gdk_flush (); gdk_threads_leave (); g_free (points); }
static void plot_color_ramp( #ifdef CTK_GTK3 cairo_t *cr, #else GdkPixmap *gdk_pixmap, GdkGC *gdk_gc, #endif gushort *color_ramp, gint n_color_ramp_entries, gint width, gint height ) { gfloat x, dx, y; GdkPoint *gdk_points; gint i; gdk_points = g_malloc(width * sizeof(GdkPoint)); x = 0; dx = (n_color_ramp_entries - 1.0) / (width - 1.0); for (i = 0; i < width; i++, x += dx) { y = (gfloat) color_ramp[(int) (x + 0.5)]; gdk_points[i].x = i; gdk_points[i].y = height - ((height - 1) * (y / 65535) + 0.5); } #ifdef CTK_GTK3 cairo_set_line_width(cr, 1.0); cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); cairo_move_to(cr, gdk_points[0].x, gdk_points[0].y); for (i = 1; i < width; i++) { cairo_line_to(cr, gdk_points[i].x, gdk_points[i].y); } cairo_stroke(cr); #else gdk_draw_lines(gdk_pixmap, gdk_gc, gdk_points, width); #endif g_free(gdk_points); }
static void gtk_plot_gdk_draw_lines (GtkPlotPC *pc, GtkPlotPoint *points, gint numpoints) { GdkPoint *p = NULL; gint i; if(!GTK_PLOT_GDK(pc)->gc) return; if(!GTK_PLOT_GDK(pc)->drawable) return; p = (GdkPoint *)g_malloc(numpoints * sizeof(GdkPoint)); for(i = 0; i < numpoints; i++){ p[i].x = roundint(points[i].x); p[i].y = roundint(points[i].y); } gdk_draw_lines(GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc, p, numpoints); g_free(p); }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawPolygon (JNIEnv *env, jobject obj, jintArray xpoints, jintArray ypoints, jint npoints) { struct graphics *g; GdkPoint *points; g = (struct graphics *) NSA_GET_PTR (env, obj); points = translate_points (env, xpoints, ypoints, npoints, g->x_offset, g->y_offset); /* make sure the polygon is closed, per Java semantics. if it's not, we close it. */ if (points[0].x != points[npoints-1].x || points[0].y != points[npoints-1].y) points[npoints++] = points[0]; gdk_threads_enter (); gdk_draw_lines (g->drawable, g->gc, points, npoints); gdk_flush (); gdk_threads_leave (); g_free (points); }
int GCsplinegon(Gwidget_t * widget, int gpn, Gpoint_t * gpp, Ggattr_t * ap) { PIXpoint_t p0, p1, p2, p3; Grect_t gr; int n, i; if (gpn == 0) return 0; gr.o = gpp[0], gr.c = gpp[0]; for (i = 1; i < gpn; i++) { gr.o.x = min(gr.o.x, gpp[i].x); gr.o.y = min(gr.o.y, gpp[i].y); gr.c.x = max(gr.c.x, gpp[i].x); gr.c.y = max(gr.c.y, gpp[i].y); } Gppi = 1; if (Gppi >= Gppn) { n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR; Gppp = Marraygrow(Gppp, (long) n * PPSIZE); Gppn = n; } Gppp[0] = p3 = pdrawtopix(widget, gpp[0]); for (i = 1; i < gpn; i += 3) { p0 = p3; p1 = pdrawtopix(widget, gpp[i]); p2 = pdrawtopix(widget, gpp[i + 1]); p3 = pdrawtopix(widget, gpp[i + 2]); bezier(p0, p1, p2, p3); } setgattr(widget, ap); gdk_draw_lines(widget->w->window, GC, Gppp, Gppi); return 0; }
void MdispGtkView::InitializeOverlay() { MIL_TEXT_CHAR chText[80]; // Initialize overlay if not already done if ((!m_isOverlayInitialized) && (m_MilDisplay)) { //Only do it on a valid windowed display [CALL TO MIL] if (m_MilImage && m_MilDisplay ) { // Prepare overlay buffer // //////////////////////////// // Enable display overlay annotations. MdispControl(m_MilDisplay, M_OVERLAY, M_ENABLE); // Inquire the Overlay buffer associated with the displayed buffer [CALL TO MIL] MdispInquire(m_MilDisplay, M_OVERLAY_ID, &m_MilOverlayImage); // Clear the overlay to transparent. MdispControl(m_MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT); // Disable the overlay display update to accelerate annotations. MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_DISABLE); // Draw MIL monochrome overlay annotation * //***************************************** // Inquire MilOverlayImage size x and y [CALL TO MIL] long imageWidth = MbufInquire(m_MilOverlayImage,M_SIZE_X,M_NULL); long imageHeight = MbufInquire(m_MilOverlayImage,M_SIZE_Y,M_NULL); // Set graphic text to transparent background. [CALL TO MIL] MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT); // Set drawing color to white. [CALL TO MIL] MgraColor(M_DEFAULT, M_COLOR_WHITE); // Print a string in the overlay image buffer. [CALL TO MIL] MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5, " -------------------- "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5+25, " - MIL Overlay Text - "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5+50, " -------------------- "); // Print a green string in the green component overlay image buffer. [CALL TO MIL] MgraColor(M_DEFAULT, M_COLOR_GREEN); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5, " -------------------- "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5+25, " - MIL Overlay Text - "); MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5+50, " -------------------- "); // Draw GDI color overlay annotation * //************************************ // Disable hook to MIL error because control might not be supported MappControl(M_ERROR_HOOKS, M_DISABLE); // Create a device context to draw in the overlay buffer with GDI. [CALL TO MIL] MbufControl(m_MilOverlayImage, M_XPIXMAP_ALLOC, M_COMPENSATION_ENABLE); // Reenable hook to MIL error MappControl(M_ERROR_HOOKS, M_ENABLE); // Retrieve the XPIXMAP of the overlay [CALL TO MIL] Pixmap XPixmap = (Pixmap)MbufInquire(m_MilOverlayImage, M_XPIXMAP_HANDLE, M_NULL); /* convert it to gdkpixmap */ GdkPixmap *gdkpixmap = gdk_pixmap_foreign_new(XPixmap); if(gdkpixmap) { GdkPoint Hor[2]; GdkPoint Ver[2]; GdkColor color[3]; GdkFont *font = NULL; font = gdk_font_load ("-misc-*-*-r-*-*-*-140-*-*-*-*-*-1"); int i; /* get graphic context from pixmap*/ GdkGC *gc = gdk_gc_new(gdkpixmap); /* allocate colors */ gdk_color_parse("blue",&color[0]); gdk_color_parse("red",&color[1]); gdk_color_parse("yellow",&color[2]); for(i=0;i<3;i++) gdk_color_alloc(gdk_colormap_get_system(), &color[i]); /* set the foreground to our color */ gdk_gc_set_foreground(gc, &color[0]); // Draw a blue cross in the overlay buffer. Hor[0].x = 0; Hor[0].y = imageHeight/2; Hor[1].x = imageWidth; Hor[1].y = imageHeight/2; gdk_draw_lines(gdkpixmap,gc,Hor,2); Ver[0].x = imageWidth/2; Ver[0].y = 0; Ver[1].x = imageWidth/2; Ver[1].y = imageHeight; gdk_draw_lines(gdkpixmap,gc,Ver,2); // Write Red text in the overlay buffer. MosStrcpy(chText, 80, "X Overlay Text "); gdk_gc_set_foreground(gc, &color[1]); gdk_draw_string(gdkpixmap, font, gc, imageWidth*3/18, imageHeight*4/6, chText); // Write Yellow text in the overlay buffer. gdk_gc_set_foreground(gc, &color[2]); gdk_draw_string(gdkpixmap, font, gc, imageWidth*12/18, imageHeight*4/6, chText); /* flush */ gdk_display_flush(gdk_display_get_default()); /* Free graphic context.*/ g_object_unref(gc); // Delete created Pixmap. [CALL TO MIL] MbufControl(m_MilOverlayImage, M_XPIXMAP_FREE, M_DEFAULT); // Signal MIL that the overlay buffer was modified. [CALL TO MIL] MbufControl(m_MilOverlayImage, M_MODIFIED, M_DEFAULT); } // Now that overlay buffer is correctly prepared, we can show it [CALL TO MIL] MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_ENABLE); // Overlay is now initialized m_isOverlayInitialized = true; } } }
//----------------------------------------------------------------------------- // 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) ; } ; } ;
static void gtk_real_check_item_draw_indicator (GtkCheckItem *check_item, GdkRectangle *area) { GtkWidget *widget; GtkToggleButton *toggle_button; GtkStateType state_type; GdkRectangle restrict_area; GdkRectangle new_area; GdkGC *fg_gc = NULL; gint width, height; gint x, y; gint border; GdkWindow *window; g_return_if_fail (check_item != NULL); g_return_if_fail (GTK_IS_CHECK_ITEM (check_item)); widget = GTK_WIDGET (check_item); toggle_button = GTK_TOGGLE_BUTTON (check_item); if (GTK_WIDGET_DRAWABLE (check_item)) { window = widget->window; state_type = GTK_WIDGET_STATE (widget); if (state_type != GTK_STATE_NORMAL && state_type != GTK_STATE_PRELIGHT) state_type = GTK_STATE_NORMAL; restrict_area.x = widget->allocation.x + GTK_CONTAINER (widget)->border_width; restrict_area.y = widget->allocation.y + GTK_CONTAINER (widget)->border_width; restrict_area.width = widget->allocation.width - ( 2 * GTK_CONTAINER (widget)->border_width); restrict_area.height = widget->allocation.height - ( 2 * GTK_CONTAINER (widget)->border_width); if (gdk_rectangle_intersect (area, &restrict_area, &new_area)) { if (state_type != GTK_STATE_NORMAL) gtk_paint_flat_box (widget->style, window, state_type, GTK_SHADOW_ETCHED_OUT, area, widget, "checkitem", new_area.x, new_area.y, new_area.width, new_area.height); } x = widget->allocation.x + CHECK_ITEM_CLASS (widget)->indicator_spacing + GTK_CONTAINER (widget)->border_width; y = widget->allocation.y + (widget->allocation.height - CHECK_ITEM_CLASS (widget)->indicator_size) / 2; width = CHECK_ITEM_CLASS (widget)->indicator_size; height = CHECK_ITEM_CLASS (widget)->indicator_size; if(!GTK_BIN(widget)->child){ x = widget->allocation.x + widget->allocation.width/2 - width/2; y = widget->allocation.y + widget->allocation.height/2 - height/2; } if (GTK_TOGGLE_BUTTON (widget)->active) { state_type = GTK_STATE_ACTIVE; } else { state_type = GTK_STATE_NORMAL; } fg_gc = gdk_gc_new(window); gdk_gc_set_foreground(fg_gc, &widget->style->white); gdk_draw_rectangle(window, fg_gc, TRUE, x, y, width, height); gtk_draw_shadow (widget->style, window, GTK_STATE_NORMAL, GTK_SHADOW_IN, x, y, width, height); if(state_type == GTK_STATE_ACTIVE){ GdkPoint points[3]; border = widget->style->klass->xthickness; gdk_gc_set_foreground(fg_gc, &widget->style->black); x += border; y += border; points[0].x = x+1; points[0].y = y+6; points[1].x = x+3; points[1].y = y+height-2*border-2; points[2].x = x+width-2*border-2; points[2].y = y+3; gdk_draw_lines(window, fg_gc, points, 3); points[0].x = x+1; points[0].y = y+5; points[1].x = x+3; points[1].y = y+height-2*border-3; points[2].x = x+width-2*border-2; points[2].y = y+2; gdk_draw_lines(window, fg_gc, points, 3); points[0].x = x+1; points[0].y = y+4; points[1].x = x+3; points[1].y = y+height-2*border-4; points[2].x = x+width-2*border-2; points[2].y = y+1; gdk_draw_lines(window, fg_gc, points, 3); } } gdk_gc_unref(fg_gc); }
/*! \brief trace_update() updates a trace onscreen, this is run for EACH individual trace (yeah, not very optimized) \param redraw_all flag to redraw all or just recent data */ G_MODULE_EXPORT void trace_update(gboolean redraw_all) { GdkPixmap * pixmap = NULL; gint w = 0; gint h = 0; gfloat val = 0.0; gfloat last_val = 0.0; gfloat percent = 0.0; gfloat last_percent = 0.0; gint len = 0; gint lo_width; gint total = 0; guint last_index = 0; guint i = 0; gint j = 0; gint x = 0; gfloat log_pos = 0.0; gfloat newpos = 0.0; GArray *array = NULL; GdkPoint pts[2048]; /* Bad idea as static...*/ Viewable_Value *v_value = NULL; gint lv_zoom; /*static gulong sig_id = 0;*/ static GtkWidget *scale = NULL; GtkAllocation allocation; gtk_widget_get_allocation(lv_data->darea,&allocation); pixmap = lv_data->pixmap; lv_zoom = (GINT)DATA_GET(global_data,"lv_zoom"); /* if (sig_id == 0) sig_id = g_signal_handler_find(lookup_widget("logviewer_log_position_hscale"),G_SIGNAL_MATCH_FUNC,0,0,NULL,(gpointer)logviewer_log_position_change,NULL); */ if (!scale) scale = lookup_widget("logviewer_log_position_hscale"); w = allocation.width; h = allocation.height; log_pos = (gfloat)((GINT)OBJ_GET(lv_data->darea,"log_pos_x100"))/100.0; /*printf("log_pos is %f\n",log_pos);*/ /* Full screen redraw, only with configure events (usually) */ if ((GBOOLEAN)redraw_all) { lo_width = allocation.width-lv_data->info_width; for (i=0;i<g_list_length(lv_data->tlist);i++) { v_value = (Viewable_Value *)g_list_nth_data(lv_data->tlist,i); array = DATA_GET(v_value->object,v_value->data_source); len = array->len; if (len == 0) /* If empty */ { return; } /*printf("length is %i\n", len);*/ len *= (log_pos/100.0); /*printf("length after is %i\n", len);*/ /* Determine total number of points * that'll fit on the window * taking into account the scroll amount */ total = len < lo_width/lv_zoom ? len : lo_width/lv_zoom; /* Draw is reverse order, from right to left, * easier to think out in my head... :) */ for (x=0;x<total;x++) { val = g_array_index(array,gfloat,len-1-x); percent = 1.0-(val/(float)(v_value->upper-v_value->lower)); pts[x].x = w-(x*lv_zoom)-1; pts[x].y = (GINT) (percent*(h-2))+1; } gdk_draw_lines(pixmap, v_value->trace_gc, pts, total); if (v_value->highlight) { for (j=0;j<total;j++) pts[j].y -= 1; gdk_draw_lines(pixmap, gtk_widget_get_style(lv_data->darea)->white_gc, pts, total); for (j=0;j<total;j++) pts[j].y += 2; gdk_draw_lines(pixmap, gtk_widget_get_style(lv_data->darea)->white_gc, pts, total); } v_value->last_y = pts[0].y; v_value->last_index = len-1; /*printf ("last index displayed was %i from %i,%i to %i,%i\n",v_value->last_index,pts[1].x,pts[1].y, pts[0].x,pts[0].y );*/ } draw_valtext(TRUE); /*printf("redraw complete\n");*/ return; } /* Playback mode, playing from logfile.... */ if (DATA_GET(global_data,"playback_mode")) { for (i=0;i<g_list_length(lv_data->tlist);i++) { v_value = (Viewable_Value *)g_list_nth_data(lv_data->tlist,i); array = DATA_GET(v_value->object,v_value->data_source); last_index = v_value->last_index; if(last_index >= array->len) return; /*printf("got data from array at index %i\n",last_index+1);*/ val = g_array_index(array,gfloat,last_index+1); percent = 1.0-(val/(float)(v_value->upper-v_value->lower)); if (val > (v_value->max)) v_value->max = val; if (val < (v_value->min)) v_value->min = val; gdk_draw_line(pixmap, v_value->trace_gc, w-lv_zoom-1,v_value->last_y, w-1,(GINT)(percent*(h-2))+1); /*printf("drawing from %i,%i to %i,%i\n",w-lv_zoom-1,v_value->last_y,w-1,(GINT)(percent*(h-2))+1);*/ v_value->last_y = (GINT)((percent*(h-2))+1); v_value->last_index = last_index + 1; if (adj_scale) { newpos = 100.0*((gfloat)(v_value->last_index)/(gfloat)array->len); blocked=TRUE; gtk_range_set_value(GTK_RANGE(scale),newpos); blocked=FALSE; OBJ_SET(lv_data->darea,"log_pos_x100",GINT_TO_POINTER((GINT)(newpos*100.0))); adj_scale = FALSE; if (newpos >= 100) stop_tickler(LV_PLAYBACK_TICKLER); /* printf("playback reset slider to position %i\n",(GINT)(newpos*100.0));*/ } if (v_value->highlight) { gdk_draw_line(pixmap, gtk_widget_get_style(lv_data->darea)->white_gc, w-lv_zoom-1,v_value->last_y-1, w-1,(GINT)(percent*(h-2))); gdk_draw_line(pixmap, gtk_widget_get_style(lv_data->darea)->white_gc, w-lv_zoom-1,v_value->last_y+1, w-1,(GINT)(percent*(h-2))+2); } } draw_valtext(FALSE); return; } /* REALTIME mode... all traces updated at once.. */ for (i=0;i<g_list_length(lv_data->tlist);i++) { v_value = (Viewable_Value *)g_list_nth_data(lv_data->tlist,i); array = DATA_GET(v_value->object,v_value->data_source); val = g_array_index(array,gfloat, array->len-1); if (val > (v_value->max)) v_value->max = val; if (val < (v_value->min)) v_value->min = val; if (v_value->last_y == -1) v_value->last_y = (GINT)((percent*(h-2))+1); /* If watching at the edge (full realtime) */ if (log_pos >= 100) { v_value->last_index = array->len-1; percent = 1.0-(val/(float)(v_value->upper-v_value->lower)); gdk_draw_line(pixmap, v_value->trace_gc, w-lv_zoom-1,v_value->last_y, w-1,(GINT)(percent*(h-2))+1); } else { /* Watching somewhat behind realtime... */ last_index = v_value->last_index; last_val = g_array_index(array,gfloat,last_index); last_percent = 1.0-(last_val/(float)(v_value->upper-v_value->lower)); val = g_array_index(array,gfloat,last_index+1); percent = 1.0-(val/(float)(v_value->upper-v_value->lower)); v_value->last_index = last_index + 1; gdk_draw_line(pixmap, v_value->trace_gc, w-lv_zoom-1,(last_percent*(h-2))+1, w-1,(GINT)(percent*(h-2))+1); if (adj_scale) { newpos = 100.0*((gfloat)v_value->last_index/(gfloat)array->len); blocked = TRUE; gtk_range_set_value(GTK_RANGE(scale),newpos); blocked = FALSE; OBJ_SET(lv_data->darea,"log_pos_x100",GINT_TO_POINTER((GINT)(newpos*100.0))); adj_scale = FALSE; } } /* Draw the data.... */ v_value->last_y = (GINT)((percent*(h-2))+1); if (v_value->highlight) { gdk_draw_line(pixmap, gtk_widget_get_style(lv_data->darea)->white_gc, w-lv_zoom-1,v_value->last_y-1, w-1,(GINT)(percent*(h-2))); gdk_draw_line(pixmap, gtk_widget_get_style(lv_data->darea)->white_gc, w-lv_zoom-1,v_value->last_y+1, w-1,(GINT)(percent*(h-2))+2); } } /* Update textual data */ draw_valtext(FALSE); }
/** @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; }