Skip to content

Commit

Permalink
Issue #454: Centralize all Config usage to one place.
Browse files Browse the repository at this point in the history
Now at the point where we have only the View and the Doc use the global configuration.
And localizing the places where we AssignConfig.

Adding a way to debug the configuration.
  • Loading branch information
rmpowell77 committed Feb 2, 2024
1 parent e225fb5 commit 685d641
Show file tree
Hide file tree
Showing 63 changed files with 751 additions and 437 deletions.
2 changes: 1 addition & 1 deletion calchart_cmd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void PrintToPS(const char* show, bool landscape, bool cont, bool contsheet,
bold_font_str, ital_font_str, bold_ital_font_str } },
PageWidth, PageHeight, PageOffsetX, PageOffsetY, PaperLength, HeaderSize,
YardsSize, TextSize, DotRatio, NumRatio, PLineRatio, SLineRatio,
ContRatio, ShowMode::GetDefaultYardLines());
ContRatio, kDefaultYardLines);

std::set<size_t> picked;
for (auto i = 0; i < p->GetNumSheets(); ++i)
Expand Down
2 changes: 1 addition & 1 deletion resources-macos/calchart_core_tests/print_to_ps_test.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void PrintToPS(CalChart::Show const& show, CalChart::ShowMode const& mode, bool
bold_font_str, ital_font_str, bold_ital_font_str } },
PageWidth, PageHeight, PageOffsetX, PageOffsetY, PaperLength, HeaderSize,
YardsSize, TextSize, DotRatio, NumRatio, PLineRatio, SLineRatio,
ContRatio, CalChart::ShowMode::GetDefaultYardLines());
ContRatio, CalChart::kDefaultYardLines);

std::set<size_t> picked;
for (auto i = 0; i < show.GetNumSheets(); ++i)
Expand Down
21 changes: 5 additions & 16 deletions src/AnimationCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
Copyright (C) 1995-2012 Richard Michael Powell
Copyright (C) 1995-2024 Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,8 +38,9 @@ EVT_MOTION(AnimationCanvas::OnMouseMove)
EVT_PAINT(AnimationCanvas::OnPaint)
END_EVENT_TABLE()

AnimationCanvas::AnimationCanvas(wxWindow* parent, wxWindowID winid, wxPoint const& pos, wxSize const& size)
AnimationCanvas::AnimationCanvas(CalChartConfiguration const& config, wxWindow* parent, wxWindowID winid, wxPoint const& pos, wxSize const& size)
: super(parent, winid, pos, size, wxTAB_TRAVERSAL | wxNO_BORDER)
, mConfig(config)
{
SetBackgroundStyle(wxBG_STYLE_PAINT);
Init();
Expand All @@ -57,17 +58,6 @@ void AnimationCanvas::CreateControls()
wxUI::VSizer{}.attachTo(this);
}

bool AnimationCanvas::GetUseSprites() const
{
return CalChartConfiguration::GetGlobalConfig().Get_UseSprites();
}

void AnimationCanvas::SetUseSprites(bool useSprites)
{
CalChartConfiguration::GetGlobalConfig().Set_UseSprites(useSprites);
Refresh();
}

void AnimationCanvas::SetZoomOnMarchers(bool zoomOnMarchers)
{
mZoomOnMarchers = zoomOnMarchers;
Expand Down Expand Up @@ -125,17 +115,16 @@ void AnimationCanvas::OnPaint(wxPaintEvent&)
UpdateScaleAndOrigin();

wxBufferedPaintDC dc(this);
auto& config = CalChartConfiguration::GetGlobalConfig();

wxCalChart::setBackground(dc, config.Get_CalChartBrushAndPen(CalChart::Colors::FIELD));
wxCalChart::setBackground(dc, mConfig.Get_CalChartBrushAndPen(CalChart::Colors::FIELD));
dc.Clear();
dc.SetUserScale(mUserScale, mUserScale);
dc.SetDeviceOrigin(mUserOrigin.first, mUserOrigin.second);

// draw the box
if (mMouseDown) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
wxCalChart::setPen(dc, config.Get_CalChartBrushAndPen(CalChart::Colors::SHAPES));
wxCalChart::setPen(dc, mConfig.Get_CalChartBrushAndPen(CalChart::Colors::SHAPES));
dc.DrawRectangle(mMouseStart.x, mMouseStart.y, mMouseEnd.x - mMouseStart.x, mMouseEnd.y - mMouseStart.y);
}
// draw the view
Expand Down
8 changes: 4 additions & 4 deletions src/AnimationCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
Copyright (C) 1995-2012 Richard Michael Powell
Copyright (C) 1995-2024 Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -24,22 +24,21 @@
#include <wx/wx.h>

