@@ -90,7 +90,7 @@ void Draw::BlitBeam(int rotation, int x, int y) {
9090 SDL_RenderFillRect (renderer, &r);
9191}
9292
93- void Draw::BlitMessage (const char *title, char **lines, size_t line_count) {
93+ void Draw::BlitMessage (const char *title, const char **lines, int line_count) {
9494 int widest_line = 0 ;
9595 int text_height = 0 ;
9696 SDL_Surface * title_surface = TTF_RenderText_Solid (font, title, {0 , 0 , 0 , 255 });
@@ -130,79 +130,81 @@ void Draw::BlitMessage(const char *title, char **lines, size_t line_count) {
130130 }
131131
132132 // Draw outside box
133- SDL_Rect box = {(COLUMNS * BLOCK_SIZE / 2 ) - ((widest_line + BLOCK_SIZE ) / 2 ), (ROWS * BLOCK_SIZE / 2 ) - ((text_height + BLOCK_SIZE ) / 2 ), widest_line + BLOCK_SIZE , text_height + BLOCK_SIZE };
134- box.x = 0 ;
135- box.y = 0 ;
133+ SDL_Rect box = {(COLUMNS * BLOCK_SIZE / 2 ) - ((widest_line + BLOCK_SIZE / 2 ) / 2 ), (ROWS * BLOCK_SIZE / 2 ) - ((text_height + BLOCK_SIZE / 2 ) / 2 ), widest_line + BLOCK_SIZE / 2 , text_height + BLOCK_SIZE / 2 };
134+ BlitMessageBox (&box);
135+
136+ // Draw text
137+ SDL_Rect title_rect = {box.x + box.w / 2 , box.y + BLOCK_SIZE / 4 , 0 , 0 };
138+ SDL_QueryTexture (title_texture, NULL , NULL , &title_rect.w , &title_rect.h );
139+ title_rect.x -= title_rect.w / 2 ;
140+ SDL_RenderCopy (renderer, title_texture, NULL , &title_rect);
141+
142+ int current_text_y = title_rect.y + title_rect.h ;
143+ for (int i = 0 ; i < line_count; i++) {
144+ SDL_Rect line_rect = {box.x + box.w / 2 , current_text_y, 0 , 0 };
145+ SDL_QueryTexture (line_textures[i], NULL , NULL , &line_rect.w , &line_rect.h );
146+ line_rect.x -= line_rect.w / 2 ;
147+ current_text_y += line_rect.h ;
148+ SDL_RenderCopy (renderer, line_textures[i], NULL , &line_rect);
149+ }
150+
151+ // Clean up
152+ SDL_DestroyTexture (title_texture);
153+ for (int i = 0 ; i < line_count; i++) {
154+ SDL_DestroyTexture (line_textures[i]);
155+ }
156+ free (line_textures);
157+ }
158+
159+ void Draw::BlitMessageBox (SDL_Rect *box) {
136160 SDL_SetRenderDrawColor (renderer, 87 , 247 , 249 , 255 );
137161
138162 // Top 2 lines
139- SDL_RenderDrawLine (renderer, box. x , box. y , box. x + box. w - 1 , box. y );
140- SDL_RenderDrawLine (renderer, box. x , box. y + 1 , box. x + box. w - 2 , box. y + 1 );
163+ SDL_RenderDrawLine (renderer, box-> x , box-> y , box-> x + box-> w - 1 , box-> y );
164+ SDL_RenderDrawLine (renderer, box-> x , box-> y + 1 , box-> x + box-> w - 2 , box-> y + 1 );
141165
142166 // Left 2 lines
143- SDL_RenderDrawLine (renderer, box. x , box. y + 2 , box. x , box. y + box. h - 1 );
144- SDL_RenderDrawLine (renderer, box. x + 1 , box. y + 2 , box. x + 1 , box. y + box. h - 2 );
167+ SDL_RenderDrawLine (renderer, box-> x , box-> y + 2 , box-> x , box-> y + box-> h - 1 );
168+ SDL_RenderDrawLine (renderer, box-> x + 1 , box-> y + 2 , box-> x + 1 , box-> y + box-> h - 2 );
145169
146170 SDL_SetRenderDrawColor (renderer, 2 , 59 , 60 , 255 );
147171 // Bottom 2 lines
148- SDL_RenderDrawLine (renderer, box. x + 1 , box. y + box. h - 1 , box. x + box. w , box. y + box. h - 1 );
149- SDL_RenderDrawLine (renderer, box. x , box. y + box. h , box. x + box. w , box. y + box. h );
172+ SDL_RenderDrawLine (renderer, box-> x + 1 , box-> y + box-> h - 1 , box-> x + box-> w , box-> y + box-> h - 1 );
173+ SDL_RenderDrawLine (renderer, box-> x , box-> y + box-> h , box-> x + box-> w , box-> y + box-> h );
150174
151175 // Right 2 lines
152- SDL_RenderDrawLine (renderer, box. x + box. w - 1 , box. y + 1 , box. x + box. w - 1 , box. y + box. h - 2 );
153- SDL_RenderDrawLine (renderer, box. x + box. w , box. y , box. x + box. w , box. y + box. h - 2 );
176+ SDL_RenderDrawLine (renderer, box-> x + box-> w - 1 , box-> y + 1 , box-> x + box-> w - 1 , box-> y + box-> h - 2 );
177+ SDL_RenderDrawLine (renderer, box-> x + box-> w , box-> y , box-> x + box-> w , box-> y + box-> h - 2 );
154178
155179 SDL_SetRenderDrawColor (renderer, 3 , 103 , 107 , 255 );
156180 for (int i = 0 ; i < 4 ; i++){
157181 SDL_Rect current_line_box = {
158- box. x + 2 + i,
159- box. y + 2 + i,
160- box. w - 3 - (i * 2 ),
161- box. h - 3 - (i * 2 ),
182+ box-> x + 2 + i,
183+ box-> y + 2 + i,
184+ box-> w - 3 - (i * 2 ),
185+ box-> h - 3 - (i * 2 ),
162186 };
163187 SDL_RenderDrawRect (renderer, ¤t_line_box);
164188 }
165189
166190 // Render inside lines
167191 SDL_SetRenderDrawColor (renderer, 2 , 59 , 60 , 255 );
168- SDL_RenderDrawLine (renderer, box. x + 6 , box. y + 6 , box. x + box. w - 6 , box. y + 6 );
169- SDL_RenderDrawLine (renderer, box. x + 6 , box. y + 7 , box. x + 6 , box. y + box. h - 6 );
192+ SDL_RenderDrawLine (renderer, box-> x + 6 , box-> y + 6 , box-> x + box-> w - 6 , box-> y + 6 );
193+ SDL_RenderDrawLine (renderer, box-> x + 6 , box-> y + 7 , box-> x + 6 , box-> y + box-> h - 6 );
170194
171195 SDL_SetRenderDrawColor (renderer, 87 , 247 , 249 , 255 );
172- SDL_RenderDrawLine (renderer, box. x + 7 , box. y + box. h - 6 , box. x + box. w - 6 , box. y + box. h - 6 );
173- SDL_RenderDrawLine (renderer, box. x + box. w - 6 , box. y + 7 , box. x + box. w - 6 , box. y + box. h - 7 );
196+ SDL_RenderDrawLine (renderer, box-> x + 7 , box-> y + box-> h - 6 , box-> x + box-> w - 6 , box-> y + box-> h - 6 );
197+ SDL_RenderDrawLine (renderer, box-> x + box-> w - 6 , box-> y + 7 , box-> x + box-> w - 6 , box-> y + box-> h - 7 );
174198
175199 // Render background
176200 SDL_SetRenderDrawColor (renderer, 3 , 103 , 107 , 255 );
177201 SDL_Rect background_rect = {
178- box. x + 7 ,
179- box. y + 7 ,
180- box. w - 13 ,
181- box. h - 13
202+ box-> x + 7 ,
203+ box-> y + 7 ,
204+ box-> w - 13 ,
205+ box-> h - 13
182206 };
183207 SDL_RenderFillRect (renderer, &background_rect);
184-
185- // Draw text
186- SDL_Rect title_rect = {background_rect.w / 2 , BLOCK_SIZE / 2 , 0 , 0 };
187- SDL_QueryTexture (title_texture, NULL , NULL , &title_rect.w , &title_rect.h );
188- title_rect.x -= title_rect.w / 2 ;
189- SDL_RenderCopy (renderer, title_texture, NULL , &title_rect);
190-
191- int current_text_y = title_rect.y + title_rect.h ;
192- for (int i = 0 ; i < line_count; i++) {
193- SDL_Rect line_rect = {background_rect.w / 2 , current_text_y, 0 , 0 };
194- SDL_QueryTexture (line_textures[i], NULL , NULL , &line_rect.w , &line_rect.h );
195- line_rect.x -= line_rect.w / 2 ;
196- current_text_y += line_rect.h ;
197- SDL_RenderCopy (renderer, line_textures[i], NULL , &line_rect);
198- }
199-
200- // Clean up
201- SDL_DestroyTexture (title_texture);
202- for (int i = 0 ; i < line_count; i++) {
203- SDL_DestroyTexture (line_textures[i]);
204- }
205- free (line_textures);
206208}
207209
208210void Draw::BlitText (char * text, int x, int y) {
0 commit comments