>
>
> > I already have a thread going that is handling the polling of=20
> > the shared memory and writing it to a local property pixbuf. =20
> > The problem is that even though the thread calls for the=20
> > redraw method of the Fl_Box on every cycle of the thread. It=20
> > only redraws if the mouse is being moved which is exceedingly odd.
>
> Would help a bit if you told us which version of fltkm and what host
> platform.
>
> Anyway, guess mode on:
> I am assuming that you are using fltk-1.1.8. Have you read chapter 10 of
> the manual, which covers multi-threading support in fltk-1?
>
> In summary, only the "main" thread can access the GUI layer (for
> cross-platform portability reasons), so calling redraw() from a non-GUI
> thread is not guaranteed to work.
>
> What you need to do instead is something like this.
> - From your main GUI thread, before you show your first window, call
> Fl::lock(); *just once* (and do not call unlock in themain thread at
> all) this will wake up fltk's threading support.
>
> - From your helper thread, each time you need to modify a widget in the
> GUI thread, do this sequence.
> Fl::lock();
> <widget changes>
> Fl::unlock();
> Fl::awake();
>
> Do not call redraw(); at all from the helper thread, as it won't do what
> you want...
>
> Cheers,
> --=20
> Ian
>
>
>
> SELEX Sensors and Airborne Systems Limited
> Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex=
> SS14 3EL
> A company registered in England & Wales. Company no. 02426132
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
>
First off I just want to say thank you to everyone who tried to help me with
this project. The FLTK version I am using is : 1.1.7 (Ubuntu Repos)
Ian thanks for your help. I am going to try running these changes and see if I
cannot get the UI to become more responsive as a result. Though if you can
look at the code below, and see any additional changes that need to be made let
me know.
The code for my LiveView object is given below. The Thread and MappedMemory
are objects written and contained in a project called CxUtils. We use it
because this is a research project at UCF and the CxUtils was written by
another one of the researchers here and is on SourceForge.net.
Again thanks for all the help!
class LiveView : public Fl_Box {
unsigned char pixbuf[YSIZE][XSIZE]; // image buffer
MappedMemory mem;
Thread liveThread;
// Method takes a pointer to a LiveView object
static void ReadMappedMemory(void* args) {
while(1) {
LiveView *view = (LiveView*)args;
view->ReadMappedMemory();
view->redraw();
SleepMs(5);
}
}
// Function will check the memory for updates
/**static void ReadMappedMemory(MappedMemory *LocalMem, unsigned char p
[][XSIZE]) {
LocalMem->SetReadPos(0);
LocalMem->Lock();
LocalMem->Read((unsigned char *)p, XSIZE*YSIZE);
LocalMem->Unlock();
}*/
void ReadMappedMemory() {
mem.SetReadPos(0);
mem.Lock();
mem.Read((unsigned char *)pixbuf, XSIZE*YSIZE);
mem.Unlock();
redraw();
}
// FLTK DRAW METHOD
void draw() {
// Cannot draw an empty object
// only proceed if p has been set
fl_draw_image_mono((const uchar*)&pixbuf, 366, 10, XSIZE, YSIZE);
}
public:
LiveView(int X, int Y, int W, int H, const char* L) : Fl_Box(X, Y, W, H, L)
{
// For testing purposes open the memory and write something from
// the shared memory to the local array pixbuf.
if(CxUtils::CX_MAPPED_MEMORY_FAILURE ==
mem.OpenMappedMemory("GRABIMAGE", CxUtils::CX_MAPPED_MEMORY_READ_ONLY)) {
//return MEMORY_ERROR; // Exit app if there is a problem with
memory
}
liveThread.SetThreadName("LiveView");
liveThread.CreateThread(ReadMappedMemory, this);
}
LiveView(Fl_Boxtype b, int x, int y, int w, int h, const char* L) :
Fl_Box(b, x, y, w, h, L) {
// For testing purposes open the memory and write something from
// the shared memory to the local array pixbuf.
if(CxUtils::CX_MAPPED_MEMORY_FAILURE ==
mem.OpenMappedMemory("GRABIMAGE", CxUtils::CX_MAPPED_MEMORY_READ_ONLY)) {
//return MEMORY_ERROR; // Exit app if there is a problem with
memory
}
liveThread.SetThreadName("LiveView");
liveThread.CreateThread(ReadMappedMemory, this);
}
~LiveView() {
liveThread.KillThread();
}
};
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk