I am having a problem redrawing the graphics in a panel group. What I need is when I press a button, the currently drawn graphics to be cleared/disappear and the new to appear. This is what I have:
Code: Select all
var ctr = 0;
var win = new Window('palette', appName+ver, [100, 100, 330, 410], {resizeable: true});
win.graphics.backgroundColor = win.graphics.newBrush(win.graphics.BrushType.SOLID_COLOR, [0.2, 0.2, 0.2]);
win.ctl_group1 = win.add('panel', [10, 5, 220,200], 'Group 1', { borderStyle: "etched" });
win.ctl_group1.onDraw = redraw;
win.ctl_button1 = win.add('button', [5, 200, 141, 228], 'APPLY');
win.ctl_button1.onClick = function(){
win.ctl_group1.onDraw.call();
};
function redraw()
{
ctr++;
var gfx = this.graphics;
var pen;
if(ctr == 1)
{
pen = this.graphics.newPen (this.graphics.PenType.SOLID_COLOR, [.5, .6, .7, 1], 2);
gfx.newPath(); /* outer frame */
gfx.moveTo(0, 0);
gfx.lineTo(200, 0);
gfx.lineTo(200, 200);
gfx.lineTo(0, 200);
gfx.lineTo(0, 0);
gfx.strokePath(pen);
}
if(ctr > 1)
{
pen = this.graphics.newPen (this.graphics.PenType.SOLID_COLOR, [.6, .7, .8, 1], 1);
gfx.newPath(); /* inner frame */
gfx.moveTo(20, 20);
gfx.lineTo(180, 20);
gfx.lineTo(180, 180);
gfx.lineTo(20, 180);
gfx.lineTo(20, 20);
gfx.strokePath(pen);
}
}
Do you know of a working method that can clear the whole panel from the current graphics and start clean?
Thanks
Kiril