Skip navigation.
Home
The QNX Community Portal

View topic - Map with reactangles drawing thread

Map with reactangles drawing thread

For discussion of realtime and/or embedded programming.

Map with reactangles drawing thread

Postby witos » Sat Jan 24, 2009 6:21 pm

Hello,

below I'll try to expalin my problem in other words.

I ve got one window in which I've got 2 background widgets. In one i have some widgets to controll parameters of ships ine the second i want my map to be drawn every 3 seconds (ship parameters are taken from the database so i have to actualize the situation on the map)

Ok everything works great till the moment in whichi i ckick on any ship controll widget (when i click on a widget in the seckond background).

The te reactangles are beind drawn in the second background not in the one i wanted them to.

I've read about prRaw but achieved nothing special.

I achieved drawing background reactangle of my map always in the backgroud1 widget.
Afeter tjhat without initializing ships i wanted to check if my thread warks good. To do that I implemented condition if (x == 1) then ectangle fill color = blue, else rectangle fill color = black.

And in my thread there is sleep (1) at the end.

when i run my application the background glimps gfrom one colour to another only if i move my mouce pointer from the background widget to outside and again in background widget. Otherwise the color is constant, just like thread doesnt want to work.

Pleace tell me what am I doing wrond
witos
Active Member
 
Posts: 11
Joined: Mon Jan 19, 2009 2:55 am

RE: Map with reactangles drawing thread

Postby juanplacco » Sat Jan 24, 2009 6:42 pm

mmm I'm not sure I'm understanding you... but if the problem is that you want to refresh your photon windows from a thread... you have to use PtEnter() and PtLeave()

http://www.qnx.com/developers/docs/6.3. ... enter.html

If the problem is that your widgets is been draw in a different parent... it's seems to be the way you are creating the widget...

It's seems to be easy what you need to do... Just call a timer, the function triggered reads the DB (every 3 seconds!! be carefull with the poor DB), get the data and draw some rectangles in some specific position... I understood right?

Try to "KIS" (Keep It Simple, you know :D ) your app...

Good luck,

Juan Manuel
juanplacco
Senior Member
 
Posts: 318
Joined: Wed May 17, 2006 2:30 pm

RE: Map with reactangles drawing thread

Postby witos » Sat Jan 24, 2009 10:11 pm

Everything you say seems very simple and this is how i do it but:

