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

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-02-13 21:06:40 +01:00
/**
* @file ui_rect.js
* @author frtk@tetalab
*/
2016-02-14 04:37:31 +01:00
NPGClient.UIRect = function(n, o) {
2016-02-13 21:06:40 +01:00
2016-02-14 00:23:22 +01:00
//
2016-02-14 04:37:31 +01:00
NPGClient.UIShape.call(this);
2016-02-13 21:06:40 +01:00
// obj name
this.name = n !== undefined ? n : '';
// geom
2016-02-14 04:37:31 +01:00
this.pos = o.pos !== undefined ? o.pos : {};
this.w = o.w !== undefined ? o.w : 0;
this.h = o.h !== undefined ? o.h : 0;
2016-02-13 21:06:40 +01:00
// style
2016-02-14 04:37:31 +01:00
this.style = o.style !== undefined ? o.style : new NPGClient.UIStyle();
2016-02-13 21:06:40 +01:00
};
NPGClient.UIRect.prototype = {
// Constructor
constructor: NPGClient.UIRect,
//
draw: function(ctx) {
var self = this;
2016-02-14 04:37:31 +01:00
if (!self.style.fm) {
self.drawNoFill(ctx, self.pos.x, self.pos.y, self.w, self.h, self.style.lw, self.style.lc);
2016-02-13 21:06:40 +01:00
} else {
2016-02-14 04:37:31 +01:00
self.drawFill(ctx, self.pos.x, self.pos.y, self.w, self.h, self.style.fc);
2016-02-13 21:06:40 +01:00
}
},
//
drawFill: function(ctx) {
var self = this;
2016-02-14 04:37:31 +01:00
NPGClient.Utils.applyStyle(ctx, self.style);
2016-02-13 21:06:40 +01:00
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();
2016-02-14 04:37:31 +01:00
NPGClient.Utils.applyStyle(ctx, self.style);
2016-02-13 21:06:40 +01:00
ctx.rect(self.pos.x, self.pos.y, self.w, self.h);
ctx.stroke();
},
};