summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2010-09-02 13:38:33 +0200
committerMurray Cumming <murrayc@murrayc.com>2010-09-02 13:38:33 +0200
commit4a705f726115fc17b15741e9406db94c02d38dfb (patch)
tree91add514de942c7317b6c8d40ed6ea1dd0febd0a
parent78f426135e7015b5567d9867907c673222e30258 (diff)
Context: Make some methods const, deprecating the non-const versions.
* cairomm/context.h: device_to_user(, device_to_user_distance(), user_to_device(), user_to_device_distance(): Deprecate the non-const versions, adding const versions.
-rw-r--r--ChangeLog8
-rw-r--r--cairomm/context.cc54
-rw-r--r--cairomm/context.h75
3 files changed, 109 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a9dd28..86ef75b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-02 Murray Cumming <murrayc@murrayc.com>
+
+ Context: Make some methods const, deprecating the non-const versions.
+
+ * cairomm/context.h: device_to_user(, device_to_user_distance(),
+ user_to_device(), user_to_device_distance(): Deprecate the non-const versions,
+ adding const versions.
+
2010-06-10 Ian Britten <britten@caris.com>
Cleanup of most -Weffc++ warnings. Bug #28246.
diff --git a/cairomm/context.cc b/cairomm/context.cc
index 1549a21..10c2cce 100644
--- a/cairomm/context.cc
+++ b/cairomm/context.cc
@@ -26,7 +26,7 @@
/* M_PI is defined in math.h in the case of Microsoft Visual C++ */
#if defined(_MSC_VER)
#define _USE_MATH_DEFINES
-#endif
+#endif
/* Solaris et. al. need math.h for M_PI too */
#include <cmath>
@@ -231,27 +231,55 @@ void Context::set_identity_matrix()
check_object_status_and_throw_exception(*this);
}
+//deprecated:
void Context::user_to_device(double& x, double& y)
{
- cairo_user_to_device(cobj(), &x, &y);
+ const Context* constThis = this;
+ constThis->user_to_device(x, y);
+}
+
+void Context::user_to_device(double& x, double& y) const
+{
+ cairo_user_to_device(const_cast<cobject*>(cobj()), &x, &y);
check_object_status_and_throw_exception(*this);
}
+//deprecated:
void Context::user_to_device_distance(double& dx, double& dy)
{
- cairo_user_to_device_distance(cobj(), &dx, &dy);
+ const Context* constThis = this;
+ constThis->user_to_device_distance(dx, dy);
+}
+
+void Context::user_to_device_distance(double& dx, double& dy) const
+{
+ cairo_user_to_device_distance(const_cast<cobject*>(cobj()), &dx, &dy);
check_object_status_and_throw_exception(*this);
}
+//deprecated:
void Context::device_to_user(double& x, double& y)
{
- cairo_device_to_user(cobj(), &x, &y);
+ const Context* constThis = this;
+ constThis->device_to_user(x, y);
+}
+
+void Context::device_to_user(double& x, double& y) const
+{
+ cairo_device_to_user(const_cast<cobject*>(cobj()), &x, &y);
check_object_status_and_throw_exception(*this);
}
+//deprecated:
void Context::device_to_user_distance(double& dx, double& dy)
{
- cairo_device_to_user_distance(cobj(), &dx, &dy);
+ const Context* constThis = this;
+ constThis->device_to_user_distance(dx, dy);
+}
+
+void Context::device_to_user_distance(double& dx, double& dy) const
+{
+ cairo_device_to_user_distance(const_cast<cobject*>(cobj()), &dx, &dy);
check_object_status_and_throw_exception(*this);
}
@@ -433,7 +461,7 @@ void Context::clip_preserve()
void Context::get_clip_extents(double& x1, double& y1, double& x2, double& y2) const
{
- cairo_clip_extents(const_cast<cairo_t*>(const_cast<cobject*>(cobj())), &x1, &y1, &x2, &y2);
+ cairo_clip_extents(const_cast<cobject*>(const_cast<cobject*>(cobj())), &x1, &y1, &x2, &y2);
check_object_status_and_throw_exception(*this);
}
@@ -442,7 +470,7 @@ void Context::copy_clip_rectangle_list(std::vector<Rectangle>& rectangles) const
cairo_rectangle_list_t* c_list = 0;
// It would be nice if the cairo interface didn't copy it into a C array first
// and just let us do the copying...
- c_list = cairo_copy_clip_rectangle_list(const_cast<cairo_t*>(const_cast<cobject*>(cobj())));
+ c_list = cairo_copy_clip_rectangle_list(const_cast<cobject*>(const_cast<cobject*>(cobj())));
// the rectangle list contains a status field that we need to check and the
// cairo context also has a status that we need to check
// FIXME: do we want to throw an exception if the clip can't be represented by
@@ -708,7 +736,7 @@ Context::get_dash(std::vector<double>& dashes, double& offset) const
// constant...
const int cnt = cairo_get_dash_count(const_cast<cobject*>(cobj()));
double* dash_array = new double[cnt];
- cairo_get_dash(const_cast<cairo_t*>(cobj()), dash_array, &offset);
+ cairo_get_dash(const_cast<cobject*>(cobj()), dash_array, &offset);
check_object_status_and_throw_exception(*this);
dashes.assign(dash_array, dash_array + cnt);
delete[] dash_array;
@@ -729,7 +757,7 @@ void Context::get_matrix(cairo_matrix_t& matrix)
Matrix Context::get_matrix() const
{
Cairo::Matrix m;
- cairo_get_matrix(const_cast<cairo_t*>(cobj()), (cairo_matrix_t*)&m);
+ cairo_get_matrix(const_cast<cobject*>(cobj()), (cairo_matrix_t*)&m);
check_object_status_and_throw_exception(*this);
return m;
}
@@ -790,21 +818,21 @@ RefPtr<Surface> get_surface_wrapper (cairo_surface_t* surface)
RefPtr<Surface> Context::get_target()
{
- cairo_surface_t* surface = cairo_get_target(const_cast<cairo_t*>(cobj()));
+ cairo_surface_t* surface = cairo_get_target(const_cast<cobject*>(cobj()));
check_object_status_and_throw_exception(*this);
return get_surface_wrapper (surface);
}
RefPtr<const Surface> Context::get_target() const
{
- cairo_surface_t* surface = cairo_get_target(const_cast<cairo_t*>(cobj()));
+ cairo_surface_t* surface = cairo_get_target(const_cast<cobject*>(cobj()));
check_object_status_and_throw_exception(*this);
return RefPtr<const Surface>::cast_const (get_surface_wrapper (surface));
}
Path* Context::copy_path() const
{
- cairo_path_t* cresult = cairo_copy_path(const_cast<cairo_t*>(cobj()));
+ cairo_path_t* cresult = cairo_copy_path(const_cast<cobject*>(cobj()));
check_object_status_and_throw_exception(*this);
return new Path(cresult, true /* take ownership */); //The caller must delete it.
}
@@ -818,7 +846,7 @@ void Context::get_path_extents(double& x1, double& y1, double& x2, double& y2) c
Path* Context::copy_path_flat() const
{
- cairo_path_t* cresult = cairo_copy_path_flat(const_cast<cairo_t*>(cobj()));
+ cairo_path_t* cresult = cairo_copy_path_flat(const_cast<cobject*>(cobj()));
check_object_status_and_throw_exception(*this);
return new Path(cresult, true /* take ownership */); //The caller must delete it.
}
diff --git a/cairomm/context.h b/cairomm/context.h
index 24f5134..6abebf4 100644
--- a/cairomm/context.h
+++ b/cairomm/context.h
@@ -36,7 +36,7 @@
namespace Cairo
{
-/** Context is the main class used to draw in cairomm.
+/** Context is the main class used to draw in cairomm.
* In the simplest case, create a Context with its target Surface, set its
* drawing options (line width, color, etc), create shapes with methods like
* move_to() and line_to(), and then draw the shapes to the Surface using
@@ -70,7 +70,7 @@ public:
* nested; each call to restore() restores the state from the matching paired
* save().
*
- * It isn't necessary to clear all saved states before a cairo_t is freed.
+ * It isn't necessary to clear all saved states before a cairo_t is freed.
* Any saved states will be freed when the Context is destroyed.
*
* @sa restore()
@@ -99,7 +99,7 @@ public:
* Note: The Pattern's transformation matrix will be locked to the user space
* in effect at the time of set_source(). This means that further
* modifications of the current transformation matrix will not affect the
- * source pattern.
+ * source pattern.
*
* @param source a Pattern to be used as the source for subsequent drawing
* operations.
@@ -162,7 +162,7 @@ public:
*
* @param surface a Surface to be used to set the source pattern
* @param x User-space X coordinate for surface origin
- * @param y User-space Y coordinate for surface origin
+ * @param y User-space Y coordinate for surface origin
*/
void set_source(const RefPtr<Surface>& surface, double x, double y);
@@ -209,7 +209,7 @@ public:
* @param width a line width, as a user-space value
*/
void set_line_width(double width);
-
+
/** Sets the current line cap style within the cairo Context. See
* LineCap for details about how the available line cap styles are drawn.
*
@@ -232,11 +232,12 @@ public:
*/
void set_line_join(LineJoin line_join);
- /**
+ /**
* Alternate version of set_dash(). You'll probably want to use the one that
* takes a std::vector argument instead.
*/
void set_dash(std::valarray<double>& dashes, double offset);
+
/** Sets the dash pattern to be used by stroke(). A dash pattern is specified
* by dashes, an array of positive values. Each value provides the user-space
* length of altenate "on" and "off" portions of the stroke. The offset
@@ -268,7 +269,7 @@ public:
* takes place after any existing transformation.
*
* @param tx amount to translate in the X direction
- * @param ty amount to translate in the Y direction
+ * @param ty amount to translate in the Y direction
*/
void translate(double tx, double ty);
@@ -326,11 +327,14 @@ public:
*/
void set_identity_matrix();
+#ifndef CAIROMM_DISABLE_DEPRECATED
/** Transform a coordinate from user space to device space by multiplying the
* given point by the current transformation matrix (CTM).
*
* @param x X value of coordinate (in/out parameter)
* @param y Y value of coordinate (in/out parameter)
+ *
+ * @deprecated Use the const version.
*/
void user_to_device(double& x, double& y);
@@ -340,6 +344,8 @@ public:
*
* @param dx X component of a distance vector (in/out parameter)
* @param dy Y component of a distance vector (in/out parameter)
+ *
+ * @deprecated Use the const version.
*/
void user_to_device_distance(double& dx, double& dy);
@@ -348,6 +354,8 @@ public:
*
* @param x X value of coordinate (in/out parameter)
* @param y Y value of coordinate (in/out parameter)
+ *
+ * @deprecated Use the const version.
*/
void device_to_user(double& x, double& y);
@@ -357,8 +365,45 @@ public:
*
* @param dx X component of a distance vector (in/out parameter)
* @param dy Y component of a distance vector (in/out parameter)
+ *
+ * @deprecated Use the const version.
*/
void device_to_user_distance(double& dx, double& dy);
+#endif //CAIROMM_DISABLE_DEPRECATED
+
+ /** Transform a coordinate from user space to device space by multiplying the
+ * given point by the current transformation matrix (CTM).
+ *
+ * @param x X value of coordinate (in/out parameter)
+ * @param y Y value of coordinate (in/out parameter)
+ */
+ void user_to_device(double& x, double& y) const;
+
+ /** Transform a distance vector from user space to device space. This
+ * function is similar to user_to_device() except that the translation
+ * components of the CTM will be ignored when transforming (dx,dy).
+ *
+ * @param dx X component of a distance vector (in/out parameter)
+ * @param dy Y component of a distance vector (in/out parameter)
+ */
+ void user_to_device_distance(double& dx, double& dy) const;
+
+ /** Transform a coordinate from device space to user space by multiplying the
+ * given point by the inverse of the current transformation matrix (CTM).
+ *
+ * @param x X value of coordinate (in/out parameter)
+ * @param y Y value of coordinate (in/out parameter)
+ */
+ void device_to_user(double& x, double& y) const;
+
+ /** Transform a distance vector from device space to user space. This
+ * function is similar to device_to_user() except that the translation
+ * components of the inverse CTM will be ignored when transforming (dx,dy).
+ *
+ * @param dx X component of a distance vector (in/out parameter)
+ * @param dy Y component of a distance vector (in/out parameter)
+ */
+ void device_to_user_distance(double& dx, double& dy) const;
/** Clears the current path. After this call there will be no current point.
*/
@@ -625,9 +670,9 @@ public:
/** A drawing operator that fills the current path according to the current
* fill rule, (each sub-path is implicitly closed before being filled). After
- * fill(), the current path will be cleared from the cairo context.
+ * fill(), the current path will be cleared from the cairo context.
*
- * @sa set_fill_rule()
+ * @sa set_fill_rule()
* @sa fill_preserve()
*/
void fill();
@@ -637,7 +682,7 @@ public:
* Unlike fill(), fill_preserve() preserves the path within the
* cairo Context.
*
- * @sa set_fill_rule()
+ * @sa set_fill_rule()
* @sa fill().
*/
void fill_preserve();
@@ -685,7 +730,7 @@ public:
* current fill rule.
*
* Unlike clip(), cairo_clip_preserve preserves the path within the cairo
- * Context.
+ * Context.
*
* @sa clip()
* @sa set_fill_rule()
@@ -784,7 +829,7 @@ public:
*
* The current point is returned in the user-space coordinate system. If
* there is no defined current point then x and y will both be set to 0.0.
- *
+ *
* Most path construction functions alter the current point. See the
* following for details on how they affect the current point: clear_path(),
* move_to(), line_to(), curve_to(), arc(), rel_move_to(), rel_line_to(),
@@ -907,7 +952,7 @@ public:
* be approximated with piecewise-linear approximations, (accurate to within
* the current tolerance value). That is, the result is guaranteed to not have
* any elements of type CAIRO_PATH_CURVE_TO which will instead be
- * replaced by a series of CAIRO_PATH_LINE_TO elements.
+ * replaced by a series of CAIRO_PATH_LINE_TO elements.
*
* @note The caller owns the Path object returned from this function. The
* Path object must be freed when you are finished with it.
@@ -916,7 +961,7 @@ public:
/** Append the path onto the current path. The path may be either the return
* value from one of copy_path() or copy_path_flat() or it may be constructed
- * manually.
+ * manually.
*
* @param path path to be appended
*/
@@ -1040,7 +1085,7 @@ public:
/** Gets a pointer to the base C type that is wrapped by the Context
*/
inline const cobject* cobj() const { return m_cobject; }
-
+
#ifndef DOXYGEN_IGNORE_THIS
///For use only by the cairomm implementation.
inline ErrorStatus get_status() const