Frank Applin
|
How to swap images using a label
|
Frank Applin
07/26/2012 11:50 AM
post94434
|
How to swap images using a label
Hi,
I'm new to QNX and PhAB, but have been programming for 20+ years. I guess I'm most familiar with the Visual Studio
paradigm.
I am using Neil Carter's example of showing an image using a label.
int ShowImage( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
PhImage_t *myImg;
char myImgFlnm[20] = "PICTURE.BMP";
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
if ((myImg = PxLoadImage( myImgFlnm, NULL)) == NULL) {
fprintf( stderr, "Error loading image file %s\n", myImgFlnm);
PtExit( EXIT_FAILURE );
}
PtSetResource(ABW_lblMyImg, Pt_ARG_LABEL_IMAGE, myImg, 0);
return( Pt_CONTINUE );
}
How can I swap out the current image with another image after a short delay?
I tried the following, but it simple shows the 2nd image:
int ShowImage( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
PhImage_t *myImg, *myImg2;
char myImgFlnm[20] = "PICTURE.BMP";
char myImgFlnm2[20] = "PICTURE2.BMP";
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
if ((myImg = PxLoadImage( myImgFlnm, NULL)) == NULL) {
fprintf( stderr, "Error loading image file %s\n", myImgFlnm);
PtExit( EXIT_FAILURE );
}
PtSetResource(ABW_lblMyImg, Pt_ARG_LABEL_IMAGE, myImg, 0);
delay(5000); /* delay 5 secs */
if ((myImg2 = PxLoadImage( myImgFlnm2, NULL)) == NULL) {
fprintf( stderr, "Error loading image file %s\n", myImgFlnm2);
PtExit( EXIT_FAILURE );
}
PtSetResource(ABW_lblMyImg, Pt_ARG_LABEL_IMAGE, myImg2, 0);
return( Pt_CONTINUE );
}
Thanks,
Frank
|
|
|
Derek Leach
|
RE: How to swap images using a label
|
Derek Leach
07/26/2012 11:57 AM
post94435
|
RE: How to swap images using a label
Setup a PtTimer that checks a "image index" ... after the callback for the PtTimer fires, check the "image index" for
what image to display, and set the Pt_ARG_LABEL_IMAGE with that image, then change the "image index". The next time the
PtTimer fires, your "image index" will be different, so you would set the other image to the label.
Preload the image (PxLoadImage) in an application startup callback, you do not want to keep reloading the images -> slow
, and if you do not release, leads to memory leak.
-----Original Message-----
From: Frank Applin [mailto:community-noreply@qnx.com]
Sent: July-26-12 11:51 AM
To: photon-graphics
Subject: How to swap images using a label
Hi,
I'm new to QNX and PhAB, but have been programming for 20+ years. I guess I'm most familiar with the Visual Studio
paradigm.
I am using Neil Carter's example of showing an image using a label.
int ShowImage( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) {
PhImage_t *myImg;
char myImgFlnm[20] = "PICTURE.BMP";
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
if ((myImg = PxLoadImage( myImgFlnm, NULL)) == NULL) {
fprintf( stderr, "Error loading image file %s\n", myImgFlnm);
PtExit( EXIT_FAILURE );
}
PtSetResource(ABW_lblMyImg, Pt_ARG_LABEL_IMAGE, myImg, 0);
return( Pt_CONTINUE );
}
How can I swap out the current image with another image after a short delay?
I tried the following, but it simple shows the 2nd image:
int ShowImage( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) {
PhImage_t *myImg, *myImg2;
char myImgFlnm[20] = "PICTURE.BMP";
char myImgFlnm2[20] = "PICTURE2.BMP";
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
if ((myImg = PxLoadImage( myImgFlnm, NULL)) == NULL) {
fprintf( stderr, "Error loading image file %s\n", myImgFlnm);
PtExit( EXIT_FAILURE );
}
PtSetResource(ABW_lblMyImg, Pt_ARG_LABEL_IMAGE, myImg, 0);
delay(5000); /* delay 5 secs */
if ((myImg2 = PxLoadImage( myImgFlnm2, NULL)) == NULL) {
fprintf( stderr, "Error loading image file %s\n", myImgFlnm2);
PtExit( EXIT_FAILURE );
}
PtSetResource(ABW_lblMyImg, Pt_ARG_LABEL_IMAGE, myImg2, 0);
return( Pt_CONTINUE );
}
Thanks,
Frank
_______________________________________________
Photon microGUI
http://community.qnx.com/sf/go/post94434
To cancel your subscription to this discussion, please e-mail photon-graphics-unsubscribe@community.qnx.com
|
|
|
Frank Applin
|
Re: RE: How to swap images using a label
|
Frank Applin
07/26/2012 1:38 PM
post94436
|
Re: RE: How to swap images using a label
Would I be able to change the timer to something that is not a set time?
What I am after is to be able to read a simple text file that has bitmap names and timings (usually in ms). This kind of
stuff is done in psychology experiments with EEG. You show an image for a period of time and delay. Move to the next
picture with a new period of time (just slightly staggered) and delay. And it keeps doing this process all the way
through the file.
So, the text file might look like:
beagle.bmp, 2000
blank.bmp, 2000
canary.bmp, 2015
blank.bmp, 2000
beagle.bmp, 2045
blank.bmp, 2000
canary.bmp, 2065
blank.bmp, 2000
beagle.bmp, 2100
blank.bmp, 2000
:
:
|
|
|
Derek Leach
|
RE: RE: How to swap images using a label
|
Derek Leach
07/26/2012 1:58 PM
post94437
|
RE: RE: How to swap images using a label
Ok, the key is that the Photon processing is not immediate in the callback versus what you see on the display, so if you
set image1 then image2, you will only ever see image2.
You never want to stall out in the middle of a callback.
What you want to do is of a rather synchronous nature, with non-equal delay time.
With a Photon app the PtMainLoop() is already running.
There are more hacker ways of going about this, but could you try setting the PtTimer to a really fine repeat, then
check your delays in there?
If not, I will have to think about this for a bit.
-----Original Message-----
From: Frank Applin [mailto:community-noreply@qnx.com]
Sent: July-26-12 1:39 PM
To: photon-graphics
Subject: Re: RE: How to swap images using a label
Would I be able to change the timer to something that is not a set time?
What I am after is to be able to read a simple text file that has bitmap names and timings (usually in ms). This kind of
stuff is done in psychology experiments with EEG. You show an image for a period of time and delay. Move to the next
picture with a new period of time (just slightly staggered) and delay. And it keeps doing this process all the way
through the file.
So, the text file might look like:
beagle.bmp, 2000
blank.bmp, 2000
canary.bmp, 2015
blank.bmp, 2000
beagle.bmp, 2045
blank.bmp, 2000
canary.bmp, 2065
blank.bmp, 2000
beagle.bmp, 2100
blank.bmp, 2000
:
:
_______________________________________________
Photon microGUI
http://community.qnx.com/sf/go/post94436
To cancel your subscription to this discussion, please e-mail photon-graphics-unsubscribe@community.qnx.com
|
|
|
Thomas Haupt
|
AW: RE: RE: How to swap images using a label
|
Thomas Haupt
07/26/2012 1:43 PM
post94438
|
AW: RE: RE: How to swap images using a label
I think Derek's suggestion is just right. Set the PtTimer interval to 1ms or so; checking a delay count doesn't generate
so much overhead.
Try to pre-load the images and delay counts when starting your application (or when opening the definition file).
- Thomas
----- Originalnachricht -----
Von: Derek Leach [mailto:community-noreply@qnx.com]
Gesendet: Thursday, July 26, 2012 01:30 PM
An: photon-graphics <photon-graphics@community.qnx.com>
Betreff: RE: RE: How to swap images using a label
Ok, the key is that the Photon processing is not immediate in the callback versus what you see on the display, so if you
set image1 then image2, you will only ever see image2.
You never want to stall out in the middle of a callback.
What you want to do is of a rather synchronous nature, with non-equal delay time.
With a Photon app the PtMainLoop() is already running.
There are more hacker ways of going about this, but could you try setting the PtTimer to a really fine repeat, then
check your delays in there?
If not, I will have to think about this for a bit.
-----Original Message-----
From: Frank Applin [mailto:community-noreply@qnx.com]
Sent: July-26-12 1:39 PM
To: photon-graphics
Subject: Re: RE: How to swap images using a label
Would I be able to change the timer to something that is not a set time?
What I am after is to be able to read a simple text file that has bitmap names and timings (usually in ms). This kind of
stuff is done in psychology experiments with EEG. You show an image for a period of time and delay. Move to the next
picture with a new period of time (just slightly staggered) and delay. And it keeps doing this process all the way
through the file.
So, the text file might look like:
beagle.bmp, 2000
blank.bmp, 2000
canary.bmp, 2015
blank.bmp, 2000
beagle.bmp, 2045
blank.bmp, 2000
canary.bmp, 2065
blank.bmp, 2000
beagle.bmp, 2100
blank.bmp, 2000
:
:
_______________________________________________
Photon microGUI
http://community.qnx.com/sf/go/post94436
To cancel your subscription to this discussion, please e-mail photon-graphics-unsubscribe@community.qnx.com
_______________________________________________
Photon microGUI
http://community.qnx.com/sf/go/post94437
To cancel your subscription to this discussion, please e-mail photon-graphics-unsubscribe@community.qnx.com
|
|
|
Frank Applin
|
Re: AW: RE: RE: How to swap images using a label
|
Frank Applin
07/26/2012 2:00 PM
post94439
|
Re: AW: RE: RE: How to swap images using a label
Thanks, guys. I am really new to this (just installed Neutrino, yesterday) and this isn't your normal C/C++/C#/Java
event handling coding. So, let me look at the PtTimer and try to absorb what you are talking about.
Should I even be attempting this via PhAB?
Frank
|
|
|
Thomas Haupt
|
AW: Re: AW: RE: RE: How to swap images using a label
|
Thomas Haupt
07/26/2012 1:54 PM
post94440
|
AW: Re: AW: RE: RE: How to swap images using a label
I'd suggest PhAb. It sets up the code framework for you, lets you drag-and-drop the widgets you want, and also generates
code templates for the callbacks you specify. Much easier than doing everything in code yourself.
- Thomas
----- Originalnachricht -----
Von: Frank Applin [mailto:community-noreply@qnx.com]
Gesendet: Thursday, July 26, 2012 02:00 PM
An: photon-graphics <photon-graphics@community.qnx.com>
Betreff: Re: AW: RE: RE: How to swap images using a label
Thanks, guys. I am really new to this (just installed Neutrino, yesterday) and this isn't your normal C/C++/C#/Java
event handling coding. So, let me look at the PtTimer and try to absorb what you are talking about.
Should I even be attempting this via PhAB?
Frank
_______________________________________________
Photon microGUI
http://community.qnx.com/sf/go/post94439
To cancel your subscription to this discussion, please e-mail photon-graphics-unsubscribe@community.qnx.com
|
|
|
Frank Applin
|
Re: AW: RE: RE: How to swap images using a label
|
Frank Applin
07/26/2012 2:24 PM
post94442
|
Re: AW: RE: RE: How to swap images using a label
I will say this for Microsoft, though. Their documentation is chalked full of examples, which make learning a new tool
set and APIs much, much easier.
|
|
|
Derek Leach
|
RE: AW: RE: RE: How to swap images using a label
|
Derek Leach
07/26/2012 2:31 PM
post94443
|
RE: AW: RE: RE: How to swap images using a label
You have read the Photon Programmers Guide? Yes, there could be more docs.
-----Original Message-----
From: Frank Applin [mailto:community-noreply@qnx.com]
Sent: July-26-12 2:24 PM
To: photon-graphics
Subject: Re: AW: RE: RE: How to swap images using a label
I will say this for Microsoft, though. Their documentation is chalked full of examples, which make learning a new tool
set and APIs much, much easier.
_______________________________________________
Photon microGUI
http://community.qnx.com/sf/go/post94442
To cancel your subscription to this discussion, please e-mail photon-graphics-unsubscribe@community.qnx.com
|
|
|
Steve Reid
|
RE: AW: RE: RE: How to swap images using a label
|
Steve Reid
07/26/2012 2:56 PM
post94444
|
RE: AW: RE: RE: How to swap images using a label
There's an example of this in the Photon Programmer's Guide. See "Animation" in this file:
http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=/com.qnx.doc.photon_prog_guide/draw.html
Steve Reid (stever@qnx.com)
Technical Editor
QNX Software Systems
-----Original Message-----
From: Frank Applin [mailto:community-noreply@qnx.com]
Sent: Thursday, July 26, 2012 2:24 PM
To: photon-graphics
Subject: Re: AW: RE: RE: How to swap images using a label
I will say this for Microsoft, though. Their documentation is chalked full of examples, which make learning a new tool
set and APIs much, much easier.
_______________________________________________
Photon microGUI
http://community.qnx.com/sf/go/post94442
To cancel your subscription to this discussion, please e-mail photon-graphics-unsubscribe@community.qnx.com
|
|
|
|