I want my rectangle always to be drawn from poin ( 0; 0) to point (100; 100) lokking from left upper corner of the window but when i click in the background widget which is below (but in the same main window) it starts to draw my reactangle in this background widget (not (0;0) (100; 100) but for example (0; 110) (100; 210)

some code:
...
PtEnter(0);
PgDrawIRect(0, 0, 100, 100, Pg_DRAW_FILL );
PtLeave(0);
...

end thats the problem, mz widget is drawn in different parent that i want and it depends on which background is active.

its so frustraiting Å
witos
Active Member
 
Posts: 11
Joined: Mon Jan 19, 2009 2:55 am

RE: Map with reactangles drawing thread

Postby PeterHuber » Sun Jan 25, 2009 8:11 pm

Photon applications are based on widgets. It's not a good idea to use the Pg* functions outside the drawing function of a widget. Please use widgets to build your GUI application. If the standard widgets are not enough, you can use the special widget PtRaw. In the draw callback function of PtRaw you are allowed to use the Pg* drawing functions.

Reading the documentation about PtRaw you will find the following hint:
"Don't call the drawing function directly from your program. Instead, damage the widget by calling PtDamageWidget(), and let the library call the drawing function."

-Peter
PeterHuber
Active Member
 
Posts: 55
Joined: Sat Sep 01, 2007 11:11 am
Location: Switzerland

RE: Map with reactangles drawing thread

Postby witos » Mon Jan 26, 2009 3:00 am

thanks for a hint,

I read about it but havent test it yet.

PtSetArg( &args[n], Pt_ARG_RAW_DRAW_F, &draw, 1 );
void draw( PtWidget_t *widget, PhTile_t *damage ) { ... }

now please advise me what shoud I pass as arguments to this draw function, as I want to draw a couple od reactangles (everyone is a ship which changes position (I get current position every 3 seconds so probably in the thread in which i get this positions i may call the draw function).

Thank you very much for help.

-witos
witos
Active Member
 
Posts: 11
Joined: Mon Jan 19, 2009 2:55 am

RE: Map with reactangles drawing thread

Postby qnxloader » Mon Jan 26, 2009 7:07 am

Use:
PgSetRegion(wgt->rid);
PgClearTranslation();
before use any PgDraw* funcs
qnxloader
Senior Member
 
Posts: 206
Joined: Mon Oct 06, 2003 8:29 am

RE: Map with reactangles drawing thread

Postby PeterHuber » Mon Jan 26, 2009 8:51 am

You should NOT call the draw function. The Photon library will call the draw function - e.g. after you called PtDamageWidget from your application. The draw function of widgets is also called for other reasons - e.g. after the area of the widget was destroyed by an other widget overlapping your PtRaw widget. The draw function itself has to get the data needed for drawing from your application (don't forget to protect this data by a mutex).

-Peter
PeterHuber
Active Member
 
Posts: 55
Joined: Sat Sep 01, 2007 11:11 am
Location: Switzerland

RE: Map with reactangles drawing thread

Postby witos » Mon Jan 26, 2009 4:11 pm

OK I still dont know how to do this so maybe you can show me it on example?

Lets say Ive got one PtRaw widget named MainRaw. In this MainRaw I want have 3 reactangles each size 10/10 which represents table of my ship stucts

struct ship{
int posx;
int posy;
};

During execution i can change position of each ship and i want it to chave result on position of drawn reactangles in my MainRaw.
MainRaw is a PtRaw which I created in PhAB.

I want to have refresh every x seconds. Please show me some code how to ashieve that.

-witos
witos
Active Member
 
Posts: 11
Joined: Mon Jan 19, 2009 2:55 am

Postby witos » Mon Jan 26, 2009 4:34 pm

thanks qnxloader,

Code: Select all
Use:
PgSetRegion(wgt->rid);
PgClearTranslation();
before use any PgDraw* funcs


Thats excactly what i needed.
witos
Active Member
 
Posts: 11
Joined: Mon Jan 19, 2009 2:55 am

PtRaw example

Postby PeterHuber » Tue Jan 27, 2009 8:49 am

1. create a new "QNX C Project"
2. Replace the source file with this
3. add the Photon library Ph in Project->Properties->Linker->extra libraries

Code: Select all
#include <stdlib.h>
#include <Pt.h>

static PhPoint_t pos[3] = {{0,0}, {0,0}, {0,0}};

static void draw(PtWidget_t *widget, PhTile_t *damage)
{
   PhRect_t canvas;
   int i;
   PtCalcCanvas(widget, &canvas);
   PgSetFillColor(Pg_GREY);
   PgDrawRect(&canvas, Pg_DRAW_FILL);
   PgSetFillColor(Pg_BLUE);
   for (i = 0; i < 3; i++)
   {
      PhPoint_t p;
      p.x = canvas.ul.x + pos[i].x % 500;
      p.y = canvas.ul.y + pos[i].y % 200;
      PgDrawIRect(p.x, p.y, p.x + 9, p.y + 9, Pg_DRAW_FILL);
   }
}
   
static int tick(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
{
   PtWidget_t *mainRaw = data;
   pos[0].x += 1;
   pos[0].y += 2;
   pos[1].x += 3;
   pos[1].y += 4;
   pos[2].x += 5;
   pos[2].y += 6;
   PtDamageWidget(mainRaw);
    return Pt_CONTINUE;
}
   
int main(int argc, char *argv[])
{
   PtWidget_t *window;
   PtWidget_t *mainRaw;
   PtWidget_t *timer;
   PtInit(NULL);
   window = PtCreateWidget(PtWindow, NULL, 0, NULL);
   PtSetResource(window, Pt_ARG_DIM, ((PhDim_t[]){{.w=600, .h=400}}), 0);
   mainRaw = PtCreateWidget(PtRaw, window, 0, NULL);
   PtSetResource(mainRaw, Pt_ARG_POS, ((PhPoint_t[]){{.x=50, .y=50}}), 0);
   PtSetResource(mainRaw, Pt_ARG_DIM, ((PhDim_t[]){{.w=500, .h=300}}), 0);
   PtSetResource(mainRaw, Pt_ARG_RAW_DRAW_F, &draw, 1);
   timer = PtCreateWidget(PtTimer, window, 0, NULL);
   PtSetResource(timer, Pt_ARG_TIMER_INITIAL, 100, 0);
   PtSetResource(timer, Pt_ARG_TIMER_REPEAT, 100, 0);
   PtAddCallback(timer, Pt_CB_TIMER_ACTIVATE, tick, mainRaw);
   PtRealizeWidget(window);
   PtMainLoop();
   return EXIT_SUCCESS;
}


-Peter
PeterHuber
Active Member
 
Posts: 55
Joined: Sat Sep 01, 2007 11:11 am
Location: Switzerland


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 2 guests