SophiaFramework UNIVERSE 5.3 |
The method to draw a window and scroll its virtual region will be described here.
In addintion to placing controls and/or containers in SFZWindow, texts or images can be drawn too.
To draw a window(SFZWindow) externally, you have to register the drawing handler into the window(SFZWindow).
Example 9.58. Declaration
SFMTYPEDEFCLASS(USRApplication)
class USRApplication: public SFYApplication {
SFMSEALCOPY(USRApplication)
private:
SFZWindowSmp _window;
...
private:
SFCError Make(Void);
// drawing handler for window
XANDLER_DECLARE_VOIDRENDER(OnRenderRequest)
};
Example 9.59. Implementation
SFCError USRApplication::Make(Void) { SFCError error(SFERR_NO_ERROR); // make window if ((_window = SFZWindow::NewInstance(&error)) != null) { // set window's parent responder to USRApplication error = _window->SetParent(GetThis()); if (error == SFERR_NO_ERROR) { // register drawing handler into window error = _window->RegisterHandler( SFXEventRange(SFEVT_RESPONDER_RENDER, SFEVT_RESPONDER_RENDER, SFP16_RENDER_REQUEST, SFP16_RENDER_REQUEST), XANDLER_INTERNAL(OnRenderRequest) ); if (error == SFERR_NO_ERROR) { // set window's real region _window->SetRealBound(GetLocalBound().Deflate(10, 10)); // set the window's state to "visible" + "active" + "enable" + "focus" together _window->SetState(true, true, true, true); // move window foremost _window->ToFront(); } } } return error; } // drawing handler XANDLER_IMPLEMENT_VOIDRENDER(USRApplication, OnRenderRequest, invoker, reason, graphics) { SFXRectangle local; SInt16 i; SInt16 j; local.Set(_window->GetLocalBound()); // draw check pattern for (j = 0; j < local.GetBottom(); j += 10) { for (i = 0; i < local.GetRight(); i += 10) { if ((i + j) / 10 % 2 == 0) { graphics->FillRectangle(SFXRectangle(i, j, 10, 10), SFXRGBColor(0xCC, 0xFF, 0xCC, 0x00)); } else { graphics->FillRectangle(SFXRectangle(i, j, 10, 10), SFXRGBColor(0xAA, 0xDD, 0xAA, 0x00)); } } } return; }
In addintion to placing controls and/or containers in a window, texts or images can be drawn too.
To draw the user-defined window inside itself, override the SFYWidget::HandleRenderRequest virtual function. In this case, you don't have to register the drawing handler.
Merit to override HandleRenderRequest() | |
---|---|
The SFYWidget::HandleRenderRequest virtual function is called in the drawing handler that is registered into SFYWidget and will be booted up first when the (SFEVT_RESPONDER_RENDER, SFP16_RENDER_REQUEST) drawing event occurs. Though it is possible to draw a window by registering its drawing handler, you don't have to register any drawing handler using this method. |
Example 9.60. Declaration
SFMTYPEDEFRESPONDER(USRWindow)
class USRWindow: public SFZWindow {
SFMSEALRESPONDER(USRWindow)
SFMRESPONDERINSTANTIATEFOUR(USRWindow, SFZWindow, SFYContainer, SFYWidget, SFYResponder)
...
protected:
// override HandleRenderRequest() virtual function booted up when drawing event is received
virtual Void HandleRenderRequest(SFXGraphicsPtr graphics) const;
};
Example 9.61. Implementation
// drawing handler Void USRWindow::HandleRenderRequest(SFXGraphicsPtr graphics) const { SFXRectangle local; SInt16 i; SInt16 j; local.Set(GetLocalBound()); // draw check pattern for (j = 0; j < local.GetBottom(); j += 10) { for (i = 0; i < local.GetRight(); i += 10) { if ((i + j) / 10 % 2 == 0) { graphics->FillRectangle(SFXRectangle(i, j, 10, 10), SFXRGBColor(0xCC, 0xFF, 0xCC, 0x00)); } else { graphics->FillRectangle(SFXRectangle(i, j, 10, 10), SFXRGBColor(0xAA, 0xDD, 0xAA, 0x00)); } } } return; }
If the virtual region of a window is set to a region larger than its real region, it can be scrolled up and down.
The sample code to scroll up and down the virtual region of a window is as follows:
Example 9.62. Declaration
SFMTYPEDEFCLASS(USRApplication) class USRApplication: public SFYApplication { SFMSEALCOPY(USRApplication) private: SFZWindowSmp _window; ... private: SFCError Make(Void); XANDLER_DECLARE_VOIDRENDER(OnRenderRequest) };
Example 9.63. Implementation
SFCError USRApplication::Make(Void) { SFCError error(SFERR_NO_ERROR); if ((_window = SFZWindow::NewInstance(&error)) != null) { error = _window->SetParent(GetThis()); if (error == SFERR_NO_ERROR) { error = _window->RegisterHandler( SFXEventRange(SFEVT_RESPONDER_RENDER, SFEVT_RESPONDER_RENDER, SFP16_RENDER_REQUEST, SFP16_RENDER_REQUEST), XANDLER_INTERNAL(OnRenderRequest) ); if (error == SFERR_NO_ERROR) { _window->SetRealBound(GetLocalBound().Deflate(10, 10)); // set virtual region to region obtained by expanding virtual region down by 100 pixels _window->SetVirtualBound(SFXRectangle(_window->GetVirtualBound()).AddBottom(100)); // set scroll step to 5 pixels _window->SetScrollStep(5); // set flag indicating whether or not to move to top or bottom by next scrolling when reaching at bottom or top _window->SetScrollRepeat(true); _window->SetState(true, true, true, true); _window->ToFront(); } } } return error; } XANDLER_IMPLEMENT_VOIDRENDER(USRApplication, OnRenderRequest, invoker, reason, graphics) { SFXRectangle local; SInt16 i; SInt16 j; local.Set(_window->GetLocalBound()); for (j = 0; j < local.GetBottom(); j += 10) { for (i = 0; i < local.GetRight(); i += 10) { if ((i + j) / 10 % 2 == 0) { graphics->FillRectangle(SFXRectangle(i, j, 10, 10), SFXRGBColor(0xCC, 0xFF - j, 0xCC + j, 0x00)); } else { graphics->FillRectangle(SFXRectangle(i, j, 10, 10), SFXRGBColor(0xAA, 0xDD - j, 0xAA + j, 0x00)); } } } return; }
Note | |
---|---|
In case of the user-defined window, it is the same as the above. |
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |