PrevNextUpHome SophiaFramework UNIVERSE 5.3

4.6. Customizing

4.6.1. Before Customization

The helloworld applet behaves as below befre customaization.

  1. When the applet boots up, the screen will be filled in white and the "Hello World" string is drawn in black.
  2. The applet will be terminated when the SELECT key is pressed.

Figure 4.1. Before customization: Device screen immediately after the applet boots up

Before customization: Device screen immediately after the applet boots up

4.6.2. Customization

Then, we will customize the helloworld applet as follows:

  1. Fill the screen in white when the applet boots up. (Nothing will be drawn in the screen.)
  2. Draw the "Hello World" string in black when the "1" key is pressed.
  3. Terminate the applet when the SELECT key is pressed.

The Draw() function, called inside the key handler of OnKey(), fills the screen in white and draws the "Hello World" string in black.

Example 4.8. Implement the HandleRender() not to draw the "Hello World" string

// handler for redrawing the device screen
Bool helloworld::HandleRender(SFXEventConstRef event)
{
    // here describe full screen redrawing when an applet starts / resumes or a highest priority event handler ends

    static SFXRGBColor::AtomRecConst            theme = {
        {{0x00, 0xFF, 0xFF, 0xFF}}
    };
    SFXGraphicsPtr graphics;
    Bool      result(false);

    // get the SFXGraphics instance
    if ((graphics = SFXGraphics::GetInstance()) != null) {

        // fill the device screen in white
        // get the device screen by calling the  SFXGraphics::GetDeviceRectangle() 
        graphics->ClearRectangle(SFXGraphics::GetDeviceRectangle(), theme);

        // call the SFXGraphics::Update() to update the device screen
        // * the device screen will not be redrawn or updated if line below is NOT described
        graphics->Update();

        result = true;  // set result to "true" since screen is redrawn
    }
    return result; // return "true" if screen has been redrawn, otherwise return "false"
}
[Note] HandleRender() function

The device screen has to be redrawn when the applet starts / resumes or a highest priority event handler ends. The HandleRender() function will be automatically called at these timings.

In the above example, the SFCApplication::HandleRender virtual function is overridden to fill the screen in white and draw the "Hello World" string.

[Note] Return value of the HandleRender() function

The HandleRender() function will return "true" if the device screen is redrawn. Otherwise it will return "false".

[Caution] "graphics->Update();"

When the device screen redrawing handler of SFCApplication::HandleRender is overridden, the screen will not be redrawn unless the SFXGraphics::Update function is called. Therefore, you have to describe the "graphics->Update();" statement at the end of the drawing processing.

Example 4.9. Draw() function


// Draw() function is a normal drawing function, which is called in the key handler("OnKey()" function)
Void Draw(Void)
{
    // fill the device screen in white and draw "Hello World" in black

    // get the SFXGraphics instance
    SFXGraphicsPtr graphics = SFXGraphics::GetInstance();

    // clear the decice screen
    // get the device screen by calling the SFXGraphics::GetDeviceRectangle function
    // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) defines white
    graphics->FillRectangle(SFXGraphics::GetDeviceRectangle(),
                               SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00));

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

    // call the SFXGraphics::Update() to update the device screen
    // * the device screen will not be redrawn or updated if line below is NOT described
    graphics->Update();

    // * there is no need to return "true" or "false" in Draw() function
}
[Note] Return value of the Draw() function

Unlike the HandleRender() function, the Draw() function does not have to return "true" nor "false" as a return value.

[Caution] "graphics->Update();"

In the Draw() function, the device screen will not be redrawn unless the SFXGraphics::Update function is called. Therefore, you have to describe the "graphics->Update();" statement at the end of the drawing processing.

However, when the responder region is drawn in the SFY applet, there is no need to describe the "graphics->Update();" statement since it will be executed automatically inside the renderer.

Next, we will customize the key handler to call the Draw() function when the "1" key is pressed.

Example 4.10. Customize the key handler "OnKey()"

// key handler
Bool helloworld::OnKey(UInt16 key)
{
    // processing the key events
    switch (key) {

        case AVK_SELECT: // when the SELECT key is pressed 

            Terminate(); // terminate this application

            return true;

        // *** following are added
        case AVK_1:      // when the "1" key is pressed

            Draw();      // call the Draw() function

            return true; // return "true" since the key event is handled
    }

    return false;  // return "false" since the key event is NOT handled
}
[Note] Return value of key handler

The key handler returns "true" if it handles an event, otherwise it returns "false".

4.6.3. After Customization

When the "1" key is pressed, the screen will be cleared and the string "Hello World" will be drawn.

After customization, the helloworld applet will behave as follows:

  1. When the applet boots up, the screen will be filled in white.
  2. Immediately after the applet boots up, nothing will be drawn in the screen.
  3. The "Hello World" string will be drawn in black when the "1" key is pressed.
  4. The applet will be terminated when the SELECT key is pressed.

Figure 4.2. After customization: Device screen after the applet boots up

After customization: Device screen after the applet boots up

Figure 4.3. After customization: Device screen after the "1" key is pressed

After customization: Device screen after the "1" key is pressed