center draw with gint

This commit is contained in:
KikooDX 2022-03-15 00:15:14 +01:00
parent d04324372d
commit 139dbb6a01
1 changed files with 13 additions and 2 deletions

View File

@ -185,6 +185,8 @@ int LZY_DrawLine(int x0, int y0, int x1, int y1) {
#include <gint/timer.h>
#include <stdint.h>
static const int draw_off_x = (DWIDTH - LZY_DISPLAY_WIDTH) / 2;
static const int draw_off_y = (DHEIGHT - LZY_DISPLAY_HEIGHT) / 2;
static color_t draw_color = C_BLACK;
static int should_quit = 0;
static int timer = 0;
@ -195,7 +197,6 @@ static unsigned int tset_width, tset_height;
#ifdef LZY_GINT_FONT
static unsigned int font_width, font_height;
#endif
static int timer_callback(volatile int *);
int LZY_Init(int argc, const char **argv, const char *title, int target_fps,
@ -262,13 +263,16 @@ int LZY_DrawClear(void) {
}
int LZY_DrawPoint(int x, int y) {
dpixel(x, y, draw_color);
dpixel(x + draw_off_x, y + draw_off_y, draw_color);
return 0;
}
int LZY_DrawRect(int x, int y, unsigned int w, unsigned int h) {
if (w < 1 || h < 1)
return -1;
x += draw_off_x;
y += draw_off_y;
drect_border(x, y, x + w - 1, y + h - 1, C_NONE, 1, draw_color);
return 0;
}
@ -276,6 +280,9 @@ 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) {
if (w < 1 || h < 1)
return -1;
x += draw_off_x;
y += draw_off_y;
drect(x, y, x + w - 1, y + h - 1, draw_color);
return 0;
}
@ -292,6 +299,8 @@ int LZY_DrawTile(unsigned int id, int x, int y) {
if (id >= tset_width * tset_height)
return -1;
x += draw_off_x;
y += draw_off_y;
ix = id % tset_width * LZY_TILE_SIZE;
iy = id % tset_height * LZY_TILE_SIZE;
@ -315,6 +324,8 @@ int LZY_DrawChar(unsigned char chr, int x, int y) {
if (id >= font_width * font_height)
return -1;
x += draw_off_x;
y += draw_off_y;
ix = (id % font_width) * LZY_CHR_WIDTH;
iy = (id / font_width) * LZY_CHR_HEIGHT;