1 /* 2 * File: gl_text.h 3 * Author: TeslaRus 4 * 5 * Created on October 24, 2015, 11:34 AM 6 */ 7 8 #ifndef GL_TEXT_H 9 #define GL_TEXT_H 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 #include <stdint.h> 16 #include <stdarg.h> 17 #include <SDL2/SDL_platform.h> 18 #include <SDL2/SDL_opengl.h> 19 20 #include "gl_font.h" 21 22 23 #define GLTEXT_MAX_FONTSTYLES 32 24 #define GLTEXT_MAX_FONTS 8 25 26 #define GLTEXT_MAX_TEMP_LINES (256) 27 28 // Horizontal alignment is simple side alignment, like in original TRs. 29 // It means that X coordinate will be either used for left, right or 30 // center orientation. 31 32 #define GLTEXT_ALIGN_LEFT 0 33 #define GLTEXT_ALIGN_RIGHT 1 34 #define GLTEXT_ALIGN_TOP 0 35 #define GLTEXT_ALIGN_BOTTOM 1 36 #define GLTEXT_ALIGN_CENTER 2 37 38 // Default line size is generally used for static in-game strings. Strings 39 // that are created dynamically may have variable string sizes. 40 41 #define GUI_LINE_DEFAULTSIZE 128 42 43 44 // OpenTomb has three types of fonts - primary, secondary and console 45 // font. This should be enough for most of the cases. However, user 46 // can generate and use additional font types via script, but engine 47 // behaviour with extra font types is undefined. 48 enum font_Type 49 { 50 FONT_CONSOLE = 0, 51 FONT_PRIMARY, 52 FONT_SECONDARY 53 }; 54 55 // This is predefined enumeration of font styles, which can be extended 56 // with user-defined script functions. 57 ///@TODO: add system message console style 58 enum font_Style 59 { 60 FONTSTYLE_CONSOLE_INFO = 0, 61 FONTSTYLE_CONSOLE_WARNING, 62 FONTSTYLE_CONSOLE_EVENT, 63 FONTSTYLE_CONSOLE_NOTIFY, 64 FONTSTYLE_MENU_TITLE, 65 FONTSTYLE_MENU_HEADING1, 66 FONTSTYLE_MENU_HEADING2, 67 FONTSTYLE_MENU_ITEM_ACTIVE, 68 FONTSTYLE_MENU_ITEM_INACTIVE, 69 FONTSTYLE_MENU_CONTENT, 70 FONTSTYLE_STATS_TITLE, 71 FONTSTYLE_STATS_CONTENT, 72 FONTSTYLE_NOTIFIER, 73 FONTSTYLE_SAVEGAMELIST, 74 FONTSTYLE_GENERIC 75 }; 76 77 78 typedef struct gl_text_line_s 79 { 80 char *text; 81 uint16_t font_id; 82 uint16_t style_id; 83 uint16_t text_size; 84 uint16_t x_align : 4; 85 uint16_t y_align : 4; 86 uint16_t show : 1; 87 88 GLfloat line_width; 89 GLfloat line_height; 90 GLfloat x; 91 GLfloat y; 92 GLfloat rect[4]; //x0, y0, x1, y1 93 94 struct gl_text_line_s *next; 95 struct gl_text_line_s *prev; 96 } gl_text_line_t, *gl_text_line_p; 97 98 99 /** 100 * Draws text using a FONT_SECONDARY. 101 */ 102 void GLText_Init(); 103 void GLText_Destroy(); 104 105 void GLText_UpdateResize(int w, int h, float scale); 106 void GLText_RenderStringLine(gl_text_line_p l); 107 void GLText_RenderStrings(); 108 109 void GLText_AddLine(gl_text_line_p line); 110 void GLText_DeleteLine(gl_text_line_p line); 111 gl_text_line_p GLText_OutTextXY(GLfloat x, GLfloat y, const char *fmt, ...); 112 gl_text_line_p GLText_VOutTextXY(GLfloat x, GLfloat y, const char *fmt, va_list argptr); 113 114 115 int GLText_AddFont(uint16_t index, uint16_t size, const char* path); 116 int GLText_RemoveFont(uint16_t index); 117 int GLText_AddFontStyle(uint16_t index, 118 GLfloat R, GLfloat G, GLfloat B, GLfloat A, 119 uint8_t shadow, uint8_t rect, uint8_t rect_border, 120 GLfloat rect_R, GLfloat rect_G, GLfloat rect_B, GLfloat rect_A); 121 int GLText_RemoveFontStyle(uint16_t index); 122 gl_tex_font_p GLText_GetFont(uint16_t index); 123 gl_fontstyle_p GLText_GetFontStyle(uint16_t index); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif /* GL_TEXT_H */ 130 131