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
160protected:
161 wxBitmap m_bitmap;
164 std::vector<std::unique_ptr<DRC_RE_OVERLAY_FIELD>> m_fields;
165 std::map<wxString, DRC_RE_OVERLAY_FIELD*> m_fieldIdMap;
166};
167
168
169template <typename T>
171 const DRC_RE_FIELD_POSITION& aPosition,
172 long aStyle )
173{
174 // Create the control
175 T* control = new T( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, aStyle );
176
177 // Create the overlay field wrapper
178 auto field = std::make_unique<DRC_RE_OVERLAY_FIELD>( this, aId, control, aPosition );
179 DRC_RE_OVERLAY_FIELD* fieldPtr = field.get();
180
181 // Set up styling
182 SetupFieldStyling( control );
183
184 // Position the field
185 wxPoint pos( aPosition.xStart, aPosition.yTop );
186 int width = aPosition.xEnd - aPosition.xStart + DRC_RE_OVERLAY_WE;
187 wxSize size( width, control->GetBestSize().GetHeight() );
188 control->SetPosition( pos );
189 control->SetSize( size );
190
191 // Create label if specified
192 fieldPtr->CreateLabel();
193
194 if( fieldPtr->HasLabel() )
195 PositionLabel( fieldPtr );
196
197 // Store in collections
198 m_fieldIdMap[aId] = fieldPtr;
199 m_fields.push_back( std::move( field ) );
200
201 return fieldPtr;
202}
203
204
205template <typename T>
207 const DRC_RE_FIELD_POSITION& aPosition,
208 UNIT_BINDER* aUnitBinder,
209 long aStyle )
210{
211 // Create the field using the base AddField method
212 DRC_RE_OVERLAY_FIELD* field = AddField<T>( aId, aPosition, aStyle );
213
214 // Associate the unit binder for value conversion
215 field->SetUnitBinder( aUnitBinder );
216
217 return field;
218}
219
220#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.
constexpr int DRC_RE_OVERLAY_WE
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.