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
84 void ShowFieldError( const wxString& aFieldId );
85
86protected:
95 template <typename T>
96 DRC_RE_OVERLAY_FIELD* AddControl( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition, T* aControl );
97
107 template <typename T>
108 DRC_RE_OVERLAY_FIELD* AddField( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition,
109 long aStyle = 0 );
110
121 template <typename T>
122 DRC_RE_OVERLAY_FIELD* AddFieldWithUnits( const wxString& aId,
123 const DRC_RE_FIELD_POSITION& aPosition,
124 UNIT_BINDER* aUnitBinder,
125 long aStyle = 0 );
126
135 DRC_RE_OVERLAY_FIELD* AddCheckbox( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition );
136
140 void LoadBitmap();
141
145 void PositionFields();
146
152 void SetupFieldStyling( wxControl* aControl );
153
154private:
155 void OnPaint( wxPaintEvent& aEvent );
156 void OnDPIChanged( wxDPIChangedEvent& aEvent );
157 void OnThemeChange( wxSysColourChangedEvent& aEvent );
158 void OnFieldFocus( wxFocusEvent& aEvent );
159 void OnFieldBlur( wxFocusEvent& aEvent );
160
166 void PositionLabel( DRC_RE_OVERLAY_FIELD* aField );
167
174
175protected:
176 wxBitmap m_bitmap;
179 std::vector<std::unique_ptr<DRC_RE_OVERLAY_FIELD>> m_fields;
180 std::map<wxString, DRC_RE_OVERLAY_FIELD*> m_fieldIdMap;
181};
182
183
184template <typename T>
186 const DRC_RE_FIELD_POSITION& aPosition, T* aControl )
187{
188 // Create the overlay field wrapper
189 auto field = std::make_unique<DRC_RE_OVERLAY_FIELD>( this, aId, aControl, aPosition );
190 DRC_RE_OVERLAY_FIELD* fieldPtr = field.get();
191
192 // Set up styling
193 SetupFieldStyling( aControl );
194
195 // Position the field (yCenter is vertical mid-point of the control)
196 int height = aControl->GetBestSize().GetHeight();
197 int width = aPosition.xEnd - aPosition.xStart;
198 wxPoint pos( aPosition.xStart, aPosition.yCenter - ( height + 1 ) / 2 );
199 wxSize size( width, height );
200 aControl->SetPosition( pos );
201 aControl->SetSize( size );
202
203 // Create labels if specified
204 fieldPtr->CreateLabels();
205
206 if( fieldPtr->HasLabel() )
207 PositionLabel( fieldPtr );
208
209 if( fieldPtr->HasPrefixLabel() )
210 PositionPrefixLabel( fieldPtr );
211
212 // Store in collections
213 m_fieldIdMap[aId] = fieldPtr;
214 m_fields.push_back( std::move( field ) );
215
216 return fieldPtr;
217}
218
219
220template <typename T>
222 const DRC_RE_FIELD_POSITION& aPosition, long aStyle )
223{
224 // Create the control
225 T* control = new T( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, aStyle );
226
227 return AddControl( aId, aPosition, control );
228}
229
230
231template <typename T>
233 const DRC_RE_FIELD_POSITION& aPosition,
234 UNIT_BINDER* aUnitBinder,
235 long aStyle )
236{
237 // Create the field using the base AddField method
238 DRC_RE_OVERLAY_FIELD* field = AddField<T>( aId, aPosition, aStyle );
239
240 // Associate the unit binder for value conversion
241 field->SetUnitBinder( aUnitBinder );
242
243 return field;
244}
245
246#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.
void ShowFieldError(const wxString &aFieldId)
Show an error indicator on the specified field.
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 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.