PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1

8.5. Application without using GUI Framework

An application without using the GUI framework can be developed by inheriting from the SFCApplication class. This kind of application is called SFC application.

SFC application has the same structure as the C program developed with standard BREW SDK.

The C++ wrapper and utility classes of SophiaFramework can be also used in the SFC application.

HelloWorld application is used as an example to explain the basic structure and the processing flow of SFC application.

Figure 8.4. HelloWorld without GUI Framework

HelloWorld without GUI Framework

Example 8.14. HelloWorld application without GUI Framework: .hpp file (class definition)

//
//      Helloworld.hpp
//
//      This source code was automatically
//      generated by SophiaFramework 4.1.
//

#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);  // Key handler (declared just like an ordinary function)
    Void Draw(Void);         // Function to draw "Hello World"
};

#endif // __HELLOWORLD_HPP //

Example 8.15. HelloWorld application without GUI Framework: .cpp file( implementing Boot Loader, Factory functions and Handlers)

//
//      Helloworld.cpp
//
//      This source code was automatically
//      generated by SophiaFramework 4.1.
//

#include "Helloworld.hpp"


// Boot Loader
SFCApplet::FactorySPP SFCApplet::Boot(AEECLSID id, SFXAnsiStringPtr license)
{
    *license = "heap://";

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


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


// Constructor
// In order to independently implement the event handler, the handler function must not be registered in the constructor
Helloworld::Helloworld(Void) static_throws
{
    return;
}


// Desctructor
Helloworld::~Helloworld(Void)
{
    return;
}


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

    // call the handler according to the event type
    switch (event.GetType()) {
        case SFEVT_KEY:    // Key event
            result = OnKey(event.GetP16());
            break;
    }
    if (!result) {
        result = SFCApplication::Invoke(event);
    }
    return result;
}


// Key handler
Bool Helloworld::OnKey(UInt16 key)
{
    // Key event handling
    switch (key) {
        case AVK_SELECT:    // if the select key is pressed
	      Draw();       // draw string "Hello World"
            return true; 
    }
    return false;
}

// Drawing string "Hello World"
Void Helloworld::Draw(Void)
{
    // get SFXGraphics instance
    SFXGraphicsPtr graphics = SFXGraphics::GetInstance();

    // paint screen in white
    // get entire screen (rectangle) using SFXGraphics::GetDeviceRectangle()
    // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) : display in white
    graphics->FillRectangle(SFXGraphics::GetDeviceRectangle(),
                               SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00));

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

    // since GUI Framework is not used, screen must be updated
    graphics->Update();
}

The above HelloWorld application class inherits from the SFCApplication class, since it does not use the GUI Framework.

[Note] Caution

The SFR application using the GUI framework; inherits from the SFRApplication class.

In the SFC application, the HANDLER_DECLARE macro is not used for declaring a handler function. Instead a handler function is declared in the same way as other functions like the OnKey function.

The Invoke function is the event handler for SFCApplication. It receives all events, and distributes each event to the appropriate handler function.

The event is transmitted through the argument of Invoke function, and sent to the appropriate handler function according to the event type. For instance a key event causes the key handler OnKey to be called.

In the key handler OnKey, when the "Select" key is pressed, the Draw function will be called. The Draw function clears the screen and draws the string "Hello World".

[Caution] Caution

In the SFC application the screen need to be drawn within the function such as Draw called in the key handler.

The "graphics->Update();" statement must be included in the "Draw" function to update the screen.