summaryrefslogtreecommitdiffstats
path: root/libdimensionxx/canvas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libdimensionxx/canvas.cpp')
-rw-r--r--libdimensionxx/canvas.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/libdimensionxx/canvas.cpp b/libdimensionxx/canvas.cpp
index 2340066..411d4e8 100644
--- a/libdimensionxx/canvas.cpp
+++ b/libdimensionxx/canvas.cpp
@@ -22,8 +22,59 @@
namespace Dimension
{
+ // Allocate the canvas with dmnsn_new_canvas()
+ Canvas::Canvas(unsigned int width, unsigned int height)
+ : m_canvas(dmnsn_new_canvas(width, height)) { }
+
+ // Virtual destructor: delete the canvas with dmnsn_delete_canvas().
Canvas::~Canvas()
{
dmnsn_delete_canvas(m_canvas);
}
+
+ // Get the width
+ unsigned int
+ Canvas::width() const
+ {
+ return m_canvas->x;
+ }
+
+ // Get the height
+ unsigned int
+ Canvas::height() const
+ {
+ return m_canvas->y;
+ }
+
+ // Get a particular pixel, thread-safely, with dmnsn_get_pixel().
+ Color
+ Canvas::pixel(unsigned int x, unsigned int y) const
+ {
+ return Color(dmnsn_get_pixel(m_canvas, x, y));
+ }
+
+ // Set a particular pixel, thread-safely, with dmnsn_set_pixel().
+ void
+ Canvas::pixel(unsigned int x, unsigned int y, const Color& c)
+ {
+ dmnsn_set_pixel(m_canvas, x, y, c.dmnsn());
+ }
+
+ // Return the wrapped canvas
+ dmnsn_canvas*
+ Canvas::dmnsn()
+ {
+ return m_canvas;
+ }
+
+ // Return a const version of the wrapped canvas
+ const dmnsn_canvas*
+ Canvas::dmnsn() const
+ {
+ return m_canvas;
+ }
+
+ // Protected default constructor: set m_canvas to NULL.
+ Canvas::Canvas()
+ : m_canvas(0) { }
}