Skip to content

Commit 64e433b

Browse files
authored
Issue #692: CalChart Windows Field Thumbnails Appear Incorrectly (#698)
1 parent a8e6303 commit 64e433b

3 files changed

Lines changed: 64 additions & 64 deletions

File tree

LATEST_RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Bugs addressed in this release:
44

55
* [#673](../../issues/673) Omniview doesn't look right
66
* [#690](../../issues/690) ASAN crash when you close a show with X and then reopen
7+
* [#692](../../issues/692) CalChart Windows Field Thumbnails Appear Incorrectly
78
* [#702](../../issues/702) libcurl is not found on windows
89
* [#704](../../issues/704) Reset All in Settings doesn't seem to be working
910

src/FieldThumbnailBrowser.cpp

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -42,56 +42,13 @@ constexpr auto kYUpperPadding = 4;
4242
constexpr auto kYNamePadding = 4;
4343
constexpr auto kYBottomPadding = 4;
4444
constexpr 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

11669
auto 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)
251253
void 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();

src/FieldThumbnailBrowser.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ class FieldThumbnailBrowser : public wxScrolledWindow {
3636
CalChart::Configuration const& config,
3737
wxWindow* parent,
3838
wxWindowID id = wxID_ANY,
39-
const wxPoint& pos = wxDefaultPosition,
40-
const wxSize& size = wxDefaultSize,
41-
long style = wxScrolledWindowStyle,
42-
const wxString& name = wxPanelNameStr);
43-
virtual ~FieldThumbnailBrowser() override = default;
39+
wxPoint const& pos = wxDefaultPosition,
40+
wxSize const& size = wxDefaultSize);
41+
~FieldThumbnailBrowser() override = default;
4442

4543
void OnUpdate(); // Refresh from the View
4644
void SetView(CalChartView* view) { mView = view; }
@@ -52,9 +50,8 @@ class FieldThumbnailBrowser : public wxScrolledWindow {
5250
void HandleMouseDown(wxMouseEvent& event);
5351
void HandleSizeEvent(wxSizeEvent& event);
5452

55-
wxSize SizeOfOneCell() const;
56-
wxSize SizeOfOneCell(bool horizontal) const;
57-
int WhichCell(wxPoint const& p) const;
53+
auto SizeOfOneCell(bool horizontal) const -> wxSize;
54+
auto WhichCell(wxPoint const& p) const -> int;
5855

5956
CalChartView* mView{};
6057

0 commit comments

Comments
 (0)