summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-03-30 20:49:36 +0000
committerMarkus Engel <markus.engel@tum.de>2013-03-30 20:49:36 +0000
commitf51227a487f3d80e096c04470a969f5efa911a98 (patch)
treedf4dc96bef8d9dd3936ff0f74bdb78db8da4149e /src
parentRemoved unused function definitions (diff)
downloadinkscape-f51227a487f3d80e096c04470a969f5efa911a98.tar.gz
inkscape-f51227a487f3d80e096c04470a969f5efa911a98.zip
Turned all functions concerning SPRect into member functions.
(bzr r11608.1.60)
Diffstat (limited to 'src')
-rw-r--r--src/extension/internal/latex-text-renderer.cpp2
-rw-r--r--src/rect-context.cpp10
-rw-r--r--src/sp-flowtext.cpp2
-rw-r--r--src/sp-item.cpp2
-rw-r--r--src/sp-rect.cpp232
-rw-r--r--src/sp-rect.h41
-rw-r--r--src/widgets/rect-toolbar.cpp21
7 files changed, 148 insertions, 162 deletions
diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp
index ecc201733..9b707d355 100644
--- a/src/extension/internal/latex-text-renderer.cpp
+++ b/src/extension/internal/latex-text-renderer.cpp
@@ -405,7 +405,7 @@ Flowing in rectangle is possible, not in arb shape.
}
SPRect *frame = SP_RECT(frame_item);
- Geom::Rect framebox = sp_rect_get_rect(frame) * transform();
+ Geom::Rect framebox = frame->getRect() * transform();
// get position and alignment
// Align on topleft corner.
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index 040127ae3..40e1d5b2a 100644
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
@@ -469,15 +469,17 @@ static void sp_rect_drag(SPRectContext &rc, Geom::Point const pt, guint state)
Geom::Rect const r = Inkscape::snap_rectangular_box(desktop, rc.item, pt, rc.center, state);
- sp_rect_position_set(SP_RECT(rc.item), r.min()[Geom::X], r.min()[Geom::Y], r.dimensions()[Geom::X], r.dimensions()[Geom::Y]);
+ SP_RECT(rc.item)->setPosition(r.min()[Geom::X], r.min()[Geom::Y], r.dimensions()[Geom::X], r.dimensions()[Geom::Y]);
+
if ( rc.rx != 0.0 ) {
- sp_rect_set_rx (SP_RECT(rc.item), TRUE, rc.rx);
+ SP_RECT(rc.item)->setRx(true, rc.rx);
}
+
if ( rc.ry != 0.0 ) {
if (rc.rx == 0.0)
- sp_rect_set_ry (SP_RECT(rc.item), TRUE, CLAMP(rc.ry, 0, MIN(r.dimensions()[Geom::X], r.dimensions()[Geom::Y])/2));
+ SP_RECT(rc.item)->setRy(true, CLAMP(rc.ry, 0, MIN(r.dimensions()[Geom::X], r.dimensions()[Geom::Y])/2));
else
- sp_rect_set_ry (SP_RECT(rc.item), TRUE, CLAMP(rc.ry, 0, r.dimensions()[Geom::Y]));
+ SP_RECT(rc.item)->setRy(true, CLAMP(rc.ry, 0, r.dimensions()[Geom::Y]));
}
// status text
diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp
index 89b718781..6496d017d 100644
--- a/src/sp-flowtext.cpp
+++ b/src/sp-flowtext.cpp
@@ -649,7 +649,7 @@ SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, Geom::Point p0,
Geom::Coord const w = x1 - x0;
Geom::Coord const h = y1 - y0;
- sp_rect_position_set(rect, x0, y0, w, h);
+ rect->setPosition(x0, y0, w, h);
rect->updateRepr();
Inkscape::XML::Node *para_repr = xml_doc->createElement("svg:flowPara");
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index 4e157666a..ccc3e2313 100644
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
@@ -1230,7 +1230,7 @@ static void
sp_item_adjust_rects_recursive(SPItem *item, Geom::Affine advertized_transform)
{
if (SP_IS_RECT (item)) {
- sp_rect_compensate_rxry (SP_RECT(item), advertized_transform);
+ SP_RECT(item)->compensateRxRy(advertized_transform);
}
for (SPObject *o = item->children; o != NULL; o = o->next) {
diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp
index 813a29367..17a03ab19 100644
--- a/src/sp-rect.cpp
+++ b/src/sp-rect.cpp
@@ -239,42 +239,33 @@ void CRect::set_shape() {
/* fixme: Think (Lauris) */
-void
-sp_rect_position_set(SPRect *rect, gdouble x, gdouble y, gdouble width, gdouble height)
-{
- g_return_if_fail(rect != NULL);
- g_return_if_fail(SP_IS_RECT(rect));
-
- rect->x.computed = x;
- rect->y.computed = y;
- rect->width.computed = width;
- rect->height.computed = height;
+void SPRect::setPosition(gdouble x, gdouble y, gdouble width, gdouble height) {
+ this->x.computed = x;
+ this->y.computed = y;
+ this->width.computed = width;
+ this->height.computed = height;
- SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
-void
-sp_rect_set_rx(SPRect *rect, gboolean set, gdouble value)
-{
- g_return_if_fail(rect != NULL);
- g_return_if_fail(SP_IS_RECT(rect));
+void SPRect::setRx(bool set, gdouble value) {
+ this->rx._set = set;
- rect->rx._set = set;
- if (set) rect->rx.computed = value;
+ if (set) {
+ this->rx.computed = value;
+ }
- SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
-void
-sp_rect_set_ry(SPRect *rect, gboolean set, gdouble value)
-{
- g_return_if_fail(rect != NULL);
- g_return_if_fail(SP_IS_RECT(rect));
+void SPRect::setRy(bool set, gdouble value) {
+ this->ry._set = set;
- rect->ry._set = set;
- if (set) rect->ry.computed = value;
+ if (set) {
+ this->ry.computed = value;
+ }
- SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
Geom::Affine CRect::set_transform(Geom::Affine const& xform) {
@@ -339,156 +330,147 @@ Geom::Affine CRect::set_transform(Geom::Affine const& xform) {
/**
Returns the ratio in which the vector from p0 to p1 is stretched by transform
*/
-static gdouble
-vector_stretch(Geom::Point p0, Geom::Point p1, Geom::Affine xform)
-{
- if (p0 == p1)
+gdouble SPRect::vectorStretch(Geom::Point p0, Geom::Point p1, Geom::Affine xform) {
+ if (p0 == p1) {
return 0;
+ }
+
return (Geom::distance(p0 * xform, p1 * xform) / Geom::distance(p0, p1));
}
-void
-sp_rect_set_visible_rx(SPRect *rect, gdouble rx)
-{
+void SPRect::setVisibleRx(gdouble rx) {
if (rx == 0) {
- rect->rx.computed = 0;
- rect->rx._set = false;
+ this->rx.computed = 0;
+ this->rx._set = false;
} else {
- rect->rx.computed = rx / vector_stretch(
- Geom::Point(rect->x.computed + 1, rect->y.computed),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
- rect->rx._set = true;
+ this->rx.computed = rx / SPRect::vectorStretch(
+ Geom::Point(this->x.computed + 1, this->y.computed),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
+ this->rx._set = true;
}
- SP_OBJECT(rect)->updateRepr();
+
+ this->updateRepr();
}
-void
-sp_rect_set_visible_ry(SPRect *rect, gdouble ry)
-{
+void SPRect::setVisibleRy(gdouble ry) {
if (ry == 0) {
- rect->ry.computed = 0;
- rect->ry._set = false;
+ this->ry.computed = 0;
+ this->ry._set = false;
} else {
- rect->ry.computed = ry / vector_stretch(
- Geom::Point(rect->x.computed, rect->y.computed + 1),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
- rect->ry._set = true;
+ this->ry.computed = ry / SPRect::vectorStretch(
+ Geom::Point(this->x.computed, this->y.computed + 1),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
+ this->ry._set = true;
}
- SP_OBJECT(rect)->updateRepr();
+ this->updateRepr();
}
-gdouble
-sp_rect_get_visible_rx(SPRect *rect)
-{
- if (!rect->rx._set)
+gdouble SPRect::getVisibleRx() const {
+ if (!this->rx._set) {
return 0;
- return rect->rx.computed * vector_stretch(
- Geom::Point(rect->x.computed + 1, rect->y.computed),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
+ }
+
+ return this->rx.computed * SPRect::vectorStretch(
+ Geom::Point(this->x.computed + 1, this->y.computed),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
}
-gdouble
-sp_rect_get_visible_ry(SPRect *rect)
-{
- if (!rect->ry._set)
+gdouble SPRect::getVisibleRy() const {
+ if (!this->ry._set) {
return 0;
- return rect->ry.computed * vector_stretch(
- Geom::Point(rect->x.computed, rect->y.computed + 1),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
+ }
+
+ return this->ry.computed * SPRect::vectorStretch(
+ Geom::Point(this->x.computed, this->y.computed + 1),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
}
-Geom::Rect
-sp_rect_get_rect (SPRect *rect)
-{
- Geom::Point p0 = Geom::Point(rect->x.computed, rect->y.computed);
- Geom::Point p2 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
+Geom::Rect SPRect::getRect() const {
+ Geom::Point p0 = Geom::Point(this->x.computed, this->y.computed);
+ Geom::Point p2 = Geom::Point(this->x.computed + this->width.computed, this->y.computed + this->height.computed);
+
return Geom::Rect(p0, p2);
}
-void
-sp_rect_compensate_rxry(SPRect *rect, Geom::Affine xform)
-{
- if (rect->rx.computed == 0 && rect->ry.computed == 0)
+void SPRect::compensateRxRy(Geom::Affine xform) {
+ if (this->rx.computed == 0 && this->ry.computed == 0) {
return; // nothing to compensate
+ }
// test unit vectors to find out compensation:
- Geom::Point c(rect->x.computed, rect->y.computed);
+ Geom::Point c(this->x.computed, this->y.computed);
Geom::Point cx = c + Geom::Point(1, 0);
Geom::Point cy = c + Geom::Point(0, 1);
// apply previous transform if any
- c *= rect->transform;
- cx *= rect->transform;
- cy *= rect->transform;
+ c *= this->transform;
+ cx *= this->transform;
+ cy *= this->transform;
// find out stretches that we need to compensate
- gdouble eX = vector_stretch(cx, c, xform);
- gdouble eY = vector_stretch(cy, c, xform);
+ gdouble eX = SPRect::vectorStretch(cx, c, xform);
+ gdouble eY = SPRect::vectorStretch(cy, c, xform);
// If only one of the radii is set, set both radii so they have the same visible length
// This is needed because if we just set them the same length in SVG, they might end up unequal because of transform
- if ((rect->rx._set && !rect->ry._set) || (rect->ry._set && !rect->rx._set)) {
- gdouble r = MAX(rect->rx.computed, rect->ry.computed);
- rect->rx.computed = r / eX;
- rect->ry.computed = r / eY;
+ if ((this->rx._set && !this->ry._set) || (this->ry._set && !this->rx._set)) {
+ gdouble r = MAX(this->rx.computed, this->ry.computed);
+ this->rx.computed = r / eX;
+ this->ry.computed = r / eY;
} else {
- rect->rx.computed = rect->rx.computed / eX;
- rect->ry.computed = rect->ry.computed / eY;
+ this->rx.computed = this->rx.computed / eX;
+ this->ry.computed = this->ry.computed / eY;
}
// Note that a radius may end up larger than half-side if the rect is scaled down;
// that's ok because this preserves the intended radii in case the rect is enlarged again,
// and set_shape will take care of trimming too large radii when generating d=
- rect->rx._set = rect->ry._set = true;
+ this->rx._set = this->ry._set = true;
}
-void
-sp_rect_set_visible_width(SPRect *rect, gdouble width)
-{
- rect->width.computed = width / vector_stretch(
- Geom::Point(rect->x.computed + 1, rect->y.computed),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
- rect->width._set = true;
- SP_OBJECT(rect)->updateRepr();
+void SPRect::setVisibleWidth(gdouble width) {
+ this->width.computed = width / SPRect::vectorStretch(
+ Geom::Point(this->x.computed + 1, this->y.computed),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
+ this->width._set = true;
+ this->updateRepr();
}
-void
-sp_rect_set_visible_height(SPRect *rect, gdouble height)
-{
- rect->height.computed = height / vector_stretch(
- Geom::Point(rect->x.computed, rect->y.computed + 1),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
- rect->height._set = true;
- SP_OBJECT(rect)->updateRepr();
+void SPRect::setVisibleHeight(gdouble height) {
+ this->height.computed = height / SPRect::vectorStretch(
+ Geom::Point(this->x.computed, this->y.computed + 1),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
+ this->height._set = true;
+ this->updateRepr();
}
-gdouble
-sp_rect_get_visible_width(SPRect *rect)
-{
- if (!rect->width._set)
+gdouble SPRect::getVisibleWidth() const {
+ if (!this->width._set) {
return 0;
- return rect->width.computed * vector_stretch(
- Geom::Point(rect->x.computed + 1, rect->y.computed),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
+ }
+
+ return this->width.computed * SPRect::vectorStretch(
+ Geom::Point(this->x.computed + 1, this->y.computed),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
}
-gdouble
-sp_rect_get_visible_height(SPRect *rect)
-{
- if (!rect->height._set)
+gdouble SPRect::getVisibleHeight() const {
+ if (!this->height._set) {
return 0;
- return rect->height.computed * vector_stretch(
- Geom::Point(rect->x.computed, rect->y.computed + 1),
- Geom::Point(rect->x.computed, rect->y.computed),
- rect->transform);
+ }
+
+ return this->height.computed * SPRect::vectorStretch(
+ Geom::Point(this->x.computed, this->y.computed + 1),
+ Geom::Point(this->x.computed, this->y.computed),
+ this->transform);
}
void CRect::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
diff --git a/src/sp-rect.h b/src/sp-rect.h
index 325413c23..e8f1e87a8 100644
--- a/src/sp-rect.h
+++ b/src/sp-rect.h
@@ -38,6 +38,28 @@ public:
SVGLength height;
SVGLength rx;
SVGLength ry;
+
+ void setPosition(gdouble x, gdouble y, gdouble width, gdouble height);
+
+ /* If SET if FALSE, VALUE is just ignored */
+ void setRx(bool set, gdouble value);
+ void setRy(bool set, gdouble value);
+
+ void setVisibleRx(gdouble rx);
+ void setVisibleRy(gdouble ry);
+ gdouble getVisibleRx() const;
+ gdouble getVisibleRy() const;
+ Geom::Rect getRect() const;
+
+ void setVisibleWidth(gdouble rx);
+ void setVisibleHeight(gdouble ry);
+ gdouble getVisibleWidth() const;
+ gdouble getVisibleHeight() const;
+
+ void compensateRxRy(Geom::Affine xform);
+
+private:
+ static gdouble vectorStretch(Geom::Point p0, Geom::Point p1, Geom::Affine xform);
};
struct SPRectClass {
@@ -72,25 +94,6 @@ protected:
/* Standard GType function */
GType sp_rect_get_type (void) G_GNUC_CONST;
-void sp_rect_position_set (SPRect * rect, gdouble x, gdouble y, gdouble width, gdouble height);
-
-/* If SET if FALSE, VALUE is just ignored */
-void sp_rect_set_rx(SPRect * rect, gboolean set, gdouble value);
-void sp_rect_set_ry(SPRect * rect, gboolean set, gdouble value);
-
-void sp_rect_set_visible_rx (SPRect *rect, gdouble rx);
-void sp_rect_set_visible_ry (SPRect *rect, gdouble ry);
-gdouble sp_rect_get_visible_rx (SPRect *rect);
-gdouble sp_rect_get_visible_ry (SPRect *rect);
-Geom::Rect sp_rect_get_rect (SPRect *rect);
-
-void sp_rect_set_visible_width (SPRect *rect, gdouble rx);
-void sp_rect_set_visible_height (SPRect *rect, gdouble ry);
-gdouble sp_rect_get_visible_width (SPRect *rect);
-gdouble sp_rect_get_visible_height (SPRect *rect);
-
-void sp_rect_compensate_rxry (SPRect *rect, Geom::Affine xform);
-
G_END_DECLS
#endif // SEEN_SP_RECT_H
diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp
index 8c1a735c5..d14b28642 100644
--- a/src/widgets/rect-toolbar.cpp
+++ b/src/widgets/rect-toolbar.cpp
@@ -86,7 +86,7 @@ static void sp_rtb_sensitivize( GObject *tbl )
static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name,
- void (*setter)(SPRect *, gdouble))
+ void (SPRect::*setter)(gdouble))
{
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
@@ -112,8 +112,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *
for (GSList const *items = selection->itemList(); items != NULL; items = items->next) {
if (SP_IS_RECT(items->data)) {
if (gtk_adjustment_get_value(adj) != 0) {
- setter(SP_RECT(items->data),
- sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit));
+ (SP_RECT(items->data)->*setter)(sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit));
} else {
SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL);
}
@@ -133,22 +132,22 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *
static void sp_rtb_rx_value_changed(GtkAdjustment *adj, GObject *tbl)
{
- sp_rtb_value_changed(adj, tbl, "rx", sp_rect_set_visible_rx);
+ sp_rtb_value_changed(adj, tbl, "rx", &SPRect::setVisibleRx);
}
static void sp_rtb_ry_value_changed(GtkAdjustment *adj, GObject *tbl)
{
- sp_rtb_value_changed(adj, tbl, "ry", sp_rect_set_visible_ry);
+ sp_rtb_value_changed(adj, tbl, "ry", &SPRect::setVisibleRy);
}
static void sp_rtb_width_value_changed(GtkAdjustment *adj, GObject *tbl)
{
- sp_rtb_value_changed(adj, tbl, "width", sp_rect_set_visible_width);
+ sp_rtb_value_changed(adj, tbl, "width", &SPRect::setVisibleWidth);
}
static void sp_rtb_height_value_changed(GtkAdjustment *adj, GObject *tbl)
{
- sp_rtb_value_changed(adj, tbl, "height", sp_rect_set_visible_height);
+ sp_rtb_value_changed(adj, tbl, "height", &SPRect::setVisibleHeight);
}
@@ -190,25 +189,25 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con
if (item && SP_IS_RECT(item)) {
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) );
- gdouble rx = sp_rect_get_visible_rx(SP_RECT(item));
+ gdouble rx = SP_RECT(item)->getVisibleRx();
gtk_adjustment_set_value(adj, sp_pixels_get_units(rx, *unit));
}
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) );
- gdouble ry = sp_rect_get_visible_ry(SP_RECT(item));
+ gdouble ry = SP_RECT(item)->getVisibleRy();
gtk_adjustment_set_value(adj, sp_pixels_get_units(ry, *unit));
}
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) );
- gdouble width = sp_rect_get_visible_width (SP_RECT(item));
+ gdouble width = SP_RECT(item)->getVisibleWidth();
gtk_adjustment_set_value(adj, sp_pixels_get_units(width, *unit));
}
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) );
- gdouble height = sp_rect_get_visible_height (SP_RECT(item));
+ gdouble height = SP_RECT(item)->getVisibleHeight();
gtk_adjustment_set_value(adj, sp_pixels_get_units(height, *unit));
}
}