SophiaFramework UNIVERSE 5.3 |
Customize the code of HelloWorld application generated by the SophiaFramework AppWizard to display the window below.
Define MyWindow class.
Example 5.8. Define the Title-Window "MyWindow"
// MyWindow inherits from SFRTitleWindow
SFMTYPEDEFCLASS(MyWindow)
class MyWindow : public SFRTitleWindow {
SFMSEALCOPY(MyWindow)
public:
MyWindow(Void) static_throws;
virtual ~MyWindow(Void);
HANDLER_DECLARE_VOIDRENDER(OnRenderContent)
HANDLER_DECLARE_BOOLEVENT(OnKey)
};
Implement handler functions for drawing the string "Hello World" and processing when the "Select" key is pressed.
Example 5.9. Implement the Title-Window "MyWindow"
// Constructor ( create and initialize window ) // window is created at coordinates: (20, 20); width: 200; height: 250 // title: "my window" MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // register drawing handler (error handling omitted) RegisterHandler(SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT, HANDLER_BEFORE, HANDLER_FUNCTION(OnRenderContent)); // register key handler RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey)); return; } // Destructor (executed when window is terminated) MyWindow::~MyWindow(Void) { return; } // Drawing handler (handles drawing events within window) HANDLER_IMPLEMENT_VOIDRENDER(MyWindow, OnRenderContent, graphics) { // draw screen // paint drawing area in white // GetContentWorld()returns an SFXRectangle (representing drawing area in window) // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) defines white graphics->FillRectangle(GetContentWorld(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); // draw "Hello Window" graphics->DrawText("Hello Window", GetContentWorld(), SFXRGBColor(0x00, 0x00, 0x00, 0x00)); return; } // Key handler (executed when a key is pressed while MyWindow is displayed) HANDLER_IMPLEMENT_BOOLEVENT(MyWindow, OnKey, event) { switch (event.GetP16()) { case AVK_CLR: // when "clear" key is pressed // window is terminated (*) return Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); case AVK_1: // when "1" key is pressed // display string for debugging on BREW simulator TRACE("1-key"); return true; } return false; }
Customize the key handler to create and display the window when the "1" key is pressed.
Example 5.10. Customize the key handler
HANDLER_IMPLEMENT_BOOLEVENT(HelloWorld, OnKey, event) { switch (event.GetP16()) { case AVK_SELECT: // when "Select" key is pressed Terminate(); // application is ended return true; // *** added code segments are in bold case AVK_1: // create window with "new" operator // (error handling is omitted) new MyWindow(); // process key event and return true return true; } return false; }
Customize the drawing handler to paint the background in white.
Example 5.11. Customize the drawing handler
// Drawing handler HANDLER_IMPLEMENT_VOIDRENDER(HelloWorld, OnRenderContent, graphics) { // paint drawing area in white // GetContentWorld()returns an SFXRectangle (representing drawing area in window) // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) defines white // *** add the following graphics->FillRectangle(GetContentWorld(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); // *** edit the following graphics->DrawText("Hello World", GetContentWorld(), SFXRGBColor(0x00, 0x00, 0x00, 0x00)); return; }
To destroy the instance of MyWindow class, send the event of SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true) by the Invoke function.
Warning | |
---|---|
The code below is to send the terminate event to the instance of MyWindow class. |
Example 5.12. Destroy the window
// destroy window
return Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true));
Warning | |
---|---|
The delete operator cannot be used to destroy the window. |
BREW Output Window
Note: | |
---|---|
The BREW Output Window can be displayed by clicking [menu]-[display]-[Output Window]. |
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |