PrevNextUpHome SophiaFramework UNIVERSE 5.3

10.9. Drawing the Responder

10.9.1. Drawing Region

There are 3 types of regions for drawing the Responder instance.

  • Base region: entire area of Responder instance
  • Content region: area for drawing texts or figures
  • Frame region: area between base and content region

Figure 10.51. TitleWindow (SFRTitleWindow)Example

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

Button (SFRButtonControl) Example
[Note] 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

10.9.2. Scrolling

When the object to be drawn is larger than the content region, the virtual region is used.

Figure 10.53. Virtual Region

Virtual Region

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.

Figure 10.54. Base Region, Content Region, Frame Region, and Virtual Region

Base Region, Content Region, Frame Region, and Virtual Region

Figure 10.55. Window regions

Window regions

10.9.3. Redrawing

The method to redraw the Responder instance is as follows:

  1. To redraw the base region of Responder instance, register it as redrawing area by using the InvalidateBase function.
  2. To redraw the content region of Responder instance, register it as redrawing area by using the InvalidateContent function.
  3. To redraw the rectangular region in the content region of Responder instance, register it as redrawing area by using the InvalidateContent function.

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.

Example 10.66. Redraw

// redraw responder content region
responder->InvalidateContent();

// redraw responder base region
responder->InvalidateBase();

// redraw part of content region (specified as rectangular region)
responder->InvalidateContent(SFXRectangle(10, 20, 40, 40));

10.9.4. Forced Redrawing

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] 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.

10.9.5. Destroying

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;
  }
}

10.9.6. Reference Value

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());