sp-star.cpp revision d2bef3bfc06e52894f1d0763eeac83c870268f88
#define __SP_STAR_C__
/*
* <sodipodi:star> implementation
*
* Authors:
* Mitsuru Oka <oka326@parkcity.ne.jp>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <cstring>
#include <string>
#include "attributes.h"
#include "document.h"
#include "sp-star.h"
static Inkscape::XML::Node *sp_star_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static void sp_star_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
static SPShapeClass *parent_class;
sp_star_get_type (void)
{
if (!type) {
sizeof (SPStarClass),
sizeof (SPStar),
16,
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
star->r[0] = 1.0;
}
static void
{
}
sp_star_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
}
if (flags & SP_OBJECT_WRITE_EXT) {
}
g_free (d);
return repr;
}
static void
{
/* fixme: we should really collect updates */
switch (key) {
case SP_ATTR_SODIPODI_SIDES:
if (value) {
} else {
}
break;
case SP_ATTR_SODIPODI_CX:
}
break;
case SP_ATTR_SODIPODI_CY:
}
break;
case SP_ATTR_SODIPODI_R1:
star->r[0] = 1.0;
}
/* fixme: Need CLAMP (Lauris) */
break;
case SP_ATTR_SODIPODI_R2:
}
return;
case SP_ATTR_SODIPODI_ARG1:
if (value) {
} else {
}
break;
case SP_ATTR_SODIPODI_ARG2:
if (value) {
} else {
}
break;
break;
case SP_ATTR_INKSCAPE_ROUNDED:
if (value) {
} else {
}
break;
if (value) {
} else {
}
break;
default:
break;
}
}
static void
{
if (flags & (SP_OBJECT_MODIFIED_FLAG |
}
}
static void
{
if (write) {
} else {
}
}
}
static gchar *
{
// while there will never be less than 3 vertices, we still need to
// make calls to ngettext because the pluralization may be different
// for various numbers >=3. The singular form is used as the index.
"<b>Star</b> with %d vertices",
else
"<b>Polygon</b> with %d vertices",
}
/**
Returns a unit-length vector at 90 degrees to the direction from o to n
*/
{
}
/**
Returns a unique 32 bit int for a given point.
Obvious (but acceptable for my purposes) limits to uniqueness:
- returned value for x,y repeats for x+n*1024,y+n*1024
- returned value is unchanged when the point is moved by less than 1/1024 of px
*/
static guint32
{
return ((guint32)
65536 *
+
);
}
/**
Returns the next pseudorandom value using the Linear Congruential Generator algorithm (LCG)
with the parameters (m = 2^32, a = 69069, b = 1). These parameters give a full-period generator,
i.e. it is guaranteed to go through all integers < 2^32 (see http://random.mat.sbg.ac.at/~charly/server/server.html)
*/
static inline guint32
{
}
/**
Returns a random number in the range [-0.5, 0.5) from the given seed, stepping the given number of steps from the seed.
*/
static double
}
{
// the point whose neighboring curve handle we're calculating
// indices of previous and next points
// the other point type
// the neighbors of o; depending on flatsided, they're either the same type (polygon) or the other type (star)
Geom::Point prev = (star->flatsided? sp_star_get_xy (star, point, pi) : sp_star_get_xy (star, other, point == SP_STAR_POINT_KNOT2? index : pi));
Geom::Point next = (star->flatsided? sp_star_get_xy (star, point, ni) : sp_star_get_xy (star, other, point == SP_STAR_POINT_KNOT1? index : ni));
// prev-next midpoint
// point to which we direct the bissector of the curve handles;
// it's far enough outside the star on the perpendicular to prev-next through mid
// lengths of vectors to prev and next
// unit-length vector perpendicular to o-biss
// multiply rot by star->rounded coefficient and the distance to the star point; flip for next
if (previ) {
} else {
}
if (star->randomized == 0) {
// add the vector to o to get the final curvepoint
return o + ret;
} else {
// the seed corresponding to the exact point
// randomly rotate (by step 3 from the seed) and scale (by step 4) the vector
// the randomized corner point
return o_randomized + ret;
}
}
#define NEXT false
#define PREV true
static void
{
// perhaps we should convert all our shapes into LPEs without source path
// and with knotholders for parameters, then this situation will be handled automatically
// by disabling the entire stack (including the shape LPE)
g_warning ("The star shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as star will remove the bad LPE");
// unconditionally read the curve from d, if any, to preserve appearance
}
return;
}
// note that we pass randomized=true to sp_star_get_xy, because the curve must be randomized;
// other places that call that function (e.g. the knotholder) need the exact point
// draw 1st segment
if (not_rounded) {
} else {
}
}
// draw all middle segments
if (not_rounded) {
} else {
} else {
}
}
if (not_rounded) {
} else {
}
}
}
// draw last segment
if (!not_rounded) {
} else {
}
}
c->closepath();
/* Reset the shape'scurve to the "original_curve"
* This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/
if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) {
if (success) {
}
}
c->unref();
}
void
sp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1, gdouble r2, gdouble arg1, gdouble arg2, bool isflat, double rounded, double randomized)
{
if (isflat == false) {
} else {
}
}
static void sp_star_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs)
{
// We will determine the star's midpoint ourselves, instead of trusting on the base class
// Therefore setSnapObjectMidpoints() is set to false temporarily
}
// Help enforcing strict snapping, i.e. only return nodes when we're snapping nodes to nodes or a guide to nodes
return;
}
if (snapprefs->getSnapObjectMidpoints()) {
p.push_back(Inkscape::SnapCandidatePoint(SP_STAR(item)->center * i2d,Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT));
}
}
/**
* sp_star_get_xy: Get X-Y value as item coordinate system
* @star: star item
* @point: point type to obtain X-Y value
* @index: index of vertex
* @p: pointer to store X-Y value
* @randomized: false (default) if you want to get exact, not randomized point
*
* Initial item coordinate system is same as document coordinate system.
*/
{
// return the exact point
return xy;
} else { // randomize the point
// find out the seed, unique for this point so that randomization is the same so long as the original point is stationary
// the full range (corresponding to star->randomized == 1.0) is equal to the star's diameter
// find out the random displacement; x is controlled by step 1 from the seed, y by the step 2
Geom::Point shift (star->randomized * range * rnd (seed, 1), star->randomized * range * rnd (seed, 2));
// add the shift to the exact point
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :