Simple drawing in Photon

Hi again,

Here’s the code:
///////////////////////////////////////////////// START CODE ///////////////////////////////////////////////

// Header
PhPoint_t p = {100, 100} ;

PgSetFillColor (Pg_RED) ;
PgDrawArc (&p, &p, 20, 120, Pg_DRAW_FILL) ;
}
//////////////////////////////////////////////// END
CODE ////////////////////////////////////////////////

This compiles fine, but it will not draw an arc, chord, or pie, no
matter what I do or what I change the flags to.

I’m sure I’m doing something (or not doing something) dumb and trivial,
but I’ve come at this problem from every angle I can even dream of.

If anyone can offer any advice, please, please do. I’m getting
desperate here. :frowning:

Thanks,
Shannon

Hi Shannon,

I inserted your code into a PhAB application and the only thing I had
to change in order for it to draw was to set the angles to a hex value.

PgDrawArc (&p, &p, 0x2000, 0x6000, Pg_DRAW_FILL) ;

These are not the angles that you specified but I got an arc on the screen.

Hope this helps
Regards
Brenda


Shannon Moore <a-cherian@nwu.edu> wrote:

Hi again,

Here’s the code:
///////////////////////////////////////////////// START CODE ///////////////////////////////////////////////

// Header
PhPoint_t p = {100, 100} ;

PgSetFillColor (Pg_RED) ;
PgDrawArc (&p, &p, 20, 120, Pg_DRAW_FILL) ;
}
//////////////////////////////////////////////// END
CODE ////////////////////////////////////////////////

This compiles fine, but it will not draw an arc, chord, or pie, no
matter what I do or what I change the flags to.

I’m sure I’m doing something (or not doing something) dumb and trivial,
but I’ve come at this problem from every angle I can even dream of.

If anyone can offer any advice, please, please do. I’m getting
desperate here. > :frowning:

Thanks,
Shannon

Gui Group <gui@qnx.com> wrote:

: Hi Shannon,

: I inserted your code into a PhAB application and the only thing I had
: to change in order for it to draw was to set the angles to a hex value.

: PgDrawArc (&p, &p, 0x2000, 0x6000, Pg_DRAW_FILL) ;

: These are not the angles that you specified but I got an arc on the screen.

Shannon: Keep in mind that the angles are in bi-grads, not degrees, so the arc
in your code might have been drawn correctly, but was too short to see.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

: I inserted your code into a PhAB application and the only thing I had
: to change in order for it to draw was to set the angles to a hex value.

: PgDrawArc (&p, &p, 0x2000, 0x6000, Pg_DRAW_FILL) ;

: These are not the angles that you specified but I got an arc on the screen.

Shannon: Keep in mind that the angles are in bi-grads, not degrees, so the arc
in your code might have been drawn correctly, but was too short to see.

Thanks for the information and advice. I changed the values to exactly what you
have above, and I’m still not getting anything drawn on the screen.

Is there anything else I could be doing wrong?

Shannon

Shannon Moore <a-cherian@nwu.edu> wrote:

: I inserted your code into a PhAB application and the only thing I had
: to change in order for it to draw was to set the angles to a hex value.

: PgDrawArc (&p, &p, 0x2000, 0x6000, Pg_DRAW_FILL) ;

: These are not the angles that you specified but I got an arc on the screen.

Shannon: Keep in mind that the angles are in bi-grads, not degrees, so the arc
in your code might have been drawn correctly, but was too short to see.

Thanks for the information and advice. I changed the values to exactly what you
have above, and I’m still not getting anything drawn on the screen.

Is there anything else I could be doing wrong?

Where are you calling that code from – it’s not in a PtRaw widget’s
draw function, is it?

If you’re drawing in a widget’s draw function, the library sets up a lot
of stuff for you that you have to take care of yourself otherwise. You
can get away without setting a translation or clipping, but you must
tell Photon which region you want to draw from – see PgSetRegion() in
the docs.


Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.

Where are you calling that code from – it’s not in a PtRaw widget’s
draw function, is it?

If you’re drawing in a widget’s draw function, the library sets up a lot
of stuff for you that you have to take care of yourself otherwise. You
can get away without setting a translation or clipping, but you must
tell Photon which region you want to draw from – see PgSetRegion() in
the docs.

Well, the answer to your question is “I’m not really sure.” I’m trying to update
code that someone else wrote (and that person isn’t here anymore). I believe that he
tried to do everything in PhAB, but when I started fixing things, I just editted the
…c files directly. I’m trying not to use widgets as much as possible. So far, that
has been fine for drawing simple figures like squares, circles, and block letters
(I didn’t use PgSetRegion for any of those).

Anyway, now I’m trying to draw a polygon (code below). Again, the function calls
return '0’s, indicating successful
completion. However, no polygon appears on the screen. (I’ve left a portion of
commented out code in
at the bottom. That code draws a block T just fine…)

I’m most appreciative of any help here.
Thanks,
Shannon

//////////////////////////////////////
START CODE //////////////////////////////////////////////

void draw_T1 (int xstart, int ystart)
{
int rxstart, rystart, rx3, ry3, rx6, rxend, ryend ;

PhPoint_t o ;
PhPoint_t p[8] ;

xend = xstart + 63 ;
yend = ystart + 63 ;
x3 = xstart + 21 ;
x6 = xstart + 42 ;
y3 = ystart + 21 ;
y6 = ystart + 42 ;

rxstart = ( (xstart * 0.707) + (ystart * 0.707) ) ;
rystart = ( (xstart * -0.707) + (ystart * 0.707) ) ;

rx3 = ( (x3 * 0.707) + (y3 * 0.707) ) ;
ry3 = ( (x3 * -0.707) + (y3 * 0.707) ) ;

rx6 = ( (x6 * 0.707) + (y6 * 0.707) ) ;

rxend = ( (xend * 0.707) + (yend * 0.707) ) ;
ryend = ( (xend * -0.707) + (yend * 0.707) ) ;

o.x = 0 ;
o.y = 0 ;

p[0].x = rxstart ;
p[0].y = rystart ;
p[1].x = rxstart ;
p[1].y = ry3 ;
p[2].x = rx3 ;
p[2].y = ry3 ;
p[3].x = rx3 ;
p[3].y = ryend ;
p[4].x = rx6 ;
p[4].y = ryend ;
p[5].x = rx6 ;
p[5].y = ry3 ;
p[6].x = rxend ;
p[6].y = ry3 ;
p[7].x = rxend ;
p[7].y = ryend ;

PgFFlush (Ph_START_DRAW) ;

PgSetFillColor (Pg_WHITE) ;
success = PgDrawPolygonmx (&p, 8, &o, Pg_DRAW_FILL | Pg_CLOSED) ;

PgFFlush (Ph_DONE_DRAW) ;

printf (“a zero = success; a negative one no. %d\n”, success ) ;

success = PgFlush () ;

printf (“a zero = success; a negative one no. %d\n”, success ) ;
/*
for (i=xstart ; i < xend ; i++) {
for (j=ystart ; j < y3 ; j++){
PgSetFillColor (Pg_WHITE) ;
PgDrawIRect (i, j, i, j, Pg_DRAW_FILL) ;
}
}

for (i=x3 ; i < x6 ; i++) {
for (j = ystart ; j < yend ; j++) {
PgSetFillColor (Pg_WHITE) ;
PgDrawIRect (i, j, i, j, Pg_DRAW_FILL) ;
}
}
*/
}

////////////////////////////////////// END CODE /////////////////////////////////////

Shannon Moore <a-cherian@nwu.edu> wrote:

Where are you calling that code from – it’s not in a PtRaw widget’s
draw function, is it?

If you’re drawing in a widget’s draw function, the library sets up a lot
of stuff for you that you have to take care of yourself otherwise. You
can get away without setting a translation or clipping, but you must
tell Photon which region you want to draw from – see PgSetRegion() in
the docs.

Well, the answer to your question is “I’m not really sure.” I’m trying to update
code that someone else wrote (and that person isn’t here anymore). I believe that he
tried to do everything in PhAB, but when I started fixing things, I just editted the
.c files directly. I’m trying not to use widgets as much as possible. So far, that
has been fine for drawing simple figures like squares, circles, and block letters
(I didn’t use PgSetRegion for any of those).

Then, I guess, you were lucky. If your application has only one window,
the library calls PgSetRegion() with that window’s rid whenever the
window is drawn, and never has a reason to set it to anything else. But
if you hade more windows, your code would draw on whatever window drew
last, which probably is not what you want.

Actually, in Photon 1, an application usually also draws its taskbar
icon. If the icon draws after the window, your drawing will go into the
taskbar (but will possibly be completely invisible due to clipping).

Anyway, now I’m trying to draw a polygon (code below). Again, the function calls
return '0’s, indicating successful
completion. However, no polygon appears on the screen. (I’ve left a portion of
commented out code in
at the bottom. That code draws a block T just fine…)

I put your code in a simple application, and indeed, the block T draws
if I uncomment it. And as I expected, it chooses to draw inside either
the window or the taskbar button depending on which drew last.

As for the polygon, I added the Pg_DRAW_STROKE flag just for fun, and
the polygon drew as a horizontal line. It turns out that all the Ys in
the p array are identical. I tried calling draw_T1() with xstart and
ystart being random numbers in the range 0 to 99; should they be
different? Are you sure the math that calculates the polygons is
correct?

\

Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.