Home > Products > SophiaFramework UNIVERSE > Tutorial > HelloWorld > SFC Application - 7 / 7 -

SFC Application [ Development Without GUI Framework ] - 7 / 7 -

SFCApplication Class

Preface

The HelloWorld application demonstrated in this tutorial inherited from the SFRApplication class, meaning that is used SophiaFramework UNIVERSE's GUI Framework.

But applications can also be developed without the GUI Framework, by inheriting from the SFCApplication class instead.

The SFCApplication class should be used by experienced BREW developers new to SophiaFramework UNIVERSE, or game developers concerned mainly with processing speed. It provides the basic tools necessary for sophisticated application development, but allows the developer to use these tools freely.

AppWizard

Screen Shot Choose "No" when the AppWizard offers the choice to use the GUI Framework.
Screen Shot The New Project Information displays the specifications of the new project's skeleton code.

Start Up Code

The Boot Loader and Factory function are now inherited from the SFCApplication class.

A license code must be entered in the Boot Loader, if the application is to be used on an actual handset.

// Boot loader
SFCApplet::FactorySPP SFCApplet::Boot(AEECLSID id, SFXAnsiStringPtr license)
{
    *license = "heap://"
     		"TIXDRQXNU5WHU8Y3Z9WOHWQR6Z3VPSDHDV"
      		"5CR1S4XASPWLUHWAS7Z5Z2TGS3XMSAT3UP"
      		"UQTLTARCYPSFUEJZ6ROSJWGUQSEYKR6V2U"
      		"4VESMTQLHKZ6X7Y2VKXHWIX3XBU0Z7VHWH"
      		"XIZBSGT5SPU3XLX0Z1Y4R3TCU6WGT9WHWI"
      		"VNYHYCUCR9T3SMTEWPRNVAX1Y4VPW2YCY9"
      		"YQV5R7Z9UIVHT6SDUPU2SIW6VCRCWBR2S4"
      		"WQUPYFWCYGT4VIT1WHXGYPTQSFYPWNV3UL"
      		"RNWFW7RBRFVKUKS2YQSQYHW1TPUPXBZ6UE"
      		"Y2WOYKR7S3TAU4TQS6UHVFVEVLU3R5SDSK"
      		"W7RPTNTPVQU2T4R8Z4VLUGEW3U98TLDR8/";;

   return (id==AEECLSID_HELLOWORLD) ? (&HelloWorld::Factory) : (null);
}

// Factory function
SFCInvokerPtr HelloWorld::Factory(Void)
{
    return ::new HelloWorld;
}

Automatically Generated Code

The Header File

The Invoke function of the SFCApplication version of HelloWorld, is not found in the SFRApplication version.

Invoke() is the event handler of the SFCApplication, it receives all events, and then distributes them to the appropriate handler functions.

SFCApplication also does not use any HANDLER_DECLARE macros for its handler functions. Instead the key handler OnKey(), is declared on its own, the same as any other function.

//      HelloWorld.hpp
//
//

#ifndef __HELLOWORLD_HPP
#define __HELLOWORLD_HPP

#include <SophiaFramework.hpp>
#include "HelloWorld.bid"

SFMTYPEDEFCLASS(HelloWorld)
class HelloWorld : public SFCApplication {
    SFMSEALCOPY(HelloWorld)
public:
    static SFCInvokerPtr Factory(Void);
private:
    explicit HelloWorld(Void) static_throws;
    virtual ~HelloWorld(Void);
    virtual Bool Invoke(SFXEventConstRef event);
    Bool OnKey(UInt16 key);
};

#endif // __HELLOWORLD_HPP //

Event Handler

Event handlers are functions that manage events, such as application start or key presses.

The event is transmitted within the Invoke function's argument, and then sent to a handler function based on it's type parameter. For instance a key event causes the key handler to be called.

// Event handler
Bool HelloWorld::Invoke(SFXEventConstRef event)
{
    Bool result(false);

    switch (event.GetType()) {
        case SFEVT_KEY:
            result = OnKey(event.GetP16());
            break;
    }
    if (!result) {
        result = SFCApplication::Invoke(event);
    }
    return result;
}

A key handler, OnKey, is automatically included by the SophiaFramework AppWizard, but it only handles the "Select" key press which leads to application termination.

// Key handler
Bool HelloWorld::OnKey(UInt16 key)
{
    // Processing when the key is pushed is described here. 
    // If the select key is pushed, the application program is ended. 

    switch (key) {
        case AVK_SELECT:
            Terminate();
            return true;
    }
    return false;
}

Constructor

Since the SFCApplication class does not use any handler macros, the constructor of this class does not need to register specific events to their handler functions.

// Constructor
HelloWorld::HelloWorld(Void) static_throws
{
    return;
}

Before Customization

Screen Shot The device screen is blank and a "Select" key press, terminates the application.

Customized Implementation

Code for Screen Drawing

Unlike the SFRApplication class, screen drawing in the SFCApplication class is done not in a drawing handler, but rather in a drawing function called by the key handler.

Instructions such as getting an instance of the graphics class, and screen updating which are automatically done in the SFRApplication must be explicitly coded in the SFCApplication.

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

    // The screen is cleared, by painting it white
    // The entire screen rectangle is obtained by SFXGraphics::GetDeviceRectangle()
    // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) defines a color
    graphics->FillRectangle(SFXGraphics::GetDeviceRectangle(),
        SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00));

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

    // The screen is updated
	// (This must be done!)
    graphics->Update();
}

The key handler is customized to call the Draw() function when the "1" key is pressed.

// Key handler
Bool HelloWorld::OnKey(UInt16 key)
{
    // Processing when the key is pushed is described here. 
    // If the select key is pushed, the application program is ended. 

    switch (key) {
        case AVK_SELECT:
            Terminate();
            return true;

	// When the "1" key is pressed
	// the Draw() function is called	
	case AVK_1:
            Draw();
            return true;

    }
    return false;
}

After Customization

Screen Shot When the "1" key is pressed, the device screen is painted over white, and the string "Hello World" is displayed.

Go back  1   2   3   4   5   Apdx   SFC