SophiaFramework UNIVERSE 5.3 |
There are 3 types of regions for drawing the Responder instance.
Figure 10.51. TitleWindow (SFRTitleWindow)Example
Table 10.13. Functions for region setting/getting
Function Name | Description |
---|---|
GetBaseBound | Get the base region with the coordinate of parent Responder instance. |
GetBaseWorld | Get the base region. |
SetBaseBound | Set the base region with the coordinate of parent Responder instance. |
GetContentBound | Get the content region with the coordinate of base region. |
GetContentWorld | Get the content region. |
SetContentBound | Set the content region with the coordinate of base region. |
GetFrameMargin | Get the frame as margin. |
SetFrameMargin | Set the frame as margin. |
Figure 10.52. Button (SFRButtonControl) Example
Note | |
---|---|
In case of button, the content region is the same with the base region. |
Example 10.61. Create Responder instances on the above figure
SFRTitleWindowPtr window1 = new SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(10, 15, 180, 200), "Window 1"); SFRButtonControlPtr button1 = new SFRButtonControl(window1, SFXRectangle(15, 30, 120, 40), "button1");
Example 10.62. How to get regions
SFXRectangle rectangle; SFXMargin margin; // methods to get drawing regions of window1 rectangle = window1->GetBaseBound(); // get base region in coordinate system of parent responder // rectangle will be (10, 15, 180, 200) (left edge 10,top edge 15, width 180, height 200) rectangle = window1->GetBaseWorld(); // get base region // rectangle will be (0, 0, 180, 200) rectangle = window1->GetContentBound(); // get content region in coordinate system of base region // rectangle will be (2, 25, 175, 172) rectangle = window1->GetContentWorld(); //get content region // rectangle will be (0, 0, 175, 172 ) margin = window1->GetFrameMargin(); // get frame as margins // margins will be ( 2, 25, 3, 3 ) // (left margin 2, top margin 25, right margin 3, bottom margin 3) // method to get drawing region of button1 rectangle = button1->GetBaseBound(); // get base region in coordinate system of its parent (window1) // rectangle will be( 15, 30, 120, 40) rectangle = button1->GetBaseWorld(); // get base region // rectangle will be (0, 0, 120, 40) rectangle = button1->GetContentBound(); // get content region in coordinate system of base region // rectangle will be (0, 0, 120, 40) // since button does not have frame, function returns same result as GetBaseWorld rectangle = button1->GetContentWorld(); //get content region // rectangle wil be (0, 0, 120, 40) margin = button1->GetFrameMargin(); // get frame as margins // margins wil be (0, 0, 0, 0)
The top, bottom, left, and right margins are presented in SFXMargin
When the object to be drawn is larger than the content region, the virtual region is used.
Example 10.63. Draw in the virtual region of Window instance
// window1 (window in above figure) is pointer to SFRTitleWindow instance // set virtual region larger than content region of window window1->SetVirtualBound(SFXRectangle(0, 0, 200, 1000));
Example 10.64. Drawing handler for window1
// paint all virtual region in white graphics->FillRectangle(GetVirtualWorld(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); SInt32 fontHeight = graphics->GetFontHeight(); // get font height SInt32 i; for (i = 0; i < 14; ++i) { SFXRectangle rect(0, i * 30, 150, fontHeight); // rectangle // draw string "Line i" SFXAnsiString str = SFXAnsiString::Format("Line %2d", i + 1); graphics->DrawText(str, rect, SFXRGBColor(0x00, 0x00, 0x00, 0x00)); }
Example 10.65. Change the view in the virtual region
// scroll virtual region of window1 by specified pixels with argument
window1->Scroll(SFXSize(0, 40));
The scroll function is used to change the view in the virtual region.
The method to redraw the Responder instance is as follows:
When the above redrawing area is registered, the drawing handler is automatically called at the end of each event loop. And then the redrawing area will be redrawn.
When calling the Invalidate function in the Callback function for processing such as timer or network communication, the redrawing event must be sent to the instance of Application class to redraw the screen forcedly.
Example 10.67. Redraw forcedly
// registered region is forced to redraw SFRApplication::GetInstance()->Invoke(SFXEvent(SREVT_RESPONDER_RENDER, SRP16_RENDER_INVOKE, false)); // all responders unrelated to registered region are forced to redraw SFRApplication::GetInstance()->Invoke(SFXEvent(SREVT_RESPONDER_RENDER, SRP16_RENDER_INVOKE, true));
Warning | |
---|---|
The Redrawing event must be sent to the instance of Application class. Since it takes much time to redraw, try to avoid Redrawing as much as possible. |
To destroy the Responder instance, sent the SREVT_RESPONDER_TERMINATE event to it.
If the errors occur while creating the Responder instance in the constructor, use the delete operator to destroy it.
Example 10.68. Destroy the Responder
SFRWindowPtr window; if ((window = new SFRTitleWindow(this, SFXRectangle(0, 0, 100, 100), "Sample")) != null) { if (window->static_catch() == SFERR_NO_ERROR) { window->Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); } else { ::delete window; } }
Reference value (VoidPtr type) can be set to the Responder instance.
Example 10.69. Button with label
SFRButtonControlPtr button; SInt32 i; // create 10 buttons and setting number (reference value) for (i = 0; i < 10; ++i) { button = new SFRButtonControl(this, SFXRectangle(0, i * 30, 20, 20), "); // identification number is set to button button->SetReference(reinterpret_cast<VoidPtr>(i)); } ... // get number (reference value) SInt32 number = reinterpret_cast<SInt32>(button->GetReference());
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |