1 #ifndef TETRIS_GRAPHICS 2 #define TETRIS_GRAPHICS 3 4 #include <stdint.h> 5 #ifdef AOS_COMP_SDL2 6 #include <SDL.h> 7 #include <SDL_ttf.h> 8 #include <SDL_image.h> 9 #endif 10 11 #define RGB565 12 13 #ifdef RGB565 14 #define COLOR_BLACK 0x000000FF 15 #define COLOR_RED 0xFF4D40FF 16 #define COLOR_GREEN 0x008000FF 17 #define COLOR_BLUE 0x0047ABFF 18 #define COLOR_CYAN 0x00FFFFFF 19 #define COLOR_YELLOW 0xFFFF00FF 20 #define COLOR_PURPLE 0x9400D3FF 21 #define COLOR_ORANGE 0xFFA000FF 22 #define COLOR_WHITE 0xFFFFFFFF 23 #define COLOR_SHADOW 0x808080FF 24 #else 25 #define COLOR_BLACK 0x000000FF 26 #define COLOR_RED 0xFF0000FF 27 #define COLOR_GREEN 0x00FF00FF 28 #define COLOR_BLUE 0x0000FFFF 29 #define COLOR_CYAN 0x00FFFFFF 30 #define COLOR_YELLOW 0xFFFF00FF 31 #define COLOR_PURPLE 0xA000FFFF 32 #define COLOR_ORANGE 0xFFA000FF 33 #define COLOR_WHITE 0xFFFFFFFF 34 #define COLOR_SHADOW 0x606060FF 35 #endif 36 37 #define SCREEN_W 320 38 #define SCREEN_H 240 39 40 #ifdef AOS_COMP_SDL2 41 #define UGRAPHICS_FONT_STYLE TTF_STYLE_BOLD 42 #else 43 #define UGRAPHICS_FONT_STYLE 0 44 #endif 45 46 /** @defgroup ugraphics_aos_api 47 * @{ 48 */ 49 50 /** 51 * Init the ugraphics module. 52 * 53 * @param[in] width width of screen. 54 * @param[in] height height of screen. 55 * 56 * @return 0 on success, negative error on failure. 57 */ 58 int32_t ugraphics_init(int32_t width, int32_t height); 59 60 /** 61 * load ttf font file. 62 * 63 * @param[in] filename ttf font file name. 64 * @param[in] size font size. 65 * 66 * @return 0 on success, negative error on failure. 67 */ 68 int32_t ugraphics_load_font(const char *filename, int32_t size); 69 70 /** 71 * load ttf font file. 72 * 73 * @param[in] style ttf font style. 74 * Refer to SDL_ttf.h: TTF_STYLE_NORMAL/TTF_STYLE_BOLD... 75 * 76 */ 77 void ugraphics_set_font_style(int32_t style); 78 79 /** 80 * Release graphics all resources. 81 * 82 */ 83 void ugraphics_quit(void); 84 85 /** 86 * Flip graphics to lcd. 87 * 88 */ 89 void ugraphics_flip(void); 90 91 /** 92 * Clear graphics on window. 93 * 94 */ 95 int32_t ugraphics_clear(void); 96 97 /** 98 * Set graphics default color. 99 * 100 * @param[in] color grapchic color. 101 * 102 * @return 0 on success, negative error on failure. 103 */ 104 int32_t ugraphics_set_color(uint32_t color); 105 106 /** 107 * Draw empty rectangle to the window. 108 * 109 * @param[in] x grapchic x location on window. 110 * @param[in] y grapchic y location on window. 111 * @param[in] w grapchic width on window. 112 * @param[in] h grapchic height on window. 113 * 114 * @return 0 on success, negative error on failure. 115 */ 116 int32_t ugraphics_draw_rect(int32_t x, int32_t y, int32_t w, int32_t h); 117 118 /** 119 * Fill full rectangle to the window. 120 * 121 * @param[in] x grapchic x location on window. 122 * @param[in] y grapchic y location on window. 123 * @param[in] w grapchic width on window. 124 * @param[in] h grapchic height on window. 125 * 126 * @return 0 on success, negative error on failure. 127 */ 128 int32_t ugraphics_fill_rect(int32_t x, int32_t y, int32_t w, int32_t h); 129 130 /** 131 * Draw line on window. 132 * 133 * @param[in] x1 line x1 start position. 134 * @param[in] y1 line y1 start position. 135 * @param[in] x2 line x2 end position. 136 * @param[in] y2 line y2 end position. 137 * 138 * @return 0 on success, negative error on failure. 139 */ 140 int32_t ugraphics_draw_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2); 141 142 /** 143 * Draw string on window. 144 * 145 * @param[in] string string you want to draw. 146 * @param[in] x draw string at x postion of window. 147 * @param[in] y draw string at y position of window. 148 * 149 * @return 0 on success, negative error on failure. 150 */ 151 int32_t ugraphics_draw_string(char *string, int32_t x, int32_t y); 152 153 /** 154 * Count string width. 155 * 156 * @param[in] string string you want to draw. 157 * 158 * @return 0 on success, negative error on failure. 159 */ 160 int32_t ugraphics_string_width(char *string); 161 162 /** 163 * Save image graphic buffer to a image file. 164 * @param[in] buffer image buffer. 165 * @param[in] len image buffer length. 166 * @param[in] path image file path in file system. 167 * 168 * @return 0 on success, negative error on failure. 169 */ 170 int32_t ugraphics_save_image(char *buffer, int32_t len, const char *path); 171 172 /** 173 * Release graphics all resources. 174 * 175 * @param[in] file image file location. 176 * @param[in] x x position on window. 177 * @param[in] y y position on window. 178 * 179 * @return 0 on success, negative error on failure. 180 */ 181 int32_t ugraphics_draw_image(const char *file, int32_t x, int32_t y); 182 183 /** 184 * @} 185 */ 186 #endif // TETRIS_GRAPHICS 187