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

62 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-02-14 14:37:31 +11:00
/**
* @file ui_cursor.js
* @author frtk@tetalab
*/
NPGClient.UICursor = function(n, o) {
2016-02-16 10:47:28 +11:00
// inheritance
NPGClient.UIObject.call(this, o);
2016-02-14 14:37:31 +11:00
// obj name
this.name = n !== undefined ? n : '';
2016-02-16 10:47:28 +11:00
this.w = o.w !== undefined ? o.w : 0;
this.h = o.h !== undefined ? o.h : 0;
// starting position
this.x0 = this.x();
this.y0 = this.y();
// style
this.style = o.style !== undefined ? o.style : {};
2016-02-14 14:37:31 +11:00
// state
this.bState = true;
this.bCount = 0;
this.bCountMax = 5;
};
2016-02-16 10:47:28 +11:00
// inheritance
NPGClient.UICursor.prototype = Object.create(NPGClient.UIObject.prototype);
// constructor
NPGClient.UICursor.prototype.constructor = NPGClient.UICursor;
// reset
NPGClient.UICursor.prototype.reset = function() {
var self = this;
self.moveTo(self.x0, self.y0);
}
2016-02-14 14:37:31 +11:00
2016-02-16 10:47:28 +11:00
// draw
NPGClient.UICursor.prototype.draw = function(ctx) {
var self = this;
if (self.bState) {
if (self.bCount == self.bCountMax) {
self.bCount = 0;
self.bState = false;
} else {
NPGClient.Utils.drawFillRect(ctx, self.x(), self.y(), self.w, self.h);
self.bCount++;
}
} else {
if (self.bCount == self.bCountMax) {
self.bCount = 0;
self.bState = true;
NPGClient.Utils.drawFillRect(ctx, self.x(), self.y(), self.w, self.h);
} else self.bCount++;
}
2016-02-14 14:37:31 +11:00
};
2016-02-16 10:47:28 +11:00