KiCad PCB EDA Suite
Loading...
Searching...
No Matches
zoom_menu.cpp
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) 2015 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <tool/zoom_menu.h>
23#include <id.h>
24#include <eda_draw_frame.h>
26#include <tool/actions.h>
28#include <bitmaps.h>
29#include <functional>
30
31using namespace std::placeholders;
32
34 ACTION_MENU( true ),
35 m_parent( aParent )
36{
39}
40
41
42OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
43{
44 OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
45 event->SetParameter<int>( aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START );
46 return event;
47}
48
49
51{
52 SetTitle( _( "Zoom" ) );
53}
54
55
57{
58 Clear();
59
60 int ii = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
61
62 for( double factor : m_parent->config()->m_Window.zoom_factors )
63 Append( ii++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
64
65 double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor();
66
67 const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
68
69 for( size_t jj = 0; jj < zoomList.size(); ++jj )
70 {
71 // Search for a value near the current zoom setting:
72 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
73
74 // IDs start with 1 (leaving 0 for auto-zoom)
75 Check( ID_POPUP_ZOOM_LEVEL_START + jj + 1, rel_error < 0.1 );
76 }
77}
static TOOL_ACTION zoomPreset
Definition actions.h:141
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
Default constructor.
void Clear()
Remove all the entries from the menu (as well as its title).
void SetTitle(const wxString &aTitle) override
Set title for the menu.
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
The base class for create windows for drawing purpose.
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition zoom_menu.cpp:42
void UpdateTitle() override
Used by some menus to just-in-time translate their titles.
Definition zoom_menu.cpp:50
EDA_DRAW_FRAME * m_parent
Definition zoom_menu.h:45
ZOOM_MENU(EDA_DRAW_FRAME *aParent)
Definition zoom_menu.cpp:33
void update() override
Update menu state stub.
Definition zoom_menu.cpp:56
#define _(s)
@ ID_POPUP_ZOOM_LEVEL_START
Definition id.h:124
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition tool_event.h:637