7 SDL_Rect ui_pane
= { -PANE_WIDTH
- 10, 0, PANE_WIDTH
+ 10, -0 };
8 SDL_Rect top_pane
= { 0, 0, -0, 20 };
9 SDL_Rect game_map
= { 0, 20, -PANE_WIDTH
, -20 };
11 SDL_Rect minimap
= { -PANE_WIDTH
, 20, PANE_WIDTH
, 128+4 };
12 SDL_Rect buildbox
= { -PANE_WIDTH
, 154, PANE_WIDTH
, 48 };
13 SDL_Rect selbox
= { -PANE_WIDTH
, 154, PANE_WIDTH
, 128 };
15 SDL_Rect unitpin
= { -24, 154 + 4, 16, 16 };
16 SDL_Rect flagicon
= { -24, 112, 16, 16 };
17 SDL_Rect tabicon
= { -PANE_WIDTH
+ 8, 0, 40, 8 };
18 SDL_Rect pinbox
= { -PANE_WIDTH
, 190, PANE_WIDTH
, 150 };
19 SDL_Rect hintbox
= { -PANE_WIDTH
, -128, PANE_WIDTH
, 128 };
21 SDL_Rect plusbtn
= { -42, 154 + 31, 16, 16 };
28 &minimap
, &buildbox
, &selbox
, &pinbox
, &hintbox
,
30 &unitpin
, &plusbtn
, &flagicon
, &tabicon
,
32 &ui_pane
, &top_pane
, &game_map
,
34 int num
= sizeof(boxes
) / sizeof(SDL_Rect
*);
38 for (i
= 0; i
< num
; i
++) {
40 SDL_Rect
*box
= boxes
[i
];
42 if (box
->x
< 0) box
->x
+= ui
.log_width
;
43 if (box
->y
< 0) box
->y
+= ui
.log_height
;
44 if (box
->w
< 0) box
->w
+= ui
.log_width
;
45 if (box
->h
< 0) box
->h
+= ui
.log_height
;
49 buildbox
.y
= minimap
.y
+ minimap
.h
+ 1;
51 ui_pane
.h
= ui
.log_height
;
52 top_pane
.w
= ui
.log_width
;
54 unitpin
.y
= selbox
.y
+ 4;
55 plusbtn
.y
= selbox
.y
+ 31;
56 flagicon
.y
+= selbox
.y
;
57 tabicon
.y
+= selbox
.y
;
58 tabicon
.y
+= selbox
.h
;
61 /* Do horrible things... */
72 void init_ui(SDL_Renderer
*renderer
, int w
, int h
) {
80 if (w
% 320 == 0 && h
% 240 == 0) { /* 320 x 240 base, good old VGA */
85 if (w
% 800 == 0 && h
% 600 == 0) { /* 800 x 600 base, good old SVGA */
90 if (w
% 320 == 0 && h
% 188 == 0) { /* 320 x 188 base -- wicked, but acceptable */
95 if (w
% 240 == 0 && h
% 160 == 0) { /* 240 x 160 base -- very small screen */
100 if (h
< 400) { /* Very small screen, double the zoom */
107 if (ui
.log_height
< 400) { /* Very small base, adjust gui accordingly */
111 hintbox
.y
= minimap
.y
;
113 selbox
.y
= ui
.log_height
- selbox
.h
;
117 buildbox
.w
= TILE_W
* 4;
118 buildbox
.x
= ui
.log_width
- buildbox
.w
- TILE_W
/2;
120 buildbox
.h
= ui
.log_height
- buildbox
.y
;
123 SDL_RenderSetLogicalSize(renderer
, ui
.log_width
, ui
.log_height
);
142 ui
.unit
= ui
.house
= ui
.flag
= -1;
143 ui
.builder
= ui
.setflag
= ui
.stat
= ui
.btn
= -1;
147 ui
.hover_top
= overNothingMajor
;
148 ui
.hover
= overNothingMinor
;
154 ui
.draw_overlays
= 0;
162 /* for touch/small-screen devices, use different ui */
168 void update_hintbox() {
172 case overBuildButton
:
175 ui
.hint
= ui
.hover_id
;
181 ui
.hint
= ui
.hover_id
;
191 if (ui
.builder
!= -1) {
194 ui
.hint
= ui
.builder
;
208 /* Given X and Y mouse position, determine various UI-related states... */
211 ui
.hover
= overNothingMinor
;
214 if (SDL_InBounds(ui
.x
, ui
.y
, &ui_pane
)) {
216 ui
.hover_top
= overPane
;
220 } else if (SDL_InBounds(ui
.x
, ui
.y
, &top_pane
)) {
222 ui
.hover_top
= overNothingMajor
;
226 ui
.hover_top
= overMap
;
235 void track_mouse_map() {
237 Uint32 unit_i
, house_i
, flag_i
;
239 ui
.hover_xcollide
= 0;
240 ui
.hover
= overNothingMinor
;
242 if (ui
.builder
!= -1) {
243 house_p
*h
= &bhouses
[ui
.builder
];
245 int lx
= ui
.x
+ ui
.vx
- game_map
.x
;
246 int ly
= ui
.y
+ ui
.vy
- game_map
.y
;
248 int cx
= -(TILE_W
* h
->w
/ 2) + (TILE_W
/2);
249 int cy
= -(TILE_H
* h
->h
/ 2) + (TILE_H
/2);
254 ui
.hover_tx
= (lx
/ TILE_W
);
255 ui
.hover_ty
= (ly
/ TILE_H
);
257 ui
.hover_xcollide
= xcollide(ui
.hover_tx
, ui
.hover_ty
, h
->w
, h
->h
);
262 ui
.hover_tx
= (ui
.x
+ ui
.vx
- game_map
.x
) / TILE_W
;
263 ui
.hover_ty
= (ui
.y
+ ui
.vy
- game_map
.y
) / TILE_H
;
265 if (ui
.setflag
!= -1) {
267 ui
.hover_xcollide
= xcollide(ui
.hover_tx
, ui
.hover_ty
, 1, 1);
269 if (find_flagT(ui
.hover_tx
, ui
.hover_ty
) != -1) ui
.hover_xcollide
= 2;
272 unit_i
= find_unit(ui
.x
, ui
.y
);
275 ui
.hover_id
= unit_i
;
278 house_i
= find_house(ui
.x
, ui
.y
);
280 ui
.hover
= overHouse
;
281 ui
.hover_id
= house_i
;
282 if (houses
[house_i
].flag_id
[ui
.faction
] != -1
283 && ui
.hover_tx
== houses
[house_i
].x
284 && ui
.hover_ty
== houses
[house_i
].y
) {
285 ui
.hover
= overHouseFlag
;
286 ui
.hover_id
= ui
.faction
;
290 flag_i
= find_flagT(ui
.hover_tx
, ui
.hover_ty
);
293 ui
.hover_id
= flag_i
;
298 void track_mouse_ui() {
303 if (SDL_InBounds(ui
.x
, ui
.y
, &minimap
)) {
305 ui
.hover
= overMinimap
;
310 /* Top-level menu (i.e. build buttons and unit-list) */
311 if (ui
.house
== -1 && ui
.unit
== -1 && ui
.flag
== -1) {
312 /* Name on the pinbox */
313 if (SDL_InBounds(ui
.x
, ui
.y
, &pinbox
)) {
315 ui
.hover
= overPinBox
;
318 SDL_Rect line
= { 0, 0, 120, 16 };
319 SDL_Rect pinbtn
= { 0, 0, 16, 16 };
323 pinbtn
.x
= pinbox
.x
+ line
.w
;
326 for (i
= 0; i
< num_units
; i
++) {
327 unit_t
*u
= &units
[i
];
328 if (u
->tile
&& u
->pin
) {
330 if (SDL_InBounds(ui
.x
, ui
.y
, &line
)) {
331 ui
.hover
= overListName
;
335 if (SDL_InBounds(ui
.x
, ui
.y
, &pinbtn
)) {
336 ui
.hover
= overListPin
;
350 /* One of the build buttons */
351 if (ui
.house
== -1 && ui
.unit
== -1 && ui
.flag
== -1) {
358 for (i
= 0; i
< 2; i
++) {
359 if (SDL_InBounds(ui
.x
, ui
.y
, &button
)) {
361 ui
.hover
= overFlagButton
;
368 if (button
.x
>= buildbox
.x
+ buildbox
.w
- TILE_W
/2) {
369 button
.x
= buildbox
.x
;
373 for (i
= 0; i
< HMENU_ITEMS
; i
++) {
375 if (SDL_InBounds(ui
.x
, ui
.y
, &button
)) {
377 ui
.hover
= overBuildButton
;
384 if (button
.x
>= buildbox
.x
+ buildbox
.w
- TILE_W
/2) {
385 button
.x
= buildbox
.x
;
391 /* Something on the flagbox */
395 if (SDL_InBounds(ui
.x
, ui
.y
, &plusbtn
)) {
397 ui
.hover
= overFlagPlus
;
404 /* Something on the housebox */
405 if (ui
.house
!= -1) {
408 if (SDL_InBounds(ui
.x
, ui
.y
, &flagicon
)) {
410 ui
.hover
= overHouseFlag
;
417 /* One of the tab icons */
419 button
.x
= tabicon
.x
;
420 button
.y
= tabicon
.y
;
421 button
.w
= tabicon
.w
;
422 button
.h
= tabicon
.h
;
423 for (i
= 0; i
< MAX_HOUSETABS
; i
++) {
424 if (SDL_InBounds(ui
.x
, ui
.y
, &button
)) {
425 ui
.hover
= overHouseTab
;
429 button
.x
+= tabicon
.w
;
430 if (button
.x
+ tabicon
.w
>= ui
.log_width
) {
431 button
.x
= tabicon
.x
;
432 button
.y
+= tabicon
.h
;
438 /* Something on the unitbox */
442 if (SDL_InBounds(ui
.x
, ui
.y
, &unitpin
)) {
444 ui
.hover
= overUnitPin
;
445 ui
.hover_id
= ui
.unit
;
451 if (SDL_InBounds(ui
.x
, ui
.y
, &flagicon
)) {
453 ui
.hover
= overUnitFlag
;
461 /* One of the tab icons */
464 button
.x
= tabicon
.x
;
465 button
.y
= tabicon
.y
;
466 button
.w
= tabicon
.w
;
467 button
.h
= tabicon
.h
;
468 for (i
= 0; i
< MAX_UNITTABS
; i
++) {
469 if (SDL_InBounds(ui
.x
, ui
.y
, &button
)) {
470 ui
.hover
= overUnitTab
;
474 button
.x
+= tabicon
.w
;
475 if (button
.x
+ tabicon
.w
>= ui
.log_width
) {
476 button
.x
= tabicon
.x
;
477 button
.y
+= tabicon
.h
;
482 /* One of the stat/skill buttons */
485 selbox
.x
+ BOX_PADDING
+ BOX_PADDING
,
486 selbox
.y
+ BOX_PADDING
+ BOX_PADDING
+ BOX_PADDING
+ 1,
491 for (i
= 0; i
< MAX_STAT
; i
++) {
493 if (SDL_InBounds(ui
.x
, ui
.y
, &button
)) {
494 ui
.hover
= overUnitStat
;
499 button
.y
-= 14 * MAX_STAT
;
502 for (i
= 0; i
< MAX_STAT
; i
++) {
504 if (SDL_InBounds(ui
.x
, ui
.y
, &button
)) {
505 ui
.hover
= overUnitSkill
;