This commit is contained in:
2016-02-16 00:47:28 +01:00
parent 45a0e86e74
commit 9677666b48
16 changed files with 252 additions and 283 deletions

View File

@@ -5,10 +5,18 @@
NPGClient.UICursor = function(n, o) {
//
this.rect = new NPGClient.UIRect(n, o);
// inheritance
NPGClient.UIObject.call(this, o);
// obj name
this.name = n !== undefined ? n : '';
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 : {};
// state
this.bState = true;
this.bCount = 0;
@@ -16,28 +24,38 @@ NPGClient.UICursor = function(n, o) {
};
NPGClient.UICursor.prototype = {
// Constructor
constructor: NPGClient.UICursor,
//
draw: function(ctx) {
var self = this;
if (self.bState) {
if (self.bCount == self.bCountMax) {
self.bCount = 0;
self.bState = false;
} else self.rect.draw(ctx);
self.bCount++;
} else {
if (self.bCount == self.bCountMax) {
self.bCount = 0;
self.bState = true;
self.rect.draw(ctx);
} else self.bCount++;
}
},
// 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);
}
// 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++;
}
};

View File

@@ -36,9 +36,11 @@ NPGClient.UIInputText.prototype = {
//
draw: function(ctx, state) {
var self = this;
var t = self.text + self.input;
self.updateInput();
//console.log(self.s);
NPGClient.Utils.setTxtStyle(ctx, self.s);
ctx.fillText(self.text + self.input, self.x, self.y);
ctx.fillText(t, self.x, self.y);
}
};

View File

@@ -1,35 +0,0 @@
/**
* @file ui_line.js
* @author frtk@tetalab
*/
NPGClient.Line = function(name, p1, p2, style) {
NPGClient.UIObject.call(this, name, style);
this.p1 = p1 !== undefined ? p1 : new NPGClient.Point2D();
this.p2 = p2 !== undefined ? p2 : new NPGClient.Point2D();
};
NPGClient.Line.prototype = Object.create(NPGClient.UIObject.prototype);
NPGClient.Line.prototype.constructor = NPGClient.Line;
NPGCLient.Line.prototype.draw = function(ctx) {
var self = this;
self.drawLine(ctx);
};
NPGClient.Line.prototype.drawLine = function(ctx) {
var self = this;
self.applyStyle(ctx);
ctx.beginPath();
ctx.moveTo(self.p1.x, self.p1.y);
ctx.lineTo(self.p2.x, self.p2.y);
ctx.stroke();
};

View File

@@ -1,45 +1,77 @@
/**
* @file ui_object
* @file ui_object.js
* @author frtk@tetalab
*/
//
NPGClient.UIObject = function(name, style) {
NPGClient.UIObject = function(o) {
//Object.defineProperty( this, 'id', { value: GT4UI.Object2DIdCount++ });
this.name = name !== undefined ? name : '';
this.style = style !== undefined ? style : new NPGClient.UIStyle();
this._x = (o.x !== undefined) ? o.x : 0; // x position
this._y = (o.y !== undefined) ? o.y : 0; // y position
this._theta = (o.theta !== undefined) ? o.theta : 0; // theta wrt horizon
};
/**
*
*/
NPGClient.UIObject.prototype = {
constructor: NPGClient.UIObject,
setStyle: function(s) {
this.style = s;
},
hasBorders: function() {
return this.style.getBorderMode();
},
// Constructor
constructor: NPGClient.UIObject,
hasFillStyle: function() {
return this.style.getFillMode();
},
applyStyle: function(ctx) {
var self = this;
if (self.style.getBorderMode()) {
ctx.lineWidth = self.style.bw;
ctx.strokeStyle = self.style.bc;
}
if (self.style.getFillMode()) {
ctx.fillStyle = self.style.fc;
}
//set/get
x: function(data) {
var self = this;
if (data !== undefined) {
self._x = data;
} else {
return self._x;
}
};
},
//set/get
y: function(data) {
var self = this;
if (data !== undefined) {
self._y = data;
} else {
return self._y;
}
},
//
moveTo: function(x, y) {
var self = this;
self._x = x;
self._y = y;
},
//
translateXY: function(x, y) {
var self = this;
self._x += x;
self._y += y;
},
//
translateX: function(x) {
this._x += x;
},
//
translateY: function(y) {
this._y += y;
},
//
rotate: function(x, y, t) {
},
};

View File

@@ -6,47 +6,27 @@
NPGClient.UIRect = function(n, o) {
//
NPGClient.UIShape.call(this);
NPGClient.UIObject.call(this, o);
// obj name
this.name = n !== undefined ? n : '';
// geom
this.pos = o.pos !== undefined ? o.pos : {};
this.w = o.w !== undefined ? o.w : 0;
this.h = o.h !== undefined ? o.h : 0;
// style
this.style = o.style !== undefined ? o.style : new NPGClient.UIStyle();
};
NPGClient.UIRect.prototype = {
// inheritance
NPGClient.UIRect.prototype = Object.create(NPGClient.UIObject.prototype);
// Constructor
NPGClient.UIRect.prototype.constructor = NPGClient.UIRect;
// Constructor
constructor: NPGClient.UIRect,
//
draw: function(ctx) {
var self = this;
if (!self.style.fm) {
self.drawNoFill(ctx, self.pos.x, self.pos.y, self.w, self.h, self.style.lw, self.style.lc);
} else {
self.drawFill(ctx, self.pos.x, self.pos.y, self.w, self.h, self.style.fc);
}
},
//
drawFill: function(ctx) {
var self = this;
NPGClient.Utils.applyStyle(ctx, self.style);
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();
NPGClient.Utils.applyStyle(ctx, self.style);
ctx.rect(self.pos.x, self.pos.y, self.w, self.h);
ctx.stroke();
},
NPGClient.UIRect.prototype.draw = function(ctx) {
var self = this;
NPGClient.Utils.applyStyle(ctx, self.style);
if (!self.style.fm) {
NPGClient.Utils.drawRect(ctx, self.x(), self.y(), self.w, self.h);
} else {
NPGClient.Utils.drawFillRect(ctx, self.x(), self.y(), self.w, self.h);
}
};

View File

@@ -1,45 +0,0 @@
/**
* @file ui_shape.js
* @author frtk@tetalab
*/
//
NPGClient.UIShape = function() {
this.x = 0; // x position
this.y = 0; // y position
};
/**
*
*/
NPGClient.UIShape.prototype = {
// Constructor
constructor: NPGClient.UIShape,
//
moveTo: function(x, y) {
var self = this;
self.x = x;
self.y = y;
},
//
move: function(x, y) {
var self = this;
self.x += x;
self.y += y;
},
//
shiftX: function(x) {
this.x += x;
},
//
shiftY: function(y) {
this.y += y;
}
};