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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef DRC_RE_BITMAP_OVERLAY_PANEL_H
25#define DRC_RE_BITMAP_OVERLAY_PANEL_H
26
27#include <map>
28#include <memory>
29#include <vector>
30
31#include <wx/bitmap.h>
32#include <wx/panel.h>
33
34#include <bitmaps.h>
38
39class wxControl;
40class wxCheckBox;
41class wxPaintEvent;
42class wxDPIChangedEvent;
43class wxSysColourChangedEvent;
44class wxFocusEvent;
45class UNIT_BINDER;
46
47
60class DRC_RE_BITMAP_OVERLAY_PANEL : public wxPanel,
62{
63public:
64 DRC_RE_BITMAP_OVERLAY_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY );
65
67
73 void SetBackgroundBitmap( BITMAPS aBitmap );
74
75 bool TransferDataToWindow() override;
76 bool TransferDataFromWindow() override;
77
81 void ClearFieldErrors();
82
88 void ShowFieldError( const wxString& aFieldId );
89
90protected:
100 template <typename T>
101 DRC_RE_OVERLAY_FIELD* AddField( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition,
102 long aStyle = 0 );
103
114 template <typename T>
115 DRC_RE_OVERLAY_FIELD* AddFieldWithUnits( const wxString& aId,
116 const DRC_RE_FIELD_POSITION& aPosition,
117 UNIT_BINDER* aUnitBinder,
118 long aStyle = 0 );
119
127 DRC_RE_OVERLAY_FIELD* AddCheckbox( const wxString& aId, const DRC_RE_FIELD_POSITION& aPosition );
128
132 void LoadBitmap();
133
137 void PositionFields();
138
144 void SetupFieldStyling( wxControl* aControl );
145
146private:
147 void OnPaint( wxPaintEvent& aEvent );
148 void OnDPIChanged( wxDPIChangedEvent& aEvent );
149 void OnThemeChange( wxSysColourChangedEvent& aEvent );
150 void OnFieldFocus( wxFocusEvent& aEvent );
151 void OnFieldBlur( wxFocusEvent& aEvent );
152
158 void PositionLabel( DRC_RE_OVERLAY_FIELD* aField );
159
160 wxBitmap m_bitmap;
163 std::vector<std::unique_ptr<DRC_RE_OVERLAY_FIELD>> m_fields;
164 std::map<wxString, DRC_RE_OVERLAY_FIELD*> m_fieldIdMap;
165};
166
167
168template <typename T>
170 const DRC_RE_FIELD_POSITION& aPosition,
171 long aStyle )
172{
173 // Create the control
174 T* control = new T( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, aStyle );
175
176 // Create the overlay field wrapper
177 auto field = std::make_unique<DRC_RE_OVERLAY_FIELD>( this, aId, control, aPosition );
178 DRC_RE_OVERLAY_FIELD* fieldPtr = field.get();
179
180 // Set up styling
181 SetupFieldStyling( control );
182
183 // Position the field
184 wxPoint pos( aPosition.xStart, aPosition.yTop );
185 int width = aPosition.xEnd - aPosition.xStart;
186 wxSize size( width, control->GetBestSize().GetHeight() );
187 control->SetPosition( pos );
188 control->SetSize( size );
189
190 // Create label if specified
191 fieldPtr->CreateLabel();
192
193 if( fieldPtr->HasLabel() )
194 PositionLabel( fieldPtr );
195
196 // Store in collections
197 m_fieldIdMap[aId] = fieldPtr;
198 m_fields.push_back( std::move( field ) );
199
200 return fieldPtr;
201}
202
203
204template <typename T>
206 const DRC_RE_FIELD_POSITION& aPosition,
207 UNIT_BINDER* aUnitBinder,
208 long aStyle )
209{
210 // Create the field using the base AddField method
211 DRC_RE_OVERLAY_FIELD* field = AddField<T>( aId, aPosition, aStyle );
212
213 // Associate the unit binder for value conversion
214 field->SetUnitBinder( aUnitBinder );
215
216 return field;
217}
218
219#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.
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_baseBitmapSize
Bitmap size at 1x scale.
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.
Wraps a wxControl positioned over a bitmap overlay panel.
void CreateLabel()
Create and associate a label 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 yTop
Top edge Y coordinate of the field.