Skip to content

Commit

Permalink
Better animation rigging
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jan 14, 2021
1 parent ef02b2f commit 84156b2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
11 changes: 6 additions & 5 deletions src/control-icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

using namespace blit;


void control_icon(Point location, Button button) {
auto temp = screen.sprites->palette[1];
switch(button){
case Button::Y:
screen.sprites->palette[1] = Pen(100, 246, 178, 255); // Green
screen.sprites->palette[1] = BTN_GREEN; // Green
screen.sprite(0, location, SpriteTransform::R270);
break;
case Button::X:
screen.sprites->palette[1] = Pen(99, 175, 227, 255); // Blue
screen.sprites->palette[1] = BTN_BLUE; // Blue
screen.sprite(0, location);
break;
case Button::A:
screen.sprites->palette[1] = Pen(236, 92, 181, 255); // Pink/Red
screen.sprites->palette[1] = BTN_PINK; // Pink/Red
screen.sprite(0, location, SpriteTransform::R90);
break;
case Button::B:
screen.sprites->palette[1] = Pen(234, 226, 81, 255); // Yellow
screen.sprites->palette[1] = BTN_YELLOW; // Yellow
screen.sprite(0, location, SpriteTransform::R180);
break;
default:
Expand Down Expand Up @@ -49,7 +50,7 @@ void ui_icon(UIcon *i, Point position, Mouse *mouse, bool active) {
label_bg.x += 2;
label_bg.w += 1;
screen.rectangle(label_bg);
screen.pen = Pen(255, 255, 255, 255);
screen.pen = active ? Pen(255, 128, 128, 255) : Pen(255, 255, 255, 255);
screen.text(i->help, minimal_font, box.tr() + Point(3, 1));
}
}
6 changes: 6 additions & 0 deletions src/control-icons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#include "32blit.hpp"
#include "mouse.hpp"

const blit::Pen BTN_GREEN = blit::Pen(100, 246, 178, 255);
const blit::Pen BTN_BLUE = blit::Pen(99, 175, 227, 255);
const blit::Pen BTN_PINK = blit::Pen(236, 92, 181, 255);
const blit::Pen BTN_YELLOW = blit::Pen(234, 226, 81, 255);
const blit::Pen WHITE = blit::Pen(255, 255, 255, 255);

struct UIcon {
unsigned int index;
std::string help;
Expand Down
67 changes: 54 additions & 13 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,22 @@ void Editor::render_help(uint32_t time) {
screen.text("Zoom Out", minimal_font, help_offset + Point(64 + line_height, 0));

control_icon(help_offset + Point(0, line_height), Button::A);
screen.text(mode == EditMode::Pixel ? "Pick" : clipboard ? "Done" : "Copy", minimal_font, help_offset + Point(line_height, line_height));

control_icon(Point(64 + help_offset.x, help_offset.y + line_height), Button::B);
screen.text(mode == EditMode::Pixel ? "Paint" : clipboard ? "Paste" : "Rotate", minimal_font, help_offset + Point(line_height + 64, line_height));
switch(mode) {
case EditMode::Pixel:
screen.text("Pick", minimal_font, help_offset + Point(line_height, line_height));
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));
break;
case EditMode::Animate:
screen.text("Start", minimal_font, help_offset + Point(line_height, line_height));
screen.text("End", minimal_font, help_offset + Point(line_height + 64, line_height));
break;
}

}

