app: add more accessors to GimpGrid and use them instead of grid->foo

This commit is contained in:
Michael Natterer
2014-05-21 21:44:28 +02:00
parent 5e2ded5020
commit d3966c2c90
4 changed files with 51 additions and 10 deletions

View File

@ -226,6 +226,37 @@ gimp_grid_set_property (GObject *object,
} }
} }
/* public functions */
GimpGridStyle
gimp_grid_get_style (GimpGrid *grid)
{
g_return_val_if_fail (GIMP_IS_GRID (grid), GIMP_GRID_SOLID);
return grid->style;
}
void
gimp_grid_get_fgcolor (GimpGrid *grid,
GimpRGB *fgcolor)
{
g_return_if_fail (GIMP_IS_GRID (grid));
g_return_if_fail (fgcolor != NULL);
*fgcolor = grid->fgcolor;
}
void
gimp_grid_get_bgcolor (GimpGrid *grid,
GimpRGB *bgcolor)
{
g_return_if_fail (GIMP_IS_GRID (grid));
g_return_if_fail (bgcolor != NULL);
*bgcolor = grid->bgcolor;
}
void void
gimp_grid_get_spacing (GimpGrid *grid, gimp_grid_get_spacing (GimpGrid *grid,
gdouble *xspacing, gdouble *xspacing,

View File

@ -59,6 +59,13 @@ struct _GimpGridClass
GType gimp_grid_get_type (void) G_GNUC_CONST; GType gimp_grid_get_type (void) G_GNUC_CONST;
GimpGridStyle gimp_grid_get_style (GimpGrid *grid);
void gimp_grid_get_fgcolor (GimpGrid *grid,
GimpRGB *fgcolor);
void gimp_grid_get_bgcolor (GimpGrid *grid,
GimpRGB *bgcolor);
void gimp_grid_get_spacing (GimpGrid *grid, void gimp_grid_get_spacing (GimpGrid *grid,
gdouble *xspacing, gdouble *xspacing,
gdouble *yspacing); gdouble *yspacing);

View File

@ -122,13 +122,18 @@ gimp_canvas_set_grid_style (GtkWidget *canvas,
cairo_t *cr, cairo_t *cr,
GimpGrid *grid) GimpGrid *grid)
{ {
GimpRGB fg;
GimpRGB bg;
g_return_if_fail (GTK_IS_WIDGET (canvas)); g_return_if_fail (GTK_IS_WIDGET (canvas));
g_return_if_fail (cr != NULL); g_return_if_fail (cr != NULL);
g_return_if_fail (GIMP_IS_GRID (grid)); g_return_if_fail (GIMP_IS_GRID (grid));
cairo_set_line_width (cr, 1.0); cairo_set_line_width (cr, 1.0);
switch (grid->style) gimp_grid_get_fgcolor (grid, &fg);
switch (gimp_grid_get_style (grid))
{ {
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
@ -136,17 +141,15 @@ gimp_canvas_set_grid_style (GtkWidget *canvas,
case GIMP_GRID_DOUBLE_DASH: case GIMP_GRID_DOUBLE_DASH:
if (grid->style == GIMP_GRID_DOUBLE_DASH) if (grid->style == GIMP_GRID_DOUBLE_DASH)
{ {
pattern = gimp_cairo_stipple_pattern_create (&grid->fgcolor, gimp_grid_get_bgcolor (grid, &bg);
&grid->bgcolor,
0); pattern = gimp_cairo_stipple_pattern_create (&fg, &bg, 0);
} }
else else
{ {
GimpRGB bg = { 0.0, 0.0, 0.0, 0.0 }; gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0);
pattern = gimp_cairo_stipple_pattern_create (&grid->fgcolor, pattern = gimp_cairo_stipple_pattern_create (&fg, &bg, 0);
&bg,
0);
} }
cairo_set_source (cr, pattern); cairo_set_source (cr, pattern);
@ -156,7 +159,7 @@ gimp_canvas_set_grid_style (GtkWidget *canvas,
case GIMP_GRID_DOTS: case GIMP_GRID_DOTS:
case GIMP_GRID_INTERSECTIONS: case GIMP_GRID_INTERSECTIONS:
case GIMP_GRID_SOLID: case GIMP_GRID_SOLID:
gimp_cairo_set_source_rgb (cr, &grid->fgcolor); gimp_cairo_set_source_rgb (cr, &fg);
break; break;
} }
} }

View File

@ -229,7 +229,7 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
while (yoffset > 0) while (yoffset > 0)
yoffset -= yspacing; yoffset -= yspacing;
switch (private->grid->style) switch (gimp_grid_get_style (private->grid))
{ {
case GIMP_GRID_DOTS: case GIMP_GRID_DOTS:
for (x = xoffset; x <= width; x += xspacing) for (x = xoffset; x <= width; x += xspacing)