version v0.1.3

This commit is contained in:
2016-02-14 04:37:31 +01:00
parent 7dd657471d
commit 45a0e86e74
18 changed files with 366 additions and 83 deletions

View File

@@ -0,0 +1,43 @@
/**
* @file ui_cursor.js
* @author frtk@tetalab
*/
NPGClient.UICursor = function(n, o) {
//
this.rect = new NPGClient.UIRect(n, o);
// obj name
this.name = n !== undefined ? n : '';
// state
this.bState = true;
this.bCount = 0;
this.bCountMax = 5;
};
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++;
}
},
};

View File

@@ -28,16 +28,15 @@ NPGClient.UIInputText.prototype = {
constructor: NPGClient.UIInputText,
//
updateState: function() {
updateInput: function() {
var self = this;
if (NPGClient.SocketIO.isConnected) self.currText = self.text.online;
else self.currText = self.text.offline;
self.input = NPGClient.userName;
},
//
draw: function(ctx, state) {
var self = this;
self.updateState();
self.updateInput();
NPGClient.Utils.setTxtStyle(ctx, self.s);
ctx.fillText(self.text + self.input, self.x, self.y);
}

View File

@@ -29,14 +29,8 @@ NPGClient.UILabel.prototype = {
//
draw: function(ctx) {
var self = this;
//self.rect.draw(ctx);
NPGClient.Utils.setTxtStyle(ctx, self.s);
ctx.fillText(self.text, self.x, self.y);
/*
ctx.font = self.font
ctx.fillStyle = self.col;
ctx.fillText(self.text, self.x, self.y);
*/
NPGClient.Utils.setTxtStyle(ctx, self.s);
ctx.fillText(self.text, self.x, self.y);
}
};

View File

@@ -35,11 +35,11 @@ NPGClient.UIMenu.prototype = {
var self = this;
var y = self.y
if (self.items !== undefined && self.items.length > 0) {
for (var i = 0; i < self.items.length; i++) {
ctx.font = self.items[i].font;
ctx.fillStyle = self.items[i].col;
ctx.fillText(self.text, self.x, self.y);
}
for (var i = 0; i < self.items.length; i++) {
ctx.font = self.items[i].font;
ctx.fillStyle = self.items[i].col;
ctx.fillText(self.text, self.x, self.y);
}
}
},

View File

@@ -3,20 +3,18 @@
* @author frtk@tetalab
*/
NPGClient.UIRect = function(n, p, w, h, s) {
NPGClient.UIRect = function(n, o) {
//
//NPGClient.UIObject.call(this, n, s);
NPGClient.UIShape.call(this);
// 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;
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 = s !== undefined ? s : new NPGclient.UIStyle();
this.style = o.style !== undefined ? o.style : new NPGClient.UIStyle();
};
NPGClient.UIRect.prototype = {
@@ -24,23 +22,20 @@ 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);
if (!self.style.fm) {
self.drawNoFill(ctx, self.pos.x, self.pos.y, self.w, self.h, self.style.lw, self.style.lc);
} else {
drawFill(ctx, self.x, self.y, self.w, self.h, self.fc);
self.drawFill(ctx, self.pos.x, self.pos.y, self.w, self.h, self.style.fc);
}
},
//
drawFill: function(ctx) {
var self = this;
self.applyStyle(ctx);
NPGClient.Utils.applyStyle(ctx, self.style);
ctx.fillRect(self.pos.x, self.pos.y, self.w, self.h);
},
@@ -48,7 +43,7 @@ NPGClient.UIRect.prototype = {
drawNoFill: function(ctx, x1, y1, w, h, lw, c) {
var self = this;
ctx.beginPath();
self.applyStyle(ctx);
NPGClient.Utils.applyStyle(ctx, self.style);
ctx.rect(self.pos.x, self.pos.y, self.w, self.h);
ctx.stroke();
},

View File

@@ -0,0 +1,45 @@
/**
* @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;
}
};

View File

@@ -3,20 +3,21 @@
* @author frtk@tetalab
*/
NPGClient.UIStyle = function(fm, fc, bm, bw, bc) {
this.fm = fm !== undefined ? fm : false;
this.fc = fc !== undefined ? fc : '';
this.bm = bm !== undefined ? bm : false;
this.bw = bw !== undefined ? bw : 0;
this.bc = bc !== undefined ? bc : '';
NPGClient.UIStyle = function(o) {
/*
this.fm = o.fm !== undefined ? o.fm : false;
this.fc = o.fc !== undefined ? o.fc : '';
this.bm = o.bm !== undefined ? o.bm : false;
this.bw = o.bw !== undefined ? o.bw : 0;
this.bc = o.bc !== undefined ? o.bc : '';
*/
};
NPGClient.UIStyle.prototype = {
constructor: NPGClient.UIStyle,
/*
borderMode: function() {
return this.bm;
},
@@ -39,13 +40,14 @@ NPGClient.UIStyle.prototype = {
applyStyle: function(ctx) {
var self = this;
// fill style
if (fm == true) ctx.fillStyle = self.fc;
if (self.fm == true) ctx.fillStyle = self.fc;
// border mode
if (bm == true) {
ctx.lineWidth = bw;
ctx.strokeStyle = bc;
ctx.lineWidth = self.bw;
ctx.strokeStyle = self.bc;
}
}
*/
};