version v0.1.1

This commit is contained in:
2016-02-13 21:06:40 +01:00
parent 372b4bfbf2
commit 8c5ac0a6d9
15 changed files with 475 additions and 79 deletions

View File

@@ -8,14 +8,7 @@ NPGClient.AppPage = function(n) {
Object.defineProperty(this, 'id', { value: NPGClient.pageCount++ });
this.name = n || '';
// draw loop paramaters
this.loopIntervalId = 0;
this.loopDelay = 40;
// canvas
this.canvas_id = "";
this.canvas_bcol = "";
this.canvas = {};
this.ctx = {};
this.idx = NPGClient.pageCount;
// ui elements
this.uiElems = [];
@@ -26,49 +19,19 @@ NPGClient.AppPage.prototype = {
constructor: NPGClient.AppPage,
//
setLoopDelay: function(d) {
this.loopDelay = d;
},
//
startDrawLoop: function() {
var self = this;
self.loopIntervalId = setInterval(function() {
self.run();
}, self.loopDelay);
},
//
stopDrawLoop: function() {
var self = this;
clearInterval(self.loopIntervalId);
self.loopIntervalId = 0;
},
//
run: function() {
var self = this;
self.drawUI();
},
//
configUI: function(id, w, h, c) {
var self = this;
self.canvas_id = id;
self.canvas = document.getElementById(id);
self.ctx = self.canvas.getContext("2d");
self.canvas.width = w;
self.canvas.height = h;
self.canvas_bcol = c;
},
//
addUIObject: function(c) {
var self = this;
self.uiElems.push(c);
},
//
getUIElems: function() {
var self = this;
return self.uiElems;
},
//
getUIElemByName: function(name) {
var self = this;
@@ -79,36 +42,12 @@ NPGClient.AppPage.prototype = {
return undefined;
},
//
drawUI: function() {
//
printInfo: function() {
var self = this;
self.clear();
self.drawUIBackground();
self.drawUIObjects();
},
console.log('[NPGClient.AppPage] name:' + self.name + ', nUIElems=' + self.pages.length);
//
drawUIBackground: function() {
var self = this;
self.ctx.fillStyle = self.canvas_bcol;
self.ctx.fillRect(0, 0, self.canvas.width, self.canvas.height);
},
//
drawUIObjects: function() {
var self = this;
if (self.uiElems.length > 0) {
for (var i = 0; i < self.uiElems.length; i++)
self.uiElems[i].draw(self.ctx);
}
},
}
//
clear: function() {
var self = this;
self.ctx.clearRect(0, 0, self.canvas.width, self.canvas.height);
},
};

View File

@@ -0,0 +1,48 @@
/**
* @file page_handler.js
* @author frtk@tetalab
*/
NPGClient.PageHandler = {
currPage: '',
pages: [],
//
setup: function() {
var self = this;
self.currPage = 'login';
// create login page
self.createLoginPage();
},
//
getCurrPageUIElems: function() {
var self = this;
return self.getPageByName(self.currPage).getUIElems();
},
//
getPageByName: function(name) {
var self = this;
if (self.pages.length > 0) {
for (var i = 0; i < self.pages.length; i++) {
if (name == self.pages[i].name) return self.pages[i];
}
}
return undefined;
},
// create login page
createLoginPage: function() {
//
var self = this;
var p = new NPGClient.AppPage('login');
// Title label
p.addUIObject(new NPGClient.UILabel('login', NPGClient.LABELS.TITLE));
self.pages.push(p);
},
};