Confused about .onpenmove() events

Discuss OrbForms Designer and PocketC Architect

Postby Woofin on Tue Mar 20, 2007 12:28 am

Sorry to be a pest with questions... this one has me stumped. I have a Player gadget that simply holds a bitmap; I want the user to be able to tap and drag this gadget to new locations on the form, but I can't get it working. The .onpendown() and .onpenmove() events fire (as evidenced when I put alerts within them) but when I try to update a label or handle the actual moving, nothing at all happens. I've added some additional events for the form, trying to see what gets fired... it looks like the OnPenDown() fires for the gadget, but the OnPenMove() fires for the form. However, the line drawing code for the form doesn't work either. What I am trying to do is allow the user to drag the gadget to a new location on the main form. Here is my code for the main form; any help is appreciated:

// mainForm.oc

int PenX;
int PenY;
int sgn(int number);

Draw draw;

handler mainForm.onopen() {
}

handler gadPlayer.onpendown() {
PenX = event.x;
PenY = event.y;
}

handler gadPlayer.onpenmove() {
int NewX;
int NewY;

NewX = event.x - PenX;
NewY = event.y - PenY;

gadget.visible=false;
gadget.x = gadget.x + 5; // sgn(NewX);
gadget.y = gadget.y + 5; //sgn(NewY);
gadget.visible=true;
}

int sgn(int number) {
int sign;
sign = 0;
if (number > 0)
sign = 1;
if (number < 0)
sign = -1;
return sign;
}

handler mainForm.onpenmove() {
//alert("Form pen move");
lblPen.text = "Pen: (" + event.x + "," + event.y + ")";
draw.begin();
draw.line(5, PenX, PenY, event.x, event.y);
draw.end();
}

handler mainForm.onpendown() {
//alert("Form pen down");
PenX = event.x;
PenY = event.y;
}
Woofin
 
Posts: 11
Joined: Thu Mar 15, 2007 2:35 pm
Location: USA

Postby samps on Tue Mar 20, 2007 5:58 am

In your sample code you don't call draw.attachForm or .attachGadget anywhere..... Could that be the cause?

Samps
Ubuntu user #82
samps
 
Posts: 143
Joined: Tue Feb 20, 2001 12:33 am
Location: Australia

Postby Woofin on Tue Mar 20, 2007 11:14 am

Thanks, Samps! You're right, the form needed a "draw.attachForm(mainForm);" statement, but I'm still missing something... after adding that statement, the pen only draws within the gadget area, not on the entire form. but I only had the line draws in there for debugging... outstanding issues are:

(1) The mainForm.onpenmove() fires, but lblPen.Text never gets updated/displayed. Why not?

(2) I can't get the gadget to move. I added a method to gadPlayer called "MoveTo()" as follows:

void PlayerGadget.MoveTo(int NewX, int NewY) {
//alert ("Moving from (" + gadget.x + "," + gadget.y + ") to (" + NewX + "," + NewY + ")");
gadget.visible=false;
gadget.x = NewX;
gadget.y = NewY;
gadget.visible=true;
x = gadget.x;
y = gadget.y;
//alert ("Moved to (" + gadget.x + "," + gadget.y + ")");
}

then within mainForm.oc's "onpenmove()" event I added:
gadPlayer.MoveTo(gadPlayer.x+5, gadPlayer.y+5);
mainForm.redraw;

The gadPlayer's "MoveTo" method is fired but the gadget never moves.
I tried putting "draw.attachgadget(gadPlayer)" into the mainForm's onopen() event but it doesn't recognize "gadPlayer" (which is the name of my gadget)... so that doesn't work.

All I want to do is find a way to allow the user to move the gadget around by dragging the pen. Any suggestions?
Woofin
 
Posts: 11
Joined: Thu Mar 15, 2007 2:35 pm
Location: USA


Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 3 guests

cron