void Editor::render_preview(uint32_t time) {
Expand All @@ -116,11 +128,26 @@ void Editor::render_preview(uint32_t time) {
screen.stretch_blit(&buffer, Rect(current_sprite * 8, Size(8, 8)), Rect(padding + 32 + 10, 240 - 32 - padding, 16, 16));
screen.stretch_blit(&buffer, Rect(current_sprite * 8, Size(8, 8)), Rect(padding + 32 + 10 + 16 + 10, 240 - 32 - padding, 8, 8));

Point anim_sprite = current_sprite;
anim_sprite.x = (time / 200) & 0x0f;
Point anim_sprite = anim_start;
Point anim_range = (anim_end - anim_start) + Point(1, 1);

if(anim_range.x < 1 || anim_range.y < 1) return;

int anim_step = (time / 200) % (anim_range.x * anim_range.y);

anim_sprite.x += anim_step % anim_range.x;
anim_sprite.y += anim_step / anim_range.x;

screen.stretch_blit(&buffer, Rect(anim_sprite * 8, Size(8, 8)), Rect(padding + 32 + 10 + 16 + 10 + 8 + 10, 240 - 32 - padding, 32, 32));
}

void Editor::outline_rect(Rect cursor) {
screen.line(cursor.tl(), cursor.tr());
screen.line(cursor.bl(), cursor.br());
screen.line(cursor.tl(), cursor.bl());
screen.line(cursor.tr(), cursor.br());
}

void Editor::render(uint32_t time, Mouse *mouse) {
Pen background_colour = screen.pen;
Rect clip = Rect(draw_offset, bounds);
Expand Down Expand Up @@ -151,7 +178,6 @@ void Editor::render(uint32_t time, Mouse *mouse) {
viewport_tl.y = 0;
}


Vec2 viewport_bounds(buffer.bounds.w, buffer.bounds.h);
viewport_bounds /= view_zoom;
Rect viewport = Rect(Point(viewport_tl), Size(ceil(viewport_bounds.x), ceil(viewport_bounds.y)));
Expand Down Expand Up @@ -184,20 +210,24 @@ void Editor::render(uint32_t time, Mouse *mouse) {
// sprite cursor
if(view_zoom < 16) {
screen.pen = Pen(128, 128, 128, 255);
screen.pen.a = 255;
cursor = Rect(draw_offset + (((current_sprite * 8) - view_offset) * view_zoom), Size(8 * view_zoom, 8 * view_zoom));
screen.line(cursor.tl(), cursor.tr());
screen.line(cursor.bl(), cursor.br());
screen.line(cursor.tl(), cursor.bl());
screen.line(cursor.tr(), cursor.br());
outline_rect(cursor);

screen.pen = Pen(64, 128, 64, 255);
cursor = Rect(draw_offset + (((anim_start * 8) - view_offset) * view_zoom), Size(8 * view_zoom, 8 * view_zoom));
outline_rect(cursor);

screen.pen = Pen(128, 64, 64, 255);
cursor = Rect(draw_offset + (((anim_end * 8) - view_offset) * view_zoom), Size(8 * view_zoom, 8 * view_zoom));
outline_rect(cursor);
}
}

screen.clip = Rect(Point(0, 0), screen.bounds);

Point ei = draw_offset - Point(14, 0);
for(auto &i : tool_icons) {
bool active = (i.sprite == 9 && mode == EditMode::Pixel) || (i.sprite == 10 && mode == EditMode::Sprite);
bool active = (i.sprite == 9 && mode == EditMode::Pixel) || (i.sprite == 10 && mode == EditMode::Sprite) || (i.sprite == 1 && mode == EditMode::Animate);
ui_icon(&i, ei, mouse, active);
ei.y += 12;
screen.sprites->palette[1] = Pen(255, 255, 255, 255);
Expand All @@ -223,10 +253,14 @@ int Editor::update(uint32_t time, Mouse *mouse) {

if (i.sprite == 9){
mode = EditMode::Pixel;
clipboard = false;
return -1;
} else if (i.sprite == 10) {
mode = EditMode::Sprite;
return -1;
} else if (i.sprite == 1) {
mode = EditMode::Animate;
return -1;
} else {
return i.index;
}
Expand Down Expand Up @@ -295,7 +329,6 @@ int Editor::update(uint32_t time, Mouse *mouse) {
break;
}
};

if(mode == EditMode::Pixel) {
if(mouse->button_b) { // Paint
set_pixel(current_pixel, palette->selected_colour);
Expand All @@ -304,6 +337,14 @@ int Editor::update(uint32_t time, Mouse *mouse) {
palette->selected_colour = get_pixel(current_pixel);
}
}
else if(mode == EditMode::Animate) {
if(mouse->button_b) { // End
anim_end = current_sprite;
}
if(mouse->button_a) { // Start
anim_start = current_sprite;
}
}
else if(mode == EditMode::Sprite) {
if(mouse->button_b_pressed) {
if(clipboard) {
Expand Down
10 changes: 8 additions & 2 deletions src/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

enum class EditMode {
Pixel,
Sprite
Sprite,
Animate
};

class Editor {
Expand All @@ -28,6 +29,9 @@ class Editor {
blit::Point current_pixel = blit::Point(0, 0);
blit::Point current_sprite = blit::Point(0, 0);

blit::Point anim_start = blit::Point(0, 0);
blit::Point anim_end = blit::Point(15, 0);

blit::Point draw_offset;
Palette *palette;

Expand All @@ -47,7 +51,8 @@ class Editor {
UIcon{1, "save", 3},
UIcon{2, "clear", 2},
UIcon{3, "pixel", 9},
UIcon{4, "sprite", 10}
UIcon{4, "sprite", 10},
UIcon{5, "animate", 1}
};

private:
Expand All @@ -59,4 +64,5 @@ class Editor {
void render_help(uint32_t time);
void render_status(uint32_t time);
void render_preview(uint32_t time);
void outline_rect(blit::Rect cursor);
};

0 comments on commit 84156b2

Please sign in to comment.