static void d_paint_rectangle (GfigObject *obj) { DobjPoints *first_pnt; DobjPoints *second_pnt; gdouble dpnts[4]; g_assert (obj != NULL); /* Drawing rectangles is hard . * 1) select rectangle * 2) stroke it */ first_pnt = obj->points; if (!first_pnt) return; /* End-of-line */ second_pnt = first_pnt->next; if (!second_pnt) { g_error ("Internal error - rectangle no second pnt"); } dpnts[0] = (gdouble) MIN (first_pnt->pnt.x, second_pnt->pnt.x); dpnts[1] = (gdouble) MIN (first_pnt->pnt.y, second_pnt->pnt.y); dpnts[2] = (gdouble) MAX (first_pnt->pnt.x, second_pnt->pnt.x); dpnts[3] = (gdouble) MAX (first_pnt->pnt.y, second_pnt->pnt.y); /* Scale before drawing */ if (selvals.scaletoimage) scale_to_original_xy (&dpnts[0], 2); else scale_to_xy (&dpnts[0], 2); gimp_context_push (); gimp_context_set_feather (selopt.feather); gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius); gimp_image_select_rectangle (gfig_context->image_id, selopt.type, dpnts[0], dpnts[1], dpnts[2] - dpnts[0], dpnts[3] - dpnts[1]); gimp_context_pop (); paint_layer_fill (dpnts[0], dpnts[1], dpnts[2], dpnts[3]); if (obj->style.paint_type == PAINT_BRUSH_TYPE) gimp_edit_stroke (gfig_context->drawable_id); }
static void d_paint_line (GfigObject *obj) { DobjPoints *spnt; gdouble *line_pnts; gint seg_count = 0; gint i = 0; for (spnt = obj->points; spnt; spnt = spnt->next) seg_count++; if (!seg_count) return; /* no-line */ line_pnts = g_new0 (gdouble, 2 * seg_count + 1); /* Go around all the points drawing a line from one to the next */ for (spnt = obj->points; spnt; spnt = spnt->next) { line_pnts[i++] = spnt->pnt.x; line_pnts[i++] = spnt->pnt.y; } /* Scale before drawing */ if (selvals.scaletoimage) scale_to_original_xy (&line_pnts[0], i/2); else scale_to_xy (&line_pnts[0], i/2); /* One go */ if (obj->style.paint_type == PAINT_BRUSH_TYPE) { gfig_paint (selvals.brshtype, gfig_context->drawable_id, seg_count * 2, line_pnts); } g_free (line_pnts); }
static void d_paint_spiral (GfigObject *obj) { /* first point center */ /* Next point is radius */ gdouble *line_pnts; gint seg_count = 0; gint i = 0; DobjPoints *center_pnt; DobjPoints *radius_pnt; gint16 shift_x; gint16 shift_y; gdouble ang_grid; gdouble ang_loop; gdouble radius; gdouble offset_angle; gdouble sp_cons; gint loop; GdkPoint last_pnt = { 0, 0 }; gint clock_wise = 1; g_assert (obj != NULL); center_pnt = obj->points; if (!center_pnt || !center_pnt->next) return; /* no-line */ /* Go around all the points drawing a line from one to the next */ radius_pnt = center_pnt->next; /* this defines the vetices */ /* Have center and radius - get lines */ shift_x = radius_pnt->pnt.x - center_pnt->pnt.x; shift_y = radius_pnt->pnt.y - center_pnt->pnt.y; radius = sqrt ((shift_x * shift_x) + (shift_y * shift_y)); clock_wise = obj->type_data / abs (obj->type_data); offset_angle = atan2 (shift_y, shift_x); if (offset_angle < 0) offset_angle += 2.0 * G_PI; sp_cons = radius/(obj->type_data * 2.0 * G_PI + offset_angle); /* Lines */ ang_grid = 2.0 * G_PI / 180.0; /* count - */ seg_count = abs (obj->type_data * 180.0) + clock_wise * (gint)RINT (offset_angle/ang_grid); line_pnts = g_new0 (gdouble, 2 * seg_count + 3); for (loop = 0 ; loop <= seg_count; loop++) { gdouble lx, ly; GdkPoint calc_pnt; ang_loop = (gdouble)loop * ang_grid; lx = sp_cons * ang_loop * cos (ang_loop)*clock_wise; ly = sp_cons * ang_loop * sin (ang_loop); calc_pnt.x = RINT (lx + center_pnt->pnt.x); calc_pnt.y = RINT (ly + center_pnt->pnt.y); /* Miss out duped pnts */ if (!loop) { if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y) { continue; } } line_pnts[i++] = calc_pnt.x; line_pnts[i++] = calc_pnt.y; last_pnt = calc_pnt; } /* Scale before drawing */ if (selvals.scaletoimage) scale_to_original_xy (&line_pnts[0], i / 2); else scale_to_xy (&line_pnts[0], i / 2); /* One go */ if (obj->style.paint_type == PAINT_BRUSH_TYPE) { gfig_paint (selvals.brshtype, gfig_context->drawable_id, i, line_pnts); } g_free (line_pnts); }
static void arc_drawing_details (GfigObject *obj, gdouble *minang, GdkPoint *center_pnt, gdouble *arcang, gdouble *radius, gboolean draw_cnts, gboolean do_scale) { DobjPoints *pnt1 = NULL; DobjPoints *pnt2 = NULL; DobjPoints *pnt3 = NULL; DobjPoints dpnts[3]; gdouble ang1, ang2, ang3; gdouble maxang; pnt1 = obj->points; if (!pnt1) return; /* Not fully drawn */ pnt2 = pnt1->next; if (!pnt2) return; /* Not fully drawn */ pnt3 = pnt2->next; if (!pnt3) return; /* Still not fully drawn */ if (do_scale) { /* Adjust pnts for scaling */ /* Warning struct copies here! and casting to double <-> int */ /* Too complex fix me - to much hacking */ gdouble xy[2]; int j; dpnts[0] = *pnt1; dpnts[1] = *pnt2; dpnts[2] = *pnt3; pnt1 = &dpnts[0]; pnt2 = &dpnts[1]; pnt3 = &dpnts[2]; for (j = 0 ; j < 3; j++) { xy[0] = dpnts[j].pnt.x; xy[1] = dpnts[j].pnt.y; if (selvals.scaletoimage) scale_to_original_xy (&xy[0], 1); else scale_to_xy (&xy[0], 1); dpnts[j].pnt.x = xy[0]; dpnts[j].pnt.y = xy[1]; } } arc_details (&pnt1->pnt, &pnt2->pnt, &pnt3->pnt, center_pnt, radius); ang1 = arc_angle (&pnt1->pnt, center_pnt); ang2 = arc_angle (&pnt2->pnt, center_pnt); ang3 = arc_angle (&pnt3->pnt, center_pnt); /* Find min/max angle */ maxang = ang1; if (ang3 > maxang) maxang = ang3; *minang = ang1; if (ang3 < *minang) *minang = ang3; if (ang2 > *minang && ang2 < maxang) *arcang = maxang - *minang; else *arcang = maxang - *minang - 360; }
static void d_paint_star (GfigObject *obj) { /* first point center */ /* Next point is radius */ gdouble *line_pnts; gint seg_count = 0; gint i = 0; DobjPoints *center_pnt; DobjPoints *outer_radius_pnt; DobjPoints *inner_radius_pnt; gint16 shift_x; gint16 shift_y; gdouble ang_grid; gdouble ang_loop; gdouble outer_radius; gdouble inner_radius; gdouble offset_angle; gint loop; GdkPoint first_pnt = { 0, 0 }; GdkPoint last_pnt = { 0, 0 }; gboolean first = TRUE; gdouble *min_max; g_assert (obj != NULL); /* count - add one to close polygon */ seg_count = 2 * obj->type_data + 1; center_pnt = obj->points; if (!center_pnt || !seg_count) return; /* no-line */ line_pnts = g_new0 (gdouble, 2 * seg_count + 1); min_max = g_new (gdouble, 4); /* Go around all the points drawing a line from one to the next */ /* Next point defines the radius */ outer_radius_pnt = center_pnt->next; /* this defines the vetices */ if (!outer_radius_pnt) { #ifdef DEBUG g_warning ("Internal error in star - no outer vertice point \n"); #endif /* DEBUG */ g_free (line_pnts); g_free (min_max); return; } inner_radius_pnt = outer_radius_pnt->next; /* this defines the vetices */ if (!inner_radius_pnt) { #ifdef DEBUG g_warning ("Internal error in star - no inner vertice point \n"); #endif /* DEBUG */ g_free (line_pnts); g_free (min_max); return; } shift_x = outer_radius_pnt->pnt.x - center_pnt->pnt.x; shift_y = outer_radius_pnt->pnt.y - center_pnt->pnt.y; outer_radius = sqrt ((shift_x*shift_x) + (shift_y*shift_y)); /* Lines */ ang_grid = 2.0 * G_PI / (2.0 * (gdouble) obj->type_data); offset_angle = atan2 (shift_y, shift_x); shift_x = inner_radius_pnt->pnt.x - center_pnt->pnt.x; shift_y = inner_radius_pnt->pnt.y - center_pnt->pnt.y; inner_radius = sqrt ((shift_x*shift_x) + (shift_y*shift_y)); for (loop = 0 ; loop < 2 * obj->type_data ; loop++) { gdouble lx, ly; GdkPoint calc_pnt; ang_loop = (gdouble)loop * ang_grid + offset_angle; if (loop % 2) { lx = inner_radius * cos (ang_loop); ly = inner_radius * sin (ang_loop); } else { lx = outer_radius * cos (ang_loop); ly = outer_radius * sin (ang_loop); } calc_pnt.x = RINT (lx + center_pnt->pnt.x); calc_pnt.y = RINT (ly + center_pnt->pnt.y); /* Miss out duped pnts */ if (!first) { if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y) { continue; } } line_pnts[i++] = calc_pnt.x; line_pnts[i++] = calc_pnt.y; last_pnt = calc_pnt; if (first) { first_pnt = calc_pnt; first = FALSE; min_max[0] = min_max[2] = calc_pnt.x; min_max[1] = min_max[3] = calc_pnt.y; } else { min_max[0] = MIN (min_max[0], calc_pnt.x); min_max[1] = MIN (min_max[1], calc_pnt.y); min_max[2] = MAX (min_max[2], calc_pnt.x); min_max[3] = MAX (min_max[3], calc_pnt.y); } } line_pnts[i++] = first_pnt.x; line_pnts[i++] = first_pnt.y; /* Scale before drawing */ if (selvals.scaletoimage) { scale_to_original_xy (&line_pnts[0], i / 2); scale_to_original_xy (min_max, 2); } else { scale_to_xy (&line_pnts[0], i / 2); scale_to_xy (min_max, 2); } if (gfig_context_get_current_style ()->fill_type != FILL_NONE) { gimp_context_push (); gimp_context_set_antialias (selopt.antia); gimp_context_set_feather (selopt.feather); gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius); gimp_image_select_polygon (gfig_context->image_id, selopt.type, i, line_pnts); gimp_context_pop (); paint_layer_fill (min_max[0], min_max[1], min_max[2], min_max[3]); gimp_selection_none (gfig_context->image_id); } if (obj->style.paint_type == PAINT_BRUSH_TYPE) gfig_paint (selvals.brshtype, gfig_context->drawable_id, i, line_pnts); g_free (line_pnts); g_free (min_max); }
static void d_paint_circle (GfigObject *obj) { DobjPoints *center_pnt; DobjPoints *edge_pnt; gint radius; gdouble dpnts[4]; g_assert (obj != NULL); center_pnt = obj->points; if (!center_pnt) return; /* End-of-line */ edge_pnt = center_pnt->next; if (!edge_pnt) { g_error ("Internal error - circle no edge pnt"); } radius = calc_radius (¢er_pnt->pnt, &edge_pnt->pnt); dpnts[0] = (gdouble) center_pnt->pnt.x - radius; dpnts[1] = (gdouble) center_pnt->pnt.y - radius; dpnts[3] = dpnts[2] = (gdouble) radius * 2; /* Scale before drawing */ if (selvals.scaletoimage) scale_to_original_xy (&dpnts[0], 2); else scale_to_xy (&dpnts[0], 2); if (gfig_context_get_current_style ()->fill_type != FILL_NONE) { gimp_context_push (); gimp_context_set_antialias (selopt.antia); gimp_context_set_feather (selopt.feather); gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius); gimp_image_select_ellipse (gfig_context->image_id, selopt.type, dpnts[0], dpnts[1], dpnts[2], dpnts[3]); gimp_context_pop (); paint_layer_fill (center_pnt->pnt.x - radius, center_pnt->pnt.y - radius, center_pnt->pnt.x + radius, center_pnt->pnt.y + radius); gimp_selection_none (gfig_context->image_id); } /* Drawing a circle may be harder than stroking a circular selection, * but we have to do it or we will not be able to draw outside of the * layer. */ if (obj->style.paint_type == PAINT_BRUSH_TYPE) { const gdouble r = dpnts[2] / 2; const gdouble cx = dpnts[0] + r, cy = dpnts[1] + r; gdouble line_pnts[362]; gdouble angle = 0; gint i = 0; while (i < 362) { static const gdouble step = 2 * G_PI / 180; line_pnts[i++] = cx + r * cos (angle); line_pnts[i++] = cy + r * sin (angle); angle += step; } gfig_paint (selvals.brshtype, gfig_context->drawable_id, i, line_pnts); } }