Bill Caroselli wrote:
Dave Rempel <firstname.lastname@example.org
DR > Bill Caroselli wrote:
I have a new problem.
Why is my translation wrong?
DR > The Translation is relative to the translation in the current GC. What
DR > I think you really want to do is set some state on your PtRaw widget
DR > (see "Storing arbitrary user data" in the doc's for PtWidget) that means
DR > that you want to draw this new object. Then call PtDamageWidget on your
DR > PtRaw so it get's drawn in the proper order (the current translation
DR > should be what you expect it to be, as will be the clipping).
My PtRaw is very complicated (i.e. many graphical objects). When some
external event occurs I merely want to draw one more dot on the screen,
and possibly erase one (draw it with background color and then draw the
If I damage the widget then I have to redraw *all* the dots. There can
be as many as 10,000 (more likely 3000 to 5000). And I want to do this
10 times a second. I can't draw the whole PtRaw 10 times a second.
The system isn't fast enough.
Generally a widget's draw function shouldn't do a lot of work (this
includes PtRaw's). Given that, then what I think you want to do is
create an offscreen context to hold what your PtRaw should currently
look like (PdCreateOffscreenContext()). You can then update the
offscreen context to look like what ever you want, when ever you want.
In your PtRaw's draw function you call PgContextBlit or
PgContextBlitArea to copy the contents of the offscreen context to the
location of your PtRaw widget's canvas. You can be even smarter about
it and look at the damage rects (remember to look starting at the second
one, since the first damage rect is always the entire canvas) and copy
just the portions you need. Offscreen Contexts are hardware
accelerated, so they are better than PhImage_t's and Memory Context's
generally. The other change you would have to do is instead of using
PtBlit you'd have to use PgContextBlit with the offscreen context as the
source and destination contexts. IIRC you are also using a
PtOSContainer already, you probably won't need it if you are using this
method to reduce flicker, but if you still need it for other reasons,
make sure that in your widget draw function that you call
PhDCGetCurrent() for the destination context parameter of
PgContextBlit(), since you will be wanting to blit to the OSContainers's
offscreen context, not the actual display (OS Container's offscreen
context needs to kept up to date so that it can handle exposes
correctly). It's generally good practice to use PhDCGetCurrent() for
blitting to the "screen" instead of NULL anyways.
Look at "Raw Drawing and Animation: Video Memory Offscreen" for
examples of using an offscreen context.
So, can I know the correct graphics context to draw my dots into?
Or, can my non-photon code somehow call a user defined callback for my
PtRaw widget? (That would force the correct GC right?)
No, there is only (generally) one GC that gets used by the widget
engine, and it's translation and clipping is constantly changing, so the
only way for it to be gaurunteed to be correct is in the widgets draw
function when the widget engine calls it.