PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1

4.4. Customization

4.4.1. Before Customization

Nothing is displayed on the screen. The application is terminated when the "Select" key is pressed.

Figure 4.1. Screen before customization

Screen before customization

4.4.2. Customizing

In the SFC application the screen need to be drawn within the function such as Draw called in the key handler.

The "graphics->Update();" statement must be included in the "Draw" function to update the screen.

Example 4.6. Draw function for drawing the screen

Void Draw(Void)
{
    // create instance of SFXGraphics class
    SFXGraphicsPtr graphics = SFXGraphics::GetInstance();

    // clear screen
    // get rectangular screen corrdinates by SFXGraphics::GetDeviceRectangle function
    // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) defines white
    graphics->FillRectangle(SFXGraphics::GetDeviceRectangle(),
                               SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00));

    // draw "Hello World" on screen
    graphics->DrawText("Hello World", SFXGraphics::GetDeviceRectangle(),
                          SFXRGBColor(0x00, 0x00, 0x00, 0x00));

    // MUST update screen
    graphics->Update();
}

Customize the key handler to call the Draw function when the "1" key is pressed.

Example 4.7. Customize the key handler "OnKey"

// Key handler: OnKey function
Bool HelloWorld::OnKey(UInt16 key)
{
    // processing for key events
    switch (key) {
        case AVK_SELECT: // when "Select" key is pressed 
            Terminate(); // terminate application
            return true;

        // *** the following are added
        case AVK_1:      // when "1" key is pressed
            Draw();      // call Draw function
            return true;
    }
    return false;
}

4.4.3. After Customization

When the "1" key is pressed, the screen is cleared, and the string "Hello World" is displayed.

Figure 4.2. Screen after customization

Screen after customization