Processing Damage Tiles in PtRaw Draw function

I’m trying to process the damage tile list in my draw function for my
PtRaw widget. The coordinates in the damage list are all relative to
the window (apparently) but all of my draw commands are relative to the
widgets coordinates.

How can I compare the two to determine IF I need to do a certain draw?

Bill Caroselli wrote:

I’m trying to process the damage tile list in my draw function for my
PtRaw widget. The coordinates in the damage list are all relative to
the window (apparently) but all of my draw commands are relative to the
widgets coordinates.

Your draw commands should be relative to the same origin as your
widget’s position and canvas are, i.e. to the top left corner of the
parent’s canvas. In other words, the rectangle that PtCalcCanvas()
returns can be passed straight to PgDrawRect() to draw your raw widget’s
canvas. Is that what you mean by “relative to the widget’s coordinates”?..

How can I compare the two to determine IF I need to do a certain draw?

PtWidgetOffset() gives you the difference between the origin of the
damage list and the origin used for positioning and drawing. In other
words, if you translate the damage list by that difference, it’ll have
the same origin as your canvas and your Pg calls. (If you translate the
damage list in place, remember to translate it back before returning.)

void
draw_f(PtWidget_t *widget, PhTile_t *damage )
{
PhTile_t damage_copy = PhCopyTiles( damage->next ); // Create a
copy of the damage list,
{
PhPoint_t offset;
PtWidgetOffset( widget, &offset );
offset.x += widget->extent.ul.x; // this also could be your
canvas
offset.y += widget->extent.ul.y;
PhDeTranslateTiles( damage_copy, &offset );
}
/
The damage_copy contains tiles which are relative to your widget
coordinates
iterate thru your intenal elements and intersect their rectangles
(PhIntersectTilings)
with the damage_copy, if intersection, then draw your element.
*/

PhFreeTiles( damage_copy );
return;
}
-Misha.

“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:cffuji$la7$1@inn.qnx.com

I’m trying to process the damage tile list in my draw function for my
PtRaw widget. The coordinates in the damage list are all relative to
the window (apparently) but all of my draw commands are relative to the
widgets coordinates.

How can I compare the two to determine IF I need to do a certain draw?

Misha Nefedov <mnefedov@qnx.com> wrote:
MN > void
MN > draw_f(PtWidget_t *widget, PhTile_t *damage )
MN > {
MN > PhTile_t damage_copy = PhCopyTiles( damage->next ); // Create a
MN > copy of the damage list,
MN > {
MN > PhPoint_t offset;
MN > PtWidgetOffset( widget, &offset );
MN > offset.x += widget->extent.ul.x; // this also could be your
MN > canvas
MN > offset.y += widget->extent.ul.y;
MN > PhDeTranslateTiles( damage_copy, &offset );
MN > }
MN > /
The damage_copy contains tiles which are relative to your widget
MN > coordinates
MN > iterate thru your intenal elements and intersect their rectangles
MN > (PhIntersectTilings)
MN > with the damage_copy, if intersection, then draw your element.
MN > */
MN > …
MN > PhFreeTiles( damage_copy );
MN > return;
MN > }
MN > -Misha.

This is very helpful. Thanks