BREW HelloWorld - 5 / 7 -
Source Code
Boot Code
Any application coded with SophiaFramework UNIVERSE needs to have SFCApplet::Boot() function and Factory() function.
// // HelloWorld.cpp // #include "HelloWorld.hpp" // 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; }
Application Class ( HelloWorld class )
Since it uses GUI framework, HelloWorld class inherits SFRApplication class.
// // HelloWorld.hpp // #ifndef __HELLOWORLD_HPP #define __HELLOWORLD_HPP #include <SophiaFramework.hpp> #include "HelloWorld.bid" // // HelloWorld application class // SFMTYPEDEFCLASS(HelloWorld) class HelloWorld : public SFRApplication { SFMSEALCOPY(HelloWorld) public: static SFCInvokerPtr Factory(Void); private: explicit HelloWorld(Void) static_throws; virtual ~HelloWorld(Void); HANDLER_DECLARE_VOIDRENDER(OnRenderContent) HANDLER_DECLARE_BOOLEVENT(OnKey) }; #endif // __HELLOWORLD_HPP //
Event Handlers
Event handler executes certain process when application boots up, or a key is pushed.
Code drawing process in drawing handler. By coding graphics->DrawText() function, "HelloWorld" will be displayed on the screen.
// Drawing handler HANDLER_IMPLEMENT_VOIDRENDER(HelloWorld, OnRenderContent, graphics) { //Constant struct static SFXRGBColor::AtomRecConst black = { 0x00, 0x00, 0x00, 0x00 }; // Screen is cleared SFRApplication::ContentHandler(graphics); // Draw text graphics->DrawText("Hello World", GetContentWorld(), black); return; }
Code events in key handler.
// Key handler HANDLER_IMPLEMENT_BOOLEVENT(HelloWorld, OnKey, event) { switch (event.GetP16()) { case AVK_SELECT: // When select key is pushed Terminate(); // Finish application return true; } return false; }
Register Event Handler
Register event handler by using RegisterHandler function. Throw in event code, data attached with event code, when to invoke the function, function pointer as option.
// Constructor HelloWorld::HelloWorld(Void) static_throws { if (static_try()) { static_throw( RegisterHandler(SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT, HANDLER_BEFORE, HANDLER_FUNCTION(OnRenderContent))); } if (static_try()) { static_throw( RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey))); } return; } // Destructor HelloWorld::HelloWorld(Void) { return; }