SRGraphTitle adds text drawing functionality to the basic component class and can display multiple line text. The new line character, \n, can be used to separate lines.
SRGraphTitle can be used in two modes. By default, an SRGraphTitle gets its title text from its parent, the SRGraph object, during every draw cycle by calling GetParentContent().
WARNING: It is critical that the call to SetYMargin() follow the call to SetMeasurement().
Alternatively, it can display its own text, provided by SetText(), if SetUseOwnText(TRUE) is also called. This allows several titles to be used in one chart.
To change the text shown in the title panel:
Change the m_title member of the SRGraph object that owns the title component by calling m_Graph.SetGraphTitle().
Or, call SetUseOwnText(TRUE) and SetText() to supply the text string.
The code below creates the multiline, autosized title shown in Figure 102.
SRGraphTitle* pTitle = new SRGraphTitle; pTitle->SetUseOwnText(TRUE); pTitle->SetText("Sales Forecast\n1999-2001"); pTitle->SetFontStyle(CX_FONT_BOLD | CX_FONT_AUTOSIZE); pTitle->SetTextColor(CXCLR_MAGENTA); pTitle->SetMeasurement(SRGraphComponent::PERCENT); pTitle->SetRect(5,5,90,90); pTitle->SetJustification(2); pTitle->GetStyle()->SetComponentFillStyle(CX_SOLID_FILL); pTitle->GetStyle()->SetColor(CXCLR_CYAN); pTitle->GetStyle()->SetComponentShadowStyle(CX_THICK_SHADOW); pTitle->GetStyle()->SetComponentBorderStyle(CX_THICK_3D_BORDER); m_Graph.AddComponent(pTitle); |
The remainder of this section discusses how the appearance of text can be modified.
The SRGraphTitle class also contains the font management functions. All classes that display text are derived from this class, so all the methods described here can be used for text in any other type of Objective Chart component.
Fonts may be selected from any of the available bitmap or TrueType fonts. The following functions specify the appearance of displayed text:
SetFaceName()
SetFontStyle()
SetFontSize()
SetTextColor()
SetLogFont()
To change text appearance, call the font selection functions defined in SRGraphTitle. For example:
SRGraphTitle* pT=new SRGraphTitle; CString sFace = "Times New Roman"; pT->SetFaceName(sFace); pT->SetFontStyle(CX_FONT_BOLD | CX_FONT_AUTOSIZE); pT->SetTextColor(CXCLR_MAGENTA); |
The font size may be specified in two ways:
By point size as a positive number
By pixel size as negative number
In the latter case, the font character height is calculated from the absolute number of the given size. For example, SetFontSize(18) sets the font to 18 points, and SetFontSize(-18) sets the height to 18 pixels.
As shown above, the SetFontStyle() function sets the standard font styles — bold, italic, underline, and strikeover. Use the following symbols to enable the related style. The symbols can be combined with the OR operator (|).
CX_FONT_BOLD CX_FONT_ITALIC CX_FONT_UNDERLINE CX_FONT_STRIKEOUT CX_FONT_AUTOSIZE CX_FONT_EMBOSS CX_FONT_RELIEF CX_FONT_NOWRAP |
The special font style, CX_FONT_AUTOSIZE, causes the component's own CalcFontAutoSize() function to be called to determine the font size. For a Title component, the font size is selected to fit the text to the component rectangle. For a Legend component, the font height is set to 10% of the rectangle height. You can override CalcFontAutoSize() to select a font size appropriate for your needs.
The SRGraphTitle functions described above provide control of most, but not all, font selection parameters. Occasionally, you may need to specify some other parameter, or you may find it more convenient to use a LOGFONT structure to select a font.
To use a LOGFONT structure for font selection:
Create a LOGFONT structure and fill it in.
Call SRGraphTitle::SetLogFont(). For example:
static LOGFONT lf; lf.lfHeight=-13; lf.lfWidth=0; lf.lfEscapement=0; lf.lfOrientation=0; lf.lfWeight=400; lf.lfItalic=TRUE; lf.lfUnderline=FALSE; lf.lfStrikeOut=FALSE; lf.lfCharSet=ANSI_CHARSET; lf.lfOutPrecision=OUT_STROKE_PRECIS; lf.lfClipPrecision=CLIP_STROKE_PRECIS; lf.lfQuality=DRAFT_QUALITY; lf.lfPitchAndFamily=DEFAULT_PITCH; _tcsncpy(lf.lfFaceName,(LPCTSTR)_T("Arial"),6); SRGraphTitle* pT = new SRGraphTitle; pT->SetLogFont(&lf); |
There is a complication in using SetLogFont() to set font information in Objective Chart. The chart's font caching system only uses the FaceName, FontSize, FontStyle, and Orientation data to identify individual fonts. The method SetLogFont()sets these parameters from the LOGFONT data, so it works better with the font caching system. You can call SetLogFont() repeatedly to change fonts on the fly, but each time you must make sure that one of the identifying traits is changed. If not, you can use one of the unused bits of FontStyle to flag the change. For example:
if(bFontChanged) { int nStyle = pC->GetFontStyle(); pC->SetFontStyle(nStyle+256); // hack to force a new font } |
The positioning of the title text within the component rectangle can be changed by calling SRGraphTitle::SetJustication(). To specify the alignment of the annotations within their allotted space:
Call SetJustification(0) for left alignment.
Call SetJustification(1) for right alignment.
Call SetJustification(2) for center alignment.
If the text is too long for the specified component rectangle (and CX_FONT_AUTOSIZE is not selected), the text will automatically wrap to a second line. You can disable this automatic word-wrapping by including CX_FONT_NOWRAP in the font style.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.