PrevNextUpHome SophiaFramework UNIVERSE 5.3

10.4. Window

10.4.1. What is Window?

There are three types of Window classes that inherit from the SFRWindow class.

Table 10.3. Window Types

Class Name Description
SFRPlainWindow Responder which represents a plain window without title and frame.
SFRFrameWindow Responder which represents a window with a frame.
SFRTitleWindow Responder which represents a window with a title.

In general, the Window class can be defined by inheriting from one among the above three types of Window classes.

Figure 10.11. Window (SFRPlainWindow, SFRFrameWindow, SFRTitleWindow )

Window (, , )

Reference: Development with SFR GUI Framework: Window

10.4.2. PlainWindow

Figure 10.12. PlainWindow

PlainWindow

Create the instance(PlainWindow) of MyWindow class that inherits from the SFRPlainWindow class.

Example 10.11. Define, Implement, and Create the PlainWindow (1)

// PlainWindow with coordinates: (20, 20), width: 200, height: 250
SFMTYPEDEFCLASS(MyWindow)
class MyWindow : public SFRPlainWindow {
    SFMSEALCOPY(MyWindow)
public:
    MyWindow(Void);
    virtual ~MyWindow(Void);
};

// Constructor
//  1st arg: pointer to Application instance, 2nd arg: position and size of Window
MyWindow::MyWindow(Void) : SFRPlainWindow(SFRApplication::GetInstance(),
    SFXRectangle(20, 20, 200, 250))
{
    return;
}

// create PlainWindow
MyWindowPtr window;
window = new MyWindow();

Figure 10.13. Execution Result

Execution Result
[Note] Note

For the PlainWindow without neither title nor frame, it seems not to be displayed.

Using the SFXGraphics instance, draw the string "Hello Window" on the instance(PlainWindow) of MyWindow class that inherits from the SFRPlainWindow class.

Example 10.12. Define, Implement, and Create the PlainWindow (2)

SFMTYPEDEFCLASS(MyWindow)
class MyWindow : public SFRPlainWindow {
    SFMSEALCOPY(MyWindow)
public:
    MyWindow(Void) static_throws;
    virtual ~MyWindow(Void);
    
    // declare drawing handler
    HANDLER_DECLARE_VOIDRENDER(OnRenderContent)
};

// Constructor
MyWindow::MyWindow(Void) : SFRPlainWindow(SFRApplication::GetInstance(),
    SFXRectangle(20, 20, 200, 250)) 
{
    // register drawing handler
    RegisterHandler(SREVT_RESPONDER_RENDER, 
                    SRP16_RENDER_CONTENT,
                    HANDLER_BEFORE, 
                    HANDLER_FUNCTION(OnRenderContent));
    return;
}

// Drawing handler
// 1st argument: class it belongs to, 2nd argument : handler name, 3rd argument: SFXGraphics instance
HANDLER_IMPLEMENT_VOIDRENDER(MyWindow, OnRenderContent, graphics)
{
    // draw using SFXGraphics instance
 
    // set inside of window to light blue
    // GetContentWorld() returns a rectangle (SFXRectangle) represents drawing area inside window
    // SFXRGBColor(0xCE, 0xFF, 0xFF, 0x00) defines light blue
    graphics->FillRectangle(GetContentWorld(), 
                            SFXRGBColor(0xCE, 0xFF, 0xFF, 0x00));

    // display "Hello Window"
    // SFXRGBColor(0x00, 0x00, 0x00, 0x00) defines black
    graphics->DrawText("Hello Window", 
                       GetContentWorld(),
                       SFXRGBColor(0x00, 0x00, 0x00, 0x00));
    return;
}

// create PlainWindow
MyWindowPtr window;
window = new MyWindow();

Figure 10.14. Execution Result

Execution Result

10.4.3. FrameWindow

Figure 10.15. FrameWindow

FrameWindow

Create the instance(FrameWindow) of MyWindow class that inherits from the SFRFrameWindow class.

Example 10.13. Define, Implement, and Create the FrameWindow (1)

// FrameWindow with coordinates: (20, 20), width: 200, height: 250
SFMTYPEDEFCLASS(MyWindow)
class MyWindow : public SFRFrameWindow {
    SFMSEALCOPY(MyWindow)
public:
    MyWindow(Void);
    virtual ~MyWindow(Void);
};

// Constructor
//  1st arg: pointer to Application instance, 2nd arg: position and size of Window
MyWindow::MyWindow(Void) : SFRFrameWindow(SFRApplication::GetInstance(),
    SFXRectangle(20, 20, 200, 250))
{
    return;
}

// create FrameWindow
MyWindowPtr window;
window = new MyWindow();

Figure 10.16. Execution Result

Execution Result

Using the SFXGraphics instance, draw the string "Hello Window" on the instance(FrameWindow) of MyWindow class that inherits from the SFRFrameWindow class.

Example 10.14. Define, Implement, and Create the FrameWindow (2)

SFMTYPEDEFCLASS(MyWindow)
class MyWindow : public SFRFrameWindow {
    SFMSEALCOPY(MyWindow)
public:
    MyWindow(Void) static_throws;
    virtual ~MyWindow(Void);
    
    // declare drawing handler
    HANDLER_DECLARE_VOIDRENDER(OnRenderContent)
};

// Constructor
MyWindow::MyWindow(Void) : SFRFrameWindow(SFRApplication::GetInstance(),
    SFXRectangle(20, 20, 200, 250)) 
{
    // register drawing handler
    RegisterHandler(SREVT_RESPONDER_RENDER, 
                    SRP16_RENDER_CONTENT,
                    HANDLER_BEFORE, 
                    HANDLER_FUNCTION(OnRenderContent));
    return;
}

