Skip to content

Commit

Permalink
Issue #544: Print Continuity text is not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpowell77 committed Nov 15, 2024
1 parent e971317 commit cf6573c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bugs addressed in this release:
* [#518](../../issues/518) Animation looks wrong
* [#540](../../issues/540) Current 3.7.1 does not run
* [#542](../../issues/542) crashes when going to last sheet of animation in RAINBOW show
* [#544](../../issues/544) Print Continuity text is not showing up

Other changes:

Expand Down
1 change: 1 addition & 0 deletions src/PrintContinuityPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void PrintContinuityPreview::OnPaint(wxPaintEvent&)
auto virtSize = GetVirtualSize();

dc.Clear();
dc.SetTextForeground(*wxBLACK);
dc.DrawRectangle(wxRect(wxPoint(0, 0), virtSize));
auto useNew = mConfig.Get_PrintContUseNewDraw();
if (useNew) {
Expand Down
57 changes: 39 additions & 18 deletions src/StackDrawPlayground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class StackDrawPreview : public wxScrolled<wxWindow> {
public:
StackDrawPreview(wxWindow* parent);

void SetDescription(std::string const& description)
void SetDrawCommand(CalChart::Draw::DrawCommand const& drawCommand)
{
mDescription = description;
mDrawCommand = drawCommand;
}

private:
std::string mDescription{};
CalChart::Draw::DrawCommand mDrawCommand{};

void OnPaint(wxPaintEvent& event);
void OnSizeEvent(wxSizeEvent& event);
Expand All @@ -59,6 +59,8 @@ StackDrawPreview::StackDrawPreview(wxWindow* parent)
Connect(wxEVT_PAINT, wxPaintEventHandler(StackDrawPreview::OnPaint));
}

namespace {

[[nodiscard]] auto done(char const* begin, char const* end) -> bool
{
return begin == end;
Expand Down Expand Up @@ -91,7 +93,7 @@ static auto ParseStringHelper(char const* begin, char const* end) -> std::tuple<
return { begin, result };
}

static auto ParseNumberHelper(char const* begin, char const* end) -> std::tuple<char const*, int>
auto ParseNumberHelper(char const* begin, char const* end) -> std::tuple<char const*, int>
{
auto result = 0;
while (begin != end && isdigit(*begin)) {
Expand All @@ -103,7 +105,7 @@ static auto ParseNumberHelper(char const* begin, char const* end) -> std::tuple<
}

// assumes that the char points to the open q
static auto ParseWord(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::Text>
auto ParseWord(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::Text>
{
if (*begin != 'q') {
throw std::runtime_error("missing q");
Expand All @@ -120,7 +122,7 @@ static auto ParseWord(char const* begin, char const* end) -> std::tuple<char con
return { begin, CalChart::Draw::Text{ CalChart::Coord{}, result } };
}

static auto ParseEllipse(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::Ellipse>
auto ParseEllipse(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::Ellipse>
{
if (*begin != 'E') {
throw std::runtime_error("missing E");
Expand All @@ -145,10 +147,10 @@ static auto ParseEllipse(char const* begin, char const* end) -> std::tuple<char
return { begin, CalChart::Draw::Ellipse{ { 0, 0 }, { c1, c2 } } };
}

static auto ParseBox(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::ZStack>
auto ParseBox(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::ZStack>
{
if (*begin != 'B') {
throw std::runtime_error("missing E");
throw std::runtime_error("missing B");
}
begin = increment(begin, end);
if (*begin != '(') {
Expand Down Expand Up @@ -177,7 +179,7 @@ static auto ParseBox(char const* begin, char const* end) -> std::tuple<char cons
};
}

static auto CharToAlign = [](auto c) {
auto CharToAlign = [](auto c) {
switch (c) {
case 'B':
return CalChart::Draw::StackAlign::Begin;
Expand All @@ -192,7 +194,7 @@ static auto CharToAlign = [](auto c) {
}
};

static auto ParseStringHelper(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::DrawCommand>
auto ParseStringHelper(char const* begin, char const* end) -> std::tuple<char const*, CalChart::Draw::DrawCommand>
{
switch (*begin) {
case 'A':
Expand Down Expand Up @@ -247,24 +249,29 @@ static auto ParseStringHelper(char const* begin, char const* end) -> std::tuple<
throw std::runtime_error("Missing things");
}

static auto ParseString(char const* begin, char const* end) -> CalChart::Draw::DrawCommand
auto ParseString(char const* begin, char const* end) -> CalChart::Draw::DrawCommand
{
auto [next, cmd] = ParseStringHelper(begin, end);
return cmd;
}

auto ParseString(std::string const& description)
{
return ParseString(description.data(), description.data() + description.size());
}

}

void StackDrawPreview::OnPaint(wxPaintEvent&)
{
wxPaintDC dc(this);
PrepareDC(dc);
wxSize virtSize = GetVirtualSize();
auto virtSize = GetVirtualSize();

dc.Clear();
dc.SetTextForeground(*wxBLACK);
dc.DrawRectangle(wxRect(wxPoint(0, 0), virtSize));
try {
wxCalChart::Draw::DrawCommandList(dc, ParseString(mDescription.data(), mDescription.data() + mDescription.size()));
} catch (std::exception const& e) {
}
wxCalChart::Draw::DrawCommandList(dc, mDrawCommand);
}

void StackDrawPreview::OnSizeEvent(wxSizeEvent& event)
Expand All @@ -291,18 +298,32 @@ StackDrawPlayground::StackDrawPlayground(wxWindow* parent)
return new StackDrawPreview(parent);
},
mUserInput = TextCtrl{}.bind([this] {
mPreview->SetDescription(*mUserInput);
try {
mPreview->SetDrawCommand(ParseString(*mUserInput));
mStatus->SetStatusText("");
} catch (std::exception const& e) {
mPreview->SetDrawCommand({});
mStatus->SetStatusText(e.what());
}
Refresh();
})
.withStyle(wxTE_MULTILINE | wxHSCROLL | wxTE_PROCESS_TAB),
}
.withSize(wxSize(500, 400)),

Generic{ CreateStdDialogButtonSizer(wxOK) },
mStatus = Generic<wxStatusBar>{ [](wxWindow* parent) {
return new wxStatusBar(parent);
} },
}
.attachTo(this);

*mUserInput = DefaultText;

mPreview->SetDescription(*mUserInput);
try {
mPreview->SetDrawCommand(ParseString(*mUserInput));
mStatus->SetStatusText("");
} catch (std::exception const& e) {
mStatus->SetStatusText(e.what());
}
}
1 change: 1 addition & 0 deletions src/StackDrawPlayground.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ class StackDrawPlayground : public wxDialog {
private:
wxUI::TextCtrl::Proxy mUserInput{};
wxUI::Generic<StackDrawPreview>::Proxy mPreview{};
wxUI::Generic<wxStatusBar>::Proxy mStatus{};
};

0 comments on commit cf6573c

Please sign in to comment.