PrevNextUpHome SophiaFramework UNIVERSE 5.3

12.8. Color

12.8.1. RGB Color

Table 12.7. Color Class

Class Name Description
SFXRGBColor Class which manages the RGB color.

The range of RGB-alpha value to be set is between 0 and 255.

[Note] What is RGB-alpha?

R = Red, G = Green, B = Blue, alpha = alpha value

Example 12.35. Define the color

// defining color (from left: R, G, B, alpha)
// SFXRGBColor(0xFF, 0x00, 0x00, 0x00) = red
SFXRGBColor color(0xFF, 0x00, 0x00, 0x00);

Example 12.36. Fill the rectangle

// rectangle
SFXRectangle rectangle(30, 30, 40, 40);

// fill rectangle (2nd argument is SFXRGBColor type)
graphics->FillRectangle(rectangle, color);

// fill rectangle with specified color
// SFXRGBColor( 0x00, 0x00, 0xFF, 0x00 ) = blue
graphics->FillRectangle(SFXRectangle(90, 30, 40, 40),
                           SFXRGBColor(0x00, 0x00, 0xFF, 0x00));

Figure 12.11. Exection Result

Exection Result

Example 12.37. Get the colors

UInt08 r = color.GetRed();   // r = 0xFF
UInt08 g = color.GetGreen(); // g = 0x00
UInt08 b = color.GetBlue();  // b = 0x00
UInt08 a = color.GetAlpha(); // a = 0x00

Example 12.38. Set the colors

// set R, G, B, alpha
color.Set(0x00, 0xFF, 0x99, 0x00);

// set RGB to 0x33, set alpha to 0x00
color.Set(0x33, 0x00);

// set each element individually
color.SetRed(0x00);
color.SetGreen(0xFF);
color.SetBlue(0x99);
color.SetAlpha(0x00);

Example 12.39. Operate the colors

color.Set(0x30, 0xE0, 0x40, 0x00);

// addition
color.AddRed(0x60);     // R value = 0x90
color.AddGreen(0x60);   // G value = 0xFF
                        // ( overflow is properly treated)
color.Add(0x33, 0x10);  // add 0x33 to RGB value, 0x10 to alpha value

// subtraction
color.SubBlue(0x60);    // B value = 0x00
                        // (underflow is properly treated)
color.Sub(0x33, 0x10);  // subtract 0x33 from RGB value, subtract 0x10 from alpha value

12.8.2. Color of 3-D looking rectangle(frame)

Table 12.8. Class to manage the color of 3-D looking rectangle(frame)

Class Name Description
SFXFrameColor Class which represents the frame color(F) and the shadow colow(S) for the 3-D looking rectangle(frame).

The frame color(F) and the shadow color(S) are set with the RGB color.

Example 12.40. Set the colors

SFXFrameColor frameColor;

frameColor.SetFrame(SFXRGBColor(0xFF, 0x00, 0x00, 0x00));  // set frame color
frameColor.SetShadow(SFXRGBColor(0x99, 0x99, 0xFF, 0x00)); // set shadow color

Example 12.41. Draw the frame

// pass rectangle to be drawn as first argument
graphics->DrawFrame(SFXRectangle(20, 20, 40, 50), frameColor);

Figure 12.12. Execution Result

Execution Result

Example 12.42. Operate the colors

frameColor.AddFrameRed(0x66);   // add 0x66 to R value of frame color
frameColor.AddFrameRGB(0x66);   // add 0x66 to RGB value of frame color
frameColor.AddShadowBlue(0x66); // add 0x66 to B value of shadow color
frameColor.AddRed(0x66);        // add 0x66 to R value of frame and shadow color
frameColor.AddRGB(0x66);        // add 0x66 to RGB value of frame and shadow color

12.8.3. Color of 3-D looking rectangle(bevel)

Table 12.9. Class to manage the color of 3-D looking rectangle(bevel)

Class Name Description
SFXBevelColor Class which represents the light color(L), the base color(B), and the dark color(D) for the 3-D looking rectangle(bevel).

The light color(L), the base color(B), and the dark color(D) are set with the RGB color.

Example 12.43. Set the colors

SFXBevelColor bevelColor;

bevelColor.SetBase(SFXRGBColor(0xFF, 0x00, 0x00, 0x00));  // set base color
bevelColor.SetLight(SFXRGBColor(0x00, 0xFF, 0x00, 0x00)); // set light color
bevelColor.SetDark(SFXRGBColor(0x00, 0x00, 0xFF, 0x00));  // set dark color

Example 12.44. Draw the bevel

// pass rectangle to be drawn as first argument
graphics->FillBevelRectangle(SFXRectangle(20, 20, 40, 50), bevelColor);

Figure 12.13. Execution Result

Execution Result

Example 12.45. Operate the colors

bevelColor.AddBaseRed(0x66);   // add 0x66 to R value of base color
bevelColor.AddBaseRGB(0x66);   // add 0x66 to RGB value of base color
bevelColor.AddLightBlue(0x66); // add 0x66 to B value of light color
bevelColor.AddRed(0x66);       // add 0x66 to R value of base, light, and dark
bevelColor.AddRGB(0x66);       // add 0x66 to RGB value of base, light, and dark

12.8.4. Setting Color to the SFXGraphics Instance

There are two methods to set the color when drawing figure or text.

Example 12.46. Method 1: Using the argument for drawing function

SFXGraphicsPtr graphics = SFXGraphics::GetInstance();

SFXRGBColor color(0x00, 0xFF, 0x00, 0x00);

// draw text using color argument
graphics->DrawText("text", SFXGrid(10, 20), color);

Example 12.47. Method 2: Using the SetForeColor function

SFXGraphicsPtr graphics = SFXGraphics::GetInstance();

SFXRGBColor color(0x00, 0xFF, 0x00, 0x00);

// set fore color using SetForeColor function
graphics->SetForeColor(color);

// draw text
graphics->DrawText("text", SFXGrid(10, 20));
[Note] Note

In the Method 1, the SetForeColor function will be called in the DrawText function. Therefore the Method 2 is recommended when the DrawText function is called more than one time.