how to get the position of cursor in phab, Thanks.

Above the ptraw, I want to catch the LButtonDown, and get the positon
of the cursor . So that I can magnify the waveform. Who can help me
Thanks

You catch the button event with a PtRaw widget. The callback you
want for PtRaw is the RawEvent callback. In the callback routine,
one of the parameters will point to an Event Control block which will
have all the information you want, Event type, subtype, which button,
where the pointer is, etc. I recall that the pointer location is
absolute, so you need to translate based on the location of your
widget. It’s pretty well spelled out in the docs, but if you can’t
figure it out, ask again and I’ll post some code.

Thanks, maschoen.
I had a try like this:
EventMask :0x2
int
RawEvent( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
cbinfo )
{
/
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
printf(“RawEvent!\n”);
return( Pt_CONTINUE );
}
but no matter where I pressed on the ptraw. this function didn’t run.
I don’t know the reason. please help me.
( in void Draw_PtRaw( PtWidget_t *widget, PhTile_t *damage ) ,there
are some PgDrawILine ,PgDrawTrend. )

I also had a try of the callback of activate and Arm .
int
activatetest( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
cbinfo )
{
/
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
printf(“activate!\n”);
return( Pt_CONTINUE );
}


int
Armtest( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )

{
/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
printf(“Arm!\n”);
return( Pt_CONTINUE );
}
It’s still nothing to printf. please give me some help. some code
is best . Thanks

There are two ways to do this, the hard way and the easy way.
I’ve put an example of the easy way in my anonymous ftp site at:
schoenbrun.com. The file is pub/mousetest.pax.F. This contains a
PhAB workspace. Basically what I did with PhAB was to put a raw
widget
in the main window, and attach the raw event callback. In the process
of doing this I was asked which events go to the callback, and I just
chose the mouse button event. The code in the event handler is as
follows:

int
raw_event( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
PhPointerEvent_t *ptr_data;
int x,y;
int cur_button;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

fprintf(stderr,“event fired\n”);
switch(cbinfo->event->type)
{
case Ph_EV_BUT_PRESS:
ptr_data = (PhPointerEvent_t *)
PhGetData(cbinfo->event);
cur_button = ptr_data->buttons;
x = ptr_data->pos.x;
y = ptr_data->pos.y;
x += cbinfo->event->translation.x;
y += cbinfo->event->translation.y;
fprintf(stderr,“Mouse Button %xh pressed at
(%d,%d)\n”,
cur_button,x,y);
break;

default:
fprintf(stderr,“Event?
%lxh\n”,cbinfo->event->type);
return( Pt_CONTINUE );
}


If you want to do it the hard way, you create the widget yourself.
Below is a paraphrase of some code that does work.

[code:1:19d39993fe]
PtWidget_t *f_raw;



f_raw = PtCreateWidget(PtRaw,windows_widget,0,NULL)
PtAddEventHandler(f_raw, Ph_EV_BUT_PRESS,raw_event,NULL);



[/code:1:19d39993fe]


}

Thanks very much .
But I still don’t know the reason why the
printf(“RawEvent!\n”) can’t print in console. fprintf is
ok.

dxwangwrote:
Thanks very much .
But I still don’t know the reason why the
printf(“RawEvent!\n”) can’t print in console. fprintf is

ok.

Hmmm, I missed that subtlety. I thought you meant there was nothing
printed because you weren’t detecting the event. Where are you
sending fprintf to? stdout, or stderr? If the former, then
something strange is going on, as I believe printf must go to stdout.
If fprintf is going to stderr, then of course you stdout must
somehow be misdirected.

:wink:
if I want to show the x and y attach to the cursor . How should I do
?
Thanks. :laughing:

Do you mean show it in the Photon Window?
You could put a label widget somewhere and update it when the mouse
is
pressed. If you want to fancy, you could blank it out when the mouse
is
released too. Are you asking how to do this?

:laughing: I have solved it with a label. Thanks

But I think that if a label can move with the cursor in PHAB. It will
be the best.


:unamused:

Well, you can change the “position” resource in the
callback.
If you just want it to jump when you press and/or release the
button, then you are close. If you want the label to follow
the mouse around, either while the button is pushed,
or not, you will need to look at DRAG events.

:laughing: Thanks very much. You are very kindly. :slight_smile: