/*
* <sodipodi:star> implementation
*
* Authors:
* Mitsuru Oka <oka326@parkcity.ne.jp>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Abhishek Sharma
*
* 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 <glib.h>
#include "attributes.h"
#include "document.h"
#include "sp-star.h"
sides(5),
center(0, 0),
flatsided(0),
rounded(0.0),
randomized(0.0)
{
this->r[0] = 1.0;
this->r[1] = 0.001;
}
}
// CPPIFY: see header file
this->readAttr( "sodipodi:cx" );
this->readAttr( "sodipodi:cy" );
this->readAttr( "sodipodi:sides" );
this->readAttr( "sodipodi:r1" );
this->readAttr( "sodipodi:r2" );
this->readAttr( "sodipodi:arg1" );
this->readAttr( "sodipodi:arg2" );
this->readAttr( "inkscape:flatsided" );
this->readAttr( "inkscape:rounded" );
this->readAttr( "inkscape:randomized" );
}
Inkscape::XML::Node* SPStar::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
}
if (flags & SP_OBJECT_WRITE_EXT) {
}
this->set_shape();
g_free(d);
// CPPIFY: see header file
return repr;
}
/* fixme: we should really collect updates */
switch (key) {
case SP_ATTR_SODIPODI_SIDES:
if (value) {
} else {
this->sides = 5;
}
break;
case SP_ATTR_SODIPODI_CX:
}
break;
case SP_ATTR_SODIPODI_CY:
}
break;
case SP_ATTR_SODIPODI_R1:
this->r[0] = 1.0;
}
/* fixme: Need CLAMP (Lauris) */
break;
case SP_ATTR_SODIPODI_R2:
this->r[1] = 0.0;
}
return;
case SP_ATTR_SODIPODI_ARG1:
if (value) {
} else {
this->arg[0] = 0.0;
}
break;
case SP_ATTR_SODIPODI_ARG2:
if (value) {
} else {
}
break;
this->flatsided = true;
} else {
this->flatsided = false;
}
break;
case SP_ATTR_INKSCAPE_ROUNDED:
if (value) {
} else {
this->rounded = 0.0;
}
break;
if (value) {
} else {
this->randomized = 0.0;
}
break;
default:
// CPPIFY: see header file
break;
}
}
if (flags & (SP_OBJECT_MODIFIED_FLAG |
this->set_shape();
}
// CPPIFY: see header file
}
this->set_shape();
if (write) {
} else {
}
}
}
if (this->flatsided == false)
return _("Star");
return _("Polygon");
}
// 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.
}
/**
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
// 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)
if (hasBrokenPathEffect()) {
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
this->setCurveBeforeLPE(cold);
}
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 (this->flatsided == false) {
if (not_rounded) {
} else {
sp_star_get_xy (this, SP_STAR_POINT_KNOT2, 0, true));
}
}
// draw all middle segments
if (not_rounded) {
} else {
if (this->flatsided == false) {
sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
} else {
sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
}
}
if (this->flatsided == false) {
if (not_rounded) {
} else {
sp_star_get_xy (this, SP_STAR_POINT_KNOT2, i, true));
}
}
}
// draw last segment
if (!not_rounded) {
if (this->flatsided == false) {
sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
} else {
sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
}
}
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)*/
this->setCurveInsync( c, TRUE);
this->setCurveBeforeLPE( c );
if (hasPathEffect() && pathEffectsEnabled()) {
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 {
}
}
void SPStar::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const {
// We will determine the star's midpoint ourselves, instead of trusting on the base class
// Therefore snapping to object midpoints is temporarily disabled
// CPPIFY: see header file
p.push_back(Inkscape::SnapCandidatePoint(this->center * i2dt,Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT));
}
}
{
// Only set transform with proportional scaling
return xform;
}
// Allow live effects
if (hasPathEffect() && pathEffectsEnabled()) {
return xform;
}
/* Calculate star start in parent coords. */
/* This function takes care of translation and scaling, we return whatever parts we can't
handle. */
if (s > 1e-9) {
ret[0] /= s;
ret[1] /= s;
ret[2] /= s;
ret[3] /= s;
} else {
ret[0] = 1.0;
}
this->r[0] *= s;
this->r[1] *= s;
/* Find start in item coords */
this->set_shape();
// Adjust stroke width
this->adjust_stroke(s);
// Adjust pattern fill
// Adjust gradient fill
return ret;
}
/**
* 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:fileencoding=utf-8:textwidth=99 :