Skip to content

Commit

Permalink
Issue #590: Move things related to drawing a sheet to sheet so it can…
Browse files Browse the repository at this point in the history
… generate Draw commands (#594)
  • Loading branch information
rmpowell77 authored Jan 11, 2025
1 parent eb4c2f5 commit 2dd849b
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 71 deletions.
2 changes: 2 additions & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ Bugs addressed in this release:

Other changes:

* [#590](../../issues/590) Move things related to drawing a sheet to sheet so it can generate Draw commands

4 changes: 0 additions & 4 deletions src/CalChartDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,6 @@ auto CalChartDoc::GenerateCurrentSheetPointsDrawCommands() const -> std::vector<
if (sheet == GetSheetEnd()) {
return drawCmds;
}
if (GetCurrentReferencePoint() > 0) {
// if we are editing a ref point other than 0, draw the 0 one in a different color.
CalChart::append(drawCmds, mShow->GeneratePointsDrawCommands(config, std::nullopt));
}
CalChart::append(drawCmds, mShow->GeneratePointsDrawCommands(config, GetCurrentReferencePoint()));
CalChart::append(drawCmds, GeneratePathsDrawCommands());
return drawCmds + origin;
Expand Down
1 change: 0 additions & 1 deletion src/ColorSetupCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ void ColorSetupCanvas::OnPaint(wxPaintEvent&)
*nextSheet));

// Draw the points
CalChart::append(drawCmds, mShow->GeneratePointsDrawCommands(mConfig, std::nullopt));
CalChart::append(drawCmds, mShow->GeneratePointsDrawCommands(mConfig, 1));

// draw the path, but because we're not a real show, we have to make the path manually.
Expand Down
2 changes: 1 addition & 1 deletion src/TransitionSolverFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void TransitionSolverFrame::SyncInstructionOptionsControlWithCurrentState()
};

