KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_bitmap_overlay_panel.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef DRC_RE_BITMAP_OVERLAY_PANEL_H
21#define DRC_RE_BITMAP_OVERLAY_PANEL_H
22
23#include <map>
24#include <memory>
25#include <vector>
26
27#include <wx/bitmap.h>
28#include <wx/panel.h>
29
30#include <bitmaps.h>
34
35class wxControl;
36class wxCheckBox;
37class wxPaintEvent;
38class wxDPIChangedEvent;
39class wxSysColourChangedEvent;
40class wxFocusEvent;
41class UNIT_BINDER;
42
43
56class DRC_RE_BITMAP_OVERLAY_PANEL : public wxPanel,
58{
59public:
60 DRC_RE_BITMAP_OVERLAY_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY );
61
63
69 void SetBackgroundBitmap( BITMAPS aBitmap );
70
71 bool TransferDataToWindow() override;
72 bool TransferDataFromWindow() override;
73
77 void ClearFieldErrors();
78
85 void ShowFieldError( const wxString& aFieldId, const wxString& aMessage );
86
87protected:
96 template <typename T>
97 DRC_RE_OVERLAY_FIELD* AddControl( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition, T* aControl );
98
108 template <typename T>
109 DRC_RE_OVERLAY_FIELD* AddField( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition,
110 long aStyle = 0 );
111
122 template <typename T>
123 DRC_RE_OVERLAY_FIELD* AddFieldWithUnits( const wxString& aId,
124 const DRC_RE_FIELD_POSITION& aPosition,
125 UNIT_BINDER* aUnitBinder,
126 long aStyle = 0 );
127
136 DRC_RE_OVERLAY_FIELD* AddCheckbox( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition );
137
141 void LoadBitmap();
142
146 void PositionFields();
147
153 void SetupFieldStyling( wxControl* aControl );
154
155private:
156 void OnPaint( wxPaintEvent& aEvent );
157 void OnDPIChanged( wxDPIChangedEvent& aEvent );
158 void OnThemeChange( wxSysColourChangedEvent& aEvent );
159 void OnFieldFocus( wxFocusEvent& aEvent );
160 void OnFieldBlur( wxFocusEvent& aEvent );
161
167 void PositionLabel( DRC_RE_OVERLAY_FIELD* aField );
168
175
176protected:
177 wxBitmap m_bitmap;
180 std::vector<std::unique_ptr<DRC_RE_OVERLAY_FIELD>> m_fields;
181 std::map<wxString, DRC_RE_OVERLAY_FIELD*> m_fieldIdMap;
182};
183
184
185template <typename T>
187 const DRC_RE_FIELD_POSITION& aPosition, T* aControl )
188{
189 // Create the overlay field wrapper
190 auto field = std::make_unique<DRC_RE_OVERLAY_FIELD>( this, aId, aControl, aPosition );
191 DRC_RE_OVERLAY_FIELD* fieldPtr = field.get();
192
193 // Set up styling
194 SetupFieldStyling( aControl );
195
196 if( !aPosition.tooltipText.IsEmpty() )
197 aControl->SetToolTip( aPosition.tooltipText );
198
199 // Position the field (yCenter is vertical mid-point of the control)
200 int height = aControl->GetBestSize().GetHeight();
201 int width = aPosition.xEnd - aPosition.xStart;
202 wxPoint pos( aPosition.xStart, aPosition.yCenter - ( height + 1 ) / 2 );
203 wxSize size( width, height );
204 aControl->SetPosition( pos );
205 aControl->SetSize( size );
206
207 // Create labels if specified
208 fieldPtr->CreateLabels();
209
210 if( fieldPtr->HasLabel() )
211 PositionLabel( fieldPtr );
212
213 if( fieldPtr->HasPrefixLabel() )
214 PositionPrefixLabel( fieldPtr );
215
216 // Store in collections
217 m_fieldIdMap[aId] = fieldPtr;
218 m_fields.push_back( std::move( field ) );
219
220 return fieldPtr;
221}
222
223
224template <typename T>
226 const DRC_RE_FIELD_POSITION& aPosition, long aStyle )
227{
228 // Create the control
229 T* control = new T( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, aStyle );
230
231 return AddControl( aId, aPosition, control );
232}
233
234
235template <typename T>
237 const DRC_RE_FIELD_POSITION& aPosition,
238 UNIT_BINDER* aUnitBinder,
239 long aStyle )
240{
241 // Create the field using the base AddField method
242 DRC_RE_OVERLAY_FIELD* field = AddField<T>( aId, aPosition, aStyle );
243
244 // Associate the unit binder for value conversion
245 field->SetUnitBinder( aUnitBinder );
246
247 return field;
248}
249
250#endif // DRC_RE_BITMAP_OVERLAY_PANEL_H
BITMAPS
A list of all bitmap identifiers.
DRC_RE_OVERLAY_FIELD * AddCheckbox(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition)
Create and position a checkbox control on the bitmap overlay.
void LoadBitmap()
Load the appropriate bitmap variant for the current theme and DPI.
void OnThemeChange(wxSysColourChangedEvent &aEvent)
wxBitmap m_bitmap
Current background bitmap.
DRC_RE_OVERLAY_FIELD * AddControl(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, T *aControl)
Position a control on the bitmap overlay.
void OnDPIChanged(wxDPIChangedEvent &aEvent)
void PositionLabel(DRC_RE_OVERLAY_FIELD *aField)
Position a label relative to its field control based on the label position setting.
DRC_RE_OVERLAY_FIELD * AddField(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, long aStyle=0)
Create and position a field control on the bitmap overlay.
void SetupFieldStyling(wxControl *aControl)
Apply transparent styling to a field control.
std::map< wxString, DRC_RE_OVERLAY_FIELD * > m_fieldIdMap
Field ID to field lookup.
void ShowFieldError(const wxString &aFieldId, const wxString &aMessage)
Show an error indicator on the specified field.
void SetBackgroundBitmap(BITMAPS aBitmap)
Set the background bitmap for this panel.
wxSize m_logicalBitmapSize
Bitmap size in logical pixels.
DRC_RE_BITMAP_OVERLAY_PANEL(wxWindow *aParent, wxWindowID aId=wxID_ANY)
void ClearFieldErrors()
Clear error indicators from all fields.
BITMAPS m_bitmapId
BITMAPS enum value.
void PositionFields()
Position all fields based on the current scale factor.
void OnFieldFocus(wxFocusEvent &aEvent)
DRC_RE_OVERLAY_FIELD * AddFieldWithUnits(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, UNIT_BINDER *aUnitBinder, long aStyle=0)
Create and position a field control with unit binding.
std::vector< std::unique_ptr< DRC_RE_OVERLAY_FIELD > > m_fields
All overlay fields.
void PositionPrefixLabel(DRC_RE_OVERLAY_FIELD *aField)
Position a prefix label to the left of its field control.
Wraps a wxControl positioned over a bitmap overlay panel.
void CreateLabels()
Create and associate labels with this field.
void SetUnitBinder(UNIT_BINDER *aBinder)
Associate a UNIT_BINDER for unit conversion.
Specifies the position and size of a field overlaid on a constraint bitmap.
int xEnd
Right edge X coordinate where the field ends.
int xStart
Left edge X coordinate where the field starts.
int yCenter
Vertical center Y coordinate of the field.
wxString tooltipText
Optional tooltip shown on the control.