@@ -42,56 +42,13 @@ constexpr auto kYUpperPadding = 4;
4242constexpr auto kYNamePadding = 4 ;
4343constexpr auto kYBottomPadding = 4 ;
4444constexpr auto kHighlightWidth = 5 ;
45- }
46-
47- BEGIN_EVENT_TABLE (FieldThumbnailBrowser, wxScrolledWindow)
48- EVT_PAINT (FieldThumbnailBrowser::OnPaint)
49- EVT_CHAR (FieldThumbnailBrowser::HandleKey)
50- EVT_LEFT_DOWN (FieldThumbnailBrowser::HandleMouseDown)
51- EVT_SIZE (FieldThumbnailBrowser::HandleSizeEvent)
52- END_EVENT_TABLE ()
5345
54- FieldThumbnailBrowser::FieldThumbnailBrowser (CalChart::Configuration const & config, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
55- : wxScrolledWindow(parent, id, pos, size, style, name)
56- , mXScrollPadding(wxSystemSettings::GetMetric(wxSYS_VSCROLL_X))
57- , mYNameSize(GetThumbnailFontSize())
58- , mYScrollPadding(wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y))
59- , mLayoutHorizontal{ true }
60- , mConfig (config)
46+ auto toAspectRatio (CalChart::Coord coord) -> double
6147{
62- SetBackgroundStyle (wxBG_STYLE_PAINT);
63- // now update the current screen
64- OnUpdate ();
48+ return coord.x / static_cast <double >(coord.y );
6549}
6650
67- // calculate the size of the panel depending on orientation
68- wxSize FieldThumbnailBrowser::SizeOfOneCell (bool horizontal) const
69- {
70- if (!mView ) {
71- return { 1 , 1 };
72- }
73-
74- auto mode_size = fDIP (mView ->GetShowFullSize ());
75- if (horizontal) {
76- auto current_size_y = GetSize ().y - kYUpperPadding - mYNameSize - kYNamePadding - kYBottomPadding - mYScrollPadding ;
77- auto box_size_x = mode_size.x * (current_size_y / double (mode_size.y ));
78- return { int (box_size_x) + kXLeftPadding + kXRightPadding , GetSize ().y };
79- }
80- auto current_size_x = GetSize ().x - kXLeftPadding - kXRightPadding - mXScrollPadding ;
81- auto box_size_y = mode_size.y * (current_size_x / double (mode_size.x ));
82- return { GetSize ().x , int (box_size_y) + kYUpperPadding + mYNameSize + kYNamePadding };
83- }
84-
85- // calculate which sheet the user clicked in
86- int FieldThumbnailBrowser::WhichCell (wxPoint const & p) const
87- {
88- auto size_of_one = SizeOfOneCell (mLayoutHorizontal );
89- return (mLayoutHorizontal ) ? p.x / size_of_one.x : p.y / size_of_one.y ;
90- }
91-
92- namespace {
93-
94- auto CalcUserScale (wxSize const & box_size, wxSize const & mode_size)
51+ auto CalcUserScale (wxSize box_size, CalChart::Coord mode_size)
9552{
9653 auto newX = static_cast <float >(box_size.x );
9754 auto newY = static_cast <float >(box_size.y );
@@ -100,17 +57,13 @@ auto CalcUserScale(wxSize const& box_size, wxSize const& mode_size)
10057
10158 auto showAspectRatio = showSizeX / showSizeY;
10259 auto newSizeRatio = newX / newY;
103- auto newvalue = 1.0 ;
10460 // always choose x when the new aspect ratio is smaller than the show.
10561 // This will keep the whole field on in the canvas
10662 if (newSizeRatio < showAspectRatio) {
107- newvalue = newX / ( float ) CalChart::CoordUnits2Int ( showSizeX) ;
63+ return newX / showSizeX;
10864 } else {
109- newvalue = newY / ( float ) CalChart::CoordUnits2Int ( showSizeY) ;
65+ return newY / showSizeY;
11066 }
111- auto userScale = newvalue * (CalChart::CoordUnits2Int (1 << 16 ) / 65536.0 );
112-
113- return userScale;
11467}
11568
11669auto LayoutSheetThumbnails (CalChartView const & view, CalChart::Configuration const & config, int YNameSize, CalChart::Coord thumbnail_offset, CalChart::Coord box_size, CalChart::Coord box_offset)
@@ -138,7 +91,56 @@ auto LayoutSheetThumbnails(CalChartView const& view, CalChart::Configuration con
13891 }
13992 + CalChart::Coord (kXLeftPadding , kYUpperPadding );
14093}
94+ }
95+
96+ BEGIN_EVENT_TABLE (FieldThumbnailBrowser, wxScrolledWindow)
97+ EVT_PAINT (FieldThumbnailBrowser::OnPaint)
98+ EVT_CHAR (FieldThumbnailBrowser::HandleKey)
99+ EVT_LEFT_DOWN (FieldThumbnailBrowser::HandleMouseDown)
100+ EVT_SIZE (FieldThumbnailBrowser::HandleSizeEvent)
101+ END_EVENT_TABLE ()
102+
103+ FieldThumbnailBrowser::FieldThumbnailBrowser (
104+ CalChart::Configuration const & config,
105+ wxWindow* parent,
106+ wxWindowID id,
107+ const wxPoint& pos,
108+ const wxSize& size)
109+ : wxScrolledWindow(parent, id, pos, size)
110+ , mXScrollPadding(wxSystemSettings::GetMetric(wxSYS_VSCROLL_X))
111+ , mYNameSize(GetThumbnailFontSize())
112+ , mYScrollPadding(wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y))
113+ , mLayoutHorizontal{ true }
114+ , mConfig (config)
115+ {
116+ SetBackgroundStyle (wxBG_STYLE_PAINT);
117+ // now update the current screen
118+ OnUpdate ();
119+ }
120+
121+ // calculate the size of the panel depending on orientation
122+ auto FieldThumbnailBrowser::SizeOfOneCell (bool horizontal) const -> wxSize
123+ {
124+ if (!mView ) {
125+ return { 1 , 1 };
126+ }
127+
128+ auto modeAspectRatio = toAspectRatio (mView ->GetShowFullSize ());
129+ if (horizontal) {
130+ auto current_size_y = GetSize ().y - kYUpperPadding - mYNameSize - kYNamePadding - kYBottomPadding - mYScrollPadding ;
131+ auto box_size_x = current_size_y * modeAspectRatio;
132+ return { static_cast <int >(box_size_x) + kXLeftPadding + kXRightPadding , GetSize ().y };
133+ }
134+ auto current_size_x = GetSize ().x - kXLeftPadding - kXRightPadding - mXScrollPadding ;
135+ auto box_size_y = current_size_x / modeAspectRatio;
136+ return { GetSize ().x , static_cast <int >(box_size_y) + kYUpperPadding + mYNameSize + kYNamePadding };
137+ }
141138
139+ // calculate which sheet the user clicked in
140+ auto FieldThumbnailBrowser::WhichCell (wxPoint const & p) const -> int
141+ {
142+ auto size_of_one = SizeOfOneCell (mLayoutHorizontal );
143+ return (mLayoutHorizontal ) ? p.x / size_of_one.x : p.y / size_of_one.y ;
142144}
143145
144146// Define the repainting behaviour
@@ -149,7 +151,7 @@ auto LayoutSheetThumbnails(CalChartView const& view, CalChart::Configuration con
149151// with a boundary of 4 above and below.
150152
151153// auto gFieldThumbnailMeasure = CalChart::MeasureDuration{ "FieldThumbnail" };
152- void FieldThumbnailBrowser::OnPaint (wxPaintEvent&)
154+ void FieldThumbnailBrowser::OnPaint ([[maybe_unused]] wxPaintEvent& event )
153155{
154156 // for profiling purposes
155157 // std::cout << gFieldThumbnailMeasure << "\n";
@@ -164,7 +166,7 @@ void FieldThumbnailBrowser::OnPaint(wxPaintEvent&)
164166 dc.Clear ();
165167
166168 // let's draw the boxes
167- auto mode_size = fDIP ( mView ->GetShowFullSize () );
169+ auto mode_size = mView ->GetShowFullSize ();
168170 auto current_size = GetSize () - wxSize (kXLeftPadding + kXRightPadding + mXScrollPadding , mYNameSize + kYNamePadding + kYUpperPadding + kYBottomPadding + mYScrollPadding );
169171 auto box_size = mLayoutHorizontal
170172 ? wxSize (mode_size.x * (current_size.y / static_cast <double >(mode_size.y )), current_size.y )
@@ -251,8 +253,8 @@ void FieldThumbnailBrowser::HandleMouseDown(wxMouseEvent& event)
251253void FieldThumbnailBrowser::HandleSizeEvent (wxSizeEvent& event)
252254{
253255 auto mode_size = mView ->GetShowFullSize ();
254- auto ratioMode = mode_size.y ? mode_size.x / float (mode_size.y ) : 0 ;
255- auto ratioSize = event.m_size .y ? event.m_size .x / float (event.m_size .y ) : 0 ;
256+ auto ratioMode = mode_size.y ? mode_size.x / static_cast < float > (mode_size.y ) : 0 ;
257+ auto ratioSize = event.m_size .y ? event.m_size .x / static_cast < float > (event.m_size .y ) : 0 ;
256258
257259 mLayoutHorizontal = ratioSize > ratioMode;
258260 OnUpdate ();
0 commit comments