mInstructionOptions.clear();
for (auto waitBeats = 0; waitBeats < (*mDoc->GetCurrentSheet()).GetBeats(); waitBeats += 2) {
for (auto waitBeats = CalChart::beats_t{}; waitBeats < (*mDoc->GetCurrentSheet()).GetBeats(); waitBeats += 2) {
for (auto pattern : marchInstructions) {
mInstructionOptions.emplace_back(pattern.first, waitBeats);
}
Expand Down
79 changes: 77 additions & 2 deletions src/core/CalChartSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "CalChartSheet.h"
#define _LIBCPP_ENABLE_EXPERIMENTAL 1

#include "CalChartSheet.h"
#include "CalChartConfiguration.h"
#include "CalChartFileFormat.h"
#include "CalChartRanges.h"
#include "CalChartShow.h"
Expand Down Expand Up @@ -689,6 +691,80 @@ nlohmann::json Sheet::toOnlineViewerJSON(unsigned sheetNum, std::vector<std::str
return j;
}

namespace {
// Returns a view adaptor that will transform a range of point indices to Draw point commands.
auto TransformIndexToDrawCommands(CalChart::Sheet const& sheet, std::vector<std::string> const& labels, int ref, CalChart::Configuration const& config)
{
return std::views::transform([&sheet, ref, labels, &config](int i) {
return sheet.GetMarcher(i).GetDrawCommands(ref, labels.at(i), config);
})
| std::ranges::views::join;
}

// Given a set and a size, return a range that has the numbers not in the set
auto NegativeIntersection(CalChart::SelectionList const& set, int count)
{
return std::views::iota(0, count)
| std::views::filter([set](int i) {
return !set.contains(i);
});
}

// convention is that we have unselected
auto GetMarcherColors(bool isGhost, bool isRef) -> std::array<Colors, 4>
{
if (isGhost) {
return { Colors::GHOST_POINT, Colors::GHOST_POINT_HLIT, Colors::GHOST_POINT_TEXT, Colors::GHOST_POINT_HLIT_TEXT };
}
if (isRef) {
return { Colors::REF_POINT, Colors::REF_POINT_HILIT, Colors::REF_POINT_TEXT, Colors::REF_POINT_HILIT_TEXT };
}
return { Colors::POINT, Colors::POINT_HILIT, Colors::POINT_TEXT, Colors::POINT_HILIT_TEXT };
}

auto GenerateSheetMarcherDrawCommands(
CalChart::Configuration const& config,
CalChart::SelectionList const& selection_list,
std::vector<std::string> const& labels,
CalChart::Sheet const& sheet,
int ref,
std::array<Colors, 4> color) -> std::vector<CalChart::Draw::DrawCommand>
{

return {
CalChart::Draw::withBrushAndPen(
config.Get_CalChartBrushAndPen(std::get<0>(color)),
CalChart::Draw::withTextForeground(
config.Get_CalChartBrushAndPen(std::get<2>(color)),
NegativeIntersection(selection_list, labels.size())
| TransformIndexToDrawCommands(sheet, labels, ref, config))),
CalChart::Draw::withBrushAndPen(
config.Get_CalChartBrushAndPen(std::get<1>(color)),
CalChart::Draw::withTextForeground(
config.Get_CalChartBrushAndPen(std::get<3>(color)),
selection_list
| TransformIndexToDrawCommands(sheet, labels, ref, config))),
};
}

}

auto Sheet::GenerateGhostElements(CalChart::Configuration const& config, SelectionList const& selected, std::vector<std::string> const& marcherLabels) const -> std::vector<CalChart::Draw::DrawCommand>
{
return GenerateSheetMarcherDrawCommands(config, selected, marcherLabels, *this, 0, GetMarcherColors(true, false));
}

auto Sheet::GenerateSheetElements(CalChart::Configuration const& config, SelectionList const& selected, std::vector<std::string> const& marcherLabels, int referencePoint) const -> std::vector<CalChart::Draw::DrawCommand>
{
auto drawCmds = std::vector<CalChart::Draw::DrawCommand>{};
if (referencePoint > 0) {
// if we are editing a ref point other than 0, draw the 0 one in a different color.
CalChart::append(drawCmds, GenerateSheetMarcherDrawCommands(config, selected, marcherLabels, *this, 0, GetMarcherColors(false, true)));
}
CalChart::append(drawCmds, GenerateSheetMarcherDrawCommands(config, selected, marcherLabels, *this, referencePoint, GetMarcherColors(false, false)));
return drawCmds;
}

void Sheet::SetPoints(std::vector<Point> const& points) { mPoints = points; }

// -=-=-=-=-=-=- Unit Tests -=-=-=-=-=-=-=-
Expand Down Expand Up @@ -811,5 +887,4 @@ auto Sheet::ShouldPrintLandscape() const -> bool
auto boundingBox = GetMarcherBoundingBox(GetAllMarchers());
return (boundingBox.second.x - boundingBox.first.x) > CalChart::Int2CoordUnits(CalChart::kFieldStepSizeNorthSouth[0]);
}

}
5 changes: 5 additions & 0 deletions src/core/CalChartSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class Sheet {
*/
[[nodiscard]] auto toOnlineViewerJSON(unsigned sheetNum, std::vector<std::string> dotLabels, std::map<std::string, std::vector<nlohmann::json>> const& movements) const -> nlohmann::json;

// Draw Commands
// the sheet can generate all the elements related to sheet specific draw aspects
[[nodiscard]] auto GenerateGhostElements(CalChart::Configuration const& config, SelectionList const& selected, std::vector<std::string> const& marcherLabels) const -> std::vector<CalChart::Draw::DrawCommand>;
[[nodiscard]] auto GenerateSheetElements(CalChart::Configuration const& config, SelectionList const& selected, std::vector<std::string> const& marcherLabels, int referencePoint) const -> std::vector<CalChart::Draw::DrawCommand>;

private:
std::vector<Continuity> mAnimationContinuity;
PrintContinuity mPrintableContinuity;
Expand Down
64 changes: 3 additions & 61 deletions src/core/CalChartShow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,75 +352,17 @@ auto Show::SerializeShow() const -> std::vector<std::byte>
return result;
}

