136 :
137 wxWindow(parent, id), m_guiColour(guiColour), m_iconElement(std::move(iconElement)), m_buttonScale(buttonScale)
138{
139 SetBackgroundColour(m_guiColour->background);
140 m_buttonFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
141
142 m_label = label;
143
144
145 wxScreenDC dc;
146 dc.SetFont(m_buttonFont);
147
148 wxSize textSize = dc.GetTextExtent(label);
149
150 m_imageSize = wxSize(static_cast<int>(m_iconElement->GetWidth()), static_cast<int>(m_iconElement->GetHeight())) * m_buttonScale;
151
152 int buttonWidth = 0;
153 if (textSize.GetWidth() > m_imageSize.GetWidth()) {
154 buttonWidth = textSize.GetWidth();
155 m_imagePosition = wxPoint((buttonWidth - m_imageSize.GetWidth()) / 2 + m_borderSize, m_borderSize);
156 m_labelPosition = wxPoint(m_borderSize, m_imageSize.GetHeight() + m_borderSize);
157 }
158 else {
159 buttonWidth = m_imageSize.GetWidth();
160 m_imagePosition = wxPoint(m_borderSize, m_borderSize);
161 m_labelPosition =
162 wxPoint((buttonWidth - textSize.GetWidth()) / 2 + m_borderSize, m_imageSize.GetHeight() + m_borderSize);
163 }
164 m_buttonSize =
165 wxSize(buttonWidth + 2 * m_borderSize, textSize.GetHeight() + m_imageSize.GetHeight() + 2 * m_borderSize);
166 SetMinSize(m_buttonSize + wxSize(m_borderSize, m_borderSize));
167
168 m_iconElement->StartMove(m_iconElement->GetPosition());
169 m_iconElement->Move(wxPoint2DDouble(m_buttonSize.GetWidth() / 2.0, (m_buttonSize.GetHeight() - textSize.GetHeight()) / 2.0));
170
171
172 Bind(wxEVT_PAINT, &ControlElementButton::OnPaint, this);
173 Bind(wxEVT_ENTER_WINDOW, &ControlElementButton::OnMouseEnter, this);
174 Bind(wxEVT_LEAVE_WINDOW, &ControlElementButton::OnMouseLeave, this);
175 Bind(wxEVT_LEFT_DOWN, &ControlElementButton::OnLeftClickDown, this);
176 Bind(wxEVT_LEFT_UP, &ControlElementButton::OnLeftClickUp, this);
177}