summaryrefslogtreecommitdiff
path: root/gfx-iso
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-iso')
-rw-r--r--gfx-iso/include/isogfx/isogfx.h3
-rw-r--r--gfx-iso/src/isogfx.c22
2 files changed, 16 insertions, 9 deletions
diff --git a/gfx-iso/include/isogfx/isogfx.h b/gfx-iso/include/isogfx/isogfx.h
index e96606c..3421a7b 100644
--- a/gfx-iso/include/isogfx/isogfx.h
+++ b/gfx-iso/include/isogfx/isogfx.h
@@ -123,6 +123,9 @@ void isogfx_draw_tile(IsoGfx*, int x, int y, Tile);
123/// Resize the virtual screen's dimensions. 123/// Resize the virtual screen's dimensions.
124bool isogfx_resize(IsoGfx*, int screen_width, int screen_height); 124bool isogfx_resize(IsoGfx*, int screen_width, int screen_height);
125 125
126/// Get the virtual screen's dimensions.
127void isogfx_get_screen_size(const IsoGfx*, int* width, int* height);
128
126/// Return a pointer to the virtual screen's colour buffer. 129/// Return a pointer to the virtual screen's colour buffer.
127/// 130///
128/// Call after each call to isogfx_render() to retrieve the render output. 131/// Call after each call to isogfx_render() to retrieve the render output.
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
921void 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
925const Pixel* isogfx_get_screen_buffer(const IsoGfx* iso) { 929const Pixel* isogfx_get_screen_buffer(const IsoGfx* iso) {
926 assert(iso); 930 assert(iso);
927 return iso->screen; 931 return iso->screen;