![]() ![]() ![]()
|
SophiaFramework UNIVERSE 5.2 |
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 full screen Bool helloworld::HandleRender(SFXEventConstRef event) { // here describe full screen redrawing when an applet starts or resumes SFXGraphicsPtr graphics; Bool result(false); if (IsRenderable()) { // if screen can be redrawn (i.e., if no highest priority event handler is registered) // get SFXGraphics instance if ((graphics = SFXGraphics::GetInstance()) != null) { // fill screen in white // get screen with SFXGraphics::GetDeviceRectangle() // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) represents white color graphics->ClearRectangle(graphics->GetDeviceRectangle(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); // call SFXGraphics::Update() to redraw screen // * 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 full screen has to be redrawn when an applet starts or resumes. 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 when this applet starts or resumes. | |
![]() |
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 full 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 screen in white and draw "Hello World" in black // get SFXGraphics instance SFXGraphicsPtr graphics = SFXGraphics::GetInstance(); // clear screen // get rectangular screen coordinates by SFXGraphics::GetDeviceRectangle function // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) defines white graphics->FillRectangle(SFXGraphics::GetDeviceRectangle(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); // draw "Hello World" in screen graphics->DrawText("Hello World", SFXGraphics::GetDeviceRectangle(), SFXRGBColor(0x00, 0x00, 0x00, 0x00)); // call SFXGraphics::Update() to redraw screen // * 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 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 for key events switch (key) { case AVK_SELECT: // when SELECT key is pressed Terminate(); // terminate application return true; // *** following are added case AVK_1: // when "1" key is pressed Draw(); // call Draw() function return true; // return "true" since key event is handled } return false; // return "false" since 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 - 2012 Sophia Cradle Incorporated All Rights Reserved. |
![]() ![]() ![]()
|