Draw spiral and spiral labels with cairo
This commit is contained in:
committed by
Stéphane Lesimple
parent
d9f9094a56
commit
f3226aaf68
@@ -252,19 +252,17 @@ static void update_geometry(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void redraw_spiral_labels(void)
|
static void redraw_spiral_labels(void)
|
||||||
{ GdkWindow *d = gtk_widget_get_window(Closure->readLinearSpiral->widget);
|
{ cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(Closure->readLinearSpiral->widget));
|
||||||
int x,w,h;
|
int x,w,h;
|
||||||
int pos = 1;
|
int pos = 1;
|
||||||
|
|
||||||
/* Draw and label the spiral */
|
/* Draw and label the spiral */
|
||||||
|
|
||||||
x = 10;
|
x = 10;
|
||||||
gdk_gc_set_rgb_fg_color(Closure->drawGC, Closure->curveColor);
|
|
||||||
GuiSetText(Closure->readLinearCurve->layout, _("Medium state"), &w, &h);
|
GuiSetText(Closure->readLinearCurve->layout, _("Medium state"), &w, &h);
|
||||||
gdk_draw_layout(d, Closure->drawGC,
|
gdk_cairo_set_source_color(cr, Closure->curveColor);
|
||||||
x,
|
cairo_move_to(cr, x, Closure->readLinearCurve->topY - h - 5);
|
||||||
Closure->readLinearCurve->topY - h - 5,
|
pango_cairo_show_layout(cr, Closure->readLinearCurve->layout);
|
||||||
Closure->readLinearCurve->layout);
|
|
||||||
|
|
||||||
if(Closure->additionalSpiralColor == 0)
|
if(Closure->additionalSpiralColor == 0)
|
||||||
GuiDrawSpiralLabel(Closure->readLinearSpiral, Closure->readLinearCurve->layout,
|
GuiDrawSpiralLabel(Closure->readLinearSpiral, Closure->readLinearCurve->layout,
|
||||||
|
|||||||
48
src/spiral.c
48
src/spiral.c
@@ -111,15 +111,15 @@ void GuiFillSpiral(Spiral *spiral, GdkColor *color)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void GuiDrawSpiral(Spiral *spiral)
|
void GuiDrawSpiral(Spiral *spiral)
|
||||||
{ GdkDrawable *d;
|
{ cairo_t *cr;
|
||||||
double a;
|
double a;
|
||||||
int xi0,yi0,xo0,yo0;
|
double xi0,yi0,xo0,yo0;
|
||||||
double scale_i,scale_o;
|
double scale_i,scale_o;
|
||||||
int i;
|
int i;
|
||||||
GdkPoint points[4];
|
|
||||||
|
|
||||||
if(!spiral->widget) return;
|
if(!spiral->widget) return;
|
||||||
d = gtk_widget_get_window(spiral->widget);
|
cr = gdk_cairo_create(gtk_widget_get_window(spiral->widget));
|
||||||
|
cairo_set_line_width(cr, 1.0);
|
||||||
|
|
||||||
scale_i = spiral->startRadius;
|
scale_i = spiral->startRadius;
|
||||||
scale_o = spiral->startRadius + spiral->segmentSize;
|
scale_o = spiral->startRadius + spiral->segmentSize;
|
||||||
@@ -128,7 +128,7 @@ void GuiDrawSpiral(Spiral *spiral)
|
|||||||
xo0 = xi0 + spiral->segmentSize;
|
xo0 = xi0 + spiral->segmentSize;
|
||||||
|
|
||||||
for(a=0.0, i=0; i<spiral->segmentClipping; i++)
|
for(a=0.0, i=0; i<spiral->segmentClipping; i++)
|
||||||
{ int xi1,yi1,xo1,yo1;
|
{ double xi1,yi1,xo1,yo1;
|
||||||
double ring_expand = ((double)spiral->segmentSize * a) / (2.0*M_PI);
|
double ring_expand = ((double)spiral->segmentSize * a) / (2.0*M_PI);
|
||||||
|
|
||||||
a += atan((double)spiral->segmentSize / scale_o);
|
a += atan((double)spiral->segmentSize / scale_o);
|
||||||
@@ -140,20 +140,18 @@ void GuiDrawSpiral(Spiral *spiral)
|
|||||||
xo1 = spiral->mx + scale_o*cos(a);
|
xo1 = spiral->mx + scale_o*cos(a);
|
||||||
yo1 = spiral->my + scale_o*sin(a);
|
yo1 = spiral->my + scale_o*sin(a);
|
||||||
|
|
||||||
points[0].x = xi0; points[0].y = yi0;
|
|
||||||
points[1].x = xo0; points[1].y = yo0;
|
|
||||||
points[2].x = xo1; points[2].y = yo1;
|
|
||||||
points[3].x = xi1; points[3].y = yi1;
|
|
||||||
|
|
||||||
GdkColor *outline = spiral->segmentOutline[i] ? spiral->segmentOutline[i] : Closure->grid;
|
GdkColor *outline = spiral->segmentOutline[i] ? spiral->segmentOutline[i] : Closure->grid;
|
||||||
|
|
||||||
if (i == spiral->cursorPos)
|
cairo_move_to(cr, xi0, yi0);
|
||||||
gdk_gc_set_rgb_fg_color(Closure->drawGC, Closure->blueSector);
|
cairo_line_to(cr, xo0, yo0);
|
||||||
else
|
cairo_line_to(cr, xo1, yo1);
|
||||||
gdk_gc_set_rgb_fg_color(Closure->drawGC, spiral->segmentColor[i]);
|
cairo_line_to(cr, xi1, yi1);
|
||||||
gdk_draw_polygon(d, Closure->drawGC, TRUE, points, 4);
|
cairo_close_path(cr);
|
||||||
gdk_gc_set_rgb_fg_color(Closure->drawGC, outline);
|
gdk_cairo_set_source_color(cr, spiral->segmentColor[i]);
|
||||||
gdk_draw_polygon(d, Closure->drawGC, FALSE, points, 4);
|
cairo_fill_preserve(cr);
|
||||||
|
gdk_cairo_set_source_color(cr, outline);
|
||||||
|
cairo_stroke(cr);
|
||||||
|
|
||||||
xi0 = xi1; yi0 = yi1;
|
xi0 = xi1; yi0 = yi1;
|
||||||
xo0 = xo1; yo0 = yo1;
|
xo0 = xo1; yo0 = yo1;
|
||||||
@@ -182,18 +180,22 @@ void GuiSetSpiralSegmentColor(Spiral *spiral, GdkColor *color, GdkColor *outline
|
|||||||
|
|
||||||
void GuiDrawSpiralLabel(Spiral *spiral, PangoLayout *layout,
|
void GuiDrawSpiralLabel(Spiral *spiral, PangoLayout *layout,
|
||||||
char *text, GdkColor *color, int x, int line)
|
char *text, GdkColor *color, int x, int line)
|
||||||
{ GdkDrawable *d = gtk_widget_get_window(spiral->widget);
|
{ cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(spiral->widget));
|
||||||
int w,h,y;
|
int w,h,y;
|
||||||
|
|
||||||
GuiSetText(layout, text, &w, &h);
|
GuiSetText(layout, text, &w, &h);
|
||||||
if(line > 0) y = spiral->my + spiral->diameter / 2 + 20 + (line-1) * (10 + h);
|
if(line > 0) y = spiral->my + spiral->diameter / 2 + 20 + (line-1) * (10 + h);
|
||||||
else y = spiral->my - spiral->diameter / 2 - 20 - h + (line+1) * (10 + h);
|
else y = spiral->my - spiral->diameter / 2 - 20 - h + (line+1) * (10 + h);
|
||||||
gdk_gc_set_rgb_fg_color(Closure->drawGC, color);
|
cairo_rectangle(cr, x + 0.5, y+(h-6)/2 + 0.5, 6, 6);
|
||||||
gdk_draw_rectangle(d, Closure->drawGC, TRUE, x, y+(h-6)/2, 6, 6);
|
gdk_cairo_set_source_color(cr, color);
|
||||||
gdk_gc_set_rgb_fg_color(Closure->drawGC, Closure->grid);
|
cairo_fill_preserve(cr);
|
||||||
gdk_draw_rectangle(d, Closure->drawGC, FALSE, x, y+(h-6)/2, 6, 6);
|
gdk_cairo_set_source_color(cr, Closure->grid);
|
||||||
gdk_gc_set_rgb_fg_color(Closure->drawGC, Closure->foreground);
|
cairo_set_line_width(cr, 1.0);
|
||||||
gdk_draw_layout(d, Closure->drawGC, x+10, y, layout);
|
cairo_stroke(cr);
|
||||||
|
|
||||||
|
cairo_move_to(cr, x+10, y);
|
||||||
|
gdk_cairo_set_source_color(cr, Closure->foreground);
|
||||||
|
pango_cairo_show_layout(cr, layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user