diff --git a/.gitignore b/.gitignore index f6e6a113..24482beb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +build/* build-macos/CalChart.xcodeproj/project.xcworkspace/* build-macos/CalChart.xcodeproj/xcuserdata/* build-win/README.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index e7822bed..42977bb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,8 +188,105 @@ source_group( add_executable ( CalChart - ${CalChartSources} - ${CalChartHeaders} + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationCanvas.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationCanvas.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationErrorsPanel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationErrorsPanel.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationPanel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationPanel.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/AnimationView.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CCOmniviewCanvas.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CCOmniviewCanvas.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartApp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartApp.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartDoc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartDoc.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartDocCommand.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartDocCommand.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartFrame.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartFrame.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartPreferences.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartPreferences.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartSizes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartSizes.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartToolBar.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartToolBar.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalChartView.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ColorPalette.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ColorPalette.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ColorSetupCanvas.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ColorSetupCanvas.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ColorSetupDialog.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ColorSetupDialog.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityBrowser.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityBrowser.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityBrowserPanel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityBrowserPanel.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityComposerDialog.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityComposerDialog.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityEditorPopup.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ContinuityEditorPopup.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/CustomListViewPanel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CustomListViewPanel.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/FieldCanvas.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/FieldCanvas.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/FieldControlsToolBar.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/FieldControlsToolBar.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/FieldThumbnailBrowser.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/FieldThumbnailBrowser.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesContCellSetup.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesContCellSetup.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesDrawingSetup.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesDrawingSetup.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesGeneralSetup.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesGeneralSetup.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesPSPrintingSetup.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesPSPrintingSetup.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesShowModeSetup.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesShowModeSetup.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesUtils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesUtils.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/PrintContinuityEditor.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/PrintContinuityEditor.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/TopFrame.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/TopFrame.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/background_image.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/background_image.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/basic_ui.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/basic_ui.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/cc_omniview_constants.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/confgr.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/confgr.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/cont_box_draw.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cont_box_draw.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/draw.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/draw.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/draw_utils.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/e7_transition_solver_ui.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/e7_transition_solver_ui.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/field_canvas_shapes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/field_canvas_shapes.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ghost_module.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ghost_module.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/linmath.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/mode_dialog.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/mode_dialog.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/mode_dialog_canvas.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/mode_dialog_canvas.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/platconf.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/print_ps_dialog.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/print_ps_dialog.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/setup_wizards.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/setup_wizards.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/show_ui.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/show_ui.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/single_instance_ipc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/single_instance_ipc.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/ui_enums.h ${CalChartDocs} ${CalChartResources} "${CMAKE_CURRENT_SOURCE_DIR}/calchart.rc" diff --git a/resources/default_sprite_strip.png b/resources/default_sprite_strip.png new file mode 100644 index 00000000..54199a4d Binary files /dev/null and b/resources/default_sprite_strip.png differ diff --git a/shows/Dance Show final.shw b/shows/Dance Show final.shw index 7b0d406d..5c749c79 100755 Binary files a/shows/Dance Show final.shw and b/shows/Dance Show final.shw differ diff --git a/src/AnimationCanvas.cpp b/src/AnimationCanvas.cpp index bf784d81..cbb806d7 100644 --- a/src/AnimationCanvas.cpp +++ b/src/AnimationCanvas.cpp @@ -56,6 +56,17 @@ void AnimationCanvas::CreateControls() SetSizer(topSizer); } +bool AnimationCanvas::GetUseSprites() const +{ + return CalChartConfiguration::GetGlobalConfig().Get_UseSprites(); +} + +void AnimationCanvas::SetUseSprites(bool useSprites) +{ + CalChartConfiguration::GetGlobalConfig().Set_UseSprites(useSprites); + Refresh(); +} + void AnimationCanvas::SetZoomOnMarchers(bool zoomOnMarchers) { mZoomOnMarchers = zoomOnMarchers; diff --git a/src/AnimationCanvas.h b/src/AnimationCanvas.h index b9fa9709..7d40f4f7 100644 --- a/src/AnimationCanvas.h +++ b/src/AnimationCanvas.h @@ -35,13 +35,15 @@ class AnimationCanvas : public wxPanel { ~AnimationCanvas() override = default; void OnUpdate(); // Refresh from the View - void SetView(AnimationView* view) { mView = view; } auto GetView() const { return mView; } + void SetView(AnimationView* view) { mView = view; } - void SetZoomOnMarchers(bool zoomOnMarchers); + bool GetUseSprites() const; + void SetUseSprites(bool useSprites); auto GetZoomOnMarchers() const { return mZoomOnMarchers; } - void SetStepsOutForMarchersZoom(int steps); + void SetZoomOnMarchers(bool zoomOnMarchers); auto GetStepsOutForMarchersZoom() const { return mStepsOutForMarcherZoom; } + void SetStepsOutForMarchersZoom(int steps); private: void Init(); diff --git a/src/AnimationPanel.cpp b/src/AnimationPanel.cpp index 77287f06..632e69f4 100644 --- a/src/AnimationPanel.cpp +++ b/src/AnimationPanel.cpp @@ -109,6 +109,14 @@ void AnimationPanel::CreateControls() AddToSizerBasic(boxsizer, mTempoCtrl); mItemsToHide.push_back(mTempoCtrl); + mSpritesCheckbox = new wxCheckBox(this, wxID_ANY, wxT("Sprites")); + mSpritesCheckbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) { + mCanvas->SetUseSprites(event.IsChecked()); + }); + mSpritesCheckbox->SetValue(mCanvas->GetUseSprites()); + AddToSizerBasic(toprow, mSpritesCheckbox); + mItemsToHide.push_back(mSpritesCheckbox); + auto sizer1 = new wxBoxSizer(wxVERTICAL); mZoomCheckbox = new wxCheckBox(this, wxID_ANY, wxT("Zoom")); mZoomCheckbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) { @@ -183,6 +191,7 @@ void AnimationPanel::OnCmd_ToggleAnimOmni(wxCommandEvent& event) mShowOmni = !mShowOmni; if (mShowOmni) { mCanvas->Hide(); + mSpritesCheckbox->Hide(); mZoomCheckbox->Hide(); mCollisionCheckbox->Hide(); mOmniCanvas->Show(); @@ -190,6 +199,7 @@ void AnimationPanel::OnCmd_ToggleAnimOmni(wxCommandEvent& event) mAnimateOmniToggle->SetLabel(wxT("Animate")); } else { mCanvas->Show(); + mSpritesCheckbox->Show(); mZoomCheckbox->Show(); mCollisionCheckbox->Show(); mOmniCanvas->Hide(); diff --git a/src/AnimationPanel.h b/src/AnimationPanel.h index 9e1a1db0..0f7863f4 100644 --- a/src/AnimationPanel.h +++ b/src/AnimationPanel.h @@ -54,6 +54,7 @@ class AnimationPanel : public wxPanel { void ToggleTimer(); void UpdatePanel(); // specfically to update the controls bool OnBeat() const; + auto TimerOn() const { return mTimerOn; } auto GetInMiniMode() const { return mInMiniMode; } void SetInMiniMode(bool); @@ -82,6 +83,7 @@ class AnimationPanel : public wxPanel { wxStaticText* mTempoLabel{}; wxSpinCtrl* mTempoCtrl{}; wxSlider* mBeatSlider{}; + wxCheckBox* mSpritesCheckbox{}; wxCheckBox* mZoomCheckbox{}; wxCheckBox* mCollisionCheckbox{}; wxBitmapToggleButton* mPlayPauseButton{}; diff --git a/src/AnimationView.cpp b/src/AnimationView.cpp index a3cce449..ca42c823 100644 --- a/src/AnimationView.cpp +++ b/src/AnimationView.cpp @@ -51,6 +51,28 @@ AnimationView::AnimationView(CalChartView* view, wxWindow* frame) : mView(view) { SetFrame(frame); + +#if defined(__APPLE__) && (__APPLE__) + const static wxString kImageDir = wxT("CalChart.app/Contents/Resources/default_sprite_strip.png"); +#else + const static wxString kImageDir = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath().Append(PATH_SEPARATOR wxT("resources") PATH_SEPARATOR wxT("default_sprite_strip.png")); +#endif + constexpr auto image_X = 64; + constexpr auto image_Y = 128; + auto image = [](){ + wxImage image; + if (!image.LoadFile(kImageDir)) { + wxLogError(wxT("Couldn't load image from ") + kImageDir + wxT(".")); + return image; + } + return image; + }(); + // now slice up all the images + auto points = std::vector(mSpriteImages.size()); + std::iota(points.begin(), points.end(), 0); + std::transform(points.begin(), points.end(), mSpriteImages.begin(), [&image](auto i) { + return image.GetSubImage({ i*image_X + 0, 0, image_X, image_Y }); + }); } AnimationView::~AnimationView() @@ -65,79 +87,114 @@ void AnimationView::OnDraw(wxDC* dc) void AnimationView::OnDraw(wxDC& dc, CalChartConfiguration const& config) { + if (!mAnimation) { + // no animation, our job is done. + return; + } dc.SetPen(config.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second); DrawMode(dc, config, mView->GetShowMode(), ShowMode_kAnimation); + auto useSprites = config.Get_UseSprites(); + if (useSprites) { + return OnDrawSprites(dc, config); + } + return OnDrawDots(dc, config); +} + +void AnimationView::OnDrawDots(wxDC& dc, CalChartConfiguration const& config) +{ auto checkForCollision = mDrawCollisionWarning; - if (mAnimation) { - for (auto i = 0; i < mView->GetNumPoints(); ++i) { - auto info = mAnimation->GetAnimateInfo(i); - - if (checkForCollision && info.mCollision) { - if (info.mCollision == CalChart::Coord::COLLISION_WARNING) { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION_WARNING); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } else if (info.mCollision == CalChart::Coord::COLLISION_INTERSECT) { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } - } else if (mView->IsSelected(i)) { - switch (info.mDirection) { - case CalChart::ANIMDIR_SW: - case CalChart::ANIMDIR_W: - case CalChart::ANIMDIR_NW: { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_BACK); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } break; - case CalChart::ANIMDIR_SE: - case CalChart::ANIMDIR_E: - case CalChart::ANIMDIR_NE: { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_FRONT); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } break; - default: { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_SIDE); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } - } - } else { - switch (info.mDirection) { - case CalChart::ANIMDIR_SW: - case CalChart::ANIMDIR_W: - case CalChart::ANIMDIR_NW: { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_BACK); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } break; - case CalChart::ANIMDIR_SE: - case CalChart::ANIMDIR_E: - case CalChart::ANIMDIR_NE: { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_FRONT); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } break; - default: { - auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_SIDE); - dc.SetBrush(brushAndPen.first); - dc.SetPen(brushAndPen.second); - } - } + for (auto info : mAnimation->GetAllAnimateInfo()) { + if (checkForCollision && info.mCollision) { + if (info.mCollision == CalChart::Coord::COLLISION_WARNING) { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION_WARNING); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } else if (info.mCollision == CalChart::Coord::COLLISION_INTERSECT) { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } + } else if (mView->IsSelected(info.index)) { + switch (info.mDirection) { + case CalChart::ANIMDIR_SW: + case CalChart::ANIMDIR_W: + case CalChart::ANIMDIR_NW: { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_BACK); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } break; + case CalChart::ANIMDIR_SE: + case CalChart::ANIMDIR_E: + case CalChart::ANIMDIR_NE: { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_FRONT); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } break; + default: { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_SIDE); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } } - auto position = info.mPosition; - auto x = position.x + mView->GetShowMode().Offset().x; - auto y = position.y + mView->GetShowMode().Offset().y; - auto drawPosition = fDIP(wxPoint(x, y)); - auto rectangleSize = fDIP(wxSize(Int2CoordUnits(1), Int2CoordUnits(1))); + } else { + switch (info.mDirection) { + case CalChart::ANIMDIR_SW: + case CalChart::ANIMDIR_W: + case CalChart::ANIMDIR_NW: { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_BACK); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } break; + case CalChart::ANIMDIR_SE: + case CalChart::ANIMDIR_E: + case CalChart::ANIMDIR_NE: { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_FRONT); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } break; + default: { + auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_SIDE); + dc.SetBrush(brushAndPen.first); + dc.SetPen(brushAndPen.second); + } + } + } + auto position = info.mPosition; + auto x = position.x + mView->GetShowMode().Offset().x; + auto y = position.y + mView->GetShowMode().Offset().y; + auto drawPosition = fDIP(wxPoint(x, y)); + auto rectangleSize = fDIP(wxSize(Int2CoordUnits(1), Int2CoordUnits(1))); + + dc.DrawRectangle(drawPosition - rectangleSize / 2, rectangleSize); + } +} - dc.DrawRectangle(drawPosition - rectangleSize / 2, rectangleSize); +void AnimationView::OnDrawSprites(wxDC& dc, CalChartConfiguration const& config) +{ + auto scale = config.Get_SpriteBitmapScale(); + constexpr auto comp_X = 0.5; + auto comp_Y = config.Get_SpriteBitmapOffsetY(); + + for (auto info : mAnimation->GetAllAnimateInfo()) { + auto image_offset = !GetAnimationFrame()->TimerOn() ? 0 : OnBeat() ? 1 : 2; + auto image_index = static_cast(info.mDirection) + image_offset * 8; + auto image = mSpriteImages[image_index]; + image = image.Scale(image.GetWidth()*scale, image.GetHeight()*scale); + if (mView->IsSelected(info.index)) { + image = image.ConvertToGreyscale(); } + + auto position = info.mPosition; + auto x = position.x + mView->GetShowMode().Offset().x; + auto y = position.y + mView->GetShowMode().Offset().y; + auto drawPosition = fDIP(wxPoint(x, y)); + auto rectangleSize = fDIP(wxSize(image.GetWidth()*comp_X , image.GetHeight()*comp_Y)); + + dc.DrawBitmap (image, drawPosition - rectangleSize); } } + void AnimationView::OnUpdate(wxView* sender, wxObject* hint) { super::OnUpdate(sender, hint); diff --git a/src/AnimationView.h b/src/AnimationView.h index 12934372..de85335b 100644 --- a/src/AnimationView.h +++ b/src/AnimationView.h @@ -23,6 +23,7 @@ #include "draw_utils.h" #include +#include #include class AnimationPanel; @@ -45,6 +46,8 @@ class AnimationView : public wxView { void OnDraw(wxDC* dc) override; void OnDraw(wxDC& dc, CalChartConfiguration const& config); + void OnDrawDots(wxDC& dc, CalChartConfiguration const& config); + void OnDrawSprites(wxDC& dc, CalChartConfiguration const& config); void OnUpdate(wxView* sender, wxObject* hint = (wxObject*)nullptr) override; void PrevBeat(); @@ -90,4 +93,13 @@ class AnimationView : public wxView { std::unique_ptr mAnimation; bool mDrawCollisionWarning = true; bool mPlayCollisionWarning = false; + + enum ImageBeat { + Standing, + Right, + Left, + Size + }; + + std::array mSpriteImages; }; diff --git a/src/CalChartFrame.cpp b/src/CalChartFrame.cpp index 9bcd433e..1f370766 100644 --- a/src/CalChartFrame.cpp +++ b/src/CalChartFrame.cpp @@ -40,7 +40,7 @@ #include "cc_coord.h" #include "cc_fileformat.h" #include "cc_point.h" -#include "cc_preferences_ui.h" +#include "CalChartPreferences.h" #include "cc_sheet.h" #include "cc_show.h" #include "ccvers.h" diff --git a/src/CalChartPreferences.cpp b/src/CalChartPreferences.cpp new file mode 100644 index 00000000..6ad34e38 --- /dev/null +++ b/src/CalChartPreferences.cpp @@ -0,0 +1,111 @@ +/* + * CalChartPreferences.cpp + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "CalChartPreferences.h" +#include "PreferencesContCellSetup.h" +#include "PreferencesDrawingSetup.h" +#include "PreferencesGeneralSetup.h" +#include "PreferencesPSPrintingSetup.h" +#include "PreferencesShowModeSetup.h" +#include "PreferencesUtils.h" + +// how the preferences work: +// 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 +// +// organized into pages. Each page is responsible for reading out +// on TransferDataToWindow, caching the values locally, and +// setting them to the system on TransferDataFromWindow + +//////////////// + +BEGIN_EVENT_TABLE(CalChartPreferences, wxDialog) +EVT_BUTTON(wxID_RESET, CalChartPreferences::OnCmdResetAll) +END_EVENT_TABLE() + +IMPLEMENT_CLASS(CalChartPreferences, wxDialog) + +CalChartPreferences::CalChartPreferences(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style) + : wxDialog(parent, id, caption, pos, size, style) + , mConfig(CalChartConfiguration::GetGlobalConfig()) +{ + auto topsizer = new wxBoxSizer(wxVERTICAL); + SetSizer(topsizer); + + mNotebook = new wxNotebook(this, wxID_ANY); + topsizer->Add(mNotebook, BasicSizerFlags()); + + mNotebook->AddPage(new GeneralSetup(mConfig, mNotebook, wxID_ANY), wxT("General")); + mNotebook->AddPage(new ContCellSetup(mConfig, mNotebook, wxID_ANY), wxT("Continuity")); + mNotebook->AddPage(new DrawingSetup(mConfig, mNotebook, wxID_ANY), wxT("Drawing")); + mNotebook->AddPage(new PSPrintingSetUp(mConfig, mNotebook, wxID_ANY), wxT("PS Printing")); + mNotebook->AddPage(new ShowModeSetup(mConfig, mNotebook, wxID_ANY), wxT("Show Mode Setup")); + + // the buttons on the bottom + wxBoxSizer* okCancelBox = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(okCancelBox, BasicSizerFlags()); + + okCancelBox->Add(new wxButton(this, wxID_APPLY), BasicSizerFlags()); + okCancelBox->Add(new wxButton(this, wxID_RESET, wxT("&Reset All")), BasicSizerFlags()); + okCancelBox->Add(new wxButton(this, wxID_OK), BasicSizerFlags()); + okCancelBox->Add(new wxButton(this, wxID_CANCEL), BasicSizerFlags()); + + // This fits the dalog to the minimum size dictated by the sizers + GetSizer()->Fit(this); + // This ensures that the dialog cannot be smaller than the minimum size + GetSizer()->SetSizeHints(this); + Center(); +} + +bool CalChartPreferences::TransferDataToWindow() { return true; } + +bool CalChartPreferences::TransferDataFromWindow() +{ + // transfer everything to the config... + size_t pages = mNotebook->GetPageCount(); + for (size_t i = 0; i < pages; ++i) { + PreferencePage* page = static_cast(mNotebook->GetPage(i)); + page->TransferDataFromWindow(); + } + CalChartConfiguration::AssignConfig(mConfig); + return true; +} + +void CalChartPreferences::OnCmdResetAll(wxCommandEvent&) +{ + // transfer everything to the config... + size_t pages = mNotebook->GetPageCount(); + for (size_t i = 0; i < pages; ++i) { + PreferencePage* page = static_cast(mNotebook->GetPage(i)); + page->ClearValuesToDefault(); + } + CalChartConfiguration::AssignConfig(mConfig); +} diff --git a/src/cc_preferences_ui.h b/src/CalChartPreferences.h similarity index 100% rename from src/cc_preferences_ui.h rename to src/CalChartPreferences.h diff --git a/src/ColorSetupCanvas.cpp b/src/ColorSetupCanvas.cpp index 9e3309ce..1a09c140 100644 --- a/src/ColorSetupCanvas.cpp +++ b/src/ColorSetupCanvas.cpp @@ -1,5 +1,5 @@ /* - * cc_preferences_ui.cpp + * CalChartPreferences.cpp * Dialox box for preferences */ diff --git a/src/ColorSetupDialog.cpp b/src/ColorSetupDialog.cpp index 96176fe4..e9623a7c 100644 --- a/src/ColorSetupDialog.cpp +++ b/src/ColorSetupDialog.cpp @@ -1,5 +1,5 @@ /* - * cc_preferences_ui.cpp + * ColorSetupDialog.cpp * Dialox box for preferences */ @@ -56,8 +56,6 @@ using namespace CalChart; // out when the user presses apply. // convience sizers to change the view behavior in all at once. -static auto sBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Center().Proportion(0); -static auto sLeftBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Left().Proportion(0); static auto sRightBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Right().Proportion(0); static auto sExpandSizerFlags = wxSizerFlags().Border(wxALL, 2).Center().Proportion(0); @@ -124,12 +122,12 @@ void ColorSetupDialog::CreateControls() wxStaticBoxSizer* boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Palette")), wxHORIZONTAL); topsizer->Add(boxsizer); - boxsizer->Add(new wxBitmapButton(this, BUTTON_EDIT_PALETTE_COLOR, CreateTempBitmap(mColorPaletteColors.at(mActiveColorPalette))), sBasicSizerFlags); + boxsizer->Add(new wxBitmapButton(this, BUTTON_EDIT_PALETTE_COLOR, CreateTempBitmap(mColorPaletteColors.at(mActiveColorPalette))), BasicSizerFlags()); - boxsizer->Add(new wxTextCtrl(this, PALETTE_NAME, mColorPaletteNames.at(mActiveColorPalette), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER), sBasicSizerFlags); + boxsizer->Add(new wxTextCtrl(this, PALETTE_NAME, mColorPaletteNames.at(mActiveColorPalette), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER), BasicSizerFlags()); - boxsizer->Add(new wxButton(this, BUTTON_EXPORT, wxT("&Export...")), sBasicSizerFlags); - boxsizer->Add(new wxButton(this, BUTTON_IMPORT, wxT("&Import...")), sBasicSizerFlags); + boxsizer->Add(new wxButton(this, BUTTON_EXPORT, wxT("&Export...")), BasicSizerFlags()); + boxsizer->Add(new wxButton(this, BUTTON_IMPORT, wxT("&Import...")), BasicSizerFlags()); boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); topsizer->Add(boxsizer); @@ -137,7 +135,7 @@ void ColorSetupDialog::CreateControls() auto 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); + horizontalsizer->Add(nameBox, BasicSizerFlags()); for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i) + 1)) { CreateAndSetItemBitmap(nameBox, i, mConfig.Get_CalChartBrushAndPen(i).first); @@ -146,14 +144,14 @@ void ColorSetupDialog::CreateControls() spin = new wxSpinCtrl(this, SPIN_WIDTH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); spin->SetValue(mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); - horizontalsizer->Add(spin, sBasicSizerFlags); - boxsizer->Add(horizontalsizer, sLeftBasicSizerFlags); + horizontalsizer->Add(spin, BasicSizerFlags()); + boxsizer->Add(horizontalsizer, LeftBasicSizerFlags()); 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); + horizontalsizer->Add(new wxButton(this, BUTTON_SELECT, wxT("&Change Color")), BasicSizerFlags()); + horizontalsizer->Add(new wxButton(this, BUTTON_RESTORE, wxT("&Reset Color")), BasicSizerFlags()); + boxsizer->Add(horizontalsizer, BasicSizerFlags()); auto prefCanvas = new ColorSetupCanvas(mConfig, this); // set scroll rate 1 to 1, so we can have even scrolling of whole field @@ -162,11 +160,11 @@ void ColorSetupDialog::CreateControls() // the buttons on the bottom wxBoxSizer* okCancelBox = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(okCancelBox, sBasicSizerFlags); + topsizer->Add(okCancelBox, BasicSizerFlags()); - okCancelBox->Add(new wxButton(this, wxID_RESET, wxT("&Reset")), sBasicSizerFlags); - okCancelBox->Add(new wxButton(this, wxID_OK), sBasicSizerFlags); - okCancelBox->Add(new wxButton(this, wxID_CANCEL), sBasicSizerFlags); + okCancelBox->Add(new wxButton(this, wxID_RESET, wxT("&Reset")), BasicSizerFlags()); + okCancelBox->Add(new wxButton(this, wxID_OK), BasicSizerFlags()); + okCancelBox->Add(new wxButton(this, wxID_CANCEL), BasicSizerFlags()); TransferDataToWindow(); } diff --git a/src/ContinuityComposerDialog.cpp b/src/ContinuityComposerDialog.cpp index a5f764f1..c22ae5f4 100755 --- a/src/ContinuityComposerDialog.cpp +++ b/src/ContinuityComposerDialog.cpp @@ -93,8 +93,6 @@ class ContinuityComposerPanel : public wxPanel { IMPLEMENT_CLASS(ContinuityComposerPanel, wxPanel) -static const auto sBasicSizerFlags = wxSizerFlags{}.Border(wxALL, 2).Center().Proportion(0); -static const auto sLeftBasicSizerFlags = wxSizerFlags{}.Border(wxALL, 2).Left().Proportion(0); static const auto sRightBasicSizerFlags = wxSizerFlags{}.Border(wxALL, 2).Right().Proportion(0); static const auto sExpandSizerFlags = wxSizerFlags{}.Border(wxALL, 2).Center().Proportion(0); @@ -612,9 +610,9 @@ ContinuityComposerDialog::ContinuityComposerDialog(std::unique_ptrAdd(button_sizer, sRightBasicSizerFlags); - button_sizer->Add(new wxButton(this, wxID_CANCEL, wxT("&Cancel")), sBasicSizerFlags); + button_sizer->Add(new wxButton(this, wxID_CANCEL, wxT("&Cancel")), BasicSizerFlags()); mCloseButton = new wxButton(this, wxID_OK, wxT("&Done")); - button_sizer->Add(mCloseButton, sBasicSizerFlags); + button_sizer->Add(mCloseButton, BasicSizerFlags()); mCloseButton->SetDefault(); mCloseButton->Enable(mPanel->Validate()); mPanel->SetOnUpdateIsValid([this](bool enable) { diff --git a/src/PreferencesContCellSetup.cpp b/src/PreferencesContCellSetup.cpp new file mode 100644 index 00000000..69f5cf5a --- /dev/null +++ b/src/PreferencesContCellSetup.cpp @@ -0,0 +1,254 @@ +/* + * CalChartPreferences.cpp + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "PreferencesContCellSetup.h" +#include "PreferencesUtils.h" +#include "ContinuityBrowserPanel.h" + +#include +#include +#include + + +enum { + BUTTON_SELECT = 1000, + BUTTON_RESTORE, + SPIN_WIDTH, + NEW_COLOR_CHOICE, + DOTRATIO, + NUMRATIO, + PLINERATIO, + SLINERATIO, + SPRITESCALE, + SPRITEHEIGHT, + BUTTON_EDIT_PALETTE_COLOR, + BUTTON_EDIT_PALETTE_NAME, + NEW_COLOR_PALETTE, +}; + + +enum { + CHECK_LongForm, + SPIN_Font_Size, + SPIN_Rouding, + SPIN_Text_Padding, + SPIN_Box_Padding, +}; + +BEGIN_EVENT_TABLE(ContCellSetup, PreferencePage) +EVT_CHECKBOX(CHECK_LongForm, ContCellSetup::OnCmdLongForm) +EVT_SPINCTRL(SPIN_Font_Size, ContCellSetup::OnCmdFontSize) +EVT_SPINCTRL(SPIN_Rouding, ContCellSetup::OnCmdRounding) +EVT_SPINCTRL(SPIN_Text_Padding, ContCellSetup::OnCmdTextPadding) +EVT_SPINCTRL(SPIN_Box_Padding, ContCellSetup::OnCmdBoxPadding) +EVT_BUTTON(BUTTON_SELECT, ContCellSetup::OnCmdSelectColors) +EVT_BUTTON(BUTTON_RESTORE, ContCellSetup::OnCmdResetColors) +EVT_COMBOBOX(NEW_COLOR_CHOICE, ContCellSetup::OnCmdChooseNewColor) +END_EVENT_TABLE() + +IMPLEMENT_CLASS(ContCellSetup, PreferencePage) + +template +static auto do_cloning(T const& cont) +{ + auto copied_cont = std::vector>{}; + for (auto&& i : cont.GetParsedContinuity()) { + copied_cont.emplace_back(i->clone()); + } + return copied_cont; +} + +ContCellSetup::ContCellSetup(CalChartConfiguration& config, wxWindow* parent, wxWindowID id, wxString const& caption, wxPoint const& pos, wxSize const& size, long style) + : PreferencePage(config) +{ + Init(); + Create(parent, id, caption, pos, size, style); +} + +void ContCellSetup::CreateControls() +{ + auto topsizer = new wxBoxSizer(wxVERTICAL); + SetSizer(topsizer); + + auto boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); + topsizer->Add(boxsizer); + + auto horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + boxsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + nameBox = new wxBitmapComboBox(this, NEW_COLOR_CHOICE, mConfig.GetContCellColorNames().at(0), wxDefaultPosition, wxDefaultSize, COLOR_CONTCELLS_NUM, mConfig.GetContCellColorNames().data(), wxCB_READONLY | wxCB_DROPDOWN); + horizontalsizer->Add(nameBox, BasicSizerFlags()); + + for (auto i = 0; i < COLOR_CONTCELLS_NUM; ++i) { + CreateAndSetItemBitmap(nameBox, i, mConfig.Get_ContCellBrushAndPen(static_cast(i)).first); + } + nameBox->SetSelection(0); + + horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + boxsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + horizontalsizer->Add(new wxButton(this, BUTTON_SELECT, wxT("&Change Color")), BasicSizerFlags()); + horizontalsizer->Add(new wxButton(this, BUTTON_RESTORE, wxT("&Reset Color")), BasicSizerFlags()); + + horizontalsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Cont Cell settings")), wxHORIZONTAL); + topsizer->Add(horizontalsizer); + + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Long form")), wxVERTICAL); + horizontalsizer->Add(boxsizer, BasicSizerFlags()); + auto checkbox = new wxCheckBox(this, CHECK_LongForm, wxT("Long form")); + checkbox->SetValue(mConfig.Get_ContCellLongForm()); + boxsizer->Add(checkbox, BasicSizerFlags()); + + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Font Size")), wxVERTICAL); + horizontalsizer->Add(boxsizer, BasicSizerFlags()); + auto spin = new wxSpinCtrl(this, SPIN_Font_Size, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 30, mConfig.Get_ContCellFontSize()); + boxsizer->Add(spin, BasicSizerFlags()); + + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Rounding")), wxVERTICAL); + horizontalsizer->Add(boxsizer, BasicSizerFlags()); + spin = new wxSpinCtrl(this, SPIN_Rouding, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mConfig.Get_ContCellRounding()); + boxsizer->Add(spin, BasicSizerFlags()); + + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Text Padding")), wxVERTICAL); + horizontalsizer->Add(boxsizer, BasicSizerFlags()); + spin = new wxSpinCtrl(this, SPIN_Text_Padding, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mConfig.Get_ContCellTextPadding()); + boxsizer->Add(spin, BasicSizerFlags()); + + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Box Padding")), wxVERTICAL); + horizontalsizer->Add(boxsizer, BasicSizerFlags()); + spin = new wxSpinCtrl(this, SPIN_Box_Padding, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mConfig.Get_ContCellBoxPadding()); + boxsizer->Add(spin, BasicSizerFlags()); + + auto canvas = new ContinuityBrowserPanel(SYMBOL_PLAIN, mConfig, this); + topsizer->Add(canvas, 1, wxEXPAND); + auto basic_cont = CalChart::Continuity{ "ewns np\nX = distfrom(sp r2)\nmt (24-X)w\nmarch gv dist(np) dir(np) w\nmtrm e" }; + auto clonedOut = do_cloning(basic_cont); + clonedOut.emplace_back(std::make_unique(std::make_unique(), std::make_unique())); + canvas->DoSetContinuity(CalChart::Continuity{ std::move(clonedOut) }); + + TransferDataToWindow(); +} + +void ContCellSetup::Init() +{ + // first read out the defaults: + for (auto i = 0; i < COLOR_CONTCELLS_NUM; ++i) { + auto brushAndPen = mConfig.Get_ContCellBrushAndPen(static_cast(i)); + mContCellBrushes[i] = brushAndPen.first; + } +} + +bool ContCellSetup::TransferDataToWindow() +{ + return true; +} + +bool ContCellSetup::TransferDataFromWindow() +{ + return true; +} + +bool ContCellSetup::ClearValuesToDefault() +{ + mConfig.Clear_ContCellLongForm(); + mConfig.Clear_ContCellFontSize(); + mConfig.Clear_ContCellRounding(); + mConfig.Clear_ContCellTextPadding(); + mConfig.Clear_ContCellBoxPadding(); + + for (ContCellColors i = COLOR_CONTCELLS_PROC; i < COLOR_CONTCELLS_NUM; i = static_cast(static_cast(i) + 1)) { + SetColor(i, mConfig.GetContCellDefaultColors()[i]); + mConfig.Clear_ContCellConfigColor(i); + } + Init(); + TransferDataToWindow(); + return true; +} + +void ContCellSetup::OnCmdLongForm(wxCommandEvent& e) +{ + mConfig.Set_ContCellLongForm(e.IsChecked()); + Refresh(); +} + +void ContCellSetup::OnCmdFontSize(wxSpinEvent& e) +{ + mConfig.Set_ContCellFontSize(e.GetValue()); + Refresh(); +} + +void ContCellSetup::OnCmdRounding(wxSpinEvent& e) +{ + mConfig.Set_ContCellRounding(e.GetValue()); + Refresh(); +} + +void ContCellSetup::OnCmdTextPadding(wxSpinEvent& e) +{ + mConfig.Set_ContCellTextPadding(e.GetValue()); + Refresh(); +} + +void ContCellSetup::OnCmdBoxPadding(wxSpinEvent& e) +{ + mConfig.Set_ContCellBoxPadding(e.GetValue()); + Refresh(); +} + +void ContCellSetup::SetColor(int selection, const wxColour& color) +{ + auto pen = *wxThePenList->FindOrCreatePen(color, 1, wxPENSTYLE_SOLID); + mContCellBrushes[selection] = *wxTheBrushList->FindOrCreateBrush(color, wxBRUSHSTYLE_SOLID); + + mConfig.Set_ContCellBrushAndPen(static_cast(selection), mContCellBrushes[selection], pen); + + // update the namebox list + CreateAndSetItemBitmap(nameBox, selection, mContCellBrushes[selection]); + Refresh(); +} + +void ContCellSetup::OnCmdSelectColors(wxCommandEvent&) +{ + auto selection = nameBox->GetSelection(); + auto data = wxColourData{}; + data.SetChooseFull(true); + data.SetColour(mContCellBrushes[selection].GetColour()); + auto dialog = wxColourDialog(this, &data); + if (dialog.ShowModal() == wxID_OK) { + auto retdata = dialog.GetColourData(); + auto c = retdata.GetColour(); + SetColor(selection, c); + } + Refresh(); +} + +void ContCellSetup::OnCmdResetColors(wxCommandEvent&) +{ + auto selection = nameBox->GetSelection(); + SetColor(selection, mConfig.GetContCellDefaultColors()[selection]); + mConfig.Clear_ContCellConfigColor(static_cast(selection)); + Refresh(); +} + +void ContCellSetup::OnCmdChooseNewColor(wxCommandEvent&) +{ + Refresh(); +} + diff --git a/src/PreferencesContCellSetup.h b/src/PreferencesContCellSetup.h new file mode 100644 index 00000000..c47e717a --- /dev/null +++ b/src/PreferencesContCellSetup.h @@ -0,0 +1,64 @@ +#pragma once +/* + * cc_preferences.h + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "PreferencesUtils.h" + +/// Continuity Cell setup +/// Handles configurations parameters of Continuity input system +/// + +class wxBitmapComboBox; + +class ContCellSetup : public PreferencePage { + DECLARE_CLASS(ContCellSetup) + DECLARE_EVENT_TABLE() + +public: + ContCellSetup(CalChartConfiguration& config, wxWindow* parent, wxWindowID id = wxID_ANY, wxString const& caption = wxT("ContCell Setup"), wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU); + virtual ~ContCellSetup() = default; + + virtual void Init() override; + virtual void CreateControls() override; + + // use these to get and set default values + virtual bool TransferDataToWindow() override; + virtual bool TransferDataFromWindow() override; + virtual bool ClearValuesToDefault() override; + +private: + void OnCmdLongForm(wxCommandEvent&); + void OnCmdFontSize(wxSpinEvent&); + void OnCmdRounding(wxSpinEvent&); + void OnCmdTextPadding(wxSpinEvent&); + void OnCmdBoxPadding(wxSpinEvent&); + void OnCmdSelectWidth(wxSpinEvent&); + + void OnCmdSelectColors(wxCommandEvent&); + void OnCmdChooseNewColor(wxCommandEvent&); + void OnCmdResetColors(wxCommandEvent&); + void SetColor(int selection, const wxColour& color); + + // we can set up the Font, colors, size. + wxBitmapComboBox* nameBox; + wxBrush mContCellBrushes[COLOR_CONTCELLS_NUM]; +}; diff --git a/src/PreferencesDrawingSetup.cpp b/src/PreferencesDrawingSetup.cpp new file mode 100644 index 00000000..9b25583b --- /dev/null +++ b/src/PreferencesDrawingSetup.cpp @@ -0,0 +1,371 @@ +/* + * CalChartPreferences.cpp + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "PreferencesDrawingSetup.h" +#include "PreferencesUtils.h" +#include "CalChartDoc.h" +#include "CalChartSizes.h" +#include "ColorSetupCanvas.h" +#include "ContinuityBrowserPanel.h" +#include "ContinuityComposerDialog.h" +#include "cc_drawcommand.h" +#include "cc_shapes.h" +#include "cc_sheet.h" +#include "confgr.h" +#include "cont.h" +#include "draw.h" +#include "mode_dialog.h" +#include "mode_dialog_canvas.h" +#include "modes.h" + +#include +#include +#include +#include +#include +#include + +using namespace CalChart; + +enum { + BUTTON_SELECT = 1000, + BUTTON_RESTORE, + SPIN_WIDTH, + NEW_COLOR_CHOICE, + DOTRATIO, + NUMRATIO, + PLINERATIO, + SLINERATIO, + SPRITESCALE, + SPRITEHEIGHT, + BUTTON_EDIT_PALETTE_COLOR, + BUTTON_EDIT_PALETTE_NAME, + NEW_COLOR_PALETTE, +}; + +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_COMBOBOX(NEW_COLOR_PALETTE, DrawingSetup::OnCmdChooseNewPalette) +EVT_TEXT_ENTER(DOTRATIO, DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(NUMRATIO, DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(PLINERATIO, DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(SLINERATIO, DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(SPRITESCALE, DrawingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(SPRITEHEIGHT, DrawingSetup::OnCmdTextChanged) +EVT_BUTTON(BUTTON_EDIT_PALETTE_COLOR, DrawingSetup::OnCmdChangePaletteColor) +EVT_BUTTON(BUTTON_EDIT_PALETTE_NAME, DrawingSetup::OnCmdChangePaletteName) +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("Palette Selector")), wxVERTICAL); + topsizer->Add(boxsizer); + + mPaletteNameBox = new wxBitmapComboBox(this, NEW_COLOR_PALETTE, mColorPaletteNames.at(0), wxDefaultPosition, wxSize(200, -1), kNumberPalettes, mColorPaletteNames.data(), wxCB_READONLY | wxCB_DROPDOWN); + boxsizer->Add(mPaletteNameBox, LeftBasicSizerFlags()); + + for (auto i = 0; i < kNumberPalettes; ++i) { + CreateAndSetItemBitmap(mPaletteNameBox, i, mColorPaletteColors.at(i)); + } + mPaletteNameBox->SetSelection(mActiveColorPalette); + + auto horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + boxsizer->Add(horizontalsizer, BasicSizerFlags()); + + horizontalsizer->Add(new wxButton(this, BUTTON_EDIT_PALETTE_COLOR, wxT("&Edit Color")), BasicSizerFlags()); + horizontalsizer->Add(new wxButton(this, BUTTON_EDIT_PALETTE_NAME, wxT("&Edit Name")), BasicSizerFlags()); + + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); + topsizer->Add(boxsizer); + + 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, BasicSizerFlags()); + + for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i) + 1)) { + CreateAndSetItemBitmap(nameBox, i, mConfig.Get_CalChartBrushAndPen(i).first); + } + nameBox->SetSelection(0); + + spin = new wxSpinCtrl(this, SPIN_WIDTH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); + spin->SetValue(mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); + horizontalsizer->Add(spin, BasicSizerFlags()); + boxsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + + horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + + horizontalsizer->Add(new wxButton(this, BUTTON_SELECT, wxT("&Change Color")), BasicSizerFlags()); + horizontalsizer->Add(new wxButton(this, BUTTON_RESTORE, wxT("&Reset Color")), BasicSizerFlags()); + + boxsizer->Add(horizontalsizer, BasicSizerFlags()); + + boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("ratios")), wxVERTICAL); + topsizer->Add(boxsizer); + + horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + boxsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + + 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); + + AddTextboxWithCaption(this, horizontalsizer, SPRITESCALE, wxT("Sprite Scale:"), wxTE_PROCESS_ENTER); + AddTextboxWithCaption(this, horizontalsizer, SPRITEHEIGHT, wxT("Sprite Height:"), wxTE_PROCESS_ENTER); + + auto prefCanvas = new ColorSetupCanvas(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 DrawingSetup::Init() +{ + // first read out the defaults: + mActiveColorPalette = mConfig.GetActiveColorPalette(); + mColorPaletteNames = GetColorPaletteNames(mConfig); + mColorPaletteColors = GetColorPaletteColors(mConfig); + + for (auto palette = 0; palette < kNumberPalettes; ++palette) { + for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i) + 1)) { + auto brushAndPen = mConfig.Get_CalChartBrushAndPen(palette, i); + mCalChartPens[palette][i] = brushAndPen.second; + mCalChartBrushes[palette][i] = brushAndPen.first; + } + } + + mDrawingValues[0] = mConfig.Get_DotRatio(); + mDrawingValues[1] = mConfig.Get_NumRatio(); + mDrawingValues[2] = mConfig.Get_PLineRatio(); + mDrawingValues[3] = mConfig.Get_SLineRatio(); + mDrawingValues[4] = mConfig.Get_SpriteBitmapScale(); + mDrawingValues[5] = mConfig.Get_SpriteBitmapOffsetY(); +} + +bool DrawingSetup::TransferDataToWindow() +{ + for (auto i = 0; i < kNumberPalettes; ++i) { + CreateAndSetItemBitmap(mPaletteNameBox, i, mColorPaletteColors.at(i)); + } + for (auto i = 0; i < kNumberPalettes; ++i) { + mPaletteNameBox->SetString(i, mColorPaletteNames.at(i)); + } + mPaletteNameBox->SetSelection(mActiveColorPalette); + + for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; + i = static_cast(static_cast(i) + 1)) { + CreateAndSetItemBitmap(nameBox, i, mCalChartBrushes[mActiveColorPalette][i]); + } + spin->SetValue(mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); + + wxString buf; + wxTextCtrl* text = (wxTextCtrl*)FindWindow(DOTRATIO); + buf.Printf(wxT("%.2f"), mDrawingValues[0]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(NUMRATIO); + buf.Printf(wxT("%.2f"), mDrawingValues[1]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(PLINERATIO); + buf.Printf(wxT("%.2f"), mDrawingValues[2]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(SLINERATIO); + buf.Printf(wxT("%.2f"), mDrawingValues[3]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(SPRITESCALE); + buf.Printf(wxT("%.2f"), mDrawingValues[4]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(SPRITEHEIGHT); + buf.Printf(wxT("%.2f"), mDrawingValues[5]); + text->SetValue(buf); + + return true; +} + +bool DrawingSetup::TransferDataFromWindow() +{ + // Data is already transferred when we update the controls, so nothing to do here. + mConfig.SetActiveColorPalette(mActiveColorPalette); + return true; +} + +bool DrawingSetup::ClearValuesToDefault() +{ + mConfig.ClearActiveColorPalette(); + for (auto i = 0; i < kNumberPalettes; ++i) { + mConfig.ClearColorPaletteColor(i); + mConfig.ClearColorPaletteName(i); + } + + for (auto palette = 0; palette < kNumberPalettes; ++palette) { + for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i) + 1)) { + mConfig.Clear_CalChartConfigColor(palette, i); + } + } + Init(); + TransferDataToWindow(); + return true; +} + +// when the palette changes +void DrawingSetup::SetColor(int selection, int width, const wxColour& color) +{ + mCalChartPens[mActiveColorPalette][selection] = *wxThePenList->FindOrCreatePen(color, width, wxPENSTYLE_SOLID); + mCalChartBrushes[mActiveColorPalette][selection] = *wxTheBrushList->FindOrCreateBrush(color, wxBRUSHSTYLE_SOLID); + + mConfig.Set_CalChartBrushAndPen(static_cast(selection), mCalChartBrushes[mActiveColorPalette][selection], mCalChartPens[mActiveColorPalette][selection]); + + // update the namebox list + CreateAndSetItemBitmap(nameBox, selection, mCalChartBrushes[mActiveColorPalette][selection]); + Refresh(); +} + +void DrawingSetup::SetPaletteColor(int selection, wxColour const& color) +{ + mColorPaletteColors.at(selection) = *wxTheBrushList->FindOrCreateBrush(color, wxBRUSHSTYLE_SOLID); + + // this is needed so we draw things out on the page correctly. + mConfig.SetColorPaletteColor(selection, mColorPaletteColors.at(selection)); + + CreateAndSetItemBitmap(mPaletteNameBox, selection, mColorPaletteColors.at(selection)); + Refresh(); +} + +void DrawingSetup::SetPaletteName(int selection, wxString const& name) +{ + mColorPaletteNames.at(selection) = name; + + // this is needed so we draw things out on the page correctly. + mConfig.SetColorPaletteName(selection, name); + + mPaletteNameBox->SetString(selection, mColorPaletteNames.at(selection)); + Refresh(); +} + +void DrawingSetup::OnCmdSelectColors(wxCommandEvent&) +{ + int selection = nameBox->GetSelection(); + wxColourData data; + data.SetChooseFull(true); + data.SetColour(mCalChartBrushes[mActiveColorPalette][selection].GetColour()); + wxColourDialog dialog(this, &data); + if (dialog.ShowModal() == wxID_OK) { + wxColourData retdata = dialog.GetColourData(); + wxColour c = retdata.GetColour(); + SetColor(selection, mCalChartPens[mActiveColorPalette][selection].GetWidth(), c); + } + Refresh(); +} + +void DrawingSetup::OnCmdChangePaletteColor(wxCommandEvent&) +{ + int selection = mPaletteNameBox->GetSelection(); + wxColourData data; + data.SetChooseFull(true); + data.SetColour(mColorPaletteColors.at(selection).GetColour()); + wxColourDialog dialog(this, &data); + if (dialog.ShowModal() == wxID_OK) { + wxColourData retdata = dialog.GetColourData(); + wxColour c = retdata.GetColour(); + SetPaletteColor(selection, c); + } + Refresh(); +} + +void DrawingSetup::OnCmdChangePaletteName(wxCommandEvent&) +{ + int selection = mPaletteNameBox->GetSelection(); + auto v = mPaletteNameBox->GetValue(); + wxTextEntryDialog dialog(this, wxT("Enter name for Palette"), wxT("Enter name for Palette"), v, wxOK | wxCANCEL); + if (dialog.ShowModal() == wxID_OK) { + SetPaletteName(selection, dialog.GetValue()); + } + Refresh(); +} + +void DrawingSetup::OnCmdSelectWidth(wxSpinEvent& e) +{ + int selection = nameBox->GetSelection(); + SetColor(selection, e.GetPosition(), mCalChartPens[mActiveColorPalette][selection].GetColour()); +} + +void DrawingSetup::OnCmdResetColors(wxCommandEvent&) +{ + int selection = nameBox->GetSelection(); + SetColor(selection, mConfig.GetDefaultPenWidth()[selection], + mConfig.GetDefaultColors()[selection]); + mConfig.Clear_CalChartConfigColor(static_cast(selection)); +} + +void DrawingSetup::OnCmdChooseNewColor(wxCommandEvent&) +{ + spin->SetValue(mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); +} + +void DrawingSetup::OnCmdChooseNewPalette(wxCommandEvent&) +{ + // we set the active palette, and now need to refresh everything + mActiveColorPalette = mPaletteNameBox->GetSelection(); + mConfig.SetActiveColorPalette(mActiveColorPalette); + TransferDataToWindow(); + Refresh(); +} + +void DrawingSetup::OnCmdTextChanged(wxCommandEvent& e) +{ + auto id = e.GetId(); + wxTextCtrl* text = (wxTextCtrl*)FindWindow(id); + double value; + if (text->GetValue().ToDouble(&value)) { + switch (id - DOTRATIO) { + case 0: + mConfig.Set_DotRatio(value); + break; + case 1: + mConfig.Set_NumRatio(value); + break; + case 2: + mConfig.Set_PLineRatio(value); + break; + case 3: + mConfig.Set_SLineRatio(value); + break; + case 4: + mConfig.Set_SpriteBitmapScale(value); + break; + case 5: + mConfig.Set_SpriteBitmapOffsetY(value); + break; + } + } + Refresh(); +} + diff --git a/src/PreferencesDrawingSetup.h b/src/PreferencesDrawingSetup.h new file mode 100644 index 00000000..50802641 --- /dev/null +++ b/src/PreferencesDrawingSetup.h @@ -0,0 +1,81 @@ +#pragma once +/* + * PreferencesDrawingSetup.h + * Dialox box for Drawing Setup part of preferences + */ + +/* + 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 . +*/ + +#include "PreferencesUtils.h" +#include +#include +#include +#include + +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 OnCmdChooseNewPalette(wxCommandEvent&); + void OnCmdTextChanged(wxCommandEvent&); + void OnCmdChangePaletteColor(wxCommandEvent&); + void OnCmdChangePaletteName(wxCommandEvent&); + + void SetColor(int selection, int width, const wxColour& color); + void SetPaletteColor(int selection, const wxColour& color); + void SetPaletteName(int selection, const wxString& name); + wxBitmapComboBox* nameBox; + wxBitmapComboBox* mPaletteNameBox; + wxSpinCtrl* spin; + + int mActiveColorPalette{}; + std::vector mColorPaletteNames; + std::vector mColorPaletteColors; + wxPen mCalChartPens[kNumberPalettes][COLOR_NUM]; + wxBrush mCalChartBrushes[kNumberPalettes][COLOR_NUM]; + + double mDrawingValues[6]; +}; diff --git a/src/PreferencesGeneralSetup.cpp b/src/PreferencesGeneralSetup.cpp new file mode 100644 index 00000000..4463f5e9 --- /dev/null +++ b/src/PreferencesGeneralSetup.cpp @@ -0,0 +1,117 @@ +/* + * CalChartPreferences.cpp + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "PreferencesGeneralSetup.h" +#include "PreferencesUtils.h" + +enum { + AUTOSAVE_INTERVAL = 1000, + BEEP_ON_COLLISIONS, + SCROLL_NATURAL, + SETSHEET_UNDO, + SELECTION_UNDO, +}; + +BEGIN_EVENT_TABLE(GeneralSetup, PreferencePage) +END_EVENT_TABLE() + +IMPLEMENT_CLASS(GeneralSetup, PreferencePage) + +GeneralSetup::GeneralSetup(CalChartConfiguration& config, wxWindow* parent, wxWindowID id, wxString const& caption, wxPoint const& pos, wxSize const& size, long style) + : PreferencePage(config) +{ + Init(); + Create(parent, id, caption, pos, size, style); +} + +void GeneralSetup::CreateControls() +{ + auto topsizer = new wxBoxSizer(wxVERTICAL); + SetSizer(topsizer); + + auto boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Autosave settings")), wxVERTICAL); + topsizer->Add(boxsizer); + + auto sizer1 = new wxBoxSizer(wxVERTICAL); + boxsizer->Add(sizer1, LeftBasicSizerFlags()); + + AddTextboxWithCaption(this, sizer1, AUTOSAVE_INTERVAL, wxT("Autosave Interval")); + AddCheckboxWithCaption(this, sizer1, BEEP_ON_COLLISIONS, wxT("Beep on animation collisions")); + AddCheckboxWithCaption(this, sizer1, SCROLL_NATURAL, wxT("Scroll Direction: Natural")); + AddCheckboxWithCaption(this, sizer1, SETSHEET_UNDO, wxT("Set Sheet is undo-able")); + AddCheckboxWithCaption(this, sizer1, SELECTION_UNDO, wxT("Point selection is undo-able")); + + TransferDataToWindow(); +} + +void GeneralSetup::Init() +{ + mAutoSave_Interval.Printf(wxT("%d"), static_cast(mConfig.Get_AutosaveInterval())); + mBeep_On_Collisions = mConfig.Get_BeepOnCollisions(); + mScroll_Natural = mConfig.Get_ScrollDirectionNatural(); + mSetSheet_Undo = mConfig.Get_CommandUndoSetSheet(); + mSelection_Undo = mConfig.Get_CommandUndoSelection(); +} + +bool GeneralSetup::TransferDataToWindow() +{ + static_cast(FindWindow(AUTOSAVE_INTERVAL))->SetValue(mAutoSave_Interval); + static_cast(FindWindow(BEEP_ON_COLLISIONS))->SetValue(mBeep_On_Collisions); + static_cast(FindWindow(SCROLL_NATURAL))->SetValue(mScroll_Natural); + static_cast(FindWindow(SETSHEET_UNDO))->SetValue(mSetSheet_Undo); + static_cast(FindWindow(SELECTION_UNDO))->SetValue(mSelection_Undo); + return true; +} + +bool GeneralSetup::TransferDataFromWindow() +{ + // read out the values from the window + mAutoSave_Interval = static_cast(FindWindow(AUTOSAVE_INTERVAL))->GetValue(); + mBeep_On_Collisions = static_cast(FindWindow(BEEP_ON_COLLISIONS))->GetValue(); + mScroll_Natural = static_cast(FindWindow(SCROLL_NATURAL))->GetValue(); + mSetSheet_Undo = static_cast(FindWindow(SETSHEET_UNDO))->GetValue(); + mSelection_Undo = static_cast(FindWindow(SELECTION_UNDO))->GetValue(); + if (long val = 0; mAutoSave_Interval.ToLong(&val)) { + mConfig.Set_AutosaveInterval(val); + } + mConfig.Set_BeepOnCollisions(mBeep_On_Collisions); + mConfig.Set_ScrollDirectionNatural(mScroll_Natural); + mConfig.Set_CommandUndoSetSheet(mSetSheet_Undo); + mConfig.Set_CommandUndoSelection(mSelection_Undo); + return true; +} + +bool GeneralSetup::ClearValuesToDefault() +{ + mConfig.Clear_AutosaveInterval(); + mConfig.Clear_CalChartFrameAUILayout_3_6_0(); + mConfig.Clear_FieldFrameZoom_3_6_0(); + mConfig.Clear_FieldFrameWidth(); + mConfig.Clear_FieldFrameHeight(); + mConfig.Clear_FieldFramePositionX(); + mConfig.Clear_FieldFramePositionY(); + mConfig.Clear_UseSprites(); + Init(); + TransferDataToWindow(); + return true; +} + diff --git a/src/PreferencesGeneralSetup.h b/src/PreferencesGeneralSetup.h new file mode 100644 index 00000000..33140499 --- /dev/null +++ b/src/PreferencesGeneralSetup.h @@ -0,0 +1,54 @@ +#pragma once +/* + * PreferencesGeneralSetup.h + * Dialox box for General Setup part of preferences + */ + +/* + 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 . +*/ + +#include "PreferencesUtils.h" + +/// General setup +/// Handles general configurations parameters of CalChart +/// + +class GeneralSetup : public PreferencePage { + DECLARE_CLASS(GeneralSetup) + DECLARE_EVENT_TABLE() + +public: + GeneralSetup(CalChartConfiguration& config, wxWindow* parent, wxWindowID id = wxID_ANY, wxString const& caption = wxT("General Setup"), wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU); + virtual ~GeneralSetup() = default; + + virtual void Init() override; + virtual void CreateControls() override; + + // use these to get and set default values + virtual bool TransferDataToWindow() override; + virtual bool TransferDataFromWindow() override; + virtual bool ClearValuesToDefault() override; + +private: + void OnCmdResetAll(wxCommandEvent&); + + wxString mAutoSave_Interval; + bool mBeep_On_Collisions; + bool mScroll_Natural; + bool mSetSheet_Undo; + bool mSelection_Undo; +}; diff --git a/src/PreferencesPSPrintingSetup.cpp b/src/PreferencesPSPrintingSetup.cpp new file mode 100644 index 00000000..8e455bf7 --- /dev/null +++ b/src/PreferencesPSPrintingSetup.cpp @@ -0,0 +1,214 @@ +/* + * CalChartPreferences.cpp + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "PreferencesPSPrintingSetup.h" +#include "PreferencesUtils.h" +#include "CalChartDoc.h" +#include "CalChartSizes.h" +#include "ColorSetupCanvas.h" +#include "ContinuityBrowserPanel.h" +#include "ContinuityComposerDialog.h" +#include "cc_drawcommand.h" +#include "cc_shapes.h" +#include "cc_sheet.h" +#include "confgr.h" +#include "cont.h" +#include "draw.h" +#include "mode_dialog.h" +#include "mode_dialog_canvas.h" +#include "modes.h" + +#include +#include +#include +#include +#include +#include + +using namespace CalChart; + + +typedef enum { + RESET = 1000, + HEADFONT, + MAINFONT, + NUMBERFONT, + CONTFONT, + BOLDFONT, + ITALFONT, + BOLDITALFONT, + HEADERSIZE, + YARDSSIZE, + TEXTSIZE, + CONTRATIO, +} PSPrintingSetUp_IDs; + +BEGIN_EVENT_TABLE(PSPrintingSetUp, PreferencePage) +END_EVENT_TABLE() + +IMPLEMENT_CLASS(PSPrintingSetUp, PreferencePage) + +void PSPrintingSetUp::CreateControls() +{ + wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); + SetSizer(topsizer); + + wxBoxSizer* horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + + AddTextboxWithCaption(this, horizontalsizer, HEADFONT, wxT("Header Font:")); + AddTextboxWithCaption(this, horizontalsizer, MAINFONT, wxT("Main Font:")); + AddTextboxWithCaption(this, horizontalsizer, NUMBERFONT, wxT("Number Font:")); + AddTextboxWithCaption(this, horizontalsizer, CONTFONT, + wxT("Continuity Font:")); + + horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + + AddTextboxWithCaption(this, horizontalsizer, BOLDFONT, wxT("Bold Font:")); + AddTextboxWithCaption(this, horizontalsizer, ITALFONT, wxT("Italic Font:")); + AddTextboxWithCaption(this, horizontalsizer, BOLDITALFONT, + wxT("Bold Italic Font:")); + + horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + + AddTextboxWithCaption(this, horizontalsizer, HEADERSIZE, wxT("Header Size:")); + AddTextboxWithCaption(this, horizontalsizer, YARDSSIZE, wxT("Yards Side:")); + AddTextboxWithCaption(this, horizontalsizer, TEXTSIZE, wxT("Text Side:")); + + horizontalsizer = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(horizontalsizer, LeftBasicSizerFlags()); + + AddTextboxWithCaption(this, horizontalsizer, CONTRATIO, + wxT("Continuity Ratio:")); + + TransferDataToWindow(); +} + +void PSPrintingSetUp::Init() +{ + mFontNames[0] = mConfig.Get_HeadFont(); + mFontNames[1] = mConfig.Get_MainFont(); + mFontNames[2] = mConfig.Get_NumberFont(); + mFontNames[3] = mConfig.Get_ContFont(); + mFontNames[4] = mConfig.Get_BoldFont(); + mFontNames[5] = mConfig.Get_ItalFont(); + mFontNames[6] = mConfig.Get_BoldItalFont(); + mPrintValues[0] = mConfig.Get_HeaderSize(); + mPrintValues[1] = mConfig.Get_YardsSize(); + mPrintValues[2] = mConfig.Get_TextSize(); + mPrintValues[7] = mConfig.Get_ContRatio(); +} + +bool PSPrintingSetUp::TransferDataToWindow() +{ + wxTextCtrl* text = (wxTextCtrl*)FindWindow(HEADFONT); + text->SetValue(mFontNames[0]); + text = (wxTextCtrl*)FindWindow(MAINFONT); + text->SetValue(mFontNames[1]); + text = (wxTextCtrl*)FindWindow(NUMBERFONT); + text->SetValue(mFontNames[2]); + text = (wxTextCtrl*)FindWindow(CONTFONT); + text->SetValue(mFontNames[3]); + text = (wxTextCtrl*)FindWindow(BOLDFONT); + text->SetValue(mFontNames[4]); + text = (wxTextCtrl*)FindWindow(ITALFONT); + text->SetValue(mFontNames[5]); + text = (wxTextCtrl*)FindWindow(BOLDITALFONT); + text->SetValue(mFontNames[6]); + text = (wxTextCtrl*)FindWindow(HEADERSIZE); + wxString buf; + buf.Printf(wxT("%.2f"), mPrintValues[0]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(YARDSSIZE); + buf.Printf(wxT("%.2f"), mPrintValues[1]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(TEXTSIZE); + buf.Printf(wxT("%.2f"), mPrintValues[2]); + text->SetValue(buf); + text = (wxTextCtrl*)FindWindow(CONTRATIO); + buf.Printf(wxT("%.2f"), mPrintValues[7]); + text->SetValue(buf); + + return true; +} + +bool PSPrintingSetUp::TransferDataFromWindow() +{ + // read out the values from the window + wxTextCtrl* text = (wxTextCtrl*)FindWindow(HEADFONT); + mFontNames[0] = text->GetValue(); + text = (wxTextCtrl*)FindWindow(MAINFONT); + mFontNames[1] = text->GetValue(); + text = (wxTextCtrl*)FindWindow(NUMBERFONT); + mFontNames[2] = text->GetValue(); + text = (wxTextCtrl*)FindWindow(CONTFONT); + mFontNames[3] = text->GetValue(); + text = (wxTextCtrl*)FindWindow(BOLDFONT); + mFontNames[4] = text->GetValue(); + text = (wxTextCtrl*)FindWindow(ITALFONT); + mFontNames[5] = text->GetValue(); + text = (wxTextCtrl*)FindWindow(BOLDITALFONT); + mFontNames[6] = text->GetValue(); + text = (wxTextCtrl*)FindWindow(HEADERSIZE); + text->GetValue().ToDouble(&mPrintValues[0]); + text = (wxTextCtrl*)FindWindow(YARDSSIZE); + text->GetValue().ToDouble(&mPrintValues[1]); + text = (wxTextCtrl*)FindWindow(TEXTSIZE); + text->GetValue().ToDouble(&mPrintValues[2]); + text = (wxTextCtrl*)FindWindow(CONTRATIO); + text->GetValue().ToDouble(&mPrintValues[7]); + + // write out the values defaults: + mConfig.Set_HeadFont(mFontNames[0]); + mConfig.Set_MainFont(mFontNames[1]); + mConfig.Set_NumberFont(mFontNames[2]); + mConfig.Set_ContFont(mFontNames[3]); + mConfig.Set_BoldFont(mFontNames[4]); + mConfig.Set_ItalFont(mFontNames[5]); + mConfig.Set_BoldItalFont(mFontNames[6]); + mConfig.Set_HeaderSize(mPrintValues[0]); + mConfig.Set_YardsSize(mPrintValues[1]); + mConfig.Set_TextSize(mPrintValues[2]); + mConfig.Set_ContRatio(mPrintValues[7]); + + return true; +} + +bool PSPrintingSetUp::ClearValuesToDefault() +{ + mConfig.Clear_HeadFont(); + mConfig.Clear_MainFont(); + mConfig.Clear_NumberFont(); + mConfig.Clear_ContFont(); + mConfig.Clear_BoldFont(); + mConfig.Clear_ItalFont(); + mConfig.Clear_BoldItalFont(); + mConfig.Clear_HeaderSize(); + mConfig.Clear_YardsSize(); + mConfig.Clear_TextSize(); + mConfig.Clear_ContRatio(); + Init(); + return TransferDataToWindow(); +} + diff --git a/src/PreferencesPSPrintingSetup.h b/src/PreferencesPSPrintingSetup.h new file mode 100644 index 00000000..4a03aa2b --- /dev/null +++ b/src/PreferencesPSPrintingSetup.h @@ -0,0 +1,66 @@ +#pragma once +/* + * PreferencesPSPrintingSetup.h + * Dialox box for PSPrinting Setup part of preferences + */ + +/* + 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 . +*/ + +#pragma once + +#include "PreferencesUtils.h" +#include "confgr.h" +#include +#include +#include +#include + +//////// General setup //////// +// setup pringing values and colors +//////// + +class PSPrintingSetUp : public PreferencePage { + DECLARE_CLASS(PSPrintingSetUp) + DECLARE_EVENT_TABLE() + +public: + 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) + : PreferencePage(config) + { + Init(); + Create(parent, id, caption, pos, size, style); + } + virtual ~PSPrintingSetUp() {} + + virtual void Init(); + virtual void CreateControls(); + + // use these to get and set default values + virtual bool TransferDataToWindow(); + virtual bool TransferDataFromWindow(); + virtual bool ClearValuesToDefault(); + +private: + wxString mFontNames[7]; + double mPrintValues[8]; +}; diff --git a/src/PreferencesShowModeSetup.cpp b/src/PreferencesShowModeSetup.cpp new file mode 100644 index 00000000..5be4b78e --- /dev/null +++ b/src/PreferencesShowModeSetup.cpp @@ -0,0 +1,270 @@ +/* + * CalChartPreferences.cpp + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "PreferencesShowModeSetup.h" +#include "PreferencesUtils.h" +#include "CalChartDoc.h" +#include "CalChartSizes.h" +#include "ColorSetupCanvas.h" +#include "ContinuityBrowserPanel.h" +#include "ContinuityComposerDialog.h" +#include "cc_drawcommand.h" +#include "cc_shapes.h" +#include "cc_sheet.h" +#include "confgr.h" +#include "cont.h" +#include "draw.h" +#include "mode_dialog.h" +#include "mode_dialog_canvas.h" +#include "modes.h" + +#include +#include +#include +#include +#include +#include + +using namespace CalChart; + + +enum { + MODE_CHOICE = 1000, + WESTHASH, + EASTHASH, + BORDER_LEFT, + BORDER_TOP, + BORDER_RIGHT, + BORDER_BOTTOM, + OFFSET_X, + OFFSET_Y, + SIZE_X, + SIZE_Y, + SHOW_LINE_MARKING, + SHOW_LINE_VALUE, + CANVAS, +}; + +BEGIN_EVENT_TABLE(ShowModeSetup, PreferencePage) +EVT_CHOICE(MODE_CHOICE, ShowModeSetup::OnCmdChoice) +EVT_CHOICE(SHOW_LINE_MARKING, ShowModeSetup::OnCmdChoice) +END_EVENT_TABLE() + +IMPLEMENT_CLASS(ShowModeSetup, PreferencePage) + +void ShowModeSetup::CreateControls() +{ + wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); + SetSizer(topsizer); + + wxChoice* modes = new wxChoice(this, MODE_CHOICE, wxDefaultPosition, + wxDefaultSize, SHOWMODE_NUM, kShowModeStrings); + modes->SetSelection(0); + topsizer->Add(modes, LeftBasicSizerFlags()); + + wxBoxSizer* sizer1 = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(sizer1, LeftBasicSizerFlags()); + + auto refresh_action = [this](wxCommandEvent&) { + this->TransferDataFromWindow(); + Refresh(); + }; + + AddTextboxWithCaptionAndAction(this, sizer1, WESTHASH, wxT("West Hash"), + refresh_action, wxTE_PROCESS_ENTER); + AddTextboxWithCaptionAndAction(this, sizer1, EASTHASH, wxT("East Hash"), + refresh_action, wxTE_PROCESS_ENTER); + + sizer1 = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(sizer1, LeftBasicSizerFlags()); + AddTextboxWithCaptionAndAction(this, sizer1, BORDER_LEFT, wxT("Left Border"), + refresh_action, wxTE_PROCESS_ENTER); + AddTextboxWithCaptionAndAction(this, sizer1, BORDER_TOP, wxT("Top Border"), + refresh_action, wxTE_PROCESS_ENTER); + AddTextboxWithCaptionAndAction(this, sizer1, BORDER_RIGHT, + wxT("Right Border"), refresh_action, + wxTE_PROCESS_ENTER); + AddTextboxWithCaptionAndAction(this, sizer1, BORDER_BOTTOM, + wxT("Bottom Border"), refresh_action, + wxTE_PROCESS_ENTER); + + sizer1 = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(sizer1, LeftBasicSizerFlags()); + AddTextboxWithCaptionAndAction(this, sizer1, OFFSET_X, wxT("Offset X"), + refresh_action, wxTE_PROCESS_ENTER); + AddTextboxWithCaptionAndAction(this, sizer1, OFFSET_Y, wxT("Offset Y"), + refresh_action, wxTE_PROCESS_ENTER); + AddTextboxWithCaptionAndAction(this, sizer1, SIZE_X, wxT("Size X"), + refresh_action, wxTE_PROCESS_ENTER); + AddTextboxWithCaptionAndAction(this, sizer1, SIZE_Y, wxT("Size Y"), + refresh_action, wxTE_PROCESS_ENTER); + + sizer1 = new wxBoxSizer(wxHORIZONTAL); + topsizer->Add(sizer1, LeftBasicSizerFlags()); + wxBoxSizer* textsizer = new wxBoxSizer(wxHORIZONTAL); + sizer1->Add(textsizer, BasicSizerFlags()); + 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, + wxArrayString{ mConfig.Get_yard_text_index().size(), mConfig.Get_yard_text_index().data() }); + textchoice->SetSelection(0); + textsizer->Add(textchoice); + auto show_line_value = new wxTextCtrl(this, SHOW_LINE_VALUE, wxEmptyString, wxDefaultPosition, + wxDefaultSize, wxTE_PROCESS_ENTER); + show_line_value->Bind(wxEVT_TEXT_ENTER, refresh_action); + textsizer->Add(show_line_value, BasicSizerFlags()); + + textsizer = new wxBoxSizer(wxHORIZONTAL); + sizer1->Add(textsizer, BasicSizerFlags()); + textsizer->Add(new wxStaticText(this, wxID_STATIC, wxT("Zoom"), + wxDefaultPosition, wxDefaultSize, 0), + 0, wxALIGN_LEFT | wxALL, 5); + wxArrayString zoomtext; + for (auto& i : zoom_amounts) { + wxString buf; + buf.sprintf(wxT("%d%%"), i); + zoomtext.Add(buf); + } + auto zoomBox = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, zoomtext); + zoomBox->Bind(wxEVT_CHOICE, [=](wxCommandEvent& event) { + size_t sel = event.GetInt(); + float zoom_amount = zoom_amounts[sel] / 100.0; + static_cast(FindWindow(CANVAS)) + ->SetZoom(zoom_amount); + }); + + // set the text to the default zoom level + textsizer->Add(zoomBox, LeftBasicSizerFlags()); + + auto modeSetupCanvas = new ShowModeSetupCanvas(mConfig, this, CANVAS); + modeSetupCanvas->SetScrollRate(1, 1); + topsizer->Add(modeSetupCanvas, 1, wxEXPAND); + + modeSetupCanvas->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); + modeSetupCanvas->SetZoom(zoom_amounts[5] / 100.0); + zoomBox->SetSelection(5); + + TransferDataToWindow(); +} + +void ShowModeSetup::Init() +{ + mWhichMode = 0; + mWhichYardLine = 0; + for (size_t i = 0; i < SHOWMODE_NUM; ++i) { + mShowModeValues[i] = mConfig.Get_ShowModeInfo(static_cast(i)); + } + for (size_t i = 0; i < kYardTextValues; ++i) { + mYardText[i] = mConfig.Get_yard_text(i); + } +} + +bool ShowModeSetup::TransferDataToWindow() +{ + // standard show + for (auto i = mShowModeValues[mWhichMode].begin(); + i != mShowModeValues[mWhichMode].end(); ++i) { + wxString buf; + wxTextCtrl* text = (wxTextCtrl*)FindWindow( + WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); + buf.Printf(wxT("%d"), static_cast(*i)); + text->ChangeValue(buf); + } + + wxTextCtrl* text = (wxTextCtrl*)FindWindow(SHOW_LINE_VALUE); + text->SetValue(mYardText[mWhichYardLine]); + return true; +} + +bool ShowModeSetup::TransferDataFromWindow() +{ + // read out the values from the window + // standard show + for (auto i = mShowModeValues[mWhichMode].begin(); + i != mShowModeValues[mWhichMode].end(); ++i) { + long val; + wxTextCtrl* text = (wxTextCtrl*)FindWindow( + WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); + text->GetValue().ToLong(&val); + *i = val; + } + // write out the values defaults: + for (size_t i = 0; i < SHOWMODE_NUM; ++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 < kYardTextValues; ++i) { + mConfig.Set_yard_text(i, mYardText[i]); + } + // now set the canvas + ((ShowModeSetupCanvas*)FindWindow(CANVAS))->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); + + return true; +} + +bool ShowModeSetup::ClearValuesToDefault() +{ + for (size_t i = 0; i < SHOWMODE_NUM; ++i) { + mConfig.Clear_ShowModeInfo(static_cast(i)); + } + for (auto i = 0; i < kYardTextValues; ++i) { + mConfig.Clear_yard_text(i); + } + Init(); + ((ShowModeSetupCanvas*)FindWindow(CANVAS))->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); + return TransferDataToWindow(); +} + +void ShowModeSetup::OnCmdChoice(wxCommandEvent&) +{ + // save off all the old values: + for (auto i = mShowModeValues[mWhichMode].begin(); + i != mShowModeValues[mWhichMode].end(); ++i) { + long val; + wxTextCtrl* text = (wxTextCtrl*)FindWindow( + WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); + text->GetValue().ToLong(&val); + *i = val; + } + wxChoice* modes = (wxChoice*)FindWindow(MODE_CHOICE); + mWhichMode = modes->GetSelection(); + ShowModeSetupCanvas* canvas = (ShowModeSetupCanvas*)FindWindow(CANVAS); + canvas->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); + + wxTextCtrl* text = (wxTextCtrl*)FindWindow(SHOW_LINE_VALUE); + mYardText[mWhichYardLine] = text->GetValue(); + // update mode + for (size_t i = 0; i < kYardTextValues; ++i) { + mConfig.Set_yard_text(i, mYardText[i]); + } + + modes = (wxChoice*)FindWindow(SHOW_LINE_MARKING); + mWhichYardLine = modes->GetSelection(); + TransferDataToWindow(); +} + diff --git a/src/PreferencesShowModeSetup.h b/src/PreferencesShowModeSetup.h new file mode 100644 index 00000000..1507a675 --- /dev/null +++ b/src/PreferencesShowModeSetup.h @@ -0,0 +1,68 @@ +#pragma once +/* + * PreferencesShowModeSetup.h + * Dialox box for ShowMode Setup part of preferences + */ + +/* + 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 . +*/ + +#include "PreferencesUtils.h" + +#include "confgr.h" +#include "modes.h" +#include +#include +#include +#include + +const int zoom_amounts[] = { 500, 200, 150, 100, 75, 50, 25, 10 }; + +class ShowModeSetup : public PreferencePage { + DECLARE_CLASS(ShowModeSetup) + DECLARE_EVENT_TABLE() + +public: + 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) + : PreferencePage(config) + { + Init(); + Create(parent, id, caption, pos, size, style); + } + ~ShowModeSetup() {} + + 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 OnCmdLineText(wxCommandEvent&); + void OnCmdChoice(wxCommandEvent&); + CalChartConfiguration::ShowModeInfo_t mShowModeValues[SHOWMODE_NUM]; + CalChart::ShowMode::YardLinesInfo_t mYardText; + int mWhichMode; + int mWhichYardLine; +}; diff --git a/src/PreferencesUtils.cpp b/src/PreferencesUtils.cpp new file mode 100644 index 00000000..c2251912 --- /dev/null +++ b/src/PreferencesUtils.cpp @@ -0,0 +1,75 @@ +/* + * CalChartPreferences.cpp + * Dialox box for preferences + */ + +/* + 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 . +*/ + +#include "PreferencesUtils.h" +#include "basic_ui.h" + +IMPLEMENT_ABSTRACT_CLASS(PreferencePage, wxPanel) + + +// how the preferences work: +// 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 +// +// organized into pages. Each page is responsible for reading out +// on TransferDataToWindow, caching the values locally, and +// setting them to the system on TransferDataFromWindow + +// convience sizers to change the view behavior in all at once. +static auto sRightBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Right().Proportion(0); +static auto sExpandSizerFlags = wxSizerFlags().Border(wxALL, 2).Center().Proportion(0); + +void AddTextboxWithCaption(wxWindow* parent, wxBoxSizer* verticalsizer, + int id, const wxString& caption, + long style) +{ + wxBoxSizer* textsizer = new wxBoxSizer(wxVERTICAL); + textsizer->Add(new wxStaticText(parent, wxID_STATIC, caption, + wxDefaultPosition, wxDefaultSize, 0), + LeftBasicSizerFlags()); + textsizer->Add(new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, + wxDefaultSize, style), + BasicSizerFlags()); + verticalsizer->Add(textsizer, BasicSizerFlags()); +} + +void AddCheckboxWithCaption(wxWindow* parent, wxBoxSizer* verticalsizer, + int id, const wxString& caption, + long style) +{ + wxBoxSizer* textsizer = new wxBoxSizer(wxVERTICAL); + textsizer->Add(new wxCheckBox(parent, id, caption, wxDefaultPosition, + wxDefaultSize, style), + BasicSizerFlags()); + verticalsizer->Add(textsizer, BasicSizerFlags()); +} + + diff --git a/src/PreferencesUtils.h b/src/PreferencesUtils.h new file mode 100644 index 00000000..160359fe --- /dev/null +++ b/src/PreferencesUtils.h @@ -0,0 +1,89 @@ +#pragma once +/* + * cc_preferences.h + * Dialox box for preferences + */ + +/* + 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 . +*/ + + +#include "confgr.h" +#include "basic_ui.h" +#include + +// 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(CalChartConfiguration& config) + : mConfig(config) + { + Init(); + } + virtual ~PreferencePage() {} + virtual void Init() {} + virtual bool Create(wxWindow* parent, wxWindowID id, const wxString& caption, + const wxPoint& pos, const wxSize& size, long style) + { + if (!wxPanel::Create(parent, id, pos, size, style, caption)) + return false; + CreateControls(); + GetSizer()->Fit(this); + GetSizer()->SetSizeHints(this); + Center(); + return true; + } + + // 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; +}; + +// should this move to basic_ui.h? +template +void AddTextboxWithCaptionAndAction(wxWindow* parent, wxBoxSizer* verticalsizer, + int id, const wxString& caption, + Function&& f, long style = 0) +{ + wxBoxSizer* textsizer = new wxBoxSizer(wxVERTICAL); + textsizer->Add(new wxStaticText(parent, wxID_STATIC, caption, + wxDefaultPosition, wxDefaultSize, 0), + LeftBasicSizerFlags()); + auto textCtrl = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, + wxDefaultSize, style); + textCtrl->Bind((style & wxTE_PROCESS_ENTER) ? wxEVT_TEXT_ENTER : wxEVT_TEXT, + f); + textsizer->Add(textCtrl, BasicSizerFlags()); + verticalsizer->Add(textsizer, BasicSizerFlags()); +} + +void AddTextboxWithCaption(wxWindow* parent, wxBoxSizer* verticalsizer, + int id, const wxString& caption, + long style = 0); +void AddCheckboxWithCaption(wxWindow* parent, wxBoxSizer* verticalsizer, + int id, const wxString& caption, + long style = 0); diff --git a/src/TopFrame.cpp b/src/TopFrame.cpp index c0374a69..1a754890 100644 --- a/src/TopFrame.cpp +++ b/src/TopFrame.cpp @@ -25,7 +25,7 @@ #include "CalChartSizes.h" #include "basic_ui.h" #include "calchart.xbm" -#include "cc_preferences_ui.h" +#include "CalChartPreferences.h" #include "ccvers.h" #include diff --git a/src/basic_ui.h b/src/basic_ui.h index bbac9d46..25b9d178 100644 --- a/src/basic_ui.h +++ b/src/basic_ui.h @@ -156,6 +156,7 @@ class ClickDragCtrlScrollCanvas : public MouseMoveScrollCanvas { virtual bool ShouldScrollOnMouseEvent(const wxMouseEvent& event) const override; }; +// common sizers all in one places wxSizerFlags BasicSizerFlags(); wxSizerFlags LeftBasicSizerFlags(); wxSizerFlags RightBasicSizerFlags(); diff --git a/src/cc_preferences_ui.cpp b/src/cc_preferences_ui.cpp deleted file mode 100644 index e26e2295..00000000 --- a/src/cc_preferences_ui.cpp +++ /dev/null @@ -1,1417 +0,0 @@ -/* - * cc_preferences_ui.cpp - * Dialox box for preferences - */ - -/* - 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 . -*/ - -#include "cc_preferences_ui.h" -#include "CalChartDoc.h" -#include "CalChartSizes.h" -#include "ColorSetupCanvas.h" -#include "ContinuityBrowserPanel.h" -#include "ContinuityComposerDialog.h" -#include "cc_drawcommand.h" -#include "cc_shapes.h" -#include "cc_sheet.h" -#include "confgr.h" -#include "cont.h" -#include "draw.h" -#include "mode_dialog.h" -#include "mode_dialog_canvas.h" -#include "modes.h" - -#include -#include -#include -#include -#include -#include - -using namespace CalChart; - -// how the preferences work: -// 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 -// -// organized into pages. Each page is responsible for reading out -// on TransferDataToWindow, caching the values locally, and -// setting them to the system on TransferDataFromWindow - -// convience sizers to change the view behavior in all at once. -static auto sBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Center().Proportion(0); -static auto sLeftBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Left().Proportion(0); -static auto sRightBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Right().Proportion(0); -static auto sExpandSizerFlags = wxSizerFlags().Border(wxALL, 2).Center().Proportion(0); - -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, wxEmptyString, wxDefaultPosition, - wxDefaultSize, style), - sBasicSizerFlags); - verticalsizer->Add(textsizer, sBasicSizerFlags); -} - -static void AddCheckboxWithCaption(wxWindow* parent, wxBoxSizer* verticalsizer, - int id, const wxString& caption, - long style = 0) -{ - wxBoxSizer* textsizer = new wxBoxSizer(wxVERTICAL); - textsizer->Add(new wxCheckBox(parent, id, caption, wxDefaultPosition, - wxDefaultSize, style), - sBasicSizerFlags); - verticalsizer->Add(textsizer, sBasicSizerFlags); -} - -template -void AddTextboxWithCaptionAndAction(wxWindow* parent, wxBoxSizer* verticalsizer, - int id, const wxString& caption, - Function&& f, long style = 0) -{ - wxBoxSizer* textsizer = new wxBoxSizer(wxVERTICAL); - textsizer->Add(new wxStaticText(parent, wxID_STATIC, caption, - wxDefaultPosition, wxDefaultSize, 0), - sLeftBasicSizerFlags); - auto textCtrl = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, - wxDefaultSize, style); - textCtrl->Bind((style & wxTE_PROCESS_ENTER) ? wxEVT_TEXT_ENTER : wxEVT_TEXT, - f); - textsizer->Add(textCtrl, sBasicSizerFlags); - verticalsizer->Add(textsizer, sBasicSizerFlags); -} - -// 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(CalChartConfiguration& config) - : mConfig(config) - { - Init(); - } - virtual ~PreferencePage() {} - virtual void Init() {} - virtual bool Create(wxWindow* parent, wxWindowID id, const wxString& caption, - const wxPoint& pos, const wxSize& size, long style) - { - if (!wxPanel::Create(parent, id, pos, size, style, caption)) - return false; - CreateControls(); - GetSizer()->Fit(this); - GetSizer()->SetSizeHints(this); - Center(); - return true; - } - - // 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 -//////// - -class GeneralSetup : public PreferencePage { - DECLARE_CLASS(GeneralSetup) - DECLARE_EVENT_TABLE() - -public: - 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) - : PreferencePage(config) - { - Init(); - Create(parent, id, caption, pos, size, style); - } - virtual ~GeneralSetup() {} - - 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 OnCmdResetAll(wxCommandEvent&); - - wxString mAutoSave_Interval; - bool mBeep_On_Collisions; - bool mScroll_Natural; - bool mSetSheet_Undo; - bool mSelection_Undo; -}; - -enum { - AUTOSAVE_INTERVAL = 1000, - BEEP_ON_COLLISIONS, - SCROLL_NATURAL, - SETSHEET_UNDO, - SELECTION_UNDO, -}; - -BEGIN_EVENT_TABLE(GeneralSetup, PreferencePage) -END_EVENT_TABLE() - -IMPLEMENT_CLASS(GeneralSetup, PreferencePage) - -void GeneralSetup::CreateControls() -{ - wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); - SetSizer(topsizer); - - wxStaticBoxSizer* boxsizer = new wxStaticBoxSizer( - new wxStaticBox(this, -1, wxT("Autosave settings")), wxVERTICAL); - topsizer->Add(boxsizer); - - wxBoxSizer* sizer1 = new wxBoxSizer(wxVERTICAL); - boxsizer->Add(sizer1, sLeftBasicSizerFlags); - - AddTextboxWithCaption(this, sizer1, AUTOSAVE_INTERVAL, - wxT("Autosave Interval")); - AddCheckboxWithCaption(this, sizer1, BEEP_ON_COLLISIONS, - wxT("Beep on animation collisions")); - AddCheckboxWithCaption(this, sizer1, SCROLL_NATURAL, - wxT("Scroll Direction: Natural")); - AddCheckboxWithCaption(this, sizer1, SETSHEET_UNDO, - wxT("Set Sheet is undo-able")); - AddCheckboxWithCaption(this, sizer1, SELECTION_UNDO, - wxT("Point selection is undo-able")); - - TransferDataToWindow(); -} - -void GeneralSetup::Init() -{ - mAutoSave_Interval.Printf(wxT("%d"), static_cast(mConfig.Get_AutosaveInterval())); - mBeep_On_Collisions = mConfig.Get_BeepOnCollisions(); - mScroll_Natural = mConfig.Get_ScrollDirectionNatural(); - mSetSheet_Undo = mConfig.Get_CommandUndoSetSheet(); - mSelection_Undo = mConfig.Get_CommandUndoSelection(); -} - -bool GeneralSetup::TransferDataToWindow() -{ - ((wxTextCtrl*)FindWindow(AUTOSAVE_INTERVAL))->SetValue(mAutoSave_Interval); - ((wxCheckBox*)FindWindow(BEEP_ON_COLLISIONS))->SetValue(mBeep_On_Collisions); - ((wxCheckBox*)FindWindow(SCROLL_NATURAL))->SetValue(mScroll_Natural); - ((wxCheckBox*)FindWindow(SETSHEET_UNDO))->SetValue(mSetSheet_Undo); - ((wxCheckBox*)FindWindow(SELECTION_UNDO))->SetValue(mSelection_Undo); - return true; -} - -bool GeneralSetup::TransferDataFromWindow() -{ - // read out the values from the window - mAutoSave_Interval = ((wxTextCtrl*)FindWindow(AUTOSAVE_INTERVAL))->GetValue(); - long val; - if (mAutoSave_Interval.ToLong(&val)) { - mConfig.Set_AutosaveInterval(val); - } - mBeep_On_Collisions = ((wxCheckBox*)FindWindow(BEEP_ON_COLLISIONS))->GetValue(); - mConfig.Set_BeepOnCollisions(mBeep_On_Collisions); - mScroll_Natural = ((wxCheckBox*)FindWindow(SCROLL_NATURAL))->GetValue(); - mConfig.Set_ScrollDirectionNatural(mScroll_Natural); - mSetSheet_Undo = ((wxCheckBox*)FindWindow(SETSHEET_UNDO))->GetValue(); - mConfig.Set_CommandUndoSetSheet(mSetSheet_Undo); - mSelection_Undo = ((wxCheckBox*)FindWindow(SELECTION_UNDO))->GetValue(); - mConfig.Set_CommandUndoSelection(mSelection_Undo); - return true; -} - -bool GeneralSetup::ClearValuesToDefault() -{ - mConfig.Clear_AutosaveInterval(); - mConfig.Clear_CalChartFrameAUILayout_3_6_0(); - mConfig.Clear_FieldFrameZoom_3_6_0(); - mConfig.Clear_FieldFrameWidth(); - mConfig.Clear_FieldFrameHeight(); - mConfig.Clear_FieldFramePositionX(); - mConfig.Clear_FieldFramePositionY(); - Init(); - TransferDataToWindow(); - return true; -} - -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 OnCmdChooseNewPalette(wxCommandEvent&); - void OnCmdTextChanged(wxCommandEvent&); - void OnCmdChangePaletteColor(wxCommandEvent&); - void OnCmdChangePaletteName(wxCommandEvent&); - - void SetColor(int selection, int width, const wxColour& color); - void SetPaletteColor(int selection, const wxColour& color); - void SetPaletteName(int selection, const wxString& name); - wxBitmapComboBox* nameBox; - wxBitmapComboBox* mPaletteNameBox; - wxSpinCtrl* spin; - - int mActiveColorPalette{}; - std::vector mColorPaletteNames; - std::vector mColorPaletteColors; - wxPen mCalChartPens[kNumberPalettes][COLOR_NUM]; - wxBrush mCalChartBrushes[kNumberPalettes][COLOR_NUM]; - - double mPrintValues[5]; -}; - -enum { - BUTTON_SELECT = 1000, - BUTTON_RESTORE, - SPIN_WIDTH, - NEW_COLOR_CHOICE, - DOTRATIO, - NUMRATIO, - PLINERATIO, - SLINERATIO, - BUTTON_EDIT_PALETTE_COLOR, - BUTTON_EDIT_PALETTE_NAME, - NEW_COLOR_PALETTE, -}; - -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_COMBOBOX(NEW_COLOR_PALETTE, DrawingSetup::OnCmdChooseNewPalette) -EVT_TEXT_ENTER(DOTRATIO, DrawingSetup::OnCmdTextChanged) -EVT_TEXT_ENTER(NUMRATIO, DrawingSetup::OnCmdTextChanged) -EVT_TEXT_ENTER(PLINERATIO, DrawingSetup::OnCmdTextChanged) -EVT_TEXT_ENTER(SLINERATIO, DrawingSetup::OnCmdTextChanged) -EVT_BUTTON(BUTTON_EDIT_PALETTE_COLOR, DrawingSetup::OnCmdChangePaletteColor) -EVT_BUTTON(BUTTON_EDIT_PALETTE_NAME, DrawingSetup::OnCmdChangePaletteName) -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("Palette Selector")), wxVERTICAL); - topsizer->Add(boxsizer); - - mPaletteNameBox = new wxBitmapComboBox(this, NEW_COLOR_PALETTE, mColorPaletteNames.at(0), wxDefaultPosition, wxSize(200, -1), kNumberPalettes, mColorPaletteNames.data(), wxCB_READONLY | wxCB_DROPDOWN); - boxsizer->Add(mPaletteNameBox, sLeftBasicSizerFlags); - - for (auto i = 0; i < kNumberPalettes; ++i) { - CreateAndSetItemBitmap(mPaletteNameBox, i, mColorPaletteColors.at(i)); - } - mPaletteNameBox->SetSelection(mActiveColorPalette); - - auto horizontalsizer = new wxBoxSizer(wxHORIZONTAL); - boxsizer->Add(horizontalsizer, sBasicSizerFlags); - - horizontalsizer->Add(new wxButton(this, BUTTON_EDIT_PALETTE_COLOR, wxT("&Edit Color")), sBasicSizerFlags); - horizontalsizer->Add(new wxButton(this, BUTTON_EDIT_PALETTE_NAME, wxT("&Edit Name")), sBasicSizerFlags); - - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); - topsizer->Add(boxsizer); - - 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)) { - CreateAndSetItemBitmap(nameBox, i, mConfig.Get_CalChartBrushAndPen(i).first); - } - nameBox->SetSelection(0); - - spin = new wxSpinCtrl(this, SPIN_WIDTH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); - spin->SetValue(mCalChartPens[mActiveColorPalette][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, 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 ColorSetupCanvas(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 DrawingSetup::Init() -{ - // first read out the defaults: - mActiveColorPalette = mConfig.GetActiveColorPalette(); - mColorPaletteNames = GetColorPaletteNames(mConfig); - mColorPaletteColors = GetColorPaletteColors(mConfig); - - for (auto palette = 0; palette < kNumberPalettes; ++palette) { - for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i) + 1)) { - auto brushAndPen = mConfig.Get_CalChartBrushAndPen(palette, i); - mCalChartPens[palette][i] = brushAndPen.second; - mCalChartBrushes[palette][i] = brushAndPen.first; - } - } - - 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 DrawingSetup::TransferDataToWindow() -{ - for (auto i = 0; i < kNumberPalettes; ++i) { - CreateAndSetItemBitmap(mPaletteNameBox, i, mColorPaletteColors.at(i)); - } - for (auto i = 0; i < kNumberPalettes; ++i) { - mPaletteNameBox->SetString(i, mColorPaletteNames.at(i)); - } - mPaletteNameBox->SetSelection(mActiveColorPalette); - - for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; - i = static_cast(static_cast(i) + 1)) { - CreateAndSetItemBitmap(nameBox, i, mCalChartBrushes[mActiveColorPalette][i]); - } - spin->SetValue(mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); - - wxString buf; - wxTextCtrl* text = (wxTextCtrl*)FindWindow(DOTRATIO); - buf.Printf(wxT("%.2f"), mPrintValues[0]); - text->SetValue(buf); - text = (wxTextCtrl*)FindWindow(NUMRATIO); - buf.Printf(wxT("%.2f"), mPrintValues[1]); - text->SetValue(buf); - text = (wxTextCtrl*)FindWindow(PLINERATIO); - buf.Printf(wxT("%.2f"), mPrintValues[2]); - text->SetValue(buf); - text = (wxTextCtrl*)FindWindow(SLINERATIO); - buf.Printf(wxT("%.2f"), mPrintValues[3]); - text->SetValue(buf); - - return true; -} - -bool DrawingSetup::TransferDataFromWindow() -{ - // Data is already transferred when we update the controls, so nothing to do here. - mConfig.SetActiveColorPalette(mActiveColorPalette); - return true; -} - -bool DrawingSetup::ClearValuesToDefault() -{ - mConfig.ClearActiveColorPalette(); - for (auto i = 0; i < kNumberPalettes; ++i) { - mConfig.ClearColorPaletteColor(i); - mConfig.ClearColorPaletteName(i); - } - - for (auto palette = 0; palette < kNumberPalettes; ++palette) { - for (CalChartColors i = COLOR_FIELD; i < COLOR_NUM; i = static_cast(static_cast(i) + 1)) { - mConfig.Clear_CalChartConfigColor(palette, i); - } - } - Init(); - TransferDataToWindow(); - return true; -} - -// when the palette changes -void DrawingSetup::SetColor(int selection, int width, const wxColour& color) -{ - mCalChartPens[mActiveColorPalette][selection] = *wxThePenList->FindOrCreatePen(color, width, wxPENSTYLE_SOLID); - mCalChartBrushes[mActiveColorPalette][selection] = *wxTheBrushList->FindOrCreateBrush(color, wxBRUSHSTYLE_SOLID); - - mConfig.Set_CalChartBrushAndPen(static_cast(selection), mCalChartBrushes[mActiveColorPalette][selection], mCalChartPens[mActiveColorPalette][selection]); - - // update the namebox list - CreateAndSetItemBitmap(nameBox, selection, mCalChartBrushes[mActiveColorPalette][selection]); - Refresh(); -} - -void DrawingSetup::SetPaletteColor(int selection, wxColour const& color) -{ - mColorPaletteColors.at(selection) = *wxTheBrushList->FindOrCreateBrush(color, wxBRUSHSTYLE_SOLID); - - // this is needed so we draw things out on the page correctly. - mConfig.SetColorPaletteColor(selection, mColorPaletteColors.at(selection)); - - CreateAndSetItemBitmap(mPaletteNameBox, selection, mColorPaletteColors.at(selection)); - Refresh(); -} - -void DrawingSetup::SetPaletteName(int selection, wxString const& name) -{ - mColorPaletteNames.at(selection) = name; - - // this is needed so we draw things out on the page correctly. - mConfig.SetColorPaletteName(selection, name); - - mPaletteNameBox->SetString(selection, mColorPaletteNames.at(selection)); - Refresh(); -} - -void DrawingSetup::OnCmdSelectColors(wxCommandEvent&) -{ - int selection = nameBox->GetSelection(); - wxColourData data; - data.SetChooseFull(true); - data.SetColour(mCalChartBrushes[mActiveColorPalette][selection].GetColour()); - wxColourDialog dialog(this, &data); - if (dialog.ShowModal() == wxID_OK) { - wxColourData retdata = dialog.GetColourData(); - wxColour c = retdata.GetColour(); - SetColor(selection, mCalChartPens[mActiveColorPalette][selection].GetWidth(), c); - } - Refresh(); -} - -void DrawingSetup::OnCmdChangePaletteColor(wxCommandEvent&) -{ - int selection = mPaletteNameBox->GetSelection(); - wxColourData data; - data.SetChooseFull(true); - data.SetColour(mColorPaletteColors.at(selection).GetColour()); - wxColourDialog dialog(this, &data); - if (dialog.ShowModal() == wxID_OK) { - wxColourData retdata = dialog.GetColourData(); - wxColour c = retdata.GetColour(); - SetPaletteColor(selection, c); - } - Refresh(); -} - -void DrawingSetup::OnCmdChangePaletteName(wxCommandEvent&) -{ - int selection = mPaletteNameBox->GetSelection(); - auto v = mPaletteNameBox->GetValue(); - wxTextEntryDialog dialog(this, wxT("Enter name for Palette"), wxT("Enter name for Palette"), v, wxOK | wxCANCEL); - if (dialog.ShowModal() == wxID_OK) { - SetPaletteName(selection, dialog.GetValue()); - } - Refresh(); -} - -void DrawingSetup::OnCmdSelectWidth(wxSpinEvent& e) -{ - int selection = nameBox->GetSelection(); - SetColor(selection, e.GetPosition(), mCalChartPens[mActiveColorPalette][selection].GetColour()); -} - -void DrawingSetup::OnCmdResetColors(wxCommandEvent&) -{ - int selection = nameBox->GetSelection(); - SetColor(selection, mConfig.GetDefaultPenWidth()[selection], - mConfig.GetDefaultColors()[selection]); - mConfig.Clear_CalChartConfigColor(static_cast(selection)); -} - -void DrawingSetup::OnCmdChooseNewColor(wxCommandEvent&) -{ - spin->SetValue(mCalChartPens[mActiveColorPalette][nameBox->GetSelection()].GetWidth()); -} - -void DrawingSetup::OnCmdChooseNewPalette(wxCommandEvent&) -{ - // we set the active palette, and now need to refresh everything - mActiveColorPalette = mPaletteNameBox->GetSelection(); - mConfig.SetActiveColorPalette(mActiveColorPalette); - TransferDataToWindow(); - Refresh(); -} - -void DrawingSetup::OnCmdTextChanged(wxCommandEvent& e) -{ - auto id = e.GetId(); - wxTextCtrl* text = (wxTextCtrl*)FindWindow(id); - double value; - if (text->GetValue().ToDouble(&value)) { - switch (id - DOTRATIO) { - case 0: - mConfig.Set_DotRatio(value); - break; - case 1: - mConfig.Set_NumRatio(value); - break; - case 2: - mConfig.Set_PLineRatio(value); - break; - case 3: - mConfig.Set_SLineRatio(value); - break; - case 4: - mConfig.Set_ContRatio(value); - break; - } - } - Refresh(); -} - -//////// General setup //////// -// setup pringing values and colors -//////// - -class PSPrintingSetUp : public PreferencePage { - DECLARE_CLASS(PSPrintingSetUp) - DECLARE_EVENT_TABLE() - -public: - 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) - : PreferencePage(config) - { - Init(); - Create(parent, id, caption, pos, size, style); - } - virtual ~PSPrintingSetUp() {} - - virtual void Init(); - virtual void CreateControls(); - - // use these to get and set default values - virtual bool TransferDataToWindow(); - virtual bool TransferDataFromWindow(); - virtual bool ClearValuesToDefault(); - -private: - wxString mFontNames[7]; - double mPrintValues[8]; -}; - -typedef enum { - RESET = 1000, - HEADFONT, - MAINFONT, - NUMBERFONT, - CONTFONT, - BOLDFONT, - ITALFONT, - BOLDITALFONT, - HEADERSIZE, - YARDSSIZE, - TEXTSIZE, - CONTRATIO, -} PSPrintingSetUp_IDs; - -BEGIN_EVENT_TABLE(PSPrintingSetUp, PreferencePage) -END_EVENT_TABLE() - -IMPLEMENT_CLASS(PSPrintingSetUp, PreferencePage) - -void PSPrintingSetUp::CreateControls() -{ - wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); - SetSizer(topsizer); - - wxBoxSizer* horizontalsizer = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(horizontalsizer, sLeftBasicSizerFlags); - - AddTextboxWithCaption(this, horizontalsizer, HEADFONT, wxT("Header Font:")); - AddTextboxWithCaption(this, horizontalsizer, MAINFONT, wxT("Main Font:")); - AddTextboxWithCaption(this, horizontalsizer, NUMBERFONT, wxT("Number Font:")); - AddTextboxWithCaption(this, horizontalsizer, CONTFONT, - wxT("Continuity Font:")); - - horizontalsizer = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(horizontalsizer, sLeftBasicSizerFlags); - - AddTextboxWithCaption(this, horizontalsizer, BOLDFONT, wxT("Bold Font:")); - AddTextboxWithCaption(this, horizontalsizer, ITALFONT, wxT("Italic Font:")); - AddTextboxWithCaption(this, horizontalsizer, BOLDITALFONT, - wxT("Bold Italic Font:")); - - horizontalsizer = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(horizontalsizer, sLeftBasicSizerFlags); - - AddTextboxWithCaption(this, horizontalsizer, HEADERSIZE, wxT("Header Size:")); - AddTextboxWithCaption(this, horizontalsizer, YARDSSIZE, wxT("Yards Side:")); - AddTextboxWithCaption(this, horizontalsizer, TEXTSIZE, wxT("Text Side:")); - - horizontalsizer = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(horizontalsizer, sLeftBasicSizerFlags); - - AddTextboxWithCaption(this, horizontalsizer, CONTRATIO, - wxT("Continuity Ratio:")); - - TransferDataToWindow(); -} - -void PSPrintingSetUp::Init() -{ - mFontNames[0] = mConfig.Get_HeadFont(); - mFontNames[1] = mConfig.Get_MainFont(); - mFontNames[2] = mConfig.Get_NumberFont(); - mFontNames[3] = mConfig.Get_ContFont(); - mFontNames[4] = mConfig.Get_BoldFont(); - mFontNames[5] = mConfig.Get_ItalFont(); - mFontNames[6] = mConfig.Get_BoldItalFont(); - mPrintValues[0] = mConfig.Get_HeaderSize(); - mPrintValues[1] = mConfig.Get_YardsSize(); - mPrintValues[2] = mConfig.Get_TextSize(); - mPrintValues[7] = mConfig.Get_ContRatio(); -} - -bool PSPrintingSetUp::TransferDataToWindow() -{ - wxTextCtrl* text = (wxTextCtrl*)FindWindow(HEADFONT); - text->SetValue(mFontNames[0]); - text = (wxTextCtrl*)FindWindow(MAINFONT); - text->SetValue(mFontNames[1]); - text = (wxTextCtrl*)FindWindow(NUMBERFONT); - text->SetValue(mFontNames[2]); - text = (wxTextCtrl*)FindWindow(CONTFONT); - text->SetValue(mFontNames[3]); - text = (wxTextCtrl*)FindWindow(BOLDFONT); - text->SetValue(mFontNames[4]); - text = (wxTextCtrl*)FindWindow(ITALFONT); - text->SetValue(mFontNames[5]); - text = (wxTextCtrl*)FindWindow(BOLDITALFONT); - text->SetValue(mFontNames[6]); - text = (wxTextCtrl*)FindWindow(HEADERSIZE); - wxString buf; - buf.Printf(wxT("%.2f"), mPrintValues[0]); - text->SetValue(buf); - text = (wxTextCtrl*)FindWindow(YARDSSIZE); - buf.Printf(wxT("%.2f"), mPrintValues[1]); - text->SetValue(buf); - text = (wxTextCtrl*)FindWindow(TEXTSIZE); - buf.Printf(wxT("%.2f"), mPrintValues[2]); - text->SetValue(buf); - text = (wxTextCtrl*)FindWindow(CONTRATIO); - buf.Printf(wxT("%.2f"), mPrintValues[7]); - text->SetValue(buf); - - return true; -} - -bool PSPrintingSetUp::TransferDataFromWindow() -{ - // read out the values from the window - wxTextCtrl* text = (wxTextCtrl*)FindWindow(HEADFONT); - mFontNames[0] = text->GetValue(); - text = (wxTextCtrl*)FindWindow(MAINFONT); - mFontNames[1] = text->GetValue(); - text = (wxTextCtrl*)FindWindow(NUMBERFONT); - mFontNames[2] = text->GetValue(); - text = (wxTextCtrl*)FindWindow(CONTFONT); - mFontNames[3] = text->GetValue(); - text = (wxTextCtrl*)FindWindow(BOLDFONT); - mFontNames[4] = text->GetValue(); - text = (wxTextCtrl*)FindWindow(ITALFONT); - mFontNames[5] = text->GetValue(); - text = (wxTextCtrl*)FindWindow(BOLDITALFONT); - mFontNames[6] = text->GetValue(); - text = (wxTextCtrl*)FindWindow(HEADERSIZE); - text->GetValue().ToDouble(&mPrintValues[0]); - text = (wxTextCtrl*)FindWindow(YARDSSIZE); - text->GetValue().ToDouble(&mPrintValues[1]); - text = (wxTextCtrl*)FindWindow(TEXTSIZE); - text->GetValue().ToDouble(&mPrintValues[2]); - text = (wxTextCtrl*)FindWindow(CONTRATIO); - text->GetValue().ToDouble(&mPrintValues[7]); - - // write out the values defaults: - mConfig.Set_HeadFont(mFontNames[0]); - mConfig.Set_MainFont(mFontNames[1]); - mConfig.Set_NumberFont(mFontNames[2]); - mConfig.Set_ContFont(mFontNames[3]); - mConfig.Set_BoldFont(mFontNames[4]); - mConfig.Set_ItalFont(mFontNames[5]); - mConfig.Set_BoldItalFont(mFontNames[6]); - mConfig.Set_HeaderSize(mPrintValues[0]); - mConfig.Set_YardsSize(mPrintValues[1]); - mConfig.Set_TextSize(mPrintValues[2]); - mConfig.Set_ContRatio(mPrintValues[7]); - - return true; -} - -bool PSPrintingSetUp::ClearValuesToDefault() -{ - mConfig.Clear_HeadFont(); - mConfig.Clear_MainFont(); - mConfig.Clear_NumberFont(); - mConfig.Clear_ContFont(); - mConfig.Clear_BoldFont(); - mConfig.Clear_ItalFont(); - mConfig.Clear_BoldItalFont(); - mConfig.Clear_HeaderSize(); - mConfig.Clear_YardsSize(); - mConfig.Clear_TextSize(); - mConfig.Clear_ContRatio(); - Init(); - return TransferDataToWindow(); -} - -//////// Show Mode setup //////// -// setup drawing characteristics -//////// - -const int zoom_amounts[] = { 500, 200, 150, 100, 75, 50, 25, 10 }; - -class ShowModeSetup : public PreferencePage { - DECLARE_CLASS(ShowModeSetup) - DECLARE_EVENT_TABLE() - -public: - 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) - : PreferencePage(config) - { - Init(); - Create(parent, id, caption, pos, size, style); - } - ~ShowModeSetup() {} - - 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 OnCmdLineText(wxCommandEvent&); - void OnCmdChoice(wxCommandEvent&); - CalChartConfiguration::ShowModeInfo_t mShowModeValues[SHOWMODE_NUM]; - CalChart::ShowMode::YardLinesInfo_t mYardText; - int mWhichMode; - int mWhichYardLine; -}; - -enum { - MODE_CHOICE = 1000, - WESTHASH, - EASTHASH, - BORDER_LEFT, - BORDER_TOP, - BORDER_RIGHT, - BORDER_BOTTOM, - OFFSET_X, - OFFSET_Y, - SIZE_X, - SIZE_Y, - SHOW_LINE_MARKING, - SHOW_LINE_VALUE, - CANVAS, -}; - -BEGIN_EVENT_TABLE(ShowModeSetup, PreferencePage) -EVT_CHOICE(MODE_CHOICE, ShowModeSetup::OnCmdChoice) -EVT_CHOICE(SHOW_LINE_MARKING, ShowModeSetup::OnCmdChoice) -END_EVENT_TABLE() - -IMPLEMENT_CLASS(ShowModeSetup, PreferencePage) - -void ShowModeSetup::CreateControls() -{ - wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); - SetSizer(topsizer); - - wxChoice* modes = new wxChoice(this, MODE_CHOICE, wxDefaultPosition, - wxDefaultSize, SHOWMODE_NUM, kShowModeStrings); - modes->SetSelection(0); - topsizer->Add(modes, sLeftBasicSizerFlags); - - wxBoxSizer* sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); - - auto refresh_action = [this](wxCommandEvent&) { - this->TransferDataFromWindow(); - Refresh(); - }; - - AddTextboxWithCaptionAndAction(this, sizer1, WESTHASH, wxT("West Hash"), - refresh_action, wxTE_PROCESS_ENTER); - AddTextboxWithCaptionAndAction(this, sizer1, EASTHASH, wxT("East Hash"), - refresh_action, wxTE_PROCESS_ENTER); - - sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); - AddTextboxWithCaptionAndAction(this, sizer1, BORDER_LEFT, wxT("Left Border"), - refresh_action, wxTE_PROCESS_ENTER); - AddTextboxWithCaptionAndAction(this, sizer1, BORDER_TOP, wxT("Top Border"), - refresh_action, wxTE_PROCESS_ENTER); - AddTextboxWithCaptionAndAction(this, sizer1, BORDER_RIGHT, - wxT("Right Border"), refresh_action, - wxTE_PROCESS_ENTER); - AddTextboxWithCaptionAndAction(this, sizer1, BORDER_BOTTOM, - wxT("Bottom Border"), refresh_action, - wxTE_PROCESS_ENTER); - - sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); - AddTextboxWithCaptionAndAction(this, sizer1, OFFSET_X, wxT("Offset X"), - refresh_action, wxTE_PROCESS_ENTER); - AddTextboxWithCaptionAndAction(this, sizer1, OFFSET_Y, wxT("Offset Y"), - refresh_action, wxTE_PROCESS_ENTER); - AddTextboxWithCaptionAndAction(this, sizer1, SIZE_X, wxT("Size X"), - refresh_action, wxTE_PROCESS_ENTER); - AddTextboxWithCaptionAndAction(this, sizer1, SIZE_Y, wxT("Size Y"), - refresh_action, wxTE_PROCESS_ENTER); - - sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); - 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, - wxArrayString{ mConfig.Get_yard_text_index().size(), mConfig.Get_yard_text_index().data() }); - textchoice->SetSelection(0); - textsizer->Add(textchoice); - auto show_line_value = new wxTextCtrl(this, SHOW_LINE_VALUE, wxEmptyString, wxDefaultPosition, - wxDefaultSize, wxTE_PROCESS_ENTER); - show_line_value->Bind(wxEVT_TEXT_ENTER, refresh_action); - textsizer->Add(show_line_value, sBasicSizerFlags); - - textsizer = new wxBoxSizer(wxHORIZONTAL); - sizer1->Add(textsizer, sBasicSizerFlags); - textsizer->Add(new wxStaticText(this, wxID_STATIC, wxT("Zoom"), - wxDefaultPosition, wxDefaultSize, 0), - 0, wxALIGN_LEFT | wxALL, 5); - wxArrayString zoomtext; - for (auto& i : zoom_amounts) { - wxString buf; - buf.sprintf(wxT("%d%%"), i); - zoomtext.Add(buf); - } - auto zoomBox = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, zoomtext); - zoomBox->Bind(wxEVT_CHOICE, [=](wxCommandEvent& event) { - size_t sel = event.GetInt(); - float zoom_amount = zoom_amounts[sel] / 100.0; - static_cast(FindWindow(CANVAS)) - ->SetZoom(zoom_amount); - }); - - // set the text to the default zoom level - textsizer->Add(zoomBox, sLeftBasicSizerFlags); - - auto modeSetupCanvas = new ShowModeSetupCanvas(mConfig, this, CANVAS); - modeSetupCanvas->SetScrollRate(1, 1); - topsizer->Add(modeSetupCanvas, 1, wxEXPAND); - - modeSetupCanvas->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); - modeSetupCanvas->SetZoom(zoom_amounts[5] / 100.0); - zoomBox->SetSelection(5); - - TransferDataToWindow(); -} - -void ShowModeSetup::Init() -{ - mWhichMode = 0; - mWhichYardLine = 0; - for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - mShowModeValues[i] = mConfig.Get_ShowModeInfo(static_cast(i)); - } - for (size_t i = 0; i < kYardTextValues; ++i) { - mYardText[i] = mConfig.Get_yard_text(i); - } -} - -bool ShowModeSetup::TransferDataToWindow() -{ - // standard show - for (auto i = mShowModeValues[mWhichMode].begin(); - i != mShowModeValues[mWhichMode].end(); ++i) { - wxString buf; - wxTextCtrl* text = (wxTextCtrl*)FindWindow( - WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); - buf.Printf(wxT("%d"), static_cast(*i)); - text->ChangeValue(buf); - } - - wxTextCtrl* text = (wxTextCtrl*)FindWindow(SHOW_LINE_VALUE); - text->SetValue(mYardText[mWhichYardLine]); - return true; -} - -bool ShowModeSetup::TransferDataFromWindow() -{ - // read out the values from the window - // standard show - for (auto i = mShowModeValues[mWhichMode].begin(); - i != mShowModeValues[mWhichMode].end(); ++i) { - long val; - wxTextCtrl* text = (wxTextCtrl*)FindWindow( - WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); - text->GetValue().ToLong(&val); - *i = val; - } - // write out the values defaults: - for (size_t i = 0; i < SHOWMODE_NUM; ++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 < kYardTextValues; ++i) { - mConfig.Set_yard_text(i, mYardText[i]); - } - // now set the canvas - ((ShowModeSetupCanvas*)FindWindow(CANVAS))->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); - - return true; -} - -bool ShowModeSetup::ClearValuesToDefault() -{ - for (size_t i = 0; i < SHOWMODE_NUM; ++i) { - mConfig.Clear_ShowModeInfo(static_cast(i)); - } - for (auto i = 0; i < kYardTextValues; ++i) { - mConfig.Clear_yard_text(i); - } - Init(); - ((ShowModeSetupCanvas*)FindWindow(CANVAS))->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); - return TransferDataToWindow(); -} - -void ShowModeSetup::OnCmdChoice(wxCommandEvent&) -{ - // save off all the old values: - for (auto i = mShowModeValues[mWhichMode].begin(); - i != mShowModeValues[mWhichMode].end(); ++i) { - long val; - wxTextCtrl* text = (wxTextCtrl*)FindWindow( - WESTHASH + std::distance(mShowModeValues[mWhichMode].begin(), i)); - text->GetValue().ToLong(&val); - *i = val; - } - wxChoice* modes = (wxChoice*)FindWindow(MODE_CHOICE); - mWhichMode = modes->GetSelection(); - ShowModeSetupCanvas* canvas = (ShowModeSetupCanvas*)FindWindow(CANVAS); - canvas->SetMode(CalChart::ShowMode::CreateShowMode(mConfig.Get_ShowModeInfo(static_cast(mWhichMode)), mYardText)); - - wxTextCtrl* text = (wxTextCtrl*)FindWindow(SHOW_LINE_VALUE); - mYardText[mWhichYardLine] = text->GetValue(); - // update mode - for (size_t i = 0; i < kYardTextValues; ++i) { - mConfig.Set_yard_text(i, mYardText[i]); - } - - modes = (wxChoice*)FindWindow(SHOW_LINE_MARKING); - mWhichYardLine = modes->GetSelection(); - TransferDataToWindow(); -} - -//////////////// -class ContCellSetup : public PreferencePage { - DECLARE_CLASS(ContCellSetup) - DECLARE_EVENT_TABLE() - -public: - ContCellSetup(CalChartConfiguration& config, wxWindow* parent, - wxWindowID id = wxID_ANY, - const wxString& caption = wxT("ContCell 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 ~ContCellSetup() {} - - 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 OnCmdLongForm(wxCommandEvent&); - void OnCmdFontSize(wxSpinEvent&); - void OnCmdRounding(wxSpinEvent&); - void OnCmdTextPadding(wxSpinEvent&); - void OnCmdBoxPadding(wxSpinEvent&); - void OnCmdSelectWidth(wxSpinEvent&); - - void OnCmdSelectColors(wxCommandEvent&); - void OnCmdChooseNewColor(wxCommandEvent&); - void OnCmdResetColors(wxCommandEvent&); - void SetColor(int selection, const wxColour& color); - - // we can set up the Font, colors, size. - wxBitmapComboBox* nameBox; - wxBrush mContCellBrushes[COLOR_CONTCELLS_NUM]; -}; - -enum { - CHECK_LongForm, - SPIN_Font_Size, - SPIN_Rouding, - SPIN_Text_Padding, - SPIN_Box_Padding, -}; - -BEGIN_EVENT_TABLE(ContCellSetup, PreferencePage) -EVT_CHECKBOX(CHECK_LongForm, ContCellSetup::OnCmdLongForm) -EVT_SPINCTRL(SPIN_Font_Size, ContCellSetup::OnCmdFontSize) -EVT_SPINCTRL(SPIN_Rouding, ContCellSetup::OnCmdRounding) -EVT_SPINCTRL(SPIN_Text_Padding, ContCellSetup::OnCmdTextPadding) -EVT_SPINCTRL(SPIN_Box_Padding, ContCellSetup::OnCmdBoxPadding) -EVT_BUTTON(BUTTON_SELECT, ContCellSetup::OnCmdSelectColors) -EVT_BUTTON(BUTTON_RESTORE, ContCellSetup::OnCmdResetColors) -EVT_COMBOBOX(NEW_COLOR_CHOICE, ContCellSetup::OnCmdChooseNewColor) -END_EVENT_TABLE() - -IMPLEMENT_CLASS(ContCellSetup, PreferencePage) - -template -static auto do_cloning(T const& cont) -{ - std::vector> copied_cont; - for (auto&& i : cont.GetParsedContinuity()) { - copied_cont.emplace_back(i->clone()); - } - return copied_cont; -} - -void ContCellSetup::CreateControls() -{ - auto topsizer = new wxBoxSizer(wxVERTICAL); - SetSizer(topsizer); - - auto boxsizer = new wxStaticBoxSizer( - new wxStaticBox(this, -1, wxT("Color settings")), wxVERTICAL); - topsizer->Add(boxsizer); - - auto horizontalsizer = new wxBoxSizer(wxHORIZONTAL); - boxsizer->Add(horizontalsizer, sLeftBasicSizerFlags); - nameBox = new wxBitmapComboBox( - this, NEW_COLOR_CHOICE, mConfig.GetContCellColorNames().at(0), wxDefaultPosition, - wxDefaultSize, COLOR_CONTCELLS_NUM, mConfig.GetContCellColorNames().data(), - wxCB_READONLY | wxCB_DROPDOWN); - horizontalsizer->Add(nameBox, sBasicSizerFlags); - - for (auto i = 0; i < COLOR_CONTCELLS_NUM; ++i) { - CreateAndSetItemBitmap(nameBox, i, mConfig.Get_ContCellBrushAndPen(static_cast(i)).first); - } - nameBox->SetSelection(0); - - horizontalsizer = new wxBoxSizer(wxHORIZONTAL); - boxsizer->Add(horizontalsizer, sLeftBasicSizerFlags); - horizontalsizer->Add(new wxButton(this, BUTTON_SELECT, wxT("&Change Color")), sBasicSizerFlags); - horizontalsizer->Add(new wxButton(this, BUTTON_RESTORE, wxT("&Reset Color")), sBasicSizerFlags); - - horizontalsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Cont Cell settings")), wxHORIZONTAL); - topsizer->Add(horizontalsizer); - - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Long form")), wxVERTICAL); - horizontalsizer->Add(boxsizer, sBasicSizerFlags); - auto checkbox = new wxCheckBox(this, CHECK_LongForm, wxT("Long form")); - checkbox->SetValue(mConfig.Get_ContCellLongForm()); - boxsizer->Add(checkbox, sBasicSizerFlags); - - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Font Size")), wxVERTICAL); - horizontalsizer->Add(boxsizer, sBasicSizerFlags); - auto spin = new wxSpinCtrl(this, SPIN_Font_Size, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 30, mConfig.Get_ContCellFontSize()); - boxsizer->Add(spin, sBasicSizerFlags); - - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Rounding")), wxVERTICAL); - horizontalsizer->Add(boxsizer, sBasicSizerFlags); - spin = new wxSpinCtrl(this, SPIN_Rouding, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mConfig.Get_ContCellRounding()); - boxsizer->Add(spin, sBasicSizerFlags); - - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Text Padding")), wxVERTICAL); - horizontalsizer->Add(boxsizer, sBasicSizerFlags); - spin = new wxSpinCtrl(this, SPIN_Text_Padding, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mConfig.Get_ContCellTextPadding()); - boxsizer->Add(spin, sBasicSizerFlags); - - boxsizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Box Padding")), wxVERTICAL); - horizontalsizer->Add(boxsizer, sBasicSizerFlags); - spin = new wxSpinCtrl(this, SPIN_Box_Padding, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 10, mConfig.Get_ContCellBoxPadding()); - boxsizer->Add(spin, sBasicSizerFlags); - - auto canvas = new ContinuityBrowserPanel(SYMBOL_PLAIN, mConfig, this); - topsizer->Add(canvas, 1, wxEXPAND); - auto basic_cont = CalChart::Continuity{ "ewns np\nX = distfrom(sp r2)\nmt (24-X)w\nmarch gv dist(np) dir(np) w\nmtrm e" }; - auto clonedOut = do_cloning(basic_cont); - clonedOut.emplace_back(std::make_unique(std::make_unique(), std::make_unique())); - canvas->DoSetContinuity(CalChart::Continuity{ std::move(clonedOut) }); - - TransferDataToWindow(); -} - -void ContCellSetup::Init() -{ - // first read out the defaults: - for (auto i = 0; i < COLOR_CONTCELLS_NUM; ++i) { - auto brushAndPen = mConfig.Get_ContCellBrushAndPen(static_cast(i)); - mContCellBrushes[i] = brushAndPen.first; - } -} - -bool ContCellSetup::TransferDataToWindow() -{ - return true; -} - -bool ContCellSetup::TransferDataFromWindow() -{ - return true; -} - -bool ContCellSetup::ClearValuesToDefault() -{ - mConfig.Clear_ContCellLongForm(); - mConfig.Clear_ContCellFontSize(); - mConfig.Clear_ContCellRounding(); - mConfig.Clear_ContCellTextPadding(); - mConfig.Clear_ContCellBoxPadding(); - - for (ContCellColors i = COLOR_CONTCELLS_PROC; i < COLOR_CONTCELLS_NUM; i = static_cast(static_cast(i) + 1)) { - SetColor(i, mConfig.GetContCellDefaultColors()[i]); - mConfig.Clear_ContCellConfigColor(i); - } - Init(); - TransferDataToWindow(); - return true; -} - -void ContCellSetup::OnCmdLongForm(wxCommandEvent& e) -{ - mConfig.Set_ContCellLongForm(e.IsChecked()); - Refresh(); -} - -void ContCellSetup::OnCmdFontSize(wxSpinEvent& e) -{ - mConfig.Set_ContCellFontSize(e.GetValue()); - Refresh(); -} - -void ContCellSetup::OnCmdRounding(wxSpinEvent& e) -{ - mConfig.Set_ContCellRounding(e.GetValue()); - Refresh(); -} - -void ContCellSetup::OnCmdTextPadding(wxSpinEvent& e) -{ - mConfig.Set_ContCellTextPadding(e.GetValue()); - Refresh(); -} - -void ContCellSetup::OnCmdBoxPadding(wxSpinEvent& e) -{ - mConfig.Set_ContCellBoxPadding(e.GetValue()); - Refresh(); -} - -void ContCellSetup::SetColor(int selection, const wxColour& color) -{ - auto pen = *wxThePenList->FindOrCreatePen(color, 1, wxPENSTYLE_SOLID); - mContCellBrushes[selection] = *wxTheBrushList->FindOrCreateBrush(color, wxBRUSHSTYLE_SOLID); - - mConfig.Set_ContCellBrushAndPen(static_cast(selection), - mContCellBrushes[selection], - pen); - - // update the namebox list - CreateAndSetItemBitmap(nameBox, selection, mContCellBrushes[selection]); - Refresh(); -} - -void ContCellSetup::OnCmdSelectColors(wxCommandEvent&) -{ - int selection = nameBox->GetSelection(); - wxColourData data; - data.SetChooseFull(true); - data.SetColour(mContCellBrushes[selection].GetColour()); - wxColourDialog dialog(this, &data); - if (dialog.ShowModal() == wxID_OK) { - wxColourData retdata = dialog.GetColourData(); - wxColour c = retdata.GetColour(); - SetColor(selection, c); - } - Refresh(); -} - -void ContCellSetup::OnCmdResetColors(wxCommandEvent&) -{ - int selection = nameBox->GetSelection(); - SetColor(selection, mConfig.GetContCellDefaultColors()[selection]); - mConfig.Clear_ContCellConfigColor(static_cast(selection)); - Refresh(); -} - -void ContCellSetup::OnCmdChooseNewColor(wxCommandEvent&) -{ - Refresh(); -} - -//////////////// - -BEGIN_EVENT_TABLE(CalChartPreferences, wxDialog) -EVT_BUTTON(wxID_RESET, CalChartPreferences::OnCmdResetAll) -END_EVENT_TABLE() - -IMPLEMENT_CLASS(CalChartPreferences, wxDialog) - -CalChartPreferences::CalChartPreferences(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style) - : wxDialog(parent, id, caption, pos, size, style) - , mConfig(CalChartConfiguration::GetGlobalConfig()) -{ - auto topsizer = new wxBoxSizer(wxVERTICAL); - SetSizer(topsizer); - - mNotebook = new wxNotebook(this, wxID_ANY); - topsizer->Add(mNotebook, sBasicSizerFlags); - - mNotebook->AddPage(new GeneralSetup(mConfig, mNotebook, wxID_ANY), wxT("General")); - mNotebook->AddPage(new ContCellSetup(mConfig, mNotebook, wxID_ANY), wxT("Continuity")); - mNotebook->AddPage(new DrawingSetup(mConfig, mNotebook, wxID_ANY), wxT("Drawing")); - mNotebook->AddPage(new PSPrintingSetUp(mConfig, mNotebook, wxID_ANY), wxT("PS Printing")); - mNotebook->AddPage(new ShowModeSetup(mConfig, mNotebook, wxID_ANY), wxT("Show Mode Setup")); - - // the buttons on the bottom - wxBoxSizer* okCancelBox = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(okCancelBox, sBasicSizerFlags); - - okCancelBox->Add(new wxButton(this, wxID_APPLY), sBasicSizerFlags); - okCancelBox->Add(new wxButton(this, wxID_RESET, wxT("&Reset All")), sBasicSizerFlags); - okCancelBox->Add(new wxButton(this, wxID_OK), sBasicSizerFlags); - okCancelBox->Add(new wxButton(this, wxID_CANCEL), sBasicSizerFlags); - - // This fits the dalog to the minimum size dictated by the sizers - GetSizer()->Fit(this); - // This ensures that the dialog cannot be smaller than the minimum size - GetSizer()->SetSizeHints(this); - Center(); -} - -bool CalChartPreferences::TransferDataToWindow() { return true; } - -bool CalChartPreferences::TransferDataFromWindow() -{ - // transfer everything to the config... - size_t pages = mNotebook->GetPageCount(); - for (size_t i = 0; i < pages; ++i) { - PreferencePage* page = static_cast(mNotebook->GetPage(i)); - page->TransferDataFromWindow(); - } - CalChartConfiguration::AssignConfig(mConfig); - return true; -} - -void CalChartPreferences::OnCmdResetAll(wxCommandEvent&) -{ - // transfer everything to the config... - size_t pages = mNotebook->GetPageCount(); - for (size_t i = 0; i < pages; ++i) { - PreferencePage* page = static_cast(mNotebook->GetPage(i)); - page->ClearValuesToDefault(); - } - CalChartConfiguration::AssignConfig(mConfig); -} diff --git a/src/confgr.cpp b/src/confgr.cpp index 2dff28bc..6578f277 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -449,6 +449,10 @@ IMPLEMENT_CONFIGURATION_FUNCTIONS(AnimationFrameOmniAnimation, bool, false); IMPLEMENT_CONFIGURATION_FUNCTIONS(AnimationFrameSplitScreen, bool, true); IMPLEMENT_CONFIGURATION_FUNCTIONS(AnimationFrameSplitVertical, bool, false); +IMPLEMENT_CONFIGURATION_FUNCTIONS(UseSprites, bool, false); +IMPLEMENT_CONFIGURATION_FUNCTIONS(SpriteBitmapScale, double, 0.5); +IMPLEMENT_CONFIGURATION_FUNCTIONS(SpriteBitmapOffsetY, double, 0.5); + IMPLEMENT_CONFIGURATION_FUNCTIONS(ScrollDirectionNatural, bool, true); IMPLEMENT_CONFIGURATION_FUNCTIONS(CommandUndoSetSheet, bool, false); diff --git a/src/confgr.h b/src/confgr.h index fda97474..eaccd38f 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -203,6 +203,10 @@ private: \ DECLARE_CONFIGURATION_FUNCTIONS(AnimationFrameSplitScreen, bool); DECLARE_CONFIGURATION_FUNCTIONS(AnimationFrameSplitVertical, bool); + DECLARE_CONFIGURATION_FUNCTIONS(UseSprites, bool); + DECLARE_CONFIGURATION_FUNCTIONS(SpriteBitmapScale, double); + DECLARE_CONFIGURATION_FUNCTIONS(SpriteBitmapOffsetY, double); + DECLARE_CONFIGURATION_FUNCTIONS(ScrollDirectionNatural, bool); DECLARE_CONFIGURATION_FUNCTIONS(CommandUndoSetSheet, bool); diff --git a/src/core/animate.cpp b/src/core/animate.cpp index 0e6e27e3..d44e9a2d 100644 --- a/src/core/animate.cpp +++ b/src/core/animate.cpp @@ -359,10 +359,31 @@ bool Animation::CurrentBeatHasCollision() const Animation::animate_info_t Animation::GetAnimateInfo(int which) const { - return Animation::animate_info_t( + return { + which, mCollisions.count({ which, mCurrentSheetNumber, mCurrentBeatNumber }) ? mCollisions.find({ which, mCurrentSheetNumber, mCurrentBeatNumber })->second : Coord::COLLISION_NONE, GetCommand(mCurrentSheetNumber, which).Direction(), - GetCommand(mCurrentSheetNumber, which).RealDirection(), mPoints.at(which)); + GetCommand(mCurrentSheetNumber, which).RealDirection(), mPoints.at(which)}; +} + +std::vector Animation::GetAllAnimateInfo() const +{ + auto points = std::vector(mPoints.size()); + std::iota(points.begin(), points.end(), 0); + auto animates = std::vector(); + std::transform(points.begin(), points.end(), std::back_inserter(animates), [this](auto which) -> Animation::animate_info_t { + return { + which, + mCollisions.count({ which, mCurrentSheetNumber, mCurrentBeatNumber }) ? mCollisions.find({ which, mCurrentSheetNumber, mCurrentBeatNumber })->second : Coord::COLLISION_NONE, + GetCommand(mCurrentSheetNumber, which).Direction(), + GetCommand(mCurrentSheetNumber, which).RealDirection(), mPoints.at(which) + }; + }); + std::sort(animates.begin(), animates.end(), [](auto& a, auto& b) { + return a.mPosition < b.mPosition; + }); + return animates; + } int Animation::GetNumberSheets() const { return static_cast(mSheets.size()); } diff --git a/src/core/animate.h b/src/core/animate.h index 7cd3101f..80c49cbf 100644 --- a/src/core/animate.h +++ b/src/core/animate.h @@ -120,20 +120,16 @@ class Animation { // For drawing: struct animate_info_t { + int index; int mCollision; AnimateDir mDirection; float mRealDirection; Coord mPosition; - animate_info_t(int col, AnimateDir dir, float rdir, Coord pos) - : mCollision(col) - , mDirection(dir) - , mRealDirection(rdir) - , mPosition(pos) - { - } }; animate_info_t GetAnimateInfo(int which) const; + std::vector GetAllAnimateInfo() const; + int GetNumberSheets() const; auto GetCurrentSheet() const { return mCurrentSheetNumber; } auto GetNumberBeats() const { return mSheets.at(mCurrentSheetNumber).GetNumBeats(); } diff --git a/src/core/math_utils.cpp b/src/core/math_utils.cpp index 4a66769b..2210796e 100644 --- a/src/core/math_utils.cpp +++ b/src/core/math_utils.cpp @@ -28,17 +28,6 @@ #include #include -float BoundDirection(float f) -{ - while (f >= 360.0) - f -= 360.0; - while (f < 0.0) - f += 360.0; - return f; -} - -float NormalizeAngle(float ang) { return BoundDirection(ang); } - float BoundDirectionSigned(float f) { while (f >= 180.0) diff --git a/src/core/math_utils.h b/src/core/math_utils.h index f8ed0059..053dfd8f 100644 --- a/src/core/math_utils.h +++ b/src/core/math_utils.h @@ -46,8 +46,19 @@ T Deg2Rad(const T& a) { return a * M_PI / 180.0; } #define SQRT2 1.4142136 -float BoundDirection(float f); -float NormalizeAngle(float ang); +template +T BoundDirection(T f) +{ + while (f >= 360.0) + f -= 360.0; + while (f < 0.0) + f += 360.0; + return f; +} + +template +T NormalizeAngle(T ang) { return BoundDirection(ang); } + float BoundDirectionSigned(float f); diff --git a/src/mode_dialog.cpp b/src/mode_dialog.cpp index 771b6a89..02cf3852 100644 --- a/src/mode_dialog.cpp +++ b/src/mode_dialog.cpp @@ -1,5 +1,5 @@ /* - * cc_preferences_ui.cpp + * mode_dialog.cpp * Dialox box for preferences */ @@ -27,8 +27,6 @@ #include "modes.h" // convience sizers to change the view behavior in all at once. -static auto sBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Center().Proportion(0); -static auto sLeftBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Left().Proportion(0); static auto sRightBasicSizerFlags = wxSizerFlags().Border(wxALL, 2).Right().Proportion(0); static auto sExpandSizerFlags = wxSizerFlags().Border(wxALL, 2).Center().Proportion(0); @@ -40,13 +38,13 @@ void AddTextboxWithCaptionAndAction(wxWindow* parent, wxBoxSizer* verticalsizer, wxBoxSizer* textsizer = new wxBoxSizer(wxVERTICAL); textsizer->Add(new wxStaticText(parent, wxID_STATIC, caption, wxDefaultPosition, wxDefaultSize, 0), - sLeftBasicSizerFlags); + LeftBasicSizerFlags()); auto textCtrl = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, style); textCtrl->Bind((style & wxTE_PROCESS_ENTER) ? wxEVT_TEXT_ENTER : wxEVT_TEXT, f); - textsizer->Add(textCtrl, sBasicSizerFlags); - verticalsizer->Add(textsizer, sBasicSizerFlags); + textsizer->Add(textCtrl, BasicSizerFlags()); + verticalsizer->Add(textsizer, BasicSizerFlags()); } //////// Show Mode setup //////// @@ -135,10 +133,10 @@ void ShowModeDialogSetup::CreateControls() wxChoice* modes = new wxChoice(this, MODE_CHOICE, wxDefaultPosition, wxDefaultSize, choices.size(), choices.data()); modes->SetSelection(0); - topsizer->Add(modes, sLeftBasicSizerFlags); + topsizer->Add(modes, LeftBasicSizerFlags()); wxBoxSizer* sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); + topsizer->Add(sizer1, LeftBasicSizerFlags()); auto refresh_action = [this](wxCommandEvent&) { this->TransferDataFromWindow(); @@ -151,7 +149,7 @@ void ShowModeDialogSetup::CreateControls() refresh_action, wxTE_PROCESS_ENTER); sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); + topsizer->Add(sizer1, LeftBasicSizerFlags()); AddTextboxWithCaptionAndAction(this, sizer1, BORDER_LEFT, wxT("Left Border"), refresh_action, wxTE_PROCESS_ENTER); AddTextboxWithCaptionAndAction(this, sizer1, BORDER_TOP, wxT("Top Border"), @@ -164,7 +162,7 @@ void ShowModeDialogSetup::CreateControls() wxTE_PROCESS_ENTER); sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); + topsizer->Add(sizer1, LeftBasicSizerFlags()); AddTextboxWithCaptionAndAction(this, sizer1, OFFSET_X, wxT("Offset X"), refresh_action, wxTE_PROCESS_ENTER); AddTextboxWithCaptionAndAction(this, sizer1, OFFSET_Y, wxT("Offset Y"), @@ -175,9 +173,9 @@ void ShowModeDialogSetup::CreateControls() refresh_action, wxTE_PROCESS_ENTER); sizer1 = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(sizer1, sLeftBasicSizerFlags); + topsizer->Add(sizer1, LeftBasicSizerFlags()); wxBoxSizer* textsizer = new wxBoxSizer(wxHORIZONTAL); - sizer1->Add(textsizer, sBasicSizerFlags); + sizer1->Add(textsizer, BasicSizerFlags()); textsizer->Add(new wxStaticText(this, wxID_STATIC, wxT("Adjust yardline marker"), wxDefaultPosition, wxDefaultSize, 0), @@ -189,10 +187,10 @@ void ShowModeDialogSetup::CreateControls() auto show_line_value = new wxTextCtrl(this, SHOW_LINE_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); show_line_value->Bind(wxEVT_TEXT_ENTER, refresh_action); - textsizer->Add(show_line_value, sBasicSizerFlags); + textsizer->Add(show_line_value, BasicSizerFlags()); textsizer = new wxBoxSizer(wxHORIZONTAL); - sizer1->Add(textsizer, sBasicSizerFlags); + sizer1->Add(textsizer, BasicSizerFlags()); textsizer->Add(new wxStaticText(this, wxID_STATIC, wxT("Zoom"), wxDefaultPosition, wxDefaultSize, 0), 0, wxALIGN_LEFT | wxALL, 5); @@ -211,7 +209,7 @@ void ShowModeDialogSetup::CreateControls() }); // set the text to the default zoom level - textsizer->Add(zoomBox, sLeftBasicSizerFlags); + textsizer->Add(zoomBox, LeftBasicSizerFlags()); auto modeSetupCanvas = new ShowModeSetupCanvas(mConfig, this, CANVAS); modeSetupCanvas->SetScrollRate(1, 1); @@ -308,14 +306,14 @@ ModeSetupDialog::ModeSetupDialog(CalChart::ShowMode const& current_mode, wxWindo m_setup = new ShowModeDialogSetup(current_mode, this, wxID_ANY); - topsizer->Add(m_setup, sBasicSizerFlags); + topsizer->Add(m_setup, BasicSizerFlags()); // the buttons on the bottom wxBoxSizer* okCancelBox = new wxBoxSizer(wxHORIZONTAL); - topsizer->Add(okCancelBox, sBasicSizerFlags); + topsizer->Add(okCancelBox, BasicSizerFlags()); - okCancelBox->Add(new wxButton(this, wxID_CANCEL), sBasicSizerFlags); - okCancelBox->Add(new wxButton(this, wxID_OK), sBasicSizerFlags); + okCancelBox->Add(new wxButton(this, wxID_CANCEL), BasicSizerFlags()); + okCancelBox->Add(new wxButton(this, wxID_OK), BasicSizerFlags()); // This fits the dalog to the minimum size dictated by the sizers GetSizer()->Fit(this); diff --git a/src/mode_dialog_canvas.cpp b/src/mode_dialog_canvas.cpp index 601c902f..24e97d04 100644 --- a/src/mode_dialog_canvas.cpp +++ b/src/mode_dialog_canvas.cpp @@ -1,5 +1,5 @@ /* - * cc_preferences_ui.cpp + * mode_dialog_canvas.cpp * Dialox box for preferences */