diff options
author | 3gg <3gg@shellblade.net> | 2024-08-29 22:09:29 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-08-29 22:09:29 -0700 |
commit | cb9b2c2fe7b77b0b8a3826ad2846655133683dfe (patch) | |
tree | 1c7fa0463c52dc24e36b0bed9aec372e0c1eed03 /gfx-iso/src | |
parent | 77b9cc7426d3da7ae4da954db2f59408e9e6be2b (diff) |
Fix offseting. Add function to get screen size.
Diffstat (limited to 'gfx-iso/src')
-rw-r--r-- | gfx-iso/src/isogfx.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/gfx-iso/src/isogfx.c b/gfx-iso/src/isogfx.c index f7d0fa9..52c4ae2 100644 --- a/gfx-iso/src/isogfx.c +++ b/gfx-iso/src/isogfx.c | |||
@@ -761,8 +761,8 @@ static Pixel alpha_blend(Pixel src, Pixel dst) { | |||
761 | 761 | ||
762 | /// Draw a rectangle (tile or sprite). | 762 | /// Draw a rectangle (tile or sprite). |
763 | /// | 763 | /// |
764 | /// The rectangle's bottom-left corner is mapped to the given origin. The | 764 | /// The rectangle's top-left corner is mapped to the screen space position given |
765 | /// rectangle then extends to the right and top of the origin. | 765 | /// by 'top_left'. |
766 | /// | 766 | /// |
767 | /// The rectangle's pixels are assumed to be arranged in a linear, row-major | 767 | /// The rectangle's pixels are assumed to be arranged in a linear, row-major |
768 | /// fashion. | 768 | /// fashion. |
@@ -775,23 +775,19 @@ static void draw_rect( | |||
775 | const Pixel* pixels, const uint8_t* indices) { | 775 | const Pixel* pixels, const uint8_t* indices) { |
776 | assert(iso); | 776 | assert(iso); |
777 | 777 | ||
778 | #define rect_pixel(x, y) \ | 778 | #define rect_pixel(X, Y) \ |
779 | (indices ? pixels[indices[py * rect_width + px]] \ | 779 | (indices ? pixels[indices[Y * rect_width + X]] : pixels[Y * rect_width + X]) |
780 | : pixels[py * rect_width + px]) | ||
781 | 780 | ||
782 | // Rect origin can be outside screen bounds, so we must offset accordingly to | 781 | // Rect origin can be outside screen bounds, so we must offset accordingly to |
783 | // draw only the visible portion. | 782 | // draw only the visible portion. |
784 | #define max(a, b) (a > b ? a : b) | 783 | #define max(a, b) (a > b ? a : b) |
785 | const int px_offset = max(0, -top_left.x); | 784 | const int px_offset = max(0, -top_left.x); |
786 | const int py_offset = max(0, -top_left.y); | 785 | const int py_offset = max(0, -top_left.y); |
787 | // Adjust top-left to be inside bounds. | ||
788 | top_left.x = max(0, top_left.x); | ||
789 | top_left.y = max(0, top_left.y); | ||
790 | 786 | ||
791 | // Rect can exceed screen bounds, so clip along Y and X as we draw. | 787 | // Rect can exceed screen bounds, so clip along Y and X as we draw. |
792 | for (int py = py_offset; | 788 | for (int py = py_offset; |
793 | (py < rect_height) && (top_left.y + py < iso->screen_height); ++py) { | 789 | (py < rect_height) && (top_left.y + py < iso->screen_height); ++py) { |
794 | const int sy = top_left.y + py - py_offset; | 790 | const int sy = top_left.y + py; |
795 | for (int px = px_offset; | 791 | for (int px = px_offset; |
796 | (px < rect_width) && (top_left.x + px < iso->screen_width); ++px) { | 792 | (px < rect_width) && (top_left.x + px < iso->screen_width); ++px) { |
797 | const Pixel colour = rect_pixel(px, py); | 793 | const Pixel colour = rect_pixel(px, py); |
@@ -922,6 +918,14 @@ bool isogfx_resize(IsoGfx* iso, int screen_width, int screen_height) { | |||
922 | return true; | 918 | return true; |
923 | } | 919 | } |
924 | 920 | ||
921 | void isogfx_get_screen_size(const IsoGfx* iso, int* width, int* height) { | ||
922 | assert(iso); | ||
923 | assert(width); | ||
924 | assert(height); | ||
925 | *width = iso->screen_width; | ||
926 | *height = iso->screen_height; | ||
927 | } | ||
928 | |||
925 | const Pixel* isogfx_get_screen_buffer(const IsoGfx* iso) { | 929 | const Pixel* isogfx_get_screen_buffer(const IsoGfx* iso) { |
926 | assert(iso); | 930 | assert(iso); |
927 | return iso->screen; | 931 | return iso->screen; |