Listing 1a Code for GUI_Init. /*‹‹‹‹‹‹‹‹‹‹‹‹- Public Function ‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹*/ // Name: GUI_Init // Brief: Initialization function associated with the GUI task. // Called By: This function is called as part of OS initialization. This function // creates the UI_DISPLAY, UI_EVENT_MANAGER, and UI_WINDOW_MANAGER required by Zinc. Once // these are created, the GUI interface is ready to roll. // Comments: // The objects created by this function are never deleted! This is not ordinarily done, // but in this case the objects are fundamental to the execution of the GUI interface, // they are intended to live forever, so there is still peace in heap-ville. /*‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹*/ int GUI_Init(int TaskIndex) { // Create the display interface object. The display constructor performs all the video // controller configuration, and prepares font bitmap information for use by text // routines (an illustration of the beauty of encapsulation). UI_DISPLAY *display = new UI_LCD_DISPLAY(); // create the eventManager (the first parameter is required, the second indicates how // many events the event manager queue should expect to manage): eventManager = new UI_EVENT_MANAGER(display, 40); // create the window manager: windowManager = new UI_WINDOW_MANAGER(display, eventManager); return(TRUE); } Listing 1b Code for GUI_Task. /*‹‹‹‹‹‹‹‹‹‹‹‹- Public Function ‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹*/ // Name: GUI_Task // Brief: This task interfaces the Zinc GUI library with the real-time operating system // and other system tasks. // Called By: This function is called as part of OS initialization. // Comments: // This function runs forever. It first creates the main window, then continuously loops // processing Zinc events and suspending waiting for OS-generated messages. /*‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹‹*/ void GUI_Task (void) { // a few automatic variables: UI_EVENT ZincEvent; // used to pass OS-messages to library EVENT_TYPE ccode; // Zinc defined status code MESSAGE *pMessage = NULL; // OS defined message type // pop the first window up on the display: windowManager->Add(new MAIN_SCREEN()); for(;;) // never returns { if (pMessage) { ZincEvent.type = MSG_TYPE_OS; // user define message type ZincEvent.data = (void *) pMessage; // pass message pointer to app eventManager->Put(ZincEvent); // place Zinc event in queue } // process any pending Zinc events: int iQueStatus = eventManager->Get(ZincEvent, Q_NO_BLOCK); while(iQueStatus != QUEUE_EMPTY) // there may be several events!! { // allow the window manager to route the message to the correct window object: windowManager->Event(ZincEvent); // get the next event (if any) iQueStatus = eventManager->Get(ZincEvent, Q_NO_BLOCK); } // Go to sleep until another message arrives from some other task or // timer in the system: pMessage = WaitForMessage(GUI_QUEUE, INFINITE); } }