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

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

◆ ~ControlElementButton()

ControlElementButton::~ControlElementButton ( )

Definition at line 83 of file ControlEditor.cpp.

83{}

Member Function Documentation

◆ OnLeftClickDown()

void ControlElementButton::OnLeftClickDown ( wxMouseEvent &  event)
protectedvirtual

Definition at line 122 of file ControlEditor.cpp.

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

◆ OnLeftClickUp()

void ControlElementButton::OnLeftClickUp ( wxMouseEvent &  event)
protectedvirtual

Definition at line 129 of file ControlEditor.cpp.

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

◆ OnMouseEnter()

void ControlElementButton::OnMouseEnter ( wxMouseEvent &  event)
protectedvirtual

Definition at line 108 of file ControlEditor.cpp.

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

◆ OnMouseLeave()

void ControlElementButton::OnMouseLeave ( wxMouseEvent &  event)
protectedvirtual

Definition at line 115 of file ControlEditor.cpp.

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

◆ OnPaint()

void ControlElementButton::OnPaint ( wxPaintEvent &  event)
protectedvirtual

Definition at line 84 of file ControlEditor.cpp.

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

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: