We can select in every directions

This commit is contained in:
Clement Roblot 2024-08-02 22:28:56 +07:00
parent 70b32fe523
commit c1c6afc0ba
2 changed files with 6 additions and 5 deletions

View File

@ -72,9 +72,10 @@ int main() {
}); });
// TODO: Make the textToCopy a callback called every times the selected text change // TODO: Make the textToCopy a callback called every times the selected text change
// TODO: Is there a way for me to embedd the catchEvent in the selected decorator?
// TODO: Implement the double click on word to select the word // TODO: Implement the double click on word to select the word
// TODO: Implement the double click and drag to select word by word (optional) // TODO: Implement the double click and drag to select word by word (optional)
// TODO: Is there a way for me to embedd the catchEvent in the selected decorator? // TODO: Add a "selectable" flag in the pixel class and take it into account when selecting things
renderer |= CatchEvent([&](Event event) { renderer |= CatchEvent([&](Event event) {
if (event.is_mouse()) { if (event.is_mouse()) {
@ -85,7 +86,7 @@ int main() {
{ {
selection.startx = mouse.x; selection.startx = mouse.x;
selection.starty = mouse.y; selection.starty = mouse.y;
selection.endx = mouse.x-1; selection.endx = mouse.x;
selection.endy = mouse.y; selection.endy = mouse.y;
} }
else if (mouse.motion == Mouse::Released) else if (mouse.motion == Mouse::Released)
@ -95,7 +96,7 @@ int main() {
} }
else if (mouse.motion == Mouse::Moved) else if (mouse.motion == Mouse::Moved)
{ {
selection.endx = mouse.x-1; selection.endx = mouse.x;
selection.endy = mouse.y; selection.endy = mouse.y;
} }

View File

@ -22,8 +22,8 @@ class Selected : public NodeDecorator {
void Render(Screen& screen) override { void Render(Screen& screen) override {
Node::Render(screen); Node::Render(screen);
destination_ = ""; destination_ = "";
for (int y = selection_.starty; y <= selection_.endy; ++y) { for (int y = std::min(selection_.starty, selection_.endy); y <= std::max(selection_.starty, selection_.endy); ++y) {
for (int x = selection_.startx; x <= selection_.endx; ++x) { for (int x = std::min(selection_.startx, selection_.endx); x <= std::max(selection_.startx, selection_.endx)-1; ++x) {
screen.PixelAt(x, y).inverted ^= true; screen.PixelAt(x, y).inverted ^= true;
destination_ += screen.PixelAt(x, y).character; destination_ += screen.PixelAt(x, y).character;
} }