![]() ![]() ![]()
|
SophiaFramework UNIVERSE 5.2 |
The application class of an SFC applet inherits directly from SFCApplication.
In the application class of the SFC applet, the XANDLER_DECLARE_..... macro is not used to declare a handler function. Instead a handler function is declared in the same way with other normal functions like the OnKey() function below.
Example 4.2. Define the helloworld application class
// // helloworld.hpp // #ifndef __HELLOWORLD_HPP #define __HELLOWORLD_HPP #define TARGET_BUILD_DEBUG #include <SophiaFramework.hpp> #include "helloworld.bid" // // helloworld application class // SFMTYPEDEFCLASS(helloworld) // macro to generate useful types class helloworld : public SFCApplication { SFMSEALCOPY(helloworld) // macro to prohibit developer from copying this instance public: static SFCInvokerPtr Factory(Void); // factory function private: helloworld(Void); virtual ~helloworld(Void); virtual Bool HandleEvent(SFXEventConstRef event); // event handler virtual Bool HandleRender(SFXEventConstRef event); // full screen drawing handler Bool OnKey(UInt16 key); // key handler }; #endif // __HELLOWORLD_HPP //
![]() |
HandleEvent() function |
|---|---|
|
The HandleEvent() function is the event handler of the SFC applet. This function will be automatically called when the applet receives an event dispatched from the BREW environment(BREW-defined event). In the SFC applet development, event handling is described by overriding the SFCApplication::HandleEvent virtual function. The HandleEvent() function has an argument which represents an event dispatched from the BREW environment, and boots up an appropriate handle function according to the event type. For instance, in the implementation of the helloworld applet below, the SFCApplication::HandleEvent virtual function is overridden to boot up the OnKey() function, key handler when the applet receives the key event. For more details, see the description of the SFCApplication::HandleEvent function. | |
![]() |
HandleRender() function |
|---|---|
|
The HandleRender() function is the full screen drawing handler of the SFC applet. This function will be automatically called when an applet starts or resumes. In the SFC applet development, full screen drawing necessary when an applet starts or resumes is described by overriding the SFCApplication::HandleRender virtual function. For instance, in the implementation of the helloworld applet below, the SFCApplication::HandleRender virtual function is overridden to fill the screen in white and draw the "Hello World" string in black when an applet starts or resumes. For more details, see the description of the SFCApplication::HandleRender function. | |
![]() |
Drawing processing |
|---|---|
|
Drawing processing other than full screen redrawing can be described anywhere in the program like the Draw() function mentioned later. This is the same with the standard BREW applet development. | |
![]() |
SFY applet |
|---|---|
In case of an SFY applet which uses the GUI framework, its application class inherits directly from SFYApplication. | |
Event Handler
The HandleEvent() function is the event handler for SFCApplication. It receives all events dispatched from the BREW environment, and distributes each event to appropriate handler functions.
The event is transmitted through the argument of the HandleEvent() function, and sent to appropriate handler functions according to its event type. For instance, a key event boots up the key handler.
Implement the HandleEvent() Function for Handling an Event
The template of the HandleEvent() function for handling an event dispatched from the BREW environment is automatically generated by the SophiaFramework UNIVERSE AppWizard.
Example 4.3. Implement the HandleEvent() function
// event handler Bool helloworld::HandleEvent(SFXEventConstRef event) { // here describe the handling of an event dispatched from the BREW environment Bool result(false); switch (event.GetType()) { case SFEVT_KEY: result = OnKey(event.GetP16()); break; } return result; // return "true" if event has been handled, otherwise return "false" }
![]() |
HandleEvent() function |
|---|---|
|
The HandleEvent() function will be automatically called when the applet receives an event dispatched from the BREW environment. In the above example, the SFCApplication::HandleEvent virtual function is overridden to call the key handler of the OnKey() function when a key event dispatched from the BREW environment is received. | |
![]() |
Return value of the HandleEvent() function |
|---|---|
The HandleEvent() function will return "true" if it handles an event. Otherwise it will return "false". | |
Implement the HandleRender() Function for Redrawing the Full Screen
The template of the HandleRender() function for redrawing the full screen is automatically generated by the SophiaFramework UNIVERSE AppWizard.
Example 4.4. Implement the HandleRender() function
// handler for drawing 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)); // draw "Hello World" in screen graphics->DrawSingleText("Hello World", graphics->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(); result = true; // set result to "true" since screen is redrawn } } return result; // return "true" if screen has been redrawn, otherwise return "false" }
Reference: SFXGraphics | SFXGraphics::GetInstance | SFXGraphics::GetDeviceRectangle | SFXGraphics::ClearRectangle | SFXGraphics::Update | SFCApplication::IsRenderable | SFCApplication::HandleError | SFYApplication::HandleRender
![]() |
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 and draw the "Hello World" string 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". | |
![]() |
About the IsRenderable() function |
|---|---|
|
If a highest priority event handler to handle the standard BREW control such as a native text input control( BREW API ITextCtl Interface) which will occupy the full screen is registered, the full screen will be occupied by this highest priority event handler. Therefore, any function other than this highest priority event handler must not draw the screen while it is registered. SFCApplication::IsRenderable is the function to check this status. | |
![]() |
Highest Priority Event Handler |
|---|---|
For more details, see the description of the SFCApplication::RegisterBypass function. | |
![]() |
"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. | |
Implement the OnKey() Function for for Handling a Key Event
The template of the OnKey() function for handling a key event dispatched from the BREW environment is automatically generated by the SophiaFramework UNIVERSE AppWizard.
Example 4.5. Implement the OnKey() function
// key handler Bool helloworld::OnKey(UInt16 key) { // here describe the handling of the key event dispatched from the BREW environment switch (key) { case AVK_SELECT: // when the SELECT key is pressed Terminate(); // terminate the application return true; // return "true" since the key event is handled } return false; // return "false" since the key event is NOT handled }
Implement the Constructor
Since an SFC applet is implemented with its own event handler, no event handler functions are registered in the constructor.
Example 4.6. Implement the Constructor
// constructor helloworld::helloworld(Void) static_throws { // In case of using GCC, the "return" statement must not be described here. }
Implement the Destructor
Example 4.7. Implement the Destructor
// destructor helloworld::~helloworld(Void) { // In case of using GCC, the "return" statement must not be described here. }
![]() |
Return statement |
|---|---|
|
The return statement should not be described in the constructor nor in the destructor with C++. The following bug is confirmed when GCC is used. If the return statement is described in the constructor or destructor, the compiler will freeze when a particular inheritance relation exists. | |
|
Copyright(c) 2002 - 2012 Sophia Cradle Incorporated All Rights Reserved. |
![]() ![]() ![]()
|