nodePong/client/lib/ui/objects/ui_rect.js

58 lines
1.1 KiB
JavaScript

/**
* @file ui_rect.js
* @author frtk@tetalab
*/
NPGClient.UIRect = function(n, p, w, h, s) {
//
//NPGClient.UIObject.call(this, n, s);
// obj name
this.name = n !== undefined ? n : '';
// geom
this.pos = p !== undefined ? p : new NPGClient.UIPoint2D();
this.w = w !== undefined ? w : 0;
this.h = h !== undefined ? h : 0;
// style
this.style = s !== undefined ? s : new NPGclient.UIStyle();
};
NPGClient.UIRect.prototype = {
// Constructor
constructor: NPGClient.UIRect,
//
//
draw: function(ctx) {
var self = this;
if (!self.s.fillMode()) {
drawNoFill(ctx, self.x, self.y, self.w, self.h, self.lw, self.lc);
} else {
drawFill(ctx, self.x, self.y, self.w, self.h, self.fc);
}
},
//
drawFill: function(ctx) {
var self = this;
self.applyStyle(ctx);
ctx.fillRect(self.pos.x, self.pos.y, self.w, self.h);
},
//
drawNoFill: function(ctx, x1, y1, w, h, lw, c) {
var self = this;
ctx.beginPath();
self.applyStyle(ctx);
ctx.rect(self.pos.x, self.pos.y, self.w, self.h);
ctx.stroke();
},
};