/*
 * Graphic driver for openKropki
 *
 * Copyright (C) 2014-2020 Mateusz Viste
 *
 * MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef drv_gra_h_sentinel
#define drv_gra_h_sentinel

#include <stdint.h> /* uint8_t and friends */

#define GRA_FULLSCREEN 1

struct gra_sprite;

/* init the video subsystem */
int gra_init(int width, int height, int flags, const char *windowtitle, const void *titleicon, long titleicon_len);

/* plays wav.gz data */
void gra_playwavgz(const void *memgz, long memgzlen);

/* close and clean up the graphic subsystem */
void gra_close(void);

/* clears the screen and fills with an rgb color (should be used at each screen refresh iteration) */
void gra_clear(uint32_t rgb);

/* renders a full background using a bmp.gz tile */
void gra_bgtile(const void *memgz, long memgzlen);

/* switch the application fullscreen on/off */
void gra_switchfullscreen(void);

void gra_drawpartsprite(const struct gra_sprite *sprite, int srcx, int srcy, int srcwidth, int srcheight, int dstx, int dsty);

void gra_drawsprite(const struct gra_sprite *sprite, int x, int y);

void gra_refresh(void);

/* loads a gziped bmp image from memory and returns an RGB surface with transparent color always set to 0xff00ff */
struct gra_sprite *gra_loadgzbmp(const void *memgz, long memgzlen);

void loadSpriteSheet(struct gra_sprite **sprites, int width, int height, int itemcount, const void *memptr, int memlen);

int gra_getspritewidth(const struct gra_sprite *sprite);

int gra_getspriteheight(const struct gra_sprite *sprite);

int gra_drawrect(int x, int y, int width, int height, uint32_t rgb, uint8_t a, int fillflag);

void gra_drawline(int x1, int y1, int x2, int y2, int thickness, uint32_t rgb, uint8_t a);

void gra_circle(int x, int y, int rad, uint32_t rgb, uint8_t a);

void gra_circle_filled(int x, int y, int rad, uint32_t rgb, uint8_t a);

/* generate a sprite that contains a text message using a ttf font of specific size and color. the text is wrapped to maxwidth pixels, or to the window width if maxwidth is less than 1. bg color will be 'transparent' if bg is set to -1, otherwise it will be filled with a solid color. */
struct gra_sprite *gra_text2sprite(const char *message, const void *font_ttf, long font_ttf_len, int fontSize, uint32_t fg, int32_t bg, uint8_t a, int maxwidth);

void gra_freesprite(struct gra_sprite *spr);

/* provides window's width and height, in pixels */
void gra_getwinsize(int *w, int *h);

#endif