diff options
Diffstat (limited to 'inc/lzy.h')
-rw-r--r-- | inc/lzy.h | 43 |
1 files changed, 19 insertions, 24 deletions
@@ -90,8 +90,8 @@ void LZY_DrawSetColorNone(void); int LZY_DrawClear(void); int LZY_DrawPoint(int x, int y); int LZY_DrawLine(int x0, int y0, int x1, int y1); -int LZY_DrawRect(int x, int y, unsigned int w, unsigned int h); -int LZY_DrawFillRect(int x, int y, unsigned int w, unsigned int h); +int LZY_DrawRect(int x, int y, int w, int h); +int LZY_DrawFillRect(int x, int y, int w, int h); int LZY_DrawTile(unsigned int id, int x, int y); int LZY_DrawTileEx(unsigned int id, int x, int y, unsigned int w, unsigned int h); @@ -210,6 +210,10 @@ static unsigned int tset_width, tset_height; static unsigned int font_width, font_height; static int timer_callback(volatile int *); +static int _LZY_Sign(int n) { + return (n > 0) - (n < 0); +} + int LZY_Init(const char *title, int target_fps, const char *tset_path, const char *font_path) { extern bopti_image_t LZY_GINT_TILESET; @@ -276,23 +280,24 @@ int LZY_DrawPoint(int x, int y) { return 0; } -int LZY_DrawRect(int x, int y, unsigned int w, unsigned int h) { - if (w < 1 || h < 1) - return -1; +int LZY_DrawRect(int x, int y, int w, int h) { + w += w == 0; + h += h == 0; x += draw_off_x; y += draw_off_y; - drect_border(x, y, x + w - 1, y + h - 1, C_NONE, 1, draw_color); + drect_border(x, y, x + w - _LZY_Sign(w), y + h - _LZY_Sign(h), C_NONE, + 1, draw_color); return 0; } -int LZY_DrawFillRect(int x, int y, unsigned int w, unsigned int h) { - if (w < 1 || h < 1) - return -1; +int LZY_DrawFillRect(int x, int y, int w, int h) { + w += w == 0; + h += h == 0; x += draw_off_x; y += draw_off_y; - drect(x, y, x + w - 1, y + h - 1, draw_color); + drect(x, y, x + w - _LZY_Sign(w), y + h - _LZY_Sign(h), draw_color); return 0; } @@ -716,13 +721,8 @@ int LZY_DrawPoint(int x, int y) { return 0; } -int LZY_DrawRect(int x, int y, unsigned int w, unsigned int h) { - const SDL_Rect rect = {x, y, w, h}; - - if (w == 0 || h == 0) { - error = "rectangle dimensions cannot be 0"; - return -1; - } +int LZY_DrawRect(int x, int y, int w, int h) { + const SDL_Rect rect = {x, y, w + (w == 0), h + (h == 0)}; if (SDL_RenderDrawRect(renderer, &rect) < 0) { error = SDL_GetError(); @@ -731,13 +731,8 @@ int LZY_DrawRect(int x, int y, unsigned int w, unsigned int h) { return 0; } -int LZY_DrawFillRect(int x, int y, unsigned int w, unsigned int h) { - const SDL_Rect rect = {x, y, w, h}; - - if (w == 0 || h == 0) { - error = "rectangle dimensions cannot be 0"; - return -1; - } +int LZY_DrawFillRect(int x, int y, int w, int h) { + const SDL_Rect rect = {x, y, w + (w == 0), h + (h == 0)}; if (SDL_RenderFillRect(renderer, &rect) < 0) { error = SDL_GetError(); |