|
From: <rob...@us...> - 2009-08-21 18:05:50
|
Revision: 22563
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=22563&view=rev
Author: rob_wheeler
Date: 2009-08-21 18:05:43 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
Battery monitor widget
Added Paths:
-----------
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
Added: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js (rev 0)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-08-21 18:05:43 UTC (rev 22563)
@@ -0,0 +1,62 @@
+var BatteryMonitor = Class.create({
+ initialize: function(domobj) {
+ this.domobj = domobj;
+ this.topics = [domobj.getAttribute("topic")];
+
+ this.key = domobj.getAttribute("key");
+ this.key2 = domobj.getAttribute("key2");
+ },
+
+ draw: function() {
+ var canvas = this.domobj.childNodes[0];
+ var span = this.domobj.childNodes[1];
+ var ctx = canvas.getContext('2d');
+ ctx.drawImage(this.img,0,0);
+ var width = 32 * this.percent / 100;
+ ctx.beginPath();
+ ctx.moveTo(38-width, 1);
+ ctx.lineTo(38, 1);
+ ctx.lineTo(40, 4);
+ ctx.lineTo(40,11);
+ ctx.lineTo(38,15);
+ ctx.lineTo(38-width,15);
+ ctx.lineTo(38-width,1);
+ if (this.percent > 30)
+ ctx.fillStyle = "rgb(0, 200, 0)";
+ else
+ ctx.fillStyle = "rgb(200, 0, 0)";
+ ctx.fill();
+ span.innerHTML = ' ' + this.percent + '%';
+ },
+
+ init: function() {
+ this.img = new Image();
+ this.img.src = 'battery_gray.png';
+ this.domobj.innerHTML = '<canvas width=41 height=16></canvas><span style="font-size:11px;position:relative;top:-3"></span>'
+
+ var width = this.domobj.getAttribute("width");
+ if(!width) width=120;
+ else width = parseInt(width);
+
+ var height = this.domobj.getAttribute("height");
+ if(!height) height=120;
+ else height = parseInt(height);
+
+ this.percent = 0;
+ this.draw();
+ },
+
+ receive: function(msg) {
+ if(msg[this.key] != null) {
+ this.percent = 100. * parseFloat(msg[this.key]) / parseFloat(msg[this.key2]);
+ if (this.percent > 100) this.percent = 100;
+ else if (this.percent < 0) this.percent = 0;
+ this.draw();
+ }
+ }
+});
+
+gRosClasses["BatteryMonitor"] = function(dom){
+ return new BatteryMonitor(dom);
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rob...@us...> - 2009-08-21 19:01:29
|
Revision: 22566
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=22566&view=rev
Author: rob_wheeler
Date: 2009-08-21 19:01:21 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
fix location of battery image
Modified Paths:
--------------
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-08-21 18:58:24 UTC (rev 22565)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-08-21 19:01:21 UTC (rev 22566)
@@ -31,7 +31,7 @@
init: function() {
this.img = new Image();
- this.img.src = 'battery_gray.png';
+ this.img.src = 'templates/images/toolbar/battery_gray.png';
this.domobj.innerHTML = '<canvas width=41 height=16></canvas><span style="font-size:11px;position:relative;top:-3"></span>'
var width = this.domobj.getAttribute("width");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rob...@us...> - 2009-08-21 20:08:35
|
Revision: 22577
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=22577&view=rev
Author: rob_wheeler
Date: 2009-08-21 20:08:23 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
round percentage to nearest integer
Modified Paths:
--------------
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-08-21 20:03:36 UTC (rev 22576)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-08-21 20:08:23 UTC (rev 22577)
@@ -48,7 +48,7 @@
receive: function(msg) {
if(msg[this.key] != null) {
- this.percent = 100. * parseFloat(msg[this.key]) / parseFloat(msg[this.key2]);
+ this.percent = Math.round(100. * parseFloat(msg[this.key]) / parseFloat(msg[this.key2]));
if (this.percent > 100) this.percent = 100;
else if (this.percent < 0) this.percent = 0;
this.draw();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rob...@us...> - 2009-09-03 20:07:47
|
Revision: 23776
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23776&view=rev
Author: rob_wheeler
Date: 2009-09-03 20:07:37 +0000 (Thu, 03 Sep 2009)
Log Message:
-----------
Call draw on image load instead of just during init
Modified Paths:
--------------
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-09-03 19:59:58 UTC (rev 23775)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-09-03 20:07:37 UTC (rev 23776)
@@ -2,45 +2,39 @@
initialize: function(domobj) {
this.domobj = domobj;
this.topics = [domobj.getAttribute("topic")];
+ this.img = new Element('img', {'src' : '/webui/webui/templates/images/toolbar/battery_gray.png', 'width': 41, 'height': 16});
+ this.canvas = new Element('canvas', {'width': this.img.width, 'height': this.img.height});
+ this.domobj.appendChild(this.canvas);
+ this.span = new Element('span', {'style':"font-size:11px;position:relative;top:-3"});
+ this.domobj.appendChild(this.span);
+ this.img.onload = this.draw.bind(this);
},
draw: function() {
- var canvas = this.domobj.childNodes[0];
- var span = this.domobj.childNodes[1];
- var ctx = canvas.getContext('2d');
- ctx.drawImage(this.img,0,0);
- var width = 32 * this.percent / 100;
- ctx.beginPath();
- ctx.moveTo(38-width, 1);
- ctx.lineTo(38, 1);
- ctx.lineTo(40, 4);
- ctx.lineTo(40,11);
- ctx.lineTo(38,15);
- ctx.lineTo(38-width,15);
- ctx.lineTo(38-width,1);
- if (this.percent > 30)
- ctx.fillStyle = "rgb(0, 200, 0)";
- else
- ctx.fillStyle = "rgb(200, 0, 0)";
- ctx.fill();
- span.innerHTML = ' ' + this.percent + '%';
+ if (this.img.complete) {
+ var ctx = this.canvas.getContext('2d');
+ ctx.drawImage(this.img,0,0);
+ var width = 32 * this.percent / 100;
+ ctx.beginPath();
+ ctx.moveTo(38-width, 1);
+ ctx.lineTo(38, 1);
+ ctx.lineTo(40, 4);
+ ctx.lineTo(40,11);
+ ctx.lineTo(38,15);
+ ctx.lineTo(38-width,15);
+ ctx.lineTo(38-width,1);
+ if (this.percent > 30)
+ ctx.fillStyle = "rgb(0, 200, 0)";
+ else
+ ctx.fillStyle = "rgb(200, 0, 0)";
+ ctx.fill();
+ }
+ this.span.innerHTML = ' ' + this.percent + '%';
},
init: function() {
- this.img = new Image();
- this.img.src = '/webui/webui/templates/images/toolbar/battery_gray.png';
- this.domobj.innerHTML = '<canvas width=41 height=16></canvas><span style="font-size:11px;position:relative;top:-3"></span>'
-
- var width = this.domobj.getAttribute("width");
- if(!width) width=120;
- else width = parseInt(width);
-
- var height = this.domobj.getAttribute("height");
- if(!height) height=120;
- else height = parseInt(height);
-
this.percent = 0;
- //this.draw();
+ this.draw();
},
receive: function(topic, msg) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|