From 40679bb7c614336cff5e4c6700121aae5ad74331 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Fri, 14 Mar 2014 21:10:55 -0700 Subject: [PATCH 01/11] did a bunch of little work. --- src/animation_canvas.cpp | 4 +- src/animation_frame.cpp | 36 +++---- src/animation_frame.h | 6 +- src/animation_view.cpp | 32 +++--- src/calchartdoc.cpp | 2 +- src/cc_omniview_canvas.cpp | 53 +++++----- src/cc_omniview_canvas.h | 4 +- src/cc_preferences_ui.cpp | 136 ++++++++++++------------- src/confgr.cpp | 157 ++++++++++++++++++---------- src/confgr.h | 203 ++++++++++++++++++------------------- src/draw.cpp | 52 +++++----- src/draw.h | 9 +- src/field_canvas.cpp | 4 +- src/field_frame.cpp | 34 ++++--- src/field_frame.h | 4 +- src/field_view.cpp | 21 ++-- src/field_view.h | 2 + src/modes.cpp | 34 +++---- src/modes.h | 15 +-- src/print_ps.cpp | 137 ++++++++++++------------- src/print_ps.h | 4 +- src/print_ps_dialog.cpp | 98 +++++++++--------- src/print_ps_dialog.h | 3 +- 23 files changed, 556 insertions(+), 494 deletions(-) diff --git a/src/animation_canvas.cpp b/src/animation_canvas.cpp index d605cd11..a93ae764 100644 --- a/src/animation_canvas.cpp +++ b/src/animation_canvas.cpp @@ -66,14 +66,14 @@ AnimationCanvas::OnPaint(wxPaintEvent& event) { wxBufferedPaintDC dc(this); - dc.SetBackground(GetCalChartBrush(COLOR_FIELD)); + dc.SetBackground(GetConfig().GetCalChartBrush(COLOR_FIELD)); dc.Clear(); dc.SetUserScale(mUserScale, mUserScale); dc.SetDeviceOrigin(mUserOriginX, 0); if (mMouseDown) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetCalChartPen(COLOR_SHAPES)); + dc.SetPen(GetConfig().GetCalChartPen(COLOR_SHAPES)); dc.DrawRectangle(mMouseXStart, mMouseYStart, mMouseXEnd - mMouseXStart, mMouseYEnd - mMouseYStart); } diff --git a/src/animation_frame.cpp b/src/animation_frame.cpp index 256de2f5..05b89a76 100644 --- a/src/animation_frame.cpp +++ b/src/animation_frame.cpp @@ -72,12 +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(new AnimationView()), +config(config_), mCanvas(NULL), mOmniViewCanvas(NULL), mTimer(new wxTimer(this, CALCHART__anim_next_beat_timer)), @@ -87,7 +89,6 @@ mWhenClosed(onClose) { // Give it an icon // give this a view so it can pick up document changes - mAnimationView = new AnimationView(); mAnimationView->SetDocument(doc); mAnimationView->SetFrame(this); SetBandIcon(this); @@ -131,19 +132,19 @@ mWhenClosed(onClose) mSplitter->SetWindowStyleFlag(mSplitter->GetWindowStyleFlag() | wxSP_LIVE_UPDATE); mSplitter->SetMinSize(wxSize(300, 400)); - mOmniViewCanvas = new CCOmniView_Canvas(mAnimationView, mSplitter); - mCanvas = new AnimationCanvas(mAnimationView, mSplitter); + mOmniViewCanvas = new CCOmniView_Canvas(mAnimationView.get(), mSplitter, config); + mCanvas = new AnimationCanvas(mAnimationView.get(), 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); @@ -242,7 +243,6 @@ AnimationFrame::~AnimationFrame() if (mOmniViewCanvas) mOmniViewCanvas->SetView(NULL); mTimer->Stop(); - delete mAnimationView; } @@ -252,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); } @@ -285,7 +285,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) @@ -651,8 +651,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 @@ -665,8 +665,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 @@ -676,7 +676,7 @@ AnimationFrame::OnCmd_SplitViewUnsplit(wxCommandEvent& event) { mSplitter->Unsplit(); } - SetConfiguration_AnimationFrameSplitScreen(false); + config.Set_AnimationFrameSplitScreen(false); } void @@ -689,7 +689,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 5b5b6791..afa182d9 100644 --- a/src/animation_frame.h +++ b/src/animation_frame.h @@ -35,6 +35,7 @@ class AnimationCanvas; class CCOmniView_Canvas; class FancyTextWin; class wxSplitterWindow; +class CalChartConfiguration; #if defined(BUILD_FOR_VIEWER) && (BUILD_FOR_VIEWER != 0) typedef wxDocChildFrame AnimationFrameParent; @@ -47,7 +48,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 - AnimationView *mAnimationView; + std::unique_ptr mAnimationView; + 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; diff --git a/src/animation_view.cpp b/src/animation_view.cpp index b1d02934..e553a92c 100644 --- a/src/animation_view.cpp +++ b/src/animation_view.cpp @@ -54,8 +54,8 @@ AnimationView::~AnimationView() void AnimationView::OnDraw(wxDC *dc) { - dc->SetPen(GetCalChartPen(COLOR_FIELD_DETAIL)); - GetShow()->GetMode().DrawAnim(*dc); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_FIELD_DETAIL)); + GetShow()->GetMode().DrawAnim(*dc, GetConfig()); const bool checkForCollision = mCollisionWarningType != COLLISION_NONE; if (mAnimation) { @@ -65,8 +65,8 @@ AnimationView::OnDraw(wxDC *dc) if (checkForCollision && info.mCollision) { - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_COLLISION)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_COLLISION)); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_COLLISION)); + dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_COLLISION)); } else if (GetShow()->IsSelected(i)) { @@ -75,18 +75,18 @@ 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)); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_HILIT_BACK)); + dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_HILIT_BACK)); 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)); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_HILIT_FRONT)); + dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_HILIT_FRONT)); break; default: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_HILIT_SIDE)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_HILIT_SIDE)); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_HILIT_SIDE)); + dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_HILIT_SIDE)); } } else @@ -96,18 +96,18 @@ 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)); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_BACK)); + dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_BACK)); break; case ANIMDIR_SE: case ANIMDIR_E: case ANIMDIR_NE: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_FRONT)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_FRONT)); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_FRONT)); + dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_FRONT)); break; default: - dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_SIDE)); - dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_SIDE)); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_SIDE)); + dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_SIDE)); } } CC_coord position = info.mPosition; diff --git a/src/calchartdoc.cpp b/src/calchartdoc.cpp index 2c20230e..3350eb6d 100644 --- a/src/calchartdoc.cpp +++ b/src/calchartdoc.cpp @@ -55,7 +55,7 @@ mShow(CC_show::Create_CC_show()), mMode(wxGetApp().GetModeList().front().get()), mTimer(*this) { - mTimer.Start(GetConfiguration_AutosaveInterval()*1000); + mTimer.Start(GetConfig().Get_AutosaveInterval()*1000); } // When a file is opened, we first check to see if there is a temporary 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..21c9f70b 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -175,7 +175,7 @@ void GeneralSetup::CreateControls() 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, GetConfig().GetColorNames().at(0), wxDefaultPosition, wxDefaultSize, COLOR_NUM, GetConfig().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 +183,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(GetConfig().GetCalChartBrush(i)); temp_dc.Clear(); nameBox->SetItemBitmap(i, temp_bitmap); } @@ -209,11 +209,11 @@ void GeneralSetup::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); + mCalChartPens[i] = GetConfig().GetCalChartPen(i); + mCalChartBrushes[i] = GetConfig().GetCalChartBrush(i); } - mAutoSave_Interval.Printf(wxT("%ld"), GetConfiguration_AutosaveInterval()); + mAutoSave_Interval.Printf(wxT("%ld"), GetConfig().Get_AutosaveInterval()); } bool GeneralSetup::TransferDataToWindow() @@ -232,13 +232,11 @@ bool GeneralSetup::TransferDataFromWindow() // 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); + GetConfig().SetCalChartBrushAndPen(i, mCalChartBrushes[i], mCalChartPens[i]); } long val; mAutoSave_Interval.ToLong(&val); - SetConfiguration_AutosaveInterval(val); + GetConfig().Set_AutosaveInterval(val); return true; } @@ -246,10 +244,10 @@ bool GeneralSetup::ClearValuesToDefault() { for (int i = 0; i < COLOR_NUM; ++i) { - SetColor(i, DefaultPenWidth[i], DefaultColors[i]); - ClearConfigColor(i); + SetColor(i, GetConfig().GetDefaultPenWidth()[i], GetConfig().GetDefaultColors()[i]); + GetConfig().ClearConfigColor(i); } - ClearConfiguration_AutosaveInterval(); + GetConfig().Clear_AutosaveInterval(); Init(); TransferDataToWindow(); return true; @@ -295,8 +293,8 @@ void GeneralSetup::OnCmdSelectWidth(wxSpinEvent& e) void GeneralSetup::OnCmdResetColors(wxCommandEvent&) { int selection = nameBox->GetSelection(); - SetColor(selection, DefaultPenWidth[selection], DefaultColors[selection]); - ClearConfigColor(selection); + SetColor(selection, GetConfig().GetDefaultPenWidth()[selection], GetConfig().GetDefaultColors()[selection]); + GetConfig().ClearConfigColor(selection); } void GeneralSetup::OnCmdChooseNewColor(wxCommandEvent&) @@ -407,21 +405,21 @@ 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] = GetConfig().Get_HeadFont(); + mFontNames[1] = GetConfig().Get_MainFont(); + mFontNames[2] = GetConfig().Get_NumberFont(); + mFontNames[3] = GetConfig().Get_ContFont(); + mFontNames[4] = GetConfig().Get_BoldFont(); + mFontNames[5] = GetConfig().Get_ItalFont(); + mFontNames[6] = GetConfig().Get_BoldItalFont(); + mPrintValues[0] = GetConfig().Get_HeaderSize(); + mPrintValues[1] = GetConfig().Get_YardsSize(); + mPrintValues[2] = GetConfig().Get_TextSize(); + mPrintValues[3] = GetConfig().Get_DotRatio(); + mPrintValues[4] = GetConfig().Get_NumRatio(); + mPrintValues[5] = GetConfig().Get_PLineRatio(); + mPrintValues[6] = GetConfig().Get_SLineRatio(); + mPrintValues[7] = GetConfig().Get_ContRatio(); } bool PSPrintingSetUp::TransferDataToWindow() @@ -503,41 +501,41 @@ bool PSPrintingSetUp::TransferDataFromWindow() 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]); + GetConfig().Set_HeadFont(mFontNames[0]); + GetConfig().Set_MainFont(mFontNames[1]); + GetConfig().Set_NumberFont(mFontNames[2]); + GetConfig().Set_ContFont(mFontNames[3]); + GetConfig().Set_BoldFont(mFontNames[4]); + GetConfig().Set_ItalFont(mFontNames[5]); + GetConfig().Set_BoldItalFont(mFontNames[6]); + GetConfig().Set_HeaderSize(mPrintValues[0]); + GetConfig().Set_YardsSize(mPrintValues[1]); + GetConfig().Set_TextSize(mPrintValues[2]); + GetConfig().Set_DotRatio(mPrintValues[3]); + GetConfig().Set_NumRatio(mPrintValues[4]); + GetConfig().Set_PLineRatio(mPrintValues[5]); + GetConfig().Set_SLineRatio(mPrintValues[6]); + GetConfig().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(); + GetConfig().Clear_HeadFont(); + GetConfig().Clear_MainFont(); + GetConfig().Clear_NumberFont(); + GetConfig().Clear_ContFont(); + GetConfig().Clear_BoldFont(); + GetConfig().Clear_ItalFont(); + GetConfig().Clear_BoldItalFont(); + GetConfig().Clear_HeaderSize(); + GetConfig().Clear_YardsSize(); + GetConfig().Clear_TextSize(); + GetConfig().Clear_DotRatio(); + GetConfig().Clear_NumRatio(); + GetConfig().Clear_PLineRatio(); + GetConfig().Clear_SLineRatio(); + GetConfig().Clear_ContRatio(); Init(); return TransferDataToWindow(); } @@ -639,7 +637,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, GetConfig().Get_yard_text_index().size(), GetConfig().Get_yard_text_index().data()); textchoice->SetSelection(0); textsizer->Add(textchoice); textsizer->Add(new wxTextCtrl(this, SHOW_LINE_VALUE), sBasicSizerFlags ); @@ -657,7 +655,7 @@ void ShowModeSetup::Init() } for (size_t i = 0; i < MAX_YARD_LINES; ++i) { - mYardText[i] = yard_text[i]; + mYardText[i] = GetConfig().Get_yard_text(i); } } @@ -696,9 +694,8 @@ bool ShowModeSetup::TransferDataFromWindow() for (size_t i = 0; i < MAX_YARD_LINES; ++i) { - yard_text[i] = mYardText[i]; + GetConfig().Set_yard_text(i, mYardText[i]); } - SetConfigShowYardline(); return true; } @@ -709,7 +706,7 @@ bool ShowModeSetup::ClearValuesToDefault() { ClearConfigurationShowMode(i); } - ClearConfigShowYardline(); + GetConfig().ClearConfigShowYardline(); Init(); return TransferDataToWindow(); } @@ -867,7 +864,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, GetConfig().Get_spr_line_text_index().size(), GetConfig().Get_spr_line_text_index().data()); textchoice->SetSelection(0); textsizer->Add(textchoice); textsizer->Add(new wxTextCtrl(this, SPRING_SHOW_LINE_VALUE), sBasicSizerFlags ); @@ -885,7 +882,7 @@ void SpringShowModeSetup::Init() } for (size_t i = 0; i < MAX_SPR_LINES; ++i) { - mYardText[i] = spr_line_text[i]; + mYardText[i] = GetConfig().Get_spr_line_text(i); } } @@ -906,7 +903,7 @@ bool SpringShowModeSetup::TransferDataToWindow() } wxTextCtrl* text = (wxTextCtrl*) FindWindow(SPRING_SHOW_LINE_VALUE); - text->SetValue(spr_line_text[mWhichYardLine]); + text->SetValue(GetConfig().Get_spr_line_text(mWhichYardLine)); return true; } @@ -938,9 +935,8 @@ bool SpringShowModeSetup::TransferDataFromWindow() for (size_t i = 0; i < MAX_SPR_LINES; ++i) { - spr_line_text[i] = mYardText[i]; + GetConfig().Set_spr_line_text(i, mYardText[i]); } - SetConfigSpringShowYardline(); return true; } @@ -951,7 +947,7 @@ bool SpringShowModeSetup::ClearValuesToDefault() { ClearConfigurationSpringShowMode(i); } - ClearConfigSpringShowYardline(); + GetConfig().ClearConfigSpringShowYardline(); Init(); return TransferDataToWindow(); } diff --git a/src/confgr.cpp b/src/confgr.cpp index cf79127a..08a95aa5 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -107,6 +107,12 @@ const int DefaultPenWidth[COLOR_NUM] = 2, }; +CalChartConfiguration& GetConfig() +{ + static CalChartConfiguration sconfig; + return sconfig; +} + // constants for behavior: // Autosave @@ -172,9 +178,9 @@ const wxString spr_line_text_index[MAX_SPR_LINES] = #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 { return GetConfigValue( k ## KeyName ## Key, k ## KeyName ## Value); } \ +void CalChartConfiguration::Set_ ## KeyName (const Type& v) { return SetConfigValue( k ## KeyName ## Key, v, k ## KeyName ## Value); } \ +void CalChartConfiguration::Clear_ ## KeyName () { return ClearConfigValue( k ## KeyName ## Key ); } IMPLEMENT_CONFIGURATION_FUNCTIONS( AutosaveInterval, long, 60); @@ -524,24 +530,8 @@ void ReadConfigColor() } } -void SetConfigColor(size_t selection) -{ - wxConfigBase *config = wxConfigBase::Get(); - - // 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(); -} - -void ClearConfigColor(size_t selection) +void +CalChartConfiguration::ClearConfigColor(size_t selection) { wxConfigBase *config = wxConfigBase::Get(); @@ -567,17 +557,77 @@ void ReadConfigYardlines() } } -void SetConfigShowYardline() +wxString +CalChartConfiguration::Get_yard_text(size_t which) const { - for (size_t i = 0; i < MAX_YARD_LINES; ++i) - { - wxString key; - key.Printf(wxT("YardLines_%ld"), i); - SetConfigValue(key, yard_text[i], yard_text_index[i]); - } + if (which >= MAX_YARD_LINES) + throw std::runtime_error("Error, exceeding yard_text size"); + return yard_text[which]; +} + +void +CalChartConfiguration::Set_yard_text(size_t which, const wxString& name) +{ + if (which >= MAX_YARD_LINES) + throw std::runtime_error("Error, exceeding yard_text size"); + yard_text[which] = name; + wxString key; + key.Printf(wxT("YardLines_%ld"), which); + SetConfigValue(key, yard_text[which], yard_text_index[which]); +} + +wxString +CalChartConfiguration::Get_spr_line_text(size_t which) const +{ + if (which >= MAX_SPR_LINES) + throw std::runtime_error("Error, exceeding yard_text size"); + return spr_line_text[which]; +} + +void +CalChartConfiguration::Set_spr_line_text(size_t which, const wxString& name) +{ + if (which >= MAX_SPR_LINES) + throw std::runtime_error("Error, exceeding yard_text size"); + spr_line_text[which] = name; + wxString key; + key.Printf(wxT("SpringShowYardLines_%ld"), which); + SetConfigValue(key, spr_line_text[which], spr_line_text_index[which]); +} + +std::vector +CalChartConfiguration::Get_yard_text_index() const +{ + return { std::begin(yard_text_index), std::end(yard_text_index) }; +} + +std::vector +CalChartConfiguration::Get_spr_line_text_index() const +{ + return { std::begin(spr_line_text_index), std::end(spr_line_text_index) }; +} + +std::vector +CalChartConfiguration::GetColorNames() const +{ + return { std::begin(ColorNames), std::end(ColorNames) }; +} + +std::vector +CalChartConfiguration::GetDefaultColors() const +{ + return { std::begin(DefaultColors), std::end(DefaultColors) }; +} + +std::vector +CalChartConfiguration::GetDefaultPenWidth() const +{ + return { std::begin(DefaultPenWidth), std::end(DefaultPenWidth) }; } -void ClearConfigShowYardline() + +void +CalChartConfiguration::ClearConfigShowYardline() { for (size_t i = 0; i < MAX_YARD_LINES; ++i) { @@ -598,17 +648,8 @@ void ReadConfigSpringYardlines() } } -void SetConfigSpringShowYardline() -{ - for (size_t i = 0; i < MAX_SPR_LINES; ++i) - { - wxString key; - key.Printf(wxT("SpringShowYardLines_%ld"), i); - SetConfigValue(key, spr_line_text[i], spr_line_text_index[i]); - } -} - -void ClearConfigSpringShowYardline() +void +CalChartConfiguration::ClearConfigSpringShowYardline() { for (size_t i = 0; i < MAX_SPR_LINES; ++i) { @@ -628,27 +669,37 @@ void ReadConfig() ReadConfigSpringYardlines(); } +wxBrush +CalChartConfiguration::GetCalChartBrush(CalChartColors c) const +{ + return CalChartBrushes[c]; +} + wxPen -GetCalChartPen(CalChartColors c) +CalChartConfiguration::GetCalChartPen(CalChartColors c) const { return CalChartPens[c]; } void -SetCalChartPen(CalChartColors c, const wxPen& pen) +CalChartConfiguration::SetCalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen) { + if (c >= COLOR_NUM) + throw std::runtime_error("Error, exceeding COLOR_NUM size"); + CalChartBrushes[c] = brush; CalChartPens[c] = pen; -} -wxBrush -GetCalChartBrush(CalChartColors c) -{ - return CalChartBrushes[c]; -} + wxConfigBase *config = wxConfigBase::Get(); -void -SetCalChartBrush(CalChartColors c, const wxBrush& brush) -{ - CalChartBrushes[c] = brush; + // read out the color configuration: + config->SetPath(wxT("/COLORS")); + wxString rbuf = ColorNames[c] + wxT("_Red"); + config->Write(rbuf, static_cast(CalChartBrushes[c].GetColour().Red())); + wxString gbuf = ColorNames[c] + wxT("_Green"); + config->Write(gbuf, static_cast(CalChartBrushes[c].GetColour().Green())); + wxString bbuf = ColorNames[c] + wxT("_Blue"); + config->Write(bbuf, static_cast(CalChartBrushes[c].GetColour().Blue())); + config->SetPath(wxT("WIDTH")); + config->Write(ColorNames[c], CalChartPens[c].GetWidth()); + config->Flush(); } - diff --git a/src/confgr.h b/src/confgr.h index 85fe211e..2f35b8bd 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -25,6 +25,7 @@ #include #include +#include // forward declare class wxPen; @@ -59,14 +60,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, @@ -87,86 +80,106 @@ enum CalChartSpringShowModes extern const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM]; -// macro for declaring configuration settings +class CalChartConfiguration +{ +public: + +// 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]; + Type Get_ ## Key () const ; \ + void Set_ ## Key (const Type& v) ; \ + void Clear_ ## 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); + + wxBrush GetCalChartBrush(CalChartColors c) const; + wxPen GetCalChartPen(CalChartColors c) const; + void SetCalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen); + void ClearConfigColor(size_t selection); + + wxString Get_yard_text(size_t which) const; + void Set_yard_text(size_t which, const wxString&); + std::vector Get_yard_text_index() const; + wxString Get_spr_line_text(size_t which) const; + void Set_spr_line_text(size_t which, const wxString&); + std::vector Get_spr_line_text_index() const; + void ClearConfigShowYardline(); + void ClearConfigSpringShowYardline(); + + std::vector GetColorNames() const; + std::vector GetDefaultColors() const; + std::vector GetDefaultPenWidth() const; + +}; + +CalChartConfiguration& GetConfig(); extern void ReadConfig(); @@ -180,21 +193,5 @@ void GetConfigurationSpringShowMode(size_t which, long values[kSpringShowModeVal 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 #endif diff --git a/src/draw.cpp b/src/draw.cpp index 3c633860..dd0efe51 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -165,37 +165,37 @@ static const double kLowerNorthArrow[2][3] = { { 1.0 - 52/kSizeX, (570)/kSizeY, static const double kContinuityStart[2] = { 606/kSizeY, 556/kSizeYLandscape }; -void Draw(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool primary) +void Draw(wxDC& dc, const CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool primary) { - 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); - dc.SetTextForeground(GetCalChartPen(COLOR_POINT_TEXT).GetColour()); + dc.SetTextForeground(config.GetCalChartPen(COLOR_POINT_TEXT).GetColour()); CC_coord origin = show.GetMode().Offset(); for (size_t i = 0; i < show.GetNumPoints(); i++) { wxBrush fillBrush; if (show.IsSelected(i) && primary) { - dc.SetPen(GetCalChartPen(COLOR_POINT_HILIT)); - fillBrush = GetCalChartBrush(COLOR_POINT_HILIT); + dc.SetPen(config.GetCalChartPen(COLOR_POINT_HILIT)); + fillBrush = config.GetCalChartBrush(COLOR_POINT_HILIT); } else if (show.IsSelected(i) && !primary) { - dc.SetPen(GetCalChartPen(COLOR_REF_POINT_HILIT)); - fillBrush = GetCalChartBrush(COLOR_REF_POINT_HILIT); + dc.SetPen(config.GetCalChartPen(COLOR_REF_POINT_HILIT)); + fillBrush = config.GetCalChartBrush(COLOR_REF_POINT_HILIT); } else if (!show.IsSelected(i) && primary) { - dc.SetPen(GetCalChartPen(COLOR_POINT)); - fillBrush = GetCalChartBrush(COLOR_POINT); + dc.SetPen(config.GetCalChartPen(COLOR_POINT)); + fillBrush = config.GetCalChartBrush(COLOR_POINT); } else { - dc.SetPen(GetCalChartPen(COLOR_REF_POINT)); - fillBrush = GetCalChartBrush(COLOR_REF_POINT); + dc.SetPen(config.GetCalChartPen(COLOR_REF_POINT)); + fillBrush = config.GetCalChartBrush(COLOR_REF_POINT); } - DrawPoint(sheet.GetPoint(i), dc, ref, origin, fillBrush, show.GetPointLabel(i)); + DrawPoint(sheet.GetPoint(i), dc, config, ref, origin, fillBrush, show.GetPointLabel(i)); } dc.SetFont(wxNullFont); } @@ -405,7 +405,7 @@ static std::auto_ptr CreateFieldForPrinting(bool landscape) return std::auto_ptr(new ShowModeStandard(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; @@ -438,18 +438,18 @@ void DrawForPrinting(wxDC *printerdc, const CalChartDoc& show, const CC_sheet& s dc->SetPen(*wxBLACK_PEN); dc->SetTextForeground(*wxBLACK); dc->SetLogicalFunction(wxCOPY); - mode->Draw(*dc); + mode->Draw(*dc, config); 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++) @@ -567,12 +567,12 @@ void DrawForPrinting(wxDC *printerdc, const CalChartDoc& show, const CC_sheet& s } void -DrawPoint(const CC_point& point, wxDC& dc, unsigned reference, const CC_coord& origin, const wxBrush& fillBrush, const wxString& label) +DrawPoint(const CC_point& point, wxDC& dc, const CalChartConfiguration& config, unsigned reference, const CC_coord& origin, const wxBrush& fillBrush, const wxString& label) { - 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 = point.GetPos(reference).x + origin.x; @@ -645,13 +645,13 @@ 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)); + dc.SetPen(config.GetCalChartPen(COLOR_PATHS)); DrawCC_DrawCommandList(dc, draw_commands); - dc.SetBrush(GetCalChartBrush(COLOR_PATHS)); - float circ_r = Float2Coord(GetConfiguration_DotRatio()); + dc.SetBrush(config.GetCalChartBrush(COLOR_PATHS)); + 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 17db8dce..126ef316 100644 --- a/src/draw.h +++ b/src/draw.h @@ -35,12 +35,13 @@ 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 Draw(wxDC& dc, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool primary); +void Draw(wxDC& dc, const CalChartConfiguration& config, 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 DrawForPrinting(wxDC *dc, const CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool landscape); void PrintStandard(std::ostream& buffer, const CC_sheet& sheet); void PrintSpringshow(std::ostream& buffer, const CC_sheet& sheet); @@ -50,9 +51,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 wxBrush& fillBrush, const wxString& label); +void DrawPoint(const CC_point& point, wxDC& dc, const CalChartConfiguration& config, unsigned reference, const CC_coord& origin, const wxBrush& fillBrush, 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/field_canvas.cpp b/src/field_canvas.cpp index 8ac9a346..8f55f4fc 100644 --- a/src/field_canvas.cpp +++ b/src/field_canvas.cpp @@ -84,7 +84,7 @@ FieldCanvas::OnPaint(wxPaintEvent& event) if (curr_shape) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetCalChartPen(COLOR_SHAPES)); + dc.SetPen(GetConfig().GetCalChartPen(COLOR_SHAPES)); CC_coord origin = mView->GetShowFieldOffset(); for (auto i=shape_list.begin(); i != shape_list.end(); @@ -100,7 +100,7 @@ FieldCanvas::PaintBackground(wxDC& dc) { // draw the background dc.SetBackgroundMode(wxTRANSPARENT); - dc.SetBackground(GetCalChartBrush(COLOR_FIELD)); + dc.SetBackground(GetConfig().GetCalChartBrush(COLOR_FIELD)); dc.Clear(); } diff --git a/src/field_frame.cpp b/src/field_frame.cpp index a9588093..6e0a6a40 100644 --- a/src/field_frame.cpp +++ b/src/field_frame.cpp @@ -152,7 +152,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) @@ -169,19 +169,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 @@ -257,7 +259,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); @@ -296,7 +298,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); @@ -386,7 +388,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; @@ -416,8 +418,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()) { @@ -450,7 +452,7 @@ void FieldFrame::OnCmdLegacyPrint(wxCommandEvent& event) PrintPostScriptDialog dialog(static_cast(GetDocument()), false, this); if (dialog.ShowModal() == wxID_OK) { - dialog.PrintShow(); + dialog.PrintShow(config); } } } @@ -462,7 +464,7 @@ void FieldFrame::OnCmdLegacyPrintEPS(wxCommandEvent& event) PrintPostScriptDialog dialog(static_cast(GetDocument()), true, this); if (dialog.ShowModal() == wxID_OK) { - dialog.PrintShow(); + dialog.PrintShow(config); } } } @@ -626,7 +628,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())); } } @@ -854,8 +856,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); } @@ -1036,7 +1038,7 @@ void FieldFrame::zoom_callback(wxCommandEvent& event) { zoom_amount = mCanvas->ZoomToFitFactor(); } - SetConfiguration_FieldFrameZoom(zoom_amount); + config.Set_FieldFrameZoom(zoom_amount); mCanvas->SetZoom(zoom_amount); } @@ -1065,7 +1067,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 e419445c..3375a0ad 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); @@ -141,6 +142,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 157ec493..e7134004 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), +config(GetConfig()) { } @@ -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, config, wxStaticCast(wxGetApp().GetTopWindow(), wxDocParentFrame), wxPoint(50, 50), wxSize(config.Get_FieldFrameWidth(), config.Get_FieldFrameHeight())); #endif mFrame->Show(true); @@ -78,21 +79,21 @@ FieldView::OnDraw(wxDC *dc) if (mShow) { // draw the field - dc->SetPen(GetCalChartPen(COLOR_FIELD_DETAIL)); - dc->SetTextForeground(GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); - mShow->GetMode().Draw(*dc); + dc->SetPen(GetConfig().GetCalChartPen(COLOR_FIELD_DETAIL)); + dc->SetTextForeground(GetConfig().GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + mShow->GetMode().Draw(*dc, config); CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); if (sheet != mShow->GetSheetEnd()) { if (mCurrentReferencePoint > 0) { - Draw(*dc, *mShow, *mShow->GetCurrentSheet(), 0, false); - Draw(*dc, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), 0, false); + Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } else { - Draw(*dc, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } DrawPaths(*dc, *sheet); } @@ -329,7 +330,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(config.Get_DotRatio()), mCurrentReferencePoint); } CC_coord @@ -430,7 +431,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, config, mAnimation->GenPathToDraw(*point, origin), mAnimation->EndPosition(*point, origin)); } } } diff --git a/src/field_view.h b/src/field_view.h index 926a5461..054cd32a 100644 --- a/src/field_view.h +++ b/src/field_view.h @@ -34,6 +34,7 @@ class FieldFrame; class AnimationFrame; class Animation; class Matrix; +class CalChartConfiguration; // Field: // Field is the editable overhead view of the marchers on the field. @@ -110,6 +111,7 @@ class FieldView : public wxView private: CalChartDoc* mShow; unsigned mCurrentReferencePoint; + CalChartConfiguration& config; DECLARE_DYNAMIC_CLASS(FieldView) }; diff --git a/src/modes.cpp b/src/modes.cpp index 52c8b593..aebbfbc5 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -86,7 +86,7 @@ ShowMode::ClipPosition(const CC_coord& pos) const wxImage -ShowMode::GetOmniLinesImage() const +ShowMode::GetOmniLinesImage(const CalChartConfiguration& config) const { CC_coord fieldsize = mSize - mBorder1 - mBorder2; wxBitmap bmp(fieldsize.x, fieldsize.y, 32); @@ -94,9 +94,9 @@ ShowMode::GetOmniLinesImage() const dc.SelectObject(bmp); dc.SetBackground(*wxTRANSPARENT_BRUSH); dc.Clear(); - dc.SetPen(GetCalChartPen(COLOR_FIELD_DETAIL)); - dc.SetTextForeground(GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); - DrawOmni(dc); + dc.SetPen(config.GetCalChartPen(COLOR_FIELD_DETAIL)); + dc.SetTextForeground(config.GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + DrawOmni(dc, config); dc.SelectObject(wxNullBitmap); return bmp.ConvertToImage(); } @@ -121,7 +121,7 @@ ShowMode::ShowType ShowModeStandard::GetType() const return SHOW_STANDARD; } -void ShowModeStandard::DrawHelper(wxDC& dc, HowToDraw howToDraw) const +void ShowModeStandard::DrawHelper(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const { wxPoint points[5]; CC_coord fieldsize = mSize - mBorder1 - mBorder2; @@ -204,16 +204,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)+(MAX_YARD_LINES-1)*4)/8), &textw, &texth, &textd); + dc.DrawText(config.Get_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(config.Get_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)); } } @@ -251,7 +251,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; @@ -297,26 +297,26 @@ 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+(MAX_YARD_LINES-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+(MAX_YARD_LINES-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+(MAX_YARD_LINES-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)); } } diff --git a/src/modes.h b/src/modes.h index 328c6b47..ab482f7c 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 @@ -70,14 +71,14 @@ class ShowMode } HowToDraw; public: - void Draw(wxDC& dc) const { DrawHelper(dc, kFieldView); } - void DrawAnim(wxDC& dc) const { DrawHelper(dc, kAnimation); } - void DrawOmni(wxDC& dc) const { DrawHelper(dc, kOmniView); } + void Draw(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kFieldView); } + void DrawAnim(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kAnimation); } + void DrawOmni(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kOmniView); } - wxImage GetOmniLinesImage() const; + wxImage GetOmniLinesImage(const CalChartConfiguration& config) const; protected: - virtual void DrawHelper(wxDC& dc, HowToDraw howToDraw) const = 0; + virtual void DrawHelper(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const = 0; CC_coord mOffset; CC_coord mSize; @@ -104,7 +105,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: unsigned short mHashW, mHashE; @@ -146,7 +147,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; diff --git a/src/print_ps.cpp b/src/print_ps.cpp index fd12cb7c..2162bd0a 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() + + (MAX_YARD_LINES-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() + + (MAX_YARD_LINES-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 @@ struct 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..8bd778a5 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; @@ -168,18 +168,18 @@ void PrintPostScriptDialog::ShowPrintSelect(wxCommandEvent&) void PrintPostScriptDialog::ResetDefaults(wxCommandEvent&) { #ifdef PRINT__RUN_CMD - ClearConfiguration_PrintCmd(); - ClearConfiguration_PrintOpts(); + GetConfig().Clear_PrintCmd(); + GetConfig().Clear_PrintOpts(); #else - ClearConfiguration_PrintFile(); + GetConfig().Clear_PrintFile(); #endif - ClearConfiguration_PrintViewCmd(); - ClearConfiguration_PrintViewOpts(); + GetConfig().Clear_PrintViewCmd(); + GetConfig().Clear_PrintViewOpts(); - ClearConfiguration_PageOffsetX(); - ClearConfiguration_PageOffsetY(); - ClearConfiguration_PageWidth(); - ClearConfiguration_PageHeight(); + GetConfig().Clear_PageOffsetX(); + GetConfig().Clear_PageOffsetY(); + GetConfig().Clear_PageWidth(); + GetConfig().Clear_PageHeight(); // re-read values TransferDataToWindow(); @@ -390,32 +390,32 @@ void PrintPostScriptDialog::CreateControls() bool PrintPostScriptDialog::TransferDataToWindow() { #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(GetConfig().Get_PrintCmd()); + text_opts->SetValue(GetConfig().Get_PrintOpts()); + text_view_cmd->SetValue(GetConfig().Get_PrintViewCmd()); + text_view_opts->SetValue(GetConfig().Get_PrintViewOpts()); #else - text_cmd->SetValue(GetConfiguration_PrintFile()); + text_cmd->SetValue(GetConfig().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(GetConfig().Get_PrintPSLandscape()); + radio_method->SetSelection(GetConfig().Get_PrintPSModes()); + check_overview->SetValue(GetConfig().Get_PrintPSOverview()); + check_cont->SetValue(GetConfig().Get_PrintPSDoCont()); if (check_pages) { - check_pages->SetValue(GetConfiguration_PrintPSDoContSheet()); + check_pages->SetValue(GetConfig().Get_PrintPSDoContSheet()); } wxString buf; - buf.Printf(wxT("%.2f"),GetConfiguration_PageOffsetX()); + buf.Printf(wxT("%.2f"),GetConfig().Get_PageOffsetX()); text_x->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PageOffsetY()); + buf.Printf(wxT("%.2f"),GetConfig().Get_PageOffsetY()); text_y->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PageWidth()); + buf.Printf(wxT("%.2f"),GetConfig().Get_PageWidth()); text_width->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PageHeight()); + buf.Printf(wxT("%.2f"),GetConfig().Get_PageHeight()); text_height->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfiguration_PaperLength()); + buf.Printf(wxT("%.2f"),GetConfig().Get_PaperLength()); text_length->SetValue(buf); return true; } @@ -423,33 +423,33 @@ bool PrintPostScriptDialog::TransferDataToWindow() bool PrintPostScriptDialog::TransferDataFromWindow() { #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()); + GetConfig().Set_PrintCmd(text_cmd->GetValue()); + GetConfig().Set_PrintOpts(text_opts->GetValue()); + GetConfig().Set_PrintViewCmd(text_view_cmd->GetValue()); + GetConfig().Set_PrintViewOpts(text_view_opts->GetValue()); #else - SetConfiguration_PrintFile(text_cmd->GetValue()); + GetConfig().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()); + GetConfig().Set_PrintPSLandscape(radio_orient->GetSelection() == CC_PRINT_ORIENT_LANDSCAPE); + GetConfig().Set_PrintPSModes(radio_method->GetSelection()); + GetConfig().Set_PrintPSOverview(check_overview->GetValue()); + GetConfig().Set_PrintPSDoCont(check_cont->GetValue()); if (check_pages) { - SetConfiguration_PrintPSDoContSheet(check_pages->GetValue()); + GetConfig().Set_PrintPSDoContSheet(check_pages->GetValue()); } double dval; text_x->GetValue().ToDouble(&dval); - SetConfiguration_PageOffsetX(dval); + GetConfig().Set_PageOffsetX(dval); text_y->GetValue().ToDouble(&dval); - SetConfiguration_PageOffsetY(dval); + GetConfig().Set_PageOffsetY(dval); text_width->GetValue().ToDouble(&dval); - SetConfiguration_PageWidth(dval); + GetConfig().Set_PageWidth(dval); text_height->GetValue().ToDouble(&dval); - SetConfiguration_PageHeight(dval); + GetConfig().Set_PageHeight(dval); text_length->GetValue().ToDouble(&dval); - SetConfiguration_PaperLength(dval); + GetConfig().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; From 152b3303520868f7b9498fce3f12844d12b7a0d6 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Tue, 25 Mar 2014 06:18:15 -0700 Subject: [PATCH 02/11] some modifications to show the field in the preferences. --- src/cc_preferences_ui.cpp | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/src/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp index 21c9f70b..cc83d474 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -22,6 +22,7 @@ #include "cc_preferences_ui.h" #include "confgr.h" +#include "modes.h" #include #include #include @@ -138,8 +139,46 @@ class GeneralSetup : public PreferencePage wxBrush mCalChartBrushes[COLOR_NUM]; wxString mAutoSave_Interval; + wxScrolledWindow* panel; }; +class FieldViewPanel : public wxScrolledWindow +{ + DECLARE_EVENT_TABLE() +public: + FieldViewPanel( wxWindow *parent ) : wxScrolledWindow(parent), + mMode(wxT("Standard"), { 96, 84 }, { 48, 42 }, { 6, 19, }, { 6, 6 }, 32, 52 ) + { +// static std::auto_ptr CreateFieldForPrinting(bool landscape) +// { +// CC_coord bord1(Int2Coord(8),Int2Coord(8)), bord2(Int2Coord(8),Int2Coord(8)); +// CC_coord siz, off; +// uint32_t whash = 32; +// uint32_t ehash = 52; +// bord1.x = Int2Coord((landscape)?12:6); +// bord1.y = Int2Coord((landscape)?21:19); +// bord2.x = Int2Coord((landscape)?12:6); +// bord2.y = Int2Coord((landscape)?12:6); +// siz.x = Int2Coord((landscape)?160:96); +// siz.y = Int2Coord(84); +// off.x = Int2Coord((landscape)?80:48); +// off.y = Int2Coord(42); +// +// return std::auto_ptr(new ShowModeStandard(wxT("Standard"), siz, off, bord1, bord2, whash, ehash)); +// } +// +} + void OnPaint(wxPaintEvent&); + void PaintBackground(wxDC& dc); + void PaintField(wxDC& dc); +private: + ShowModeStandard mMode; +}; +BEGIN_EVENT_TABLE(FieldViewPanel, PreferencePage) +EVT_PAINT(FieldViewPanel::OnPaint) +END_EVENT_TABLE() + + enum { AUTOSAVE_INTERVAL = 1000, @@ -201,9 +240,78 @@ void GeneralSetup::CreateControls() boxsizer->Add(horizontalsizer, sBasicSizerFlags ); + panel = new FieldViewPanel(this); + topsizer->Add(panel, wxSizerFlags(1).Expand().Proportion(1) ); + + TransferDataToWindow(); } +void +FieldViewPanel::OnPaint(wxPaintEvent& event) +{ + wxBufferedPaintDC dc(this); + PrepareDC(dc); + + // draw the background + PaintBackground(dc); +#if 0 + // draw the view + mView->OnDraw(&dc); + + if (curr_shape) + { + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.SetPen(GetConfig().GetCalChartPen(COLOR_SHAPES)); + CC_coord origin = mView->GetShowFieldOffset(); + for (auto i=shape_list.begin(); + i != shape_list.end(); + ++i) + { + DrawCC_DrawCommandList(dc, (*i)->GetCC_DrawCommand(origin.x, origin.y)); + } + } +#endif +} + + +void +FieldViewPanel::PaintBackground(wxDC& dc) +{ + // draw the background + dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackground(GetConfig().GetCalChartBrush(COLOR_FIELD)); + dc.Clear(); + PaintField(dc); +} + +void +FieldViewPanel::PaintField(wxDC& dc) +{ + // draw the field + dc.SetPen(GetConfig().GetCalChartPen(COLOR_FIELD_DETAIL)); + dc.SetTextForeground(GetConfig().GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + mMode.Draw(dc, GetConfig()); + +#if 0 + CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); + if (sheet != mShow->GetSheetEnd()) + { + if (mCurrentReferencePoint > 0) + { + Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), 0, false); + Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + } + else + { + Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + } + DrawPaths(*dc, *sheet); + } +} +#endif +} + void GeneralSetup::Init() { // first read out the defaults: From b9decfd5d8462b6a7cbe189f0aa18fb703bc1b32 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sat, 29 Mar 2014 21:52:00 -0700 Subject: [PATCH 03/11] making it so that changes to the preferences don't require a reboot. --- src/calchartapp.cpp | 8 +- src/calchartapp.h | 4 +- src/calchartdoc.cpp | 6 +- src/calchartdoc.h | 4 +- src/cc_command.cpp | 4 +- src/cc_preferences_ui.cpp | 83 ++++++-------- src/confgr.cpp | 232 ++++++++++++++++++++------------------ src/confgr.h | 24 ++-- src/field_frame.cpp | 12 +- src/field_view.cpp | 4 +- src/setup_wizards.cpp | 8 +- 11 files changed, 196 insertions(+), 193 deletions(-) diff --git a/src/calchartapp.cpp b/src/calchartapp.cpp index 36cf40cd..035a017e 100644 --- a/src/calchartapp.cpp +++ b/src/calchartapp.cpp @@ -64,9 +64,6 @@ bool CalChartApp::OnInit() gPrintDialogData = new wxPrintDialogData(); - // setup the configuration. - ReadConfig(); - //// Create the main frame window wxFrame *frame = new TopFrame(mDocManager, (wxFrame *) NULL, _T("CalChart")); @@ -128,3 +125,8 @@ int CalChartApp::OnExit() return wxApp::OnExit(); } +std::unique_ptr +CalChartApp::GetMode(const wxString& which) +{ + return GetConfig().GetMode(which); +} diff --git a/src/calchartapp.h b/src/calchartapp.h index 9a72ea94..765f7c72 100644 --- a/src/calchartapp.h +++ b/src/calchartapp.h @@ -45,10 +45,8 @@ class CalChartApp : public wxApp virtual void MacOpenFile(const wxString &fileName); int OnExit(); - ShowModeList& GetModeList() { return mModeList; } + std::unique_ptr GetMode(const wxString& which); private: - ShowModeList mModeList; - wxDocManager* mDocManager; }; diff --git a/src/calchartdoc.cpp b/src/calchartdoc.cpp index 3350eb6d..ada557aa 100644 --- a/src/calchartdoc.cpp +++ b/src/calchartdoc.cpp @@ -52,7 +52,7 @@ 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(GetConfig().Get_AutosaveInterval()*1000); @@ -510,13 +510,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 4438b7f7..53bd38f3 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_preferences_ui.cpp b/src/cc_preferences_ui.cpp index cc83d474..1472a8c3 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -139,35 +139,16 @@ class GeneralSetup : public PreferencePage wxBrush mCalChartBrushes[COLOR_NUM]; wxString mAutoSave_Interval; - wxScrolledWindow* panel; + wxPanel* panel; }; -class FieldViewPanel : public wxScrolledWindow +class FieldViewPanel : public wxPanel { DECLARE_EVENT_TABLE() public: - FieldViewPanel( wxWindow *parent ) : wxScrolledWindow(parent), - mMode(wxT("Standard"), { 96, 84 }, { 48, 42 }, { 6, 19, }, { 6, 6 }, 32, 52 ) - { -// static std::auto_ptr CreateFieldForPrinting(bool landscape) -// { -// CC_coord bord1(Int2Coord(8),Int2Coord(8)), bord2(Int2Coord(8),Int2Coord(8)); -// CC_coord siz, off; -// uint32_t whash = 32; -// uint32_t ehash = 52; -// bord1.x = Int2Coord((landscape)?12:6); -// bord1.y = Int2Coord((landscape)?21:19); -// bord2.x = Int2Coord((landscape)?12:6); -// bord2.y = Int2Coord((landscape)?12:6); -// siz.x = Int2Coord((landscape)?160:96); -// siz.y = Int2Coord(84); -// off.x = Int2Coord((landscape)?80:48); -// off.y = Int2Coord(42); -// -// return std::auto_ptr(new ShowModeStandard(wxT("Standard"), siz, off, bord1, bord2, whash, ehash)); -// } -// -} + FieldViewPanel( wxWindow *parent ) : wxPanel(parent), + mMode(wxT("Standard"), { Int2Coord(160), Int2Coord(84) }, { Int2Coord(6), Int2Coord(6) }, { Int2Coord(6), Int2Coord(6), }, { Int2Coord(6), Int2Coord(6) }, Int2Coord(32), Int2Coord(52) ) + {} void OnPaint(wxPaintEvent&); void PaintBackground(wxDC& dc); void PaintField(wxDC& dc); @@ -291,6 +272,7 @@ FieldViewPanel::PaintField(wxDC& dc) // draw the field dc.SetPen(GetConfig().GetCalChartPen(COLOR_FIELD_DETAIL)); dc.SetTextForeground(GetConfig().GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + dc.SetUserScale(1, 1); mMode.Draw(dc, GetConfig()); #if 0 @@ -681,7 +663,7 @@ class ShowModeSetup : public PreferencePage private: void OnCmdLineText(wxCommandEvent&); void OnCmdChoice(wxCommandEvent&); - long mShowModeValues[SHOWMODE_NUM][kShowModeValues]; + std::vector mShowModeValues[SHOWMODE_NUM]; wxString mYardText[MAX_YARD_LINES]; int mWhichMode; int mWhichYardLine; @@ -759,7 +741,7 @@ void ShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - GetConfigurationShowMode(i, mShowModeValues[i]); + mShowModeValues[i] = GetConfig().GetConfigurationShowMode(i); } for (size_t i = 0; i < MAX_YARD_LINES; ++i) { @@ -770,11 +752,11 @@ void ShowModeSetup::Init() 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); } @@ -787,17 +769,17 @@ 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]); + GetConfig().SetConfigurationShowMode(i, mShowModeValues[i]); } for (size_t i = 0; i < MAX_YARD_LINES; ++i) @@ -812,7 +794,7 @@ bool ShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - ClearConfigurationShowMode(i); + GetConfig().ClearConfigurationShowMode(i); } GetConfig().ClearConfigShowYardline(); Init(); @@ -822,12 +804,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(); @@ -870,7 +852,7 @@ class SpringShowModeSetup : public PreferencePage virtual bool ClearValuesToDefault(); private: void OnCmdChoice(wxCommandEvent&); - long mSpringShowModeValues[SPRINGSHOWMODE_NUM][kSpringShowModeValues]; + std::vector mSpringShowModeValues[SPRINGSHOWMODE_NUM]; wxString mYardText[MAX_SPR_LINES]; int mWhichMode; int mWhichYardLine; @@ -986,7 +968,7 @@ void SpringShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - GetConfigurationSpringShowMode(i, mSpringShowModeValues[i]); + mSpringShowModeValues[i] = GetConfig().GetConfigurationSpringShowMode(i); } for (size_t i = 0; i < MAX_SPR_LINES; ++i) { @@ -1002,11 +984,11 @@ bool SpringShowModeSetup::TransferDataToWindow() wxCheckBox* checkbox = (wxCheckBox*) FindWindow(DISPLAY_YARDLINE_BELOW + i); checkbox->SetValue(mSpringShowModeValues[mWhichMode][0] & (1<SetValue(buf); } @@ -1027,18 +1009,18 @@ 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]); + GetConfig().SetConfigurationSpringShowMode(modes->GetSelection(), mSpringShowModeValues[mWhichMode]); } for (size_t i = 0; i < MAX_SPR_LINES; ++i) @@ -1053,7 +1035,7 @@ bool SpringShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - ClearConfigurationSpringShowMode(i); + GetConfig().ClearConfigurationSpringShowMode(i); } GetConfig().ClearConfigSpringShowYardline(); Init(); @@ -1069,12 +1051,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(); @@ -1180,7 +1162,6 @@ 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")); return true; } diff --git a/src/confgr.cpp b/src/confgr.cpp index 08a95aa5..794efd8e 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -165,6 +165,8 @@ const wxString yard_text_index[MAX_YARD_LINES] = 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") }; +static bool yard_text_valid = false; + wxString spr_line_text[MAX_SPR_LINES] = { wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), @@ -175,6 +177,8 @@ const wxString spr_line_text_index[MAX_SPR_LINES] = wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), }; +static bool spr_line_yard_text_valid = false; + #define IMPLEMENT_CONFIGURATION_FUNCTIONS( KeyName, Type, TheValue ) \ static const wxString k ## KeyName ## Key = wxT( #KeyName ); \ static const Type k ## KeyName ## Value = (TheValue); \ @@ -263,6 +267,7 @@ IMPLEMENT_CONFIGURATION_FUNCTIONS( AnimationFrameSplitVertical, bool, false); // Color is more complicated, we use functions for setting that wxPen CalChartPens[COLOR_NUM]; wxBrush CalChartBrushes[COLOR_NUM]; +std::bitset s_brush_pen_valid; ///// Show mode configuration ///// @@ -279,7 +284,7 @@ const wxString kShowModeStrings[SHOWMODE_NUM] = // 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] = +const std::vector kShowModeDefaultValues[SHOWMODE_NUM] = { { 32, 52, 8, 8, 8, 8, -80, -42, 160, 84 }, { 32, 52, 8, 8, 8, 8, -96, -42, 192, 84 }, @@ -301,17 +306,15 @@ const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM] = // 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] = +const std::vector kSpringShowModeDefaultValues[SPRINGSHOWMODE_NUM] = { { 0xD, 8, 8, 8, 8, -16, -30, 32, 28, 0, 0, 571, 400, 163, 38, 265, 232, 153, 438, 270, 12 } }; -void GetConfigurationShowMode(size_t which, long values[kShowModeValues]) +std::vector +CalChartConfiguration::GetConfigurationShowMode(size_t which) { - for (size_t i = 0; i < kShowModeValues; ++i) - { - values[i] = kShowModeDefaultValues[which][i]; - } + std::vector values = kShowModeDefaultValues[which]; wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/SHOWMODES")); @@ -329,14 +332,17 @@ void GetConfigurationShowMode(size_t which, long values[kShowModeValues]) values[8] = config->Read(wxT("offset_x"), values[8]); values[9] = config->Read(wxT("offset_y"), values[9]); } + return values; } -void ReadConfigurationShowMode() +std::unique_ptr +CalChartConfiguration::GetMode(const wxString& which) { - for (size_t i=0; i values = GetConfig().GetConfigurationShowMode(i); unsigned short whash = values[0]; unsigned short ehash = values[1]; CC_coord bord1, bord2; @@ -349,17 +355,54 @@ void ReadConfigurationShowMode() offset.y = Int2Coord(-values[7]); size.x = Int2Coord(values[8]); size.y = Int2Coord(values[9]); - - wxGetApp().GetModeList().emplace_back(std::unique_ptr(new ShowModeStandard(kShowModeStrings[i], size, offset, bord1, bord2, whash, ehash))); + return std::unique_ptr(new ShowModeStandard(kShowModeStrings[i], size, offset, bord1, bord2, whash, ehash)); } + iter = std::find(std::begin(kSpringShowModeStrings), std::end(kSpringShowModeStrings), which); + if (iter != std::end(kSpringShowModeStrings)) + { + auto i = std::distance(std::begin(kSpringShowModeStrings), iter); + std::vector values = GetConfig().GetConfigurationSpringShowMode(i); + 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(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)); + } + return {}; } -void GetConfigurationSpringShowMode(size_t which, long values[kShowModeValues]) +std::vector +CalChartConfiguration::GetConfigurationSpringShowMode(size_t which) { - for (size_t i = 0; i < kSpringShowModeValues; ++i) - { - values[i] = kSpringShowModeDefaultValues[which][i]; - } + std::vector values = kSpringShowModeDefaultValues[which]; wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/SPRINGSHOWMODES")); @@ -389,52 +432,11 @@ void GetConfigurationSpringShowMode(size_t which, long values[kShowModeValues]) values[19] = config->Read(wxT("eps_text_top"), values[19]); values[20] = config->Read(wxT("eps_text_bottom"), values[20]); } + return values; } -void ReadConfigurationSpringShowMode() -{ - 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))); - - } -} - -void SetConfigurationShowMode(size_t which, const long values[kShowModeValues]) +void +CalChartConfiguration::SetConfigurationShowMode(size_t which, const std::vector& values) { wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/SHOWMODES")); @@ -452,7 +454,8 @@ void SetConfigurationShowMode(size_t which, const long values[kShowModeValues]) config->Flush(); } -void SetConfigurationSpringShowMode(size_t which, const long values[kSpringShowModeValues]) +void +CalChartConfiguration::SetConfigurationSpringShowMode(size_t which, const std::vector& values) { wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/SPRINGSHOWMODES")); @@ -482,14 +485,16 @@ void SetConfigurationSpringShowMode(size_t which, const long values[kSpringShowM config->Flush(); } -void ClearConfigurationShowMode(size_t which) +void +CalChartConfiguration::ClearConfigurationShowMode(size_t which) { wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/SHOWMODES")); config->DeleteEntry(kShowModeStrings[which]); } -void ClearConfigurationSpringShowMode(size_t which) +void +CalChartConfiguration::ClearConfigurationSpringShowMode(size_t which) { wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/SPRINGSHOWMODES")); @@ -497,37 +502,38 @@ void ClearConfigurationSpringShowMode(size_t which) } ///// Color Configuration ///// -void ReadConfigColor() +void ReadConfigColor(CalChartColors i) { + if (s_brush_pen_valid.test(i)) + { + return; + } wxConfigBase *config = wxConfigBase::Get(); // read out the color configuration: config->SetPath(wxT("/COLORS")); - for (size_t i=0; iExists(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 { - 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("..")); + 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); + s_brush_pen_valid.set(i); } void @@ -545,16 +551,37 @@ CalChartConfiguration::ClearConfigColor(size_t selection) config->SetPath(wxT("WIDTH")); config->DeleteEntry(ColorNames[selection]); config->Flush(); + s_brush_pen_valid.reset(selection); } void ReadConfigYardlines() { + if (yard_text_valid) + { + return; + } 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]); } + yard_text_valid = true; +} + +void ReadConfigSpringYardlines() +{ + if (spr_line_yard_text_valid) + { + return; + } + 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]); + } + spr_line_yard_text_valid = true; } wxString @@ -562,6 +589,7 @@ CalChartConfiguration::Get_yard_text(size_t which) const { if (which >= MAX_YARD_LINES) throw std::runtime_error("Error, exceeding yard_text size"); + ReadConfigYardlines(); return yard_text[which]; } @@ -581,6 +609,7 @@ CalChartConfiguration::Get_spr_line_text(size_t which) const { if (which >= MAX_SPR_LINES) throw std::runtime_error("Error, exceeding yard_text size"); + ReadConfigSpringYardlines(); return spr_line_text[which]; } @@ -635,17 +664,7 @@ CalChartConfiguration::ClearConfigShowYardline() key.Printf(wxT("YardLines_%ld"), i); ClearConfigValue(key); } - ReadConfigYardlines(); -} - -void ReadConfigSpringYardlines() -{ - 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]); - } + yard_text_valid = false; } void @@ -657,27 +676,20 @@ CalChartConfiguration::ClearConfigSpringShowYardline() key.Printf(wxT("SpringShowYardLines_%ld"), i); ClearConfigValue(key); } - ReadConfigSpringYardlines(); -} - -void ReadConfig() -{ - ReadConfigColor(); - ReadConfigurationShowMode(); - ReadConfigurationSpringShowMode(); - ReadConfigYardlines(); - ReadConfigSpringYardlines(); + spr_line_yard_text_valid = false; } wxBrush CalChartConfiguration::GetCalChartBrush(CalChartColors c) const { + ReadConfigColor(c); return CalChartBrushes[c]; } wxPen CalChartConfiguration::GetCalChartPen(CalChartColors c) const { + ReadConfigColor(c); return CalChartPens[c]; } diff --git a/src/confgr.h b/src/confgr.h index 2f35b8bd..c1909151 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -31,6 +31,7 @@ class wxPen; class wxBrush; class wxPathList; +class ShowMode; #define MAX_SPR_LINES 5 #define MAX_YARD_LINES 53 @@ -177,21 +178,20 @@ class CalChartConfiguration std::vector GetDefaultColors() const; std::vector GetDefaultPenWidth() const; + static const size_t kShowModeValues = 10; + std::vector GetConfigurationShowMode(size_t which); + void SetConfigurationShowMode(size_t which, const std::vector& values); + void ClearConfigurationShowMode(size_t which); + + static const size_t kSpringShowModeValues = 21; + std::vector GetConfigurationSpringShowMode(size_t which); + void SetConfigurationSpringShowMode(size_t which, const std::vector& values); + void ClearConfigurationSpringShowMode(size_t which); + + std::unique_ptr GetMode(const wxString& which); }; CalChartConfiguration& GetConfig(); -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); - #endif diff --git a/src/field_frame.cpp b/src/field_frame.cpp index 6e0a6a40..14b611e8 100644 --- a/src/field_frame.cpp +++ b/src/field_frame.cpp @@ -990,10 +990,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, diff --git a/src/field_view.cpp b/src/field_view.cpp index e7134004..8e98a5ba 100644 --- a/src/field_view.cpp +++ b/src/field_view.cpp @@ -174,10 +174,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()); } 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 ); From 3ec6b8a7f268c874ddc7ec3c9645f3cdf1d80e1d Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sat, 29 Mar 2014 22:22:19 -0700 Subject: [PATCH 04/11] Cleaning up the work of making a special preferences graphic (wasn't working out so well) --- src/cc_preferences_ui.cpp | 94 +++------------------------------------ 1 file changed, 5 insertions(+), 89 deletions(-) diff --git a/src/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp index 1472a8c3..32218351 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -139,27 +139,8 @@ class GeneralSetup : public PreferencePage wxBrush mCalChartBrushes[COLOR_NUM]; wxString mAutoSave_Interval; - wxPanel* panel; }; -class FieldViewPanel : public wxPanel -{ - DECLARE_EVENT_TABLE() -public: - FieldViewPanel( wxWindow *parent ) : wxPanel(parent), - mMode(wxT("Standard"), { Int2Coord(160), Int2Coord(84) }, { Int2Coord(6), Int2Coord(6) }, { Int2Coord(6), Int2Coord(6), }, { Int2Coord(6), Int2Coord(6) }, Int2Coord(32), Int2Coord(52) ) - {} - void OnPaint(wxPaintEvent&); - void PaintBackground(wxDC& dc); - void PaintField(wxDC& dc); -private: - ShowModeStandard mMode; -}; -BEGIN_EVENT_TABLE(FieldViewPanel, PreferencePage) -EVT_PAINT(FieldViewPanel::OnPaint) -END_EVENT_TABLE() - - enum { AUTOSAVE_INTERVAL = 1000, @@ -221,79 +202,9 @@ void GeneralSetup::CreateControls() boxsizer->Add(horizontalsizer, sBasicSizerFlags ); - panel = new FieldViewPanel(this); - topsizer->Add(panel, wxSizerFlags(1).Expand().Proportion(1) ); - - TransferDataToWindow(); } -void -FieldViewPanel::OnPaint(wxPaintEvent& event) -{ - wxBufferedPaintDC dc(this); - PrepareDC(dc); - - // draw the background - PaintBackground(dc); -#if 0 - // draw the view - mView->OnDraw(&dc); - - if (curr_shape) - { - dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetConfig().GetCalChartPen(COLOR_SHAPES)); - CC_coord origin = mView->GetShowFieldOffset(); - for (auto i=shape_list.begin(); - i != shape_list.end(); - ++i) - { - DrawCC_DrawCommandList(dc, (*i)->GetCC_DrawCommand(origin.x, origin.y)); - } - } -#endif -} - - -void -FieldViewPanel::PaintBackground(wxDC& dc) -{ - // draw the background - dc.SetBackgroundMode(wxTRANSPARENT); - dc.SetBackground(GetConfig().GetCalChartBrush(COLOR_FIELD)); - dc.Clear(); - PaintField(dc); -} - -void -FieldViewPanel::PaintField(wxDC& dc) -{ - // draw the field - dc.SetPen(GetConfig().GetCalChartPen(COLOR_FIELD_DETAIL)); - dc.SetTextForeground(GetConfig().GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); - dc.SetUserScale(1, 1); - mMode.Draw(dc, GetConfig()); - -#if 0 - CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); - if (sheet != mShow->GetSheetEnd()) - { - if (mCurrentReferencePoint > 0) - { - Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), 0, false); - Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); - } - else - { - Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); - } - DrawPaths(*dc, *sheet); - } -} -#endif -} - void GeneralSetup::Init() { // first read out the defaults: @@ -782,6 +693,9 @@ bool ShowModeSetup::TransferDataFromWindow() GetConfig().SetConfigurationShowMode(i, mShowModeValues[i]); } + // grab whatever's in the box + wxTextCtrl* text = (wxTextCtrl*) FindWindow(SHOW_LINE_VALUE); + mYardText[mWhichYardLine] = text->GetValue(); for (size_t i = 0; i < MAX_YARD_LINES; ++i) { GetConfig().Set_yard_text(i, mYardText[i]); @@ -1023,6 +937,8 @@ bool SpringShowModeSetup::TransferDataFromWindow() GetConfig().SetConfigurationSpringShowMode(modes->GetSelection(), mSpringShowModeValues[mWhichMode]); } + wxTextCtrl* text = (wxTextCtrl*) FindWindow(SPRING_SHOW_LINE_VALUE); + mYardText[mWhichYardLine] = text->GetValue(); for (size_t i = 0; i < MAX_SPR_LINES; ++i) { GetConfig().Set_spr_line_text(i, mYardText[i]); From 201ac0ddbcdfb41aeaa193d85c65cc5c081b3775 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sat, 29 Mar 2014 22:30:48 -0700 Subject: [PATCH 05/11] using GetConfig only when we need to. --- src/animation_view.cpp | 33 +++++++++-------- src/field_view.cpp | 4 +- src/print_ps_dialog.cpp | 81 +++++++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/animation_view.cpp b/src/animation_view.cpp index e553a92c..7a716c52 100644 --- a/src/animation_view.cpp +++ b/src/animation_view.cpp @@ -54,8 +54,9 @@ AnimationView::~AnimationView() void AnimationView::OnDraw(wxDC *dc) { - dc->SetPen(GetConfig().GetCalChartPen(COLOR_FIELD_DETAIL)); - GetShow()->GetMode().DrawAnim(*dc, GetConfig()); + auto& config = GetConfig(); + dc->SetPen(config.GetCalChartPen(COLOR_FIELD_DETAIL)); + GetShow()->GetMode().DrawAnim(*dc, config); const bool checkForCollision = mCollisionWarningType != COLLISION_NONE; if (mAnimation) { @@ -65,8 +66,8 @@ AnimationView::OnDraw(wxDC *dc) if (checkForCollision && info.mCollision) { - dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_COLLISION)); - dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_COLLISION)); + dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_COLLISION)); + dc->SetBrush(config.GetCalChartBrush(COLOR_POINT_ANIM_COLLISION)); } else if (GetShow()->IsSelected(i)) { @@ -75,18 +76,18 @@ AnimationView::OnDraw(wxDC *dc) case ANIMDIR_SW: case ANIMDIR_W: case ANIMDIR_NW: - dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_HILIT_BACK)); - dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_HILIT_BACK)); + dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_HILIT_BACK)); + dc->SetBrush(config.GetCalChartBrush(COLOR_POINT_ANIM_HILIT_BACK)); break; case ANIMDIR_SE: case ANIMDIR_E: case ANIMDIR_NE: - dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_HILIT_FRONT)); - dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_HILIT_FRONT)); + dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_HILIT_FRONT)); + dc->SetBrush(config.GetCalChartBrush(COLOR_POINT_ANIM_HILIT_FRONT)); break; default: - dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_HILIT_SIDE)); - dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_HILIT_SIDE)); + dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_HILIT_SIDE)); + dc->SetBrush(config.GetCalChartBrush(COLOR_POINT_ANIM_HILIT_SIDE)); } } else @@ -96,18 +97,18 @@ AnimationView::OnDraw(wxDC *dc) case ANIMDIR_SW: case ANIMDIR_W: case ANIMDIR_NW: - dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_BACK)); - dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_BACK)); + dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_BACK)); + dc->SetBrush(config.GetCalChartBrush(COLOR_POINT_ANIM_BACK)); break; case ANIMDIR_SE: case ANIMDIR_E: case ANIMDIR_NE: - dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_FRONT)); - dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_FRONT)); + dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_FRONT)); + dc->SetBrush(config.GetCalChartBrush(COLOR_POINT_ANIM_FRONT)); break; default: - dc->SetPen(GetConfig().GetCalChartPen(COLOR_POINT_ANIM_SIDE)); - dc->SetBrush(GetConfig().GetCalChartBrush(COLOR_POINT_ANIM_SIDE)); + dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_SIDE)); + dc->SetBrush(config.GetCalChartBrush(COLOR_POINT_ANIM_SIDE)); } } CC_coord position = info.mPosition; diff --git a/src/field_view.cpp b/src/field_view.cpp index 8e98a5ba..f8b8929b 100644 --- a/src/field_view.cpp +++ b/src/field_view.cpp @@ -79,8 +79,8 @@ FieldView::OnDraw(wxDC *dc) if (mShow) { // draw the field - dc->SetPen(GetConfig().GetCalChartPen(COLOR_FIELD_DETAIL)); - dc->SetTextForeground(GetConfig().GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + dc->SetPen(config.GetCalChartPen(COLOR_FIELD_DETAIL)); + dc->SetTextForeground(config.GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); mShow->GetMode().Draw(*dc, config); CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); diff --git a/src/print_ps_dialog.cpp b/src/print_ps_dialog.cpp index 8bd778a5..223c7915 100644 --- a/src/print_ps_dialog.cpp +++ b/src/print_ps_dialog.cpp @@ -167,19 +167,20 @@ void PrintPostScriptDialog::ShowPrintSelect(wxCommandEvent&) void PrintPostScriptDialog::ResetDefaults(wxCommandEvent&) { + auto& config = GetConfig(); #ifdef PRINT__RUN_CMD - GetConfig().Clear_PrintCmd(); - GetConfig().Clear_PrintOpts(); + config.Clear_PrintCmd(); + config.Clear_PrintOpts(); #else - GetConfig().Clear_PrintFile(); + config.Clear_PrintFile(); #endif - GetConfig().Clear_PrintViewCmd(); - GetConfig().Clear_PrintViewOpts(); + config.Clear_PrintViewCmd(); + config.Clear_PrintViewOpts(); - GetConfig().Clear_PageOffsetX(); - GetConfig().Clear_PageOffsetY(); - GetConfig().Clear_PageWidth(); - GetConfig().Clear_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 = GetConfig(); #ifdef PRINT__RUN_CMD - text_cmd->SetValue(GetConfig().Get_PrintCmd()); - text_opts->SetValue(GetConfig().Get_PrintOpts()); - text_view_cmd->SetValue(GetConfig().Get_PrintViewCmd()); - text_view_opts->SetValue(GetConfig().Get_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(GetConfig().Get_PrintFile()); + text_cmd->SetValue(config.Get_PrintFile()); #endif - radio_orient->SetSelection(GetConfig().Get_PrintPSLandscape()); - radio_method->SetSelection(GetConfig().Get_PrintPSModes()); - check_overview->SetValue(GetConfig().Get_PrintPSOverview()); - check_cont->SetValue(GetConfig().Get_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(GetConfig().Get_PrintPSDoContSheet()); + check_pages->SetValue(config.Get_PrintPSDoContSheet()); } wxString buf; - buf.Printf(wxT("%.2f"),GetConfig().Get_PageOffsetX()); + buf.Printf(wxT("%.2f"),config.Get_PageOffsetX()); text_x->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfig().Get_PageOffsetY()); + buf.Printf(wxT("%.2f"),config.Get_PageOffsetY()); text_y->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfig().Get_PageWidth()); + buf.Printf(wxT("%.2f"),config.Get_PageWidth()); text_width->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfig().Get_PageHeight()); + buf.Printf(wxT("%.2f"),config.Get_PageHeight()); text_height->SetValue(buf); - buf.Printf(wxT("%.2f"),GetConfig().Get_PaperLength()); + buf.Printf(wxT("%.2f"),config.Get_PaperLength()); text_length->SetValue(buf); return true; } bool PrintPostScriptDialog::TransferDataFromWindow() { + auto& config = GetConfig(); #ifdef PRINT__RUN_CMD - GetConfig().Set_PrintCmd(text_cmd->GetValue()); - GetConfig().Set_PrintOpts(text_opts->GetValue()); - GetConfig().Set_PrintViewCmd(text_view_cmd->GetValue()); - GetConfig().Set_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 - GetConfig().Set_PrintFile(text_cmd->GetValue()); + config.Set_PrintFile(text_cmd->GetValue()); #endif - GetConfig().Set_PrintPSLandscape(radio_orient->GetSelection() == CC_PRINT_ORIENT_LANDSCAPE); - GetConfig().Set_PrintPSModes(radio_method->GetSelection()); - GetConfig().Set_PrintPSOverview(check_overview->GetValue()); - GetConfig().Set_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) { - GetConfig().Set_PrintPSDoContSheet(check_pages->GetValue()); + config.Set_PrintPSDoContSheet(check_pages->GetValue()); } double dval; text_x->GetValue().ToDouble(&dval); - GetConfig().Set_PageOffsetX(dval); + config.Set_PageOffsetX(dval); text_y->GetValue().ToDouble(&dval); - GetConfig().Set_PageOffsetY(dval); + config.Set_PageOffsetY(dval); text_width->GetValue().ToDouble(&dval); - GetConfig().Set_PageWidth(dval); + config.Set_PageWidth(dval); text_height->GetValue().ToDouble(&dval); - GetConfig().Set_PageHeight(dval); + config.Set_PageHeight(dval); text_length->GetValue().ToDouble(&dval); - GetConfig().Set_PaperLength(dval); + config.Set_PaperLength(dval); return true; } From 31e94c21c2b62ca90e772155ba68dd6011866ca6 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Mon, 30 Jun 2014 22:57:37 -0700 Subject: [PATCH 06/11] More work on improving config. --- .../CalChart.xcodeproj/project.pbxproj | 2 + src/animation_canvas.cpp | 2 +- src/animation_view.cpp | 6 + src/animation_view.h | 2 + src/confgr.cpp | 249 +++++++----------- src/confgr.h | 4 + src/draw.cpp | 38 +-- src/draw_utils.h | 65 +++++ src/modes.cpp | 57 ++++ src/modes.h | 5 + 10 files changed, 232 insertions(+), 198 deletions(-) create mode 100644 src/draw_utils.h diff --git a/build-macos/CalChart.xcodeproj/project.pbxproj b/build-macos/CalChart.xcodeproj/project.pbxproj index 0c0c4b8f..10ea2eb7 100644 --- a/build-macos/CalChart.xcodeproj/project.pbxproj +++ b/build-macos/CalChart.xcodeproj/project.pbxproj @@ -963,6 +963,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 = ""; }; @@ -1185,6 +1186,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 a93ae764..9bd42350 100644 --- a/src/animation_canvas.cpp +++ b/src/animation_canvas.cpp @@ -79,7 +79,7 @@ AnimationCanvas::OnPaint(wxPaintEvent& event) } if (mAnimationView) { - mAnimationView->OnDraw(&dc); + mAnimationView->OnDraw(&dc, GetConfig()); } } diff --git a/src/animation_view.cpp b/src/animation_view.cpp index 7a716c52..2a62bef3 100644 --- a/src/animation_view.cpp +++ b/src/animation_view.cpp @@ -55,6 +55,12 @@ void AnimationView::OnDraw(wxDC *dc) { auto& config = GetConfig(); + OnDraw(dc, config); +} + +void +AnimationView::OnDraw(wxDC *dc, const CalChartConfiguration& config) +{ dc->SetPen(config.GetCalChartPen(COLOR_FIELD_DETAIL)); GetShow()->GetMode().DrawAnim(*dc, config); const bool checkForCollision = mCollisionWarningType != COLLISION_NONE; diff --git a/src/animation_view.h b/src/animation_view.h index d9f8e52d..26d774e8 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/confgr.cpp b/src/confgr.cpp index 794efd8e..97cf43d2 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -29,82 +29,35 @@ #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("ANIM FRONT"), - wxT("ANIM BACK"), - wxT("ANIM SIDE"), - wxT("HILIT ANIM FRONT"), - wxT("HILIT ANIM BACK"), - wxT("HILIT ANIM SIDE"), - wxT("ANIM COLLISION"), - wxT("CONTINUITY PATHS"), - wxT("SHAPES") -}; - -const wxString DefaultColors[COLOR_NUM] = -{ - wxT("FOREST GREEN"), - wxT("WHITE"), - wxT("BLACK"), - wxT("WHITE"), - wxT("BLACK"), - wxT("YELLOW"), - wxT("BLACK"), - wxT("PURPLE"), - wxT("BLACK"), - wxT("PURPLE"), - wxT("BLACK"), - wxT("WHITE"), - wxT("YELLOW"), - wxT("SKY BLUE"), - wxT("RED"), - wxT("RED"), - wxT("RED"), - wxT("PURPLE"), - wxT("RED"), - wxT("ORANGE") -}; - -const int DefaultPenWidth[COLOR_NUM] = -{ - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 2, +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("BLACK"), 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("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("CONTINUITY PATHS"), wxT("RED"), 1 }, + { wxT("SHAPES"), wxT("ORANGE"), 2 }, }; CalChartConfiguration& GetConfig() @@ -264,11 +217,6 @@ 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]; -std::bitset s_brush_pen_valid; - ///// Show mode configuration ///// const wxString kShowModeStrings[SHOWMODE_NUM] = @@ -341,60 +289,12 @@ CalChartConfiguration::GetMode(const wxString& which) auto iter = std::find(std::begin(kShowModeStrings), std::end(kShowModeStrings), which); if (iter != std::end(kShowModeStrings)) { - auto i = std::distance(std::begin(kShowModeStrings), iter); - std::vector values = GetConfig().GetConfigurationShowMode(i); - 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(kShowModeStrings[i], size, offset, bord1, bord2, whash, ehash)); + return CreateShowMode(which, GetConfig().GetConfigurationShowMode(std::distance(std::begin(kShowModeStrings), iter))); } iter = std::find(std::begin(kSpringShowModeStrings), std::end(kSpringShowModeStrings), which); if (iter != std::end(kSpringShowModeStrings)) { - auto i = std::distance(std::begin(kSpringShowModeStrings), iter); - std::vector values = GetConfig().GetConfigurationSpringShowMode(i); - 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(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)); + return CreateSpringShowMode(which, GetConfig().GetConfigurationSpringShowMode(std::distance(std::begin(kSpringShowModeStrings), iter))); } return {}; } @@ -502,38 +402,57 @@ CalChartConfiguration::ClearConfigurationSpringShowMode(size_t which) } ///// Color Configuration ///// -void ReadConfigColor(CalChartColors i) +// Color is more complicated, we use functions for setting that +std::array sColors[COLOR_NUM]; +long sWidths[COLOR_NUM]; +std::bitset s_color_valid; +std::bitset s_width_valid; + +std::array ReadConfigColor(CalChartColors i) { - if (s_brush_pen_valid.test(i)) + if (s_color_valid.test(i)) { - return; + return sColors[i]; } wxConfigBase *config = wxConfigBase::Get(); // read out the color configuration: config->SetPath(wxT("/COLORS")); - wxColour c; - wxString rbuf = ColorNames[i] + wxT("_Red"); - wxString gbuf = ColorNames[i] + wxT("_Green"); - wxString bbuf = ColorNames[i] + wxT("_Blue"); + wxString rbuf = std::get<0>(ColorInfo[i]) + wxT("_Red"); + wxString gbuf = std::get<0>(ColorInfo[i]) + wxT("_Green"); + wxString bbuf = std::get<0>(ColorInfo[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); + sColors[i] = { {r, g, b} }; } else { - c = wxColour(DefaultColors[i]); + auto color = wxColour(std::get<1>(ColorInfo[i])); + sColors[i] = { {color.Red(), color.Green(), color.Blue()} }; } - CalChartBrushes[i] = *wxTheBrushList->FindOrCreateBrush(c, wxSOLID); + s_color_valid.set(i); + return sColors[i]; +} + +long ReadConfigColorWidth(CalChartColors i) +{ + if (s_width_valid.test(i)) + { + return sWidths[i]; + } + wxConfigBase *config = wxConfigBase::Get(); + + // read out the color configuration: + config->SetPath(wxT("/COLORS")); // 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); - s_brush_pen_valid.set(i); + sWidths[i] = std::get<2>(ColorInfo[i]); + config->Read(std::get<0>(ColorInfo[i]), &sWidths[i]); + s_width_valid.set(i); + return sWidths[i]; } void @@ -542,16 +461,17 @@ CalChartConfiguration::ClearConfigColor(size_t selection) wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/COLORS")); - wxString rbuf = ColorNames[selection] + wxT("_Red"); + wxString rbuf = std::get<0>(ColorInfo[selection]) + wxT("_Red"); config->DeleteEntry(rbuf); - wxString gbuf = ColorNames[selection] + wxT("_Green"); + wxString gbuf = std::get<0>(ColorInfo[selection]) + wxT("_Green"); config->DeleteEntry(gbuf); - wxString bbuf = ColorNames[selection] + wxT("_Blue"); + wxString bbuf = std::get<0>(ColorInfo[selection]) + wxT("_Blue"); config->DeleteEntry(bbuf); config->SetPath(wxT("WIDTH")); - config->DeleteEntry(ColorNames[selection]); + config->DeleteEntry(std::get<0>(ColorInfo[selection])); config->Flush(); - s_brush_pen_valid.reset(selection); + s_color_valid.reset(selection); + s_width_valid.reset(selection); } void ReadConfigYardlines() @@ -639,19 +559,25 @@ CalChartConfiguration::Get_spr_line_text_index() const std::vector CalChartConfiguration::GetColorNames() const { - return { std::begin(ColorNames), std::end(ColorNames) }; + 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; } std::vector CalChartConfiguration::GetDefaultColors() const { - return { std::begin(DefaultColors), std::end(DefaultColors) }; + 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; } std::vector CalChartConfiguration::GetDefaultPenWidth() const { - return { std::begin(DefaultPenWidth), std::end(DefaultPenWidth) }; + 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; } @@ -682,15 +608,18 @@ CalChartConfiguration::ClearConfigSpringShowYardline() wxBrush CalChartConfiguration::GetCalChartBrush(CalChartColors c) const { - ReadConfigColor(c); - return CalChartBrushes[c]; + auto color_values = ReadConfigColor(c); + auto color = wxColour(color_values[0], color_values[1], color_values[2]); + return *wxTheBrushList->FindOrCreateBrush(color, wxSOLID); } wxPen CalChartConfiguration::GetCalChartPen(CalChartColors c) const { - ReadConfigColor(c); - return CalChartPens[c]; + auto color_values = ReadConfigColor(c); + auto color = wxColour(color_values[0], color_values[1], color_values[2]); + auto width = ReadConfigColorWidth(c); + return *wxThePenList->FindOrCreatePen(color, width, wxSOLID); } void @@ -698,20 +627,20 @@ CalChartConfiguration::SetCalChartBrushAndPen(CalChartColors c, const wxBrush& b { if (c >= COLOR_NUM) throw std::runtime_error("Error, exceeding COLOR_NUM size"); - CalChartBrushes[c] = brush; - CalChartPens[c] = pen; wxConfigBase *config = wxConfigBase::Get(); // read out the color configuration: config->SetPath(wxT("/COLORS")); - wxString rbuf = ColorNames[c] + wxT("_Red"); - config->Write(rbuf, static_cast(CalChartBrushes[c].GetColour().Red())); - wxString gbuf = ColorNames[c] + wxT("_Green"); - config->Write(gbuf, static_cast(CalChartBrushes[c].GetColour().Green())); - wxString bbuf = ColorNames[c] + wxT("_Blue"); - config->Write(bbuf, static_cast(CalChartBrushes[c].GetColour().Blue())); + wxString rbuf = std::get<0>(ColorInfo[c]) + wxT("_Red"); + config->Write(rbuf, static_cast(brush.GetColour().Red())); + wxString gbuf = std::get<0>(ColorInfo[c]) + wxT("_Green"); + config->Write(gbuf, static_cast(brush.GetColour().Green())); + wxString bbuf = std::get<0>(ColorInfo[c]) + wxT("_Blue"); + config->Write(bbuf, static_cast(brush.GetColour().Blue())); config->SetPath(wxT("WIDTH")); - config->Write(ColorNames[c], CalChartPens[c].GetWidth()); + config->Write(std::get<0>(ColorInfo[c]), pen.GetWidth()); config->Flush(); + s_color_valid.reset(c); + s_width_valid.reset(c); } diff --git a/src/confgr.h b/src/confgr.h index c1909151..93a6ebb6 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -81,6 +81,10 @@ enum CalChartSpringShowModes extern const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM]; +// so: +// we take a snapshot of the config and give to the system to use. They can modify. +// on the d-tor, save out the values that it may have changed; unless it was told to be +// discarded. class CalChartConfiguration { public: diff --git a/src/draw.cpp b/src/draw.cpp index dd0efe51..01b60ed8 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -33,47 +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); } -}; - // draw text centered around x (though still at y down) void DrawCenteredText(wxDC& dc, const wxString& text, const wxPoint& pt) { diff --git a/src/draw_utils.h b/src/draw_utils.h new file mode 100644 index 00000000..623bc9a2 --- /dev/null +++ b/src/draw_utils.h @@ -0,0 +1,65 @@ +/* + * 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); } +}; + +#endif // __DRAW_UTILS_H__ diff --git a/src/modes.cpp b/src/modes.cpp index aebbfbc5..4c131cc5 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -338,3 +338,60 @@ ShowModeList_Find(const ShowModeList& showModes, const wxString& which) return (*i).get(); return NULL; } + +std::unique_ptr +CreateShowMode(const wxString& which, std::vector values) +{ + 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 +CreateSpringShowMode(const wxString& which, std::vector 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 ab482f7c..78447a07 100644 --- a/src/modes.h +++ b/src/modes.h @@ -162,4 +162,9 @@ typedef std::list > ShowModeList; ShowMode* ShowModeList_Find(const ShowModeList& showModes, const wxString& which); +std::unique_ptr +CreateShowMode(const wxString& which, std::vector values); +std::unique_ptr +CreateSpringShowMode(const wxString& which, std::vector values); + #endif From ba69acc916cffc82d7b3d3b5dbb88e7b9f6ba965 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Mon, 18 Aug 2014 22:40:09 -0700 Subject: [PATCH 07/11] Now we draw a little preview of the changes. Getting changes to have a write-queue, currently disabled. You can change the way things draw. --- src/animation_canvas.cpp | 4 +- src/animation_view.cpp | 49 ++++++--- src/cc_preferences_ui.cpp | 147 ++++++++++++++++++++++--- src/confgr.cpp | 219 +++++++++++++++++++------------------- src/confgr.h | 35 ++++-- src/cont_ui.cpp | 7 ++ src/core/cc_drawcommand.h | 11 ++ src/core/cc_show.cpp | 1 + src/draw.cpp | 40 +++---- src/draw.h | 4 +- src/field_canvas.cpp | 4 +- src/field_view.cpp | 11 +- src/modes.cpp | 4 +- 13 files changed, 362 insertions(+), 174 deletions(-) diff --git a/src/animation_canvas.cpp b/src/animation_canvas.cpp index 9bd42350..301509c4 100644 --- a/src/animation_canvas.cpp +++ b/src/animation_canvas.cpp @@ -66,14 +66,14 @@ AnimationCanvas::OnPaint(wxPaintEvent& event) { wxBufferedPaintDC dc(this); - dc.SetBackground(GetConfig().GetCalChartBrush(COLOR_FIELD)); + dc.SetBackground(GetConfig().Get_CalChartBrushAndPen(COLOR_FIELD).first); dc.Clear(); dc.SetUserScale(mUserScale, mUserScale); dc.SetDeviceOrigin(mUserOriginX, 0); if (mMouseDown) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetConfig().GetCalChartPen(COLOR_SHAPES)); + dc.SetPen(GetConfig().Get_CalChartBrushAndPen(COLOR_SHAPES).second); dc.DrawRectangle(mMouseXStart, mMouseYStart, mMouseXEnd - mMouseXStart, mMouseYEnd - mMouseYStart); } diff --git a/src/animation_view.cpp b/src/animation_view.cpp index 2a62bef3..4b399c9a 100644 --- a/src/animation_view.cpp +++ b/src/animation_view.cpp @@ -61,7 +61,7 @@ AnimationView::OnDraw(wxDC *dc) void AnimationView::OnDraw(wxDC *dc, const CalChartConfiguration& config) { - dc->SetPen(config.GetCalChartPen(COLOR_FIELD_DETAIL)); + dc->SetPen(config.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); GetShow()->GetMode().DrawAnim(*dc, config); const bool checkForCollision = mCollisionWarningType != COLLISION_NONE; if (mAnimation) @@ -72,8 +72,9 @@ AnimationView::OnDraw(wxDC *dc, const CalChartConfiguration& config) if (checkForCollision && info.mCollision) { - dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_COLLISION)); - dc->SetBrush(config.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)) { @@ -82,18 +83,27 @@ AnimationView::OnDraw(wxDC *dc, const CalChartConfiguration& config) case ANIMDIR_SW: case ANIMDIR_W: case ANIMDIR_NW: - dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_HILIT_BACK)); - dc->SetBrush(config.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(config.GetCalChartPen(COLOR_POINT_ANIM_HILIT_FRONT)); - dc->SetBrush(config.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(config.GetCalChartPen(COLOR_POINT_ANIM_HILIT_SIDE)); - dc->SetBrush(config.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 @@ -103,18 +113,27 @@ AnimationView::OnDraw(wxDC *dc, const CalChartConfiguration& config) case ANIMDIR_SW: case ANIMDIR_W: case ANIMDIR_NW: - dc->SetPen(config.GetCalChartPen(COLOR_POINT_ANIM_BACK)); - dc->SetBrush(config.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(config.GetCalChartPen(COLOR_POINT_ANIM_FRONT)); - dc->SetBrush(config.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(config.GetCalChartPen(COLOR_POINT_ANIM_SIDE)); - dc->SetBrush(config.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/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp index 32218351..de6dffba 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -21,8 +21,11 @@ */ #include "cc_preferences_ui.h" +#include "cc_drawcommand.h" #include "confgr.h" #include "modes.h" +#include "draw.h" +#include "cc_sheet.h" #include #include #include @@ -109,7 +112,8 @@ class GeneralSetup : public PreferencePage 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 ) : + mConfig(GetConfig()) { Init(); Create(parent, id, caption, pos, size, style); @@ -139,6 +143,8 @@ class GeneralSetup : public PreferencePage wxBrush mCalChartBrushes[COLOR_NUM]; wxString mAutoSave_Interval; + CalChartConfiguration mConfig; + }; enum @@ -158,6 +164,30 @@ EVT_COMBOBOX(NEW_COLOR_CHOICE,GeneralSetup::OnCmdChooseNewColor) END_EVENT_TABLE() IMPLEMENT_CLASS( GeneralSetup, PreferencePage ) +#include "basic_ui.h" +#include "calchartdoc.h" + +class PrefCanvas : public ClickDragCtrlScrollCanvas +{ + DECLARE_EVENT_TABLE() + using super = ClickDragCtrlScrollCanvas; +public: + PrefCanvas(wxWindow *parent, CalChartConfiguration& config); + + void OnPaint(wxPaintEvent& event); + void PaintBackground(wxDC& dc); + void OnEraseBackground(wxEraseEvent& event); + std::unique_ptr mShow; + std::unique_ptr mMode; + CC_coord mOffset; + CalChartConfiguration& mConfig; + +}; + +BEGIN_EVENT_TABLE(PrefCanvas, ClickDragCtrlScrollCanvas) +EVT_PAINT(PrefCanvas::OnPaint) +EVT_ERASE_BACKGROUND(PrefCanvas::OnEraseBackground) +END_EVENT_TABLE() void GeneralSetup::CreateControls() { @@ -176,7 +206,7 @@ void GeneralSetup::CreateControls() topsizer->Add(boxsizer); wxBoxSizer *horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); - nameBox = new wxBitmapComboBox(this, NEW_COLOR_CHOICE, GetConfig().GetColorNames().at(0), wxDefaultPosition, wxDefaultSize, COLOR_NUM, GetConfig().GetColorNames().data(), 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)) @@ -184,7 +214,7 @@ void GeneralSetup::CreateControls() wxBitmap temp_bitmap(16, 16); wxMemoryDC temp_dc; temp_dc.SelectObject(temp_bitmap); - temp_dc.SetBackground(GetConfig().GetCalChartBrush(i)); + temp_dc.SetBackground(mConfig.Get_CalChartBrushAndPen(i).first); temp_dc.Clear(); nameBox->SetItemBitmap(i, temp_bitmap); } @@ -202,19 +232,107 @@ void GeneralSetup::CreateControls() boxsizer->Add(horizontalsizer, sBasicSizerFlags ); + auto prefCanvas = new PrefCanvas(this, mConfig); + // 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(); } +PrefCanvas::PrefCanvas(wxWindow *parent, CalChartConfiguration& config) : +super(parent), +mMode(new ShowModeStandard(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) )), + +mOffset(mMode->FieldOffset()), +mConfig(config) +{ + mShow = CC_show::Create_CC_show(); + mShow->SetupNewShow(); + mShow->SetNumPoints(4, 4, mOffset); + 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(mOffset + CC_coord(Int2Coord(i*4), Int2Coord(2)), i); + sheet->SetPosition(mOffset + CC_coord(Int2Coord(i*4), Int2Coord(6)), i, 1); + } +} + + +// Define the repainting behaviour +void +PrefCanvas::OnPaint(wxPaintEvent& event) +{ + wxBufferedPaintDC dc(this); + PrepareDC(dc); + + // draw the background + PaintBackground(dc); + + dc.SetPen(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); + dc.SetTextForeground(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD_TEXT).second.GetColour()); + mMode->Draw(dc, mConfig); + CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); + + SelectionList list; + list.insert(2); + list.insert(3); + + 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); + + auto offset = mMode->FieldOffset(); + auto point_start = mMode->Offset() + offset + CC_coord(Int2Coord(4), Int2Coord(2)); + auto point_end = point_start + CC_coord(Int2Coord(0), Int2Coord(2)); + std::vector cmds; + cmds.push_back(CC_DrawCommand(point_start, point_end)); + point_start = point_end; + point_end += CC_coord(Int2Coord(10), Int2Coord(0)); + cmds.push_back(CC_DrawCommand(point_start, point_end)); + +// struct CC_DrawCommand + + DrawPath(dc, mConfig, cmds, point_end); + +} + +void +PrefCanvas::PaintBackground(wxDC& dc) +{ + // draw the background + dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackground(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD).first); + dc.Clear(); +} + +// We have a empty erase background to improve redraw performance. +void +PrefCanvas::OnEraseBackground(wxEraseEvent& event) +{ +} + void GeneralSetup::Init() { // first read out the defaults: for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i)+1)) { - mCalChartPens[i] = GetConfig().GetCalChartPen(i); - mCalChartBrushes[i] = GetConfig().GetCalChartBrush(i); + auto brushAndPen = mConfig.Get_CalChartBrushAndPen(i); + mCalChartPens[i] = brushAndPen.second; + mCalChartBrushes[i] = brushAndPen.first; } - mAutoSave_Interval.Printf(wxT("%ld"), GetConfig().Get_AutosaveInterval()); + mAutoSave_Interval.Printf(wxT("%ld"), mConfig.Get_AutosaveInterval()); } bool GeneralSetup::TransferDataToWindow() @@ -233,11 +351,11 @@ bool GeneralSetup::TransferDataFromWindow() // write out the values defaults: for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i)+1)) { - GetConfig().SetCalChartBrushAndPen(i, mCalChartBrushes[i], mCalChartPens[i]); + mConfig.Set_CalChartBrushAndPen(i, mCalChartBrushes[i], mCalChartPens[i]); } long val; mAutoSave_Interval.ToLong(&val); - GetConfig().Set_AutosaveInterval(val); + mConfig.Set_AutosaveInterval(val); return true; } @@ -245,10 +363,10 @@ bool GeneralSetup::ClearValuesToDefault() { for (int i = 0; i < COLOR_NUM; ++i) { - SetColor(i, GetConfig().GetDefaultPenWidth()[i], GetConfig().GetDefaultColors()[i]); - GetConfig().ClearConfigColor(i); + SetColor(i, mConfig.GetDefaultPenWidth()[i], mConfig.GetDefaultColors()[i]); + mConfig.Clear_ConfigColor(i); } - GetConfig().Clear_AutosaveInterval(); + mConfig.Clear_AutosaveInterval(); Init(); TransferDataToWindow(); return true; @@ -259,6 +377,8 @@ void GeneralSetup::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); @@ -268,6 +388,7 @@ void GeneralSetup::SetColor(int selection, int width, const wxColour& color) temp_dc.Clear(); nameBox->SetItemBitmap(selection, test_bitmap); } + Refresh(); } void GeneralSetup::OnCmdSelectColors(wxCommandEvent&) @@ -294,8 +415,8 @@ void GeneralSetup::OnCmdSelectWidth(wxSpinEvent& e) void GeneralSetup::OnCmdResetColors(wxCommandEvent&) { int selection = nameBox->GetSelection(); - SetColor(selection, GetConfig().GetDefaultPenWidth()[selection], GetConfig().GetDefaultColors()[selection]); - GetConfig().ClearConfigColor(selection); + SetColor(selection, mConfig.GetDefaultPenWidth()[selection], mConfig.GetDefaultColors()[selection]); + mConfig.Clear_ConfigColor(selection); } void GeneralSetup::OnCmdChooseNewColor(wxCommandEvent&) diff --git a/src/confgr.cpp b/src/confgr.cpp index 97cf43d2..262d2523 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -36,6 +36,8 @@ #include "modes.h" #include "cc_omniview_constants.h" +using ColorWidth_t = std::pair; + const std::tuple ColorInfo[COLOR_NUM] = { { wxT("FIELD"), wxT("FOREST GREEN"), 1 }, @@ -56,8 +58,8 @@ const std::tuple ColorInfo[COLOR_NUM] = { wxT("HILIT ANIM BACK"), wxT("RED"), 1 }, { wxT("HILIT ANIM SIDE"), wxT("RED"), 1 }, { wxT("ANIM COLLISION"), wxT("PURPLE"), 1 }, - { wxT("CONTINUITY PATHS"), wxT("RED"), 1 }, { wxT("SHAPES"), wxT("ORANGE"), 2 }, + { wxT("CONTINUITY PATHS"), wxT("RED"), 1 }, }; CalChartConfiguration& GetConfig() @@ -66,9 +68,8 @@ CalChartConfiguration& GetConfig() return sconfig; } -// constants for behavior: -// Autosave +// functions for dealing with the wx config directly template T GetConfigValue(const wxString& key, const T& def) { @@ -79,6 +80,10 @@ T GetConfigValue(const wxString& key, const T& def) return value; } +// clear out the config if it matches +template +void ClearConfigValue(const wxString& key); + // default value need to check if we need to set a value template void SetConfigValue(const wxString& key, const T& value, const T& def) @@ -86,6 +91,13 @@ void SetConfigValue(const wxString& key, const T& value, const T& def) // 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) + { + ClearConfigValue(key); + return; + } + wxConfigBase *config = wxConfigBase::Get(); config->SetPath(wxT("/CalChart")); config->Write(key, value); @@ -101,6 +113,66 @@ void ClearConfigValue(const wxString& key) config->Flush(); } +// Specialize on Color +template <> +ColorWidth_t GetConfigValue(const wxString& key, const ColorWidth_t& def) +{ + wxConfigBase *config = wxConfigBase::Get(); + config->SetPath(wxT("/COLORS")); + wxString rkey = key + wxT("_Red"); + wxString gkey = key + wxT("_Green"); + wxString bkey = key + wxT("_Blue"); + long r = std::get<0>(def).Red(); + long g = std::get<0>(def).Green(); + long b = std::get<0>(def).Blue(); + config->Read(rkey, &r); + config->Read(gkey, &g); + config->Read(bkey, &b); + + // store widths in a subgroup + config->SetPath(wxT("WIDTH")); + long w = std::get<1>(def); + config->Read(key, &w); + return { wxColour( r, g, b ), w }; +} + +// Specialize on Color +template <> +void SetConfigValue(const wxString& key, const ColorWidth_t& value, const ColorWidth_t& def) +{ + // 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) +// { +// ClearConfigValue(rkey); +// ClearConfigValue(gkey); +// ClearConfigValue(bkey); +// return; +// } + + wxConfigBase *config = wxConfigBase::Get(); + config->SetPath(wxT("/COLORS")); + long r = std::get<0>(value).Red(); + long g = std::get<0>(value).Green(); + long b = std::get<0>(value).Blue(); + config->Write(rkey, r); + config->Write(gkey, g); + config->Write(bkey, b); + config->SetPath(wxT("WIDTH")); + long w = std::get<1>(def); + config->Write(key, w); + config->Flush(); +} + + + // printing controls wxString yard_text[MAX_YARD_LINES] = { @@ -135,9 +207,21 @@ static bool spr_line_yard_text_valid = false; #define IMPLEMENT_CONFIGURATION_FUNCTIONS( KeyName, Type, TheValue ) \ static const wxString k ## KeyName ## Key = wxT( #KeyName ); \ static const Type k ## KeyName ## Value = (TheValue); \ -Type CalChartConfiguration::Get_ ## KeyName () const { return GetConfigValue( k ## KeyName ## Key, k ## KeyName ## Value); } \ -void CalChartConfiguration::Set_ ## KeyName (const Type& v) { return SetConfigValue( k ## KeyName ## Key, v, k ## KeyName ## Value); } \ -void CalChartConfiguration::Clear_ ## 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); @@ -401,79 +485,6 @@ CalChartConfiguration::ClearConfigurationSpringShowMode(size_t which) config->DeleteEntry(kSpringShowModeStrings[which]); } -///// Color Configuration ///// -// Color is more complicated, we use functions for setting that -std::array sColors[COLOR_NUM]; -long sWidths[COLOR_NUM]; -std::bitset s_color_valid; -std::bitset s_width_valid; - -std::array ReadConfigColor(CalChartColors i) -{ - if (s_color_valid.test(i)) - { - return sColors[i]; - } - wxConfigBase *config = wxConfigBase::Get(); - - // read out the color configuration: - config->SetPath(wxT("/COLORS")); - wxString rbuf = std::get<0>(ColorInfo[i]) + wxT("_Red"); - wxString gbuf = std::get<0>(ColorInfo[i]) + wxT("_Green"); - wxString bbuf = std::get<0>(ColorInfo[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); - sColors[i] = { {r, g, b} }; - } - else - { - auto color = wxColour(std::get<1>(ColorInfo[i])); - sColors[i] = { {color.Red(), color.Green(), color.Blue()} }; - } - s_color_valid.set(i); - return sColors[i]; -} - -long ReadConfigColorWidth(CalChartColors i) -{ - if (s_width_valid.test(i)) - { - return sWidths[i]; - } - wxConfigBase *config = wxConfigBase::Get(); - - // read out the color configuration: - config->SetPath(wxT("/COLORS")); - // store widths in a subgroup - config->SetPath(wxT("WIDTH")); - sWidths[i] = std::get<2>(ColorInfo[i]); - config->Read(std::get<0>(ColorInfo[i]), &sWidths[i]); - s_width_valid.set(i); - return sWidths[i]; -} - -void -CalChartConfiguration::ClearConfigColor(size_t selection) -{ - wxConfigBase *config = wxConfigBase::Get(); - - config->SetPath(wxT("/COLORS")); - wxString rbuf = std::get<0>(ColorInfo[selection]) + wxT("_Red"); - config->DeleteEntry(rbuf); - wxString gbuf = std::get<0>(ColorInfo[selection]) + wxT("_Green"); - config->DeleteEntry(gbuf); - wxString bbuf = std::get<0>(ColorInfo[selection]) + wxT("_Blue"); - config->DeleteEntry(bbuf); - config->SetPath(wxT("WIDTH")); - config->DeleteEntry(std::get<0>(ColorInfo[selection])); - config->Flush(); - s_color_valid.reset(selection); - s_width_valid.reset(selection); -} - void ReadConfigYardlines() { if (yard_text_valid) @@ -605,42 +616,36 @@ CalChartConfiguration::ClearConfigSpringShowYardline() spr_line_yard_text_valid = false; } -wxBrush -CalChartConfiguration::GetCalChartBrush(CalChartColors c) const -{ - auto color_values = ReadConfigColor(c); - auto color = wxColour(color_values[0], color_values[1], color_values[2]); - return *wxTheBrushList->FindOrCreateBrush(color, wxSOLID); -} +///// Color Configuration ///// -wxPen -CalChartConfiguration::GetCalChartPen(CalChartColors c) const +std::pair +CalChartConfiguration::Get_CalChartBrushAndPen(CalChartColors c) const { - auto color_values = ReadConfigColor(c); - auto color = wxColour(color_values[0], color_values[1], color_values[2]); - auto width = ReadConfigColorWidth(c); - return *wxThePenList->FindOrCreatePen(color, width, wxSOLID); + if (!mColorsAndWidth.count(c)) + { + 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 -CalChartConfiguration::SetCalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen) +CalChartConfiguration::Set_CalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen) { if (c >= COLOR_NUM) throw std::runtime_error("Error, exceeding COLOR_NUM size"); - wxConfigBase *config = wxConfigBase::Get(); + ColorWidth_t v{ brush.GetColour(), pen.GetWidth() }; - // read out the color configuration: - config->SetPath(wxT("/COLORS")); - wxString rbuf = std::get<0>(ColorInfo[c]) + wxT("_Red"); - config->Write(rbuf, static_cast(brush.GetColour().Red())); - wxString gbuf = std::get<0>(ColorInfo[c]) + wxT("_Green"); - config->Write(gbuf, static_cast(brush.GetColour().Green())); - wxString bbuf = std::get<0>(ColorInfo[c]) + wxT("_Blue"); - config->Write(bbuf, static_cast(brush.GetColour().Blue())); - config->SetPath(wxT("WIDTH")); - config->Write(std::get<0>(ColorInfo[c]), pen.GetWidth()); - config->Flush(); - s_color_valid.reset(c); - s_width_valid.reset(c); + 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 +CalChartConfiguration::Clear_ConfigColor(size_t selection) +{ + 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); +} + + diff --git a/src/confgr.h b/src/confgr.h index 93a6ebb6..3d922bf5 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -26,11 +26,14 @@ #include #include #include +#include +#include // forward declare class wxPen; class wxBrush; class wxPathList; +class wxColour; class ShowMode; #define MAX_SPR_LINES 5 @@ -88,12 +91,23 @@ extern const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM]; class CalChartConfiguration { public: + // on dtor, if triggered to flush, flush-out + // explicit flush +//private: + void FlushValuesToConfig(); +private: + void AddToWriteQueue(); + std::map> mWriteQueue; +// ~CalChartConfiguration(); // macro for declaring configuration Get_, Set_, and Clear_ #define DECLARE_CONFIGURATION_FUNCTIONS( Key, Type ) \ +public: \ Type Get_ ## Key () const ; \ void Set_ ## Key (const Type& v) ; \ - void Clear_ ## Key () ; + void Clear_ ## Key () ; \ +private: \ + mutable std::pair m ## Key = { false, Type() }; DECLARE_CONFIGURATION_FUNCTIONS( AutosaveInterval, long); @@ -164,10 +178,17 @@ class CalChartConfiguration DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSplitScreen, bool); DECLARE_CONFIGURATION_FUNCTIONS( AnimationFrameSplitVertical, bool); - wxBrush GetCalChartBrush(CalChartColors c) const; - wxPen GetCalChartPen(CalChartColors c) const; - void SetCalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen); - void ClearConfigColor(size_t selection); +public: + std::vector GetColorNames() const; + std::vector GetDefaultColors() const; + std::vector GetDefaultPenWidth() const; + + 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); wxString Get_yard_text(size_t which) const; void Set_yard_text(size_t which, const wxString&); @@ -178,10 +199,6 @@ class CalChartConfiguration void ClearConfigShowYardline(); void ClearConfigSpringShowYardline(); - std::vector GetColorNames() const; - std::vector GetDefaultColors() const; - std::vector GetDefaultPenWidth() const; - static const size_t kShowModeValues = 10; std::vector GetConfigurationShowMode(size_t which); void SetConfigurationShowMode(size_t which, const std::vector& values); diff --git a/src/cont_ui.cpp b/src/cont_ui.cpp index 37b92815..b6d63e68 100644 --- a/src/cont_ui.cpp +++ b/src/cont_ui.cpp @@ -167,6 +167,13 @@ void ContinuityEditor::CreateControls() mUserInput = new FancyTextWin(this, ContinuityEditor_KeyPress, wxEmptyString, wxDefaultPosition, wxSize(50, 300)); + + wxArrayString autocompletes; + for (auto& i : { wxT("Hello"), wxT("Bye"), wxT("Cat"), wxT("Hela") }) + { + autocompletes.Add(i); + } + mUserInput->AutoComplete(autocompletes); topsizer->Add(mUserInput, 0, wxGROW|wxALL, 5 ); 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 7952374d..875ba3d0 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 01b60ed8..38e8052e 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -129,37 +129,40 @@ static const double kLowerNorthArrow[2][3] = { { 1.0 - 52/kSizeX, (570)/kSizeY, static const double kContinuityStart[2] = { 606/kSizeY, 556/kSizeYLandscape }; -void Draw(wxDC& dc, const CalChartConfiguration& config, 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) { wxFont *pointLabelFont = wxTheFontList->FindOrCreateFont((int)Float2Coord(config.Get_DotRatio() * config.Get_NumRatio()), wxSWISS, wxNORMAL, wxNORMAL); dc.SetFont(*pointLabelFont); - dc.SetTextForeground(config.GetCalChartPen(COLOR_POINT_TEXT).GetColour()); - 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++) { wxBrush fillBrush; - if (show.IsSelected(i) && primary) + if (selection_list.count(i) && primary) { - dc.SetPen(config.GetCalChartPen(COLOR_POINT_HILIT)); - fillBrush = config.GetCalChartBrush(COLOR_POINT_HILIT); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_HILIT); + fillBrush = brushAndPen.first; + dc.SetPen(brushAndPen.second); } - else if (show.IsSelected(i) && !primary) + else if (selection_list.count(i) && !primary) { - dc.SetPen(config.GetCalChartPen(COLOR_REF_POINT_HILIT)); - fillBrush = config.GetCalChartBrush(COLOR_REF_POINT_HILIT); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_REF_POINT_HILIT); + fillBrush = brushAndPen.first; + dc.SetPen(brushAndPen.second); } - else if (!show.IsSelected(i) && primary) + else if (!selection_list.count(i) && primary) { - dc.SetPen(config.GetCalChartPen(COLOR_POINT)); - fillBrush = config.GetCalChartBrush(COLOR_POINT); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT); + fillBrush = brushAndPen.first; + dc.SetPen(brushAndPen.second); } else { - dc.SetPen(config.GetCalChartPen(COLOR_REF_POINT)); - fillBrush = config.GetCalChartBrush(COLOR_REF_POINT); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_REF_POINT); + fillBrush = brushAndPen.first; + dc.SetPen(brushAndPen.second); } - DrawPoint(sheet.GetPoint(i), dc, config, ref, origin, fillBrush, show.GetPointLabel(i)); + DrawPoint(sheet.GetPoint(i), dc, config, ref, origin, fillBrush, labels.at(i)); } dc.SetFont(wxNullFont); } @@ -612,9 +615,10 @@ void DrawCC_DrawCommandList(wxDC& dc, const std::vector& draw_co void DrawPath(wxDC& dc, const CalChartConfiguration& config, const std::vector& draw_commands, const CC_coord& end) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(config.GetCalChartPen(COLOR_PATHS)); + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_PATHS); + dc.SetPen(brushAndPen.second); DrawCC_DrawCommandList(dc, draw_commands); - dc.SetBrush(config.GetCalChartBrush(COLOR_PATHS)); + 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 126ef316..19db4be9 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 class wxBrush; class wxString; @@ -39,7 +41,7 @@ class CalChartConfiguration; typedef std::vector CC_textline_list; // draw the continuity starting at a specific offset -void Draw(wxDC& dc, const CalChartConfiguration& config, 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); void DrawCont(wxDC& dc, const CC_textline_list& print_continuity, const wxRect& bounding, bool landscape); void DrawForPrinting(wxDC *dc, const CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool landscape); diff --git a/src/field_canvas.cpp b/src/field_canvas.cpp index 4c36d1b5..bf24c4df 100644 --- a/src/field_canvas.cpp +++ b/src/field_canvas.cpp @@ -84,7 +84,7 @@ FieldCanvas::OnPaint(wxPaintEvent& event) if (curr_shape) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetConfig().GetCalChartPen(COLOR_SHAPES)); + dc.SetPen(GetConfig().Get_CalChartBrushAndPen(COLOR_SHAPES).second); CC_coord origin = mView->GetShowFieldOffset(); for (auto i=shape_list.begin(); i != shape_list.end(); @@ -100,7 +100,7 @@ FieldCanvas::PaintBackground(wxDC& dc) { // draw the background dc.SetBackgroundMode(wxTRANSPARENT); - dc.SetBackground(GetConfig().GetCalChartBrush(COLOR_FIELD)); + dc.SetBackground(GetConfig().Get_CalChartBrushAndPen(COLOR_FIELD).first); dc.Clear(); } diff --git a/src/field_view.cpp b/src/field_view.cpp index e379444f..03e32c8b 100644 --- a/src/field_view.cpp +++ b/src/field_view.cpp @@ -79,21 +79,22 @@ FieldView::OnDraw(wxDC *dc) if (mShow) { // draw the field - dc->SetPen(config.GetCalChartPen(COLOR_FIELD_DETAIL)); - dc->SetTextForeground(config.GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + dc->SetPen(config.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); + dc->SetTextForeground(config.Get_CalChartBrushAndPen(COLOR_FIELD_TEXT).second.GetColour()); mShow->GetMode().Draw(*dc, config); + CC_coord origin = mShow->GetMode().Offset(); CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); if (sheet != mShow->GetSheetEnd()) { if (mCurrentReferencePoint > 0) { - Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), 0, false); - Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + DrawPoints(*dc, config, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), 0, false); + DrawPoints(*dc, config, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } else { - Draw(*dc, config, *mShow, *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + DrawPoints(*dc, config, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } DrawPaths(*dc, *sheet); } diff --git a/src/modes.cpp b/src/modes.cpp index 4c131cc5..0378a9ac 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -94,8 +94,8 @@ ShowMode::GetOmniLinesImage(const CalChartConfiguration& config) const dc.SelectObject(bmp); dc.SetBackground(*wxTRANSPARENT_BRUSH); dc.Clear(); - dc.SetPen(config.GetCalChartPen(COLOR_FIELD_DETAIL)); - dc.SetTextForeground(config.GetCalChartPen(COLOR_FIELD_TEXT).GetColour()); + dc.SetPen(config.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); + dc.SetTextForeground(config.Get_CalChartBrushAndPen(COLOR_FIELD_TEXT).second.GetColour()); DrawOmni(dc, config); dc.SelectObject(wxNullBitmap); return bmp.ConvertToImage(); From 667be098023e5a438c94d00b86f1e878077bc822 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sun, 24 Aug 2014 13:59:09 -0700 Subject: [PATCH 08/11] steps closer to a better config system. --- src/animation_canvas.cpp | 7 +- src/animation_view.cpp | 2 +- src/calchartapp.cpp | 4 +- src/calchartapp.h | 2 - src/calchartdoc.cpp | 2 +- src/cc_preferences_ui.cpp | 600 ++++++++++++++++++++++++-------------- src/cc_preferences_ui.h | 2 + src/confgr.cpp | 46 +-- src/confgr.h | 35 ++- src/draw.cpp | 6 +- src/field_canvas.cpp | 18 +- src/field_canvas.h | 4 +- src/field_view.cpp | 22 +- src/field_view.h | 4 +- src/modes.cpp | 46 +-- src/modes.h | 50 ++-- src/print_ps_dialog.cpp | 6 +- 17 files changed, 537 insertions(+), 319 deletions(-) diff --git a/src/animation_canvas.cpp b/src/animation_canvas.cpp index 301509c4..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(GetConfig().Get_CalChartBrushAndPen(COLOR_FIELD).first); + 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(GetConfig().Get_CalChartBrushAndPen(COLOR_SHAPES).second); + dc.SetPen(config.Get_CalChartBrushAndPen(COLOR_SHAPES).second); dc.DrawRectangle(mMouseXStart, mMouseYStart, mMouseXEnd - mMouseXStart, mMouseYEnd - mMouseYStart); } if (mAnimationView) { - mAnimationView->OnDraw(&dc, GetConfig()); + mAnimationView->OnDraw(&dc, config); } } diff --git a/src/animation_view.cpp b/src/animation_view.cpp index 235a5720..d79c21fe 100644 --- a/src/animation_view.cpp +++ b/src/animation_view.cpp @@ -54,7 +54,7 @@ AnimationView::~AnimationView() void AnimationView::OnDraw(wxDC *dc) { - auto& config = GetConfig(); + auto& config = CalChartConfiguration::GetGlobalConfig(); OnDraw(dc, config); } diff --git a/src/calchartapp.cpp b/src/calchartapp.cpp index dfe73e6b..0ccefc20 100644 --- a/src/calchartapp.cpp +++ b/src/calchartapp.cpp @@ -155,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,7 +174,7 @@ void CalChartApp::ExitAppAsServer() { std::unique_ptr CalChartApp::GetMode(const wxString& which) { - return GetConfig().GetMode(which); + return ShowMode::GetMode(which); } void CalChartApp::ExitAppAsClient() { diff --git a/src/calchartapp.h b/src/calchartapp.h index dc0aab23..d8f2cec5 100644 --- a/src/calchartapp.h +++ b/src/calchartapp.h @@ -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 3ca53b1f..966bc718 100644 --- a/src/calchartdoc.cpp +++ b/src/calchartdoc.cpp @@ -55,7 +55,7 @@ mShow(CC_show::Create_CC_show()), mMode(wxGetApp().GetMode(kShowModeStrings[0])), mTimer(*this) { - mTimer.Start(GetConfig().Get_AutosaveInterval()*1000); + mTimer.Start(CalChartConfiguration::GetGlobalConfig().Get_AutosaveInterval()*1000); } // When a file is opened, we first check to see if there is a temporary diff --git a/src/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp index de6dffba..4e118e26 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -26,6 +26,10 @@ #include "modes.h" #include "draw.h" #include "cc_sheet.h" +#include "basic_ui.h" +#include "calchartdoc.h" +#include "cc_shapes.h" + #include #include #include @@ -33,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 @@ -50,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, @@ -85,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 @@ -107,13 +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 ) : - mConfig(GetConfig()) + PreferencePage(config) { Init(); Create(parent, id, caption, pos, size, style); @@ -129,65 +140,21 @@ 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; - CalChartConfiguration mConfig; - }; 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 ) -#include "basic_ui.h" -#include "calchartdoc.h" - -class PrefCanvas : public ClickDragCtrlScrollCanvas -{ - DECLARE_EVENT_TABLE() - using super = ClickDragCtrlScrollCanvas; -public: - PrefCanvas(wxWindow *parent, CalChartConfiguration& config); - - void OnPaint(wxPaintEvent& event); - void PaintBackground(wxDC& dc); - void OnEraseBackground(wxEraseEvent& event); - std::unique_ptr mShow; - std::unique_ptr mMode; - CC_coord mOffset; - CalChartConfiguration& mConfig; - -}; - -BEGIN_EVENT_TABLE(PrefCanvas, ClickDragCtrlScrollCanvas) -EVT_PAINT(PrefCanvas::OnPaint) -EVT_ERASE_BACKGROUND(PrefCanvas::OnEraseBackground) -END_EVENT_TABLE() void GeneralSetup::CreateControls() { @@ -202,54 +169,83 @@ void GeneralSetup::CreateControls() AddTextboxWithCaption(this, sizer1, AUTOSAVE_INTERVAL, wxT("Autosave Interval")); - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); - topsizer->Add(boxsizer); + TransferDataToWindow(); +} - wxBoxSizer *horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); - 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)) +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)) { - wxBitmap temp_bitmap(16, 16); - wxMemoryDC temp_dc; - temp_dc.SelectObject(temp_bitmap); - temp_dc.SetBackground(mConfig.Get_CalChartBrushAndPen(i).first); - temp_dc.Clear(); - nameBox->SetItemBitmap(i, temp_bitmap); + mConfig.Set_AutosaveInterval(val); } - nameBox->SetSelection(0); + return true; +} - spin = new wxSpinCtrl(this, SPIN_WIDTH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mCalChartPens[nameBox->GetSelection()].GetWidth()); - spin->SetValue(mCalChartPens[nameBox->GetSelection()].GetWidth()); - horizontalsizer->Add(spin, sBasicSizerFlags ); - boxsizer->Add(horizontalsizer, sLeftBasicSizerFlags ); +bool GeneralSetup::ClearValuesToDefault() +{ + mConfig.Clear_AutosaveInterval(); + Init(); + TransferDataToWindow(); + return true; +} - horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); - horizontalsizer->Add(new wxButton(this, BUTTON_SELECT, wxT("&Change Color")), sBasicSizerFlags ); - horizontalsizer->Add(new wxButton(this, BUTTON_RESTORE, wxT("&Reset Color")), sBasicSizerFlags ); +//////// Draw setup //////// +// handling Drawing colors +//////// - boxsizer->Add(horizontalsizer, sBasicSizerFlags ); +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; +}; - auto prefCanvas = new PrefCanvas(this, mConfig); - // 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(); -} -PrefCanvas::PrefCanvas(wxWindow *parent, CalChartConfiguration& config) : -super(parent), -mMode(new ShowModeStandard(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) )), +BEGIN_EVENT_TABLE(PrefCanvas, ClickDragCtrlScrollCanvas) +EVT_PAINT(PrefCanvas::OnPaint) +EVT_ERASE_BACKGROUND(PrefCanvas::OnEraseBackground) +END_EVENT_TABLE() -mOffset(mMode->FieldOffset()), +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, mOffset); + mShow->SetNumPoints(4, 4, field_offset); mShow->SetPointLabel(std::vector{ "unsel", "unsel", @@ -264,9 +260,21 @@ mConfig(config) for (auto i = 0; i < 4; ++i) { - sheet->SetAllPositions(mOffset + CC_coord(Int2Coord(i*4), Int2Coord(2)), i); - sheet->SetPosition(mOffset + CC_coord(Int2Coord(i*4), Int2Coord(6)), i, 1); + 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); } + + 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(10), Int2Coord(0)); + mPath.push_back(CC_DrawCommand(point_start, mPathEnd)); + + auto shape_start = field_offset + CC_coord(Int2Coord(20), Int2Coord(2)); + auto shape_end = shape_start + CC_coord(Int2Coord(8), Int2Coord(4)); + CC_shape_rect rect(shape_start, shape_end); + mShape = rect.GetCC_DrawCommand(offset.x, offset.y); } @@ -278,51 +286,168 @@ PrefCanvas::OnPaint(wxPaintEvent& event) PrepareDC(dc); // draw the background - PaintBackground(dc); + dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackground(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD).first); + dc.Clear(); - dc.SetPen(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); - dc.SetTextForeground(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD_TEXT).second.GetColour()); - mMode->Draw(dc, mConfig); - CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); + // Draw the field + mMode->DrawMode(dc, mConfig, ShowMode::kFieldView); + // Draw the points + CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); SelectionList list; list.insert(2); list.insert(3); - 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); - auto offset = mMode->FieldOffset(); - auto point_start = mMode->Offset() + offset + CC_coord(Int2Coord(4), Int2Coord(2)); - auto point_end = point_start + CC_coord(Int2Coord(0), Int2Coord(2)); - std::vector cmds; - cmds.push_back(CC_DrawCommand(point_start, point_end)); - point_start = point_end; - point_end += CC_coord(Int2Coord(10), Int2Coord(0)); - cmds.push_back(CC_DrawCommand(point_start, point_end)); - -// struct CC_DrawCommand - - DrawPath(dc, mConfig, cmds, point_end); + // 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::PaintBackground(wxDC& dc) +PrefCanvas::OnEraseBackground(wxEraseEvent& event) { - // draw the background - dc.SetBackgroundMode(wxTRANSPARENT); - dc.SetBackground(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD).first); - dc.Clear(); } -// 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, + A_DOTRATIO, + A_NUMRATIO, + A_PLINERATIO, + A_SLINERATIO, + A_CONTRATIO +}; + + +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(A_DOTRATIO,DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(A_NUMRATIO,DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(A_PLINERATIO,DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(A_SLINERATIO,DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(A_CONTRATIO,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, 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)) + { + wxBitmap temp_bitmap(16, 16); + wxMemoryDC temp_dc; + temp_dc.SelectObject(temp_bitmap); + temp_dc.SetBackground(mConfig.Get_CalChartBrushAndPen(i).first); + temp_dc.Clear(); + nameBox->SetItemBitmap(i, temp_bitmap); + } + nameBox->SetSelection(0); + + spin = new wxSpinCtrl(this, SPIN_WIDTH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mCalChartPens[nameBox->GetSelection()].GetWidth()); + spin->SetValue(mCalChartPens[nameBox->GetSelection()].GetWidth()); + horizontalsizer->Add(spin, sBasicSizerFlags ); + boxsizer->Add(horizontalsizer, sLeftBasicSizerFlags ); + + horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); + + horizontalsizer->Add(new wxButton(this, BUTTON_SELECT, wxT("&Change Color")), sBasicSizerFlags ); + horizontalsizer->Add(new wxButton(this, BUTTON_RESTORE, wxT("&Reset Color")), sBasicSizerFlags ); + + 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, A_DOTRATIO, wxT("Dot Ratio:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, A_NUMRATIO, wxT("Num Ratio:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, A_PLINERATIO, wxT("P-Line Ratio:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, A_SLINERATIO, wxT("S-Line Ratio:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, A_CONTRATIO, wxT("Continuity 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)) @@ -331,54 +456,65 @@ void GeneralSetup::Init() mCalChartPens[i] = brushAndPen.second; mCalChartBrushes[i] = brushAndPen.first; } - - mAutoSave_Interval.Printf(wxT("%ld"), mConfig.Get_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(A_DOTRATIO); + buf.Printf(wxT("%.2f"), mPrintValues[0]); + text->SetValue(buf); + text = (wxTextCtrl*) FindWindow(A_NUMRATIO); + buf.Printf(wxT("%.2f"), mPrintValues[1]); + text->SetValue(buf); + text = (wxTextCtrl*) FindWindow(A_PLINERATIO); + buf.Printf(wxT("%.2f"), mPrintValues[2]); + text->SetValue(buf); + text = (wxTextCtrl*) FindWindow(A_SLINERATIO); + buf.Printf(wxT("%.2f"), mPrintValues[3]); + text->SetValue(buf); + text = (wxTextCtrl*) FindWindow(A_CONTRATIO); + buf.Printf(wxT("%.2f"), mPrintValues[4]); + 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)) { mConfig.Set_CalChartBrushAndPen(i, mCalChartBrushes[i], mCalChartPens[i]); } - long val; - mAutoSave_Interval.ToLong(&val); - mConfig.Set_AutosaveInterval(val); return true; } -bool GeneralSetup::ClearValuesToDefault() +bool DrawingSetup::ClearValuesToDefault() { for (int i = 0; i < COLOR_NUM; ++i) { SetColor(i, mConfig.GetDefaultPenWidth()[i], mConfig.GetDefaultColors()[i]); mConfig.Clear_ConfigColor(i); } - mConfig.Clear_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); @@ -391,7 +527,7 @@ void GeneralSetup::SetColor(int selection, int width, const wxColour& color) Refresh(); } -void GeneralSetup::OnCmdSelectColors(wxCommandEvent&) +void DrawingSetup::OnCmdSelectColors(wxCommandEvent&) { int selection = nameBox->GetSelection(); wxColourData data; @@ -406,24 +542,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, 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 - A_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 @@ -435,12 +600,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); @@ -527,21 +693,21 @@ void PSPrintingSetUp::CreateControls() void PSPrintingSetUp::Init() { - mFontNames[0] = GetConfig().Get_HeadFont(); - mFontNames[1] = GetConfig().Get_MainFont(); - mFontNames[2] = GetConfig().Get_NumberFont(); - mFontNames[3] = GetConfig().Get_ContFont(); - mFontNames[4] = GetConfig().Get_BoldFont(); - mFontNames[5] = GetConfig().Get_ItalFont(); - mFontNames[6] = GetConfig().Get_BoldItalFont(); - mPrintValues[0] = GetConfig().Get_HeaderSize(); - mPrintValues[1] = GetConfig().Get_YardsSize(); - mPrintValues[2] = GetConfig().Get_TextSize(); - mPrintValues[3] = GetConfig().Get_DotRatio(); - mPrintValues[4] = GetConfig().Get_NumRatio(); - mPrintValues[5] = GetConfig().Get_PLineRatio(); - mPrintValues[6] = GetConfig().Get_SLineRatio(); - mPrintValues[7] = GetConfig().Get_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[3] = mConfig.Get_DotRatio(); + mPrintValues[4] = mConfig.Get_NumRatio(); + mPrintValues[5] = mConfig.Get_PLineRatio(); + mPrintValues[6] = mConfig.Get_SLineRatio(); + mPrintValues[7] = mConfig.Get_ContRatio(); } bool PSPrintingSetUp::TransferDataToWindow() @@ -623,41 +789,41 @@ bool PSPrintingSetUp::TransferDataFromWindow() text->GetValue().ToDouble(&mPrintValues[7]); // write out the values defaults: - GetConfig().Set_HeadFont(mFontNames[0]); - GetConfig().Set_MainFont(mFontNames[1]); - GetConfig().Set_NumberFont(mFontNames[2]); - GetConfig().Set_ContFont(mFontNames[3]); - GetConfig().Set_BoldFont(mFontNames[4]); - GetConfig().Set_ItalFont(mFontNames[5]); - GetConfig().Set_BoldItalFont(mFontNames[6]); - GetConfig().Set_HeaderSize(mPrintValues[0]); - GetConfig().Set_YardsSize(mPrintValues[1]); - GetConfig().Set_TextSize(mPrintValues[2]); - GetConfig().Set_DotRatio(mPrintValues[3]); - GetConfig().Set_NumRatio(mPrintValues[4]); - GetConfig().Set_PLineRatio(mPrintValues[5]); - GetConfig().Set_SLineRatio(mPrintValues[6]); - GetConfig().Set_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_DotRatio(mPrintValues[3]); + mConfig.Set_NumRatio(mPrintValues[4]); + mConfig.Set_PLineRatio(mPrintValues[5]); + mConfig.Set_SLineRatio(mPrintValues[6]); + mConfig.Set_ContRatio(mPrintValues[7]); return true; } bool PSPrintingSetUp::ClearValuesToDefault() { - GetConfig().Clear_HeadFont(); - GetConfig().Clear_MainFont(); - GetConfig().Clear_NumberFont(); - GetConfig().Clear_ContFont(); - GetConfig().Clear_BoldFont(); - GetConfig().Clear_ItalFont(); - GetConfig().Clear_BoldItalFont(); - GetConfig().Clear_HeaderSize(); - GetConfig().Clear_YardsSize(); - GetConfig().Clear_TextSize(); - GetConfig().Clear_DotRatio(); - GetConfig().Clear_NumRatio(); - GetConfig().Clear_PLineRatio(); - GetConfig().Clear_SLineRatio(); - GetConfig().Clear_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_DotRatio(); + mConfig.Clear_NumRatio(); + mConfig.Clear_PLineRatio(); + mConfig.Clear_SLineRatio(); + mConfig.Clear_ContRatio(); Init(); return TransferDataToWindow(); } @@ -673,12 +839,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); @@ -759,7 +926,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, GetConfig().Get_yard_text_index().size(), GetConfig().Get_yard_text_index().data()); + 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 ); @@ -773,11 +940,11 @@ void ShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - mShowModeValues[i] = GetConfig().GetConfigurationShowMode(i); + mShowModeValues[i] = mConfig.GetConfigurationShowMode(i); } for (size_t i = 0; i < MAX_YARD_LINES; ++i) { - mYardText[i] = GetConfig().Get_yard_text(i); + mYardText[i] = mConfig.Get_yard_text(i); } } @@ -811,7 +978,7 @@ bool ShowModeSetup::TransferDataFromWindow() // write out the values defaults: for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - GetConfig().SetConfigurationShowMode(i, mShowModeValues[i]); + mConfig.SetConfigurationShowMode(i, mShowModeValues[i]); } // grab whatever's in the box @@ -819,7 +986,7 @@ bool ShowModeSetup::TransferDataFromWindow() mYardText[mWhichYardLine] = text->GetValue(); for (size_t i = 0; i < MAX_YARD_LINES; ++i) { - GetConfig().Set_yard_text(i, mYardText[i]); + mConfig.Set_yard_text(i, mYardText[i]); } return true; @@ -829,9 +996,9 @@ bool ShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - GetConfig().ClearConfigurationShowMode(i); + mConfig.ClearConfigurationShowMode(i); } - GetConfig().ClearConfigShowYardline(); + mConfig.ClearConfigShowYardline(); Init(); return TransferDataToWindow(); } @@ -866,12 +1033,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); @@ -989,7 +1157,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, GetConfig().Get_spr_line_text_index().size(), GetConfig().Get_spr_line_text_index().data()); + 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 ); @@ -1003,11 +1171,11 @@ void SpringShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - mSpringShowModeValues[i] = GetConfig().GetConfigurationSpringShowMode(i); + mSpringShowModeValues[i] = mConfig.GetConfigurationSpringShowMode(i); } for (size_t i = 0; i < MAX_SPR_LINES; ++i) { - mYardText[i] = GetConfig().Get_spr_line_text(i); + mYardText[i] = mConfig.Get_spr_line_text(i); } } @@ -1028,7 +1196,7 @@ bool SpringShowModeSetup::TransferDataToWindow() } wxTextCtrl* text = (wxTextCtrl*) FindWindow(SPRING_SHOW_LINE_VALUE); - text->SetValue(GetConfig().Get_spr_line_text(mWhichYardLine)); + text->SetValue(mConfig.Get_spr_line_text(mWhichYardLine)); return true; } @@ -1055,14 +1223,14 @@ bool SpringShowModeSetup::TransferDataFromWindow() // write out the values defaults: for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - GetConfig().SetConfigurationSpringShowMode(modes->GetSelection(), mSpringShowModeValues[mWhichMode]); + mConfig.SetConfigurationSpringShowMode(modes->GetSelection(), mSpringShowModeValues[mWhichMode]); } wxTextCtrl* text = (wxTextCtrl*) FindWindow(SPRING_SHOW_LINE_VALUE); mYardText[mWhichYardLine] = text->GetValue(); for (size_t i = 0; i < MAX_SPR_LINES; ++i) { - GetConfig().Set_spr_line_text(i, mYardText[i]); + mConfig.Set_spr_line_text(i, mYardText[i]); } return true; @@ -1072,9 +1240,9 @@ bool SpringShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - GetConfig().ClearConfigurationSpringShowMode(i); + mConfig.ClearConfigurationSpringShowMode(i); } - GetConfig().ClearConfigSpringShowYardline(); + mConfig.ClearConfigSpringShowYardline(); Init(); return TransferDataToWindow(); } @@ -1122,7 +1290,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(); @@ -1166,13 +1336,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 @@ -1199,6 +1371,7 @@ bool CalChartPreferences::TransferDataFromWindow() PreferencePage* page = static_cast(mNotebook->GetPage(i)); page->TransferDataFromWindow(); } + CalChartConfiguration::AssignConfig(mConfig); return true; } @@ -1211,4 +1384,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 dc3cc0c9..543d3762 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -67,12 +67,26 @@ const std::tuple ColorInfo[COLOR_NUM] = { wxT("CONTINUITY PATHS"), wxT("RED"), 1 }, }; -CalChartConfiguration& GetConfig() +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(); +} + // functions for dealing with the wx config directly @@ -350,7 +364,7 @@ const std::vector kSpringShowModeDefaultValues[SPRINGSHOWMODE_NUM] = }; std::vector -CalChartConfiguration::GetConfigurationShowMode(size_t which) +CalChartConfiguration::GetConfigurationShowMode(size_t which) const { std::vector values = kShowModeDefaultValues[which]; @@ -373,24 +387,8 @@ CalChartConfiguration::GetConfigurationShowMode(size_t which) return values; } -std::unique_ptr -CalChartConfiguration::GetMode(const wxString& which) -{ - auto iter = std::find(std::begin(kShowModeStrings), std::end(kShowModeStrings), which); - if (iter != std::end(kShowModeStrings)) - { - return CreateShowMode(which, GetConfig().GetConfigurationShowMode(std::distance(std::begin(kShowModeStrings), iter))); - } - iter = std::find(std::begin(kSpringShowModeStrings), std::end(kSpringShowModeStrings), which); - if (iter != std::end(kSpringShowModeStrings)) - { - return CreateSpringShowMode(which, GetConfig().GetConfigurationSpringShowMode(std::distance(std::begin(kSpringShowModeStrings), iter))); - } - return {}; -} - std::vector -CalChartConfiguration::GetConfigurationSpringShowMode(size_t which) +CalChartConfiguration::GetConfigurationSpringShowMode(size_t which) const { std::vector values = kSpringShowModeDefaultValues[which]; @@ -654,4 +652,14 @@ CalChartConfiguration::Clear_ConfigColor(size_t selection) SetConfigValue(std::get<0>(ColorInfo[selection]), default_value, default_value); } +// function technically const because it is changing a mutable value +void +CalChartConfiguration::FlushWriteQueue() const +{ + for (auto& i : mWriteQueue) + { + i.second(); + } + mWriteQueue.clear(); +} diff --git a/src/confgr.h b/src/confgr.h index a3d77b17..27fab96d 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -89,21 +89,28 @@ enum CalChartSpringShowModes extern const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM]; -// so: -// we take a snapshot of the config and give to the system to use. They can modify. -// on the d-tor, save out the values that it may have changed; unless it was told to be -// discarded. +// 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: - // on dtor, if triggered to flush, flush-out + static CalChartConfiguration& GetGlobalConfig(); + static void AssignConfig(const CalChartConfiguration& config); + // explicit flush -//private: - void FlushValuesToConfig(); + void FlushWriteQueue() const; + private: - void AddToWriteQueue(); - std::map> mWriteQueue; -// ~CalChartConfiguration(); + mutable std::map> mWriteQueue; // macro for declaring configuration Get_, Set_, and Clear_ #define DECLARE_CONFIGURATION_FUNCTIONS( Key, Type ) \ @@ -205,19 +212,15 @@ private: \ void ClearConfigSpringShowYardline(); static const size_t kShowModeValues = 10; - std::vector GetConfigurationShowMode(size_t which); + std::vector GetConfigurationShowMode(size_t which) const; void SetConfigurationShowMode(size_t which, const std::vector& values); void ClearConfigurationShowMode(size_t which); static const size_t kSpringShowModeValues = 21; - std::vector GetConfigurationSpringShowMode(size_t which); + std::vector GetConfigurationSpringShowMode(size_t which) const; void SetConfigurationSpringShowMode(size_t which, const std::vector& values); void ClearConfigurationSpringShowMode(size_t which); - - std::unique_ptr GetMode(const wxString& which); }; -CalChartConfiguration& GetConfig(); - #endif diff --git a/src/draw.cpp b/src/draw.cpp index 4d46ffb9..a116eca0 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -365,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; @@ -380,7 +380,7 @@ 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 CalChartConfiguration& config, const CalChartDoc& show, const CC_sheet& sheet, unsigned ref, bool landscape) @@ -403,7 +403,7 @@ void DrawForPrinting(wxDC *printerdc, const CalChartConfiguration& config, const } // create a field for drawing: - std::auto_ptr mode = CreateFieldForPrinting(landscape); + auto mode = CreateFieldForPrinting(landscape); int pageW, pageH; dc->GetSize(&pageW, &pageH); diff --git a/src/field_canvas.cpp b/src/field_canvas.cpp index 909b0432..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) { @@ -80,12 +88,12 @@ FieldCanvas::OnPaint(wxPaintEvent& event) // draw the view mView->OnDraw(&dc); - mView->DrawOtherPoints(dc, GetConfig(), mMovePoints); + mView->DrawOtherPoints(dc, mMovePoints); if (curr_shape) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.SetPen(GetConfig().Get_CalChartBrushAndPen(COLOR_SHAPES).second); + 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(GetConfig().Get_CalChartBrushAndPen(COLOR_FIELD).first); + 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_view.cpp b/src/field_view.cpp index 607a36c9..4d7dd483 100644 --- a/src/field_view.cpp +++ b/src/field_view.cpp @@ -46,7 +46,7 @@ FieldView::FieldView() : mFrame(NULL), mDrawPaths(false), mCurrentReferencePoint(0), -config(GetConfig()) +mConfig(CalChartConfiguration::GetGlobalConfig()) { } @@ -63,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, config, wxStaticCast(wxGetApp().GetTopWindow(), wxDocParentFrame), wxPoint(50, 50), wxSize(config.Get_FieldFrameWidth(), config.Get_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); @@ -80,13 +80,13 @@ FieldView::OnDraw(wxDC *dc) { // draw the field CC_coord origin = mShow->GetMode().Offset(); - mShow->GetMode().DrawMode(*dc, config, ShowMode::kFieldView); + mShow->GetMode().DrawMode(*dc, mConfig, ShowMode::kFieldView); CC_sheet* ghostSheet = mGhostModule.getGhostSheet(mShow, GetCurrentSheetNum()); if (ghostSheet != nullptr) { - DrawGhostSheet(*dc, config, origin, SelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *ghostSheet, 0); + DrawGhostSheet(*dc, mConfig, origin, SelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *ghostSheet, 0); } CC_show::const_CC_sheet_iterator_t sheet = mShow->GetCurrentSheet(); @@ -94,12 +94,12 @@ FieldView::OnDraw(wxDC *dc) { if (mCurrentReferencePoint > 0) { - DrawPoints(*dc, config, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), 0, false); - DrawPoints(*dc, config, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *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 { - DrawPoints(*dc, config, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); + DrawPoints(*dc, mConfig, origin, mShow->GetSelectionList(), mShow->GetNumPoints(), mShow->GetPointLabels(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } DrawPaths(*dc, *sheet); } @@ -109,9 +109,9 @@ FieldView::OnDraw(wxDC *dc) // Sneakily gets used for default print/preview // as well as drawing on the screen. void -FieldView::DrawOtherPoints(wxDC &dc, const CalChartConfiguration& config, const std::map& positions) +FieldView::DrawOtherPoints(wxDC &dc, const std::map& positions) { - DrawPhatomPoints(dc, config, *mShow, *mShow->GetCurrentSheet(), positions); + DrawPhatomPoints(dc, mConfig, *mShow, *mShow->GetCurrentSheet(), positions); } void @@ -355,7 +355,7 @@ FieldView::DoImportPrintableContinuity(const wxString& file) int FieldView::FindPoint(CC_coord pos) const { - return mShow->GetCurrentSheet()->FindPoint(pos.x, pos.y, Float2Coord(config.Get_DotRatio()), mCurrentReferencePoint); + return mShow->GetCurrentSheet()->FindPoint(pos.x, pos.y, Float2Coord(mConfig.Get_DotRatio()), mCurrentReferencePoint); } CC_coord @@ -461,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, config, 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 ec8297b6..54f241e6 100644 --- a/src/field_view.h +++ b/src/field_view.h @@ -49,7 +49,7 @@ class FieldView : public wxView bool OnCreate(wxDocument *doc, long flags); void OnDraw(wxDC *dc); - void DrawOtherPoints(wxDC& dc, const CalChartConfiguration& config, const std::map& positions); + void DrawOtherPoints(wxDC& dc, const std::map& positions); void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); bool OnClose(bool deleteWindow = true); @@ -120,7 +120,7 @@ class FieldView : public wxView CalChartDoc* mShow; unsigned mCurrentReferencePoint; - CalChartConfiguration& config; + CalChartConfiguration& mConfig; DECLARE_DYNAMIC_CLASS(FieldView) }; diff --git a/src/modes.cpp b/src/modes.cpp index 1bc965dd..c898b2af 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -312,27 +312,25 @@ void ShowModeSprShow::DrawHelper(wxDC& dc, const CalChartConfiguration& config, } } -class FindByName -{ -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) +std::unique_ptr +ShowMode::GetMode(const wxString& which) { - ShowModeList::const_iterator i; - if ((i = std::find_if(showModes.begin(), showModes.end(), FindByName(which))) != showModes.end()) - return (*i).get(); - return NULL; + auto iter = std::find(std::begin(kShowModeStrings), std::end(kShowModeStrings), which); + if (iter != std::end(kShowModeStrings)) + { + return ShowModeStandard::CreateShowMode(which, CalChartConfiguration::GetGlobalConfig().GetConfigurationShowMode(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().GetConfigurationSpringShowMode(std::distance(std::begin(kSpringShowModeStrings), iter))); + } + return {}; } + std::unique_ptr -CreateShowMode(const wxString& which, std::vector values) +ShowModeStandard::CreateShowMode(const wxString& which, std::vector values) { unsigned short whash = values[0]; unsigned short ehash = values[1]; @@ -350,7 +348,19 @@ CreateShowMode(const wxString& which, std::vector values) } std::unique_ptr -CreateSpringShowMode(const wxString& which, std::vector values) +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, std::vector values) { unsigned char which_spr_yards = values[0]; CC_coord bord1, bord2; diff --git a/src/modes.h b/src/modes.h index 96b2038a..bd4e8037 100644 --- a/src/modes.h +++ b/src/modes.h @@ -40,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); } @@ -67,15 +66,21 @@ class ShowMode kOmniView } HowToDraw; -public: - void Draw(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kFieldView); } - void DrawAnim(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kAnimation); } - void DrawOmni(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kOmniView); } +//public: +// void Draw(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kFieldView); } +// void DrawAnim(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kAnimation); } +// void DrawOmni(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kOmniView); } void DrawMode(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const; wxImage GetOmniLinesImage(const CalChartConfiguration& config) const; protected: + // 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; @@ -89,6 +94,16 @@ class ShowMode class ShowModeStandard : public ShowMode { public: + static std::unique_ptr CreateShowMode(const wxString& which, std::vector 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, @@ -96,6 +111,7 @@ class ShowModeStandard : public ShowMode CC_coord border2, unsigned short whash, unsigned short ehash); +public: virtual ~ShowModeStandard(); virtual ShowType GetType() const; @@ -112,6 +128,9 @@ class ShowModeStandard : public ShowMode class ShowModeSprShow : public ShowMode { public: + static std::unique_ptr CreateSpringShowMode(const wxString& which, std::vector values); + +private: // Look at calchart.cfg for description of arguments ShowModeSprShow(const wxString& name, CC_coord border1, CC_coord border2, unsigned char which, @@ -123,6 +142,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; @@ -155,14 +175,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); - -std::unique_ptr -CreateShowMode(const wxString& which, std::vector values); -std::unique_ptr -CreateSpringShowMode(const wxString& which, std::vector values); - #endif diff --git a/src/print_ps_dialog.cpp b/src/print_ps_dialog.cpp index 223c7915..1e2f24eb 100644 --- a/src/print_ps_dialog.cpp +++ b/src/print_ps_dialog.cpp @@ -167,7 +167,7 @@ void PrintPostScriptDialog::ShowPrintSelect(wxCommandEvent&) void PrintPostScriptDialog::ResetDefaults(wxCommandEvent&) { - auto& config = GetConfig(); + auto& config = CalChartConfiguration::GetGlobalConfig(); #ifdef PRINT__RUN_CMD config.Clear_PrintCmd(); config.Clear_PrintOpts(); @@ -390,7 +390,7 @@ void PrintPostScriptDialog::CreateControls() bool PrintPostScriptDialog::TransferDataToWindow() { - auto& config = GetConfig(); + auto& config = CalChartConfiguration::GetGlobalConfig(); #ifdef PRINT__RUN_CMD text_cmd->SetValue(config.Get_PrintCmd()); text_opts->SetValue(config.Get_PrintOpts()); @@ -424,7 +424,7 @@ bool PrintPostScriptDialog::TransferDataToWindow() bool PrintPostScriptDialog::TransferDataFromWindow() { - auto& config = GetConfig(); + auto& config = CalChartConfiguration::GetGlobalConfig(); #ifdef PRINT__RUN_CMD config.Set_PrintCmd(text_cmd->GetValue()); config.Set_PrintOpts(text_opts->GetValue()); From 2b9ac72ddb5263fc7b52cbb78d624a9a22f95d48 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sun, 24 Aug 2014 17:13:43 -0700 Subject: [PATCH 09/11] More merge --- src/animation_frame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/animation_frame.cpp b/src/animation_frame.cpp index 08017f4d..82cfda9b 100644 --- a/src/animation_frame.cpp +++ b/src/animation_frame.cpp @@ -132,7 +132,7 @@ 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; From ac7d8de96f926a3e90fb449d15714656d0329423 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sun, 24 Aug 2014 19:15:45 -0700 Subject: [PATCH 10/11] Converting yard_text and Show info into member variables so they follow the same caching system. Added Ghost sheet to draw preview. --- src/cc_preferences_ui.cpp | 64 ++-- src/confgr.cpp | 685 ++++++++++++++++++++------------------ src/confgr.h | 49 ++- src/modes.cpp | 20 +- src/modes.h | 4 +- src/print_ps.cpp | 6 +- 6 files changed, 446 insertions(+), 382 deletions(-) diff --git a/src/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp index 4e118e26..c4d6c108 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -264,15 +264,26 @@ mConfig(config) 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(10), Int2Coord(0)); + mPathEnd += CC_coord(Int2Coord(18), Int2Coord(0)); mPath.push_back(CC_DrawCommand(point_start, mPathEnd)); - auto shape_start = field_offset + CC_coord(Int2Coord(20), Int2Coord(2)); - auto shape_end = shape_start + CC_coord(Int2Coord(8), Int2Coord(4)); + 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); } @@ -293,11 +304,18 @@ PrefCanvas::OnPaint(wxPaintEvent& event) // Draw the field mMode->DrawMode(dc, mConfig, ShowMode::kFieldView); - // Draw the points 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); @@ -862,8 +880,8 @@ class ShowModeSetup : public PreferencePage private: void OnCmdLineText(wxCommandEvent&); void OnCmdChoice(wxCommandEvent&); - std::vector mShowModeValues[SHOWMODE_NUM]; - wxString mYardText[MAX_YARD_LINES]; + CalChartConfiguration::ShowModeInfo_t mShowModeValues[SHOWMODE_NUM]; + wxString mYardText[CalChartConfiguration::kYardTextValues]; int mWhichMode; int mWhichYardLine; }; @@ -940,9 +958,9 @@ void ShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - mShowModeValues[i] = mConfig.GetConfigurationShowMode(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] = mConfig.Get_yard_text(i); } @@ -978,13 +996,13 @@ bool ShowModeSetup::TransferDataFromWindow() // write out the values defaults: for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - mConfig.SetConfigurationShowMode(i, mShowModeValues[i]); + mConfig.Set_ShowModeInfo(static_cast(i), mShowModeValues[i]); } // grab whatever's in the box wxTextCtrl* text = (wxTextCtrl*) FindWindow(SHOW_LINE_VALUE); mYardText[mWhichYardLine] = text->GetValue(); - for (size_t i = 0; i < MAX_YARD_LINES; ++i) + for (size_t i = 0; i < CalChartConfiguration::kYardTextValues; ++i) { mConfig.Set_yard_text(i, mYardText[i]); } @@ -996,9 +1014,12 @@ bool ShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - mConfig.ClearConfigurationShowMode(i); + mConfig.Clear_ShowModeInfo(static_cast(i)); + } + for (auto i = 0; i < CalChartConfiguration::kYardTextValues; ++i) + { + mConfig.Clear_yard_text(i); } - mConfig.ClearConfigShowYardline(); Init(); return TransferDataToWindow(); } @@ -1055,8 +1076,8 @@ class SpringShowModeSetup : public PreferencePage virtual bool ClearValuesToDefault(); private: void OnCmdChoice(wxCommandEvent&); - std::vector mSpringShowModeValues[SPRINGSHOWMODE_NUM]; - wxString mYardText[MAX_SPR_LINES]; + CalChartConfiguration::SpringShowModeInfo_t mSpringShowModeValues[SPRINGSHOWMODE_NUM]; + wxString mYardText[CalChartConfiguration::kSprLineTextValues]; int mWhichMode; int mWhichYardLine; }; @@ -1171,9 +1192,9 @@ void SpringShowModeSetup::Init() mWhichYardLine = 0; for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - mSpringShowModeValues[i] = mConfig.GetConfigurationSpringShowMode(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] = mConfig.Get_spr_line_text(i); } @@ -1223,12 +1244,12 @@ bool SpringShowModeSetup::TransferDataFromWindow() // write out the values defaults: for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - mConfig.SetConfigurationSpringShowMode(modes->GetSelection(), mSpringShowModeValues[mWhichMode]); + mConfig.Set_SpringShowModeInfo(static_cast(modes->GetSelection()), mSpringShowModeValues[mWhichMode]); } wxTextCtrl* text = (wxTextCtrl*) FindWindow(SPRING_SHOW_LINE_VALUE); mYardText[mWhichYardLine] = text->GetValue(); - for (size_t i = 0; i < MAX_SPR_LINES; ++i) + for (size_t i = 0; i < CalChartConfiguration::kSprLineTextValues; ++i) { mConfig.Set_spr_line_text(i, mYardText[i]); } @@ -1240,9 +1261,12 @@ bool SpringShowModeSetup::ClearValuesToDefault() { for (size_t i = 0; i < SPRINGSHOWMODE_NUM; ++i) { - mConfig.ClearConfigurationSpringShowMode(i); + mConfig.Clear_SpringShowModeInfo(static_cast(i)); + } + for (auto i = 0; i < CalChartConfiguration::kSprLineTextValues; ++i) + { + mConfig.Clear_spr_line_text(i); } - mConfig.ClearConfigSpringShowYardline(); Init(); return TransferDataToWindow(); } diff --git a/src/confgr.cpp b/src/confgr.cpp index 543d3762..cf7c1364 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -36,8 +36,6 @@ #include "modes.h" #include "cc_omniview_constants.h" -using ColorWidth_t = std::pair; - const std::tuple ColorInfo[COLOR_NUM] = { { wxT("FIELD"), wxT("FOREST GREEN"), 1 }, @@ -67,6 +65,77 @@ const std::tuple ColorInfo[COLOR_NUM] = { wxT("CONTINUITY PATHS"), wxT("RED"), 1 }, }; +///// Show mode configuration ///// + +const wxString kShowModeStrings[SHOWMODE_NUM] = +{ + 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 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"), +}; + +// 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; @@ -88,13 +157,12 @@ CalChartConfiguration::AssignConfig(const CalChartConfiguration& config) } - -// functions for dealing with the wx config directly +// 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; @@ -102,7 +170,41 @@ T GetConfigValue(const wxString& key, const T& def) // clear out the config if it matches template -void ClearConfigValue(const wxString& key); +void ClearConfigPathKey(const wxString& path, const wxString& key) +{ + wxConfigBase *config = wxConfigBase::Get(); + config->SetPath(path); + config->DeleteEntry(key); + config->Flush(); +} + +// default value need to check if we need to set a value +template +void SetConfigPathKey(const wxString& path, const wxString& key, const T& value) +{ + wxConfigBase *config = wxConfigBase::Get(); + config->SetPath(path); + config->Write(key, value); + config->Flush(); +} + + +// functions for dealing with the wx config directly +template +T GetConfigValue(const wxString& key, const T& def) +{ + return GetConfigPathKey(wxT("/CalChart"), key, def); +} + +// 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 @@ -114,115 +216,146 @@ void SetConfigValue(const wxString& key, const T& value, const T& def) // clear out the value if it's the same as the default if (def == value) { - ClearConfigValue(key); + ClearConfigPathKey(wxT("/CalChart"), key); return; } - - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/CalChart")); - config->Write(key, value); - config->Flush(); -} - -template -void ClearConfigValue(const wxString& key) -{ - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/CalChart")); - config->DeleteEntry(key); - config->Flush(); + SetConfigPathKey(wxT("/CalChart"), key, value); } // Specialize on Color template <> -ColorWidth_t GetConfigValue(const wxString& key, const ColorWidth_t& def) +CalChartConfiguration::ColorWidth_t GetConfigValue(const wxString& key, const CalChartConfiguration::ColorWidth_t& def) { - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/COLORS")); - wxString rkey = key + wxT("_Red"); - wxString gkey = key + wxT("_Green"); - wxString bkey = key + wxT("_Blue"); long r = std::get<0>(def).Red(); long g = std::get<0>(def).Green(); long b = std::get<0>(def).Blue(); - config->Read(rkey, &r); - config->Read(gkey, &g); - config->Read(bkey, &b); + 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); - // store widths in a subgroup - config->SetPath(wxT("WIDTH")); long w = std::get<1>(def); - config->Read(key, &w); + w = GetConfigPathKey(wxT("/COLORS/WIDTH"), key, w); + return { wxColour( r, g, b ), w }; } // Specialize on Color template <> -void SetConfigValue(const wxString& key, const ColorWidth_t& value, const ColorWidth_t& def) +void SetConfigValue(const wxString& key, const CalChartConfiguration::ColorWidth_t& value, const CalChartConfiguration::ColorWidth_t& def) { // don't write if we don't have to - if (GetConfigValue(key, def) == value) + 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) -// { -// ClearConfigValue(rkey); -// ClearConfigValue(gkey); -// ClearConfigValue(bkey); -// return; -// } + // 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; + } - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/COLORS")); long r = std::get<0>(value).Red(); long g = std::get<0>(value).Green(); long b = std::get<0>(value).Blue(); - config->Write(rkey, r); - config->Write(gkey, g); - config->Write(bkey, b); - config->SetPath(wxT("WIDTH")); long w = std::get<1>(def); - config->Write(key, w); - config->Flush(); + 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") }; - -// printing controls -wxString yard_text[MAX_YARD_LINES] = +template <> +CalChartConfiguration::ShowModeInfo_t GetConfigValue(const wxString& key, const CalChartConfiguration::ShowModeInfo_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") -}; + 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; +} -const wxString yard_text_index[MAX_YARD_LINES] = +// Specialize on show mode +template <> +void SetConfigValue(const wxString& key, const CalChartConfiguration::ShowModeInfo_t& value, const CalChartConfiguration::ShowModeInfo_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; + 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]); + } +} -static bool yard_text_valid = false; +// 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") }; -wxString spr_line_text[MAX_SPR_LINES] = +template <> +CalChartConfiguration::SpringShowModeInfo_t GetConfigValue(const wxString& key, const CalChartConfiguration::SpringShowModeInfo_t& def) { - wxT("A"), wxT("B"), wxT("C"), wxT("D"), wxT("E"), -}; + 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; +} -const wxString spr_line_text_index[MAX_SPR_LINES] = +// Specialize on spring show mode +template <> +void SetConfigValue(const wxString& key, const CalChartConfiguration::SpringShowModeInfo_t& value, const CalChartConfiguration::SpringShowModeInfo_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 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]); + } +} -static bool spr_line_yard_text_valid = false; #define IMPLEMENT_CONFIGURATION_FUNCTIONS( KeyName, Type, TheValue ) \ static const wxString k ## KeyName ## Key = wxT( #KeyName ); \ @@ -321,335 +454,229 @@ IMPLEMENT_CONFIGURATION_FUNCTIONS( AnimationFrameSplitVertical, bool, false); //IMPLEMENT_CONFIGURATION_FUNCTIONS( MainFrameHeight, long, 450); -///// 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") -}; + 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; +} -// 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::vector kShowModeDefaultValues[SHOWMODE_NUM] = +std::vector +CalChartConfiguration::GetDefaultColors() const { - { 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<1>(i); }); + return result; +} -const wxString kSpringShowModeStrings[SPRINGSHOWMODE_NUM] = +std::vector +CalChartConfiguration::GetDefaultPenWidth() 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<2>(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 std::vector kSpringShowModeDefaultValues[SPRINGSHOWMODE_NUM] = +std::vector +CalChartConfiguration::Get_yard_text_index() const { - { 0xD, 8, 8, 8, 8, -16, -30, 32, 28, 0, 0, 571, 400, 163, 38, 265, 232, 153, 438, 270, 12 } -}; + return { std::begin(yard_text_index), std::end(yard_text_index) }; +} -std::vector -CalChartConfiguration::GetConfigurationShowMode(size_t which) const +std::vector +CalChartConfiguration::Get_spr_line_text_index() const { - std::vector values = kShowModeDefaultValues[which]; - - 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 values; + return { std::begin(spr_line_text_index), std::end(spr_line_text_index) }; } -std::vector -CalChartConfiguration::GetConfigurationSpringShowMode(size_t which) const +///// Color Configuration ///// + +std::pair +CalChartConfiguration::Get_CalChartBrushAndPen(CalChartColors c) const { - std::vector values = kSpringShowModeDefaultValues[which]; + 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]))); } - return values; + auto colorAndWidth = mColorsAndWidth[c]; + return { *wxTheBrushList->FindOrCreateBrush(std::get<0>(colorAndWidth), wxSOLID), *wxThePenList->FindOrCreatePen(std::get<0>(colorAndWidth), std::get<1>(colorAndWidth), wxSOLID) }; } void -CalChartConfiguration::SetConfigurationShowMode(size_t which, const std::vector& values) +CalChartConfiguration::Set_CalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen) { - 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(); -} + if (c >= COLOR_NUM) + throw std::runtime_error("Error, exceeding COLOR_NUM size"); -void -CalChartConfiguration::SetConfigurationSpringShowMode(size_t which, const std::vector& values) -{ - 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(); -} + ColorWidth_t v{ brush.GetColour(), pen.GetWidth() }; -void -CalChartConfiguration::ClearConfigurationShowMode(size_t which) -{ - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SHOWMODES")); - config->DeleteEntry(kShowModeStrings[which]); + 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 -CalChartConfiguration::ClearConfigurationSpringShowMode(size_t which) +CalChartConfiguration::Clear_ConfigColor(size_t selection) { - wxConfigBase *config = wxConfigBase::Get(); - config->SetPath(wxT("/SPRINGSHOWMODES")); - config->DeleteEntry(kSpringShowModeStrings[which]); -} + if (selection >= COLOR_NUM) + throw std::runtime_error("Error, exceeding COLOR_NUM size"); -void ReadConfigYardlines() -{ - if (yard_text_valid) - { - return; - } - 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]); - } - yard_text_valid = true; + 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 ReadConfigSpringYardlines() +///// Show Configuration ///// + +CalChartConfiguration::ShowModeInfo_t +CalChartConfiguration::Get_ShowModeInfo(CalChartShowModes which) const { - if (spr_line_yard_text_valid) - { - return; - } - for (size_t i = 0; i < MAX_SPR_LINES; ++i) + if (which >= SHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SHOWMODE_NUM size"); + + if (!mShowModeInfos.count(which)) { - wxString key; - key.Printf(wxT("SpringShowYardLines_%ld"), i); - spr_line_text[i] = GetConfigValue(key, spr_line_text_index[i]); + mShowModeInfos[which] = GetConfigValue(kShowModeStrings[which], kShowModeDefaultValues[which]); } - spr_line_yard_text_valid = true; -} - -wxString -CalChartConfiguration::Get_yard_text(size_t which) const -{ - if (which >= MAX_YARD_LINES) - throw std::runtime_error("Error, exceeding yard_text size"); - ReadConfigYardlines(); - return yard_text[which]; + return mShowModeInfos[which]; } void -CalChartConfiguration::Set_yard_text(size_t which, const wxString& name) -{ - if (which >= MAX_YARD_LINES) - throw std::runtime_error("Error, exceeding yard_text size"); - yard_text[which] = name; - wxString key; - key.Printf(wxT("YardLines_%ld"), which); - SetConfigValue(key, yard_text[which], yard_text_index[which]); -} - -wxString -CalChartConfiguration::Get_spr_line_text(size_t which) const +CalChartConfiguration::Set_ShowModeInfo(CalChartShowModes which, const ShowModeInfo_t& values) { - if (which >= MAX_SPR_LINES) - throw std::runtime_error("Error, exceeding yard_text size"); - ReadConfigSpringYardlines(); - return spr_line_text[which]; + if (which >= SHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SHOWMODE_NUM size"); + + mWriteQueue[kShowModeStrings[which]] = [which, values]() { SetConfigValue(kShowModeStrings[which], values, kShowModeDefaultValues[which]); }; + mShowModeInfos[which] = values; } void -CalChartConfiguration::Set_spr_line_text(size_t which, const wxString& name) +CalChartConfiguration::Clear_ShowModeInfo(CalChartShowModes which) { - if (which >= MAX_SPR_LINES) - throw std::runtime_error("Error, exceeding yard_text size"); - spr_line_text[which] = name; - wxString key; - key.Printf(wxT("SpringShowYardLines_%ld"), which); - SetConfigValue(key, spr_line_text[which], spr_line_text_index[which]); + if (which >= SHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SHOWMODE_NUM size"); + + auto default_value = kShowModeDefaultValues[which]; + SetConfigValue(kShowModeStrings[which], default_value, default_value); } -std::vector -CalChartConfiguration::Get_yard_text_index() const -{ - return { std::begin(yard_text_index), std::end(yard_text_index) }; -} -std::vector -CalChartConfiguration::Get_spr_line_text_index() const +CalChartConfiguration::SpringShowModeInfo_t +CalChartConfiguration::Get_SpringShowModeInfo(CalChartSpringShowModes which) const { - return { std::begin(spr_line_text_index), std::end(spr_line_text_index) }; -} - -std::vector -CalChartConfiguration::GetColorNames() const -{ - 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; + if (which >= SPRINGSHOWMODE_NUM) + throw std::runtime_error("Error, exceeding SPRINGSHOWMODE_NUM size"); + + if (!mSpringShowModeInfos.count(which)) + { + mSpringShowModeInfos[which] = GetConfigValue(kSpringShowModeStrings[which], kSpringShowModeDefaultValues[which]); + } + return mSpringShowModeInfos[which]; } -std::vector -CalChartConfiguration::GetDefaultColors() const +void +CalChartConfiguration::Set_SpringShowModeInfo(CalChartSpringShowModes which, const SpringShowModeInfo_t& values) { - 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; + 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; } -std::vector -CalChartConfiguration::GetDefaultPenWidth() const +void +CalChartConfiguration::Clear_SpringShowModeInfo(CalChartSpringShowModes which) { - 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; + 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 -CalChartConfiguration::ClearConfigShowYardline() +// Yard Lines +wxString +CalChartConfiguration::Get_yard_text(size_t which) const { - for (size_t i = 0; i < MAX_YARD_LINES; ++i) + if (which >= kYardTextValues) + throw std::runtime_error("Error, exceeding kYardTextValues size"); + + if (!mYardTextInfos.count(which)) { wxString key; - key.Printf(wxT("YardLines_%ld"), i); - ClearConfigValue(key); + key.Printf(wxT("YardLines_%ld"), which); + mYardTextInfos[which] = GetConfigValue(key, yard_text_defaults[which]); } - yard_text_valid = false; + return mYardTextInfos[which]; } void -CalChartConfiguration::ClearConfigSpringShowYardline() +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); - } - spr_line_yard_text_valid = false; + 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; } -///// Color Configuration ///// +void +CalChartConfiguration::Clear_yard_text(size_t which) +{ + 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); +} -std::pair -CalChartConfiguration::Get_CalChartBrushAndPen(CalChartColors c) const +wxString +CalChartConfiguration::Get_spr_line_text(size_t which) const { - if (!mColorsAndWidth.count(c)) + if (which >= kSprLineTextValues) + throw std::runtime_error("Error, exceeding kSprLineTextValues size"); + + if (!mSprLineTextInfos.count(which)) { - mColorsAndWidth[c] = GetConfigValue(std::get<0>(ColorInfo[c]), ColorWidth_t(std::get<1>(ColorInfo[c]), std::get<2>(ColorInfo[c]))); + wxString key; + key.Printf(wxT("SpringShowLines_%ld"), which); + mSprLineTextInfos[which] = GetConfigValue(key, spr_line_text_defaults[which]); } - auto colorAndWidth = mColorsAndWidth[c]; - return { *wxTheBrushList->FindOrCreateBrush(std::get<0>(colorAndWidth), wxSOLID), *wxThePenList->FindOrCreatePen(std::get<0>(colorAndWidth), std::get<1>(colorAndWidth), wxSOLID) }; + return mSprLineTextInfos[which]; } void -CalChartConfiguration::Set_CalChartBrushAndPen(CalChartColors c, const wxBrush& brush, const wxPen& pen) +CalChartConfiguration::Set_spr_line_text(size_t which, const wxString& value) { - if (c >= COLOR_NUM) - throw std::runtime_error("Error, exceeding COLOR_NUM size"); - - ColorWidth_t v{ brush.GetColour(), pen.GetWidth() }; - - 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; + 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; } void -CalChartConfiguration::Clear_ConfigColor(size_t selection) +CalChartConfiguration::Clear_spr_line_text(size_t 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); + 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 diff --git a/src/confgr.h b/src/confgr.h index 27fab96d..e491846b 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -28,6 +28,7 @@ #include #include #include +#include // forward declare class wxPen; @@ -36,9 +37,6 @@ class wxPathList; class wxColour; class ShowMode; -#define MAX_SPR_LINES 5 -#define MAX_YARD_LINES 53 - enum CalChartColors { COLOR_FIELD, @@ -191,35 +189,50 @@ private: \ 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&); - std::vector Get_yard_text_index() const; + 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&); - std::vector Get_spr_line_text_index() const; - void ClearConfigShowYardline(); - void ClearConfigSpringShowYardline(); - - static const size_t kShowModeValues = 10; - std::vector GetConfigurationShowMode(size_t which) const; - void SetConfigurationShowMode(size_t which, const std::vector& values); - void ClearConfigurationShowMode(size_t which); - - static const size_t kSpringShowModeValues = 21; - std::vector GetConfigurationSpringShowMode(size_t which) const; - void SetConfigurationSpringShowMode(size_t which, const std::vector& values); - void ClearConfigurationSpringShowMode(size_t which); + void Clear_spr_line_text(size_t which); }; diff --git a/src/modes.cpp b/src/modes.cpp index c898b2af..4ec8774f 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -203,9 +203,9 @@ void ShowModeStandard::DrawHelper(wxDC& dc, const CalChartConfiguration& config, { CC_coord fieldedge = mOffset - mBorder1; wxCoord textw, texth, textd; - dc.GetTextExtent(config.Get_yard_text(i+(-Coord2Int(fieldedge.x)+(MAX_YARD_LINES-1)*4)/8), &textw, &texth, &textd); - dc.DrawText(config.Get_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(config.Get_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)); } } @@ -295,11 +295,11 @@ void ShowModeSprShow::DrawHelper(wxDC& dc, const CalChartConfiguration& config, for (int i = 0; howToDraw == kFieldView && i < Coord2Int(fieldsize.x)/8+1; i++) { wxCoord textw, texth, textd; - dc.GetTextExtent(config.Get_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(config.Get_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(config.Get_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) { @@ -318,19 +318,19 @@ ShowMode::GetMode(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().GetConfigurationShowMode(std::distance(std::begin(kShowModeStrings), iter))); + 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().GetConfigurationSpringShowMode(std::distance(std::begin(kSpringShowModeStrings), iter))); + 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, std::vector values) +ShowModeStandard::CreateShowMode(const wxString& which, const CalChartConfiguration::ShowModeInfo_t& values) { unsigned short whash = values[0]; unsigned short ehash = values[1]; @@ -360,7 +360,7 @@ ShowModeStandard::CreateShowMode(const wxString& name, } std::unique_ptr -ShowModeSprShow::CreateSpringShowMode(const wxString& which, std::vector values) +ShowModeSprShow::CreateSpringShowMode(const wxString& which, const CalChartConfiguration::SpringShowModeInfo_t& values) { unsigned char which_spr_yards = values[0]; CC_coord bord1, bord2; diff --git a/src/modes.h b/src/modes.h index bd4e8037..8877ea3a 100644 --- a/src/modes.h +++ b/src/modes.h @@ -94,7 +94,7 @@ class ShowMode class ShowModeStandard : public ShowMode { public: - static std::unique_ptr CreateShowMode(const wxString& which, std::vector values); + 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, @@ -128,7 +128,7 @@ class ShowModeStandard : public ShowMode class ShowModeSprShow : public ShowMode { public: - static std::unique_ptr CreateSpringShowMode(const wxString& which, std::vector values); + static std::unique_ptr CreateSpringShowMode(const wxString& which, const CalChartConfiguration::SpringShowModeInfo_t& values); private: // Look at calchart.cfg for description of arguments diff --git a/src/print_ps.cpp b/src/print_ps.cpp index 2162bd0a..bc54303e 100644 --- a/src/print_ps.cpp +++ b/src/print_ps.cpp @@ -815,7 +815,7 @@ void PrintShowToPS::PrintStandard(std::ostream& buffer, const CC_sheet& sheet) snprintf(buf, sizeof(buf), "/y %.2f def\n", field_h + (step_size / 2)); buffer<StageH()); buffer<StepsX() + - (MAX_YARD_LINES-1)*4 + j)/8).utf8_str()); + (CalChartConfiguration::kYardTextValues-1)*4 + j)/8).utf8_str()); snprintf(buf, sizeof(buf), "(%s) centerText\n", yardstr.c_str()); buffer<StageH() -(step_size*config.Get_YardsSize())); buffer<StepsX() + - (MAX_YARD_LINES-1)*4 + j)/8).utf8_str()); + (CalChartConfiguration::kYardTextValues-1)*4 + j)/8).utf8_str()); snprintf(buf, sizeof(buf), "(%s) centerText\n", yardstr.c_str()); buffer< Date: Sun, 24 Aug 2014 22:05:26 -0700 Subject: [PATCH 11/11] final amount of clean-up. --- src/cc_preferences_ui.cpp | 133 ++++++++++++-------------------------- src/cont_ui.cpp | 7 -- src/modes.h | 4 -- 3 files changed, 43 insertions(+), 101 deletions(-) diff --git a/src/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp index c4d6c108..e9a61af4 100644 --- a/src/cc_preferences_ui.cpp +++ b/src/cc_preferences_ui.cpp @@ -214,11 +214,11 @@ class PrefCanvas : public ClickDragCtrlScrollCanvas 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; @@ -257,7 +257,7 @@ mConfig(config) 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); @@ -295,7 +295,7 @@ PrefCanvas::OnPaint(wxPaintEvent& event) { wxBufferedPaintDC dc(this); PrepareDC(dc); - + // draw the background dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackground(mConfig.Get_CalChartBrushAndPen(COLOR_FIELD).first); @@ -340,7 +340,7 @@ class DrawingSetup : public PreferencePage { DECLARE_CLASS( DrawingSetup ) DECLARE_EVENT_TABLE() - + public: DrawingSetup( CalChartConfiguration& config, wxWindow *parent, wxWindowID id = wxID_ANY, @@ -354,15 +354,15 @@ class DrawingSetup : public PreferencePage 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&); @@ -370,16 +370,15 @@ class DrawingSetup : public PreferencePage 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 @@ -388,11 +387,10 @@ enum BUTTON_RESTORE, SPIN_WIDTH, NEW_COLOR_CHOICE, - A_DOTRATIO, - A_NUMRATIO, - A_PLINERATIO, - A_SLINERATIO, - A_CONTRATIO + DOTRATIO, + NUMRATIO, + PLINERATIO, + SLINERATIO }; @@ -401,11 +399,10 @@ 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(A_DOTRATIO,DrawingSetup::OnCmdTextChanged) -EVT_TEXT_ENTER(A_NUMRATIO,DrawingSetup::OnCmdTextChanged) -EVT_TEXT_ENTER(A_PLINERATIO,DrawingSetup::OnCmdTextChanged) -EVT_TEXT_ENTER(A_SLINERATIO,DrawingSetup::OnCmdTextChanged) -EVT_TEXT_ENTER(A_CONTRATIO,DrawingSetup::OnCmdTextChanged) +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 ) @@ -414,10 +411,10 @@ 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, mConfig.GetColorNames().at(0), wxDefaultPosition, wxDefaultSize, COLOR_NUM, mConfig.GetColorNames().data(), wxCB_READONLY|wxCB_DROPDOWN); horizontalsizer->Add(nameBox, sBasicSizerFlags ); @@ -432,36 +429,35 @@ void DrawingSetup::CreateControls() nameBox->SetItemBitmap(i, temp_bitmap); } nameBox->SetSelection(0); - + spin = new wxSpinCtrl(this, SPIN_WIDTH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mCalChartPens[nameBox->GetSelection()].GetWidth()); spin->SetValue(mCalChartPens[nameBox->GetSelection()].GetWidth()); horizontalsizer->Add(spin, sBasicSizerFlags ); boxsizer->Add(horizontalsizer, sLeftBasicSizerFlags ); - + horizontalsizer = new wxBoxSizer( wxHORIZONTAL ); - + horizontalsizer->Add(new wxButton(this, BUTTON_SELECT, wxT("&Change Color")), sBasicSizerFlags ); horizontalsizer->Add(new wxButton(this, BUTTON_RESTORE, wxT("&Reset Color")), sBasicSizerFlags ); - + 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, A_DOTRATIO, wxT("Dot Ratio:"), wxTE_PROCESS_ENTER); - AddTextboxWithCaption(this, horizontalsizer, A_NUMRATIO, wxT("Num Ratio:"), wxTE_PROCESS_ENTER); - AddTextboxWithCaption(this, horizontalsizer, A_PLINERATIO, wxT("P-Line Ratio:"), wxTE_PROCESS_ENTER); - AddTextboxWithCaption(this, horizontalsizer, A_SLINERATIO, wxT("S-Line Ratio:"), wxTE_PROCESS_ENTER); - AddTextboxWithCaption(this, horizontalsizer, A_CONTRATIO, wxT("Continuity Ratio:"), wxTE_PROCESS_ENTER); - + + 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(); } @@ -474,7 +470,7 @@ void DrawingSetup::Init() mCalChartPens[i] = brushAndPen.second; mCalChartBrushes[i] = brushAndPen.first; } - + mPrintValues[0] = mConfig.Get_DotRatio(); mPrintValues[1] = mConfig.Get_NumRatio(); mPrintValues[2] = mConfig.Get_PLineRatio(); @@ -485,22 +481,19 @@ void DrawingSetup::Init() bool DrawingSetup::TransferDataToWindow() { wxString buf; - wxTextCtrl* text = (wxTextCtrl*) FindWindow(A_DOTRATIO); + wxTextCtrl* text = (wxTextCtrl*) FindWindow(DOTRATIO); buf.Printf(wxT("%.2f"), mPrintValues[0]); text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(A_NUMRATIO); + text = (wxTextCtrl*) FindWindow(NUMRATIO); buf.Printf(wxT("%.2f"), mPrintValues[1]); text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(A_PLINERATIO); + text = (wxTextCtrl*) FindWindow(PLINERATIO); buf.Printf(wxT("%.2f"), mPrintValues[2]); text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(A_SLINERATIO); + text = (wxTextCtrl*) FindWindow(SLINERATIO); buf.Printf(wxT("%.2f"), mPrintValues[3]); text->SetValue(buf); - text = (wxTextCtrl*) FindWindow(A_CONTRATIO); - buf.Printf(wxT("%.2f"), mPrintValues[4]); - text->SetValue(buf); - + return true; } @@ -530,9 +523,9 @@ 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); @@ -585,7 +578,7 @@ void DrawingSetup::OnCmdTextChanged(wxCommandEvent& e) double value; if (text->GetValue().ToDouble(&value)) { - switch (id - A_DOTRATIO) + switch (id - DOTRATIO) { case 0: mConfig.Set_DotRatio(value); @@ -657,10 +650,6 @@ typedef enum HEADERSIZE, YARDSSIZE, TEXTSIZE, - DOTRATIO, - NUMRATIO, - PLINERATIO, - SLINERATIO, CONTRATIO } PSPrintingSetUp_IDs; @@ -700,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(); @@ -721,10 +706,6 @@ void PSPrintingSetUp::Init() mPrintValues[0] = mConfig.Get_HeaderSize(); mPrintValues[1] = mConfig.Get_YardsSize(); mPrintValues[2] = mConfig.Get_TextSize(); - mPrintValues[3] = mConfig.Get_DotRatio(); - mPrintValues[4] = mConfig.Get_NumRatio(); - mPrintValues[5] = mConfig.Get_PLineRatio(); - mPrintValues[6] = mConfig.Get_SLineRatio(); mPrintValues[7] = mConfig.Get_ContRatio(); } @@ -754,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); @@ -795,14 +764,6 @@ 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]); @@ -817,10 +778,6 @@ bool PSPrintingSetUp::TransferDataFromWindow() mConfig.Set_HeaderSize(mPrintValues[0]); mConfig.Set_YardsSize(mPrintValues[1]); mConfig.Set_TextSize(mPrintValues[2]); - mConfig.Set_DotRatio(mPrintValues[3]); - mConfig.Set_NumRatio(mPrintValues[4]); - mConfig.Set_PLineRatio(mPrintValues[5]); - mConfig.Set_SLineRatio(mPrintValues[6]); mConfig.Set_ContRatio(mPrintValues[7]); return true; } @@ -837,10 +794,6 @@ bool PSPrintingSetUp::ClearValuesToDefault() mConfig.Clear_HeaderSize(); mConfig.Clear_YardsSize(); mConfig.Clear_TextSize(); - mConfig.Clear_DotRatio(); - mConfig.Clear_NumRatio(); - mConfig.Clear_PLineRatio(); - mConfig.Clear_SLineRatio(); mConfig.Clear_ContRatio(); Init(); return TransferDataToWindow(); diff --git a/src/cont_ui.cpp b/src/cont_ui.cpp index aafddd75..4dbcda43 100644 --- a/src/cont_ui.cpp +++ b/src/cont_ui.cpp @@ -167,13 +167,6 @@ void ContinuityEditor::CreateControls() mUserInput = new FancyTextWin(this, ContinuityEditor_KeyPress, wxEmptyString, wxDefaultPosition, wxSize(50, 300)); - - wxArrayString autocompletes; - for (auto& i : { wxT("Hello"), wxT("Bye"), wxT("Cat"), wxT("Hela") }) - { - autocompletes.Add(i); - } - mUserInput->AutoComplete(autocompletes); topsizer->Add(mUserInput, 0, wxGROW|wxALL, 5 ); diff --git a/src/modes.h b/src/modes.h index 8877ea3a..87edab33 100644 --- a/src/modes.h +++ b/src/modes.h @@ -66,10 +66,6 @@ class ShowMode kOmniView } HowToDraw; -//public: -// void Draw(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kFieldView); } -// void DrawAnim(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kAnimation); } -// void DrawOmni(wxDC& dc, const CalChartConfiguration& config) const { DrawHelper(dc, config, kOmniView); } void DrawMode(wxDC& dc, const CalChartConfiguration& config, HowToDraw howToDraw) const; wxImage GetOmniLinesImage(const CalChartConfiguration& config) const;