Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
GCText Class Reference

Class to draw text on Graphics Context using wxWidgets. More...

#include <GCText.h>

Public Member Functions

 GCText (wxString text)
 
virtual void Draw (wxPoint2DDouble position, wxGraphicsContext *gc, double angle=0.0, wxColour colour= *wxBLACK) const
 Draw the text in wxGraphicsContext.
 
virtual void Draw (wxPoint2DDouble position, double width, double height, wxDC &dc, double angle=0.0, wxColour colour= *wxBLACK) const
 
virtual GCTextGetCopy ()
 Get a deep text copy.
 
virtual void SetText (wxString text)
 Set correctly a new text string.
 
virtual void SetText (wxString text, wxSize size)
 
virtual wxString GetText () const
 
virtual int GetWidth () const
 
virtual int GetHeight () const
 
virtual void SetFontSize (int fontSize)
 
virtual int GetFontSize ()
 
virtual void SetFont (wxFont font)
 
virtual wxFont GetFont ()
 

Protected Attributes

wxString m_text = _("Text")
 
int m_fontSize = 10
 
wxFont m_font
 
bool m_customFont = false
 
wxSize m_size
 

Detailed Description

Class to draw text on Graphics Context using wxWidgets.

Author
Thales Lima Oliveira thale.nosp@m.s@uf.nosp@m.u.br
Date
16/05/2024

Definition at line 31 of file GCText.h.

Constructor & Destructor Documentation

◆ GCText() [1/2]

GCText::GCText ( )

Definition at line 25 of file GCText.cpp.

25{}

◆ GCText() [2/2]

GCText::GCText ( wxString  text)

Definition at line 26 of file GCText.cpp.

27{
28 SetText(text);
29}
virtual void SetText(wxString text)
Set correctly a new text string.
Definition GCText.cpp:68

◆ ~GCText()

GCText::~GCText ( )
virtual

Definition at line 31 of file GCText.cpp.

32{
33}

Member Function Documentation

◆ Draw() [1/2]

void GCText::Draw ( wxPoint2DDouble  position,
double  width,
double  height,
wxDC &  dc,
double  angle = 0.0,
wxColour  colour = *wxBLACK 
) const
virtual

Definition at line 43 of file GCText.cpp.

44{
45 dc.SetFont(m_font);
46 dc.SetPen(wxPen(colour));
47 dc.SetTextForeground(colour);
48
49 if(angle == 0.0) {
50 dc.DrawText(m_text, position.m_x - width / 2.0, position.m_y - height / 2.0);
51 return;
52 }
53
54 double rad = wxDegToRad(angle);
55
56 double dx = -width / 2.0;
57 double dy = -height / 2.0;
58
59 double rx = dx * cos(rad) - dy * sin(rad);
60 double ry = dx * sin(rad) + dy * cos(rad);
61
62 double drawX = position.m_x + rx;
63 double drawY = position.m_y + ry;
64
65 dc.DrawRotatedText(m_text, drawX, drawY, -angle);
66}

◆ Draw() [2/2]

void GCText::Draw ( wxPoint2DDouble  position,
wxGraphicsContext *  gc,
double  angle = 0.0,
wxColour  colour = *wxBLACK 
) const
virtual

Draw the text in wxGraphicsContext.

Parameters
positionText position.
gcGraphics Context.
angleText angle.
colourText colour.

Definition at line 35 of file GCText.cpp.

36{
37 //gc->SetFont(wxFont(m_fontSize, m_fontFamily, m_fontStyle, m_fontWeight), colour);
38
39 gc->SetFont(m_font, colour);
40 gc->DrawText(m_text, position.m_x, position.m_y, angle);
41}
Here is the caller graph for this function:

◆ GetCopy()

GCText * GCText::GetCopy ( )
virtual

Get a deep text copy.

Warning
The original object is not freed.
Returns
New text pointer.

Definition at line 99 of file GCText.cpp.

100{
101 GCText* copy = new GCText();
102 *copy = *this;
103 return copy;
104}
Class to draw text on Graphics Context using wxWidgets.
Definition GCText.h:32
Here is the caller graph for this function:

◆ GetFont()

virtual wxFont GCText::GetFont ( )
inlinevirtual

Definition at line 68 of file GCText.h.

68{ return m_font; }

◆ GetFontSize()

virtual int GCText::GetFontSize ( )
inlinevirtual

Definition at line 66 of file GCText.h.

66{ return m_fontSize; }

◆ GetHeight()

virtual int GCText::GetHeight ( ) const
inlinevirtual

Definition at line 64 of file GCText.h.

64{ return m_size.GetHeight(); }

◆ GetText()

virtual wxString GCText::GetText ( ) const
inlinevirtual

Definition at line 62 of file GCText.h.

62{ return m_text; }

◆ GetWidth()

virtual int GCText::GetWidth ( ) const
inlinevirtual

Definition at line 63 of file GCText.h.

63{ return m_size.GetWidth(); }

◆ SetFont()

void GCText::SetFont ( wxFont  font)
virtual

Definition at line 92 of file GCText.cpp.

93{
94 m_font = font;
95 m_customFont = true;
96 SetText(m_text); // Recalculate the size with the new font
97}

◆ SetFontSize()

virtual void GCText::SetFontSize ( int  fontSize)
inlinevirtual

Definition at line 65 of file GCText.h.

65{ m_fontSize = fontSize; }

◆ SetText() [1/2]

void GCText::SetText ( wxString  text)
virtual

Set correctly a new text string.

Parameters
textNew text string.

Definition at line 68 of file GCText.cpp.

69{
70 m_text = text;
71 if (!m_customFont) {
72 m_font = wxFont(m_fontSize,
73 wxFONTFAMILY_DEFAULT,
74 wxFONTSTYLE_NORMAL,
75 wxFONTWEIGHT_NORMAL,
76 false,
77 wxT("Arial"));
78 }
79
80
81 wxScreenDC dc;
82 dc.SetFont(m_font);
83 m_size = dc.GetTextExtent(m_text);
84}
Here is the caller graph for this function:

◆ SetText() [2/2]

void GCText::SetText ( wxString  text,
wxSize  size 
)
virtual

Definition at line 86 of file GCText.cpp.

87{
88 m_text = text;
89 m_size = size;
90}

Member Data Documentation

◆ m_customFont

bool GCText::m_customFont = false
protected

Definition at line 76 of file GCText.h.

◆ m_font

wxFont GCText::m_font
protected

Definition at line 75 of file GCText.h.

◆ m_fontSize

int GCText::m_fontSize = 10
protected

Definition at line 74 of file GCText.h.

◆ m_size

wxSize GCText::m_size
protected

Definition at line 78 of file GCText.h.

◆ m_text

wxString GCText::m_text = _("Text")
protected

Definition at line 73 of file GCText.h.


The documentation for this class was generated from the following files: