Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions VortexEngine/VortexLib/VortexLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ EMSCRIPTEN_BINDINGS(Vortex) {
.function("peek", &Colorset::peek)
.function("peekNext", &Colorset::peekNext)
.function("numColors", &Colorset::numColors)
.function("shift", &Colorset::shift)
.function("onStart", &Colorset::onStart)
.function("onEnd", &Colorset::onEnd)
.function("serialize", &Colorset::serialize)
Expand Down
24 changes: 24 additions & 0 deletions VortexEngine/src/Colors/Colorset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,30 @@ RGBColor Colorset::peek(int32_t offset) const
return m_palette[nextIndex];
}

// shift an index to a new destination, dest index before move
void Colorset::shift(uint8_t idx, uint8_t dest)
{
if (idx >= m_numColors || dest >= m_numColors || idx == dest) {
return;
}
// Backup the color being shifted
RGBColor temp = m_palette[idx];
// shift the block of colors next to it
if (idx < dest) {
// Forward shift: Move the block from idx + 1 to dest
memmove(m_palette + idx,
m_palette + idx + 1,
(dest - idx) * sizeof(RGBColor));
} else {
// Backward shift: Move the block from dest to idx - 1
memmove(m_palette + dest + 1,
m_palette + dest,
(idx - dest) * sizeof(RGBColor));
}
// Place the saved element at the destination
m_palette[dest] = temp;
}

bool Colorset::onStart() const
{
return (m_curIndex == 0);
Expand Down
3 changes: 3 additions & 0 deletions VortexEngine/src/Colors/Colorset.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class Colorset
// the number of colors in the palette
uint8_t numColors() const { return m_numColors; }

// shift an index to a new destination, dest index before move
void shift(uint8_t idx, uint8_t dest);

// whether the colorset is currently on the first color or last color
bool onStart() const;
bool onEnd() const;
Expand Down
Loading