class AnimationView;
class CalChartConfiguration;

// holds an instance of animation for the reference to draw.
class AnimationCanvas : public wxPanel {
using super = wxPanel;
wxDECLARE_EVENT_TABLE();

public:
AnimationCanvas(wxWindow* parent, wxWindowID winid = wxID_ANY, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize);
AnimationCanvas(CalChartConfiguration const& config, wxWindow* parent, wxWindowID winid = wxID_ANY, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize);
~AnimationCanvas() override = default;

void OnUpdate(); // Refresh from the View
auto GetView() const { return mView; }
void SetView(AnimationView* view) { mView = view; }

bool GetUseSprites() const;
void SetUseSprites(bool useSprites);
auto GetZoomOnMarchers() const { return mZoomOnMarchers; }
void SetZoomOnMarchers(bool zoomOnMarchers);
auto GetStepsOutForMarchersZoom() const { return mStepsOutForMarcherZoom; }
Expand Down Expand Up @@ -71,4 +70,5 @@ class AnimationCanvas : public wxPanel {
bool mMouseDown{};
wxPoint mMouseStart{};
wxPoint mMouseEnd{};
CalChartConfiguration const& mConfig;
};
14 changes: 7 additions & 7 deletions src/AnimationPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
Copyright (C) 1995-2012 Richard Michael Powell
Copyright (C) 1995-2024 Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -49,15 +49,15 @@ EVT_COMMAND_SCROLL(CALCHART__anim_gotobeat, AnimationPanel::OnSlider_anim_gotobe
EVT_TIMER(CALCHART__anim_next_beat_timer, AnimationPanel::OnCmd_anim_next_beat_timer)
END_EVENT_TABLE()

AnimationPanel::AnimationPanel(wxWindow* parent, wxWindowID winid, wxPoint const& pos, wxSize const& size, long style, wxString const& name)
AnimationPanel::AnimationPanel(CalChartConfiguration& config, wxWindow* parent, wxWindowID winid, wxPoint const& pos, wxSize const& size, long style, wxString const& name)
: super(parent, winid, pos, size, style, name)
, mCanvas(new AnimationCanvas(this, wxID_ANY, wxDefaultPosition, wxSize(-1, GetAnimationCanvasMinY())))
, mOmniCanvas(new CCOmniviewCanvas(this, CalChartConfiguration::GetGlobalConfig()))
, mCanvas(new AnimationCanvas(config, this, wxID_ANY, wxDefaultPosition, wxSize(-1, GetAnimationCanvasMinY())))
, mOmniCanvas(new CCOmniviewCanvas(this, config))
, mTimer(new wxTimer(this, CALCHART__anim_next_beat_timer))
, mTempo(120)
, mTimerOn(false)
, mInMiniMode(true)

, mConfig(config)
{
Init();
CreateControls();
Expand Down Expand Up @@ -99,7 +99,7 @@ void AnimationPanel::CreateControls()
wxUI::VSizer{
mSpritesCheckbox = wxUI::CheckBox{ "Sprites" }
.bind([this](wxCommandEvent& event) {
mCanvas->SetUseSprites(event.IsChecked());
mConfig.Set_UseSprites(event.IsChecked());
}),
mZoomCheckbox = wxUI::CheckBox{ "Zoom" }
.bind([this](wxCommandEvent& event) {
Expand Down Expand Up @@ -286,7 +286,7 @@ void AnimationPanel::SetView(CalChartView* view)
mView = nullptr;
return;
}
mView = new AnimationView(view, this);
mView = new AnimationView(view, mConfig, this);
mView->SetDocument(view->GetDocument());
// at this point the document is manging the view.
mView->SetFrame(this);
Expand Down
6 changes: 4 additions & 2 deletions src/AnimationPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
Copyright (C) 1995-2012 Richard Michael Powell
Copyright (C) 1995-2024 Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,6 +33,7 @@ class wxStaticText;
class wxSpinCtrl;
class wxButton;
class CCOmniviewCanvas;
class CalChartConfiguration;

// Animiation Panel is a little bit different because it has it's own view.
// When we are animating a show we are taking an CalChart animation object
Expand All @@ -44,7 +45,7 @@ class AnimationPanel : public wxPanel {
wxDECLARE_EVENT_TABLE();

public:
AnimationPanel(wxWindow* parent, wxWindowID winid = wxID_ANY, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = wxTAB_TRAVERSAL | wxNO_BORDER, wxString const& name = wxPanelNameStr);
AnimationPanel(CalChartConfiguration& config, wxWindow* parent, wxWindowID winid = wxID_ANY, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = wxTAB_TRAVERSAL | wxNO_BORDER, wxString const& name = wxPanelNameStr);
~AnimationPanel() override;

void OnUpdate(); // Refresh from the View
Expand Down Expand Up @@ -96,4 +97,5 @@ class AnimationPanel : public wxPanel {
bool mInMiniMode{};
bool mShowOmni{};
std::vector<wxWindow*> mItemsToHide;
CalChartConfiguration& mConfig;
};
10 changes: 5 additions & 5 deletions src/AnimationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
Copyright (C) 1995-2011 Garrick Brian Meeker, Richard Michael Powell
Copyright (C) 1995-2024 Garrick Brian Meeker, Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -40,8 +40,9 @@
#include <wx/filename.h>
#include <wx/stdpaths.h>

AnimationView::AnimationView(CalChartView* view, wxWindow* frame)
AnimationView::AnimationView(CalChartView* view, CalChartConfiguration const& config, wxWindow* frame)
: mView(view)
, mConfig(config)
{
SetFrame(frame);

Expand Down Expand Up @@ -74,8 +75,7 @@ AnimationView::~AnimationView()

void AnimationView::OnDraw(wxDC* dc)
{
auto& config = CalChartConfiguration::GetGlobalConfig();
OnDraw(*dc, config);
OnDraw(*dc, mConfig);
}

void AnimationView::OnDraw(wxDC& dc, CalChartConfiguration const& config)
Expand Down Expand Up @@ -187,7 +187,7 @@ void AnimationView::OnUpdate(wxView* sender, wxObject* hint)

void AnimationView::RefreshFrame()
{
if (mPlayCollisionWarning && mAnimation && mAnimation->CurrentBeatHasCollision() && CalChartConfiguration::GetGlobalConfig().Get_BeepOnCollisions()) {
if (mPlayCollisionWarning && mAnimation && mAnimation->CurrentBeatHasCollision() && mConfig.Get_BeepOnCollisions()) {
wxBell();
}
GetAnimationFrame()->UpdatePanel();
Expand Down
5 changes: 3 additions & 2 deletions src/AnimationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
Copyright (C) 1995-2011 Garrick Brian Meeker, Richard Michael Powell
Copyright (C) 1995-2024 Garrick Brian Meeker, Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -43,7 +43,7 @@ class AnimationView : public wxView {
using super = wxView;

public:
AnimationView(CalChartView* view, wxWindow* frame);
AnimationView(CalChartView* view, CalChartConfiguration const& config, wxWindow* frame);
~AnimationView() override;

void OnDraw(wxDC* dc) override;
Expand Down Expand Up @@ -100,6 +100,7 @@ class AnimationView : public wxView {

// Yes, this view has a view...
CalChartView* mView{};
CalChartConfiguration const& mConfig;

std::unique_ptr<CalChart::Animation> mAnimation;
bool mDrawCollisionWarning = true;
Expand Down
68 changes: 34 additions & 34 deletions src/CCOmniviewCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
Copyright (C) 1995-2012 Richard Michael Powell
Copyright (C) 1995-2024 Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -566,10 +566,10 @@ void CCOmniView_GLContext::Draw3dMarcher(AnimationView::MarcherInfo const& info,
DrawTextureOnBox(points, 1, 1, m_textures[face]);
}

CCOmniviewCanvas::CCOmniviewCanvas(wxWindow* parent, CalChartConfiguration& config_, wxSize const& size)
: wxGLCanvas(parent, wxID_ANY, NULL, wxDefaultPosition, size, wxFULL_REPAINT_ON_RESIZE)
CCOmniviewCanvas::CCOmniviewCanvas(wxWindow* parent, CalChartConfiguration& config, wxSize const& size)
: wxGLCanvas(parent, wxID_ANY, NULL, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
, m_glContext(new CCOmniView_GLContext(this))
, config(config_)
, mConfig(config)
, mViewPoint(kStartingViewPoint)
, mViewAngle(kStartingViewAngle)
, mViewAngleZ(kStartingViewAngleZ)
Expand Down Expand Up @@ -767,55 +767,55 @@ void CCOmniviewCanvas::OnChar(wxKeyEvent& event)

case '4':
OnCmd_FollowMarcher(-1);
mViewPoint = ViewPoint{ config.Get_OmniViewPoint_X_4(),
config.Get_OmniViewPoint_Y_4(),
config.Get_OmniViewPoint_Z_4() };
mViewAngle = CalChart::Radian{ config.Get_OmniViewAngle_4() };
mViewAngleZ = CalChart::Radian{ config.Get_OmniViewAngle_Z_4() };
mViewPoint = ViewPoint{ mConfig.Get_OmniViewPoint_X_4(),
mConfig.Get_OmniViewPoint_Y_4(),
mConfig.Get_OmniViewPoint_Z_4() };
mViewAngle = CalChart::Radian{ mConfig.Get_OmniViewAngle_4() };
mViewAngleZ = CalChart::Radian{ mConfig.Get_OmniViewAngle_Z_4() };
break;
case '5':
mViewPoint = ViewPoint{ config.Get_OmniViewPoint_X_5(),
config.Get_OmniViewPoint_Y_5(),
config.Get_OmniViewPoint_Z_5() };
mViewAngle = CalChart::Radian{ config.Get_OmniViewAngle_5() };
mViewAngleZ = CalChart::Radian{ config.Get_OmniViewAngle_Z_5() };
mViewPoint = ViewPoint{ mConfig.Get_OmniViewPoint_X_5(),
mConfig.Get_OmniViewPoint_Y_5(),
mConfig.Get_OmniViewPoint_Z_5() };
mViewAngle = CalChart::Radian{ mConfig.Get_OmniViewAngle_5() };
mViewAngleZ = CalChart::Radian{ mConfig.Get_OmniViewAngle_Z_5() };
break;
case '6':
mViewPoint = ViewPoint{ config.Get_OmniViewPoint_X_6(),
config.Get_OmniViewPoint_Y_6(),
config.Get_OmniViewPoint_Z_6() };
mViewAngle = CalChart::Radian{ config.Get_OmniViewAngle_6() };
mViewAngleZ = CalChart::Radian{ config.Get_OmniViewAngle_Z_6() };
mViewPoint = ViewPoint{ mConfig.Get_OmniViewPoint_X_6(),
mConfig.Get_OmniViewPoint_Y_6(),
mConfig.Get_OmniViewPoint_Z_6() };
mViewAngle = CalChart::Radian{ mConfig.Get_OmniViewAngle_6() };
mViewAngleZ = CalChart::Radian{ mConfig.Get_OmniViewAngle_Z_6() };
break;

case '$':
OnCmd_FollowMarcher(-1);
if (wxMessageBox(wxT("Set Custom Viewpoint 4?"), wxT("Custom Viewpoint"), wxYES_NO) == wxYES) {
config.Set_OmniViewPoint_X_4(mViewPoint.x);
config.Set_OmniViewPoint_Y_4(mViewPoint.y);
config.Set_OmniViewPoint_Z_4(mViewPoint.z);
config.Set_OmniViewAngle_4(mViewAngle.getValue());
config.Set_OmniViewAngle_Z_4(mViewAngleZ.getValue());
mConfig.Set_OmniViewPoint_X_4(mViewPoint.x);
mConfig.Set_OmniViewPoint_Y_4(mViewPoint.y);
mConfig.Set_OmniViewPoint_Z_4(mViewPoint.z);
mConfig.Set_OmniViewAngle_4(mViewAngle.getValue());
mConfig.Set_OmniViewAngle_Z_4(mViewAngleZ.getValue());
}
break;
case '%':
OnCmd_FollowMarcher(-1);
if (wxMessageBox(wxT("Set Custom Viewpoint 5?"), wxT("Custom Viewpoint"), wxYES_NO) == wxYES) {
config.Set_OmniViewPoint_X_5(mViewPoint.x);
config.Set_OmniViewPoint_Y_5(mViewPoint.y);
config.Set_OmniViewPoint_Z_5(mViewPoint.z);
config.Set_OmniViewAngle_5(mViewAngle.getValue());
config.Set_OmniViewAngle_Z_5(mViewAngleZ.getValue());
mConfig.Set_OmniViewPoint_X_5(mViewPoint.x);
mConfig.Set_OmniViewPoint_Y_5(mViewPoint.y);
mConfig.Set_OmniViewPoint_Z_5(mViewPoint.z);
mConfig.Set_OmniViewAngle_5(mViewAngle.getValue());
mConfig.Set_OmniViewAngle_Z_5(mViewAngleZ.getValue());
}
break;
case '^':
OnCmd_FollowMarcher(-1);
if (wxMessageBox(wxT("Set Custom Viewpoint 6?"), wxT("Custom Viewpoint"), wxYES_NO) == wxYES) {
config.Set_OmniViewPoint_X_6(mViewPoint.x);
config.Set_OmniViewPoint_Y_6(mViewPoint.y);
config.Set_OmniViewPoint_Z_6(mViewPoint.z);
config.Set_OmniViewAngle_6(mViewAngle.getValue());
config.Set_OmniViewAngle_Z_6(mViewAngleZ.getValue());
mConfig.Set_OmniViewPoint_X_6(mViewPoint.x);
mConfig.Set_OmniViewPoint_Y_6(mViewPoint.y);
mConfig.Set_OmniViewPoint_Z_6(mViewPoint.z);
mConfig.Set_OmniViewAngle_6(mViewAngle.getValue());
mConfig.Set_OmniViewAngle_Z_6(mViewAngleZ.getValue());
}
break;

Expand Down
4 changes: 2 additions & 2 deletions src/CCOmniviewCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
Copyright (C) 1995-2012 Richard Michael Powell
Copyright (C) 1995-2024 Richard Michael Powell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -66,7 +66,7 @@ class CCOmniviewCanvas : public wxGLCanvas {

std::shared_ptr<CCOmniView_GLContext> m_glContext;
AnimationView* mView{};
CalChartConfiguration& config;
CalChartConfiguration& mConfig;

ViewPoint mViewPoint{};

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ add_executable(
ColorSetupCanvas.h
ColorSetupDialog.cpp
ColorSetupDialog.h
ConfigurationDebugDialog.cpp
ConfigurationDebugDialog.h
ContinuityBoxDrawer.cpp
ContinuityBoxDrawer.h
ContinuityBrowser.cpp
Expand Down
Loading

0 comments on commit 685d641

Please sign in to comment.