photon: more on screen contexts

I have a question about photon (I think that’s not documented).
In the documentation all drawing functions works on various sorts of
contexts. Effectively what’s the CURRENT context? the screen? The
visible area of the last created/manipulated widget? (CURRENT
intended as the default one provided by the library when specifying
NULL)

As read in some examples the fastest (in code terms) way to draw
something is: initalize photon, create a window, than magically the
context will be the window itself. But what I have to do if I want
to draw on the screen everywere (not only in my window) without using
a direct context? (a sort of “root” context)

The photon screen savers do a magic thing: they draws exactly on the
whole screen. How they do that?

Thanks - Dedalo

Hi Dedalo,

I have spoken to one of the developers and they have provided the following
info:


Dedalo <dedalo@ipv7.net> wrote:

I have a question about photon (I think that’s not documented).
In the documentation all drawing functions works on various sorts of
contexts. Effectively what’s the CURRENT context? the screen? The
visible area of the last created/manipulated widget? (CURRENT
intended as the default one provided by the library when specifying
NULL)

PhDCGetCurrent for Draw Contexts
PgGetGC for graphics contexts.

All Draw Contexts have a GC.

As read in some examples the fastest (in code terms) way to draw
something is: initalize photon, create a window, than magically the
context will be the window itself. But what I have to do if I want
to draw on the screen everywere (not only in my window) without using
a direct context? (a sort of “root” context)

The photon screen savers do a magic thing: they draws exactly on the
whole screen. How they do that?

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? :stuck_out_tongue_winking_eye:

Thanks - Dedalo

Hope this helps
Regards
Brenda

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? :stuck_out_tongue_winking_eye:

the last part is clear :slight_smile:, at least

Hope this helps
Regards
Brenda

Dedalo

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? :stuck_out_tongue_winking_eye:

the last part is clear > :slight_smile:> , at least

Hope this helps
Regards
Brenda

Dedalo