diff --git a/LATEST_RELEASE_NOTES.md b/LATEST_RELEASE_NOTES.md index f62cdf86..030101bb 100644 --- a/LATEST_RELEASE_NOTES.md +++ b/LATEST_RELEASE_NOTES.md @@ -8,6 +8,7 @@ Bugs addressed in this release: Other changes: +* [#677](../../issues/677) We should have a print configuration * [#714](../../issues/714) When adding continuities, writing R1 and pressing return should select the R1 tile (Ref Point 1 in the dropdown) * [#760](../../issues/760) Switch away from VCPKG_OVERLAY_PORTS when we can * [#773](../../issues/773) Add the minimal integration of CalChart-Viewer diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 59d81d16..70528a78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -139,6 +139,8 @@ add_executable( PreferencesGeneralSetup.h PreferencesPrintContinuitySetup.cpp PreferencesPrintContinuitySetup.h + PreferencesPrintingSetup.cpp + PreferencesPrintingSetup.hpp PreferencesPSPrintingSetup.cpp PreferencesPSPrintingSetup.h PreferencesShowModeSetup.cpp @@ -149,6 +151,8 @@ add_executable( PrintContinuityEditor.h PrintContinuityPreview.cpp PrintContinuityPreview.h + PrintingPreview.cpp + PrintingPreview.hpp PrintPostScriptDialog.cpp PrintPostScriptDialog.h SetupInstruments.cpp diff --git a/src/CalChartDrawing.cpp b/src/CalChartDrawing.cpp index 1ca5fb93..d2e3d484 100644 --- a/src/CalChartDrawing.cpp +++ b/src/CalChartDrawing.cpp @@ -411,7 +411,8 @@ auto CalculatePointsPerLine( namespace { auto GeneratePrintField( CalChart::Configuration const& config, - CalChartDoc const& show, + CalChart::ShowMode const& mode, + std::vector const& labels, CalChart::Sheet const& sheet, int ref, bool landscape) -> std::tuple> @@ -420,20 +421,20 @@ namespace { // create a field for drawing: const auto pts = sheet.GetAllMarchers(); auto boundingBox = GetMarcherBoundingBox(pts); - auto mode = show.GetShowMode().CreateFieldForPrinting(CalChart::CoordUnits2Int(boundingBox.first.x), CalChart::CoordUnits2Int(boundingBox.second.x), landscape); - auto drawCmds = CalChart::CreateModeDrawCommandsWithBorder(config, mode, CalChart::HowToDraw::Printing); + auto printMode = mode.CreateFieldForPrinting(CalChart::CoordUnits2Int(boundingBox.first.x), CalChart::CoordUnits2Int(boundingBox.second.x), landscape); + auto drawCmds = CalChart::CreateModeDrawCommandsWithBorder(config, printMode, CalChart::HowToDraw::Printing); auto pointBrush = CalChart::Brush{ CalChart::Color::Black() }; CalChart::append(drawCmds, CalChart::Draw::withBrush( pointBrush, CalChart::Draw::toDrawCommands(std::views::iota(0u, pts.size()) | std::views::transform([&](auto i) { - return pts.at(i).GetDrawCommands(ref, show.GetPointLabel(i), config); + return pts.at(i).GetDrawCommands(ref, labels.at(i), config); }) | std::views::join) - + mode.Offset())); + + printMode.Offset()); - return { static_cast(mode.Size().x), drawCmds }; + return { static_cast(printMode.Size().x), drawCmds }; } auto GenerateLargePrintElements(bool landscape, wxSize page, std::string sheetName) @@ -482,75 +483,97 @@ namespace { } } -void DrawForPrintingHelper( +void DrawForPrintingContinuity( wxDC& dc, + wxSize pageSize, CalChart::Configuration const& config, CalChart::Sheet const& sheet, - bool landscape, - double scale_x, - std::vector fieldDrawCommand) + bool landscape) { // set up everything to be restored after we print SaveAndRestore::DeviceOrigin orig_dev(dc); SaveAndRestore::UserScale orig_scale(dc); SaveAndRestore::Font orig_font(dc); - // get the page dimensions - auto page = dc.GetSize(); - // a possible future optimization would be to generate this ahead of time. auto printLayout = CalChart::PrintContinuityLayout::Parse(sheet.GetRawPrintContinuity()); - auto printDrawCommands = GenerateDrawCommands(dc, config, printLayout, wxRect(wxPoint(10, page.y * kContinuityStart[landscape]), wxSize(page.x - 20, page.y - page.y * kContinuityStart[landscape])), landscape); - - dc.Clear(); - dc.SetLogicalFunction(wxCOPY); - - // Print the field: + auto printDrawCommands = GenerateDrawCommands(dc, config, printLayout, wxRect(wxPoint(10, pageSize.y * kContinuityStart[landscape]), wxSize(pageSize.x - 20, pageSize.y - pageSize.y * kContinuityStart[landscape])), landscape); - // set the origin and scaling for drawing the field - dc.SetDeviceOrigin(kFieldBorderOffset * page.x, kFieldTop * page.y); - - // create a field for drawing: - auto scale = tDIP(page.x - 2 * kFieldBorderOffset * page.x) / scale_x; - // Because we are drawing to a bitmap, DIP isn't happening. So we compensate by changing the scaling. - dc.SetUserScale(scale, scale); + // set the page for drawing: + auto sizeX = (landscape) ? kSizeXLandscape : kSizeX; + auto sizeY = (landscape) ? kSizeYLandscape : kSizeY; + // because we are drawing to a bitmap, we manipulate the scaling factor so it just draws as normal + dc.SetUserScale(tDIP(pageSize.x) / sizeX, tDIP(pageSize.y) / sizeY); + pageSize.x = fDIP(sizeX); + pageSize.y = fDIP(sizeY); - // draw the field. - wxCalChart::Draw::DrawCommandList(dc, fieldDrawCommand); + // now draw the continuity into its own box. It uses Stack layout so needs to have a constrained area. + wxCalChart::Draw::DrawCommandList(dc, + wxCalChart::Draw::DrawSurface{ + { 0, 0 }, + wxSize(pageSize.x - 20, pageSize.y * (1 - kContinuityStart[landscape])) }, + std::vector{ printDrawCommands } + CalChart::Coord(10, pageSize.y * kContinuityStart[landscape])); +} - // now reset everything to draw the rest of the text - dc.SetDeviceOrigin(CalChart::Int2CoordUnits(0), CalChart::Int2CoordUnits(0)); - dc.SetBrush(*wxTRANSPARENT_BRUSH); +void DrawForPrintingElements( + wxDC& dc, + wxSize pageSize, + CalChart::Sheet const& sheet, + bool landscape) +{ + // set up everything to be restored after we print + SaveAndRestore::DeviceOrigin orig_dev(dc); + SaveAndRestore::UserScale orig_scale(dc); + SaveAndRestore::Font orig_font(dc); - // set the page for drawing: - page = dc.GetSize(); auto sizeX = (landscape) ? kSizeXLandscape : kSizeX; auto sizeY = (landscape) ? kSizeYLandscape : kSizeY; // because we are drawing to a bitmap, we manipulate the scaling factor so it just draws as normal - dc.SetUserScale(tDIP(page.x) / sizeX, tDIP(page.y) / sizeY); - page.x = fDIP(sizeX); - page.y = fDIP(sizeY); + dc.SetUserScale(tDIP(pageSize.x) / sizeX, tDIP(pageSize.y) / sizeY); + pageSize.x = fDIP(sizeX); + pageSize.y = fDIP(sizeY); auto drawCmds = std::vector{}; CalChart::append(drawCmds, CalChart::Draw::withFont( CalChart::Font{ 16, CalChart::Font::Family::Roman, CalChart::Font::Style::Normal, CalChart::Font::Weight::Bold }, - GenerateLargePrintElements(landscape, page, sheet.GetPrintNumber()))); + GenerateLargePrintElements(landscape, pageSize, sheet.GetPrintNumber()))); CalChart::append(drawCmds, CalChart::Draw::withFont( CalChart::Font{ 8 }, GeneratePrintElements( landscape, - page))); + pageSize))); wxCalChart::Draw::DrawCommandList(dc, drawCmds); - // now draw the continuity into its own box. It uses Stack layout so needs to have a constrained area. - wxCalChart::Draw::DrawCommandList(dc, - wxCalChart::Draw::DrawSurface{ - { 0, 0 }, - wxSize(page.x - 20, page.y * (1 - kContinuityStart[landscape])) }, - std::vector{ printDrawCommands } + CalChart::Coord(10, page.y * kContinuityStart[landscape])); +} + +void DrawForPrintingField( + wxDC& dc, + wxSize pageSize, + CalChart::Configuration const& config, + CalChart::ShowMode const& mode, + std::vector const& labels, + CalChart::Sheet const& sheet, + int ref, + bool landscape) +{ + auto [scale_x, fieldDrawCommand] = GeneratePrintField(config, mode, labels, sheet, ref, landscape); + // set up everything to be restored after we print + SaveAndRestore::DeviceOrigin orig_dev(dc); + SaveAndRestore::UserScale orig_scale(dc); + SaveAndRestore::Font orig_font(dc); + + // create a field for drawing: + auto scale = tDIP(pageSize.x - 2 * kFieldBorderOffset * pageSize.x) / scale_x; + // Because we are drawing to a bitmap, DIP isn't happening. So we compensate by changing the scaling. + dc.SetUserScale(scale, scale); + // and because we've scaled, the offset needs to be scaled. + auto offset = CalChart::Coord(kFieldBorderOffset * pageSize.x, kFieldTop * pageSize.y) / scale; + + // draw the field. + wxCalChart::Draw::DrawCommandList(dc, fieldDrawCommand + offset); } auto GenerateDrawCommands(wxDC& dc, @@ -608,8 +631,13 @@ void DrawForPrinting(wxDC* printerdc, CalChart::Configuration const& config, Cal wxBitmap membm(bitmapWidth, bitmapHeight); // first convert to image wxMemoryDC memdc(membm); - auto [scale_x, drawCmds1] = GeneratePrintField(config, show, sheet, ref, should_landscape); - DrawForPrintingHelper(memdc, config, sheet, should_landscape, scale_x, drawCmds1); + memdc.Clear(); + memdc.SetLogicalFunction(wxCOPY); + memdc.SetBrush(*wxTRANSPARENT_BRUSH); + + DrawForPrintingElements(memdc, memdc.GetSize(), sheet, should_landscape); + DrawForPrintingContinuity(memdc, memdc.GetSize(), config, sheet, should_landscape); + DrawForPrintingField(memdc, memdc.GetSize(), config, show.GetShowMode(), show.GetPointsLabel(), sheet, ref, should_landscape); auto image = membm.ConvertToImage(); if (forced_landscape) { diff --git a/src/CalChartDrawing.h b/src/CalChartDrawing.h index 92466190..aed686ea 100644 --- a/src/CalChartDrawing.h +++ b/src/CalChartDrawing.h @@ -45,6 +45,7 @@ struct Textline; using Textline_list = std::vector; class Point; class Configuration; +class ShowMode; } class CalChartDoc; @@ -61,6 +62,29 @@ auto GenerateDrawCommands(wxDC& dc, void DrawForPrinting(wxDC* dc, CalChart::Configuration const& config, CalChartDoc const& show, CalChart::Sheet const& sheet, int ref, bool landscape); +void DrawForPrintingContinuity( + wxDC& dc, + wxSize pageSize, + CalChart::Configuration const& config, + CalChart::Sheet const& sheet, + bool landscape); + +void DrawForPrintingElements( + wxDC& dc, + wxSize pageSize, + CalChart::Sheet const& sheet, + bool landscape); + +void DrawForPrintingField( + wxDC& dc, + wxSize pageSize, + CalChart::Configuration const& config, + CalChart::ShowMode const& mode, + std::vector const& labels, + CalChart::Sheet const& sheet, + int ref, + bool landscape); + } namespace wxCalChart::Draw { diff --git a/src/CalChartPreferences.cpp b/src/CalChartPreferences.cpp index c0fa4ac7..80082d2a 100644 --- a/src/CalChartPreferences.cpp +++ b/src/CalChartPreferences.cpp @@ -26,6 +26,7 @@ #include "PreferencesGeneralSetup.h" #include "PreferencesPSPrintingSetup.h" #include "PreferencesPrintContinuitySetup.h" +#include "PreferencesPrintingSetup.hpp" #include "PreferencesShowModeSetup.h" #include "PreferencesUtils.h" #include @@ -69,6 +70,7 @@ CalChartPreferences::CalChartPreferences(wxWindow* parent, CalChart::Configurati mNotebook->AddPage(ContCellSetup::CreatePreference(mConfig, mNotebook), wxT("Continuity")); mNotebook->AddPage(DrawingSetup::CreatePreference(mConfig, mNotebook), wxT("Drawing")); mNotebook->AddPage(ShowModeSetup::CreatePreference(mConfig, mNotebook), wxT("Show Mode Setup")); + mNotebook->AddPage(PrintingSetup::CreatePreference(mConfig, mNotebook), wxT("Printing")); mNotebook->AddPage(PrintContinuitySetup::CreatePreference(mConfig, mNotebook), wxT("Print Continuity Setup")); mNotebook->AddPage(PSPrintingSetUp::CreatePreference(mConfig, mNotebook), wxT("PS Printing")); return mNotebook; diff --git a/src/PreferencesPrintingSetup.cpp b/src/PreferencesPrintingSetup.cpp new file mode 100644 index 00000000..4572dbaf --- /dev/null +++ b/src/PreferencesPrintingSetup.cpp @@ -0,0 +1,165 @@ +/* + * CalChartPrintingSetup.cpp + * Dialox box for PrintContinuity Setup part of preferences + */ + +/* + Copyright (C) 1995-2024 Garrick Brian Meeker, Richard Michael Powell + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + 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 "PreferencesPrintingSetup.hpp" +#include "CalChartConfiguration.h" +#include "CalChartDoc.h" +#include "PrintingPreview.hpp" +#include "basic_ui.h" + +#include +#include +#include +#include +#include +#include + +IMPLEMENT_CLASS(PrintingSetup, PreferencePage) + +enum { + CALCHART__CONT_NEW = 100, + PrintingSetup_KeyPress, + PrintingSetup_DOTRATIO, + PrintingSetup_PLINERATIO, + PrintingSetup_SLINERATIO, +}; + +BEGIN_EVENT_TABLE(PrintingSetup, PrintingSetup::super) +EVT_TEXT(PrintingSetup_KeyPress, PrintingSetup::OnKeyPress) +EVT_TEXT_ENTER(PrintingSetup_DOTRATIO, PrintingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(PrintingSetup_PLINERATIO, PrintingSetup::OnCmdTextChanged) +EVT_TEXT_ENTER(PrintingSetup_SLINERATIO, PrintingSetup::OnCmdTextChanged) +END_EVENT_TABLE() + +void PrintingSetup::CreateControls() +{ + wxUI::VSizer{ + wxSizerFlags{}.Border(wxALL, 2), + wxUI::HSizer{ + wxUI::CheckBox{ "Landscape" } + .bind([this] { + mPrintingDisplay->SetOrientation(*mLandscape); + Refresh(); + }) + .withProxy(mLandscape), + }, + wxUI::HSizer{ + "Printing details", + VLabelWidget("Symbol Ratio:", wxUI::TextCtrl{ PrintingSetup_DOTRATIO }.withSize({ 100, -1 }).withStyle(wxTE_PROCESS_ENTER).withProxy(mDotRatio)), + VLabelWidget("P-Line Ratio:", wxUI::TextCtrl{ PrintingSetup_PLINERATIO }.withSize({ 100, -1 }).withStyle(wxTE_PROCESS_ENTER).withProxy(mPLineRatio)), + VLabelWidget("S-Line Ratio:", wxUI::TextCtrl{ PrintingSetup_SLINERATIO }.withSize({ 100, -1 }).withStyle(wxTE_PROCESS_ENTER).withProxy(mSLineRatio)), + VLabelWidget("Line Pad:", wxUI::SpinCtrl{ std::pair{ 0, 10 } }.bind([this] { + mConfig.Set_PrintContLinePad(static_cast(*mLinePad)); + Refresh(); + }) + .withProxy(mLinePad)), + VLabelWidget("Max Font Size:", wxUI::SpinCtrl{ std::pair{ 6, 30 } }.bind([this] { + mConfig.Set_PrintContMaxFontSize(static_cast(*mMaxFontSize)); + Refresh(); + }) + .withProxy(mMaxFontSize)), + }, + mPrintingDisplay = wxUI::Generic{ + wxSizerFlags{ 1 }.Expand(), + [this](wxWindow* parent) { return new PrintingPreview(parent, mConfig); } }, + } + .fitTo(this); + + TransferDataToWindow(); +} + +void PrintingSetup::OnCmdTextChanged(wxCommandEvent& e) +{ + auto id = e.GetId(); + wxTextCtrl* text = (wxTextCtrl*)FindWindow(id); + double value; + if (text->GetValue().ToDouble(&value)) { + switch (id) { + case PrintingSetup_DOTRATIO: + mConfig.Set_PrintContDotRatio(value); + break; + case PrintingSetup_PLINERATIO: + mConfig.Set_PrintContPLineRatio(value); + break; + case PrintingSetup_SLINERATIO: + mConfig.Set_PrintContSLineRatio(value); + break; + } + } + Refresh(); +} + +void PrintingSetup::InitFromConfig() +{ +} + +bool PrintingSetup::TransferDataToWindow() +{ + wxString buf; + wxTextCtrl* text = static_cast(FindWindow(PrintingSetup_DOTRATIO)); + buf.Printf(wxT("%.2f"), mConfig.Get_PrintContDotRatio()); + text->SetValue(buf); + text = static_cast(FindWindow(PrintingSetup_PLINERATIO)); + buf.Printf(wxT("%.2f"), mConfig.Get_PrintContPLineRatio()); + text->SetValue(buf); + text = static_cast(FindWindow(PrintingSetup_SLINERATIO)); + buf.Printf(wxT("%.2f"), mConfig.Get_PrintContSLineRatio()); + text->SetValue(buf); + *mLinePad = mConfig.Get_PrintContLinePad(); + *mMaxFontSize = mConfig.Get_PrintContMaxFontSize(); + + return true; +} + +bool PrintingSetup::TransferDataFromWindow() +{ + double value = 0.0; + if (mDotRatio->GetValue().ToDouble(&value)) { + mConfig.Set_PrintContDotRatio(value); + } + if (mPLineRatio->GetValue().ToDouble(&value)) { + mConfig.Set_PrintContPLineRatio(value); + } + if (mSLineRatio->GetValue().ToDouble(&value)) { + mConfig.Set_PrintContSLineRatio(value); + } + mConfig.Set_PrintContLinePad(*mLinePad); + mConfig.Set_PrintContMaxFontSize(*mMaxFontSize); + return true; +} + +bool PrintingSetup::ClearValuesToDefault() +{ + mConfig.Clear_PrintContUseNewDraw(); + mConfig.Clear_PrintContDotRatio(); + mConfig.Clear_PrintContPLineRatio(); + mConfig.Clear_PrintContSLineRatio(); + mConfig.Clear_PrintContLinePad(); + mConfig.Clear_PrintContMaxFontSize(); + return TransferDataToWindow(); +} + +void PrintingSetup::OnKeyPress(wxCommandEvent&) +{ + // mPrintingDisplay->SetPrintContinuity(CalChart::PrintContinuity("", mUserInput->GetValue())); + Refresh(); +} \ No newline at end of file diff --git a/src/PreferencesPrintingSetup.hpp b/src/PreferencesPrintingSetup.hpp new file mode 100644 index 00000000..27e107fd --- /dev/null +++ b/src/PreferencesPrintingSetup.hpp @@ -0,0 +1,80 @@ +#pragma once +/* + * PreferencesPrintingSetup.h + * Dialox box for PrintContinuity Setup part of preferences + */ + +/* + Copyright (C) 1995-2024 Garrick Brian Meeker, Richard Michael Powell + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + 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 +#include + +class FancyTextWin; +class PrintingPreview; +namespace CalChart { +class Configuration; +} + +class PrintingSetup : public PreferencePage { + using super = PreferencePage; + DECLARE_CLASS(PrintingSetup) + DECLARE_EVENT_TABLE() + +public: + static PrintingSetup* CreatePreference(CalChart::Configuration& config, wxWindow* parent) + { + auto pref = new PrintingSetup(config, parent); + pref->Initialize(); + return pref; + } + +private: + // private, use the CreatePreference method + PrintingSetup(CalChart::Configuration& config, wxWindow* parent) + : super(config, parent, "Print Continuity") + { + } + +public: + ~PrintingSetup() override = default; + + // use these to get and set default values + auto TransferDataToWindow() -> bool override; + auto TransferDataFromWindow() -> bool override; + auto ClearValuesToDefault() -> bool override; + +private: + wxUI::Generic::Proxy mUserInput{}; + wxUI::Generic::Proxy mPrintingDisplay{}; + wxUI::CheckBox::Proxy mLandscape{}; + wxUI::TextCtrl::Proxy mDotRatio{}; + wxUI::TextCtrl::Proxy mPLineRatio{}; + wxUI::TextCtrl::Proxy mSLineRatio{}; + wxUI::SpinCtrl::Proxy mLinePad{}; + wxUI::SpinCtrl::Proxy mMaxFontSize{}; + + void InitFromConfig() override; + void CreateControls() override; + void OnKeyPress(wxCommandEvent&); + void OnCmdTextChanged(wxCommandEvent&); +}; diff --git a/src/PrintingPreview.cpp b/src/PrintingPreview.cpp new file mode 100644 index 00000000..752cb506 --- /dev/null +++ b/src/PrintingPreview.cpp @@ -0,0 +1,110 @@ +/* + * PrintingPreview.cpp + * Continuity editors + */ + +/* + Copyright (C) 1995-2024 Garrick Brian Meeker, Richard Michael Powell + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + 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 "PrintingPreview.hpp" +#include "CalChartConfiguration.h" +#include "CalChartDrawPrimativesHelper.h" +#include "CalChartDrawing.h" +#include "CalChartMeasure.h" +#include "CalChartPrintContinuityLayout.h" +#include "CalChartShow.h" +#include "DCSaveRestore.h" + +BEGIN_EVENT_TABLE(PrintingPreview, PrintingPreview::super) +EVT_SIZE(PrintingPreview::OnSizeEvent) +END_EVENT_TABLE() + +static constexpr double kSizeX = 576, kSizeY = 734; +static constexpr double kSizeXLandscape = 917, kSizeYLandscape = 720; + +static constexpr auto kAspectRatio = kSizeX / kSizeY; +static constexpr auto kAspectRatioLandscape = kSizeXLandscape / kSizeYLandscape; + +static constexpr auto DefaultText + = "~This is a centered line of text\n" + "Normal \\bsBold \\isBold+Italics \\beItalics \\ieNormal\n" + "All the symbols with two tabs\n" + "\t\t\\po:\tplainman\n" + "\t\t\\sx:\tsolidxman\n" + ""; + +PrintingPreview::PrintingPreview(wxWindow* parent, CalChart::Configuration const& config) + : super(config, parent, wxID_ANY, wxDefaultPosition, wxSize(kSizeX, kSizeY / 2)) + , mShow(CalChart::Show::Create(CalChart::ShowMode::GetDefaultShowMode())) + , mLandscape(false) + , mConfig(config) +{ + using namespace CalChart; + mShow->Create_SetupMarchersCommand({ { "A", "A" }, { "B", "B" }, { "C", "C" }, { "D", "D" } }, 1, 0).first(*mShow); + SetVirtualSize(wxSize(kSizeX, kSizeY)); + SetScrollRate(10, 10); + SetBackgroundColour(*wxWHITE); + Connect(wxEVT_PAINT, wxPaintEventHandler(PrintingPreview::OnPaint)); +} + +void PrintingPreview::OnPaint(wxPaintEvent&) +{ + wxPaintDC dc(this); + PrepareDC(dc); + auto virtSize = GetVirtualSize(); + + dc.Clear(); + dc.SetTextForeground(*wxBLACK); + dc.DrawRectangle(wxRect(wxPoint(0, 0), virtSize)); + + auto sheet = CalChart::Sheet(4, "hello"); + sheet.SetPrintableContinuity("Test1", DefaultText); + sheet.SetPosition({ 0, 0 }, 0); + sheet.SetPosition({ 16, 16 }, 1); + sheet.SetPosition({ 32, 32 }, 2); + sheet.SetPosition({ 48, 48 }, 3); + CalChartDraw::DrawForPrintingContinuity(dc, virtSize, mConfig, sheet, mLandscape); + CalChartDraw::DrawForPrintingElements(dc, virtSize, sheet, mLandscape); + CalChartDraw::DrawForPrintingField( + dc, + virtSize, + mConfig, + CalChart::ShowMode::GetDefaultShowMode(), + mShow->GetPointsLabel(), + sheet, + 0, + mLandscape); +} + +void PrintingPreview::SetOrientation(bool landscape) +{ + mLandscape = landscape; + auto size = GetSize(); + auto x = std::max(size.x, kSizeX); + auto y = x / (mLandscape ? kAspectRatioLandscape : kAspectRatio); + SetVirtualSize(wxSize(x, y)); + SetScrollRate(10, 10); +} + +void PrintingPreview::OnSizeEvent(wxSizeEvent& event) +{ + // width is always going to be + auto x = std::max(event.m_size.x, kSizeX); + auto y = x / (mLandscape ? kAspectRatioLandscape : kAspectRatio); + SetVirtualSize(wxSize(x, y)); + SetScrollRate(10, 10); +} diff --git a/src/PrintingPreview.hpp b/src/PrintingPreview.hpp new file mode 100644 index 00000000..db564b17 --- /dev/null +++ b/src/PrintingPreview.hpp @@ -0,0 +1,49 @@ +#pragma once +/* + * PrintingPreview.hpp + * Header for continuity preview + */ + +/* + Copyright (C) 1995-2024 Garrick Brian Meeker, Richard Michael Powell + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + 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 "CalChartText.h" +#include "basic_ui.h" +#include + +namespace CalChart { +class Configuration; +class Show; +} + +class PrintingPreview : public ClickDragCtrlScrollCanvas { + using super = ClickDragCtrlScrollCanvas; + DECLARE_EVENT_TABLE() + +public: + PrintingPreview(wxWindow* parent, CalChart::Configuration const& config); + + void SetOrientation(bool landscape); + +private: + std::unique_ptr mShow; + bool mLandscape{}; + CalChart::Configuration const& mConfig; + + void OnPaint(wxPaintEvent& event); + void OnSizeEvent(wxSizeEvent& event); +};