static void d_draw_arc (GfigObject *obj, cairo_t *cr) { DobjPoints *pnt1, *pnt2, *pnt3; GdkPoint center_pnt; gdouble radius, minang, arcang; g_assert (obj != NULL); if (!obj) return; pnt1 = obj->points; pnt2 = pnt1 ? pnt1->next : NULL; pnt3 = pnt2 ? pnt2->next : NULL; if (! pnt3) return; draw_sqr (&pnt1->pnt, obj == gfig_context->selected_obj, cr); draw_sqr (&pnt2->pnt, obj == gfig_context->selected_obj, cr); draw_sqr (&pnt3->pnt, obj == gfig_context->selected_obj, cr); arc_drawing_details (obj, &minang, ¢er_pnt, &arcang, &radius, TRUE, FALSE); gfig_draw_arc (center_pnt.x, center_pnt.y, radius, radius, -minang, -(minang + arcang), cr); }
static void d_draw_line (GfigObject *obj, cairo_t *cr) { DobjPoints *spnt; DobjPoints *epnt; spnt = obj->points; if (!spnt) return; /* End-of-line */ epnt = spnt->next; while (spnt && epnt) { draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj, cr); /* Go around all the points drawing a line from one to the next */ gfig_draw_line (spnt->pnt.x, spnt->pnt.y, epnt->pnt.x, epnt->pnt.y, cr); spnt = epnt; epnt = epnt->next; } if (obj_creating == obj) draw_circle (&spnt->pnt, TRUE, cr); else draw_sqr (&spnt->pnt, obj == gfig_context->selected_obj, cr); }
static void d_draw_circle (GfigObject *obj, cairo_t *cr) { DobjPoints *center_pnt; DobjPoints *edge_pnt; gint radius; center_pnt = obj->points; if (!center_pnt) return; /* End-of-line */ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr); edge_pnt = center_pnt->next; if (!edge_pnt) return; radius = calc_radius (¢er_pnt->pnt, &edge_pnt->pnt); if (obj_creating == obj) draw_circle (&edge_pnt->pnt, TRUE, cr); else draw_sqr (&edge_pnt->pnt, obj == gfig_context->selected_obj, cr); gfig_draw_arc (center_pnt->pnt.x, center_pnt->pnt.y, radius, radius, 0, 360, cr); }
static void d_draw_rectangle (GfigObject *obj) { DobjPoints *first_pnt; DobjPoints *second_pnt; gint xmin, ymin; gint xmax, ymax; first_pnt = obj->points; if (!first_pnt) return; /* End-of-line */ second_pnt = first_pnt->next; if (!second_pnt) { g_warning ("Internal error - rectangle no edge pnt"); } draw_sqr (&first_pnt->pnt, obj == gfig_context->selected_obj); draw_sqr (&second_pnt->pnt, obj == gfig_context->selected_obj); xmin = MIN (gfig_scale_x (first_pnt->pnt.x), gfig_scale_x (second_pnt->pnt.x)); ymin = MIN (gfig_scale_y (first_pnt->pnt.y), gfig_scale_y (second_pnt->pnt.y)); xmax = MAX (gfig_scale_x (first_pnt->pnt.x), gfig_scale_x (second_pnt->pnt.x)); ymax = MAX (gfig_scale_y (first_pnt->pnt.y), gfig_scale_y (second_pnt->pnt.y)); gdk_draw_rectangle (gtk_widget_get_window (gfig_context->preview), gfig_gc, FALSE, xmin, ymin, xmax - xmin, ymax - ymin); }
static void d_draw_spiral (GfigObject *obj) { 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 start_pnt = { 0, 0 }; GdkPoint first_pnt; gboolean do_line = FALSE; gint clock_wise = 1; center_pnt = obj->points; if (!center_pnt) return; /* End-of-line */ /* First point is the center */ /* Just draw a control point around it */ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj); /* Next point defines the radius */ radius_pnt = center_pnt->next; /* this defines the vetices */ if (!radius_pnt) { #ifdef DEBUG g_warning ("Internal error in spiral - no vertice point \n"); #endif /* DEBUG */ return; } /* Other control point */ draw_sqr (&radius_pnt->pnt, obj == gfig_context->selected_obj); /* Have center and radius - draw spiral */ 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)); offset_angle = atan2 (shift_y, shift_x); clock_wise = obj->type_data / abs (obj->type_data); if (offset_angle < 0) offset_angle += 2.0 * G_PI; sp_cons = radius/(obj->type_data * 2 * G_PI + offset_angle); /* Lines */ ang_grid = 2.0 * G_PI / 180.0; for (loop = 0 ; loop <= abs (obj->type_data * 180) + clock_wise * (gint)RINT (offset_angle/ang_grid) ; 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); if (do_line) { /* Miss out points that come to the same location */ if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y) continue; gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y); } else { do_line = TRUE; first_pnt = calc_pnt; } start_pnt = calc_pnt; } }
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 (draw_cnts) { draw_sqr (&pnt1->pnt, obj == gfig_context->selected_obj); draw_sqr (&pnt2->pnt, obj == gfig_context->selected_obj); draw_sqr (&pnt3->pnt, obj == gfig_context->selected_obj); } 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_draw_star (GfigObject *obj, cairo_t *cr) { 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 start_pnt = { 0, 0 }; GdkPoint first_pnt = { 0, 0 }; gboolean do_line = FALSE; center_pnt = obj->points; if (!center_pnt) return; /* End-of-line */ /* First point is the center */ /* Just draw a control point around it */ draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr); /* Next point defines the radius */ outer_radius_pnt = center_pnt->next; /* this defines the vertices */ if (!outer_radius_pnt) { return; } inner_radius_pnt = outer_radius_pnt->next; /* this defines the vertices */ if (!inner_radius_pnt) { return; } /* Other control points */ if (obj == obj_creating) { draw_circle (&outer_radius_pnt->pnt, TRUE, cr); draw_circle (&inner_radius_pnt->pnt, TRUE, cr); } else { draw_sqr (&outer_radius_pnt->pnt, obj == gfig_context->selected_obj, cr); draw_sqr (&inner_radius_pnt->pnt, obj == gfig_context->selected_obj, cr); } /* Have center and radius - draw star */ 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); if (do_line) { /* Miss out points that come to the same location */ if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y) continue; gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y, cr); } else { do_line = TRUE; first_pnt = calc_pnt; } start_pnt = calc_pnt; } gfig_draw_line (first_pnt.x, first_pnt.y, start_pnt.x, start_pnt.y, cr); }