Power System Platform  2026w10a-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 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 161 of file GCText.cpp.

162{
163 GCText* copy = new GCText();
164 *copy = *this;
165
166 copy->SetText(copy->m_text);
167 return copy;
168}
Class to draw text on Graphics Context using wxWidgets.
Definition GCText.h:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFont()

virtual wxFont GCText::GetFont ( )
inlinevirtual

Definition at line 70 of file GCText.h.

70{ return m_font; }

◆ GetFontSize()

virtual int GCText::GetFontSize ( )
inlinevirtual

Definition at line 65 of file GCText.h.

65{ return m_fontSize; }

◆ GetHeight()

virtual int GCText::GetHeight ( ) const
inlinevirtual

Definition at line 63 of file GCText.h.

63{ return m_size.GetHeight(); }

◆ GetText()

virtual wxString GCText::GetText ( ) const
inlinevirtual

Definition at line 61 of file GCText.h.

61{ return m_text; }

◆ GetWidth()

virtual int GCText::GetWidth ( ) const
inlinevirtual

Definition at line 62 of file GCText.h.

62{ return m_size.GetWidth(); }

◆ SetFont()

void GCText::SetFont ( wxFont  font)
virtual

Definition at line 121 of file GCText.cpp.

122{
123 m_font = font;
124 m_customFont = true;
125}

◆ SetFontSize()

virtual void GCText::SetFontSize ( int  fontSize)
inlinevirtual

Definition at line 64 of file GCText.h.

64{ m_fontSize = fontSize; }

◆ SetText()

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.SetFaceName(wxT("CMU Serif"));
73 //m_font.SetPointSize(m_fontSize);
74 m_font = wxFont(m_fontSize,
75 wxFONTFAMILY_DEFAULT,
76 wxFONTSTYLE_NORMAL,
77 wxFONTWEIGHT_NORMAL,
78 false,
79 wxT("Arial"));
80 }
81
82 //wxFont font = wxFont(m_fontSize, m_fontFamily, m_fontStyle, m_fontWeight);
83 //wxBitmap bmp(1, 1);
84 //wxMemoryDC mdc(bmp);
85 //
86 //wxGraphicsContext* gc = wxGraphicsContext::Create(mdc);
87 //
88 //gc->SetFont(m_font, *wxBLACK);
89 //
90 //wxDouble w, h, descent, extLead;
91 //gc->GetTextExtent(text, &w, &h, &descent, &extLead);
92 //
93 //delete gc;
94 //
95 //m_size = wxSize((int)w, (int)h);
96
97 wxScreenDC dc;
98 dc.SetFont(m_font);
99 m_size = dc.GetTextExtent(m_text);
100
101 //m_size = CalculateTextExtend();
102
103
104 //wxMemoryDC memDC;
106 //
107 //wxGraphicsContext* gc = wxGraphicsContext::Create(memDC);
108 //if (gc) {
109 // gc->SetFont(m_font, *wxBLACK);
110 // double width, height, descent, externalLeading;
111 // gc->GetTextExtent(m_text, &width, &height, &descent, &externalLeading);
112 // m_size = wxSize(std::ceil(width + descent), std::ceil(height + externalLeading));
113 // delete gc;
114 //}
115 //else {
116 // memDC.SetFont(m_font);
117 // m_size = memDC.GetTextExtent(m_text);
118 //}
119}
Here is the caller graph for this function:

Member Data Documentation

◆ m_customFont

bool GCText::m_customFont = false
protected

Definition at line 81 of file GCText.h.

◆ m_font

wxFont GCText::m_font
protected

Definition at line 80 of file GCText.h.

◆ m_fontSize

int GCText::m_fontSize = 10
protected

Definition at line 76 of file GCText.h.

◆ m_size

wxSize GCText::m_size
protected

Definition at line 83 of file GCText.h.

◆ m_text

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

Definition at line 75 of file GCText.h.


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