Skip to content

Commit

Permalink
Merge roll/rot, simplify copy&paste
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jan 17, 2021
1 parent 3c2e8ee commit 5b1c83e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ It works in 8x8 tiles but will handle sprites up to 3x3 tiles in side (24x24 pix
- [Load/Save/Clear](#loadsaveclear)
- [Sprite Size](#sprite-size)
- [Mirror](#mirror)
- [Roll](#roll)
- [(TODO) Rotate](#todo-rotate)
- [Roll / Rotate](#roll--rotate)
- [The Palette](#the-palette)

## The Editor
Expand Down Expand Up @@ -117,15 +116,15 @@ The Mirror tool will mirror the current sprite Left/Right or Up/Down. Use the d-

The Mirror tool will only be active if you're zoomed in enough to have a locked (red) Sprite Cursor.

#### Roll
#### Roll / Rotate

The Roll tool will roll the current sprite Left/Right or Up/Down. Use the d-pad buttons to roll one pixel at a time. This is useful for shifting art around inside a sprite bounds for animation, or just correcting your drawing position.
The Roll/Rotate tool will roll the current sprite Left/Right or Up/Down or rotate it 90 (square) or 180 (rectangular) degrees.

The Roll tool will only be active if you're zoomed in enough to have a locked (red) Sprite Cursor.
Use the d-pad buttons to roll one pixel at a time. This is useful for shifting art around inside a sprite bounds for animation, or just correcting your drawing position.

#### (TODO) Rotate
Press the A button rotate clockwise.

Rotate is currently only available in Sprite Mode, but should probably have its own icon so that Sprite Mode can make better use of that button.
The Roll / Rotate tool will only be active if you're zoomed in enough to have a locked (red) Sprite Cursor.

## The Palette

Expand Down
60 changes: 32 additions & 28 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void Editor::render_help(uint32_t time) {
screen.text("Paint", minimal_font, help_offset + Point(line_height + 64, line_height));
break;
case EditMode::Sprite:
screen.text(clipboard ? "Done" : "Copy", minimal_font, help_offset + Point(line_height, line_height));
screen.text(clipboard ? "Paste" : "Rotate", minimal_font, help_offset + Point(line_height + 64, line_height));
screen.text("Copy", minimal_font, help_offset + Point(line_height, line_height));
screen.text("Paste", minimal_font, help_offset + Point(line_height + 64, line_height));
break;
case EditMode::Animate:
screen.text("Start", minimal_font, help_offset + Point(line_height, line_height));
Expand Down Expand Up @@ -265,7 +265,9 @@ void Editor::update_current_sprite(Vec2 viewport_shift) {
// This only applies while sprite cursor lock is on- IE when you are considered to be "zoomed in" enough to be working on *a* sprite.
int visible_pixels = 16 * 8 / view_zoom;
Rect current_sprite_bounds = Rect(current_sprite_offset, sprite_size_pixels);
current_sprite_bounds.inflate(2); // margin for error for when using d-pad to accurately paint
if(sprite_size.w > 1 || sprite_size.h > 1) {
current_sprite_bounds.inflate(2); // margin for error for when using d-pad to accurately paint
}
if(current_sprite_bounds.contains(current_pixel)) return;
current_sprite_bounds.deflate(2);

Expand Down Expand Up @@ -352,6 +354,8 @@ int Editor::update(uint32_t time, Mouse *mouse) {
}
}
}

continue;
}
}
}
Expand All @@ -370,7 +374,29 @@ int Editor::update(uint32_t time, Mouse *mouse) {
set_pixel(current_sprite_offset + Point(x, y), tempdata[nx + ny * 64]);
}
}
continue;
}
}
if(mouse->button_a_pressed && icon_bounds(ei).contains(mouse->cursor)) {
// Rotate 90
// Since i have to loop to clear to 0 anyway, might as well raw copy from SRC to DST
copy_sprite_to_temp();

// actual rotation happens here
if(sprite_size.w == sprite_size.h) { // Can do 90 degree intervals because our sprite is square
for(auto x = 0; x < sprite_size_pixels.w; x++) {
for(auto y = 0; y < sprite_size_pixels.h; y++) {
set_pixel(current_sprite_offset + Point(sprite_size_pixels.w - 1 - y, x), tempdata[x + y * 64]);
}
}
} else { // must do 180
for(auto x = 0; x < sprite_size_pixels.w; x++) {
for(auto y = 0; y < sprite_size_pixels.h; y++) {
set_pixel(current_sprite_offset + Point(sprite_size_pixels.w - 1 - x, sprite_size_pixels.h - 1 - y), tempdata[x + y * 64]);
}
}
}
continue;
}
}
if(i.sprite == 11){ // sprite size
Expand Down Expand Up @@ -419,10 +445,10 @@ int Editor::update(uint32_t time, Mouse *mouse) {
if(mouse->button_a_pressed && icon_bounds(ei).contains(mouse->cursor)) {
if (i.sprite == 9){
mode = EditMode::Pixel;
clipboard = false;
return -1;
} else if (i.sprite == 10) {
mode = EditMode::Sprite;
clipboard = false;
return -1;
} else if (i.sprite == 1) {
mode = EditMode::Animate;
Expand Down Expand Up @@ -501,32 +527,10 @@ int Editor::update(uint32_t time, Mouse *mouse) {
set_pixel(current_sprite_offset + Point(x, y), tempdata[x + y * 64]);
}
}
} else {
// Rotate 90
// Since i have to loop to clear to 0 anyway, might as well raw copy from SRC to DST
copy_sprite_to_temp();

// actual rotation happens here
if(sprite_size.w == sprite_size.h) { // Can do 90 degree intervals because our sprite is square
for(auto x = 0; x < sprite_size_pixels.w; x++) {
for(auto y = 0; y < sprite_size_pixels.h; y++) {
set_pixel(current_sprite_offset + Point(sprite_size_pixels.w - 1 - y, x), tempdata[x + y * 64]);
}
}
} else { // must do 180
for(auto x = 0; x < sprite_size_pixels.w; x++) {
for(auto y = 0; y < sprite_size_pixels.h; y++) {
set_pixel(current_sprite_offset + Point(sprite_size_pixels.w - 1 - x, sprite_size_pixels.h - 1 - y), tempdata[x + y * 64]);
}
}
}

}
} else if(mouse->button_a_pressed) {
if(!clipboard) {
copy_sprite_to_temp();
}
clipboard = !clipboard;
copy_sprite_to_temp();
clipboard = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Editor {
UIcon{5, "animate", 1},
UIcon{6, "size", 11},
UIcon{7, "mirror", 6},
UIcon{8, "roll", 15}
UIcon{8, "roll/rot", 15}
};

private:
Expand Down

0 comments on commit 5b1c83e

Please sign in to comment.