diff --git a/build-macos/CalChart.xcodeproj/project.pbxproj b/build-macos/CalChart.xcodeproj/project.pbxproj index 0bd2448c..279248ea 100644 --- a/build-macos/CalChart.xcodeproj/project.pbxproj +++ b/build-macos/CalChart.xcodeproj/project.pbxproj @@ -966,6 +966,7 @@ E803363417EE27C500A58457 /* math_utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = math_utils.cpp; sourceTree = ""; }; E803363517EE27C500A58457 /* math_utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = math_utils.h; sourceTree = ""; }; E803364117EE2E5400A58457 /* parse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parse.h; sourceTree = ""; }; + E803A0C7193BA54900C5F2D5 /* draw_utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = draw_utils.h; sourceTree = ""; }; E807BD5C17ED71F50052A53F /* calchart_cmd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = calchart_cmd; sourceTree = BUILT_PRODUCTS_DIR; }; E807BD5E17ED71F60052A53F /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; E807BD6017ED71F60052A53F /* calchart_cmd.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = calchart_cmd.1; sourceTree = ""; }; @@ -1192,6 +1193,7 @@ C7AFA97A117A6DBA00CC53E2 /* contscan.l */, C7AFA97B117A6DBA00CC53E2 /* draw.cpp */, E884F3A217A631BB00831301 /* draw.h */, + E803A0C7193BA54900C5F2D5 /* draw_utils.h */, C7E047CA155F7B8900D8C71B /* field_canvas.cpp */, C7E047CB155F7B8A00D8C71B /* field_canvas.h */, C7E047CD155F892400D8C71B /* field_frame.cpp */, diff --git a/src/animation_canvas.cpp b/src/animation_canvas.cpp index d605cd11..ca818250 100644 --- a/src/animation_canvas.cpp +++ b/src/animation_canvas.cpp @@ -65,21 +65,22 @@ void AnimationCanvas::OnPaint(wxPaintEvent& event) { wxBufferedPaintDC dc(this); + auto& config = CalChartConfiguration::GetGlobalConfig(); - dc.SetBackground(GetCalChartBrush(COLOR_FIELD)); + dc.SetBackground(config.Get_CalChartBrushAndPen(COLOR_FIELD).first); dc.Clear(); dc.SetUserScale(mUserScale, mUserScale); dc.SetDeviceOrigin(mUserOriginX, 0); if (mMouseDown) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetCalChartPen(COLOR_SHAPES)); + dc.SetPen(config.Get_CalChartBrushAndPen(COLOR_SHAPES).second); dc.DrawRectangle(mMouseXStart, mMouseYStart, mMouseXEnd - mMouseXStart, mMouseYEnd - mMouseYStart); } if (mAnimationView) { - mAnimationView->OnDraw(&dc); + mAnimationView->OnDraw(&dc, config); } } diff --git a/src/animation_frame.cpp b/src/animation_frame.cpp index 9577e551..82cfda9b 100644 --- a/src/animation_frame.cpp +++ b/src/animation_frame.cpp @@ -72,13 +72,14 @@ EVT_SIZE(AnimationFrame::OnSize) END_EVENT_TABLE() -AnimationFrame::AnimationFrame(std::function onClose, wxDocument *doc, wxView *view, wxFrame *parent, const wxSize& size) : +AnimationFrame::AnimationFrame(std::function onClose, wxDocument *doc, CalChartConfiguration& config_, wxView *view, wxFrame *parent, const wxSize& size) : #if defined(BUILD_FOR_VIEWER) && (BUILD_FOR_VIEWER != 0) wxDocChildFrame(doc, view, parent, wxID_ANY, wxT("CalChart Viewer"), wxDefaultPosition, size), #else wxFrame(parent, wxID_ANY, wxT("CalChart Viewer"), wxDefaultPosition, size), #endif mAnimationView(), +config(config_), mCanvas(NULL), mOmniViewCanvas(NULL), mTimer(new wxTimer(this, CALCHART__anim_next_beat_timer)), @@ -131,19 +132,19 @@ mWhenClosed(onClose) mSplitter->SetWindowStyleFlag(mSplitter->GetWindowStyleFlag() | wxSP_LIVE_UPDATE); mSplitter->SetMinSize(wxSize(300, 400)); - mOmniViewCanvas = new CCOmniView_Canvas(&mAnimationView, mSplitter); + mOmniViewCanvas = new CCOmniView_Canvas(&mAnimationView, mSplitter, config); mCanvas = new AnimationCanvas(&mAnimationView, mSplitter); mSplitA = mOmniViewCanvas; mSplitB = mCanvas; - if (!GetConfiguration_AnimationFrameOmniAnimation()) + if (!config.Get_AnimationFrameOmniAnimation()) { std::swap(mSplitA, mSplitB); } mSplitter->Initialize(mSplitA); - if (GetConfiguration_AnimationFrameSplitScreen()) + if (config.Get_AnimationFrameSplitScreen()) { - if (GetConfiguration_AnimationFrameSplitVertical()) + if (config.Get_AnimationFrameSplitVertical()) { mSplitter->SplitVertically(mSplitA, mSplitB); } @@ -152,7 +153,7 @@ mWhenClosed(onClose) mSplitter->SplitHorizontally(mSplitA, mSplitB); } } - mSplitter->SetSashPosition(GetConfiguration_AnimationFrameSashPosition()); + mSplitter->SetSashPosition(config.Get_AnimationFrameSashPosition()); AddCoolToolBar(GetAnimationToolBar(), *this); @@ -251,8 +252,8 @@ AnimationFrame::OnSize(wxSizeEvent& event) // HACK: Prevent width and height from growing out of control int w = event.GetSize().GetWidth(); int h = event.GetSize().GetHeight(); - SetConfiguration_AnimationFrameWidth((w > 1200) ? 1200 : w); - SetConfiguration_AnimationFrameHeight((h > 700) ? 700 : h); + config.Set_AnimationFrameWidth((w > 1200) ? 1200 : w); + config.Set_AnimationFrameHeight((h > 700) ? 700 : h); super::OnSize(event); } @@ -278,7 +279,7 @@ AnimationFrame::OnCmdClose(wxCloseEvent& event) { if (mSplitter) { - SetConfiguration_AnimationFrameSashPosition(mSplitter->GetSashPosition()); + config.Set_AnimationFrameSashPosition(mSplitter->GetSashPosition()); } // we should inform the parent frame we are closing if (mWhenClosed) @@ -620,8 +621,8 @@ AnimationFrame::OnCmd_SplitViewHorizontal(wxCommandEvent& event) mSplitA->Show(true); mSplitB->Show(true); mSplitter->SplitHorizontally(mSplitA, mSplitB); - SetConfiguration_AnimationFrameSplitScreen(true); - SetConfiguration_AnimationFrameSplitVertical(false); + config.Set_AnimationFrameSplitScreen(true); + config.Set_AnimationFrameSplitVertical(false); } void @@ -634,8 +635,8 @@ AnimationFrame::OnCmd_SplitViewVertical(wxCommandEvent& event) mSplitA->Show(true); mSplitB->Show(true); mSplitter->SplitVertically(mSplitA, mSplitB); - SetConfiguration_AnimationFrameSplitScreen(true); - SetConfiguration_AnimationFrameSplitVertical(true); + config.Set_AnimationFrameSplitScreen(true); + config.Set_AnimationFrameSplitVertical(true); } void @@ -645,7 +646,7 @@ AnimationFrame::OnCmd_SplitViewUnsplit(wxCommandEvent& event) { mSplitter->Unsplit(); } - SetConfiguration_AnimationFrameSplitScreen(false); + config.Set_AnimationFrameSplitScreen(false); } void @@ -658,7 +659,7 @@ AnimationFrame::OnCmd_SwapAnimateAndOmni(wxCommandEvent& event) mSplitter->Unsplit(); } std::swap(mSplitA, mSplitB); - SetConfiguration_AnimationFrameOmniAnimation(!GetConfiguration_AnimationFrameOmniAnimation()); + config.Set_AnimationFrameOmniAnimation(!config.Get_AnimationFrameOmniAnimation()); if (mode == wxSPLIT_HORIZONTAL) { mSplitter->SplitHorizontally(mSplitA, mSplitB); diff --git a/src/animation_frame.h b/src/animation_frame.h index 30230ade..a6346b63 100644 --- a/src/animation_frame.h +++ b/src/animation_frame.h @@ -36,6 +36,7 @@ class AnimationCanvas; class CCOmniView_Canvas; class FancyTextWin; class wxSplitterWindow; +class CalChartConfiguration; #if defined(BUILD_FOR_VIEWER) && (BUILD_FOR_VIEWER != 0) typedef wxDocChildFrame AnimationFrameParent; @@ -48,7 +49,7 @@ class AnimationFrame : public AnimationFrameParent public: typedef AnimationFrameParent super; - AnimationFrame(std::function onClose, wxDocument *doc, wxView *view, wxFrame *parent, const wxSize& size); + AnimationFrame(std::function onClose, wxDocument *doc, CalChartConfiguration& config, wxView *view, wxFrame *parent, const wxSize& size); ~AnimationFrame(); void OnSize(wxSizeEvent& event); @@ -107,7 +108,8 @@ class AnimationFrame : public AnimationFrameParent void TransitionToNextSheet(); AnimationView mAnimationView; - // we really do need one of each. We can't do inheritance because they have different base classes + CalChartConfiguration& config; + // we really do need one of each. We can't do inheritance because they have different base classes AnimationCanvas *mCanvas; CCOmniView_Canvas *mOmniViewCanvas; wxSlider *mSheetSlider; diff --git a/src/animation_view.cpp b/src/animation_view.cpp index e9d6bdfc..d79c21fe 100644 --- a/src/animation_view.cpp +++ b/src/animation_view.cpp @@ -54,7 +54,15 @@ AnimationView::~AnimationView() void AnimationView::OnDraw(wxDC *dc) { - GetShow()->GetMode().DrawMode(*dc, ShowMode::kAnimation); + auto& config = CalChartConfiguration::GetGlobalConfig(); + OnDraw(dc, config); +} + +void +AnimationView::OnDraw(wxDC *dc, const CalChartConfiguration& config) +{ + dc->SetPen(config.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); + GetShow()->GetMode().DrawMode(*dc, config, ShowMode::kAnimation); const bool checkForCollision = mCollisionWarningType != COLLISION_RESPONSE_NONE; if (mAnimation) { @@ -65,13 +73,14 @@ AnimationView::OnDraw(wxDC *dc) if (checkForCollision && info.mCollision) { if (info.mCollision == COLLISION_WARNING) { - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_COLLISION_WARNING)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_COLLISION_WARNING)); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION_WARNING); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); } else if (info.mCollision == COLLISION_INTERSECT) { - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_COLLISION)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_COLLISION)); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); } - } else if (GetShow()->IsSelected(i)) { @@ -80,18 +89,27 @@ AnimationView::OnDraw(wxDC *dc) case ANIMDIR_SW: case ANIMDIR_W: case ANIMDIR_NW: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_HILIT_BACK)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_HILIT_BACK)); + { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_BACK); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); + } break; case ANIMDIR_SE: case ANIMDIR_E: case ANIMDIR_NE: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_HILIT_FRONT)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_HILIT_FRONT)); + { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_FRONT); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); + } break; default: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_HILIT_SIDE)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_HILIT_SIDE)); + { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_SIDE); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); + } } } else @@ -101,18 +119,27 @@ AnimationView::OnDraw(wxDC *dc) case ANIMDIR_SW: case ANIMDIR_W: case ANIMDIR_NW: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_BACK)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_BACK)); + { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_BACK); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); + } break; case ANIMDIR_SE: case ANIMDIR_E: case ANIMDIR_NE: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_FRONT)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_FRONT)); + { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_FRONT); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); + } break; default: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_SIDE)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_SIDE)); + { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_SIDE); + dc->SetBrush(brushAndPen.first); + dc->SetPen(brushAndPen.second); + } } } CC_coord position = info.mPosition; diff --git a/src/animation_view.h b/src/animation_view.h index 88d6053c..9c3078dc 100644 --- a/src/animation_view.h +++ b/src/animation_view.h @@ -31,6 +31,7 @@ class AnimationFrame; class FieldView; +class CalChartConfiguration; class AnimationView : public wxView { @@ -41,6 +42,7 @@ class AnimationView : public wxView // virtual bool OnCreate(wxDocument *doc, long flags); // virtual bool OnClose(bool deleteWindow = true); virtual void OnDraw(wxDC *dc); + void OnDraw(wxDC *dc, const CalChartConfiguration& config); virtual void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); void RefreshFrame(); diff --git a/src/calchartapp.cpp b/src/calchartapp.cpp index 449b41e5..0ccefc20 100644 --- a/src/calchartapp.cpp +++ b/src/calchartapp.cpp @@ -99,9 +99,6 @@ void CalChartApp::InitAppAsServer() { gPrintDialogData = new wxPrintDialogData(); mHelpController = std::unique_ptr(new wxHtmlHelpController()); - // setup the configuration. - ReadConfig(); - //// Create the main frame window wxFrame *frame = new TopFrame(mDocManager, (wxFrame *)NULL, _T("CalChart")); @@ -158,6 +155,8 @@ void CalChartApp::ProcessArguments() { void CalChartApp::ExitAppAsServer() { + // Flush out the other commands + CalChartConfiguration::GetGlobalConfig().FlushWriteQueue(); // Get the file history wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/FileHistory")); @@ -172,5 +171,12 @@ void CalChartApp::ExitAppAsServer() { mHelpController.reset(); } +std::unique_ptr +CalChartApp::GetMode(const wxString& which) +{ + return ShowMode::GetMode(which); +} + void CalChartApp::ExitAppAsClient() { -} \ No newline at end of file +} + diff --git a/src/calchartapp.h b/src/calchartapp.h index 7f33e1dc..d8f2cec5 100644 --- a/src/calchartapp.h +++ b/src/calchartapp.h @@ -45,7 +45,7 @@ class CalChartApp : public wxApp virtual void MacOpenFiles(const wxArrayString &fileNames); int OnExit(); - ShowModeList& GetModeList() { return mModeList; } + std::unique_ptr GetMode(const wxString& which); // the global help system: wxHtmlHelpController& GetGlobalHelpController(); @@ -60,8 +60,6 @@ class CalChartApp : public wxApp void ExitAppAsServer(); void ExitAppAsClient(); - ShowModeList mModeList; - wxDocManager* mDocManager; std::unique_ptr mHelpController; diff --git a/src/calchartdoc.cpp b/src/calchartdoc.cpp index 9471566b..966bc718 100644 --- a/src/calchartdoc.cpp +++ b/src/calchartdoc.cpp @@ -52,10 +52,10 @@ IMPLEMENT_DYNAMIC_CLASS(CalChartDoc, wxDocument); // Create a new show CalChartDoc::CalChartDoc() : mShow(CC_show::Create_CC_show()), -mMode(wxGetApp().GetModeList().front().get()), +mMode(wxGetApp().GetMode(kShowModeStrings[0])), mTimer(*this) { - mTimer.Start(GetConfiguration_AutosaveInterval()*1000); + mTimer.Start(CalChartConfiguration::GetGlobalConfig().Get_AutosaveInterval()*1000); } // When a file is opened, we first check to see if there is a temporary @@ -511,13 +511,13 @@ CalChartDoc::GetMode() const } void -CalChartDoc::SetMode(const ShowMode* m) +CalChartDoc::SetMode(std::unique_ptr m) { if (!m) { throw std::runtime_error("Cannot use NULL ShowMode"); } - mMode = m; + std::swap(mMode, m); UpdateAllViews(); } diff --git a/src/calchartdoc.h b/src/calchartdoc.h index a875ade9..84e4a4c5 100644 --- a/src/calchartdoc.h +++ b/src/calchartdoc.h @@ -159,7 +159,7 @@ class CalChartDoc : public wxDocument const SelectionList& GetSelectionList() const; const ShowMode& GetMode() const; - void SetMode(const ShowMode* m); + void SetMode(std::unique_ptr m); bool AlreadyHasPrintContinuity() const; @@ -193,7 +193,7 @@ class CalChartDoc : public wxDocument void RestoreSnapShot(const CC_show& snapshot); std::unique_ptr mShow; - const ShowMode* mMode; + std::unique_ptr mMode; AutoSaveTimer mTimer; }; diff --git a/src/cc_command.cpp b/src/cc_command.cpp index 6363c1c1..1ad3eb1a 100644 --- a/src/cc_command.cpp +++ b/src/cc_command.cpp @@ -86,10 +86,10 @@ SetModeCommand::~SetModeCommand() void SetModeCommand::DoAction() { - ShowMode *newmode = ShowModeList_Find(wxGetApp().GetModeList(), mMode); + auto newmode = wxGetApp().GetMode(mMode); if (newmode) { - mDoc.SetMode(newmode); + mDoc.SetMode(std::move(newmode)); } } diff --git a/src/cc_omniview_canvas.cpp b/src/cc_omniview_canvas.cpp index bbb1cae6..72fe6180 100644 --- a/src/cc_omniview_canvas.cpp +++ b/src/cc_omniview_canvas.cpp @@ -537,10 +537,11 @@ CCOmniView_GLContext::Draw3dMarcher(const MarcherInfo &info, const viewpoint_t & } -CCOmniView_Canvas::CCOmniView_Canvas(AnimationView *view, wxWindow *frame, const wxSize& size) : +CCOmniView_Canvas::CCOmniView_Canvas(AnimationView *view, wxWindow *frame, CalChartConfiguration& config_, const wxSize& size) : wxGLCanvas(frame, wxID_ANY, NULL, wxDefaultPosition, size, wxFULL_REPAINT_ON_RESIZE), m_glContext(new CCOmniView_GLContext(this)), mAnimationView(view), +config(config_), mViewPoint(KStartingViewPoint), mFollowMarcher(-1), mCrowdOn(false), @@ -552,7 +553,7 @@ mFOV(60), mShiftMoving(false) { #if defined(__APPLE__) && (__APPLE__) - m_glContext->UseForLines(mAnimationView->GetShow()->GetMode().GetOmniLinesImage()); + m_glContext->UseForLines(mAnimationView->GetShow()->GetMode().GetOmniLinesImage(config)); #endif } @@ -777,52 +778,52 @@ CCOmniView_Canvas::OnChar(wxKeyEvent& event) case '4': OnCmd_FollowMarcher(-1); - mViewPoint = viewpoint_t(GetConfiguration_OmniViewPoint_X_4(), GetConfiguration_OmniViewPoint_Y_4(), GetConfiguration_OmniViewPoint_Z_4()); - mViewAngle = GetConfiguration_OmniViewAngle_4(); - mViewAngleZ = GetConfiguration_OmniViewAngle_Z_4(); + mViewPoint = viewpoint_t(config.Get_OmniViewPoint_X_4(), config.Get_OmniViewPoint_Y_4(), config.Get_OmniViewPoint_Z_4()); + mViewAngle = config.Get_OmniViewAngle_4(); + mViewAngleZ = config.Get_OmniViewAngle_Z_4(); break; case '5': - mViewPoint = viewpoint_t(GetConfiguration_OmniViewPoint_X_5(), GetConfiguration_OmniViewPoint_Y_5(), GetConfiguration_OmniViewPoint_Z_5()); - mViewAngle = GetConfiguration_OmniViewAngle_5(); - mViewAngleZ = GetConfiguration_OmniViewAngle_Z_5(); + mViewPoint = viewpoint_t(config.Get_OmniViewPoint_X_5(), config.Get_OmniViewPoint_Y_5(), config.Get_OmniViewPoint_Z_5()); + mViewAngle = config.Get_OmniViewAngle_5(); + mViewAngleZ = config.Get_OmniViewAngle_Z_5(); break; case '6': - mViewPoint = viewpoint_t(GetConfiguration_OmniViewPoint_X_6(), GetConfiguration_OmniViewPoint_Y_6(), GetConfiguration_OmniViewPoint_Z_6()); - mViewAngle = GetConfiguration_OmniViewAngle_6(); - mViewAngleZ = GetConfiguration_OmniViewAngle_Z_6(); + mViewPoint = viewpoint_t(config.Get_OmniViewPoint_X_6(), config.Get_OmniViewPoint_Y_6(), config.Get_OmniViewPoint_Z_6()); + mViewAngle = config.Get_OmniViewAngle_6(); + mViewAngleZ = config.Get_OmniViewAngle_Z_6(); break; case '$': OnCmd_FollowMarcher(-1); if (wxMessageBox(wxT("Set Custom Viewpoint 4?"), wxT("Custom Viewpoint"), wxYES_NO) == wxYES) { - SetConfiguration_OmniViewPoint_X_4(mViewPoint.x); - SetConfiguration_OmniViewPoint_Y_4(mViewPoint.y); - SetConfiguration_OmniViewPoint_Z_4(mViewPoint.z); - SetConfiguration_OmniViewAngle_4(mViewAngle); - SetConfiguration_OmniViewAngle_Z_4(mViewAngleZ); + 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); + config.Set_OmniViewAngle_Z_4(mViewAngleZ); } break; case '%': OnCmd_FollowMarcher(-1); if (wxMessageBox(wxT("Set Custom Viewpoint 5?"), wxT("Custom Viewpoint"), wxYES_NO) == wxYES) { - SetConfiguration_OmniViewPoint_X_5(mViewPoint.x); - SetConfiguration_OmniViewPoint_Y_5(mViewPoint.y); - SetConfiguration_OmniViewPoint_Z_5(mViewPoint.z); - SetConfiguration_OmniViewAngle_5(mViewAngle); - SetConfiguration_OmniViewAngle_Z_5(mViewAngleZ); + 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); + config.Set_OmniViewAngle_Z_5(mViewAngleZ); } break; case '^': OnCmd_FollowMarcher(-1); if (wxMessageBox(wxT("Set Custom Viewpoint 6?"), wxT("Custom Viewpoint"), wxYES_NO) == wxYES) { - SetConfiguration_OmniViewPoint_X_6(mViewPoint.x); - SetConfiguration_OmniViewPoint_Y_6(mViewPoint.y); - SetConfiguration_OmniViewPoint_Z_6(mViewPoint.z); - SetConfiguration_OmniViewAngle_6(mViewAngle); - SetConfiguration_OmniViewAngle_Z_6(mViewAngleZ); + 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); + config.Set_OmniViewAngle_Z_6(mViewAngleZ); } break; diff --git a/src/cc_omniview_canvas.h b/src/cc_omniview_canvas.h index 0c15909a..775eeba6 100644 --- a/src/cc_omniview_canvas.h +++ b/src/cc_omniview_canvas.h @@ -31,6 +31,7 @@ class AnimationView; class CCOmniView_GLContext; +class CalChartConfiguration; struct viewpoint_t { @@ -49,7 +50,7 @@ struct MarcherInfo class CCOmniView_Canvas: public wxGLCanvas { public: - CCOmniView_Canvas(AnimationView *view, wxWindow *frame, const wxSize& size = wxDefaultSize); + CCOmniView_Canvas(AnimationView *view, wxWindow *frame, CalChartConfiguration& config, const wxSize& size = wxDefaultSize); ~CCOmniView_Canvas(); void SetView(AnimationView *view); @@ -72,6 +73,7 @@ class CCOmniView_Canvas: public wxGLCanvas std::shared_ptr m_glContext; AnimationView *mAnimationView; + CalChartConfiguration& config; viewpoint_t mViewPoint; // a -1 means not following any marcher diff --git a/src/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp index 9f6500ff..e9a61af4 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -21,7 +21,15 @@ */ #include "cc_preferences_ui.h" +#include "cc_drawcommand.h" #include "confgr.h" +#include "modes.h" +#include "draw.h" +#include "cc_sheet.h" +#include "basic_ui.h" +#include "calchartdoc.h" +#include "cc_shapes.h" + #include #include #include @@ -29,10 +37,12 @@ #include // how the preferences work: -// preference dialog will read system data on startup, cache a copy and then -// when the user presses apply, they will be written back to the system. +// preference dialog create a copy of the CalChart config from which to read and set values +// CalChart config doesn't automatically write values to main config, it must be flushed +// out when the user presses apply. // first page will be general settings: // Auto save behavior: file location, time +// second page is Drawing preferences for edit menu // Color preferences // second page is PS printing settings // 3rd page is Show mode setup @@ -46,24 +56,26 @@ static wxSizerFlags sBasicSizerFlags; static wxSizerFlags sLeftBasicSizerFlags; static wxSizerFlags sExpandSizerFlags; -static void AddTextboxWithCaption(wxWindow* parent, wxBoxSizer* verticalsizer, int id, const wxString& caption) +static void AddTextboxWithCaption(wxWindow* parent, wxBoxSizer* verticalsizer, int id, const wxString& caption, long style = 0) { wxBoxSizer* textsizer = new wxBoxSizer( wxVERTICAL ); textsizer->Add(new wxStaticText(parent, wxID_STATIC, caption, wxDefaultPosition, wxDefaultSize, 0), sLeftBasicSizerFlags); - textsizer->Add(new wxTextCtrl(parent, id), sBasicSizerFlags ); + textsizer->Add(new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, style), sBasicSizerFlags ); verticalsizer->Add(textsizer, sBasicSizerFlags); } -// the basic class panel we use for all the pages: +// the basic class panel we use for all the pages. +// Each page gets a references to the CalChartConfig which will be used for getting and setting class PreferencePage : public wxPanel { DECLARE_ABSTRACT_CLASS( GeneralSetup ) public: - PreferencePage() + PreferencePage(CalChartConfiguration& config) : + mConfig(config) { Init(); } - virtual ~PreferencePage( ) {} + virtual ~PreferencePage() {} virtual void Init() {} virtual bool Create(wxWindow *parent, wxWindowID id, @@ -81,20 +93,23 @@ class PreferencePage : public wxPanel return true; } - virtual void CreateControls() = 0; - // use these to get and set default values virtual bool TransferDataToWindow() = 0; virtual bool TransferDataFromWindow() = 0; virtual bool ClearValuesToDefault() = 0; +private: + virtual void CreateControls() = 0; + +protected: + CalChartConfiguration& mConfig; }; IMPLEMENT_ABSTRACT_CLASS( PreferencePage, wxPanel ) //////// General setup //////// -// handling autosave and colors +// handling autosave //////// class GeneralSetup : public PreferencePage @@ -103,12 +118,13 @@ class GeneralSetup : public PreferencePage DECLARE_EVENT_TABLE() public: - GeneralSetup( wxWindow *parent, + GeneralSetup( CalChartConfiguration& config, wxWindow *parent, wxWindowID id = wxID_ANY, const wxString& caption = wxT("General Setup"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) + long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) : + PreferencePage(config) { Init(); Create(parent, id, caption, pos, size, style); @@ -124,18 +140,7 @@ class GeneralSetup : public PreferencePage virtual bool ClearValuesToDefault(); private: - void OnCmdSelectColors(wxCommandEvent&); - void OnCmdSelectWidth(wxSpinEvent&); - void OnCmdResetColors(wxCommandEvent&); void OnCmdResetAll(wxCommandEvent&); - void OnCmdChooseNewColor(wxCommandEvent&); - - void SetColor(int selection, int width, const wxColour& color); - wxBitmapComboBox* nameBox; - wxSpinCtrl* spin; - - wxPen mCalChartPens[COLOR_NUM]; - wxBrush mCalChartBrushes[COLOR_NUM]; wxString mAutoSave_Interval; }; @@ -143,17 +148,10 @@ class GeneralSetup : public PreferencePage enum { AUTOSAVE_INTERVAL = 1000, - BUTTON_SELECT, - BUTTON_RESTORE, - SPIN_WIDTH, - NEW_COLOR_CHOICE }; + BEGIN_EVENT_TABLE(GeneralSetup, PreferencePage) -EVT_BUTTON(BUTTON_SELECT,GeneralSetup::OnCmdSelectColors) -EVT_BUTTON(BUTTON_RESTORE,GeneralSetup::OnCmdResetColors) -EVT_SPINCTRL(SPIN_WIDTH,GeneralSetup::OnCmdSelectWidth) -EVT_COMBOBOX(NEW_COLOR_CHOICE,GeneralSetup::OnCmdChooseNewColor) END_EVENT_TABLE() IMPLEMENT_CLASS( GeneralSetup, PreferencePage ) @@ -171,11 +169,254 @@ void GeneralSetup::CreateControls() AddTextboxWithCaption(this, sizer1, AUTOSAVE_INTERVAL, wxT("Autosave Interval")); - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); + TransferDataToWindow(); +} + +void GeneralSetup::Init() +{ + mAutoSave_Interval.Printf(wxT("%ld"), mConfig.Get_AutosaveInterval()); +} + +bool GeneralSetup::TransferDataToWindow() +{ + ((wxTextCtrl*) FindWindow(AUTOSAVE_INTERVAL))->SetValue(mAutoSave_Interval); + return true; +} + +bool GeneralSetup::TransferDataFromWindow() +{ + // read out the values from the window + mAutoSave_Interval = ((wxTextCtrl*) FindWindow(AUTOSAVE_INTERVAL))->GetValue(); + long val; + if (mAutoSave_Interval.ToLong(&val)) + { + mConfig.Set_AutosaveInterval(val); + } + return true; +} + +bool GeneralSetup::ClearValuesToDefault() +{ + mConfig.Clear_AutosaveInterval(); + Init(); + TransferDataToWindow(); + return true; +} + + +//////// Draw setup //////// +// handling Drawing colors +//////// + +class PrefCanvas : public ClickDragCtrlScrollCanvas +{ + DECLARE_EVENT_TABLE() + using super = ClickDragCtrlScrollCanvas; +public: + PrefCanvas(CalChartConfiguration& config, wxWindow *parent); + + void OnPaint(wxPaintEvent& event); +private: + void OnEraseBackground(wxEraseEvent& event); + + std::unique_ptr mShow; + std::unique_ptr mMode; + CalChartConfiguration& mConfig; + std::vector mPath; + CC_coord mPathEnd; + std::vector mShape; +}; + + + +BEGIN_EVENT_TABLE(PrefCanvas, ClickDragCtrlScrollCanvas) +EVT_PAINT(PrefCanvas::OnPaint) +EVT_ERASE_BACKGROUND(PrefCanvas::OnEraseBackground) +END_EVENT_TABLE() + +PrefCanvas::PrefCanvas(CalChartConfiguration& config, wxWindow *parent) : +super(parent, wxID_ANY, wxDefaultPosition, wxSize(640, 240)), +mMode(ShowModeStandard::CreateShowMode(wxT(""), CC_coord(Int2Coord(160), Int2Coord(84)), CC_coord(Int2Coord(80), Int2Coord(42)), CC_coord(Int2Coord(4), Int2Coord(4)), CC_coord(Int2Coord(4), Int2Coord(4)), Int2Coord(32), Int2Coord(52) )), +mConfig(config) +{ + auto field_offset = mMode->FieldOffset(); + auto offset = mMode->Offset(); + + // Create a fake show with some points and selections to draw an example for the user + mShow = CC_show::Create_CC_show(); + mShow->SetupNewShow(); + mShow->SetNumPoints(4, 4, field_offset); + mShow->SetPointLabel(std::vector{ + "unsel", + "unsel", + "sel", + "sel", + }); + CC_show::CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); + sheet->GetPoint(0).SetSymbol(SYMBOL_X); + sheet->GetPoint(1).SetSymbol(SYMBOL_SOLX); + sheet->GetPoint(2).SetSymbol(SYMBOL_X); + sheet->GetPoint(3).SetSymbol(SYMBOL_SOLX); + + for (auto i = 0; i < 4; ++i) + { + sheet->SetAllPositions(field_offset + CC_coord(Int2Coord(i*4), Int2Coord(2)), i); + sheet->SetPosition(field_offset + CC_coord(Int2Coord(i*4), Int2Coord(6)), i, 1); + } + + mShow->InsertSheet(*sheet, 1); + mShow->SetCurrentSheet(0); + sheet = mShow->GetCurrentSheet(); + ++sheet; + for (auto i = 0; i < 4; ++i) + { + sheet->SetAllPositions(field_offset + CC_coord(Int2Coord(18+i*4), Int2Coord(2+2)), i); + sheet->SetPosition(field_offset + CC_coord(Int2Coord(18+i*4), Int2Coord(2+6)), i, 1); + } + mShow->SetCurrentSheet(0); + + auto point_start = offset + field_offset + CC_coord(Int2Coord(4), Int2Coord(2)); + mPathEnd = point_start + CC_coord(Int2Coord(0), Int2Coord(2)); + mPath.push_back(CC_DrawCommand(point_start, mPathEnd)); + point_start = mPathEnd; + mPathEnd += CC_coord(Int2Coord(18), Int2Coord(0)); + mPath.push_back(CC_DrawCommand(point_start, mPathEnd)); + + auto shape_start = field_offset + CC_coord(Int2Coord(18), Int2Coord(-2)); + auto shape_end = shape_start + CC_coord(Int2Coord(4), Int2Coord(4)); + CC_shape_rect rect(shape_start, shape_end); + mShape = rect.GetCC_DrawCommand(offset.x, offset.y); +} + + +// Define the repainting behaviour +void +PrefCanvas::OnPaint(wxPaintEvent& event) +{ + wxBufferedPaintDC dc(this); + PrepareDC(dc); + + // draw the background + dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackground(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD).first); + dc.Clear(); + + // Draw the field + mMode->DrawMode(dc, mConfig, ShowMode::kFieldView); + + CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); + auto nextSheet = sheet; + ++nextSheet; + + SelectionList list; + list.insert(2); + list.insert(3); + + // draw the ghost sheet + DrawGhostSheet(dc, mConfig, mMode->Offset(), list, mShow->GetNumPoints(), mShow->GetPointLabels(), *nextSheet, 0); + + // Draw the points + DrawPoints(dc, mConfig, mMode->Offset(), list, mShow->GetNumPoints(), mShow->GetPointLabels(), *sheet, 0, true); + DrawPoints(dc, mConfig, mMode->Offset(), list, mShow->GetNumPoints(), mShow->GetPointLabels(), *sheet, 1, false); + + // draw the path + DrawPath(dc, mConfig, mPath, mPathEnd); + + // draw the shap + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.SetPen(mConfig.Get_CalChartBrushAndPen(COLOR_SHAPES).second); + DrawCC_DrawCommandList(dc, mShape); +} + +// We have a empty erase background to improve redraw performance. +void +PrefCanvas::OnEraseBackground(wxEraseEvent& event) +{ +} + + + +class DrawingSetup : public PreferencePage +{ + DECLARE_CLASS( DrawingSetup ) + DECLARE_EVENT_TABLE() + +public: + DrawingSetup( CalChartConfiguration& config, wxWindow *parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("General Setup"), + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) : + PreferencePage(config) + { + Init(); + Create(parent, id, caption, pos, size, style); + } + virtual ~DrawingSetup( ) {} + + virtual void Init(); + virtual void CreateControls(); + + // use these to get and set default values + virtual bool TransferDataToWindow(); + virtual bool TransferDataFromWindow(); + virtual bool ClearValuesToDefault(); + +private: + void OnCmdSelectColors(wxCommandEvent&); + void OnCmdSelectWidth(wxSpinEvent&); + void OnCmdResetColors(wxCommandEvent&); + void OnCmdResetAll(wxCommandEvent&); + void OnCmdChooseNewColor(wxCommandEvent&); + void OnCmdTextChanged(wxCommandEvent&); + + void SetColor(int selection, int width, const wxColour& color); + wxBitmapComboBox* nameBox; + wxSpinCtrl* spin; + + wxPen mCalChartPens[COLOR_NUM]; + wxBrush mCalChartBrushes[COLOR_NUM]; + + double mPrintValues[5]; +}; + +enum +{ + BUTTON_SELECT = 1000, + BUTTON_RESTORE, + SPIN_WIDTH, + NEW_COLOR_CHOICE, + DOTRATIO, + NUMRATIO, + PLINERATIO, + SLINERATIO +}; + + +BEGIN_EVENT_TABLE(DrawingSetup, PreferencePage) +EVT_BUTTON(BUTTON_SELECT,DrawingSetup::OnCmdSelectColors) +EVT_BUTTON(BUTTON_RESTORE,DrawingSetup::OnCmdResetColors) +EVT_SPINCTRL(SPIN_WIDTH,DrawingSetup::OnCmdSelectWidth) +EVT_COMBOBOX(NEW_COLOR_CHOICE,DrawingSetup::OnCmdChooseNewColor) +EVT_TEXT_ENTER(DOTRATIO,DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(NUMRATIO,DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(PLINERATIO,DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(SLINERATIO,DrawingSetup::OnCmdTextChanged) +END_EVENT_TABLE() + +IMPLEMENT_CLASS( DrawingSetup, PreferencePage ) + +void DrawingSetup::CreateControls() +{ + wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL); + SetSizer( topsizer ); + + wxStaticBoxSizer* boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); topsizer->Add(boxsizer); wxBoxSizer *horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); - nameBox = new wxBitmapComboBox(this, NEW_COLOR_CHOICE, ColorNames[0], wxDefaultPosition, wxDefaultSize, COLOR_NUM, ColorNames, wxCB_READONLY|wxCB_DROPDOWN); + nameBox = new wxBitmapComboBox(this, NEW_COLOR_CHOICE, mConfig.GetColorNames().at(0), wxDefaultPosition, wxDefaultSize, COLOR_NUM, mConfig.GetColorNames().data(), wxCB_READONLY|wxCB_DROPDOWN); horizontalsizer->Add(nameBox, sBasicSizerFlags ); for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i)+1)) @@ -183,7 +424,7 @@ void GeneralSetup::CreateControls() wxBitmap temp_bitmap(16, 16); wxMemoryDC temp_dc; temp_dc.SelectObject(temp_bitmap); - temp_dc.SetBackground(GetCalChartBrush(i)); + temp_dc.SetBackground(mConfig.Get_CalChartBrushAndPen(i).first); temp_dc.Clear(); nameBox->SetItemBitmap(i, temp_bitmap); } @@ -201,65 +442,90 @@ void GeneralSetup::CreateControls() boxsizer->Add(horizontalsizer, sBasicSizerFlags ); + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("ratios")), wxVERTICAL); + topsizer->Add(boxsizer); + + horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); + boxsizer->Add(horizontalsizer, sLeftBasicSizerFlags); + + AddTextboxWithCaption(this, horizontalsizer, DOTRATIO, wxT("Dot Ratio:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, NUMRATIO, wxT("Num Ratio:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, PLINERATIO, wxT("P-Line Ratio:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, SLINERATIO, wxT("S-Line Ratio:"), wxTE_PROCESS_ENTER); + + auto prefCanvas = new PrefCanvas(mConfig, this); + // set scroll rate 1 to 1, so we can have even scrolling of whole field + topsizer->Add(prefCanvas, 1, wxEXPAND); + // mCanvas->SetScrollRate(1, 1); + TransferDataToWindow(); } -void GeneralSetup::Init() +void DrawingSetup::Init() { // first read out the defaults: for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i)+1)) { - mCalChartPens[i] = GetCalChartPen(i); - mCalChartBrushes[i] = GetCalChartBrush(i); + auto brushAndPen = mConfig.Get_CalChartBrushAndPen(i); + mCalChartPens[i] = brushAndPen.second; + mCalChartBrushes[i] = brushAndPen.first; } - mAutoSave_Interval.Printf(wxT("%ld"), GetConfiguration_AutosaveInterval()); + mPrintValues[0] = mConfig.Get_DotRatio(); + mPrintValues[1] = mConfig.Get_NumRatio(); + mPrintValues[2] = mConfig.Get_PLineRatio(); + mPrintValues[3] = mConfig.Get_SLineRatio(); + mPrintValues[4] = mConfig.Get_ContRatio(); } -bool GeneralSetup::TransferDataToWindow() +bool DrawingSetup::TransferDataToWindow() { - wxTextCtrl* text = (wxTextCtrl*) FindWindow(AUTOSAVE_INTERVAL); - text->SetValue(mAutoSave_Interval); + wxString buf; + wxTextCtrl* text = (wxTextCtrl*) FindWindow(DOTRATIO); + buf.Printf(wxT("%.2f"), mPrintValues[0]); + text->SetValue(buf); + text = (wxTextCtrl*) FindWindow(NUMRATIO); + buf.Printf(wxT("%.2f"), mPrintValues[1]); + text->SetValue(buf); + text = (wxTextCtrl*) FindWindow(PLINERATIO); + buf.Printf(wxT("%.2f"), mPrintValues[2]); + text->SetValue(buf); + text = (wxTextCtrl*) FindWindow(SLINERATIO); + buf.Printf(wxT("%.2f"), mPrintValues[3]); + text->SetValue(buf); + return true; } -bool GeneralSetup::TransferDataFromWindow() +bool DrawingSetup::TransferDataFromWindow() { - // read out the values from the window - wxTextCtrl* text = (wxTextCtrl*) FindWindow(AUTOSAVE_INTERVAL); - mAutoSave_Interval = text->GetValue(); - // write out the values defaults: for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i)+1)) { - SetCalChartPen(i, mCalChartPens[i]); - SetCalChartBrush(i, mCalChartBrushes[i]); - SetConfigColor(i); + mConfig.Set_CalChartBrushAndPen(i, mCalChartBrushes[i], mCalChartPens[i]); } - long val; - mAutoSave_Interval.ToLong(&val); - SetConfiguration_AutosaveInterval(val); return true; } -bool GeneralSetup::ClearValuesToDefault() +bool DrawingSetup::ClearValuesToDefault() { for (int i = 0; i < COLOR_NUM; ++i) { - SetColor(i, DefaultPenWidth[i], DefaultColors[i]); - ClearConfigColor(i); + SetColor(i, mConfig.GetDefaultPenWidth()[i], mConfig.GetDefaultColors()[i]); + mConfig.Clear_ConfigColor(i); } - ClearConfiguration_AutosaveInterval(); Init(); TransferDataToWindow(); return true; } -void GeneralSetup::SetColor(int selection, int width, const wxColour& color) +void DrawingSetup::SetColor(int selection, int width, const wxColour& color) { mCalChartPens[selection] = *wxThePenList->FindOrCreatePen(color, width, wxSOLID); mCalChartBrushes[selection] = *wxTheBrushList->FindOrCreateBrush(color, wxSOLID); + mConfig.Set_CalChartBrushAndPen(static_cast(selection), mCalChartBrushes[selection], mCalChartPens[selection]); + // update the namebox list { wxBitmap test_bitmap(16, 16); @@ -269,9 +535,10 @@ void GeneralSetup::SetColor(int selection, int width, const wxColour& color) temp_dc.Clear(); nameBox->SetItemBitmap(selection, test_bitmap); } + Refresh(); } -void GeneralSetup::OnCmdSelectColors(wxCommandEvent&) +void DrawingSetup::OnCmdSelectColors(wxCommandEvent&) { int selection = nameBox->GetSelection(); wxColourData data; @@ -286,24 +553,53 @@ void GeneralSetup::OnCmdSelectColors(wxCommandEvent&) } } -void GeneralSetup::OnCmdSelectWidth(wxSpinEvent& e) +void DrawingSetup::OnCmdSelectWidth(wxSpinEvent& e) { int selection = nameBox->GetSelection(); SetColor(selection, e.GetPosition(), mCalChartPens[selection].GetColour()); } -void GeneralSetup::OnCmdResetColors(wxCommandEvent&) +void DrawingSetup::OnCmdResetColors(wxCommandEvent&) { int selection = nameBox->GetSelection(); - SetColor(selection, DefaultPenWidth[selection], DefaultColors[selection]); - ClearConfigColor(selection); + SetColor(selection, mConfig.GetDefaultPenWidth()[selection], mConfig.GetDefaultColors()[selection]); + mConfig.Clear_ConfigColor(selection); } -void GeneralSetup::OnCmdChooseNewColor(wxCommandEvent&) +void DrawingSetup::OnCmdChooseNewColor(wxCommandEvent&) { spin->SetValue(mCalChartPens[nameBox->GetSelection()].GetWidth()); } +void DrawingSetup::OnCmdTextChanged(wxCommandEvent& e) +{ + auto id = e.GetId(); + wxTextCtrl* text = (wxTextCtrl*) FindWindow(id); + double value; + if (text->GetValue().ToDouble(&value)) + { + switch (id - DOTRATIO) + { + case 0: + mConfig.Set_DotRatio(value); + break; + case 1: + mConfig.Set_NumRatio(value); + break; + case 2: + mConfig.Set_PLineRatio(value); + break; + case 3: + mConfig.Set_SLineRatio(value); + break; + case 4: + mConfig.Set_ContRatio(value); + break; + } + } + Refresh(); +} + //////// General setup //////// // setup pringing values and colors @@ -315,12 +611,13 @@ class PSPrintingSetUp : public PreferencePage DECLARE_EVENT_TABLE() public: - PSPrintingSetUp( wxWindow *parent, + PSPrintingSetUp( CalChartConfiguration& config, wxWindow *parent, wxWindowID id = wxID_ANY, const wxString& caption = wxT("Printing Values"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) + long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) : + PreferencePage(config) { Init(); Create(parent, id, caption, pos, size, style); @@ -353,10 +650,6 @@ typedef enum HEADERSIZE, YARDSSIZE, TEXTSIZE, - DOTRATIO, - NUMRATIO, - PLINERATIO, - SLINERATIO, CONTRATIO } PSPrintingSetUp_IDs; @@ -396,10 +689,6 @@ void PSPrintingSetUp::CreateControls() horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); topsizer->Add(horizontalsizer, sLeftBasicSizerFlags ); - AddTextboxWithCaption(this, horizontalsizer, DOTRATIO, wxT("Dot Ratio:")); - AddTextboxWithCaption(this, horizontalsizer, NUMRATIO, wxT("Num Ratio:")); - AddTextboxWithCaption(this, horizontalsizer, PLINERATIO, wxT("P-Line Ratio:")); - AddTextboxWithCaption(this, horizontalsizer, SLINERATIO, wxT("S-Line Ratio:")); AddTextboxWithCaption(this, horizontalsizer, CONTRATIO, wxT("Continuity Ratio:")); TransferDataToWindow(); @@ -407,21 +696,17 @@ void PSPrintingSetUp::CreateControls() void PSPrintingSetUp::Init() { - mFontNames[0] = GetConfiguration_HeadFont(); - mFontNames[1] = GetConfiguration_MainFont(); - mFontNames[2] = GetConfiguration_NumberFont(); - mFontNames[3] = GetConfiguration_ContFont(); - mFontNames[4] = GetConfiguration_BoldFont(); - mFontNames[5] = GetConfiguration_ItalFont(); - mFontNames[6] = GetConfiguration_BoldItalFont(); - mPrintValues[0] = GetConfiguration_HeaderSize(); - mPrintValues[1] = GetConfiguration_YardsSize(); - mPrintValues[2] = GetConfiguration_TextSize(); - mPrintValues[3] = GetConfiguration_DotRatio(); - mPrintValues[4] = GetConfiguration_NumRatio(); - mPrintValues[5] = GetConfiguration_PLineRatio(); - mPrintValues[6] = GetConfiguration_SLineRatio(); - mPrintValues[7] = GetConfiguration_ContRatio(); + mFontNames[0] = mConfig.Get_HeadFont(); + mFontNames[1] = mConfig.Get_MainFont(); + mFontNames[2] = mConfig.Get_NumberFont(); + mFontNames[3] = mConfig.Get_ContFont(); + mFontNames[4] = mConfig.Get_BoldFont(); + mFontNames[5] = mConfig.Get_ItalFont(); + mFontNames[6] = mConfig.Get_BoldItalFont(); + mPrintValues[0] = mConfig.Get_HeaderSize(); + mPrintValues[1] = mConfig.Get_YardsSize(); + mPrintValues[2] = mConfig.Get_TextSize(); + mPrintValues[7] = mConfig.Get_ContRatio(); } bool PSPrintingSetUp::TransferDataToWindow() @@ -450,18 +735,6 @@ bool PSPrintingSetUp::TransferDataToWindow() text = (wxTextCtrl*) FindWindow(TEXTSIZE); buf.Printf(wxT("%.2f"), mPrintValues[2]); text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(DOTRATIO); - buf.Printf(wxT("%.2f"), mPrintValues[3]); - text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(NUMRATIO); - buf.Printf(wxT("%.2f"), mPrintValues[4]); - text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(PLINERATIO); - buf.Printf(wxT("%.2f"), mPrintValues[5]); - text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(SLINERATIO); - buf.Printf(wxT("%.2f"), mPrintValues[6]); - text->SetValue(buf); text = (wxTextCtrl*) FindWindow(CONTRATIO); buf.Printf(wxT("%.2f"), mPrintValues[7]); text->SetValue(buf); @@ -491,53 +764,37 @@ bool PSPrintingSetUp::TransferDataFromWindow() text->GetValue().ToDouble(&mPrintValues[1]); text = (wxTextCtrl*) FindWindow(TEXTSIZE); text->GetValue().ToDouble(&mPrintValues[2]); - text = (wxTextCtrl*) FindWindow(DOTRATIO); - text->GetValue().ToDouble(&mPrintValues[3]); - text = (wxTextCtrl*) FindWindow(NUMRATIO); - text->GetValue().ToDouble(&mPrintValues[4]); - text = (wxTextCtrl*) FindWindow(PLINERATIO); - text->GetValue().ToDouble(&mPrintValues[5]); - text = (wxTextCtrl*) FindWindow(SLINERATIO); - text->GetValue().ToDouble(&mPrintValues[6]); text = (wxTextCtrl*) FindWindow(CONTRATIO); text->GetValue().ToDouble(&mPrintValues[7]); // write out the values defaults: - SetConfiguration_HeadFont(mFontNames[0]); - SetConfiguration_MainFont(mFontNames[1]); - SetConfiguration_NumberFont(mFontNames[2]); - SetConfiguration_ContFont(mFontNames[3]); - SetConfiguration_BoldFont(mFontNames[4]); - SetConfiguration_ItalFont(mFontNames[5]); - SetConfiguration_BoldItalFont(mFontNames[6]); - SetConfiguration_HeaderSize(mPrintValues[0]); - SetConfiguration_YardsSize(mPrintValues[1]); - SetConfiguration_TextSize(mPrintValues[2]); - SetConfiguration_DotRatio(mPrintValues[3]); - SetConfiguration_NumRatio(mPrintValues[4]); - SetConfiguration_PLineRatio(mPrintValues[5]); - SetConfiguration_SLineRatio(mPrintValues[6]); - SetConfiguration_ContRatio(mPrintValues[7]); + mConfig.Set_HeadFont(mFontNames[0]); + mConfig.Set_MainFont(mFontNames[1]); + mConfig.Set_NumberFont(mFontNames[2]); + mConfig.Set_ContFont(mFontNames[3]); + mConfig.Set_BoldFont(mFontNames[4]); + mConfig.Set_ItalFont(mFontNames[5]); + mConfig.Set_BoldItalFont(mFontNames[6]); + mConfig.Set_HeaderSize(mPrintValues[0]); + mConfig.Set_YardsSize(mPrintValues[1]); + mConfig.Set_TextSize(mPrintValues[2]); + mConfig.Set_ContRatio(mPrintValues[7]); return true; } bool PSPrintingSetUp::ClearValuesToDefault() { - ClearConfiguration_HeadFont(); - ClearConfiguration_MainFont(); - ClearConfiguration_NumberFont(); - ClearConfiguration_ContFont(); - ClearConfiguration_BoldFont(); - ClearConfiguration_ItalFont(); - ClearConfiguration_BoldItalFont(); - ClearConfiguration_HeaderSize(); - ClearConfiguration_YardsSize(); - ClearConfiguration_TextSize(); - ClearConfiguration_DotRatio(); - ClearConfiguration_NumRatio(); - ClearConfiguration_PLineRatio(); - ClearConfiguration_SLineRatio(); - ClearConfiguration_ContRatio(); + mConfig.Clear_HeadFont(); + mConfig.Clear_MainFont(); + mConfig.Clear_NumberFont(); + mConfig.Clear_ContFont(); + mConfig.Clear_BoldFont(); + mConfig.Clear_ItalFont(); + mConfig.Clear_BoldItalFont(); + mConfig.Clear_HeaderSize(); + mConfig.Clear_YardsSize(); + mConfig.Clear_TextSize(); + mConfig.Clear_ContRatio(); Init(); return TransferDataToWindow(); } @@ -553,12 +810,13 @@ class ShowModeSetup : public PreferencePage DECLARE_EVENT_TABLE() public: - ShowModeSetup( wxWindow *parent, + ShowModeSetup( CalChartConfiguration& config, wxWindow *parent, wxWindowID id = wxID_ANY, const wxString& caption = wxT("Setup Modes"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) + long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) : + PreferencePage(config) { Init(); Create(parent, id, caption, pos, size, style); @@ -575,8 +833,8 @@ class ShowModeSetup : public PreferencePage private: void OnCmdLineText(wxCommandEvent&); void OnCmdChoice(wxCommandEvent&); - long mShowModeValues[SHOWMODE_NUM][kShowModeValues]; - wxString mYardText[MAX_YARD_LINES]; + CalChartConfiguration::ShowModeInfo_t mShowModeValues[SHOWMODE_NUM]; + wxString mYardText[CalChartConfiguration::kYardTextValues]; int mWhichMode; int mWhichYardLine; }; @@ -639,7 +897,7 @@ void ShowModeSetup::CreateControls() wxBoxSizer* textsizer = new wxBoxSizer( wxHORIZONTAL ); sizer1->Add(textsizer, sBasicSizerFlags ); textsizer->Add(new wxStaticText(this, wxID_STATIC, wxT("Adjust yardline marker"), wxDefaultPosition, wxDefaultSize, 0), 0, wxALIGN_LEFT|wxALL, 5); - wxChoice* textchoice = new wxChoice(this, SHOW_LINE_MARKING, wxDefaultPosition, wxDefaultSize, MAX_YARD_LINES, yard_text_index); + wxChoice* textchoice = new wxChoice(this, SHOW_LINE_MARKING, wxDefaultPosition, wxDefaultSize, mConfig.Get_yard_text_index().size(), mConfig.Get_yard_text_index().data()); textchoice->SetSelection(0); textsizer->Add(textchoice); textsizer->Add(new wxTextCtrl(this, SHOW_LINE_VALUE), sBasicSizerFlags ); @@ -653,22 +911,22 @@ void ShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - GetConfigurationShowMode(i, mShowModeValues[i]); + mShowModeValues[i] = mConfig.Get_ShowModeInfo(static_cast(i)); } - for (size_t i = 0; i < MAX_YARD_LINES; ++i) + for (size_t i = 0; i < CalChartConfiguration::kYardTextValues; ++i) { - mYardText[i] = yard_text[i]; + mYardText[i] = mConfig.Get_yard_text(i); } } bool ShowModeSetup::TransferDataToWindow() { // standard show - for (size_t i = 0; i < kShowModeValues; ++i) + for (auto i = mShowModeValues[mWhichMode].begin(); i != mShowModeValues[mWhichMode].end(); ++i) { wxString buf; - wxTextCtrl* text = (wxTextCtrl*) FindWindow(WESTHASH + i); - buf.Printf(wxT("%ld"), mShowModeValues[mWhichMode][i]); + wxTextCtrl* text = (wxTextCtrl*) FindWindow(WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); + buf.Printf(wxT("%ld"), *i); text->SetValue(buf); } @@ -681,24 +939,26 @@ bool ShowModeSetup::TransferDataFromWindow() { // read out the values from the window // standard show - for (size_t i = 0; i < kShowModeValues; ++i) + for (auto i = mShowModeValues[mWhichMode].begin(); i != mShowModeValues[mWhichMode].end(); ++i) { long val; - wxTextCtrl* text = (wxTextCtrl*) FindWindow(WESTHASH + i); + wxTextCtrl* text = (wxTextCtrl*) FindWindow(WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); text->GetValue().ToLong(&val); - mShowModeValues[mWhichMode][i] = val; + *i = val; } // write out the values defaults: for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - SetConfigurationShowMode(i, mShowModeValues[i]); + mConfig.Set_ShowModeInfo(static_cast(i), mShowModeValues[i]); } - for (size_t i = 0; i < MAX_YARD_LINES; ++i) + // grab whatever's in the box + wxTextCtrl* text = (wxTextCtrl*) FindWindow(SHOW_LINE_VALUE); + mYardText[mWhichYardLine] = text->GetValue(); + for (size_t i = 0; i < CalChartConfiguration::kYardTextValues; ++i) { - yard_text[i] = mYardText[i]; + mConfig.Set_yard_text(i, mYardText[i]); } - SetConfigShowYardline(); return true; } @@ -707,9 +967,12 @@ bool ShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - ClearConfigurationShowMode(i); + mConfig.Clear_ShowModeInfo(static_cast(i)); + } + for (auto i = 0; i < CalChartConfiguration::kYardTextValues; ++i) + { + mConfig.Clear_yard_text(i); } - ClearConfigShowYardline(); Init(); return TransferDataToWindow(); } @@ -717,12 +980,12 @@ bool ShowModeSetup::ClearValuesToDefault() void ShowModeSetup::OnCmdChoice(wxCommandEvent&) { // save off all the old values: - for (size_t i = 0; i < kShowModeValues; ++i) + for (auto i = mShowModeValues[mWhichMode].begin(); i != mShowModeValues[mWhichMode].end(); ++i) { long val; - wxTextCtrl* text = (wxTextCtrl*) FindWindow(WESTHASH + i); + wxTextCtrl* text = (wxTextCtrl*) FindWindow(WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); text->GetValue().ToLong(&val); - mShowModeValues[mWhichMode][i] = val; + *i = val; } wxChoice* modes = (wxChoice*) FindWindow(MODE_CHOICE); mWhichMode = modes->GetSelection(); @@ -744,12 +1007,13 @@ class SpringShowModeSetup : public PreferencePage DECLARE_EVENT_TABLE() public: - SpringShowModeSetup( wxWindow *parent, + SpringShowModeSetup( CalChartConfiguration& config, wxWindow *parent, wxWindowID id = wxID_ANY, const wxString& caption = wxT("Setup Modes"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) + long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU ) : + PreferencePage(config) { Init(); Create(parent, id, caption, pos, size, style); @@ -765,8 +1029,8 @@ class SpringShowModeSetup : public PreferencePage virtual bool ClearValuesToDefault(); private: void OnCmdChoice(wxCommandEvent&); - long mSpringShowModeValues[SPRINGSHOWMODE_NUM][kSpringShowModeValues]; - wxString mYardText[MAX_SPR_LINES]; + CalChartConfiguration::SpringShowModeInfo_t mSpringShowModeValues[SPRINGSHOWMODE_NUM]; + wxString mYardText[CalChartConfiguration::kSprLineTextValues]; int mWhichMode; int mWhichYardLine; }; @@ -867,7 +1131,7 @@ void SpringShowModeSetup::CreateControls() wxBoxSizer* textsizer = new wxBoxSizer( wxHORIZONTAL ); sizer1->Add(textsizer, sBasicSizerFlags ); textsizer->Add(new wxStaticText(this, wxID_STATIC, wxT("Adjust yardline marker"), wxDefaultPosition, wxDefaultSize, 0), 0, wxALIGN_LEFT|wxALL, 5); - wxChoice* textchoice = new wxChoice(this, SPRING_SHOW_LINE_MARKING, wxDefaultPosition, wxDefaultSize, MAX_SPR_LINES, spr_line_text_index); + wxChoice* textchoice = new wxChoice(this, SPRING_SHOW_LINE_MARKING, wxDefaultPosition, wxDefaultSize, mConfig.Get_spr_line_text_index().size(), mConfig.Get_spr_line_text_index().data()); textchoice->SetSelection(0); textsizer->Add(textchoice); textsizer->Add(new wxTextCtrl(this, SPRING_SHOW_LINE_VALUE), sBasicSizerFlags ); @@ -881,11 +1145,11 @@ void SpringShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - GetConfigurationSpringShowMode(i, mSpringShowModeValues[i]); + mSpringShowModeValues[i] = mConfig.Get_SpringShowModeInfo(static_cast(i)); } - for (size_t i = 0; i < MAX_SPR_LINES; ++i) + for (size_t i = 0; i < CalChartConfiguration::kSprLineTextValues; ++i) { - mYardText[i] = spr_line_text[i]; + mYardText[i] = mConfig.Get_spr_line_text(i); } } @@ -897,16 +1161,16 @@ bool SpringShowModeSetup::TransferDataToWindow() wxCheckBox* checkbox = (wxCheckBox*) FindWindow(DISPLAY_YARDLINE_BELOW + i); checkbox->SetValue(mSpringShowModeValues[mWhichMode][0] & (1<SetValue(buf); } wxTextCtrl* text = (wxTextCtrl*) FindWindow(SPRING_SHOW_LINE_VALUE); - text->SetValue(spr_line_text[mWhichYardLine]); + text->SetValue(mConfig.Get_spr_line_text(mWhichYardLine)); return true; } @@ -922,25 +1186,26 @@ bool SpringShowModeSetup::TransferDataFromWindow() wxCheckBox* checkbox = (wxCheckBox*) FindWindow(DISPLAY_YARDLINE_BELOW + i); mSpringShowModeValues[mWhichMode][0] |= checkbox->IsChecked() ? (1<GetValue().ToLong(&val); - mSpringShowModeValues[mWhichMode][i] = val; + *i = val; } // write out the values defaults: for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - SetConfigurationSpringShowMode(modes->GetSelection(), mSpringShowModeValues[mWhichMode]); + mConfig.Set_SpringShowModeInfo(static_cast(modes->GetSelection()), mSpringShowModeValues[mWhichMode]); } - for (size_t i = 0; i < MAX_SPR_LINES; ++i) + wxTextCtrl* text = (wxTextCtrl*) FindWindow(SPRING_SHOW_LINE_VALUE); + mYardText[mWhichYardLine] = text->GetValue(); + for (size_t i = 0; i < CalChartConfiguration::kSprLineTextValues; ++i) { - spr_line_text[i] = mYardText[i]; + mConfig.Set_spr_line_text(i, mYardText[i]); } - SetConfigSpringShowYardline(); return true; } @@ -949,9 +1214,12 @@ bool SpringShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - ClearConfigurationSpringShowMode(i); + mConfig.Clear_SpringShowModeInfo(static_cast(i)); + } + for (auto i = 0; i < CalChartConfiguration::kSprLineTextValues; ++i) + { + mConfig.Clear_spr_line_text(i); } - ClearConfigSpringShowYardline(); Init(); return TransferDataToWindow(); } @@ -965,12 +1233,12 @@ void SpringShowModeSetup::OnCmdChoice(wxCommandEvent&) wxCheckBox* checkbox = (wxCheckBox*) FindWindow(DISPLAY_YARDLINE_BELOW + i); mSpringShowModeValues[mWhichMode][0] |= checkbox->IsChecked() ? (1<GetValue().ToLong(&val); - mSpringShowModeValues[mWhichMode][i] = val; + *i = val; } wxChoice* modes = (wxChoice*) FindWindow(SPRING_MODE_CHOICE); mWhichMode = modes->GetSelection(); @@ -999,7 +1267,9 @@ CalChartPreferences::CalChartPreferences( wxWindow *parent, const wxString& caption, const wxPoint& pos, const wxSize& size, - long style ) + long style ): +// make a copy of the config +mConfig(CalChartConfiguration::GetGlobalConfig()) { Init(); @@ -1043,13 +1313,15 @@ void CalChartPreferences::CreateControls() mNotebook = new wxNotebook(this, wxID_ANY); topsizer->Add(mNotebook, sBasicSizerFlags ); - wxPanel* window0 = new GeneralSetup(mNotebook, wxID_ANY); - mNotebook->AddPage(window0, wxT("General")); - wxPanel* window2 = new PSPrintingSetUp(mNotebook, wxID_ANY); + wxPanel* window0 = new DrawingSetup(mConfig, mNotebook, wxID_ANY); + mNotebook->AddPage(window0, wxT("Drawing")); + wxPanel* window1 = new GeneralSetup(mConfig, mNotebook, wxID_ANY); + mNotebook->AddPage(window1, wxT("General")); + wxPanel* window2 = new PSPrintingSetUp(mConfig, mNotebook, wxID_ANY); mNotebook->AddPage(window2, wxT("PS Printing")); - wxPanel* window3 = new ShowModeSetup(mNotebook, wxID_ANY); + wxPanel* window3 = new ShowModeSetup(mConfig, mNotebook, wxID_ANY); mNotebook->AddPage(window3, wxT("Show Mode Setup")); - wxPanel* window4 = new SpringShowModeSetup(mNotebook, wxID_ANY); + wxPanel* window4 = new SpringShowModeSetup(mConfig, mNotebook, wxID_ANY); mNotebook->AddPage(window4, wxT("SpringShow Mode Setup")); // the buttons on the bottom @@ -1076,7 +1348,7 @@ bool CalChartPreferences::TransferDataFromWindow() PreferencePage* page = static_cast(mNotebook->GetPage(i)); page->TransferDataFromWindow(); } - wxMessageBox(wxT("If you change any preferences, you may have restart CalChart to have them take effect"), wxT("Restart CalChart")); + CalChartConfiguration::AssignConfig(mConfig); return true; } @@ -1089,4 +1361,5 @@ void CalChartPreferences::OnCmdResetAll(wxCommandEvent&) PreferencePage* page = static_cast(mNotebook->GetPage(i)); page->ClearValuesToDefault(); } + CalChartConfiguration::AssignConfig(mConfig); } diff --git a/src/cc_preferences_ui.h b/src/cc_preferences_ui.h index 6e7e5b2f..f6be5246 100644 --- a/src/cc_preferences_ui.h +++ b/src/cc_preferences_ui.h @@ -27,6 +27,7 @@ #include #include #include +#include "confgr.h" class CalChartPreferences : public wxDialog { @@ -59,6 +60,7 @@ class CalChartPreferences : public wxDialog private: void OnCmdResetAll(wxCommandEvent&); wxNotebook* mNotebook; + CalChartConfiguration mConfig; }; #endif diff --git a/src/confgr.cpp b/src/confgr.cpp index 80416bb0..cf7c1364 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -29,167 +29,352 @@ #include #include #include +#include #include "calchartapp.h" #include "confgr.h" #include "modes.h" #include "cc_omniview_constants.h" -const wxString ColorNames[COLOR_NUM] = -{ - wxT("FIELD"), - wxT("FIELD DETAIL"), - wxT("FIELD TEXT"), - wxT("POINT"), - wxT("POINT TEXT"), - wxT("HILIT POINT"), - wxT("HILIT POINT TEXT"), - wxT("REF POINT"), - wxT("REF POINT TEXT"), - wxT("HILIT REF POINT"), - wxT("HILIT REF POINT TEXT"), - wxT("GHOST POINT"), - wxT("GHOST POINT TEXT"), - wxT("HLIT GHOST POINT"), - wxT("HLIT GHOST POINT TEXT"), - wxT("ANIM FRONT"), - wxT("ANIM BACK"), - wxT("ANIM SIDE"), - wxT("HILIT ANIM FRONT"), - wxT("HILIT ANIM BACK"), - wxT("HILIT ANIM SIDE"), - wxT("ANIM COLLISION"), - wxT("ANIM COLLISION WARNING"), - wxT("CONTINUITY PATHS"), - wxT("SHAPES") +const std::tuple ColorInfo[COLOR_NUM] = +{ + { wxT("FIELD"), wxT("FOREST GREEN"), 1 }, + { wxT("FIELD DETAIL"), wxT("WHITE"), 1 }, + { wxT("FIELD TEXT"), wxT("BLACK"), 1 }, + { wxT("POINT"), wxT("WHITE"), 1 }, + { wxT("POINT TEXT"), wxT("BLACK"), 1 }, + { wxT("HILIT POINT"), wxT("YELLOW"), 1 }, + { wxT("HILIT POINT TEXT"), wxT("YELLOW"), 1 }, + { wxT("REF POINT"), wxT("PURPLE"), 1 }, + { wxT("REF POINT TEXT"), wxT("BLACK"), 1 }, + { wxT("HILIT REF POINT"), wxT("PURPLE"), 1 }, + { wxT("HILIT REF POINT TEXT"), wxT("BLACK"), 1 }, + { wxT("GHOST POINT"), wxT("BLUE"), 1 }, + { wxT("GHOST POINT TEXT"), wxT("NAVY"), 1 }, + { wxT("HLIT GHOST POINT"), wxT("PURPLE"), 1 }, + { wxT("HLIT GHOST POINT TEXT"), wxT("PLUM"), 1 }, + { wxT("ANIM FRONT"), wxT("WHITE"), 1 }, + { wxT("ANIM BACK"), wxT("YELLOW"), 1 }, + { wxT("ANIM SIDE"), wxT("SKY BLUE"), 1 }, + { wxT("HILIT ANIM FRONT"), wxT("RED"), 1 }, + { wxT("HILIT ANIM BACK"), wxT("RED"), 1 }, + { wxT("HILIT ANIM SIDE"), wxT("RED"), 1 }, + { wxT("ANIM COLLISION"), wxT("PURPLE"), 1 }, + { wxT("ANIM COLLISION WARNING"), wxT("CORAL"), 1 }, + { wxT("SHAPES"), wxT("ORANGE"), 2 }, + { wxT("CONTINUITY PATHS"), wxT("RED"), 1 }, }; -const wxString DefaultColors[COLOR_NUM] = -{ - wxT("FOREST GREEN"), - wxT("WHITE"), - wxT("BLACK"), - wxT("WHITE"), - wxT("BLACK"), - wxT("YELLOW"), - wxT("YELLOW"), - wxT("PURPLE"), - wxT("BLACK"), - wxT("PURPLE"), - wxT("BLACK"), - wxT("BLUE"), - wxT("NAVY"), - wxT("PURPLE"), - wxT("PLUM"), - wxT("WHITE"), - wxT("YELLOW"), - wxT("SKY BLUE"), - wxT("RED"), - wxT("RED"), - wxT("RED"), - wxT("PURPLE"), - wxT("CORAL"), - wxT("RED"), - wxT("ORANGE") +///// Show mode configuration ///// + +const wxString kShowModeStrings[SHOWMODE_NUM] = +{ + wxT("Standard"), + wxT("Full Field"), + wxT("Tunnel"), + wxT("Old Field"), + wxT("Pro Field") }; -const int DefaultPenWidth[COLOR_NUM] = -{ - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 2, +// What values mean: +// whash ehash (steps from west sideline) +// left top right bottom (border in steps) +// x y w h (region of the field to use, in steps) +const std::array kShowModeDefaultValues[SHOWMODE_NUM] = +{ + {{ 32, 52, 8, 8, 8, 8, -80, -42, 160, 84 }}, + {{ 32, 52, 8, 8, 8, 8, -96, -42, 192, 84 }}, + {{ 32, 52, 8, 8, 8, 8, 16, -42, 192, 84 }}, + {{ 28, 52, 8, 8, 8, 8, -80, -42, 160, 84 }}, + {{ 36, 48, 8, 8, 8, 8, -80, -42, 160, 84 }} +}; + +const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM] = +{ + wxT("Zellerbach"), }; -// constants for behavior: -// Autosave +// what values mean +// X (hex digit of which yard lines to print: +// 8 = left, 4 = right, 2 = above, 1 = below) +// left top right bottom (border in steps) +// x y w h (region of the field to use, in steps) +// x y w h (size of stage EPS file as per BoundingBox) +// x y w h (where to put the field on the stage, depends on the EPS file) +// l r t b (location of yard line text's inside edge, depends on the EPS file) +const std::array kSpringShowModeDefaultValues[SPRINGSHOWMODE_NUM] = +{ + {{ 0xD, 8, 8, 8, 8, -16, -30, 32, 28, 0, 0, 571, 400, 163, 38, 265, 232, 153, 438, 270, 12 }} +}; +// Yard lines +const wxString yard_text_defaults[CalChartConfiguration::kYardTextValues] = +{ + wxT("N"), wxT("M"), wxT("L"), wxT("K"), wxT("J"), wxT("I"), wxT("H"), wxT("G"), wxT("F"), wxT("E"), wxT("D"), wxT("C"), wxT("B"), wxT("A"), + wxT("-10"), wxT("-5"), wxT("0"), wxT("5"), wxT("10"), wxT("15"), wxT("20"), wxT("25"), wxT("30"), wxT("35"), wxT("40"), wxT("45"), wxT("50"), + wxT("45"), wxT("40"), wxT("35"), wxT("30"), wxT("25"), wxT("20"), wxT("15"), wxT("10"), wxT("5"), wxT("0"), wxT("-5"), wxT("-10"), + wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), wxT("F"), wxT("G"), wxT("H"), wxT("I"), wxT("J"), wxT("K"), wxT("L"), wxT("M"), wxT("N") +}; + +const wxString yard_text_index[CalChartConfiguration::kYardTextValues] = +{ + wxT("N"), wxT("M"), wxT("L"), wxT("K"), wxT("J"), wxT("I"), wxT("H"), wxT("G"), wxT("F"), wxT("E"), wxT("D"), wxT("C"), wxT("B"), wxT("A"), + wxT("-10"), wxT("-5"), wxT("0"), wxT("5"), wxT("10"), wxT("15"), wxT("20"), wxT("25"), wxT("30"), wxT("35"), wxT("40"), wxT("45"), wxT("50"), + wxT("45"), wxT("40"), wxT("35"), wxT("30"), wxT("25"), wxT("20"), wxT("15"), wxT("10"), wxT("5"), wxT("0"), wxT("-5"), wxT("-10"), + wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), wxT("F"), wxT("G"), wxT("H"), wxT("I"), wxT("J"), wxT("K"), wxT("L"), wxT("M"), wxT("N") +}; + +const wxString spr_line_text_defaults[CalChartConfiguration::kSprLineTextValues] = +{ + wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), +}; + +const wxString spr_line_text_index[CalChartConfiguration::kSprLineTextValues] = +{ + wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), +}; + + + +static CalChartConfiguration& GetConfig() +{ + static CalChartConfiguration sconfig; + return sconfig; +} + +CalChartConfiguration& +CalChartConfiguration::GetGlobalConfig() +{ + return GetConfig(); +} + +void +CalChartConfiguration::AssignConfig(const CalChartConfiguration& config) +{ + // now flush out the config + GetConfig() = config; + GetConfig().FlushWriteQueue(); +} + + +// Get, Clear and Set PathKey are the primatives; do not use these directly. template -T GetConfigValue(const wxString& key, const T& def) +T GetConfigPathKey(const wxString& path, const wxString& key, const T& def) { wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/CalChart")); + config->SetPath(path); T value = def; config->Read(key, &value); return value; } -// default value need to check if we need to set a value +// clear out the config if it matches template -void SetConfigValue(const wxString& key, const T& value, const T& def) +void ClearConfigPathKey(const wxString& path, const wxString& key) { - // don't write if we don't have to - if (GetConfigValue(key, def) == value) - return; wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/CalChart")); - config->Write(key, value); + config->SetPath(path); + config->DeleteEntry(key); config->Flush(); } +// default value need to check if we need to set a value template -void ClearConfigValue(const wxString& key) +void SetConfigPathKey(const wxString& path, const wxString& key, const T& value) { wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/CalChart")); - config->DeleteEntry(key); + config->SetPath(path); + config->Write(key, value); config->Flush(); } -// printing controls -wxString yard_text[MAX_YARD_LINES] = + +// functions for dealing with the wx config directly +template +T GetConfigValue(const wxString& key, const T& def) { - wxT("N"), wxT("M"), wxT("L"), wxT("K"), wxT("J"), wxT("I"), wxT("H"), wxT("G"), wxT("F"), wxT("E"), wxT("D"), wxT("C"), wxT("B"), wxT("A"), - wxT("-10"), wxT("-5"), wxT("0"), wxT("5"), wxT("10"), wxT("15"), wxT("20"), wxT("25"), wxT("30"), wxT("35"), wxT("40"), wxT("45"), wxT("50"), - wxT("45"), wxT("40"), wxT("35"), wxT("30"), wxT("25"), wxT("20"), wxT("15"), wxT("10"), wxT("5"), wxT("0"), wxT("-5"), wxT("-10"), - wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), wxT("F"), wxT("G"), wxT("H"), wxT("I"), wxT("J"), wxT("K"), wxT("L"), wxT("M"), wxT("N") -}; + return GetConfigPathKey(wxT("/CalChart"), key, def); +} -const wxString yard_text_index[MAX_YARD_LINES] = +// clear out the config if it matches +//template +//void ClearConfigValue(const wxString& key) +//{ +// wxConfigBase *config = wxConfigBase::Get(); +// config->SetPath(wxT("/CalChart")); +// config->DeleteEntry(key); +// config->Flush(); +//} + +// default value need to check if we need to set a value +template +void SetConfigValue(const wxString& key, const T& value, const T& def) { - wxT("N"), wxT("M"), wxT("L"), wxT("K"), wxT("J"), wxT("I"), wxT("H"), wxT("G"), wxT("F"), wxT("E"), wxT("D"), wxT("C"), wxT("B"), wxT("A"), - wxT("-10"), wxT("-5"), wxT("0"), wxT("5"), wxT("10"), wxT("15"), wxT("20"), wxT("25"), wxT("30"), wxT("35"), wxT("40"), wxT("45"), wxT("50"), - wxT("45"), wxT("40"), wxT("35"), wxT("30"), wxT("25"), wxT("20"), wxT("15"), wxT("10"), wxT("5"), wxT("0"), wxT("-5"), wxT("-10"), - wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), wxT("F"), wxT("G"), wxT("H"), wxT("I"), wxT("J"), wxT("K"), wxT("L"), wxT("M"), wxT("N") -}; + // don't write if we don't have to + if (GetConfigValue(key, def) == value) + return; + // clear out the value if it's the same as the default + if (def == value) + { + ClearConfigPathKey(wxT("/CalChart"), key); + return; + } + SetConfigPathKey(wxT("/CalChart"), key, value); +} -wxString spr_line_text[MAX_SPR_LINES] = +// Specialize on Color +template <> +CalChartConfiguration::ColorWidth_t GetConfigValue(const wxString& key, const CalChartConfiguration::ColorWidth_t& def) { - wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), -}; + long r = std::get<0>(def).Red(); + long g = std::get<0>(def).Green(); + long b = std::get<0>(def).Blue(); + wxString rkey = key + wxT("_Red"); + wxString gkey = key + wxT("_Green"); + wxString bkey = key + wxT("_Blue"); + r = GetConfigPathKey(wxT("/COLORS"), rkey, r); + g = GetConfigPathKey(wxT("/COLORS"), gkey, g); + b = GetConfigPathKey(wxT("/COLORS"), bkey, b); + + long w = std::get<1>(def); + w = GetConfigPathKey(wxT("/COLORS/WIDTH"), key, w); + + return { wxColour( r, g, b ), w }; +} -const wxString spr_line_text_index[MAX_SPR_LINES] = +// Specialize on Color +template <> +void SetConfigValue(const wxString& key, const CalChartConfiguration::ColorWidth_t& value, const CalChartConfiguration::ColorWidth_t& def) { - wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), -}; + // don't write if we don't have to + if (GetConfigValue(key, def) == value) + return; + wxString rkey = key + wxT("_Red"); + wxString gkey = key + wxT("_Green"); + wxString bkey = key + wxT("_Blue"); + + // TODO: fix this so it clears + // clear out the value if it's the same as the default + if (def == value) + { + ClearConfigPathKey(wxT("/COLORS"), rkey); + ClearConfigPathKey(wxT("/COLORS"), gkey); + ClearConfigPathKey(wxT("/COLORS"), bkey); + ClearConfigPathKey(wxT("/COLORS/WIDTH"), key); + return; + } + + long r = std::get<0>(value).Red(); + long g = std::get<0>(value).Green(); + long b = std::get<0>(value).Blue(); + long w = std::get<1>(def); + SetConfigPathKey(wxT("/COLORS"), rkey, r); + SetConfigPathKey(wxT("/COLORS"), gkey, g); + SetConfigPathKey(wxT("/COLORS"), bkey, b); + SetConfigPathKey(wxT("/COLORS/WIDTH"), key, w); +} + +// Specialize on show mode +wxString ShowModeKeys[CalChartConfiguration::kShowModeValues] = { wxT("whash"), wxT("ehash"), wxT("bord1_x"), wxT("bord1_y"), wxT("bord2_x"), wxT("bord2_y"), wxT("size_x"), wxT("size_y"), wxT("offset_x"), wxT("offset_y") }; + +template <> +CalChartConfiguration::ShowModeInfo_t GetConfigValue(const wxString& key, const CalChartConfiguration::ShowModeInfo_t& def) +{ + CalChartConfiguration::ShowModeInfo_t values; + wxString path = wxT("/SHOWMODES/") + key; + for (auto i=0; i < CalChartConfiguration::kShowModeValues; ++i) + { + values[i] = GetConfigPathKey(path, ShowModeKeys[i], values[i]); + } + return values; +} + +// Specialize on show mode +template <> +void SetConfigValue(const wxString& key, const CalChartConfiguration::ShowModeInfo_t& value, const CalChartConfiguration::ShowModeInfo_t& def) +{ + // don't write if we don't have to + if (GetConfigValue(key, def) == value) + return; + wxString path = wxT("/SHOWMODES/") + key; + + // TODO: fix this so it clears + // clear out the value if it's the same as the default + if (def == value) + { + for (auto i=0; i < CalChartConfiguration::kShowModeValues; ++i) + { + ClearConfigPathKey(path, ShowModeKeys[i]); + } + return; + } + + for (auto i=0; i < CalChartConfiguration::kShowModeValues; ++i) + { + SetConfigPathKey(path, ShowModeKeys[i], value[i]); + } +} + +// Specialize on spring show mode +wxString SpringShowModeKeys[CalChartConfiguration::kSpringShowModeValues] = { wxT("which_spr_yards"), wxT("bord1_x"), wxT("bord1_y"), wxT("bord2_x"), wxT("bord2_y"), wxT("mode_steps_x"), wxT("mode_steps_y"), wxT("mode_steps_w"), wxT("mode_steps_h"), wxT("eps_stage_x"), wxT("eps_stage_y"), wxT("eps_stage_w"), wxT("eps_stage_h"), wxT("eps_field_x"), wxT("eps_field_y"), wxT("eps_field_w"), wxT("eps_field_h"), wxT("eps_text_left"), wxT("eps_text_right"), wxT("eps_text_top"), wxT("eps_text_bottom") }; + +template <> +CalChartConfiguration::SpringShowModeInfo_t GetConfigValue(const wxString& key, const CalChartConfiguration::SpringShowModeInfo_t& def) +{ + CalChartConfiguration::SpringShowModeInfo_t values; + wxString path = wxT("/SPRINGSHOWMODES/") + key; + for (auto i=0; i < CalChartConfiguration::kSpringShowModeValues; ++i) + { + values[i] = GetConfigPathKey(path, SpringShowModeKeys[i], values[i]); + } + return values; +} + +// Specialize on spring show mode +template <> +void SetConfigValue(const wxString& key, const CalChartConfiguration::SpringShowModeInfo_t& value, const CalChartConfiguration::SpringShowModeInfo_t& def) +{ + // don't write if we don't have to + if (GetConfigValue(key, def) == value) + return; + wxString path = wxT("/SPRINGSHOWMODES/") + key; + + // TODO: fix this so it clears + // clear out the value if it's the same as the default + if (def == value) + { + for (auto i=0; i < CalChartConfiguration::kSpringShowModeValues; ++i) + { + ClearConfigPathKey(path, SpringShowModeKeys[i]); + } + return; + } + + for (auto i=0; i < CalChartConfiguration::kSpringShowModeValues; ++i) + { + SetConfigPathKey(path, SpringShowModeKeys[i], value[i]); + } +} + #define IMPLEMENT_CONFIGURATION_FUNCTIONS( KeyName, Type, TheValue ) \ static const wxString k ## KeyName ## Key = wxT( #KeyName ); \ static const Type k ## KeyName ## Value = (TheValue); \ -Type GetConfiguration_ ## KeyName () { return GetConfigValue( k ## KeyName ## Key, k ## KeyName ## Value); } \ -void SetConfiguration_ ## KeyName (const Type& v) { return SetConfigValue( k ## KeyName ## Key, v, k ## KeyName ## Value); } \ -void ClearConfiguration_ ## KeyName () { return ClearConfigValue( k ## KeyName ## Key ); } +Type CalChartConfiguration::Get_ ## KeyName () const \ +{ \ + if (! m ## KeyName.first) { \ + m ## KeyName.second = GetConfigValue( k ## KeyName ## Key, k ## KeyName ## Value); \ + m ## KeyName.first = true; \ + } \ + return m ## KeyName.second; \ +} \ +void CalChartConfiguration::Set_ ## KeyName (const Type& v) \ +{ \ + mWriteQueue[k ## KeyName ## Key] = [v]() { SetConfigValue( k ## KeyName ## Key, v, k ## KeyName ## Value); }; \ + m ## KeyName.first = true; \ + m ## KeyName.second = v; \ +} \ +void CalChartConfiguration::Clear_ ## KeyName () { return Set_ ## KeyName (k ## KeyName ## Value); } IMPLEMENT_CONFIGURATION_FUNCTIONS( AutosaveInterval, long, 60); @@ -269,401 +454,239 @@ IMPLEMENT_CONFIGURATION_FUNCTIONS( AnimationFrameSplitVertical, bool, false); //IMPLEMENT_CONFIGURATION_FUNCTIONS( MainFrameHeight, long, 450); -// Color is more complicated, we use functions for setting that -wxPen CalChartPens[COLOR_NUM]; -wxBrush CalChartBrushes[COLOR_NUM]; - -///// Show mode configuration ///// - -const wxString kShowModeStrings[SHOWMODE_NUM] = +std::vector +CalChartConfiguration::GetColorNames() const { - wxT("Standard"), - wxT("Full Field"), - wxT("Tunnel"), - wxT("Old Field"), - wxT("Pro Field") -}; - -// What values mean: -// whash ehash (steps from west sideline) -// left top right bottom (border in steps) -// x y w h (region of the field to use, in steps) -const long kShowModeDefaultValues[SHOWMODE_NUM][kShowModeValues] = -{ - { 32, 52, 8, 8, 8, 8, -80, -42, 160, 84 }, - { 32, 52, 8, 8, 8, 8, -96, -42, 192, 84 }, - { 32, 52, 8, 8, 8, 8, 16, -42, 192, 84 }, - { 28, 52, 8, 8, 8, 8, -80, -42, 160, 84 }, - { 36, 48, 8, 8, 8, 8, -80, -42, 160, 84 } -}; + std::vector result; + std::transform(std::begin(ColorInfo), std::end(ColorInfo), std::back_inserter(result), [](const std::tuple& i) { return std::get<0>(i); }); + return result; +} -const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM] = +std::vector +CalChartConfiguration::GetDefaultColors() const { - wxT("Zellerbach"), -}; + std::vector result; + std::transform(std::begin(ColorInfo), std::end(ColorInfo), std::back_inserter(result), [](const std::tuple& i) { return std::get<1>(i); }); + return result; +} -// what values mean -// X (hex digit of which yard lines to print: -// 8 = left, 4 = right, 2 = above, 1 = below) -// left top right bottom (border in steps) -// x y w h (region of the field to use, in steps) -// x y w h (size of stage EPS file as per BoundingBox) -// x y w h (where to put the field on the stage, depends on the EPS file) -// l r t b (location of yard line text's inside edge, depends on the EPS file) -const long kSpringShowModeDefaultValues[SPRINGSHOWMODE_NUM][kSpringShowModeValues] = +std::vector +CalChartConfiguration::GetDefaultPenWidth() const { - { 0xD, 8, 8, 8, 8, -16, -30, 32, 28, 0, 0, 571, 400, 163, 38, 265, 232, 153, 438, 270, 12 } -}; + std::vector result; + std::transform(std::begin(ColorInfo), std::end(ColorInfo), std::back_inserter(result), [](const std::tuple& i) { return std::get<2>(i); }); + return result; +} -void GetConfigurationShowMode(size_t which, long values[kShowModeValues]) +std::vector +CalChartConfiguration::Get_yard_text_index() const { - for (size_t i = 0; i < kShowModeValues; ++i) - { - values[i] = kShowModeDefaultValues[which][i]; - } - - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SHOWMODES")); - if (config->Exists(kShowModeStrings[which])) - { - config->SetPath(kShowModeStrings[which]); - values[0] = config->Read(wxT("whash"), values[0]); - values[1] = config->Read(wxT("ehash"), values[1]); - values[2] = config->Read(wxT("bord1_x"), values[2]); - values[3] = config->Read(wxT("bord1_y"), values[3]); - values[4] = config->Read(wxT("bord2_x"), values[4]); - values[5] = config->Read(wxT("bord2_y"), values[5]); - values[6] = config->Read(wxT("size_x"), values[6]); - values[7] = config->Read(wxT("size_y"), values[7]); - values[8] = config->Read(wxT("offset_x"), values[8]); - values[9] = config->Read(wxT("offset_y"), values[9]); - } + return { std::begin(yard_text_index), std::end(yard_text_index) }; } -void ReadConfigurationShowMode() +std::vector +CalChartConfiguration::Get_spr_line_text_index() const { - for (size_t i=0; i(new ShowModeStandard(kShowModeStrings[i], size, offset, bord1, bord2, whash, ehash))); - } + return { std::begin(spr_line_text_index), std::end(spr_line_text_index) }; } -void GetConfigurationSpringShowMode(size_t which, long values[kShowModeValues]) +///// Color Configuration ///// + +std::pair +CalChartConfiguration::Get_CalChartBrushAndPen(CalChartColors c) const { - for (size_t i = 0; i < kSpringShowModeValues; ++i) - { - values[i] = kSpringShowModeDefaultValues[which][i]; - } + if (c >= COLOR_NUM) + throw std::runtime_error("Error, exceeding COLOR_NUM size"); - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SPRINGSHOWMODES")); - if (config->Exists(kSpringShowModeStrings[which])) + if (!mColorsAndWidth.count(c)) { - config->SetPath(kSpringShowModeStrings[which]); - values[0] = config->Read(wxT("which_spr_yards"), values[0]); - values[1] = config->Read(wxT("bord1_x"), values[1]); - values[2] = config->Read(wxT("bord1_y"), values[2]); - values[3] = config->Read(wxT("bord2_x"), values[3]); - values[4] = config->Read(wxT("bord2_y"), values[4]); - - values[5] = config->Read(wxT("mode_steps_x"), values[5]); - values[6] = config->Read(wxT("mode_steps_y"), values[6]); - values[7] = config->Read(wxT("mode_steps_w"), values[7]); - values[8] = config->Read(wxT("mode_steps_h"), values[8]); - values[9] = config->Read(wxT("eps_stage_x"), values[9]); - values[10] = config->Read(wxT("eps_stage_y"), values[10]); - values[11] = config->Read(wxT("eps_stage_w"), values[11]); - values[12] = config->Read(wxT("eps_stage_h"), values[12]); - values[13] = config->Read(wxT("eps_field_x"), values[13]); - values[14] = config->Read(wxT("eps_field_y"), values[14]); - values[15] = config->Read(wxT("eps_field_w"), values[15]); - values[16] = config->Read(wxT("eps_field_h"), values[16]); - values[17] = config->Read(wxT("eps_text_left"), values[17]); - values[18] = config->Read(wxT("eps_text_right"), values[18]); - values[19] = config->Read(wxT("eps_text_top"), values[19]); - values[20] = config->Read(wxT("eps_text_bottom"), values[20]); + mColorsAndWidth[c] = GetConfigValue(std::get<0>(ColorInfo[c]), ColorWidth_t(std::get<1>(ColorInfo[c]), std::get<2>(ColorInfo[c]))); } + auto colorAndWidth = mColorsAndWidth[c]; + return { *wxTheBrushList->FindOrCreateBrush(std::get<0>(colorAndWidth), wxSOLID), *wxThePenList->FindOrCreatePen(std::get<0>(colorAndWidth), std::get<1>(colorAndWidth), wxSOLID) }; } -void ReadConfigurationSpringShowMode() +void +CalChartConfiguration::Set_CalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen) { - for (size_t i=0; i(new ShowModeSprShow(kSpringShowModeStrings[i], bord1, bord2, - which_spr_yards, - mode_steps_x, mode_steps_y, - mode_steps_w, mode_steps_h, - eps_stage_x, eps_stage_y, - eps_stage_w, eps_stage_h, - eps_field_x, eps_field_y, - eps_field_w, eps_field_h, - eps_text_left, eps_text_right, - eps_text_top, eps_text_bottom))); + if (c >= COLOR_NUM) + throw std::runtime_error("Error, exceeding COLOR_NUM size"); - } -} + ColorWidth_t v{ brush.GetColour(), pen.GetWidth() }; -void SetConfigurationShowMode(size_t which, const long values[kShowModeValues]) -{ - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SHOWMODES")); - config->SetPath(kShowModeStrings[which]); - config->Write(wxT("whash"), values[0]); - config->Write(wxT("ehash"), values[1]); - config->Write(wxT("bord1_x"), values[2]); - config->Write(wxT("bord1_y"), values[3]); - config->Write(wxT("bord2_x"), values[4]); - config->Write(wxT("bord2_y"), values[5]); - config->Write(wxT("size_x"), values[6]); - config->Write(wxT("size_y"), values[7]); - config->Write(wxT("offset_x"), values[8]); - config->Write(wxT("offset_y"), values[9]); - config->Flush(); + mWriteQueue[std::get<0>(ColorInfo[c])] = [c, v]() { SetConfigValue(std::get<0>(ColorInfo[c]), v, ColorWidth_t(std::get<1>(ColorInfo[c]), std::get<2>(ColorInfo[c]))); }; + mColorsAndWidth[c] = v; } -void SetConfigurationSpringShowMode(size_t which, const long values[kSpringShowModeValues]) +void +CalChartConfiguration::Clear_ConfigColor(size_t selection) { - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SPRINGSHOWMODES")); - config->SetPath(kSpringShowModeStrings[which]); - config->Write(wxT("which_spr_yards"), values[0]); - config->Write(wxT("bord1_x"), values[1]); - config->Write(wxT("bord1_y"), values[2]); - config->Write(wxT("bord2_x"), values[3]); - config->Write(wxT("bord2_y"), values[4]); - - config->Write(wxT("mode_steps_x"), values[5]); - config->Write(wxT("mode_steps_y"), values[6]); - config->Write(wxT("mode_steps_w"), values[7]); - config->Write(wxT("mode_steps_h"), values[8]); - config->Write(wxT("eps_stage_x"), values[9]); - config->Write(wxT("eps_stage_y"), values[10]); - config->Write(wxT("eps_stage_w"), values[11]); - config->Write(wxT("eps_stage_h"), values[12]); - config->Write(wxT("eps_field_x"), values[13]); - config->Write(wxT("eps_field_y"), values[14]); - config->Write(wxT("eps_field_w"), values[15]); - config->Write(wxT("eps_field_h"), values[16]); - config->Write(wxT("eps_text_left"), values[17]); - config->Write(wxT("eps_text_right"), values[18]); - config->Write(wxT("eps_text_top"), values[19]); - config->Write(wxT("eps_text_bottom"), values[20]); - config->Flush(); -} + if (selection >= COLOR_NUM) + throw std::runtime_error("Error, exceeding COLOR_NUM size"); -void ClearConfigurationShowMode(size_t which) -{ - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SHOWMODES")); - config->DeleteEntry(kShowModeStrings[which]); + auto default_value = ColorWidth_t(std::get<1>(ColorInfo[selection]), std::get<2>(ColorInfo[selection])); + SetConfigValue(std::get<0>(ColorInfo[selection]), default_value, default_value); } -void ClearConfigurationSpringShowMode(size_t which) -{ - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SPRINGSHOWMODES")); - config->DeleteEntry(kSpringShowModeStrings[which]); -} +///// Show Configuration ///// -///// Color Configuration ///// -void ReadConfigColor() +CalChartConfiguration::ShowModeInfo_t +CalChartConfiguration::Get_ShowModeInfo(CalChartShowModes which) const { - wxConfigBase *config = wxConfigBase::Get(); - - // read out the color configuration: - config->SetPath(wxT("/COLORS")); - for (size_t i=0; i= SHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SHOWMODE_NUM size"); + + if (!mShowModeInfos.count(which)) { - wxColour c; - wxString rbuf = ColorNames[i] + wxT("_Red"); - wxString gbuf = ColorNames[i] + wxT("_Green"); - wxString bbuf = ColorNames[i] + wxT("_Blue"); - if (config->Exists(rbuf) && config->Exists(gbuf) && config->Exists(bbuf)) - { - long r = config->Read(rbuf, 0l); - long g = config->Read(gbuf, 0l); - long b = config->Read(bbuf, 0l); - c = wxColour(r, g, b); - } - else - { - c = wxColour(DefaultColors[i]); - } - CalChartBrushes[i] = *wxTheBrushList->FindOrCreateBrush(c, wxSOLID); - // store widths in a subgroup - config->SetPath(wxT("WIDTH")); - long width = DefaultPenWidth[i]; - config->Read(ColorNames[i], &width); - CalChartPens[i] = *wxThePenList->FindOrCreatePen(c, width, wxSOLID); - config->SetPath(wxT("..")); + mShowModeInfos[which] = GetConfigValue(kShowModeStrings[which], kShowModeDefaultValues[which]); } + return mShowModeInfos[which]; } -void SetConfigColor(size_t selection) +void +CalChartConfiguration::Set_ShowModeInfo(CalChartShowModes which, const ShowModeInfo_t& values) { - wxConfigBase *config = wxConfigBase::Get(); + if (which >= SHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SHOWMODE_NUM size"); - // read out the color configuration: - config->SetPath(wxT("/COLORS")); - wxString rbuf = ColorNames[selection] + wxT("_Red"); - config->Write(rbuf, static_cast(CalChartBrushes[selection].GetColour().Red())); - wxString gbuf = ColorNames[selection] + wxT("_Green"); - config->Write(gbuf, static_cast(CalChartBrushes[selection].GetColour().Green())); - wxString bbuf = ColorNames[selection] + wxT("_Blue"); - config->Write(bbuf, static_cast(CalChartBrushes[selection].GetColour().Blue())); - config->SetPath(wxT("WIDTH")); - config->Write(ColorNames[selection], CalChartPens[selection].GetWidth()); - config->Flush(); + mWriteQueue[kShowModeStrings[which]] = [which, values]() { SetConfigValue(kShowModeStrings[which], values, kShowModeDefaultValues[which]); }; + mShowModeInfos[which] = values; } -void ClearConfigColor(size_t selection) +void +CalChartConfiguration::Clear_ShowModeInfo(CalChartShowModes which) { - wxConfigBase *config = wxConfigBase::Get(); + if (which >= SHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SHOWMODE_NUM size"); - config->SetPath(wxT("/COLORS")); - wxString rbuf = ColorNames[selection] + wxT("_Red"); - config->DeleteEntry(rbuf); - wxString gbuf = ColorNames[selection] + wxT("_Green"); - config->DeleteEntry(gbuf); - wxString bbuf = ColorNames[selection] + wxT("_Blue"); - config->DeleteEntry(bbuf); - config->SetPath(wxT("WIDTH")); - config->DeleteEntry(ColorNames[selection]); - config->Flush(); + auto default_value = kShowModeDefaultValues[which]; + SetConfigValue(kShowModeStrings[which], default_value, default_value); } -void ReadConfigYardlines() -{ - for (size_t i = 0; i < MAX_YARD_LINES; ++i) - { - wxString key; - key.Printf(wxT("YardLines_%ld"), i); - yard_text[i] = GetConfigValue(key, yard_text_index[i]); - } -} -void SetConfigShowYardline() +CalChartConfiguration::SpringShowModeInfo_t +CalChartConfiguration::Get_SpringShowModeInfo(CalChartSpringShowModes which) const { - for (size_t i = 0; i < MAX_YARD_LINES; ++i) + if (which >= SPRINGSHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SPRINGSHOWMODE_NUM size"); + + if (!mSpringShowModeInfos.count(which)) { - wxString key; - key.Printf(wxT("YardLines_%ld"), i); - SetConfigValue(key, yard_text[i], yard_text_index[i]); + mSpringShowModeInfos[which] = GetConfigValue(kSpringShowModeStrings[which], kSpringShowModeDefaultValues[which]); } + return mSpringShowModeInfos[which]; } -void ClearConfigShowYardline() +void +CalChartConfiguration::Set_SpringShowModeInfo(CalChartSpringShowModes which, const SpringShowModeInfo_t& values) { - for (size_t i = 0; i < MAX_YARD_LINES; ++i) - { - wxString key; - key.Printf(wxT("YardLines_%ld"), i); - ClearConfigValue(key); - } - ReadConfigYardlines(); + if (which >= SPRINGSHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SPRINGSHOWMODE_NUM size"); + + mWriteQueue[kSpringShowModeStrings[which]] = [which, values]() { SetConfigValue(kSpringShowModeStrings[which], values, kSpringShowModeDefaultValues[which]); }; + mSpringShowModeInfos[which] = values; } -void ReadConfigSpringYardlines() +void +CalChartConfiguration::Clear_SpringShowModeInfo(CalChartSpringShowModes which) { - for (size_t i = 0; i < MAX_SPR_LINES; ++i) - { - wxString key; - key.Printf(wxT("SpringShowYardLines_%ld"), i); - spr_line_text[i] = GetConfigValue(key, spr_line_text_index[i]); - } + if (which >= SPRINGSHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SPRINGSHOWMODE_NUM size"); + + auto default_value = kSpringShowModeDefaultValues[which]; + SetConfigValue(kSpringShowModeStrings[which], default_value, default_value); } -void SetConfigSpringShowYardline() + +// Yard Lines +wxString +CalChartConfiguration::Get_yard_text(size_t which) const { - for (size_t i = 0; i < MAX_SPR_LINES; ++i) + if (which >= kYardTextValues) + throw std::runtime_error("Error, exceeding kYardTextValues size"); + + if (!mYardTextInfos.count(which)) { wxString key; - key.Printf(wxT("SpringShowYardLines_%ld"), i); - SetConfigValue(key, spr_line_text[i], spr_line_text_index[i]); + key.Printf(wxT("YardLines_%ld"), which); + mYardTextInfos[which] = GetConfigValue(key, yard_text_defaults[which]); } + return mYardTextInfos[which]; } -void ClearConfigSpringShowYardline() +void +CalChartConfiguration::Set_yard_text(size_t which, const wxString& value) { - for (size_t i = 0; i < MAX_SPR_LINES; ++i) - { - wxString key; - key.Printf(wxT("SpringShowYardLines_%ld"), i); - ClearConfigValue(key); - } - ReadConfigSpringYardlines(); + if (which >= kYardTextValues) + throw std::runtime_error("Error, exceeding kYardTextValues size"); + + wxString key; + key.Printf(wxT("YardLines_%ld"), which); + auto default_value = yard_text_defaults[which]; + mWriteQueue[key] = [key, value, default_value]() { SetConfigValue(key, value, default_value); }; + mYardTextInfos[which] = value; } -void ReadConfig() +void +CalChartConfiguration::Clear_yard_text(size_t which) { - ReadConfigColor(); - ReadConfigurationShowMode(); - ReadConfigurationSpringShowMode(); - ReadConfigYardlines(); - ReadConfigSpringYardlines(); + if (which >= kYardTextValues) + throw std::runtime_error("Error, exceeding kYardTextValues size"); + + wxString key; + key.Printf(wxT("YardLines_%ld"), which); + auto default_value = yard_text_defaults[which]; + SetConfigValue(key, default_value, default_value); } -wxPen -GetCalChartPen(CalChartColors c) +wxString +CalChartConfiguration::Get_spr_line_text(size_t which) const { - return CalChartPens[c]; + if (which >= kSprLineTextValues) + throw std::runtime_error("Error, exceeding kSprLineTextValues size"); + + if (!mSprLineTextInfos.count(which)) + { + wxString key; + key.Printf(wxT("SpringShowLines_%ld"), which); + mSprLineTextInfos[which] = GetConfigValue(key, spr_line_text_defaults[which]); + } + return mSprLineTextInfos[which]; } void -SetCalChartPen(CalChartColors c, const wxPen& pen) +CalChartConfiguration::Set_spr_line_text(size_t which, const wxString& value) { - CalChartPens[c] = pen; + if (which >= kSprLineTextValues) + throw std::runtime_error("Error, exceeding kSprLineTextValues size"); + + wxString key; + key.Printf(wxT("SpringShowLines_%ld"), which); + auto default_value = spr_line_text_defaults[which]; + mWriteQueue[key] = [key, value, default_value]() { SetConfigValue(key, value, default_value); }; + mSprLineTextInfos[which] = value; } -wxBrush -GetCalChartBrush(CalChartColors c) +void +CalChartConfiguration::Clear_spr_line_text(size_t which) { - return CalChartBrushes[c]; + if (which >= kSprLineTextValues) + throw std::runtime_error("Error, exceeding kSprLineTextValues size"); + + wxString key; + key.Printf(wxT("SpringShowLines_%ld"), which); + auto default_value = spr_line_text_defaults[which]; + SetConfigValue(key, default_value, default_value); } +// function technically const because it is changing a mutable value void -SetCalChartBrush(CalChartColors c, const wxBrush& brush) +CalChartConfiguration::FlushWriteQueue() const { - CalChartBrushes[c] = brush; + for (auto& i : mWriteQueue) + { + i.second(); + } + mWriteQueue.clear(); } diff --git a/src/confgr.h b/src/confgr.h index 68fbc0cd..e491846b 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -25,14 +25,17 @@ #include #include +#include +#include +#include +#include // forward declare class wxPen; class wxBrush; class wxPathList; - -#define MAX_SPR_LINES 5 -#define MAX_YARD_LINES 53 +class wxColour; +class ShowMode; enum CalChartColors { @@ -64,14 +67,6 @@ enum CalChartColors COLOR_NUM }; -wxPen GetCalChartPen(CalChartColors c); -void SetCalChartPen(CalChartColors c, const wxPen& pen); -wxBrush GetCalChartBrush(CalChartColors c); -void SetCalChartBrush(CalChartColors c, const wxBrush& brush); -extern const wxString ColorNames[COLOR_NUM]; -extern const wxString DefaultColors[COLOR_NUM]; -extern const int DefaultPenWidth[COLOR_NUM]; - enum CalChartShowModes { STANDARD, @@ -92,114 +87,153 @@ enum CalChartSpringShowModes extern const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM]; -// macro for declaring configuration settings +// CalChartConfiguration interfaces with the system config and acts as a "cache" for the values. +// On Get, it reads the values from system config, and caches a copy. +// On Set (and clear), it updates it's cache, and puts the command into a write-queue. +// The write-queue needs to be explicitly flushed or the values will be lost +// +// To use a config value, first get the Global config, and then Get_ the value from it: +// auto save_interval = CalChartConfiguration::GetGlobalConfig().Get_AutosaveInterval(); +// +// To add a new config value: +// Add DECLARE_CONFIGURATION_FUNCTIONS in the class declaration of the right type; this will make the Get_, Set_ and Clear_ +// functions available. Then in the implementation file, declare IMPLEMENT_CONFIGURATION_FUNCTIONS with the default. +class CalChartConfiguration +{ +public: + static CalChartConfiguration& GetGlobalConfig(); + static void AssignConfig(const CalChartConfiguration& config); + + // explicit flush + void FlushWriteQueue() const; + +private: + mutable std::map> mWriteQueue; + +// macro for declaring configuration Get_, Set_, and Clear_ #define DECLARE_CONFIGURATION_FUNCTIONS( Key, Type ) \ -Type GetConfiguration_ ## Key () ; \ -void SetConfiguration_ ## Key (const Type& v) ; \ -void ClearConfiguration_ ## Key () ; - -DECLARE_CONFIGURATION_FUNCTIONS( AutosaveInterval, long); - -// page setup and zoom -DECLARE_CONFIGURATION_FUNCTIONS( FieldFrameZoom, double); -DECLARE_CONFIGURATION_FUNCTIONS( FieldFrameWidth, long); -DECLARE_CONFIGURATION_FUNCTIONS( FieldFrameHeight, long); - -// printing configurations -DECLARE_CONFIGURATION_FUNCTIONS( PrintFile, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( PrintCmd, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( PrintOpts, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( PrintViewCmd, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( PrintViewOpts, wxString); - -DECLARE_CONFIGURATION_FUNCTIONS( PageWidth, double); -DECLARE_CONFIGURATION_FUNCTIONS( PageHeight, double); -DECLARE_CONFIGURATION_FUNCTIONS( PageOffsetX, double); -DECLARE_CONFIGURATION_FUNCTIONS( PageOffsetY, double); -DECLARE_CONFIGURATION_FUNCTIONS( PaperLength, double); - -DECLARE_CONFIGURATION_FUNCTIONS( HeadFont, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( MainFont, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( NumberFont, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( ContFont, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( BoldFont, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( ItalFont, wxString); -DECLARE_CONFIGURATION_FUNCTIONS( BoldItalFont, wxString); - -DECLARE_CONFIGURATION_FUNCTIONS( HeaderSize, double); -DECLARE_CONFIGURATION_FUNCTIONS( YardsSize, double); -DECLARE_CONFIGURATION_FUNCTIONS( TextSize, double); -DECLARE_CONFIGURATION_FUNCTIONS( DotRatio, double); -DECLARE_CONFIGURATION_FUNCTIONS( NumRatio, double); -DECLARE_CONFIGURATION_FUNCTIONS( PLineRatio, double); -DECLARE_CONFIGURATION_FUNCTIONS( SLineRatio, double); -DECLARE_CONFIGURATION_FUNCTIONS( ContRatio, double); - -DECLARE_CONFIGURATION_FUNCTIONS( PrintPSModes, long); -DECLARE_CONFIGURATION_FUNCTIONS( PrintPSLandscape, long); -DECLARE_CONFIGURATION_FUNCTIONS( PrintPSOverview, long); -DECLARE_CONFIGURATION_FUNCTIONS( PrintPSDoCont, long); -DECLARE_CONFIGURATION_FUNCTIONS( PrintPSDoContSheet, long); - -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_X_4, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Y_4, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Z_4, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_4, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_Z_4, float); - -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_X_5, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Y_5, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Z_5, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_5, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_Z_5, float); - -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_X_6, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Y_6, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Z_6, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_6, float); -DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_Z_6, float); - -DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameWidth, long); -DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameHeight, long); - -DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSashPosition, long); -DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameOmniAnimation, bool); -DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSplitScreen, bool); -DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSplitVertical, bool); - - -extern wxString yard_text[MAX_YARD_LINES]; -extern const wxString yard_text_index[MAX_YARD_LINES]; -extern wxString spr_line_text[MAX_SPR_LINES]; -extern const wxString spr_line_text_index[MAX_SPR_LINES]; - -extern void ReadConfig(); - -const size_t kShowModeValues = 10; -void GetConfigurationShowMode(size_t which, long values[kShowModeValues]); -void SetConfigurationShowMode(size_t which, const long values[kShowModeValues]); -void ClearConfigurationShowMode(size_t which); - -const size_t kSpringShowModeValues = 21; -void GetConfigurationSpringShowMode(size_t which, long values[kSpringShowModeValues]); -void SetConfigurationSpringShowMode(size_t which, const long values[kSpringShowModeValues]); -void ClearConfigurationSpringShowMode(size_t which); - -void SetConfigColor(size_t selection); -void ClearConfigColor(size_t selection); - -// TODO: Setup linenumbers -void SetConfigShowYardline(); -void ClearConfigShowYardline(); -void SetConfigSpringShowYardline(); -void ClearConfigSpringShowYardline(); - -class wxFile; - -// DEBUG printing facilities -#ifndef NDEBUG -#define DEBUG_LOG(format, ...) fprintf(stderr, format, ## __VA_ARGS__) -#else -#define DEBUG_LOG(format, ...) -#endif +public: \ + Type Get_ ## Key () const ; \ + void Set_ ## Key (const Type& v) ; \ + void Clear_ ## Key () ; \ +private: \ + mutable std::pair m ## Key = { false, Type() }; + + DECLARE_CONFIGURATION_FUNCTIONS( AutosaveInterval, long); + + // page setup and zoom + DECLARE_CONFIGURATION_FUNCTIONS( FieldFrameZoom, double); + DECLARE_CONFIGURATION_FUNCTIONS( FieldFrameWidth, long); + DECLARE_CONFIGURATION_FUNCTIONS( FieldFrameHeight, long); + + // printing configurations + DECLARE_CONFIGURATION_FUNCTIONS( PrintFile, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( PrintCmd, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( PrintOpts, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( PrintViewCmd, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( PrintViewOpts, wxString); + + DECLARE_CONFIGURATION_FUNCTIONS( PageWidth, double); + DECLARE_CONFIGURATION_FUNCTIONS( PageHeight, double); + DECLARE_CONFIGURATION_FUNCTIONS( PageOffsetX, double); + DECLARE_CONFIGURATION_FUNCTIONS( PageOffsetY, double); + DECLARE_CONFIGURATION_FUNCTIONS( PaperLength, double); + + DECLARE_CONFIGURATION_FUNCTIONS( HeadFont, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( MainFont, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( NumberFont, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( ContFont, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( BoldFont, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( ItalFont, wxString); + DECLARE_CONFIGURATION_FUNCTIONS( BoldItalFont, wxString); + + DECLARE_CONFIGURATION_FUNCTIONS( HeaderSize, double); + DECLARE_CONFIGURATION_FUNCTIONS( YardsSize, double); + DECLARE_CONFIGURATION_FUNCTIONS( TextSize, double); + DECLARE_CONFIGURATION_FUNCTIONS( DotRatio, double); + DECLARE_CONFIGURATION_FUNCTIONS( NumRatio, double); + DECLARE_CONFIGURATION_FUNCTIONS( PLineRatio, double); + DECLARE_CONFIGURATION_FUNCTIONS( SLineRatio, double); + DECLARE_CONFIGURATION_FUNCTIONS( ContRatio, double); + + DECLARE_CONFIGURATION_FUNCTIONS( PrintPSModes, long); + DECLARE_CONFIGURATION_FUNCTIONS( PrintPSLandscape, long); + DECLARE_CONFIGURATION_FUNCTIONS( PrintPSOverview, long); + DECLARE_CONFIGURATION_FUNCTIONS( PrintPSDoCont, long); + DECLARE_CONFIGURATION_FUNCTIONS( PrintPSDoContSheet, long); + + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_X_4, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Y_4, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Z_4, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_4, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_Z_4, float); + + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_X_5, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Y_5, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Z_5, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_5, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_Z_5, float); + + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_X_6, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Y_6, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewPoint_Z_6, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_6, float); + DECLARE_CONFIGURATION_FUNCTIONS( OmniViewAngle_Z_6, float); + + DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameWidth, long); + DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameHeight, long); + + DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSashPosition, long); + DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameOmniAnimation, bool); + DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSplitScreen, bool); + DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSplitVertical, bool); + +public: + // helpers for displaying different config attributes + std::vector GetColorNames() const; + std::vector GetDefaultColors() const; + std::vector GetDefaultPenWidth() const; + std::vector Get_yard_text_index() const; + std::vector Get_spr_line_text_index() const; + + // Colors + using ColorWidth_t = std::pair; + mutable std::map mColorsAndWidth; + std::pair Get_CalChartBrushAndPen(CalChartColors c) const; + void Set_CalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen); + void Clear_ConfigColor(size_t selection); + + // Shows + static const size_t kShowModeValues = 10; + using ShowModeInfo_t = std::array; + mutable std::map mShowModeInfos; + ShowModeInfo_t Get_ShowModeInfo(CalChartShowModes which) const; + void Set_ShowModeInfo(CalChartShowModes which, const ShowModeInfo_t& values); + void Clear_ShowModeInfo(CalChartShowModes which); + + static const size_t kSpringShowModeValues = 21; + using SpringShowModeInfo_t = std::array; + mutable std::map mSpringShowModeInfos; + SpringShowModeInfo_t Get_SpringShowModeInfo(CalChartSpringShowModes which) const; + void Set_SpringShowModeInfo(CalChartSpringShowModes which, const SpringShowModeInfo_t& values); + void Clear_SpringShowModeInfo(CalChartSpringShowModes which); + +//#define MAX_SPR_LINES 5 +//#define MAX_YARD_LINES 53 +// + // Yard Lines + static const size_t kYardTextValues = 53; + mutable std::map mYardTextInfos; + wxString Get_yard_text(size_t which) const; + void Set_yard_text(size_t which, const wxString&); + void Clear_yard_text(size_t which); + + static const size_t kSprLineTextValues = 5; + mutable std::map mSprLineTextInfos; + wxString Get_spr_line_text(size_t which) const; + void Set_spr_line_text(size_t which, const wxString&); + void Clear_spr_line_text(size_t which); +}; + + #endif diff --git a/src/core/cc_drawcommand.h b/src/core/cc_drawcommand.h index a98ecaa0..ad0351e9 100644 --- a/src/core/cc_drawcommand.h +++ b/src/core/cc_drawcommand.h @@ -23,6 +23,8 @@ #ifndef _CC_DRAWCOMMAND_H_ #define _CC_DRAWCOMMAND_H_ +#include "cc_coord.h" + struct CC_DrawCommand { typedef enum { Ignore, Line, Arc } DrawType; @@ -41,6 +43,15 @@ struct CC_DrawCommand y2(endy) {} + // Line version + CC_DrawCommand(const CC_coord& start, const CC_coord& end) : + mType(Line), + x1(start.x), + y1(start.y), + x2(end.x), + y2(end.y) + {} + // Arc version CC_DrawCommand(int startx, int starty, int endx, int endy, int centerx, int centery) : mType(Arc), diff --git a/src/core/cc_show.cpp b/src/core/cc_show.cpp index b7a9170f..6b135f21 100644 --- a/src/core/cc_show.cpp +++ b/src/core/cc_show.cpp @@ -417,6 +417,7 @@ void CC_show::SetNumPoints(unsigned num, unsigned columns, const CC_coord& new_m sht->SetNumPoints(num, columns, new_march_position); } numpoints = num; + pt_labels.resize(numpoints); } diff --git a/src/draw.cpp b/src/draw.cpp index ade8ac3b..a116eca0 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -33,56 +33,11 @@ #include "cc_text.h" #include "animate.h" #include "animatecommand.h" +#include "draw_utils.h" #include extern wxFont *pointLabelFont; -// helper classes for saving and restoring state -class SaveAndRestore_DeviceOrigin -{ - wxDC& dc; - wxCoord origX, origY; -public: - SaveAndRestore_DeviceOrigin(wxDC& dc_) : dc(dc_) { dc.GetDeviceOrigin(&origX, &origY); } - ~SaveAndRestore_DeviceOrigin() { dc.SetDeviceOrigin(origX, origY); } -}; - -class SaveAndRestore_UserScale -{ - wxDC& dc; - double origXscale, origYscale; -public: - SaveAndRestore_UserScale(wxDC& dc_) : dc(dc_) { dc.GetUserScale(&origXscale, &origYscale); } - ~SaveAndRestore_UserScale() { dc.SetUserScale(origXscale, origYscale); } -}; - -class SaveAndRestore_TextForeground -{ - wxDC& dc; - wxColour origForegroundColor; -public: - SaveAndRestore_TextForeground(wxDC& dc_) : dc(dc_), origForegroundColor(dc.GetTextForeground()) {} - ~SaveAndRestore_TextForeground() { dc.SetTextForeground(origForegroundColor); } -}; - -class SaveAndRestore_Font -{ - wxDC& dc; - wxFont origFont; -public: - SaveAndRestore_Font(wxDC& dc_) : dc(dc_), origFont(dc.GetFont()) {} - ~SaveAndRestore_Font() { dc.SetFont(origFont); } -}; - -class SaveAndRestore_Brush -{ - wxDC& dc; - wxBrush origBrush; -public: - SaveAndRestore_Brush(wxDC& dc_) : dc(dc_), origBrush(dc.GetBrush()) {} - ~SaveAndRestore_Brush() { dc.SetBrush(origBrush); } -}; - // draw text centered around x (though still at y down) void DrawCenteredText(wxDC& dc, const wxString& text, const wxPoint& pt) { @@ -173,36 +128,40 @@ static const double kLowerNorthArrow[2][3] = { { 1.0 - 52/kSizeX, (570)/kSizeY, static const double kContinuityStart[2] = { 606/kSizeY, 556/kSizeYLandscape }; -void DrawSheetPoints(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, CalChartColors unselectedColor, CalChartColors selectedColor, CalChartColors unselectedTextColor, CalChartColors selectedTextColor) +void DrawSheetPoints(wxDC& dc, const CalChartConfiguration& config, CC_coord origin, const SelectionList& selection_list, unsigned short numberPoints, const std::vector& labels, const CC_sheet& sheet, unsigned ref, CalChartColors unselectedColor, CalChartColors selectedColor, CalChartColors unselectedTextColor, CalChartColors selectedTextColor) { SaveAndRestore_Font orig_font(dc); - wxFont *pointLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(GetConfiguration_DotRatio() * GetConfiguration_NumRatio()), - wxSWISS, wxNORMAL, wxNORMAL); + wxFont *pointLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(config.Get_DotRatio() * config.Get_NumRatio()), wxSWISS, wxNORMAL, wxNORMAL); dc.SetFont(*pointLabelFont); - CC_coord origin = show.GetMode().Offset(); - for (size_t i = 0; i < show.GetNumPoints(); i++) + dc.SetTextForeground(config.Get_CalChartBrushAndPen(COLOR_POINT_TEXT).first.GetColour()); + for (size_t i = 0; i < numberPoints; i++) { - if (show.IsSelected(i)) + wxBrush fillBrush; + if (selection_list.count(i)) { - dc.SetPen(GetCalChartPen(selectedColor)); - dc.SetBrush(GetCalChartBrush(selectedColor)); - dc.SetTextForeground(GetCalChartPen(selectedTextColor).GetColour()); + auto brushAndPen = config.Get_CalChartBrushAndPen(selectedColor); + fillBrush = brushAndPen.first; + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + dc.SetTextForeground(config.Get_CalChartBrushAndPen(selectedTextColor).second.GetColour()); } else { - dc.SetPen(GetCalChartPen(unselectedColor)); - dc.SetBrush(GetCalChartBrush(unselectedColor)); - dc.SetTextForeground(GetCalChartPen(unselectedTextColor).GetColour()); + auto brushAndPen = config.Get_CalChartBrushAndPen(unselectedColor); + fillBrush = brushAndPen.first; + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + dc.SetTextForeground(config.Get_CalChartBrushAndPen(unselectedTextColor).second.GetColour()); } - DrawPoint(sheet.GetPoint(i), dc, ref, origin, show.GetPointLabel(i)); + DrawPoint(sheet.GetPoint(i), dc, config, ref, origin, labels.at(i)); } } -void DrawGhostSheet(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref) { - DrawSheetPoints(dc, show, sheet, ref, COLOR_GHOST_POINT, COLOR_GHOST_POINT_HLIT, COLOR_GHOST_POINT_TEXT, COLOR_GHOST_POINT_HLIT_TEXT); +void DrawGhostSheet(wxDC& dc, const CalChartConfiguration& config, CC_coord origin, const SelectionList& selection_list, unsigned short numberPoints, const std::vector& labels, const CC_sheet& sheet, unsigned ref) { + DrawSheetPoints(dc, config, origin, selection_list, numberPoints, labels, sheet, ref, COLOR_GHOST_POINT, COLOR_GHOST_POINT_HLIT, COLOR_GHOST_POINT_TEXT, COLOR_GHOST_POINT_HLIT_TEXT); } -void Draw(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool primary) +void DrawPoints(wxDC& dc, const CalChartConfiguration& config, CC_coord origin, const SelectionList& selection_list, unsigned short numberPoints, const std::vector& labels, const CC_sheet& sheet, unsigned ref, bool primary) { CalChartColors unselectedColor, selectedColor, unselectedTextColor, selectedTextColor; if (primary) { @@ -216,7 +175,7 @@ void Draw(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref unselectedTextColor = COLOR_REF_POINT_TEXT; selectedTextColor = COLOR_REF_POINT_HILIT_TEXT; } - DrawSheetPoints(dc, show, sheet, ref, unselectedColor, selectedColor, unselectedTextColor, selectedTextColor); + DrawSheetPoints(dc, config, origin, selection_list, numberPoints, labels, sheet, ref, unselectedColor, selectedColor, unselectedTextColor, selectedTextColor); } // draw the continuity starting at a specific offset @@ -406,7 +365,7 @@ void DrawCont(wxDC& dc, const CC_textline_list& print_continuity, const wxRect& #endif } -static std::auto_ptr CreateFieldForPrinting(bool landscape) +static std::unique_ptr CreateFieldForPrinting(bool landscape) { CC_coord bord1(Int2Coord(8),Int2Coord(8)), bord2(Int2Coord(8),Int2Coord(8)); CC_coord siz, off; @@ -421,10 +380,10 @@ static std::auto_ptr CreateFieldForPrinting(bool landscape) off.x = Int2Coord((landscape)?80:48); off.y = Int2Coord(42); - return std::auto_ptr(new ShowModeStandard(wxT("Standard"), siz, off, bord1, bord2, whash, ehash)); + return ShowModeStandard::CreateShowMode(wxT("Standard"), siz, off, bord1, bord2, whash, ehash); } -void DrawForPrinting(wxDC *printerdc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool landscape) +void DrawForPrinting(wxDC *printerdc, const CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool landscape) { unsigned short i; unsigned long x, y; @@ -444,7 +403,7 @@ void DrawForPrinting(wxDC *printerdc, const CalChartDoc& show, const CC_sheet& s } // create a field for drawing: - std::auto_ptr mode = CreateFieldForPrinting(landscape); + auto mode = CreateFieldForPrinting(landscape); int pageW, pageH; dc->GetSize(&pageW, &pageH); @@ -455,18 +414,18 @@ void DrawForPrinting(wxDC *printerdc, const CalChartDoc& show, const CC_sheet& s // draw the field. dc->Clear(); dc->SetLogicalFunction(wxCOPY); - mode->DrawMode(*dc, ShowMode::kPrinting); + mode->DrawMode(*dc, config, ShowMode::kPrinting); const std::vector pts = sheet.GetPoints(); if (!pts.empty()) { - wxFont *pointLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(GetConfiguration_DotRatio() * GetConfiguration_NumRatio()), + wxFont *pointLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(config.Get_DotRatio() * config.Get_NumRatio()), wxSWISS, wxNORMAL, wxNORMAL); dc->SetFont(*pointLabelFont); - circ_r = Float2Coord(GetConfiguration_DotRatio()); + circ_r = Float2Coord(config.Get_DotRatio()); const float offset = circ_r / 2; - const float plineoff = offset * GetConfiguration_PLineRatio(); - const float slineoff = offset * GetConfiguration_SLineRatio(); + const float plineoff = offset * config.Get_PLineRatio(); + const float slineoff = offset * config.Get_SLineRatio(); const float textoff = offset * 1.25; origin = mode->Offset(); for (int selectd = 0; selectd < 2; selectd++) @@ -584,13 +543,14 @@ void DrawForPrinting(wxDC *printerdc, const CalChartDoc& show, const CC_sheet& s } void -DrawPointHelper(const CC_coord& pos, const CC_point& point, wxDC& dc, const wxString& label) +DrawPointHelper(const CC_coord& pos, const CC_point& point, wxDC& dc, const CalChartConfiguration& config, const wxString& label) + { SaveAndRestore_Brush restore(dc); - float circ_r = Float2Coord(GetConfiguration_DotRatio()); + float circ_r = Float2Coord(config.Get_DotRatio()); float offset = circ_r / 2; - float plineoff = offset * GetConfiguration_PLineRatio(); - float slineoff = offset * GetConfiguration_SLineRatio(); + float plineoff = offset * config.Get_PLineRatio(); + float slineoff = offset * config.Get_SLineRatio(); float textoff = offset * 1.25; long x = pos.x; @@ -646,25 +606,26 @@ DrawPointHelper(const CC_coord& pos, const CC_point& point, wxDC& dc, const wxSt } void -DrawPoint(const CC_point& point, wxDC& dc, unsigned reference, const CC_coord& origin, const wxString& label) +DrawPoint(const CC_point& point, wxDC& dc, const CalChartConfiguration& config, unsigned reference, const CC_coord& origin, const wxString& label) { - DrawPointHelper(point.GetPos(reference) + origin, point, dc, label); + DrawPointHelper(point.GetPos(reference) + origin, point, dc, config, label); } void -DrawPhatomPoints(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, const std::map& positions) +DrawPhatomPoints(wxDC& dc, const CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, const std::map& positions) { SaveAndRestore_Font orig_font(dc); - wxFont *pointLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(GetConfiguration_DotRatio() * GetConfiguration_NumRatio()), wxSWISS, wxNORMAL, wxNORMAL); + wxFont *pointLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(config.Get_DotRatio() * config.Get_NumRatio()), wxSWISS, wxNORMAL, wxNORMAL); dc.SetFont(*pointLabelFont); CC_coord origin = show.GetMode().Offset(); - dc.SetPen(GetCalChartPen(COLOR_GHOST_POINT)); - dc.SetBrush(GetCalChartBrush(COLOR_GHOST_POINT)); - dc.SetTextForeground(GetCalChartPen(COLOR_GHOST_POINT_TEXT).GetColour()); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_GHOST_POINT); + dc.SetPen(brushAndPen.second); + dc.SetBrush(brushAndPen.first); + dc.SetTextForeground(config.Get_CalChartBrushAndPen(COLOR_GHOST_POINT_TEXT).first.GetColour()); for (auto& i : positions) { - DrawPointHelper(i.second + origin, sheet.GetPoint(i.first), dc, show.GetPointLabel(i.first)); + DrawPointHelper(i.second + origin, sheet.GetPoint(i.first), dc, config, show.GetPointLabel(i.first)); } } @@ -686,13 +647,14 @@ void DrawCC_DrawCommandList(wxDC& dc, const std::vector& draw_co } } -void DrawPath(wxDC& dc, const std::vector& draw_commands, const CC_coord& end) +void DrawPath(wxDC& dc, const CalChartConfiguration& config, const std::vector& draw_commands, const CC_coord& end) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetCalChartPen(COLOR_PATHS)); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_PATHS); + dc.SetPen(brushAndPen.second); DrawCC_DrawCommandList(dc, draw_commands); - dc.SetBrush(GetCalChartBrush(COLOR_PATHS)); - float circ_r = Float2Coord(GetConfiguration_DotRatio()); + dc.SetBrush(brushAndPen.first); + float circ_r = Float2Coord(config.Get_DotRatio()); dc.DrawEllipse(end.x - circ_r/2, end.y - circ_r/2, circ_r, circ_r); } diff --git a/src/draw.h b/src/draw.h index d1a5a0ae..5d1d4a65 100644 --- a/src/draw.h +++ b/src/draw.h @@ -23,8 +23,10 @@ #ifndef __DRAW_H__ #define __DRAW_H__ +#include "cc_show.h" #include #include +#include #include #include "confgr.h" @@ -37,15 +39,16 @@ class CC_coord; struct CC_DrawCommand; class CalChartDoc; class CC_textline; +class CalChartConfiguration; typedef std::vector CC_textline_list; // draw the continuity starting at a specific offset -void DrawSheetPoints(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, CalChartColors unselectedColor, CalChartColors selectedColor, CalChartColors unselectedTextColor, CalChartColors selectedTextColor); -void DrawGhostSheet(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref); +void DrawPoints(wxDC& dc, const CalChartConfiguration& config, CC_coord origin, const SelectionList& selection_list, unsigned short numberPoints, const std::vector& labels, const CC_sheet& sheet, unsigned ref, bool primary); +void DrawGhostSheet(wxDC& dc, const CalChartConfiguration& config, CC_coord origin, const SelectionList& selection_list, unsigned short numberPoints, const std::vector& labels, const CC_sheet& sheet, unsigned ref); void Draw(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool primary); void DrawCont(wxDC& dc, const CC_textline_list& print_continuity, const wxRect& bounding, bool landscape); -void DrawForPrinting(wxDC *dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool landscape); -void DrawPhatomPoints(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, const std::map& positions); +void DrawForPrinting(wxDC *dc, const CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool landscape); +void DrawPhatomPoints(wxDC& dc, const CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, const std::map& positions); void PrintStandard(std::ostream& buffer, const CC_sheet& sheet); void PrintSpringshow(std::ostream& buffer, const CC_sheet& sheet); @@ -55,9 +58,9 @@ void PrintCont(std::ostream& buffer, const CC_sheet& sheet); // We break this out of the class to make CalChart internals more cross platform // Draw the point -void DrawPoint(const CC_point& point, wxDC& dc, unsigned reference, const CC_coord& origin, const wxString& label); +void DrawPoint(const CC_point& point, wxDC& dc, const CalChartConfiguration& config, unsigned reference, const CC_coord& origin, const wxString& label); -void DrawPath(wxDC& dc, const std::vector& draw_commands, const CC_coord& end); +void DrawPath(wxDC& dc, const CalChartConfiguration& config, const std::vector& draw_commands, const CC_coord& end); void DrawCC_DrawCommandList(wxDC& dc, const std::vector& draw_commands); //void DrawShape(wxDC& dc, const CC_shape& shape, float x, float y); diff --git a/src/draw_utils.h b/src/draw_utils.h new file mode 100644 index 00000000..5a07d1a3 --- /dev/null +++ b/src/draw_utils.h @@ -0,0 +1,74 @@ +/* + * draw.cpp + * Member functions for drawing stuntsheets + */ + +/* + Copyright (C) 1995-2011 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __DRAW_UTILS_H__ +#define __DRAW_UTILS_H__ + +#include + +// helper classes for saving and restoring state +class SaveAndRestore_DeviceOrigin +{ + wxDC& dc; + wxCoord origX, origY; +public: + SaveAndRestore_DeviceOrigin(wxDC& dc_) : dc(dc_) { dc.GetDeviceOrigin(&origX, &origY); } + ~SaveAndRestore_DeviceOrigin() { dc.SetDeviceOrigin(origX, origY); } +}; + +class SaveAndRestore_UserScale +{ + wxDC& dc; + double origXscale, origYscale; +public: + SaveAndRestore_UserScale(wxDC& dc_) : dc(dc_) { dc.GetUserScale(&origXscale, &origYscale); } + ~SaveAndRestore_UserScale() { dc.SetUserScale(origXscale, origYscale); } +}; + +class SaveAndRestore_TextForeground +{ + wxDC& dc; + wxColour origForegroundColor; +public: + SaveAndRestore_TextForeground(wxDC& dc_) : dc(dc_), origForegroundColor(dc.GetTextForeground()) {} + ~SaveAndRestore_TextForeground() { dc.SetTextForeground(origForegroundColor); } +}; + +class SaveAndRestore_Font +{ + wxDC& dc; + wxFont origFont; +public: + SaveAndRestore_Font(wxDC& dc_) : dc(dc_), origFont(dc.GetFont()) {} + ~SaveAndRestore_Font() { dc.SetFont(origFont); } +}; + +class SaveAndRestore_Brush +{ + wxDC& dc; + wxBrush origBrush; +public: + SaveAndRestore_Brush(wxDC& dc_) : dc(dc_), origBrush(dc.GetBrush()) {} + ~SaveAndRestore_Brush() { dc.SetBrush(origBrush); } +}; + +#endif // __DRAW_UTILS_H__ diff --git a/src/field_canvas.cpp b/src/field_canvas.cpp index 5d983edf..dacd57ab 100644 --- a/src/field_canvas.cpp +++ b/src/field_canvas.cpp @@ -66,12 +66,20 @@ FieldCanvas::~FieldCanvas(void) // Define the repainting behaviour void FieldCanvas::OnPaint(wxPaintEvent& event) +{ + const auto& config = CalChartConfiguration::GetGlobalConfig(); + OnPaint(event, config); + +} + +void +FieldCanvas::OnPaint(wxPaintEvent& event, const CalChartConfiguration& config) { wxBufferedPaintDC dc(this); PrepareDC(dc); // draw the background - PaintBackground(dc); + PaintBackground(dc, config); // draw Background Image if (mBackgroundImage) { @@ -85,7 +93,7 @@ FieldCanvas::OnPaint(wxPaintEvent& event) if (curr_shape) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetCalChartPen(COLOR_SHAPES)); + dc.SetPen(config.Get_CalChartBrushAndPen(COLOR_SHAPES).second); CC_coord origin = mView->GetShowFieldOffset(); for (auto i=shape_list.begin(); i != shape_list.end(); @@ -97,11 +105,11 @@ FieldCanvas::OnPaint(wxPaintEvent& event) } void -FieldCanvas::PaintBackground(wxDC& dc) +FieldCanvas::PaintBackground(wxDC& dc, const CalChartConfiguration& config) { // draw the background dc.SetBackgroundMode(wxTRANSPARENT); - dc.SetBackground(GetCalChartBrush(COLOR_FIELD)); + dc.SetBackground(config.Get_CalChartBrushAndPen(COLOR_FIELD).first); dc.Clear(); } diff --git a/src/field_canvas.h b/src/field_canvas.h index d426a683..e1c802c0 100644 --- a/src/field_canvas.h +++ b/src/field_canvas.h @@ -39,6 +39,7 @@ class CC_shape; class BackgroundImage; class CC_coord; class Matrix; +class CalChartConfiguration; // Field Canvas controls how to paint and the first line control of user input class FieldCanvas : public ClickDragCtrlScrollCanvas @@ -94,7 +95,8 @@ class FieldCanvas : public ClickDragCtrlScrollCanvas std::shared_ptr curr_shape; // Background Picture - void PaintBackground(wxDC& dc); + void OnPaint(wxPaintEvent& event, const CalChartConfiguration& config); + void PaintBackground(wxDC& dc, const CalChartConfiguration& config); std::unique_ptr mBackgroundImage; std::map mMovePoints; std::function(const CC_coord&)> mTransformer; diff --git a/src/field_frame.cpp b/src/field_frame.cpp index c7cc4482..7770434f 100644 --- a/src/field_frame.cpp +++ b/src/field_frame.cpp @@ -171,7 +171,7 @@ END_EVENT_TABLE() class MyPrintout : public wxPrintout { public: - MyPrintout(const wxString& title, const CalChartDoc& show) : wxPrintout(title), mShow(show) {} + MyPrintout(const wxString& title, const CalChartDoc& show, const CalChartConfiguration& config_) : wxPrintout(title), mShow(show), config(config_) {} virtual ~MyPrintout() {} virtual bool HasPage(int pageNum) { return pageNum <= mShow.GetNumSheets(); } virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) @@ -188,19 +188,21 @@ class MyPrintout : public wxPrintout int size = gPrintDialogData->GetPrintData().GetOrientation(); - DrawForPrinting(dc, mShow, *sheet, 0, 2 == size); + DrawForPrinting(dc, config, mShow, *sheet, 0, 2 == size); return true; } const CalChartDoc& mShow; + const CalChartConfiguration& config; }; // Main frame constructor -FieldFrame::FieldFrame(wxDocument* doc, wxView* view, wxDocParentFrame *frame, const wxPoint& pos, const wxSize& size): +FieldFrame::FieldFrame(wxDocument* doc, wxView* view, CalChartConfiguration& config_, wxDocParentFrame *frame, const wxPoint& pos, const wxSize& size): wxDocChildFrame(doc, view, frame, -1, wxT("CalChart"), pos, size), mCanvas(NULL), -mAnimationFrame(NULL) +mAnimationFrame(NULL), +config(config_) { this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) ); // Give it an icon @@ -290,7 +292,7 @@ mAnimationFrame(NULL) // Add the field canvas this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENU)); - mCanvas = new FieldCanvas(view, this, GetConfiguration_FieldFrameZoom()); + mCanvas = new FieldCanvas(view, this, config.Get_FieldFrameZoom()); // set scroll rate 1 to 1, so we can have even scrolling of whole field mCanvas->SetScrollRate(1, 1); @@ -329,7 +331,7 @@ mAnimationFrame(NULL) if (mZoomBox) { wxString zoomtxt; - zoomtxt.sprintf("%d%%", (int)(GetConfiguration_FieldFrameZoom()*100)); + zoomtxt.sprintf("%d%%", (int)(config.Get_FieldFrameZoom()*100)); mZoomBox->SetValue(zoomtxt); } sizer1->Add(mZoomBox, centerWidget); @@ -420,7 +422,7 @@ void FieldFrame::OnCmdPrint(wxCommandEvent& event) { // grab our current page setup. wxPrinter printer(gPrintDialogData); - MyPrintout printout(wxT("My Printout"), *GetShow()); + MyPrintout printout(wxT("My Printout"), *GetShow(), config); wxPrintDialogData& printDialog = printer.GetPrintDialogData(); int minPage, maxPage, pageFrom, pageTo; @@ -450,8 +452,8 @@ void FieldFrame::OnCmdPrintPreview(wxCommandEvent& event) { // grab our current page setup. wxPrintPreview *preview = new wxPrintPreview( - new MyPrintout(wxT("My Printout"), *GetShow()), - new MyPrintout(wxT("My Printout"), *GetShow()), + new MyPrintout(wxT("My Printout"), *GetShow(), config), + new MyPrintout(wxT("My Printout"), *GetShow(), config), gPrintDialogData); if (!preview->Ok()) { @@ -484,7 +486,7 @@ void FieldFrame::OnCmdLegacyPrint(wxCommandEvent& event) PrintPostScriptDialog dialog(static_cast(GetDocument()), false, this); if (dialog.ShowModal() == wxID_OK) { - dialog.PrintShow(); + dialog.PrintShow(config); } } } @@ -496,7 +498,7 @@ void FieldFrame::OnCmdLegacyPrintEPS(wxCommandEvent& event) PrintPostScriptDialog dialog(static_cast(GetDocument()), true, this); if (dialog.ShowModal() == wxID_OK) { - dialog.PrintShow(); + dialog.PrintShow(config); } } } @@ -763,7 +765,7 @@ void FieldFrame::OnCmdAnimate(wxCommandEvent& event) } else if (GetShow()) { - mAnimationFrame = new AnimationFrame([this]() { this->ClearAnimationFrame(); }, GetShow(), GetView(), this, wxSize(GetConfiguration_AnimationFrameWidth(), GetConfiguration_AnimationFrameHeight())); + mAnimationFrame = new AnimationFrame([this]() { this->ClearAnimationFrame(); }, GetShow(), config, GetView(), this, wxSize(config.Get_AnimationFrameWidth(), config.Get_AnimationFrameHeight())); } } @@ -1042,8 +1044,8 @@ void FieldFrame::OnSize(wxSizeEvent& event) // HACK: Prevent width and height from growing out of control int w = event.GetSize().GetWidth(); int h = event.GetSize().GetHeight(); - SetConfiguration_FieldFrameWidth((w > 1200) ? 1200 : w); - SetConfiguration_FieldFrameHeight((h > 700) ? 700 : h); + config.Set_FieldFrameWidth((w > 1200) ? 1200 : w); + config.Set_FieldFrameHeight((h > 700) ? 700 : h); super::OnSize(event); } @@ -1176,10 +1178,16 @@ void FieldFrame::SetMode() { wxArrayString modeStrings; unsigned whichMode = 0, tmode = 0; - for (auto mode = wxGetApp().GetModeList().begin(); mode != wxGetApp().GetModeList().end(); ++mode, ++tmode) + for (auto mode : kShowModeStrings) { - modeStrings.Add((*mode)->GetName()); - if ((*mode)->GetName() == GetShow()->GetMode().GetName()) + modeStrings.Add(mode); + if (mode == GetShow()->GetMode().GetName()) + whichMode = tmode; + } + for (auto mode : kSpringShowModeStrings) + { + modeStrings.Add(mode); + if (mode == GetShow()->GetMode().GetName()) whichMode = tmode; } wxSingleChoiceDialog dialog(this, @@ -1224,7 +1232,7 @@ void FieldFrame::zoom_callback(wxCommandEvent& event) { zoom_amount = mCanvas->ZoomToFitFactor(); } - SetConfiguration_FieldFrameZoom(zoom_amount); + config.Set_FieldFrameZoom(zoom_amount); mCanvas->SetZoom(zoom_amount); } @@ -1253,7 +1261,7 @@ void FieldFrame::zoom_callback_textenter(wxCommandEvent& event) // return if not valid return; } - SetConfiguration_FieldFrameZoom(zoom_amount); + config.Set_FieldFrameZoom(zoom_amount); // set the text to have '%' appended zoomtxt += wxT("%"); mZoomBox->SetValue(zoomtxt); diff --git a/src/field_frame.h b/src/field_frame.h index 57fda87f..3827b066 100644 --- a/src/field_frame.h +++ b/src/field_frame.h @@ -35,6 +35,7 @@ class CC_show; class FieldCanvas; class FieldView; class CalChartDoc; +class CalChartConfiguration; // Define the main editing frame class FieldFrame : public wxDocChildFrame @@ -42,7 +43,7 @@ class FieldFrame : public wxDocChildFrame typedef wxDocChildFrame super; public: // FieldFrame will own the show that is passed in - FieldFrame(wxDocument* doc, wxView* view, wxDocParentFrame *frame, const wxPoint& pos, const wxSize& size); + FieldFrame(wxDocument* doc, wxView* view, CalChartConfiguration& config_, wxDocParentFrame *frame, const wxPoint& pos, const wxSize& size); ~FieldFrame(); void OnCmdAppend(wxCommandEvent& event); @@ -150,6 +151,7 @@ class FieldFrame : public wxDocChildFrame FieldCanvas *mCanvas; wxWindow *mAnimationFrame; + CalChartConfiguration& config; void ClearAnimationFrame(); DECLARE_EVENT_TABLE() diff --git a/src/field_view.cpp b/src/field_view.cpp index ae466da5..4d7dd483 100644 --- a/src/field_view.cpp +++ b/src/field_view.cpp @@ -45,7 +45,8 @@ IMPLEMENT_DYNAMIC_CLASS(FieldView, wxView) FieldView::FieldView() : mFrame(NULL), mDrawPaths(false), -mCurrentReferencePoint(0) +mCurrentReferencePoint(0), +mConfig(CalChartConfiguration::GetGlobalConfig()) { } @@ -62,7 +63,7 @@ FieldView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) #if defined(BUILD_FOR_VIEWER) && (BUILD_FOR_VIEWER != 0) mFrame = new AnimationFrame(NULL, doc, this, wxStaticCast(wxGetApp().GetTopWindow(), wxDocParentFrame)); #else - mFrame = new FieldFrame(doc, this, wxStaticCast(wxGetApp().GetTopWindow(), wxDocParentFrame), wxPoint(50, 50), wxSize(GetConfiguration_FieldFrameWidth(), GetConfiguration_FieldFrameHeight())); + mFrame = new FieldFrame(doc, this, mConfig, wxStaticCast(wxGetApp().GetTopWindow(), wxDocParentFrame), wxPoint(50, 50), wxSize(mConfig.Get_FieldFrameWidth(), mConfig.Get_FieldFrameHeight())); #endif mFrame->Show(true); @@ -77,13 +78,15 @@ FieldView::OnDraw(wxDC *dc) { if (mShow) { - mShow->GetMode().DrawMode(*dc, ShowMode::kFieldView); + // draw the field + CC_coord origin = mShow->GetMode().Offset(); + mShow->GetMode().DrawMode(*dc, mConfig, ShowMode::kFieldView); CC_sheet* ghostSheet = mGhostModule.getGhostSheet(mShow, GetCurrentSheetNum()); if (ghostSheet != nullptr) { - DrawGhostSheet(*dc, *mShow, *ghostSheet, 0); + DrawGhostSheet(*dc, mConfig, origin, SelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *ghostSheet, 0); } CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); @@ -91,12 +94,12 @@ FieldView::OnDraw(wxDC *dc) { if (mCurrentReferencePoint > 0) { - Draw(*dc, *mShow, *mShow->GetCurrentSheet(), 0, false); - Draw(*dc, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + DrawPoints(*dc, mConfig, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), 0, false); + DrawPoints(*dc, mConfig, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } else { - Draw(*dc, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + DrawPoints(*dc, mConfig, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } DrawPaths(*dc, *sheet); } @@ -108,8 +111,7 @@ FieldView::OnDraw(wxDC *dc) void FieldView::DrawOtherPoints(wxDC &dc, const std::map& positions) { - - DrawPhatomPoints(dc, *mShow, *mShow->GetCurrentSheet(), positions); + DrawPhatomPoints(dc, mConfig, *mShow, *mShow->GetCurrentSheet(), positions); } void @@ -186,10 +188,10 @@ FieldView::OnWizardSetup(CalChartDoc& show) auto labels = page1->GetLabels(); std::vector tlabels(labels.begin(), labels.end()); show.SetPointLabel(tlabels); - ShowMode *newmode = ShowModeList_Find(wxGetApp().GetModeList(), page2->GetValue()); + auto newmode = wxGetApp().GetMode(page2->GetValue()); if (newmode) { - show.SetMode(newmode); + show.SetMode(std::move(newmode)); } show.SetDescr(page3->GetValue().ToStdString()); } @@ -353,7 +355,7 @@ FieldView::DoImportPrintableContinuity(const wxString& file) int FieldView::FindPoint(CC_coord pos) const { - return mShow->GetCurrentSheet()->FindPoint(pos.x, pos.y, Float2Coord(GetConfiguration_DotRatio()), mCurrentReferencePoint); + return mShow->GetCurrentSheet()->FindPoint(pos.x, pos.y, Float2Coord(mConfig.Get_DotRatio()), mCurrentReferencePoint); } CC_coord @@ -459,7 +461,7 @@ FieldView::DrawPaths(wxDC& dc, const CC_sheet& sheet) mAnimation->GotoSheet(mShow->GetCurrentSheetNum()); for (auto point = mShow->GetSelectionList().begin(); point != mShow->GetSelectionList().end(); ++point) { - DrawPath(dc, mAnimation->GenPathToDraw(*point, origin), mAnimation->EndPosition(*point, origin)); + DrawPath(dc, mConfig, mAnimation->GenPathToDraw(*point, origin), mAnimation->EndPosition(*point, origin)); } } } diff --git a/src/field_view.h b/src/field_view.h index e6369ff6..54f241e6 100644 --- a/src/field_view.h +++ b/src/field_view.h @@ -36,6 +36,7 @@ class FieldFrame; class AnimationFrame; class Animation; class Matrix; +class CalChartConfiguration; // Field: // Field is the editable overhead view of the marchers on the field. @@ -119,6 +120,7 @@ class FieldView : public wxView CalChartDoc* mShow; unsigned mCurrentReferencePoint; + CalChartConfiguration& mConfig; DECLARE_DYNAMIC_CLASS(FieldView) }; diff --git a/src/modes.cpp b/src/modes.cpp index 6f320ecb..4ec8774f 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -61,7 +61,7 @@ ShowMode::ClipPosition(const CC_coord& pos) const wxImage -ShowMode::GetOmniLinesImage() const +ShowMode::GetOmniLinesImage(const CalChartConfiguration& config) const { auto fieldsize = FieldSize(); wxBitmap bmp(fieldsize.x, fieldsize.y, 32); @@ -69,7 +69,7 @@ ShowMode::GetOmniLinesImage() const dc.SelectObject(bmp); dc.SetBackground(*wxTRANSPARENT_BRUSH); dc.Clear(); - DrawMode(dc, ShowMode::kOmniView); + DrawMode(dc, config, ShowMode::kOmniView); return bmp.ConvertToImage(); } @@ -94,15 +94,15 @@ ShowMode::ShowType ShowModeStandard::GetType() const } void -ShowMode::DrawMode(wxDC& dc, HowToDraw howToDraw) const +ShowMode::DrawMode(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const { switch (howToDraw) { case kFieldView: case kAnimation: case kOmniView: - dc.SetPen(GetCalChartPen(COLOR_FIELD_DETAIL)); - dc.SetTextForeground(GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + dc.SetPen(config.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); + dc.SetTextForeground(config.Get_CalChartBrushAndPen(COLOR_FIELD_TEXT).second.GetColour()); break; case kPrinting: dc.SetPen(*wxBLACK_PEN); @@ -110,10 +110,10 @@ ShowMode::DrawMode(wxDC& dc, HowToDraw howToDraw) const break; } // draw the field - DrawHelper(dc, howToDraw); + DrawHelper(dc, config, howToDraw); } -void ShowModeStandard::DrawHelper(wxDC& dc, HowToDraw howToDraw) const +void ShowModeStandard::DrawHelper(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const { wxPoint points[5]; auto fieldsize = FieldSize(); @@ -196,16 +196,16 @@ void ShowModeStandard::DrawHelper(wxDC& dc, HowToDraw howToDraw) const } // Draw labels - wxFont *yardLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(GetConfiguration_YardsSize()), + wxFont *yardLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(config.Get_YardsSize()), wxSWISS, wxNORMAL, wxNORMAL); dc.SetFont(*yardLabelFont); for (int i = 0; (howToDraw == kFieldView || howToDraw == kOmniView) && i < Coord2Int(fieldsize.x)/8+1; i++) { CC_coord fieldedge = mOffset - mBorder1; wxCoord textw, texth, textd; - dc.GetTextExtent(yard_text[i+(-Coord2Int(fieldedge.x)+(MAX_YARD_LINES-1)*4)/8], &textw, &texth, &textd); - dc.DrawText(yard_text[i+(-Coord2Int(fieldedge.x)+(MAX_YARD_LINES-1)*4)/8], Int2Coord(i*8) - textw/2 + border1.x, border1.y - texth + ((howToDraw == kOmniView) ? Int2Coord(8) : 0)); - dc.DrawText(yard_text[i+(-Coord2Int(fieldedge.x)+(MAX_YARD_LINES-1)*4)/8], Int2Coord(i*8) - textw/2 + border1.x, border1.y + fieldsize.y - ((howToDraw == kOmniView) ? Int2Coord(8) : 0)); + dc.GetTextExtent(config.Get_yard_text(i+(-Coord2Int(fieldedge.x)+(CalChartConfiguration::kYardTextValues-1)*4)/8), &textw, &texth, &textd); + dc.DrawText(config.Get_yard_text(i+(-Coord2Int(fieldedge.x)+(CalChartConfiguration::kYardTextValues-1)*4)/8), Int2Coord(i*8) - textw/2 + border1.x, border1.y - texth + ((howToDraw == kOmniView) ? Int2Coord(8) : 0)); + dc.DrawText(config.Get_yard_text(i+(-Coord2Int(fieldedge.x)+(CalChartConfiguration::kYardTextValues-1)*4)/8), Int2Coord(i*8) - textw/2 + border1.x, border1.y + fieldsize.y - ((howToDraw == kOmniView) ? Int2Coord(8) : 0)); } } @@ -243,7 +243,7 @@ ShowMode::ShowType ShowModeSprShow::GetType() const } -void ShowModeSprShow::DrawHelper(wxDC& dc, HowToDraw howToDraw) const +void ShowModeSprShow::DrawHelper(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const { wxPoint points[2]; CC_coord fieldsize = mSize - mBorder1 - mBorder2; @@ -289,44 +289,111 @@ void ShowModeSprShow::DrawHelper(wxDC& dc, HowToDraw howToDraw) const } // Draw labels - wxFont *yardLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(GetConfiguration_YardsSize()), + wxFont *yardLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(config.Get_YardsSize()), wxSWISS, wxNORMAL, wxNORMAL); dc.SetFont(*yardLabelFont); for (int i = 0; howToDraw == kFieldView && i < Coord2Int(fieldsize.x)/8+1; i++) { wxCoord textw, texth, textd; - dc.GetTextExtent(yard_text[i+(steps_x+(MAX_YARD_LINES-1)*4)/8], &textw, &texth, &textd); + dc.GetTextExtent(config.Get_yard_text(i+(steps_x+(CalChartConfiguration::kYardTextValues-1)*4)/8), &textw, &texth, &textd); if (which_yards & SPR_YARD_ABOVE) - dc.DrawText(yard_text[i+(steps_x+(MAX_YARD_LINES-1)*4)/8], Int2Coord(i*8) - textw/2 + mBorder1.x, mBorder1.y - texth); + dc.DrawText(config.Get_yard_text(i+(steps_x+(CalChartConfiguration::kYardTextValues-1)*4)/8), Int2Coord(i*8) - textw/2 + mBorder1.x, mBorder1.y - texth); if (which_yards & SPR_YARD_BELOW) - dc.DrawText(yard_text[i+(steps_x+(MAX_YARD_LINES-1)*4)/8], Int2Coord(i*8) - textw/2 + mBorder1.x, mSize.y - mBorder2.y); + dc.DrawText(config.Get_yard_text(i+(steps_x+(CalChartConfiguration::kYardTextValues-1)*4)/8), Int2Coord(i*8) - textw/2 + mBorder1.x, mSize.y - mBorder2.y); } for (int i = 0; howToDraw == kFieldView && i <= Coord2Int(fieldsize.y); i+=8) { wxCoord textw, texth, textd; - dc.GetTextExtent(spr_line_text[i/8], &textw, &texth, &textd); + dc.GetTextExtent(config.Get_spr_line_text(i/8), &textw, &texth, &textd); if (which_yards & SPR_YARD_LEFT) - dc.DrawText(spr_line_text[i/8], mBorder1.x - textw, mBorder1.y - texth/2 + Int2Coord(i)); + dc.DrawText(config.Get_spr_line_text(i/8), mBorder1.x - textw, mBorder1.y - texth/2 + Int2Coord(i)); if (which_yards & SPR_YARD_RIGHT) - dc.DrawText(spr_line_text[i/8], fieldsize.x + mBorder1.x, mBorder1.y - texth/2 + Int2Coord(i)); + dc.DrawText(config.Get_spr_line_text(i/8), fieldsize.x + mBorder1.x, mBorder1.y - texth/2 + Int2Coord(i)); } } -class FindByName +std::unique_ptr +ShowMode::GetMode(const wxString& which) { -public: - FindByName(wxString name) : mName(name) {} - template - bool operator()(const T& a) { return mName == a->GetName(); } -private: - wxString mName; -}; - -ShowMode* -ShowModeList_Find(const ShowModeList& showModes, const wxString& which) + auto iter = std::find(std::begin(kShowModeStrings), std::end(kShowModeStrings), which); + if (iter != std::end(kShowModeStrings)) + { + return ShowModeStandard::CreateShowMode(which, CalChartConfiguration::GetGlobalConfig().Get_ShowModeInfo(static_cast(std::distance(std::begin(kShowModeStrings), iter)))); + } + iter = std::find(std::begin(kSpringShowModeStrings), std::end(kSpringShowModeStrings), which); + if (iter != std::end(kSpringShowModeStrings)) + { + return ShowModeSprShow::CreateSpringShowMode(which, CalChartConfiguration::GetGlobalConfig().Get_SpringShowModeInfo(static_cast(std::distance(std::begin(kSpringShowModeStrings), iter)))); + } + return {}; +} + + +std::unique_ptr +ShowModeStandard::CreateShowMode(const wxString& which, const CalChartConfiguration::ShowModeInfo_t& values) { - ShowModeList::const_iterator i; - if ((i = std::find_if(showModes.begin(), showModes.end(), FindByName(which))) != showModes.end()) - return (*i).get(); - return NULL; + unsigned short whash = values[0]; + unsigned short ehash = values[1]; + CC_coord bord1, bord2; + bord1.x = Int2Coord(values[2]); + bord1.y = Int2Coord(values[3]); + bord2.x = Int2Coord(values[4]); + bord2.y = Int2Coord(values[5]); + CC_coord size, offset; + offset.x = Int2Coord(-values[6]); + offset.y = Int2Coord(-values[7]); + size.x = Int2Coord(values[8]); + size.y = Int2Coord(values[9]); + return std::unique_ptr(new ShowModeStandard(which, size, offset, bord1, bord2, whash, ehash)); } + +std::unique_ptr +ShowModeStandard::CreateShowMode(const wxString& name, + CC_coord size, + CC_coord offset, + CC_coord border1, + CC_coord border2, + unsigned short whash, + unsigned short ehash) +{ + return std::unique_ptr(new ShowModeStandard(name, size, offset, border1, border2, whash, ehash)); +} + +std::unique_ptr +ShowModeSprShow::CreateSpringShowMode(const wxString& which, const CalChartConfiguration::SpringShowModeInfo_t& values) +{ + unsigned char which_spr_yards = values[0]; + CC_coord bord1, bord2; + bord1.x = Int2Coord(values[1]); + bord1.y = Int2Coord(values[2]); + bord2.x = Int2Coord(values[3]); + bord2.y = Int2Coord(values[4]); + + short mode_steps_x = values[5]; + short mode_steps_y = values[6]; + short mode_steps_w = values[7]; + short mode_steps_h = values[8]; + short eps_stage_x = values[9]; + short eps_stage_y = values[10]; + short eps_stage_w = values[11]; + short eps_stage_h = values[12]; + short eps_field_x = values[13]; + short eps_field_y = values[14]; + short eps_field_w = values[15]; + short eps_field_h = values[16]; + short eps_text_left = values[17]; + short eps_text_right = values[18]; + short eps_text_top = values[19]; + short eps_text_bottom = values[20]; + return std::unique_ptr(new ShowModeSprShow(which, bord1, bord2, + which_spr_yards, + mode_steps_x, mode_steps_y, + mode_steps_w, mode_steps_h, + eps_stage_x, eps_stage_y, + eps_stage_w, eps_stage_h, + eps_field_x, eps_field_y, + eps_field_w, eps_field_h, + eps_text_left, eps_text_right, + eps_text_top, eps_text_bottom)); +} + diff --git a/src/modes.h b/src/modes.h index d4a43c27..87edab33 100644 --- a/src/modes.h +++ b/src/modes.h @@ -24,6 +24,7 @@ #define _MODES_H_ #include "cc_coord.h" +#include "confgr.h" #include #include @@ -39,14 +40,13 @@ class ShowMode { public: typedef enum { SHOW_STANDARD, SHOW_SPRINGSHOW } ShowType; - - ShowMode(const wxString& name, - const CC_coord& size, - const CC_coord& offset, - const CC_coord& border1, - const CC_coord& border2); + + // to find a specific Show: + static std::unique_ptr GetMode(const wxString& which); virtual ~ShowMode(); +public: + virtual ShowType GetType() const = 0; inline const CC_coord& Offset() const { return mOffset; }; inline CC_coord FieldOffset() const { return -(mOffset-mBorder1); } @@ -65,12 +65,19 @@ class ShowMode kPrinting, kOmniView } HowToDraw; - void DrawMode(wxDC& dc, HowToDraw howToDraw) const; - wxImage GetOmniLinesImage() const; + void DrawMode(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const; + + wxImage GetOmniLinesImage(const CalChartConfiguration& config) const; protected: - virtual void DrawHelper(wxDC& dc, HowToDraw howToDraw) const = 0; + // Users shouldn't create show modes, it should be done through derived classes + ShowMode(const wxString& name, + const CC_coord& size, + const CC_coord& offset, + const CC_coord& border1, + const CC_coord& border2); + virtual void DrawHelper(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const = 0; const CC_coord mOffset; const CC_coord mSize; @@ -83,6 +90,16 @@ class ShowMode class ShowModeStandard : public ShowMode { public: + static std::unique_ptr CreateShowMode(const wxString& which, const CalChartConfiguration::ShowModeInfo_t& values); + static std::unique_ptr CreateShowMode(const wxString& name, + CC_coord size, + CC_coord offset, + CC_coord border1, + CC_coord border2, + unsigned short whash, + unsigned short ehash); + +private: ShowModeStandard(const wxString& name, CC_coord size, CC_coord offset, @@ -90,6 +107,7 @@ class ShowModeStandard : public ShowMode CC_coord border2, unsigned short whash, unsigned short ehash); +public: virtual ~ShowModeStandard(); virtual ShowType GetType() const; @@ -97,7 +115,7 @@ class ShowModeStandard : public ShowMode inline unsigned short HashE() const { return mHashE; } protected: - virtual void DrawHelper(wxDC& dc, HowToDraw howToDraw) const; + virtual void DrawHelper(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const; private: const unsigned short mHashW, mHashE; @@ -106,6 +124,9 @@ class ShowModeStandard : public ShowMode class ShowModeSprShow : public ShowMode { public: + static std::unique_ptr CreateSpringShowMode(const wxString& which, const CalChartConfiguration::SpringShowModeInfo_t& values); + +private: // Look at calchart.cfg for description of arguments ShowModeSprShow(const wxString& name, CC_coord border1, CC_coord border2, unsigned char which, @@ -117,6 +138,7 @@ class ShowModeSprShow : public ShowMode short fld_w, short fld_h, short txt_l, short txt_r, short txt_tp, short txt_bm); +public: virtual ~ShowModeSprShow(); virtual ShowType GetType() const; @@ -139,7 +161,7 @@ class ShowModeSprShow : public ShowMode inline short TextBottom() const { return text_bottom; } protected: - virtual void DrawHelper(wxDC& dc, HowToDraw howToDraw) const; + virtual void DrawHelper(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const; private: unsigned char which_yards; @@ -149,9 +171,4 @@ class ShowModeSprShow : public ShowMode short text_left, text_right, text_top, text_bottom; }; -typedef std::list > ShowModeList; - -ShowMode* -ShowModeList_Find(const ShowModeList& showModes, const wxString& which); - #endif diff --git a/src/print_ps.cpp b/src/print_ps.cpp index fd12cb7c..bc54303e 100644 --- a/src/print_ps.cpp +++ b/src/print_ps.cpp @@ -71,8 +71,9 @@ static const char *fontnames[] = static const size_t kBufferSize = 256; -PrintShowToPS::PrintShowToPS(const CalChartDoc& show, bool print_landscape, bool print_do_cont, bool print_do_cont_sheet) : +PrintShowToPS::PrintShowToPS(const CalChartDoc& show, const CalChartConfiguration& config_, bool print_landscape, bool print_do_cont, bool print_do_cont_sheet) : mShow(show), +config(config_), mPrintLandscape(print_landscape), mPrintDoCont(print_do_cont), mPrintDoContSheet(print_do_cont_sheet) @@ -91,13 +92,13 @@ PrintShowToPS::operator()(std::ostream& buffer, bool eps, bool overview, unsigne float fieldwidth = Coord2Float(fieldsize.x); float fieldheight = Coord2Float(fieldsize.y); - std::string head_font_str(GetConfiguration_HeadFont().utf8_str()); - std::string main_font_str(GetConfiguration_MainFont().utf8_str()); - std::string number_font_str(GetConfiguration_NumberFont().utf8_str()); - std::string cont_font_str(GetConfiguration_ContFont().utf8_str()); - std::string bold_font_str(GetConfiguration_BoldFont().utf8_str()); - std::string ital_font_str(GetConfiguration_ItalFont().utf8_str()); - std::string bold_ital_font_str(GetConfiguration_BoldItalFont().utf8_str()); + std::string head_font_str(config.Get_HeadFont().utf8_str()); + std::string main_font_str(config.Get_MainFont().utf8_str()); + std::string number_font_str(config.Get_NumberFont().utf8_str()); + std::string cont_font_str(config.Get_ContFont().utf8_str()); + std::string bold_font_str(config.Get_BoldFont().utf8_str()); + std::string ital_font_str(config.Get_ItalFont().utf8_str()); + std::string bold_ital_font_str(config.Get_BoldItalFont().utf8_str()); short num_pages = 0; /* first, calculate dimensions */ @@ -108,34 +109,34 @@ PrintShowToPS::operator()(std::ostream& buffer, bool eps, bool overview, unsigne case ShowMode::SHOW_STANDARD: if (mPrintLandscape) { - width = GetConfiguration_PageHeight() * DPI; + width = config.Get_PageHeight() * DPI; if (mPrintDoCont) { - height = GetConfiguration_PageWidth() * (1.0 - GetConfiguration_ContRatio()) * DPI; - field_y = GetConfiguration_PageWidth() * GetConfiguration_ContRatio() * DPI; + height = config.Get_PageWidth() * (1.0 - config.Get_ContRatio()) * DPI; + field_y = config.Get_PageWidth() * config.Get_ContRatio() * DPI; } else { - height = GetConfiguration_PageWidth() * DPI; + height = config.Get_PageWidth() * DPI; field_y = 0; } } else { - width = GetConfiguration_PageWidth() * DPI; + width = config.Get_PageWidth() * DPI; if (mPrintDoCont) { - height = GetConfiguration_PageHeight() * (1.0 - GetConfiguration_ContRatio()) * DPI; - field_y = GetConfiguration_PageHeight() * GetConfiguration_ContRatio() * DPI; + height = config.Get_PageHeight() * (1.0 - config.Get_ContRatio()) * DPI; + field_y = config.Get_PageHeight() * config.Get_ContRatio() * DPI; } else { - height = GetConfiguration_PageHeight() * DPI; + height = config.Get_PageHeight() * DPI; field_y = 0; } } - real_width = GetConfiguration_PageWidth() * DPI; - real_height = GetConfiguration_PageHeight() * DPI; + real_width = config.Get_PageWidth() * DPI; + real_height = config.Get_PageHeight() * DPI; step_width = (short)(width / (height / (fullheight+8.0))); if (step_width > Coord2Int(fieldsize.x)) step_width = Coord2Int(fieldsize.x); @@ -171,34 +172,34 @@ PrintShowToPS::operator()(std::ostream& buffer, bool eps, bool overview, unsigne if (mPrintLandscape) { - width = GetConfiguration_PageHeight() * DPI; + width = config.Get_PageHeight() * DPI; if (mPrintDoCont) { - height = GetConfiguration_PageWidth() * (1.0 - GetConfiguration_ContRatio()) * DPI; - field_y = GetConfiguration_PageWidth() * GetConfiguration_ContRatio() * DPI; + height = config.Get_PageWidth() * (1.0 - config.Get_ContRatio()) * DPI; + field_y = config.Get_PageWidth() * config.Get_ContRatio() * DPI; } else { - height = GetConfiguration_PageWidth() * DPI; + height = config.Get_PageWidth() * DPI; field_y = 0; } } else { - width = GetConfiguration_PageWidth() * DPI; + width = config.Get_PageWidth() * DPI; if (mPrintDoCont) { - height = GetConfiguration_PageHeight() * (1.0 - GetConfiguration_ContRatio()) * DPI; - field_y = GetConfiguration_PageHeight() * GetConfiguration_ContRatio() * DPI; + height = config.Get_PageHeight() * (1.0 - config.Get_ContRatio()) * DPI; + field_y = config.Get_PageHeight() * config.Get_ContRatio() * DPI; } else { - height = GetConfiguration_PageHeight() * DPI; + height = config.Get_PageHeight() * DPI; field_y = 0; } } - real_width = GetConfiguration_PageWidth() * DPI; - real_height = GetConfiguration_PageHeight() * DPI; + real_width = config.Get_PageWidth() * DPI; + real_height = config.Get_PageHeight() * DPI; field_h = height / (1 + 16*springShow.FieldW()/ ((float)springShow.StageW()*80)); field_w = field_h/springShow.StageH() * @@ -229,13 +230,13 @@ PrintShowToPS::operator()(std::ostream& buffer, bool eps, bool overview, unsigne { if (mPrintLandscape) { - width = GetConfiguration_PageHeight() * DPI; - height = GetConfiguration_PageWidth() * DPI; + width = config.Get_PageHeight() * DPI; + height = config.Get_PageWidth() * DPI; } else { - width = GetConfiguration_PageWidth() * DPI; - height = GetConfiguration_PageHeight() * DPI; + width = config.Get_PageWidth() * DPI; + height = config.Get_PageHeight() * DPI; } if ((width * (fullheight / fullwidth)) > height) { @@ -272,10 +273,10 @@ PrintShowToPS::operator()(std::ostream& buffer, bool eps, bool overview, unsigne buffer<<"%!PS-Adobe-3.0\n"; } snprintf(buf, sizeof(buf), "%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", - GetConfiguration_PageOffsetX() * DPI, - (GetConfiguration_PaperLength() - GetConfiguration_PageOffsetY()) * DPI - real_height, - GetConfiguration_PageOffsetX() * DPI + real_width, - (GetConfiguration_PaperLength() - GetConfiguration_PageOffsetY()) * DPI); + config.Get_PageOffsetX() * DPI, + (config.Get_PaperLength() - config.Get_PageOffsetY()) * DPI - real_height, + config.Get_PageOffsetX() * DPI + real_width, + (config.Get_PaperLength() - config.Get_PageOffsetY()) * DPI); buffer< GetConfiguration_TextSize()) this_size = GetConfiguration_TextSize(); + if (this_size > config.Get_TextSize()) this_size = config.Get_TextSize(); snprintf(buf, sizeof(buf), "/y %.2f def\n", cont_height - this_size); buffer<WhichYards()) { snprintf(buf, sizeof(buf), "/mainfont findfont %.2f scalefont setfont\n", - step_size * GetConfiguration_YardsSize()); + step_size * config.Get_YardsSize()); buffer<WhichYards() & (SPR_YARD_ABOVE | SPR_YARD_BELOW)) for (short j=0; j <= modesprshow->StepsW(); j+=8) @@ -917,8 +918,8 @@ void PrintShowToPS::PrintSpringshow(std::ostream& buffer, const CC_sheet& sheet) (modesprshow->TextTop()-modesprshow->StageX())/ modesprshow->StageH()); buffer<StepsX() + - (MAX_YARD_LINES-1)*4 + j)/8].utf8_str()); + std::string yardstr(config.Get_yard_text((modesprshow->StepsX() + + (CalChartConfiguration::kYardTextValues-1)*4 + j)/8).utf8_str()); snprintf(buf, sizeof(buf), "(%s) centerText\n", yardstr.c_str()); buffer<TextBottom() - modesprshow->StageX()) / - modesprshow->StageH() -(step_size*GetConfiguration_YardsSize())); + modesprshow->StageH() -(step_size*config.Get_YardsSize())); buffer<StepsX() + - (MAX_YARD_LINES-1)*4 + j)/8].utf8_str()); + std::string yardstr(config.Get_yard_text((modesprshow->StepsX() + + (CalChartConfiguration::kYardTextValues-1)*4 + j)/8).utf8_str()); snprintf(buf, sizeof(buf), "(%s) centerText\n", yardstr.c_str()); buffer<StepsH()-j-GetConfiguration_YardsSize()/2) / + (modesprshow->StepsH()-j-config.Get_YardsSize()/2) / modesprshow->StepsH()); buffer<TextLeft()-modesprshow->StageX()) / modesprshow->StageW()); buffer<WhichYards() & SPR_YARD_RIGHT) { buffer<<"("< #include @@ -37,7 +38,7 @@ class CC_textline; class PrintShowToPS { public: - PrintShowToPS(const CalChartDoc&, bool print_landscape, bool print_do_cont, bool print_do_cont_sheet); + PrintShowToPS(const CalChartDoc&, const CalChartConfiguration& config_, bool print_landscape, bool print_do_cont, bool print_do_cont_sheet); int operator()(std::ostream& buffer, bool eps, bool overview, unsigned curr_ss, int min_yards, const std::set& isPicked); @@ -51,6 +52,7 @@ class PrintShowToPS void print_start_page(std::ostream& buffer, bool landscape); const CalChartDoc& mShow; + const CalChartConfiguration& config; bool mPrintLandscape; bool mPrintDoCont; bool mPrintDoContSheet; diff --git a/src/print_ps_dialog.cpp b/src/print_ps_dialog.cpp index 340b97bb..1e2f24eb 100644 --- a/src/print_ps_dialog.cpp +++ b/src/print_ps_dialog.cpp @@ -58,7 +58,7 @@ EVT_BUTTON(CC_PRINT_BUTTON_SELECT,PrintPostScriptDialog::ShowPrintSelect) EVT_BUTTON(CC_PRINT_BUTTON_RESET_DEFAULTS,PrintPostScriptDialog::ResetDefaults) END_EVENT_TABLE() -void PrintPostScriptDialog::PrintShow() +void PrintPostScriptDialog::PrintShow(const CalChartConfiguration& config) { wxString s; #ifdef PRINT__RUN_CMD @@ -73,15 +73,15 @@ void PrintPostScriptDialog::PrintShow() wxLogError(wxT("Yards entered invalid. Please enter a number between 10 and 100.")); return; } - overview = GetConfiguration_PrintPSOverview(); + overview = config.Get_PrintPSOverview(); - switch (GetConfiguration_PrintPSModes()) + switch (config.Get_PrintPSModes()) { case CC_PRINT_ACTION_PREVIEW: { #ifdef PRINT__RUN_CMD s = wxFileName::CreateTempFileName(wxT("cc_")); - buf.sprintf(wxT("%s %s \"%s\""), GetConfiguration_PrintViewCmd().c_str(), GetConfiguration_PrintViewCmd().c_str(), s.c_str()); + buf.sprintf(wxT("%s %s \"%s\""), config.Get_PrintViewCmd().c_str(), config.Get_PrintViewCmd().c_str(), s.c_str()); #endif } break; @@ -94,7 +94,7 @@ void PrintPostScriptDialog::PrintShow() { #ifdef PRINT__RUN_CMD s = wxFileName::CreateTempFileName(wxT("cc_")); - buf.sprintf(wxT("%s %s \"%s\""), GetConfiguration_PrintCmd().c_str(), GetConfiguration_PrintOpts().c_str(), s.c_str()); + buf.sprintf(wxT("%s %s \"%s\""), config.Get_PrintCmd().c_str(), config.Get_PrintOpts().c_str(), s.c_str()); #else #endif } @@ -104,11 +104,11 @@ void PrintPostScriptDialog::PrintShow() } std::ostringstream buffer; - bool doLandscape = GetConfiguration_PrintPSLandscape(); - bool doCont = GetConfiguration_PrintPSDoCont(); - bool doContSheet = GetConfiguration_PrintPSDoContSheet(); + bool doLandscape = config.Get_PrintPSLandscape(); + bool doCont = config.Get_PrintPSDoCont(); + bool doContSheet = config.Get_PrintPSDoContSheet(); - PrintShowToPS printShowToPS(*mShow, doLandscape, doCont, doContSheet); + PrintShowToPS printShowToPS(*mShow, config, doLandscape, doCont, doContSheet); int n = printShowToPS(buffer, eps, overview, mShow->GetCurrentSheetNum(), minyards, mIsSheetPicked); // stream to file: { @@ -117,7 +117,7 @@ void PrintPostScriptDialog::PrintShow() } #ifdef PRINT__RUN_CMD - switch (GetConfiguration_PrintPSModes()) + switch (config.Get_PrintPSModes()) { case CC_PRINT_ACTION_FILE: break; @@ -167,19 +167,20 @@ void PrintPostScriptDialog::ShowPrintSelect(wxCommandEvent&) void PrintPostScriptDialog::ResetDefaults(wxCommandEvent&) { + auto& config = CalChartConfiguration::GetGlobalConfig(); #ifdef PRINT__RUN_CMD - ClearConfiguration_PrintCmd(); - ClearConfiguration_PrintOpts(); + config.Clear_PrintCmd(); + config.Clear_PrintOpts(); #else - ClearConfiguration_PrintFile(); + config.Clear_PrintFile(); #endif - ClearConfiguration_PrintViewCmd(); - ClearConfiguration_PrintViewOpts(); + config.Clear_PrintViewCmd(); + config.Clear_PrintViewOpts(); - ClearConfiguration_PageOffsetX(); - ClearConfiguration_PageOffsetY(); - ClearConfiguration_PageWidth(); - ClearConfiguration_PageHeight(); + config.Clear_PageOffsetX(); + config.Clear_PageOffsetY(); + config.Clear_PageWidth(); + config.Clear_PageHeight(); // re-read values TransferDataToWindow(); @@ -389,67 +390,69 @@ void PrintPostScriptDialog::CreateControls() bool PrintPostScriptDialog::TransferDataToWindow() { + auto& config = CalChartConfiguration::GetGlobalConfig(); #ifdef PRINT__RUN_CMD - text_cmd->SetValue(GetConfiguration_PrintCmd()); - text_opts->SetValue(GetConfiguration_PrintOpts()); - text_view_cmd->SetValue(GetConfiguration_PrintViewCmd()); - text_view_opts->SetValue(GetConfiguration_PrintViewOpts()); + text_cmd->SetValue(config.Get_PrintCmd()); + text_opts->SetValue(config.Get_PrintOpts()); + text_view_cmd->SetValue(config.Get_PrintViewCmd()); + text_view_opts->SetValue(config.Get_PrintViewOpts()); #else - text_cmd->SetValue(GetConfiguration_PrintFile()); + text_cmd->SetValue(config.Get_PrintFile()); #endif - radio_orient->SetSelection(GetConfiguration_PrintPSLandscape()); - radio_method->SetSelection(GetConfiguration_PrintPSModes()); - check_overview->SetValue(GetConfiguration_PrintPSOverview()); - check_cont->SetValue(GetConfiguration_PrintPSDoCont()); + radio_orient->SetSelection(config.Get_PrintPSLandscape()); + radio_method->SetSelection(config.Get_PrintPSModes()); + check_overview->SetValue(config.Get_PrintPSOverview()); + check_cont->SetValue(config.Get_PrintPSDoCont()); if (check_pages) { - check_pages->SetValue(GetConfiguration_PrintPSDoContSheet()); + check_pages->SetValue(config.Get_PrintPSDoContSheet()); } wxString buf; - buf.Printf(wxT("%.2f"),GetConfiguration_PageOffsetX()); + buf.Printf(wxT("%.2f"),config.Get_PageOffsetX()); text_x->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PageOffsetY()); + buf.Printf(wxT("%.2f"),config.Get_PageOffsetY()); text_y->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PageWidth()); + buf.Printf(wxT("%.2f"),config.Get_PageWidth()); text_width->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PageHeight()); + buf.Printf(wxT("%.2f"),config.Get_PageHeight()); text_height->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PaperLength()); + buf.Printf(wxT("%.2f"),config.Get_PaperLength()); text_length->SetValue(buf); return true; } bool PrintPostScriptDialog::TransferDataFromWindow() { + auto& config = CalChartConfiguration::GetGlobalConfig(); #ifdef PRINT__RUN_CMD - SetConfiguration_PrintCmd(text_cmd->GetValue()); - SetConfiguration_PrintOpts(text_opts->GetValue()); - SetConfiguration_PrintViewCmd(text_view_cmd->GetValue()); - SetConfiguration_PrintViewOpts(text_view_opts->GetValue()); + config.Set_PrintCmd(text_cmd->GetValue()); + config.Set_PrintOpts(text_opts->GetValue()); + config.Set_PrintViewCmd(text_view_cmd->GetValue()); + config.Set_PrintViewOpts(text_view_opts->GetValue()); #else - SetConfiguration_PrintFile(text_cmd->GetValue()); + config.Set_PrintFile(text_cmd->GetValue()); #endif - SetConfiguration_PrintPSLandscape(radio_orient->GetSelection() == CC_PRINT_ORIENT_LANDSCAPE); - SetConfiguration_PrintPSModes(radio_method->GetSelection()); - SetConfiguration_PrintPSOverview(check_overview->GetValue()); - SetConfiguration_PrintPSDoCont(check_cont->GetValue()); + config.Set_PrintPSLandscape(radio_orient->GetSelection() == CC_PRINT_ORIENT_LANDSCAPE); + config.Set_PrintPSModes(radio_method->GetSelection()); + config.Set_PrintPSOverview(check_overview->GetValue()); + config.Set_PrintPSDoCont(check_cont->GetValue()); if (check_pages) { - SetConfiguration_PrintPSDoContSheet(check_pages->GetValue()); + config.Set_PrintPSDoContSheet(check_pages->GetValue()); } double dval; text_x->GetValue().ToDouble(&dval); - SetConfiguration_PageOffsetX(dval); + config.Set_PageOffsetX(dval); text_y->GetValue().ToDouble(&dval); - SetConfiguration_PageOffsetY(dval); + config.Set_PageOffsetY(dval); text_width->GetValue().ToDouble(&dval); - SetConfiguration_PageWidth(dval); + config.Set_PageWidth(dval); text_height->GetValue().ToDouble(&dval); - SetConfiguration_PageHeight(dval); + config.Set_PageHeight(dval); text_length->GetValue().ToDouble(&dval); - SetConfiguration_PaperLength(dval); + config.Set_PaperLength(dval); return true; } diff --git a/src/print_ps_dialog.h b/src/print_ps_dialog.h index 071c25de..4815092d 100644 --- a/src/print_ps_dialog.h +++ b/src/print_ps_dialog.h @@ -30,6 +30,7 @@ #include class CalChartDoc; +class CalChartConfiguration; class PrintPostScriptDialog : public wxDialog { @@ -62,7 +63,7 @@ class PrintPostScriptDialog : public wxDialog virtual bool TransferDataFromWindow(); // to print a show, call this function - void PrintShow(); + void PrintShow(const CalChartConfiguration& config); private: const CalChartDoc* mShow; diff --git a/src/setup_wizards.cpp b/src/setup_wizards.cpp index bdbc2dd9..454aceb4 100644 --- a/src/setup_wizards.cpp +++ b/src/setup_wizards.cpp @@ -51,9 +51,13 @@ SetDescriptionWizard::GetValue() ChooseShowModeWizard::ChooseShowModeWizard(wxWizard *parent) : wxWizardPageSimple(parent) { - for (ShowModeList::const_iterator mode = wxGetApp().GetModeList().begin(); mode != wxGetApp().GetModeList().end(); ++mode) + for (auto mode : kShowModeStrings) { - modeStrings.Add((*mode)->GetName()); + modeStrings.Add(mode); + } + for (auto mode : kSpringShowModeStrings) + { + modeStrings.Add(mode); } wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );