Resources | Resources |



Drawing to the display

In a widget-based application, the root container controls the drawing of the widgets on the display.

When a widget needs to be redrawn, it sends an invalidation request to its parent container, which sends it to its parent. The request is forwarded up the widget hierarchy until it reaches the root container. The root container schedules the drawing.

A widget-based application should not draw directly to the display, which means the application should not call any functions that draw to the display, such as IBitmap_DrawPixel() or IDisplay_DrawText().

Brew MP application wizard

If the Brew MP application wizard is used to create the application framework, the application will contain a DrawScreen() function that is called in the HandleEvent() function. The DrawScreen() function should not be used in a widget-based application. Make the following changes to the code created by the application wizard:

  1. Delete the DrawScreen() function.
  2. In HandleEvent(), delete the call to DrawScreen() when the EVT_APP_START event is received.

    In c_simple_widget_app_HandleEvent(), EVT_APP_START is handled as follows:

    case EVT_APP_START:
       return TRUE;   
  3. In HandleEvent(), change the call to DrawScreen when the EVT_APP_RESUME event is received to a call to IRootContainer_Invalidate(), which will cause the screen to be redrawn.

    In c_simple_widget_app_HandleEvent(), EVT_APP_RESUME is handled as follows:

    case EVT_APP_RESUME:
       // invalidate so screen is redrawn
       IRootContainer_Invalidate(pMe->picRoot, NULL, NULL, 0); 
       return TRUE;