A Little Java Help Please
Posted: Sun Apr 20, 2014 8:43 am
Blue Dot Code from ECC (http://www.embeddedcc.com/hmi/external.js)
I tried to add some code to create another widget (just a larger blue dot). I want to create a number of widgets. I get the single widget to work fine but am stymied on how to do more than one.
BTW: I am new to Java. I understand what most of the code is doing as I have programmed in Visual Basic for years. I am sure I am missing something simple. I did make 2 new Vars.
I added the following text after
ctx.closePath();
}
// More widgets here!
var newWidgetObj1 = new Object;
var TYP_LBLUE_DOT = 41;
newWidgetObj1.desc = "L Blue Dot";
newWidgetObj1.typ = TYP_LBLUE_DOT;
registerNewWidget(newWidgetObj1);
//*****************************************************************************
//
//! draws a custom widget
//!
//! \param widgetObj
//!
//! This function performs the periodic, refresh-based updates to the UI. It
//! is called every tick, and can be used to display real-time data, etc
//!
//! \return None.
//
//*****************************************************************************
drawExtWidget = function (widgetObj){
var oncolor,offcolor;
var ctx = widgetObj.ctx;
ctx.font = '1em Verdana';
ctx.textAlign = 'center';
//Test for type
if(widgetObj.typ==TYP_LBLUE_DOT)
{
var scale=1.1;
var rad, radgrad2,radgrad3;
rad=20*scale;
ctx.lineWidth = 5*scale;
oncolor = '#0000CD';
offcolor = '#CECECE';
ctx.beginPath();
ctx.arc(widgetObj.xcoord,widgetObj.ycoord,rad,0,Math.PI*2,true);
//On/Off Color
ctx.fillStyle = (widgetObj.act)? oncolor : offcolor;
ctx.fill();
//Reflection
radgrad3 = ctx.createRadialGradient(widgetObj.xcoord-rad/2,widgetObj.ycoord-rad/2,0.25*rad,widgetObj.xcoord,widgetObj.ycoord,rad);
radgrad3.addColorStop(0, 'rgba(255,255,255,0.8)');
radgrad3.addColorStop(0.5, 'rgba(255,255,255,0.25)');
ctx.fillStyle = radgrad3;
ctx.fill();
//Bezzle
radgrad2 = ctx.createRadialGradient(widgetObj.xcoord,widgetObj.ycoord,0.85*rad,widgetObj.xcoord,widgetObj.ycoord,1.1*rad);
radgrad2.addColorStop(0, '#222222');
radgrad2.addColorStop(0.5, '#CDCDCD'); //cdcdcd CDCDCD
radgrad2.addColorStop(1, '#222222');
ctx.strokeStyle = radgrad2;
ctx.stroke();
//Draw the name
if(widgetObj.draw_txt)
{
ctx.fillStyle='black';
ctx.fillText(widgetObj.txt,widgetObj.xcoord,widgetObj.ycoord+25);
}
ctx.closePath()
// More widgets here!
else
{
}
}//drawExtWidget
//Set this variable to signal the script is loaded.
externalJSloading=0;
I tried to add some code to create another widget (just a larger blue dot). I want to create a number of widgets. I get the single widget to work fine but am stymied on how to do more than one.
BTW: I am new to Java. I understand what most of the code is doing as I have programmed in Visual Basic for years. I am sure I am missing something simple. I did make 2 new Vars.
I added the following text after
ctx.closePath();
}
// More widgets here!
var newWidgetObj1 = new Object;
var TYP_LBLUE_DOT = 41;
newWidgetObj1.desc = "L Blue Dot";
newWidgetObj1.typ = TYP_LBLUE_DOT;
registerNewWidget(newWidgetObj1);
//*****************************************************************************
//
//! draws a custom widget
//!
//! \param widgetObj
//!
//! This function performs the periodic, refresh-based updates to the UI. It
//! is called every tick, and can be used to display real-time data, etc
//!
//! \return None.
//
//*****************************************************************************
drawExtWidget = function (widgetObj){
var oncolor,offcolor;
var ctx = widgetObj.ctx;
ctx.font = '1em Verdana';
ctx.textAlign = 'center';
//Test for type
if(widgetObj.typ==TYP_LBLUE_DOT)
{
var scale=1.1;
var rad, radgrad2,radgrad3;
rad=20*scale;
ctx.lineWidth = 5*scale;
oncolor = '#0000CD';
offcolor = '#CECECE';
ctx.beginPath();
ctx.arc(widgetObj.xcoord,widgetObj.ycoord,rad,0,Math.PI*2,true);
//On/Off Color
ctx.fillStyle = (widgetObj.act)? oncolor : offcolor;
ctx.fill();
//Reflection
radgrad3 = ctx.createRadialGradient(widgetObj.xcoord-rad/2,widgetObj.ycoord-rad/2,0.25*rad,widgetObj.xcoord,widgetObj.ycoord,rad);
radgrad3.addColorStop(0, 'rgba(255,255,255,0.8)');
radgrad3.addColorStop(0.5, 'rgba(255,255,255,0.25)');
ctx.fillStyle = radgrad3;
ctx.fill();
//Bezzle
radgrad2 = ctx.createRadialGradient(widgetObj.xcoord,widgetObj.ycoord,0.85*rad,widgetObj.xcoord,widgetObj.ycoord,1.1*rad);
radgrad2.addColorStop(0, '#222222');
radgrad2.addColorStop(0.5, '#CDCDCD'); //cdcdcd CDCDCD
radgrad2.addColorStop(1, '#222222');
ctx.strokeStyle = radgrad2;
ctx.stroke();
//Draw the name
if(widgetObj.draw_txt)
{
ctx.fillStyle='black';
ctx.fillText(widgetObj.txt,widgetObj.xcoord,widgetObj.ycoord+25);
}
ctx.closePath()
// More widgets here!
else
{
}
}//drawExtWidget
//Set this variable to signal the script is loaded.
externalJSloading=0;