aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy.h
diff options
context:
space:
mode:
Diffstat (limited to 'teensy/teensy.h')
-rw-r--r--teensy/teensy.h109
1 files changed, 59 insertions, 50 deletions
diff --git a/teensy/teensy.h b/teensy/teensy.h
index 4a60882..c272664 100644
--- a/teensy/teensy.h
+++ b/teensy/teensy.h
@@ -6,10 +6,17 @@
#include "teensy_common.h"
#include "teensy_list.h"
-#define ty_vec2(x, y) ((struct ty_vec2){x, y})
-#define ty_vec2i(x, y) ((struct ty_vec2i){x, y})
-#define ty_color(R, G, B) ((struct ty_color){R, G, B})
-#define ty_img_full(img) ((struct ty_recti){0, 0, (img).width, (img).height})
+#define ty_vec2(x, y) ((ty_Vec2){x, y})
+#define ty_vec2i(x, y) ((ty_Vec2i){x, y})
+#define ty_color(R, G, B) ((ty_Color){R, G, B})
+#define ty_img_full(img) ((ty_Recti){0, 0, (img).width, (img).height})
+
+#define ty_rect_start(rect) (ty_vec2(rect.x, rect.y))
+#define ty_recti_start(rect) (ty_vec2i(rect.x, rect.y))
+#define ty_rect_end(rect) (ty_vec2(rect.x+rect.w, rect.y+rect.h))
+#define ty_recti_end(rect) (ty_vec2i(rect.x+rect.w, rect.y+rect.h))
+#define ty_rect_size(rect) (ty_vec2(rect.w, rect.h))
+#define ty_recti_size(rect) (ty_vec2i(rect.w, rect.h))
#define TY_COLOR_BLACK ty_color(0, 0, 0 )
#define TY_COLOR_RED ty_color(255, 0, 0 )
@@ -19,9 +26,10 @@
#define TY_COLOR_MAGENTA ty_color(255, 0, 255)
#define TY_COLOR_CYAN ty_color(0, 255, 255)
#define TY_COLOR_WHITE ty_color(255, 255, 255)
+#define TY_COLOR_GRAY ty_color(128, 128, 128)
// Virtual controller. Keyboard keys are also mapped to this.
-enum ty_button {
+enum {
TY_BTN_LEFT_UP, // D-pad #1 up
TY_BTN_LEFT_DOWN, // D-pad #1 down
TY_BTN_LEFT_LEFT, // D-pad #1 left
@@ -43,61 +51,62 @@ enum ty_button {
TY_BTN_COUNT,
};
+typedef uint8_t ty_Button;
-struct ty_hints {
+typedef struct {
int scr_width;
int scr_height;
const char *game_title;
int ticrate;
-};
+} ty_Hints;
-struct ty_color {
+typedef struct {
uint8_t r;
uint8_t g;
uint8_t b;
-};
+} ty_Color;
-struct ty_vec2 {
+typedef struct {
float x;
float y;
-};
+} ty_Vec2;
-struct ty_vec2i {
+typedef struct {
int x;
int y;
-};
+} ty_Vec2i;
-struct ty_rect {
+typedef struct {
float x;
float y;
float w;
float h;
-};
+} ty_Rect;
-struct ty_recti {
+typedef struct {
int x;
int y;
int w;
int h;
-};
+} ty_Recti;
-struct ty_image {
- struct ty_color *data;
+typedef struct {
+ ty_Color *data;
int width;
int height;
-};
+} ty_Image;
-struct ty_font {
- struct ty_image glyphs[CHAR_MAX];
-};
+typedef struct {
+ ty_Image glyphs[CHAR_MAX];
+} ty_Font;
-void ty_init(struct ty_hints hints);
+void ty_init(ty_Hints hints);
void ty_deinit(void);
// If the button is being held down
-bool ty_button_down(enum ty_button btn);
+bool ty_button_down(ty_Button btn);
// If the button was pressed just now
-bool ty_button_pressed(enum ty_button btn);
+bool ty_button_pressed(ty_Button btn);
// Whether or not the main loop should continue executing.
bool ty_is_game_running(void);
@@ -107,43 +116,43 @@ double ty_get_time(void);
// tic.
int ty_tick(void);
-struct ty_image ty_create_image(int w, int h, const struct ty_color* data);
-void ty_free_image(struct ty_image img);
-struct ty_color ty_img_get_pixel(struct ty_image img, struct ty_vec2i pos);
+ty_Image ty_create_image(int w, int h, const ty_Color* data);
+void ty_free_image(ty_Image img);
+ty_Color ty_img_get_pixel(ty_Image img, ty_Vec2i pos);
void ty_img_set_pixel(
- struct ty_image img,
- struct ty_vec2i pos,
- struct ty_color color
+ ty_Image img,
+ ty_Vec2i pos,
+ ty_Color color
);
-void ty_font_add_glyph(struct ty_font *font, uint8_t c, struct ty_image img);
-int ty_font_width(struct ty_font *font, const char *fmt, ...);
+void ty_font_add_glyph(ty_Font *font, uint8_t c, ty_Image img);
+int ty_font_width(ty_Font *font, const char *fmt, ...);
// Pass NULL to restore the screen.
-void ty_draw_set_target(const struct ty_image *img);
-void ty_draw_clear(struct ty_color col);
-void ty_draw_image(struct ty_image img, struct ty_vec2i pos);
+void ty_draw_set_target(const ty_Image *img);
+void ty_draw_clear(ty_Color col);
+void ty_draw_image(ty_Image img, ty_Vec2i pos);
void ty_draw_image_ex(
- struct ty_image img,
- struct ty_recti src,
- struct ty_recti dst
+ ty_Image img,
+ ty_Recti src,
+ ty_Recti dst
);
void ty_draw_image_rot(
- struct ty_image img,
- struct ty_vec2i pos,
- struct ty_vec2i offset,
+ ty_Image img,
+ ty_Vec2i pos,
+ ty_Vec2i offset,
double rot
);
-void ty_draw_rect(struct ty_recti rect, struct ty_color color);
+void ty_draw_rect(ty_Recti rect, ty_Color color);
void ty_draw_line(
- struct ty_vec2i start,
- struct ty_vec2i end,
- struct ty_color color
+ ty_Vec2i start,
+ ty_Vec2i end,
+ ty_Color color
);
-void ty_draw_text(struct ty_font *font, struct ty_vec2i pos, const char *text);
+void ty_draw_text(ty_Font *font, ty_Vec2i pos, const char *text);
void ty_draw_text_fmt(
- struct ty_font *font,
- struct ty_vec2i pos,
+ ty_Font *font,
+ ty_Vec2i pos,
const char *fmt,
...
);