{"size": 1286, "ext": "js", "max_stars_repo_path": "src/display/PixelView.js", "max_stars_repo_name": "nosir/obelisk.js", "max_stars_repo_stars_event_min_datetime": "2015-01-02T14:35:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T20:54:16.000Z", "max_issues_repo_path": "src/display/PixelView.js", "max_issues_repo_name": "nosir/obelisk.js", "max_issues_repo_issues_event_min_datetime": "2015-01-01T10:00:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T12:24:43.000Z", "max_forks_repo_path": "src/display/PixelView.js", "max_forks_repo_name": "nosir/obelisk.js", "max_forks_repo_forks_event_min_datetime": "2015-01-02T14:35:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-10T08:04:57.000Z"}
{"max_stars_count": 986, "max_issues_count": 14, "max_forks_count": 81, "avg_line_length": 21.4333333333, "max_line_length": 80, "alphanum_fraction": 0.6446345257}
/*jslint node: true*/
/*global jQuery:true*/

'use strict';

var Point = require('../geom/Point');
var PixelObject = require('../display/PixelObject');

var PixelView, p;
PixelView = function (canvas, point) {
    this.initialize(canvas, point);
};
p = PixelView.prototype;

// public properties
p.canvas = null;
p.context = null;
p.point = null;

// constructor
p.initialize = function (canvas, point) {
    if (!canvas) {
        throw new Error('Canvas is not defined');
    }

    try {
        if (canvas instanceof jQuery) {
            canvas = canvas.get(0);
        }
    } catch (ignore) {
    }

    this.canvas = canvas;

    this.context = this.canvas.getContext('2d');
    this.context.mozImageSmoothingEnabled = false;
    this.context.msImageSmoothingEnabled = false;
    this.context.imageSmoothingEnabled = false;

    this.point = point || new Point(0, 0);

    return this;
};

// public methods
p.renderObject = function (primitive, point3D) {
    var po = new PixelObject(primitive, point3D);
    this.context.drawImage(po.canvas, this.point.x + po.x, this.point.y + po.y);
};

p.clear = function () {
    this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
};

p.toString = function () {
    return '[PixelView]';
};

module.exports = PixelView;
