SophiaFramework UNIVERSE 5.3 |
The helloworld applet behaves as below befre customaization.
Then, we will customize the helloworld applet as follows:
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" }
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. |
Return value of the HandleRender() function | |
---|---|
The HandleRender() function will return "true" if the device screen is redrawn. Otherwise it will return "false". |
"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 }
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. |
"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 }
Return value of key handler | |
---|---|
The key handler returns "true" if it handles an event, otherwise it returns "false". |
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:
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |