Skip to content

Commit

Permalink
SpriteHandler.h:
Browse files Browse the repository at this point in the history
* BitmapSprite flip_ud() and flip_lr() functions now more correctly flips the textels by using mirrorred characters where possible, which yields better results.
  • Loading branch information
razterizer committed Nov 18, 2024
1 parent 99556a0 commit e15d301
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions SpriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,21 @@ class BitmapSprite : public Sprite

void flip_ud(int anim_frame)
{
auto f_flip_char = [](drawing::Textel& txt)
{
auto& ch = txt.ch;
switch(ch)
{
case '_': ch = '-'; break;
case '-': ch = '_'; break;
case 'W': ch = 'M'; break;
case 'M': ch = 'W'; break;
case 'w': ch = 'm'; break;
case 'm': ch = 'w'; break;
default: break;
}
};

auto* texture = fetch_frame(anim_frame);
const int half_height = size.r/2;
for (int c = 0; c < size.c; ++c)
Expand All @@ -433,6 +448,8 @@ class BitmapSprite : public Sprite
int r_inv = size.r - r - 1;
auto a = texture->operator()(r, c);
auto b = texture->operator()(r_inv, c);
f_flip_char(a);
f_flip_char(b);
texture->set_textel(r, c, b);
texture->set_textel(r_inv, c, a);
}
Expand All @@ -448,6 +465,28 @@ class BitmapSprite : public Sprite

void flip_lr(int anim_frame)
{
auto f_flip_char = [](drawing::Textel& txt)
{
auto& ch = txt.ch;
switch(ch)
{
case '/': ch = '\\'; break;
case '\\': ch = '/'; break;
case '(': ch = ')'; break;
case ')': ch = '('; break;
case '[': ch = ']'; break;
case ']': ch = '['; break;
case '}': ch = '{'; break;
case 'd': ch = 'b'; break;
case 'b': ch = 'd'; break;
case 'J': ch = 'L'; break;
case 'L': ch = 'J'; break;
case '<': ch = '>'; break;
case '>': ch = '<'; break;
default: break;
}
};

auto* texture = fetch_frame(anim_frame);
const int half_width = size.c/2;
for (int r = 0; r < size.r; ++r)
Expand All @@ -457,6 +496,8 @@ class BitmapSprite : public Sprite
int c_inv = size.c - c - 1;
auto a = texture->operator()(r, c);
auto b = texture->operator()(r, c_inv);
f_flip_char(a);
f_flip_char(b);
texture->set_textel(r, c, b);
texture->set_textel(r, c_inv, a);
}
Expand Down

0 comments on commit e15d301

Please sign in to comment.