canvas-grid.cpp revision f4ab745a2deea8393eea28220acc073a973f225d
#define INKSCAPE_CANVAS_GRID_C
/*
*
* Copyright (C) Johan Engelen 2006-2007 <johan@shouraizou.nl>
* Copyright (C) Lauris Kaplinski 2000
*
*/
/* As a general comment, I am not exactly proud of how things are done.
* (for example the 'enable' widget and readRepr things)
* It does seem to work however. I intend to clean up and sort things out later, but that can take forever...
* Don't be shy to correct things.
*/
#include "sp-canvas-util.h"
#include "display-forward.h"
#include <libnr/nr-pixops.h>
#include "desktop-handles.h"
#include "svg/svg-color.h"
#include "xml/node-event-vector.h"
#include "sp-object.h"
#include "sp-namedview.h"
#include "inkscape.h"
#include "desktop.h"
#include "../document.h"
#include "prefs-utils.h"
#include "canvas-grid.h"
#include "canvas-axonomgrid.h"
namespace Inkscape {
N_("Rectangular grid"),
N_("Axonometric grid")
};
static gchar const *const grid_svgname[] = {
"xygrid",
"axonomgrid"
};
// ##########################################################
// Grid CanvasItem
static void grid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
static SPCanvasItemClass * parent_class;
grid_canvasitem_get_type (void)
{
static GtkType grid_canvasitem_type = 0;
if (!grid_canvasitem_type) {
"GridCanvasItem",
sizeof (GridCanvasItem),
sizeof (GridCanvasItemClass),
};
}
return grid_canvasitem_type;
}
static void
{
}
static void
{
}
static void
{
}
/**
*/
static void
{
}
}
static void
{
if (parent_class->update)
if (gridcanvasitem->grid) {
-1000000, -1000000,
1000000, 1000000);
}
}
// ##########################################################
// CanvasGrid
NULL, /* child_added */
NULL, /* child_removed */
NULL, /* content_changed */
NULL /* order_changed */
};
CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type)
{
if (repr) {
}
canvasitems = NULL;
}
CanvasGrid::~CanvasGrid()
{
if (repr) {
repr->removeListenerByData (this);
}
while (canvasitems) {
}
}
const char *
{
}
const char *
{
return grid_svgname[gridtype];
}
{
return gridtype;
}
char const *
{
}
char const *
{
return grid_svgname[type];
}
{
if (!typestr) return GRID_RECTANGULAR;
gint t = 0;
for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
}
return (GridType) t;
}
{
if (!typestr) return GRID_RECTANGULAR;
gint t = 0;
for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
}
return (GridType) t;
}
/*
* writes an <inkscape:grid> child to repr.
*/
void
{
if (!repr) return;
if (gridtype > GRID_MAXTYPENR) return;
// first create the child xml node, then hook it to repr. This order is important, to not set off listeners to repr before the new node is complete.
}
/*
* Creates a new CanvasGrid object of type gridtype
*/
CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype)
{
if (!doc) {
g_error("CanvasGrid::NewGrid - doc==NULL");
return NULL;
}
switch (gridtype) {
case GRID_RECTANGULAR:
case GRID_AXONOMETRIC:
}
return NULL;
}
/**
* creates a new grid canvasitem for the SPDesktop given as parameter. Keeps a link to this canvasitem in the canvasitems list.
*/
{
// Johan: I think for multiple desktops it is best if each has their own canvasitem,
// but share the same CanvasGrid object; that is what this function is for.
// check if there is already a canvasitem on this desktop linking to this grid
return NULL;
}
}
GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(sp_desktop_gridgroup(desktop), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) );
gtk_object_ref(GTK_OBJECT(item)); // since we're keeping a link to this item, we need to bump up the ref count
return item;
}
{
str += "</b>";
_("Determines whether to snap to this grid or not. Can be 'on' for invisible grids."),
_("Determines whether the grid is displayed or not. Objects are still snapped to invisible grids."),
// set widget values
}
}
void
CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gchar const *oldval, gchar const *newval, bool is_interactive, void *data)
{
if (!data)
return;
}
bool CanvasGrid::isEnabled()
{
return false;
}
return snapper->getEnabled();
}
// ##########################################################
// CanvasXYGrid
/**
* "attach_all" function
* A DIRECT COPY-PASTE FROM DOCUMENT-PROPERTIES.CPP TO QUICKLY GET RESULTS
*
* Helper function that attachs widgets in a 3xn table. The widgets come in an
* array that has two entries per table row. The two entries code for four
* possible cases: (0,0) means insert space in first column; (0, non-0) means
* widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
* (non-0, non-0) means two widgets in columns 2 and 3.
**/
#define SPACE_SIZE_X 15
#define SPACE_SIZE_Y 10
static inline void
{
} else {
if (arr[i+1]) {
} else if (arr[i]) {
} else {
}
}
++r;
}
}
{
if (!gridunit)
origin[NR::X] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "origin_x", 0.0), *(gridunit) );
origin[NR::Y] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "origin_y", 0.0), *(gridunit) );
spacing[NR::X] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "spacing_x", 0.0), *(gridunit) );
spacing[NR::Y] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "spacing_y", 0.0), *(gridunit) );
}
CanvasXYGrid::~CanvasXYGrid ()
{
}
/* fixme: Collect all these length parsing methods and think common sane API */
static gboolean
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
while (isspace(*u)) {
u += 1;
}
if (!*u) {
/* No unit specified - keep default */
*val = v;
return TRUE;
}
if (base & SP_UNIT_DEVICE) {
*val = v;
return TRUE;
}
}
if (base & SP_UNIT_ABSOLUTE) {
} else {
return FALSE;
}
*val = v;
return TRUE;
}
return FALSE;
}
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
return TRUE;
}
/** If the passed scalar is invalid (<=0), then set the widget and the scalar
to use the given old value.
@param oldVal Old value to use if the new one is invalid.
@param pTarget The scalar to validate.
@param widget Widget associated with the scalar.
*/
static void validateScalar(double oldVal,
double* pTarget)
{
// Avoid nullness.
return;
// Invalid new value?
if ( *pTarget <= 0 ) {
// If the old value is somehow invalid as well, then default to 1.
if ( oldVal <= 0 )
oldVal = 1;
// Reset the scalar and associated widget to the old value.
} //if
} //validateScalar
/** If the passed int is invalid (<=0), then set the widget and the int
to use the given old value.
@param oldVal Old value to use if the new one is invalid.
@param pTarget The int to validate.
@param widget Widget associated with the int.
*/
{
// Avoid nullness.
return;
// Invalid new value?
if ( *pTarget <= 0 ) {
// If the old value is somehow invalid as well, then default to 1.
if ( oldVal <= 0 )
oldVal = 1;
// Reset the int and associated widget to the old value.
} //if
} //validateInt
void
{
}
}
}
}
}
}
}
}
}
}
}
}
}
return;
}
/**
* Called when XML node attribute changed; updates dialog widgets if change was not done by widgets themselves.
*/
void
CanvasXYGrid::onReprAttrChanged(Inkscape::XML::Node */*repr*/, gchar const */*key*/, gchar const */*oldval*/, gchar const */*newval*/, bool /*is_interactive*/)
{
readRepr();
if ( ! (_wr.isUpdating()) )
}
{
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = new Inkscape::UI::Widget::RegisteredScalarUnit();
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = new Inkscape::UI::Widget::RegisteredScalarUnit();
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = new Inkscape::UI::Widget::RegisteredScalarUnit();
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = new Inkscape::UI::Widget::RegisteredScalarUnit();
Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol = new Inkscape::UI::Widget::RegisteredColorPicker();
Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gmcol = new Inkscape::UI::Widget::RegisteredColorPicker();
Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = new Inkscape::UI::Widget::RegisteredSuffixedInteger();
// initialize widgets:
_wr.setUpdating (true);
_("Color of the major (highlighted) grid lines"),
_("If set, displays dots at gridpoints instead of gridlines"),
);
_wr.setUpdating (false);
0, 0,
0, _rcb_dotted,
};
// set widget values
return table;
}
/**
* Update dialog widgets from object's values.
*/
void
{
/*
if (_wr.isUpdating()) return;
_wr.setUpdating (true);
_rcb_visible.setActive(visible);
if (snapper != NULL) {
_rcb_enabled.setActive(snapper->getEnabled());
}
_rumg.setUnit (gridunit);
gdouble val;
val = origin[NR::X];
val = sp_pixels_get_units (val, *(gridunit));
_rsu_ox.setValue (val);
val = origin[NR::Y];
val = sp_pixels_get_units (val, *(gridunit));
_rsu_oy.setValue (val);
val = spacing[NR::X];
double gridx = sp_pixels_get_units (val, *(gridunit));
_rsu_sx.setValue (gridx);
val = spacing[NR::Y];
double gridy = sp_pixels_get_units (val, *(gridunit));
_rsu_sy.setValue (gridy);
_rcp_gcol.setRgba32 (color);
_rcp_gmcol.setRgba32 (empcolor);
_rsi.setValue (empspacing);
_rcb_dotted.setActive(render_dotted);
_wr.setUpdating (false);
return;
*/
}
void
{
if (scaling_factor <= 1)
scaling_factor = 5;
/* First pass, go up to the major line spacing, then
keep increasing by two. */
scaling_factor = 2;
}
}
}
static void
{
guint r, g, b, a;
guchar *p;
r = NR_RGBA32_R (rgba);
g = NR_RGBA32_G (rgba);
b = NR_RGBA32_B (rgba);
a = NR_RGBA32_A (rgba);
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
p += 3;
}
}
}
static void
{
guint r, g, b, a;
guchar *p;
r = NR_RGBA32_R(rgba);
g = NR_RGBA32_G (rgba);
b = NR_RGBA32_B (rgba);
a = NR_RGBA32_A (rgba);
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
p += buf->buf_rowstride;
}
}
}
static void
{
guint r, g, b, a;
guchar *p;
r = NR_RGBA32_R (rgba);
g = NR_RGBA32_G (rgba);
b = NR_RGBA32_B (rgba);
a = NR_RGBA32_A (rgba);
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
}
}
void
{
//set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring)
} else {
}
if (!render_dotted) {
gdouble y;
} else {
}
}
gdouble x;
} else {
}
}
} else {
gdouble y;
gdouble x;
{
} else {
}
}
}
}
}
CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d)
{
}
{
LineList s;
return s;
}
for (unsigned int i = 0; i < 2; ++i) {
/* This is to make sure we snap to only visible grid lines */
// convert screen pixels to px
// FIXME: after we switch to snapping dist in screen pixels, this will be unnecessary
if (SP_ACTIVE_DESKTOP) {
}
}
return s;
}
void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const
{
SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
}
/**
* \return true if this Snapper will snap at least one kind of point.
*/
bool CanvasXYGridSnapper::ThisSnapperMightSnap() const
{
}
}; /* namespace Inkscape */
/*
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 :