Hi,
Thankyou for your response. I still haven’t been able to solve my problem,
so I hope you might be able to help me out some more.
My goal is to grab the image from the button and have it draw where I click
on the raw widget. So it draws at the mouse position when I click. I’m not
sure how to work your dimensions suggestion into that. I have checked the
coordinates I use to draw the image and they seem to be relative to the Raw
widgets upper left corner. When I click in the upper left corner the draw
position is around 0,0. So I think my points are ok. The picture still
does not draw however. I’m thinking I still draw underneath the raw widget.
When I click near the right hand side of the widget I can see a small
section of the image appear on the parent window itself. Here is the code
I’ve been using to get the mouse coordinates and do the drawing. I only
just started learning how to use photon, so forgive me if I’m doing
something stupid. I tried using the translating functions, but that didn’t
work either. The mouse coordinates I am using to draw the image seem fine
without them.
Activate Callback:
int
drop_device( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
PhArea_t rawWidget;
PhPoint_t offset;
//get canvas of PtRaw widget
PhRect_t *canvas_rect=PtCalcCanvas(widget,NULL);
//get event rectangle, should be 1x1 for mouse click
//same as mouse pos
PhRect_t event_rect=PhGetRects(cbinfo->event);
/ eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
draw_flag=1;
//save mouse pos
draw_pos.x=event_rect->ul.x;
draw_pos.y=event_rect->ul.y;
PtDamageWidget(widget);//redraw canvas
return( Pt_CONTINUE );
}
Draw Callback:
void draw_stuff( PtWidget_t *widget, PhTile_t *damage ) {
PhPoint_t pos;
char *string;
PhRect_t canvas;
string=(char*)malloc(256);
PtSuperClassDraw( PtBasic, widget, damage );
PtCalcCanvas(widget,&canvas);
PtClipAdd(widget,&canvas);
pos.x=widget->canvas.ul.x+draw_pos.x;
pos.y=widget->canvas.ul.y+draw_pos.y;
sprintf(string,“I am at %d %d canvas is %d %d draw_pos is %d %d”,
pos.x,pos.y,widget->canvas.ul.x, widget->canvas.ul.y,
draw_pos.x,draw_pos.y);
if(draw_flag){
PgDrawPhImage(&draw_pos,button_image,NULL);
PtMessageBox(NULL,“Message”,string,NULL,NULL);
draw_flag=0;
}
PtClipRemove();
}
Thanks
Sara
“Misha Nefedov” <mnefedov@qnx.com> wrote in message
news:c0g2sg$sl8$1@inn.qnx.com…
It looks like you draw the image outside of the clipped area.
When your draw function is called, graphics translation is set to the
widget’s origin, make sure that you draw within your widget’s canvas.
Let’s say you want to draw it in the center of your widget:
PhImage_t *image = …; // whenever it is stored
PhPoint_t pos;
PhDim_t dim = { // calculate the internal dim of your widget
widget->canvas.lr.x - widget->canvas.ul.x + 1,
widget->canvas.lr.y - widget->canvas.ul.y + 1 };
/* center the image */
pos.x = widget->canvas.ul.x + ( dim.w - image->size.w )/2;
pos.y = widget->canvas.ul.y + ( dim.h - image->size.h)/2;
PgDrawImage( …, &pos, … );
-Misha.
“Sara Mallory” <> pushkin@cogeco.ca> > wrote in message
news:> 402A7480.4090301@cogeco.ca> …
Hi,
I am creating an application that includes a drawing area and a tool
bar. The goal is to click on a button, grab the picture from the
button’s resources and redraw it on the PtRaw widget after a mouse click
on the raw widget. I use PtGetResource to get the PhImage_t structure
and then use PgDrawPhImage to draw the image in the Raw widgets draw
function. The draw function does have the PtSuperClassDraw() call and I
damage the raw widget by calling PtDamageWidget(). The image does not
appear on the raw widget. I have an inkling that it is drawing behind
the widget, because when I used similar drawing code for the main window
the image got drawn.
Is there a flag I have to set to get the drawing working in the Raw
widget? I can’t find anything in the documentation. A shove in the
right direction would be greatly appreciated
Thanks
Sara