mouse Coordinate between Ptraw's Draw Function and RawEvent

in qnx6.3.0
PtRawDrawFuncion( PtWidget_t *widget, PhTile_t *damage )
{

PtCalcCanvas( widget, &raw_canvas ); //
PtClipAdd( widget, &raw_canvas );//
rect=raw_canvas;//
rect.ul.x+=40,rect.ul.y+=40,rect.lr.x-=40,rect.lr.y-=40;//
PgSetStrokeColor(Pg_BLUE ); //Do our drawing…
PgDrawRect(&raw_canvas, Pg_DRAW_STROKE );
PgDrawRect(&rect, Pg_DRAW_STROKE );
fprintf(stderr,“canvas.ul.x=%d,canvas.ul.y=%d;rect.ul.x=%d,rect.ul.y=%d\n”,raw_canvas.ul.x,raw_canvas.ul.y,rect.ul.x,rect.ul.y);
//41,0 ; 81,40
// I don’t use PgSetTranslation (&raw_canvas.ul, Pg_RELATIVE);

}

PtRawRawEvent( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{

case Ph_EV_BUT_PRESS:
ptr_data = (PhPointerEvent_t *) PhGetData(cbinfo->event);
cur_button = ptr_data->buttons;
x = ptr_data->pos.x; //52
y = ptr_data->pos.y;//125
PgSetStrokeColor(Pg_RED); // the first method
PgDrawILine(x,0,x,y);
PgDrawILine(0,y,x,y);
x += cbinfo->event->translation.x;//41
y += cbinfo->event->translation.y;//41
PgSetStrokeColor(Pg_DGREEN ); // the second method
PgDrawILine(x,0,x,y);
PgDrawILine(0,y,x,y);
PgSetStrokeColor(Pg_MAGENTA );// the third method
PgSetTranslation (&raw_canvas.ul, Pg_RELATIVE);
PgDrawILine(x,0,x,y);
PgDrawILine(0,y,x,y);
rect.ul.x *= -1;.
rect.ul.y *= -1;
PgSetTranslation (&raw_canvas.ul, Pg_RELATIVE);

//my purpose: when I press the left button in PtRaw , I hope to draw two lines, and the cross point is the point where mouse pressed… but all the three draw methods can’t carry out it. I don’t know how to change the point (0,0) in DrawEvent Function to the raw_canvas.ul in PtRawDrawFuction.
}

I don’t understand what you want, but if you use PgSetTranslation, most likely to use PgClearTranslation.

I have tried three methods to show a horizontal line and a vertical one.
my purpose is that when I press the left button in PtRaw , I hope to draw this two lines, and the focus is the point where mouse pressed. but all the three draw methods can’t carry out it. the focus isn’t the point where mouse pressed. Maybe I need to change the point (0,0) in DrawEvent Function to the raw_canvas.ul in PtRawDrawFuction. But I know how to do that.

To be simple, I want to draw a point when I press the left button on the ptraw. so I capture Ph_EV_BUT_PRESS, then draw two lines in three methods , but the focus of two lines isn’t the point where the mouse is.

Is PgClearTranslation equal to the below three lines ?
rect.ul.x *= -1;.
rect.ul.y *= -1;
PgSetTranslation (&raw_canvas.ul, Pg_RELATIVE);

PgClearTranslation is clear translation that you set with PgSetTranslation. It equvivalent to:
rect.ul.x = 0;.
rect.ul.y = 0;
PgSetTranslation (&rect.ul, 0);

How I understand you point drawed in some translation from pointer, yes?
Than:

case Ph_EV_BUT_PRESS:
ptr_data = (PhPointerEvent_t *) PhGetData(cbinfo->event);
cur_button = ptr_data->buttons;
x = ptr_data->pos.x + you_raw_wgt->area.pos.x;
y = ptr_data->pos.y + you_raw_wgt->area.pos.y;
PgSetStrokeColor(Pg_RED);
PgDrawILine(x,0,x,y);
PgDrawILine(0,y,x,y);

OR

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 ;
rect.ul.x = you_raw_wgt->area.pos.x;
rect.ul.y = you_raw_wgt->area.pos.y;
PgSetTranslation (&rect.ul, 0);
PgSetStrokeColor(Pg_RED);
PgDrawILine(x,0,x,y);
PgDrawILine(0,y,x,y);
PgClearTranslation();

I done mistake, must be like this:

PtWindowFrameSize( NULL, main_window_wgt, &main_window_canvas);

x = ptr_data->pos.x - you_raw_wgt->area.pos.x - main_window_canvas.ul.x;
y = ptr_data->pos.y - you_raw_wgt->area.pos.y - main_window_canvas.ul.y;

how to get you_raw_wgt->area.pos.x , is it raw-canvas.u.l.x (PtCalcCanvas( widget, &raw_canvas );)?

widget->area.pos.x
or
ABW_name_you_raw_wgt->area.pos.x if you write in PhAB
or
poiner_to_you_created_raw_wgt->area.pos.x

1,2 both not right.

  1.               PtWindowFrameSize( NULL,ABW_base, &main_window_canvas);
               x = ptr_data->pos.x-main_window_canvas.ul.x;  
       y = ptr_data->pos.y--main_window_canvas.ul.y;	
    
  2.            PtWindowFrameSize( NULL,ABW_base, &main_window_canvas);
               x = ptr_data->pos.x-raw_canvas.ul.x-main_window_canvas.ul.x;  
       y = ptr_data->pos.y-raw_canvas.ul.y-main_window_canvas.ul.y;

it is still not right:
PtWindowFrameSize( NULL,ABW_base, &main_window_canvas);
x = ptr_data->pos.x-ABW_PtRaw1->area.pos.x-main_window_canvas.ul.x;
y = ptr_data->pos.y-ABW_PtRaw1->area.pos.y-main_window_canvas.ul.y;

from the lines ,it is similar to :
PtCalcCanvas( ABW_PtRaw1, &raw_canvas );
PtWindowFrameSize( NULL,ABW_base, &main_window_canvas);
x = ptr_data->pos.x-raw_canvas.ul.x-main_window_canvas.ul.x;
y = ptr_data->pos.y-raw_canvas.ul.y-main_window_canvas.ul.y;

As I know canvas calculate from top left corner of widget, but not from top left corner of the screen, so if you widget have canvas decrement it too!
x = ptr_data->pos.x - ABW_you_raw_wgt->area.pos.x - raw_canvas.ul.x - main_window_canvas.ul.x; !!!

You also must decrement position of you base window: ABW_base->area.pos.x

Thanks for your advice.
x = ptr_data->pos.x - ABW_base->area.pos.x - main_window_canvas.ul.x; is right.

And I still don’t know when to use it like this:
x = ptr_data->pos.x;
y = ptr_data->pos.y;
x += cbinfo->event->translation.x;
y += cbinfo->event->translation.y;

Maybe when you do DRAG or DRAG & DROP

qnxloader, Very Thanks! You are very kind! :wink: