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

@@ -6,7 +6,64 @@
NPGClient.Utils = {
/**
* UI
* UI draw
*/
//
drawText: function(ctx, x1, y1, t, s, c) {
ctx.font = s;
ctx.fillStyle = c;
ctx.fillText(t, x1, y1);
},
//
drawFillRect: function(ctx, x1, y1, w, h) {
ctx.fillRect(x1, y1, w, h);
},
//
drawRect: function(ctx, x1, y1, w, h) {
ctx.beginPath();
ctx.rect(x1, y1, w, h);
ctx.stroke();
},
//
drawLine: function(ctx, x1, y1, x2, y2) {
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
},
//
drawSemiCircle: function(ctx, x, y, r, a1, a2, o, w, c) {
ctx.lineWidth = w;
ctx.strokeStyle = c;
ctx.beginPath();
ctx.arc(x, y, r, a1, a2, o);
ctx.closePath();
ctx.stroke();
},
drawFillCircle: function(ctx, x, y, r) {
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI*2, false);
ctx.fill();
ctx.stroke();
ctx.closePath();
},
//
drawCircle: function(ctx, x, y, r) {
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI*2, false);
ctx.closePath();
ctx.stroke();
},
/**
* UI Style
*/
//
setTxtStyle : function(ctx, style) {
@@ -37,32 +94,42 @@ NPGClient.Utils = {
//console.log(key + ' ' + NPGClient.userName);
if (NPGClient.userName.length < NPGClient.NAMEMAXSIZE) {
NPGClient.userName = NPGClient.userName + String.fromCharCode(key).toLowerCase();
console.log(NPGClient.userName);
//console.log(NPGClient.userName);
}
},
//
removeChar : function(key) {
removeChar: function(key) {
if (NPGClient.userName.length > 0) {
NPGClient.userName = NPGClient.userName.substring(0, NPGClient.userName.length - 1);
console.log(NPGClient.userName);
//console.log(NPGClient.userName);
}
},
//
validChar : function(key) {
validChar: function(key) {
return NPGClient.evtHandler.loginValidKey(key);
},
//
validName : function(key) {
validName: function() {
var len = NPGClient.userName.length;
return (len >= 0 && len <= NPGClient.NAMEMAXSIZE);
return (len >= 3 && len <= NPGClient.NAMEMAXSIZE);
},
//
maxNameSize: function() {
return NPGClient.userName.length == NPGClient.NAMEMAXSIZE;
},
//
resetName : function() {
resetName: function() {
NPGClient.userName = '';
},
//
nameEmpty: function() {
return (NPGClient.userName.length == 0);
},
}

View File

@@ -1,57 +0,0 @@
/**
* @file utils.js
* @author frtk@tetalab
*/
NPGClient.Utils = {
/**
* UI
*/
//
setTxtStyle : function(ctx, style) {
ctx.font = style.font;
ctx.fillStyle = style.col;
ctx.textAlign = style.align;
},
/**
* User Name
*/
//
addChar : function(key, name) {
if (name.length < NPGClient.NAMEMAXSIZE) {
name = name + String.fromCharCode(key).toLowerCase();
}
},
//
removeChar : function(key) {
if (name.length > 0) {
name = name.substring(0, name.length - 1);
}
},
//
validChar : function(key) {
return NPGClient.evtHandler.loginValidKey(key);
},
//
validName : function(key) {
var len = name.length;
return (len >= 0 && len <= NPGClient.MAXNAMESIZE);
},
//
resetName : function(name) {
name = '';
},
}