Power System Platform  2026w11a-beta
Loading...
Searching...
No Matches
ControlElementButton Class Reference

This class is responsible to handle the user interaction with control elements. More...

#include <ControlEditor.h>

Inheritance diagram for ControlElementButton:
Collaboration diagram for ControlElementButton:

Public Member Functions

 ControlElementButton (wxWindow *parent, wxString label, wxImage image, wxWindowID id=wxID_ANY)
 

Protected Member Functions

virtual void OnPaint (wxPaintEvent &event)
 
virtual void OnMouseEnter (wxMouseEvent &event)
 
virtual void OnMouseLeave (wxMouseEvent &event)
 
virtual void OnLeftClickDown (wxMouseEvent &event)
 
virtual void OnLeftClickUp (wxMouseEvent &event)
 

Protected Attributes

wxString m_label
 
wxFont m_font
 
wxPoint m_labelPosition
 
wxImage m_image
 
wxSize m_imageSize
 
wxPoint m_imagePosition
 
int m_borderSize = 2
 
bool m_mouseAbove = false
 
bool m_selected = false
 
wxSize m_buttonSize
 

Detailed Description

This class is responsible to handle the user interaction with control elements.

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

Definition at line 81 of file ControlEditor.h.

Constructor & Destructor Documentation

◆ ControlElementButton()

ControlElementButton::ControlElementButton ( wxWindow *  parent,
wxString  label,
wxImage  image,
wxWindowID  id = wxID_ANY 
)

Definition at line 46 of file ControlEditor.cpp.

47 : wxWindow(parent, id)
48{
49 SetBackgroundColour(*wxWHITE);
50 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
51 m_label = label;
52 m_image = image;
53 m_imageSize = wxSize(image.GetWidth(), image.GetHeight());
54
55 // Calculate label size.
56 wxScreenDC dc;
57 dc.SetFont(m_font);
58 wxSize textSize = dc.GetTextExtent(label);
59
60 int buttonWidth = 0;
61 if (textSize.GetWidth() > m_imageSize.GetWidth()) {
62 buttonWidth = textSize.GetWidth();
63 m_imagePosition = wxPoint((buttonWidth - m_imageSize.GetWidth()) / 2 + m_borderSize, m_borderSize);
64 m_labelPosition = wxPoint(m_borderSize, m_imageSize.GetHeight() + m_borderSize);
65 }
66 else {
67 buttonWidth = m_imageSize.GetWidth();
68 m_imagePosition = wxPoint(m_borderSize, m_borderSize);
69 m_labelPosition =
70 wxPoint((buttonWidth - textSize.GetWidth()) / 2 + m_borderSize, m_imageSize.GetHeight() + m_borderSize);
71 }
72 m_buttonSize =
73 wxSize(buttonWidth + 2 * m_borderSize, textSize.GetHeight() + m_imageSize.GetHeight() + 2 * m_borderSize);
74 SetMinSize(m_buttonSize + wxSize(m_borderSize, m_borderSize));
75
76 // Events.
77 Bind(wxEVT_PAINT, &ControlElementButton::OnPaint, this);
78 Bind(wxEVT_ENTER_WINDOW, &ControlElementButton::OnMouseEnter, this);
79 Bind(wxEVT_LEAVE_WINDOW, &ControlElementButton::OnMouseLeave, this);
80 Bind(wxEVT_LEFT_DOWN, &ControlElementButton::OnLeftClickDown, this);
81 Bind(wxEVT_LEFT_UP, &ControlElementButton::OnLeftClickUp, this);
82}

◆ ~ControlElementButton()

ControlElementButton::~ControlElementButton ( )

Definition at line 84 of file ControlEditor.cpp.

84{}

Member Function Documentation

◆ OnLeftClickDown()

void ControlElementButton::OnLeftClickDown ( wxMouseEvent &  event)
protectedvirtual

Definition at line 123 of file ControlEditor.cpp.

124{
125 m_selected = true;
126 Refresh();
127 event.Skip();
128}

◆ OnLeftClickUp()

void ControlElementButton::OnLeftClickUp ( wxMouseEvent &  event)
protectedvirtual

Definition at line 130 of file ControlEditor.cpp.

131{
132 m_selected = false;
133 Refresh();
134 event.Skip();
135}

◆ OnMouseEnter()

void ControlElementButton::OnMouseEnter ( wxMouseEvent &  event)
protectedvirtual

Definition at line 109 of file ControlEditor.cpp.

110{
111 m_mouseAbove = true;
112 Refresh();
113 event.Skip();
114}

◆ OnMouseLeave()

void ControlElementButton::OnMouseLeave ( wxMouseEvent &  event)
protectedvirtual

Definition at line 116 of file ControlEditor.cpp.

117{
118 m_mouseAbove = false;
119 Refresh();
120 event.Skip();
121}

◆ OnPaint()

void ControlElementButton::OnPaint ( wxPaintEvent &  event)
protectedvirtual

Definition at line 85 of file ControlEditor.cpp.

86{
87 wxPaintDC dc(this);
88 wxGraphicsContext* gc = wxGraphicsContext::Create(dc);
89 if (gc) {
90 if (m_mouseAbove) {
91 if (m_selected) {
92 gc->SetPen(wxPen(wxColour(0, 125, 255, 255), m_borderSize - 1));
93 gc->SetBrush(wxBrush(wxColour(0, 125, 255, 100)));
94 }
95 else {
96 gc->SetPen(*wxTRANSPARENT_PEN);
97 gc->SetBrush(wxBrush(wxColour(0, 125, 255, 70)));
98 }
99 gc->DrawRectangle(m_borderSize / 2, m_borderSize / 2, m_buttonSize.GetWidth(), m_buttonSize.GetHeight());
100 }
101 gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), m_imagePosition.x, m_imagePosition.y, m_imageSize.GetWidth(),
102 m_imageSize.GetHeight());
103 gc->SetFont(m_font, *wxBLACK);
104 gc->DrawText(m_label, m_labelPosition.x, m_labelPosition.y);
105 delete gc;
106 }
107}

Member Data Documentation

◆ m_borderSize

int ControlElementButton::m_borderSize = 2
protected

Definition at line 102 of file ControlEditor.h.

◆ m_buttonSize

wxSize ControlElementButton::m_buttonSize
protected

Definition at line 106 of file ControlEditor.h.

◆ m_font

wxFont ControlElementButton::m_font
protected

Definition at line 95 of file ControlEditor.h.

◆ m_image

wxImage ControlElementButton::m_image
protected

Definition at line 98 of file ControlEditor.h.

◆ m_imagePosition

wxPoint ControlElementButton::m_imagePosition
protected

Definition at line 100 of file ControlEditor.h.

◆ m_imageSize

wxSize ControlElementButton::m_imageSize
protected

Definition at line 99 of file ControlEditor.h.

◆ m_label

wxString ControlElementButton::m_label
protected

Definition at line 94 of file ControlEditor.h.

◆ m_labelPosition

wxPoint ControlElementButton::m_labelPosition
protected

Definition at line 96 of file ControlEditor.h.

◆ m_mouseAbove

bool ControlElementButton::m_mouseAbove = false
protected

Definition at line 103 of file ControlEditor.h.

◆ m_selected

bool ControlElementButton::m_selected = false
protected

Definition at line 104 of file ControlEditor.h.


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