// Drawing handler
// 1st argument: class it belongs to, 2nd argument: handler name, 3rd argument: SFXGraphics instance
HANDLER_IMPLEMENT_VOIDRENDER(MyWindow, OnRenderContent, graphics)
{
    // draw using SFXGraphics instance
 
    // set inside of window to light blue
    // GetContentWorld() returns a rectangle (SFXRectangle) represents drawing area inside window
    // SFXRGBColor(0xCE, 0xFF, 0xFF, 0x00) defines light blue
    graphics->FillRectangle(GetContentWorld(), 
                            SFXRGBColor(0xCE, 0xFF, 0xFF, 0x00));

    // display "Hello Window"
    // SFXRGBColor(0x00, 0x00, 0x00, 0x00) defines black
    graphics->DrawText("Hello Window", 
                       GetContentWorld(),
                       SFXRGBColor(0x00, 0x00, 0x00, 0x00));
    return;
}

// create FrameWindow
MyWindowPtr window;
window = new MyWindow();

Figure 10.17. Execution Result

Execution Result

10.4.4. TitleWindow

Figure 10.18. TitleWindow

TitleWindow

Create the instance(TitleWindow) of MyWindow class that inherits from the SFRTitleWindow class.

Example 10.15. Define, Implement, and Create the TitleWindow (1)

// TitleWindow coordinates: (20, 20), width: 200, height: 250, title: "my window"
SFMTYPEDEFCLASS(MyWindow)
class MyWindow : public SFRTitleWindow {
    SFMSEALCOPY(MyWindow)
public:
    MyWindow(Void);
    virtual ~MyWindow(Void);
};

// Constructor
//  1st arg: pointer to Application instance, 2nd arg: position and size of Window, 3rd arg: window title
MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(),
    SFXRectangle(20, 20, 200, 250), "my window")
{
    return;
}

// create TitleWindow
MyWindowPtr window;
window = new MyWindow();

Figure 10.19. Execution Result

Execution Result

Using the SFXGraphics instance, draw the string "Hello Window" on the instance(TitleWindow) of MyWindow class that inherits from the SFRTitleWindow class.

Example 10.16. Define, Implement, and Create the TitleWindow (2)

SFMTYPEDEFCLASS(MyWindow)
class MyWindow : public SFRTitleWindow {
    SFMSEALCOPY(MyWindow)
public:
    MyWindow(Void) static_throws;
    virtual ~MyWindow(Void);
    
    // Declare drawing handler
    HANDLER_DECLARE_VOIDRENDER(OnRenderContent)
};

// Constructor
MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(),
    SFXRectangle(20, 20, 200, 250), "my window") 
{
    // register drawing handler
    RegisterHandler(SREVT_RESPONDER_RENDER, 
                    SRP16_RENDER_CONTENT,
                    HANDLER_BEFORE, 
                    HANDLER_FUNCTION(OnRenderContent));
    return;
}

// Drawing handler
// 1st arg: class it belongs to, 2nd arg: handler name, 3rd arg: SFXGraphics instance
HANDLER_IMPLEMENT_VOIDRENDER(MyWindow, OnRenderContent, graphics)
{
    // draw using SFXGraphics instance
 
    // set inside of window to light blue
    // GetContentWorld() returns a rectangle (SFXRectangle) represents drawing area inside window
    // SFXRGBColor(0xCE, 0xFF, 0xFF, 0x00) defines light blue
    graphics->FillRectangle(GetContentWorld(), 
                            SFXRGBColor(0xCE, 0xFF, 0xFF, 0x00));

    // display "Hello Window"
    // SFXRGBColor(0x00, 0x00, 0x00, 0x00) defines black
    graphics->DrawText("Hello Window", 
                       GetContentWorld(),
                       SFXRGBColor(0x00, 0x00, 0x00, 0x00));
    return;
}

// create TitleWindow
MyWindowPtr window;
window = new MyWindow();

Figure 10.20. Execution Result

Execution Result

The topleft of drawing area is (0,0) that can be obtained by using GetContentWorld function.

Figure 10.21. Drawing Area of TitleWindow

Drawing Area of TitleWindow

10.4.5. Multiple Windows

The number of Window instances to be created is not limited. When there are more than one Window instances, event handling depends upon the event type. For example, a key event is dispatched to the topmost Window instance with the Control instance focused. Suspend and resume events are dispatched to all the Window instances.

Figure 10.22. Multiple Windows

Multiple Windows

To make a window to be topmost, use the Select function.

Example 10.17. Method to make the window to be topmost

// _window is SFRWindowPtr type
_window->Select();

10.4.6. Invalidation

A window can be disabled to be selected or be invisible. When a window is invalidated, all the controls in within become invalidated, too.

Table 10.4. Functions for setting / getting the Responder status

Function Name Description
SetStatusEnable Set the "enable/disable" status of Responder instance.(true: enable, false: disable)
GetStatusEnable Get the "enable/disable" status of Responder instance.(true: enable, false: disable)
SetStatusVisible Set the "visible/invisible" status of Responder instance. (true: visible, false: invisible)
GetStatusVisible Get the "visible/invisible" status of Responder instance.(true: visible, false: invisible)

Method to Make the Window Disable

// _window is SFRWindowPtr type
_window->SetStatusEnable(false);

Figure 10.23. Window became disabled

Window became disabled