diff options
Diffstat (limited to 'display.c')
-rw-r--r-- | display.c | 69 |
1 files changed, 41 insertions, 28 deletions
@@ -2,9 +2,12 @@ | |||
2 | #include "SDL2/SDL2_gfxPrimitives.h" | 2 | #include "SDL2/SDL2_gfxPrimitives.h" |
3 | #include <SDL2/SDL_ttf.h> | 3 | #include <SDL2/SDL_ttf.h> |
4 | 4 | ||
5 | #include "GenBkBasB.h" | ||
6 | #include "display.h" | 5 | #include "display.h" |
7 | 6 | ||
7 | #define FONT_NAME(suffix) SourceCodePro_Semibold ## suffix | ||
8 | extern unsigned char FONT_NAME(_ttf[]); | ||
9 | extern unsigned int FONT_NAME(_ttf_len); | ||
10 | |||
8 | #define display_measure_text(text,w,h) TTF_SizeText(font,(text),(w),(h)) | 11 | #define display_measure_text(text,w,h) TTF_SizeText(font,(text),(w),(h)) |
9 | enum { FONT_SIZE = 28 }; | 12 | enum { FONT_SIZE = 28 }; |
10 | 13 | ||
@@ -39,7 +42,7 @@ display_init(int screen_width, int screen_height, int harfe_width, int harfe_hei | |||
39 | SDL_RenderClear(renderer); | 42 | SDL_RenderClear(renderer); |
40 | 43 | ||
41 | TTF_Init(); | 44 | TTF_Init(); |
42 | font_file = SDL_RWFromConstMem(GenBkBasB_ttf, GenBkBasB_ttf_len); | 45 | font_file = SDL_RWFromConstMem( FONT_NAME(_ttf), FONT_NAME(_ttf_len) ); |
43 | font = TTF_OpenFontRW(font_file, 1, FONT_SIZE); | 46 | font = TTF_OpenFontRW(font_file, 1, FONT_SIZE); |
44 | 47 | ||
45 | g_scale_factor = (double)harfe_height / (double)screen_height; | 48 | g_scale_factor = (double)harfe_height / (double)screen_height; |
@@ -108,17 +111,22 @@ display_line_color(int x0, int y0, int x1, int y1, int color) | |||
108 | SDL_RenderDrawLine(renderer, x0, y0, x1, y1); | 111 | SDL_RenderDrawLine(renderer, x0, y0, x1, y1); |
109 | } | 112 | } |
110 | 113 | ||
111 | void | 114 | static void |
112 | display_rect_color(int x, int y, int width, int height, int color) | 115 | display_rect_color_static(int x, int y, int width, int height, int color) |
113 | { | 116 | { |
114 | SDL_Rect r; | 117 | SDL_Rect r; |
115 | r.x = x; | 118 | r.x = x; |
116 | r.y = g_screen_height - y; | 119 | r.y = y; |
117 | r.w = width; | 120 | r.w = width; |
118 | r.h = height; | 121 | r.h = height; |
119 | SDL_SetRenderDrawColor(renderer, (color >> 24) & 255, (color >> 16) & 255, (color >> 8) & 255, 255); | 122 | SDL_SetRenderDrawColor(renderer, (color >> 24) & 255, (color >> 16) & 255, (color >> 8) & 255, 255); |
120 | SDL_RenderFillRect(renderer, &r); | 123 | SDL_RenderFillRect(renderer, &r); |
121 | } | 124 | } |
125 | void | ||
126 | display_rect_color(int x, int y, int width, int height, int color) | ||
127 | { | ||
128 | display_rect_color_static(x, g_screen_height - y, width, height, color); | ||
129 | } | ||
122 | 130 | ||
123 | void | 131 | void |
124 | display_redraw() | 132 | display_redraw() |
@@ -126,10 +134,9 @@ display_redraw() | |||
126 | SDL_RenderPresent(renderer); | 134 | SDL_RenderPresent(renderer); |
127 | } | 135 | } |
128 | 136 | ||
129 | void | 137 | static void |
130 | display_text(char *text, int x, int y, int color) | 138 | display_text_static(char const *text, int x, int y, int color) |
131 | { | 139 | { |
132 | y = g_screen_height - y; | ||
133 | SDL_Color s_color = { 255 & (color>>24), 255 & (color>>16), 255 & (color>>8) }; | 140 | SDL_Color s_color = { 255 & (color>>24), 255 & (color>>16), 255 & (color>>8) }; |
134 | SDL_Surface *sText = TTF_RenderText_Solid(font, text, s_color); | 141 | SDL_Surface *sText = TTF_RenderText_Solid(font, text, s_color); |
135 | SDL_Rect rect = {x, y, sText->w, sText->h}; | 142 | SDL_Rect rect = {x, y, sText->w, sText->h}; |
@@ -139,20 +146,41 @@ display_text(char *text, int x, int y, int color) | |||
139 | SDL_DestroyTexture(texture); | 146 | SDL_DestroyTexture(texture); |
140 | SDL_FreeSurface(sText); | 147 | SDL_FreeSurface(sText); |
141 | } | 148 | } |
149 | void | ||
150 | display_text(char const *text, int x, int y, int color) | ||
151 | { | ||
152 | display_text_static(text, x, g_screen_height - y, color); | ||
153 | } | ||
142 | 154 | ||
143 | void | 155 | void |
144 | display_textbox(int min_x, int pos, int max_x, int max_pos, char *text, int color) | 156 | display_textbox(int min_x, int pos, int max_x, int max_pos, char const *text, int color) |
145 | { | 157 | { |
146 | int w, h, min_y, item_height; | 158 | int w, h, min_y, item_height; |
147 | 159 | ||
148 | display_measure_text("#", &w, &h); | 160 | display_measure_text("#", &w, &h); |
149 | item_height = 3 * h / 2; | 161 | item_height = 3 * h / 2; |
150 | min_y = (g_screen_height - item_height * max_pos) / 2 + pos * item_height; | 162 | min_y = pos * item_height + 4; |
163 | |||
164 | display_rect_color_static(min_x, min_y, max_x - min_x, item_height - 4, color); | ||
151 | 165 | ||
152 | //boxColor(screen, min_x, min_y, max_x, min_y + item_height, color); | ||
153 | //rectangleColor(screen, min_x, min_y, max_x, min_y + item_height, 0xffffffff); | ||
154 | display_measure_text(text, &w, &h); | 166 | display_measure_text(text, &w, &h); |
155 | display_text(text, min_x + (max_x - min_x - w) / 2, min_y + (item_height - h) / 2, 0xffffffff); | 167 | // display_text(text, min_x + (max_x - min_x - w) / 2, min_y + (item_height - h) / 2, 0xffffffff); |
168 | display_text_static(text, min_x + 8, min_y + (item_height - h) / 2, 0xffffffff); | ||
169 | } | ||
170 | |||
171 | int | ||
172 | display_test_menu_click(int y) | ||
173 | { | ||
174 | int w, h, min_y, item_height; | ||
175 | |||
176 | y -= 4; | ||
177 | if (y<0) | ||
178 | return -1; | ||
179 | |||
180 | display_measure_text( "#", &w, &h ); | ||
181 | item_height = 3 * h / 2; | ||
182 | |||
183 | return y / item_height; | ||
156 | } | 184 | } |
157 | 185 | ||
158 | void | 186 | void |
@@ -174,18 +202,3 @@ display_messagebox_yesno(char *title, char *info) { | |||
174 | return buttonid == 1; | 202 | return buttonid == 1; |
175 | } | 203 | } |
176 | 204 | ||
177 | int | ||
178 | display_test_menu_click(int y, int max_pos) | ||
179 | { | ||
180 | int w, h, min_y, item_height; | ||
181 | |||
182 | /* | ||
183 | display_measure_text( "#", &w, &h ); | ||
184 | item_height = 3 * h / 2; | ||
185 | min_y = ( g_screen_height - item_height * max_pos ) / 2; | ||
186 | if( y < min_y ) return -1; | ||
187 | if( y > min_y + item_height * max_pos ) return -1; | ||
188 | return ( y - min_y ) / item_height; | ||
189 | */ | ||
190 | return 0; | ||
191 | } | ||