namespace {
// Returns a view adaptor that will transform a range of point indices to Draw point commands.
auto TransformIndexToDrawCommands(CalChart::Sheet const& sheet, std::vector<std::string> const& labels, int ref, CalChart::Configuration const& config)
{
return std::views::transform([&sheet, ref, labels, &config](int i) {
return sheet.GetMarcher(i).GetDrawCommands(ref, labels.at(i), config);
})
| std::ranges::views::join;
}

// Given a set and a size, return a range that has the numbers not in the set
auto NegativeIntersection(CalChart::SelectionList const& set, int count)
{
return std::views::iota(0, count)
| std::views::filter([set](int i) {
return !set.contains(i);
});
}

auto GenerateSheetPointsDrawCommands(
CalChart::Configuration const& config,
CalChart::SelectionList const& selection_list,
int numberPoints,
std::vector<std::string> const& labels,
CalChart::Sheet const& sheet,
int ref,
CalChart::Colors unselectedColor,
CalChart::Colors selectedColor,
CalChart::Colors unselectedTextColor,
CalChart::Colors selectedTextColor) -> std::vector<CalChart::Draw::DrawCommand>
{

return {
CalChart::Draw::withBrushAndPen(
config.Get_CalChartBrushAndPen(unselectedColor),
CalChart::Draw::withTextForeground(
config.Get_CalChartBrushAndPen(unselectedTextColor),
NegativeIntersection(selection_list, numberPoints)
| TransformIndexToDrawCommands(sheet, labels, ref, config))),
CalChart::Draw::withBrushAndPen(
config.Get_CalChartBrushAndPen(selectedColor),
CalChart::Draw::withTextForeground(
config.Get_CalChartBrushAndPen(selectedTextColor),
selection_list
| TransformIndexToDrawCommands(sheet, labels, ref, config))),
};
}

}

auto Show::GeneratePointsDrawCommands(CalChart::Configuration const& config, std::optional<int> ref) const -> std::vector<CalChart::Draw::DrawCommand>
auto Show::GeneratePointsDrawCommands(CalChart::Configuration const& config, int referencePoint) const -> std::vector<CalChart::Draw::DrawCommand>
{
auto unselectedColor = ref.has_value() ? CalChart::Colors::POINT : CalChart::Colors::REF_POINT;
auto selectedColor = ref.has_value() ? CalChart::Colors::POINT_HILIT : CalChart::Colors::REF_POINT_HILIT;
auto unselectedTextColor = ref.has_value() ? CalChart::Colors::POINT_TEXT : CalChart::Colors::REF_POINT_TEXT;
auto selectedTextColor = ref.has_value() ? CalChart::Colors::POINT_HILIT_TEXT : CalChart::Colors::REF_POINT_HILIT_TEXT;
return GenerateSheetPointsDrawCommands(config, mSelectionList, GetNumPoints(), GetPointsLabel(), *GetCurrentSheet(), ref.value_or(0), unselectedColor, selectedColor, unselectedTextColor, selectedTextColor);
return GetCurrentSheet()->GenerateSheetElements(config, mSelectionList, GetPointsLabel(), referencePoint);
}

auto Show::GenerateGhostPointsDrawCommands(
CalChart::Configuration const& config,
CalChart::SelectionList const& selection_list,
CalChart::Sheet const& sheet) const -> std::vector<CalChart::Draw::DrawCommand>
{
auto unselectedColor = CalChart::Colors::GHOST_POINT;
auto selectedColor = CalChart::Colors::GHOST_POINT_HLIT;
auto unselectedTextColor = CalChart::Colors::GHOST_POINT_TEXT;
auto selectedTextColor = CalChart::Colors::GHOST_POINT_HLIT_TEXT;
return GenerateSheetPointsDrawCommands(config, selection_list, GetNumPoints(), GetPointsLabel(), sheet, 0, unselectedColor, selectedColor, unselectedTextColor, selectedTextColor);
return sheet.GenerateGhostElements(config, selection_list, GetPointsLabel());
}

template <std::ranges::input_range Range>
Expand Down
3 changes: 1 addition & 2 deletions src/core/CalChartShow.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,14 @@ class Show {

[[nodiscard]] auto GeneratePointsDrawCommands(
CalChart::Configuration const& config,
std::optional<int> ref) const -> std::vector<CalChart::Draw::DrawCommand>;
int ref) const -> std::vector<CalChart::Draw::DrawCommand>;

[[nodiscard]] auto GenerateGhostPointsDrawCommands(
CalChart::Configuration const& config,
CalChart::SelectionList const& selection_list,
CalChart::Sheet const& sheet) const -> std::vector<CalChart::Draw::DrawCommand>;

[[nodiscard]] auto GenerateFieldWithMarchersDrawCommands(CalChart::Configuration const& config) const -> std::vector<std::vector<CalChart::Draw::DrawCommand>>;
[[nodiscard]] auto GenerateFieldWithMarchersDrawCommands2(CalChart::Configuration const& config) const -> std::vector<std::vector<std::string>>;

private:
// modification of show is private, and externally done through create and exeucte commands
Expand Down

0 comments on commit 2dd849b

Please sign in to comment.