Page 1 of 1

PostPosted: Tue Mar 20, 2007 12:28 am
by Woofin
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.x = gadget.x + 5; // sgn(NewX);
gadget.y = gadget.y + 5; //sgn(NewY);

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.line(5, PenX, PenY, event.x, event.y);

handler mainForm.onpendown() {
//alert("Form pen down");
PenX = event.x;
PenY = event.y;

PostPosted: Tue Mar 20, 2007 5:58 am
by samps
In your sample code you don't call draw.attachForm or .attachGadget anywhere..... Could that be the cause?


PostPosted: Tue Mar 20, 2007 11:14 am
by Woofin
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.x = NewX;
gadget.y = NewY;
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);

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?