#include "libwasm.h" #include "canvas.h" int round (const double a) { return int (a + 0.5); } Canvas::Canvas(const int w, const int h) : width(w), height(h), outpixel(0u), current(0xFF000000), matrix (1.0, 0.0, 0.0, -1.0, 0.5 * (real) w, 0.5 * (real) (h)) { data = new Color [w * h]; } Canvas::~Canvas() { delete [] data; } void Canvas::fill (const Color & c) { for (int y=0; y= width) return false; if (y >= height) return false; return true; } void Canvas::line (const int xp, const int yp, const int xe, const int ye, const bool doted) { bool dot = true; int x1 = xp, y1 = yp; const int x2 = xe, y2 = ye; bool done = false; int mx = 0, my = 0; // Determine direction and distance const int xd = (x1 < x2) ? 1 : -1; const int yd = (y1 < y2) ? 1 : -1; const int xl = (x1 < x2) ? (x2 - x1) : (x1 - x2); const int yl = (y1 < y2) ? (y2 - y1) : (y1 - y2); while (!done) { if (x1 == x2 && y1 == y2) done = true; if (dot) at(x1,y1) = current; // Plot pixel if (doted) dot = !dot; mx += xl; if (x1 != x2 && mx > yl) x1 += xd, mx -= yl; my += yl; if (y1 != y2 && my > xl) y1 += yd, my -= xl; } } void Canvas::rect (const int x0, const int y0, const int x1, const int y1) { for (int y=y0; y ms) break; } } void Canvas::setMatrix (const Matrix& m) { matrix = m; }