Mouse Coordinates

bridged with qdn.public.photon
Post Reply
lucas

Mouse Coordinates

Post by lucas » Tue Nov 25, 2003 3:05 pm

Hey,
I'm writing a program that needs to decoded the mouse position inside of
a widgets callback routing, i am able to get the mouse position, but it
is relitive to the upper left hand corner of the screen. How can i get
it relitive position to the upper left hand corner of my window/widget.

Thanks,
Lucas

Guest

Re: Mouse Coordinates

Post by Guest » Wed Nov 26, 2003 8:24 pm

hi Lucas,

You could use the following snippet to translate the mouse coordinates to be
relative to the window it is in..
This function was attached to the window in a Pt_CB_RAW callback that had
its mask set for Ph_EV_BUT_RELEASE events

int mouse_coordinates_cb( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t *cbinfo )
{
int mouse_x;
int mouse_y;
PhRect_t *canvas_rect;
PhPoint_t offset;
PhRect_t *event_rect;

if( ( cbinfo->event->type == Ph_EV_BUT_RELEASE ) && (
cbinfo->event->subtype == Ph_EV_RELEASE_REAL ) )
{
/* Gets the Windows canvas rectangle */
canvas_rect = PtCalcCanvas(widget, NULL );

/* Figure out the offset */
offset.x = canvas_rect->ul.x;
offset.y = canvas_rect->ul.y;

/* Get the event rectangle for the mouse event - should be a 1 pixel
by 1 pixel rectange */
event_rect = PhGetRects(cbinfo->event);

/* Detranslate the position - figure out the relative co-ordinates
*/
PhDeTranslateRect( event_rect, &offset);

/* The upper left co-ordinates is the mouse pointer */
mouse_x = event_rect->ul.x;
mouse_y = event_rect->ul.y;
printf("Relative Mouse pos X = %d, Y = %d\n",mouse_x, mouse_y);
}
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
return( Pt_CONTINUE );
}

Let me know if this helps.
Regards
Brenda


"lucas" <lblancher@ati.sl.on.ca> wrote in message
news:3FC36FB9.7010309@ati.sl.on.ca...
Hey,
I'm writing a program that needs to decoded the mouse position inside of
a widgets callback routing, i am able to get the mouse position, but it
is relitive to the upper left hand corner of the screen. How can i get
it relitive position to the upper left hand corner of my window/widget.

Thanks,
Lucas

Lucas Blancher

Re: Mouse Coordinates

Post by Lucas Blancher » Sat Nov 29, 2003 11:26 pm

Hey,

Thanks Brenda for the offset information, it worked great! i just had to
offset the widgets area, to the widgets canvas, and all was good.

Thanks,
Lucas

Post Reply

Return to “qdn.public.photon”