Hi Dedalo,
I’ve gotten some more information from the developers…I hope this helps.
short answer:
You shouldn’t care so long as you follow the examples in the
doc’s and use PtDamage to cause a draw.
long answer:
When an app attaches to Photon via PhAttach() a default DC is created,
which in turn creates a default GC, with an undefined active rid (plus a
bunch of other default state. The default GC and DC are always around
even if they aren’t the currenttly active ones (PhDCSetCurrent(NULL) for
example will set the active draw context to the default one).
You could set the current region to the the rid of
the disjoint widget (see PgSetRegion, PtWidgetRid, PtFindDisjoint),
but once the window has drawn itself it is likely that the correct rid has
been set in the GC so you shouldn’t have to worry about it.
The raw widgets would be parented in the window widget, the window widget
is disjoint so it has a PtRegion associated with it (which is a widget
level abstraction of a photon region).
You will need to translate in the PtRaw’s Draw function so that it
renders where the PtRaw exists relative to the parent disjoint (PtWindow).
There are examples in the Doc’s under Raw Drawing and Animation on how to
do this (there are a couple of really simple PtRaw draw function
examples, one that just draws the super class, and another that draws an
ellipse). Normally you don’t have to worry about the active draw context,
graphics context, or active region, they should already be properly set
by the time the Raw widget’s draw function is called.
So if you are drawing multiple raws in multiple windows then using
PgSetRegion(PtWidgetRid(PtFindDisjoint(raw_widget_instance)));
would ensure that the draw stream is always emitted from the correct
region, but you probably don’t have to unless you call the raw widgets
draw function directly (instead of using PtDamage which is the correct
way to tell widgets to draw themselves), or swap out GC’s during the draw
call (which usually isn’t necessary either), since the parent
disjoint widget (PtWindow) would have already set the appropriate rid as the
emitting region. If you are planning on changing DC’s in the raw drawing
function call (eg: switching to an Offscreen context to render some stuff
offscreen and then blitting them to the screen), then you will need to
make the PgSetRegion call after activating the DC:
eg:
extern PdOffscreenContext_t *osc;
void raw_draw_fnc ( PtWidget_t *widget, PhTile_t *damage )
{
PhDrawContext_t *old_dc;
PhRect_t raw_canvas, srect;
/* assuming it points to a valid offscreen DC */
old_dc=PhDCSetCurrent(osc);
PgSetRegion(PtWidgetRid(PtFindDisjoint(widget)));
PgSetFillColor(Pg_RED);
PgDrawIRect(0,0,99,99,Pg_DRAW_FILL);
PgFlush();
PhDCSetCurrent(old_dc);
PtCalcCanvas (widget, &raw_canvas);
srect.ul.x=srect.ul.y=0;
srect.lr.x=raw_canvas.lr.x-canvas.ul.x;
srect.lr.y=raw_canvas.lr.y-canvas.ul.y;
PgContextBlit(osc, &srect, old_dc, &raw_canvas);
PgFlush();
}
Note: this is just an example…I actually haven’t tried to compile an
run it, but you should be able to get the idea.
I hope this helps
Regards
Brenda
Dedalo <dedalo@ipv7.net> wrote:
Gui Group <> gui@qnx.com> > wrote:
PhDCGetCurrent for Draw Contexts
PgGetGC for graphics contexts.
but my question was exactly that: If I create multiple widget, how I
can determine on which context I’m drawing?
If I create only one widget this is simple: the main window, but what
(for example) if I would have a windows with 3 raw widgets, and from
any portion of code I want to draw a line on a specific one?
And what if I don’t create anything? Where the draw streams goes?
All Draw Contexts have a GC.
So for changing a GC for a context I have to set the current context
to the interested one, change the GC and than reset the old context?
The screen savers put up a force front region that covers the entire
display and emits the draw stream from that region.
The GC has the region to emit from, and there is always a default Draw
Context made during the Init calls (which have a GC in them).
Clear as mud?
the last part is clear > > , at least
Hope this helps
Regards
Brenda
Dedalo