Page 1 of 1

PostPosted: Tue Mar 20, 2007 6:20 pm
by Woofin
Can we move a gadget by changing the gadget's x and y values? I added the following method to my gadget:

void SpriteGadget.MoveTo(int NewX, int NewY) {
gadget.enabled = false;
gadget.visible = false;
gadget.x = NewX;
gadget.y = NewY;
gadget.visible = true;
gadget.enabled = true;
alert("Moved sprite to (" + gadget.x + "," + gadget.y + ")");

When I run my form and it executes this method, it shows an alert with the new (x,y) coordinates, but the gadget still appears in its original location; it does not actually move.

How can I move a gadget to a new (x,y)?

PostPosted: Tue Mar 20, 2007 7:24 pm
by nmc
try 'this.gadget.x' instead;
at least for .w and .h this works in my apps.

PostPosted: Tue Mar 20, 2007 8:18 pm
by Woofin
Thanks, nmc - good idea. I tried it but it still didn't work, no difference. Would you be willing to post your code illustrating how yours works? I tried modifying .w and .h to see if that would work and they don't reflect the changes either :(

PostPosted: Wed Mar 21, 2007 9:12 am
by nmc
My gadget is resized by the Orbforms runtime when the user rotates the screen or shows/hides the DIA.

Relevant code snippets:

Code: Select all
handler mainForm.onresize() {

struct GridGadget {
   UIGadget   gadget;
   Draw      G, DC;

where 'G' is my onscreen draw context and 'DC' is for offscreen drawing (avoids flickering).

Code: Select all
void GridGadget.Resize() {
   DC.create(this.gadget.w*2, this.gadget.h*2);

void GridGadget.ondraw() {
   G.draw(DC, 0, 0);
   G.line(clrFG, timeLineX-XOff, 0, timeLineX-XOff, this.gadget.h*2);

The attached draw context is automatically adjusted since I only do some extra work for my special draw functionality, so there seems to be no voodoo in changing the coordinates of a gadget.

And for the 'onpen' thread: this gadget uses the onpen events to show the coordinates of the pen in my grids context, moving the pen updates the coordinate-output; the mainForm ony uses onpenup() to cleanup the output, so 'pendown' and 'penmove' seems to be fired for the gadget while 'penup' must be fired in the form itself.

PostPosted: Wed Mar 21, 2007 1:04 pm
by Woofin
Excellent, it works now. Thank you very much for all of the help, including the onpen events. Very helpful! :)