Raw Drawing Help

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

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

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

Well I figured out that problem, I can now draw the image where I click the
mouse. I decided to just start from scratch and try again. I’m not
positive what my problem was before. I do have a question about
PtDamageExtent(). This canvas area I have will eventually be drawing
multiple images and I didn’t want to redraw the entire raw area everytime an
image was added to the canvas. PtDamageExtent looks like the right
function, but I’m not sure if there is something special I should be doing
in the raw drawing function when I use PtDamageExtent. Should I be keeping
track of all the images that have been added to the canvas, or do I just
need the current one and just damage the area that it occupies?

thanks
Sara
“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

The PtDamageExtent() is a correct function to use in your case. It adds a
new damage rectangle into the widget’s list of damages. You do need to
maintain a list of images in your raw widget – if you want to optimize
drawing. When your draw function is called a list of damage tiles is passed
in.
The very first tile represents a bounding rectangle of all damages – for
your case don’t look at it.
You should look at the actual damages starting from the damage->next.
Iterate through the list (starting from damage->next) until you reach NULL
and intersect each tile->rect with rectangles of the images you have. Those
which intersect with damages – mark them.
Do the drawing of the marked images.
-Misha.

“Sara Mallory” <pushkin@cogeco.ca> wrote in message
news:c0pb27$m9u$1@inn.qnx.com

Well I figured out that problem, I can now draw the image where I click
the
mouse. I decided to just start from scratch and try again. I’m not
positive what my problem was before. I do have a question about
PtDamageExtent(). This canvas area I have will eventually be drawing
multiple images and I didn’t want to redraw the entire raw area everytime
an
image was added to the canvas. PtDamageExtent looks like the right
function, but I’m not sure if there is something special I should be doing
in the raw drawing function when I use PtDamageExtent. Should I be
keeping
track of all the images that have been added to the canvas, or do I just
need the current one and just damage the area that it occupies?

thanks
Sara
“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

Hi,

Thanks very much for your help so far. I’m having one very odd issue
with my raw canvas area. Everything works fine except the clipping area
or something seems to be wrong. I’m not positive that the clipping area
is the issue, it could be the translation, but I’ve tried everything I
can think of. Anyways, the problem I’m encountering is that the canvas
won’t draw images along the top and left hand sides of the canvas. At
the moment the canvas is in the top left hand corner of a window (that
contains a menu and toolbar also). The space in which images won’t be
drawn seems to correlate with the distance between the upper left corner
of the raw widget and the upper left corner of the window itself. If I
move the raw widget further down and to the right, this “no draw” space
increases. Below is my raw drawing function. Is there any reason this
should be happening?

Thanks
Sara



void draw_Stuff( PtWidget_t *widget, PhTile_t *damage ) {
PhRect_t canvas;
int i;

PtSuperClassDraw( PtBasic, widget, damage );
PtCalcCanvas(widget,&canvas);
PtClipAdd(widget,&canvas);
PgSetTranslation(&canvas.ul,Pg_RELATIVE);

/check damage tiles/
if(damage->next!=NULL){
damage=damage->next; /skip first tile/
}

while(damage!=NULL){
/examine damage to see if any tiles intersect with images in our list/
for(i=0; i<numDevices; i++){
if(PhRectIntersect(&Devices_.rect,&damage->rect)){
if(draw_flag){ /don’t do this stuff if draw flag isn’t set/
PgDrawPhImage(&Devices.rect.ul,Devices.image,0);
}
}
}
damage=damage->next;/go to next tile/
}

canvas.ul.x*=-1;
canvas.ul.y*=-1;
PgSetTranslation(&canvas.ul,Pg_RELATIVE);
PtClipRemove();


}_

The damages are relative to your disjoint widget (window). Make sure that
when
you intersect image rectangles with the damages that both rectangles have
the same origin.

something like this:
PhPoint_t offset;
PtWidgetOffset( widget, &offset );
offset.x += widget->canvas.ul.x;
offset.y += widget->canvas.ul.y;


for( i = 0; i < numDevices; i++ ) {
PhRect_t rect = Device_.rect;
PhTranslateRect( &rect, &offset );
if( PhRectIntersect( &damage->rect, &rect ) ) {

}
}


-Misha.

“Sara Mallory” <pushkin@cogeco.ca> wrote in message
news:4038B375.6090504@cogeco.ca…_

Hi,

Thanks very much for your help so far. I’m having one very odd issue
with my raw canvas area. Everything works fine except the clipping area
or something seems to be wrong. I’m not positive that the clipping area
is the issue, it could be the translation, but I’ve tried everything I
can think of. Anyways, the problem I’m encountering is that the canvas
won’t draw images along the top and left hand sides of the canvas. At
the moment the canvas is in the top left hand corner of a window (that
contains a menu and toolbar also). The space in which images won’t be
drawn seems to correlate with the distance between the upper left corner
of the raw widget and the upper left corner of the window itself. If I
move the raw widget further down and to the right, this “no draw” space
increases. Below is my raw drawing function. Is there any reason this
should be happening?

Thanks
Sara



void draw_Stuff( PtWidget_t widget, PhTile_t damage ) {
PhRect_t canvas;
int i;

PtSuperClassDraw( PtBasic, widget, damage );
PtCalcCanvas(widget,&canvas);
PtClipAdd(widget,&canvas);
PgSetTranslation(&canvas.ul,Pg_RELATIVE);

/check damage tiles/
if(damage->next!=NULL){
damage=damage->next; /skip first tile/
}

while(damage!=NULL){
/examine damage to see if any tiles intersect with images in our list/
for(i=0; i<numDevices; i++){
if(PhRectIntersect(&Devices> .rect,&damage->rect)){
if(draw_flag){ /don’t do this stuff if draw flag isn’t set/
PgDrawPhImage(&Devices> .rect.ul,Devices> .image,0);
}
}
}
damage=damage->next;/go to next tile/
}

canvas.ul.x
=-1;
canvas.ul.y
=-1;
PgSetTranslation(&canvas.ul,Pg_RELATIVE);
PtClipRemove();


}