-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathhud_editor.c
2805 lines (2409 loc) · 75.6 KB
/
hud_editor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2011 ezQuake team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
HUD Editor module
Initial concept code jogihoogi, rewritten by Cokeman, Feb 2007
*/
#include "quakedef.h"
#include "qsound.h"
#include "utils.h"
#include "menu.h"
#include "keys.h"
#include "Ctrl.h"
#include "ez_controls.h"
#include "ez_button.h"
#include "ez_label.h"
#include "ez_scrollbar.h"
#include "ez_scrollpane.h"
#include "ez_slider.h"
#include "ez_listview.h"
#include "ez_window.h"
#include "hud.h"
#include "hud_editor.h"
ez_tree_t help_control_tree;
extern mpic_t *scr_cursor_icon; // cl_screen.c
extern cvar_t hud_planmode; // hud_common.c
mpic_t *hud_editor_move_icon = NULL;
mpic_t *hud_editor_resize_icon = NULL;
mpic_t *hud_editor_align_icon = NULL;
mpic_t *hud_editor_place_icon = NULL;
cvar_t hud_editor_allowresize = {"hud_editor_allowresize", "1"}; // Show resize handles / allow resizing.
cvar_t hud_editor_allowmove = {"hud_editor_allowmove", "1"}; // Allow moving...
cvar_t hud_editor_allowplace = {"hud_editor_allowplace", "1"}; // Allow placing HUDs.
cvar_t hud_editor_allowalign = {"hud_editor_allowalign", "1"}; // Allow aligning HUDs.
extern hud_t *hud_huds; // The list of HUDs..
hud_t *selected_hud = NULL; // The currently selected HUD.
qbool hud_editor = false; // If we're in HUD editor mode or not.
hud_editor_mode_t hud_editor_mode = hud_editmode_off; // The current mode the HUD editor is in.
hud_editor_mode_t hud_editor_prevmode = hud_editmode_off; // The previous mode the HUD editor was in.
qbool hud_editor_showhelp = false; // Show the help plaque or not?
qbool hud_editor_showoutlines = true; // Show guidelines around the HUD elements.
float hud_mouse_x; // The screen coordinates of the mouse cursor.
float hud_mouse_y;
// Macros for what mouse buttons are clicked.
#define MOUSEDOWN ( keydown[K_MOUSE1] || keydown[K_MOUSE2]|| keydown[K_MOUSE3])
#define MOUSEDOWN_1_2 ( keydown[K_MOUSE1] && keydown[K_MOUSE2])
#define MOUSEDOWN_1_3 ( keydown[K_MOUSE1] && keydown[K_MOUSE3])
#define MOUSEDOWN_1_2_3 ( keydown[K_MOUSE1] && keydown[K_MOUSE2] && keydown[K_MOUSE3])
#define MOUSEDOWN_1_ONLY ( keydown[K_MOUSE1] && !keydown[K_MOUSE2] && !keydown[K_MOUSE3])
#define MOUSEDOWN_2_ONLY (!keydown[K_MOUSE1] && keydown[K_MOUSE2] && !keydown[K_MOUSE3])
#define MOUSEDOWN_3_ONLY (!keydown[K_MOUSE1] && !keydown[K_MOUSE2] && keydown[K_MOUSE3])
#define MOUSEDOWN_1_2_ONLY ( keydown[K_MOUSE1] && keydown[K_MOUSE2] && !keydown[K_MOUSE3])
#define MOUSEDOWN_1_3_ONLY ( keydown[K_MOUSE1] && !keydown[K_MOUSE2] && keydown[K_MOUSE3])
#define MOUSEDOWN_2_3_ONLY (!keydown[K_MOUSE1] && keydown[K_MOUSE2] && keydown[K_MOUSE3])
#define MOUSEDOWN_NONE (!keydown[K_MOUSE1] && !keydown[K_MOUSE2] && !keydown[K_MOUSE3])
#define HUD_CENTER_X(h) ((h)->lx + (h)->lw / 2) // Gets the coordinates for the center point of the specified hud.
#define HUD_CENTER_Y(h) ((h)->ly + (h)->lh / 2)
//
// HUD align polygons.
//
#define HUD_ALIGN_POLYCOUNT_CORNER 5
#define HUD_ALIGN_POLYCOUNT_EDGE 4
#define HUD_ALIGN_POLYCOUNT_CENTER 8
#define HUD_ALIGN_POLYCOUNT_CONSOLE 4
vec3_t *hud_align_current_poly = NULL; // The current alignment polygon when in alignment mode.
int hud_align_current_polycount = 0; // Number of vertices in teh polygon.
vec3_t hud_align_topright_poly[HUD_ALIGN_POLYCOUNT_CORNER];
vec3_t hud_align_top_poly[HUD_ALIGN_POLYCOUNT_EDGE];
vec3_t hud_align_topleft_poly[HUD_ALIGN_POLYCOUNT_CORNER];
vec3_t hud_align_left_poly[HUD_ALIGN_POLYCOUNT_EDGE];
vec3_t hud_align_bottomleft_poly[HUD_ALIGN_POLYCOUNT_CORNER];
vec3_t hud_align_bottom_poly[HUD_ALIGN_POLYCOUNT_EDGE];
vec3_t hud_align_bottomright_poly[HUD_ALIGN_POLYCOUNT_CORNER];
vec3_t hud_align_right_poly[HUD_ALIGN_POLYCOUNT_EDGE];
vec3_t hud_align_center_poly[HUD_ALIGN_POLYCOUNT_CENTER];
vec3_t hud_align_consoleleft_poly[HUD_ALIGN_POLYCOUNT_CONSOLE];
vec3_t hud_align_console_poly[HUD_ALIGN_POLYCOUNT_CONSOLE];
vec3_t hud_align_consoleright_poly[HUD_ALIGN_POLYCOUNT_CONSOLE];
typedef enum hud_alignmode_s
{
hud_align_center,
hud_align_top,
hud_align_topleft,
hud_align_left,
hud_align_bottomleft,
hud_align_bottom,
hud_align_bottomright,
hud_align_right,
hud_align_topright,
hud_align_consoleleft,
hud_align_consoleright,
hud_align_console
// Not including before/after for now.
} hud_alignmode_t;
hud_alignmode_t hud_alignmode = hud_align_center;
// Possible positions for a grep handle.
typedef enum hud_greppos_s
{
pos_visible, // On screen.
pos_top,
pos_left,
pos_bottom,
pos_right
} hud_greppos_t;
// A Grep handle for when a HUD goes offscreen.
typedef struct hud_grephandle_s
{
hud_t *hud; // HUD associated with this grep handle.
int x; // The position in screen coordinates for the grephandle.
int y;
int width;
int height;
qbool highlighted; // Should this grephandle be drawn highlighted?
hud_greppos_t pos; // The offscreen position of the HUD associated with this handle.
struct hud_grephandle_s *next;
struct hud_grephandle_s *previous;
} hud_grephandle_t;
hud_grephandle_t *hud_greps = NULL; // The list of "grep handles" that are shown if a HUD element is moved offscreen.
hud_grephandle_t *hud_hoverlist = NULL; // The list of HUDs the mouse is hovering.
int hud_hoverlist_count = 0; // The number of hovered HUDs...
qbool hud_hoverlist_pos_is_set = false; // Has the coordinates been set for the hoverlist yet?
float hud_hoverlist_x; // The x position of the hover list.
float hud_hoverlist_y; // The y position of the hover list.
hud_grephandle_t hud_containers[MAX_HUD_ELEMENTS]; // List of HUDs which have been hovered.
//
// Change in cursor's X position since last frame
//
static float HUD_CursorDeltaX(void)
{
return (scr_pointer_state.x - scr_pointer_state.x_old);
}
//
// Change in cursor's Y position since last frame
//
static float HUD_CursorDeltaY(void)
{
return (scr_pointer_state.y - scr_pointer_state.y_old);
}
//
// Adds a new HUD to the list of HUDs that are being hovered.
//
static void HUD_Editor_AddHoverHud(hud_grephandle_t *hud_container)
{
// Nothing to add.
if(!hud_container)
{
return;
}
hud_container->next = hud_hoverlist;
if(hud_hoverlist)
{
hud_hoverlist->previous = hud_container;
}
hud_hoverlist = hud_container;
hud_hoverlist_count++;
}
//
// Associates ("Creates") a HUD with a HUD container.
//
static hud_grephandle_t *HUD_Editor_CreateHoverHud(hud_t *hud)
{
static int i = 0;
int j = 0;
if(i >= MAX_HUD_ELEMENTS - 1)
{
return NULL;
}
// Check if the HUD already exists and use that one if that's the case...
for(j = 0; j < MAX_HUD_ELEMENTS && hud_containers[j].hud; j++)
{
if(hud_containers[j].hud == hud)
{
hud_containers[j].next = NULL;
hud_containers[j].previous = NULL;
return &hud_containers[j];
}
}
// The HUD wasn't found so add it to the end of the list.
hud_containers[i].hud = hud;
hud_containers[i].next = NULL;
hud_containers[i].previous = NULL;
i++;
return &hud_containers[i - 1];
}
//
// Find the HUD that is being selected in the hover list.
//
static hud_t *HUD_Editor_FindHoverListSelection(hud_grephandle_t *list)
{
hud_t *match = NULL;
hud_grephandle_t *hud_iter = list;
while(hud_iter)
{
if(hud_iter->hud
&& hud_mouse_x > hud_iter->x
&& hud_mouse_x < (hud_iter->x + hud_iter->width)
&& hud_mouse_y > hud_iter->y
&& hud_mouse_y < (hud_iter->y + hud_iter->height))
{
hud_iter->highlighted = true;
match = hud_iter->hud;
}
else
{
hud_iter->highlighted = false;
}
hud_iter = hud_iter->next;
}
return match;
}
//
// Draw the hover list...
//
static qbool HUD_Editor_DrawHoverList(int x, int y, hud_grephandle_t *list)
{
#define PADDING 5
#define LINEGAP 1
int width = 0;
int height = 0;
int i = 0;
clrinfo_t color, highlight;
hud_grephandle_t *hud_iter = list;
// No point in showing a list if there's only one hud under the cursor
// or if the user hasn't right-clicked.
if (hud_hoverlist_count <= 1 || hud_editor_mode != hud_editmode_hoverlist)
{
return false;
}
// Get the width of to draw with.
while (hud_iter)
{
width = max(width, (PADDING + 2 + strlen(hud_iter->hud->name)) * 8);
hud_iter = hud_iter->next;
}
// Draw the background fill.
height = ((hud_hoverlist_count - 1) * (8 + LINEGAP)) + (2 * PADDING);
Draw_AlphaFillRGB(x, y - height, width, height, RGBA_TO_COLOR(0, 0, 0, 255));
hud_iter = list;
// Highlight color (yellow)...
highlight.c = RGBA_TO_COLOR(0, 255, 0, 255);
highlight.i = 0;
// Orange.
color.c = RGBA_TO_COLOR(255, 150, 0, 255);
color.i = 0;
// Draw the list items.
while(hud_iter)
{
// Calculate the size and position of the HUD in the list.
hud_iter->x = x;
hud_iter->y = y - height + (i * 8) + LINEGAP;
hud_iter->width = width;
hud_iter->height = 8;
// Draw the z-order + name of the HUD.
Draw_ColoredString3(hud_iter->x, hud_iter->y,
va("%2d - %s", hud_iter->hud->order->integer, hud_iter->hud->name),
(hud_iter->highlighted ? &highlight : &color), 1, 0);
hud_iter = hud_iter->next;
i++;
}
return true;
}
//
// Sets a new HUD Editor mode (and saves the previous one).
//
static void HUD_Editor_SetMode(hud_editor_mode_t newmode)
{
hud_editor_prevmode = hud_editor_mode;
hud_editor_mode = newmode;
}
//
// Draws a tool tip with a background next to the cursor.
//
static void HUD_Editor_DrawTooltip(int x, int y, char *string, color_t color) //float r, float g, float b, float a)
{
int len = strlen(string) * 8;
y -= 9;
// Make sure we're drawing within the screen.
if (x + len > vid.width)
{
x -= len;
}
if (y + 9 > vid.height)
{
y -= 9;
}
Draw_AlphaFillRGB(x, y, len, 8, color);
Draw_String(x, y, string);
}
//
// Gets an alignment string for a specified alignmode enum.
//
static char *HUD_Editor_GetAlignmentString(hud_alignmode_t align)
{
switch(hud_alignmode)
{
case hud_align_center : return "center center";
case hud_align_top : return "center top";
case hud_align_topleft : return "left top";
case hud_align_left : return "left center";
case hud_align_bottomleft : return "left bottom";
case hud_align_bottom : return "center bottom";
case hud_align_bottomright :return "right bottom";
case hud_align_right : return "right center";
case hud_align_topright : return "right top";
case hud_align_consoleleft :return "left console";
case hud_align_console : return "center console";
case hud_align_consoleright:return "right console";
default : return "";
}
}
//
// Returns an alignment enum based on a specified alignment string.
//
static hud_alignmode_t HUD_Editor_GetAlignmentFromString(char *alignstr)
{
if(!strcmp(alignstr, "center center"))
{
return hud_align_center;
}
else if(!strcmp(alignstr, "center top"))
{
return hud_align_top;
}
else if(!strcmp(alignstr, "left top"))
{
return hud_align_topleft;
}
else if(!strcmp(alignstr, "left center"))
{
return hud_align_left;
}
else if(!strcmp(alignstr, "left bottom"))
{
return hud_align_bottomleft;
}
else if(!strcmp(alignstr, "center bottom"))
{
return hud_align_bottom;
}
else if(!strcmp(alignstr, "right bottom"))
{
return hud_align_bottomright;
}
else if(!strcmp(alignstr, "right center"))
{
return hud_align_right;
}
else if(!strcmp(alignstr, "right top"))
{
return hud_align_topright;
}
else if(!strcmp(alignstr, "left console"))
{
return hud_align_consoleleft;
}
else if(!strcmp(alignstr, "center console"))
{
return hud_align_console;
}
else if(!strcmp(alignstr, "right console"))
{
return hud_align_consoleright;
}
return hud_align_center;
}
//
// Returns the alignment we are trying to align the selected HUD to at it's placement
// when in alignment mode.
//
static hud_alignmode_t HUD_Editor_GetAlignment(int x, int y, hud_t *hud_element)
{
// For less clutter.
float mid_x = 0.0;
float mid_y = 0.0;
int offset_x = 0;
int offset_y = 0;
if(hud_element)
{
// Aligns for HUD elements.
offset_x = hud_element->lx;
offset_y = hud_element->ly;
mid_x = hud_element->lw / 2.0;
mid_y = hud_element->lh / 2.0;
}
else
{
// Aligns for Screen.
offset_x = 0;
offset_y = (int)(vid.height * 0.05);
mid_x = vid.width / 2.0;
mid_y = (vid.height + offset_y) / 2.0;
}
if(!hud_element)
{
// Console left.
{
hud_align_consoleleft_poly[0][0] = 0;
hud_align_consoleleft_poly[0][1] = 0;
hud_align_consoleleft_poly[0][2] = 0;
hud_align_consoleleft_poly[1][0] = 0;
hud_align_consoleleft_poly[1][1] = offset_y;
hud_align_consoleleft_poly[1][2] = 0;
hud_align_consoleleft_poly[2][0] = mid_x / 2.0;
hud_align_consoleleft_poly[2][1] = offset_y;
hud_align_consoleleft_poly[2][2] = 0;
hud_align_consoleleft_poly[3][0] = mid_x / 2.0;
hud_align_consoleleft_poly[3][1] = 0;
hud_align_consoleleft_poly[3][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CONSOLE, hud_align_consoleleft_poly, x, y))
{
hud_align_current_poly = hud_align_consoleleft_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CONSOLE;
return hud_align_consoleleft;
}
}
// Console.
{
hud_align_console_poly[0][0] = mid_x / 2.0;
hud_align_console_poly[0][1] = 0;
hud_align_console_poly[0][2] = 0;
hud_align_console_poly[1][0] = mid_x / 2.0;
hud_align_console_poly[1][1] = offset_y;
hud_align_console_poly[1][2] = 0;
hud_align_console_poly[2][0] = mid_x + (mid_x / 2.0);
hud_align_console_poly[2][1] = offset_y;
hud_align_console_poly[2][2] = 0;
hud_align_console_poly[3][0] = mid_x + (mid_x / 2.0);
hud_align_console_poly[3][1] = 0;
hud_align_console_poly[3][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CONSOLE, hud_align_console_poly, x, y))
{
hud_align_current_poly = hud_align_console_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CONSOLE;
return hud_align_console;
}
}
// Console right.
{
hud_align_consoleright_poly[0][0] = mid_x + (mid_x / 2.0);
hud_align_consoleright_poly[0][1] = 0;
hud_align_consoleright_poly[0][2] = 0;
hud_align_consoleright_poly[1][0] = mid_x + (mid_x / 2.0);
hud_align_consoleright_poly[1][1] = offset_y;
hud_align_consoleright_poly[1][2] = 0;
hud_align_consoleright_poly[2][0] = 2 * mid_x;
hud_align_consoleright_poly[2][1] = offset_y;
hud_align_consoleright_poly[2][2] = 0;
hud_align_consoleright_poly[3][0] = 2 * mid_x;
hud_align_consoleright_poly[3][1] = 0;
hud_align_consoleright_poly[3][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CONSOLE, hud_align_consoleright_poly, x, y))
{
hud_align_current_poly = hud_align_consoleright_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CONSOLE;
return hud_align_consoleright;
}
}
}
// Top right.
{
hud_align_topright_poly[0][0] = mid_x + (mid_x / 2.0);
hud_align_topright_poly[0][1] = 0;
hud_align_topright_poly[0][2] = 0;
hud_align_topright_poly[1][0] = mid_x + (mid_x / 4.0);
hud_align_topright_poly[1][1] = mid_y - (mid_y / 2.0);
hud_align_topright_poly[1][2] = 0;
hud_align_topright_poly[2][0] = mid_x + (mid_x / 2.0);
hud_align_topright_poly[2][1] = mid_y - (mid_y / 4.0);
hud_align_topright_poly[2][2] = 0;
hud_align_topright_poly[3][0] = 2 * mid_x;
hud_align_topright_poly[3][1] = mid_y - (mid_y / 2.0);
hud_align_topright_poly[3][2] = 0;
hud_align_topright_poly[4][0] = 2 * mid_x;
hud_align_topright_poly[4][1] = 0;
hud_align_topright_poly[4][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CORNER, hud_align_topright_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_topright_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CORNER;
return hud_align_topright;
}
}
// Top.
{
hud_align_top_poly[0][0] = mid_x / 2.0;
hud_align_top_poly[0][1] = 0;
hud_align_top_poly[0][2] = 0;
hud_align_top_poly[1][0] = mid_x - (mid_x / 4.0);
hud_align_top_poly[1][1] = mid_y - (mid_y / 2.0);
hud_align_top_poly[1][2] = 0;
hud_align_top_poly[2][0] = mid_x + (mid_x / 4.0);
hud_align_top_poly[2][1] = mid_y - (mid_y / 2.0);
hud_align_top_poly[2][2] = 0;
hud_align_top_poly[3][0] = mid_x + (mid_x / 2.0);
hud_align_top_poly[3][1] = 0;
hud_align_top_poly[3][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_EDGE, hud_align_top_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_top_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_EDGE;
return hud_align_top;
}
}
// Top Left.
{
hud_align_topleft_poly[0][0] = 0;
hud_align_topleft_poly[0][1] = 0;
hud_align_topleft_poly[0][2] = 0;
hud_align_topleft_poly[1][0] = 0;
hud_align_topleft_poly[1][1] = mid_y - (mid_y / 2.0);
hud_align_topleft_poly[1][2] = 0;
hud_align_topleft_poly[2][0] = mid_x - (mid_x / 2.0);
hud_align_topleft_poly[2][1] = mid_y - (mid_y / 4.0);
hud_align_topleft_poly[2][2] = 0;
hud_align_topleft_poly[3][0] = mid_x - (mid_x / 4.0);
hud_align_topleft_poly[3][1] = mid_y - (mid_y / 2.0);
hud_align_topleft_poly[3][2] = 0;
hud_align_topleft_poly[4][0] = mid_x - (mid_x / 2.0);
hud_align_topleft_poly[4][1] = 0;
hud_align_topleft_poly[4][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CORNER, hud_align_topleft_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_topleft_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CORNER;
return hud_align_topleft;
}
}
// Left.
{
hud_align_left_poly[0][0] = 0;
hud_align_left_poly[0][1] = mid_y / 2.0;
hud_align_left_poly[0][2] = 0;
hud_align_left_poly[1][0] = 0;
hud_align_left_poly[1][1] = mid_y + (mid_y / 2.0);
hud_align_left_poly[1][2] = 0;
hud_align_left_poly[2][0] = mid_x / 2.0;
hud_align_left_poly[2][1] = mid_y + (mid_y / 4.0);
hud_align_left_poly[2][2] = 0;
hud_align_left_poly[3][0] = mid_x / 2.0;
hud_align_left_poly[3][1] = mid_y - (mid_y / 4.0);
hud_align_left_poly[3][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_EDGE, hud_align_left_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_left_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_EDGE;
return hud_align_left;
}
}
// Bottom Left.
{
hud_align_bottomleft_poly[0][0] = 0;
hud_align_bottomleft_poly[0][1] = mid_y + (mid_y / 2.0);
hud_align_bottomleft_poly[0][2] = 0;
hud_align_bottomleft_poly[1][0] = 0;
hud_align_bottomleft_poly[1][1] = 2 * mid_y;
hud_align_bottomleft_poly[1][2] = 0;
hud_align_bottomleft_poly[2][0] = mid_x / 2.0;
hud_align_bottomleft_poly[2][1] = 2 * mid_y;
hud_align_bottomleft_poly[2][2] = 0;
hud_align_bottomleft_poly[3][0] = mid_x - (mid_x / 4.0);
hud_align_bottomleft_poly[3][1] = mid_y + (mid_y / 2.0);
hud_align_bottomleft_poly[3][2] = 0;
hud_align_bottomleft_poly[4][0] = mid_x / 2.0;
hud_align_bottomleft_poly[4][1] = mid_y + (mid_y / 4.0);
hud_align_bottomleft_poly[4][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CORNER, hud_align_bottomleft_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_bottomleft_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CORNER;
return hud_align_bottomleft;
}
}
// Bottom.
{
hud_align_bottom_poly[0][0] = mid_x - (mid_x / 2.0);
hud_align_bottom_poly[0][1] = 2 * mid_y;
hud_align_bottom_poly[0][2] = 0;
hud_align_bottom_poly[1][0] = mid_x + (mid_x / 2.0);
hud_align_bottom_poly[1][1] = 2 * mid_y;
hud_align_bottom_poly[1][2] = 0;
hud_align_bottom_poly[2][0] = mid_x + (mid_x / 4.0);
hud_align_bottom_poly[2][1] = mid_y + (mid_y / 2.0);
hud_align_bottom_poly[2][2] = 0;
hud_align_bottom_poly[3][0] = mid_x - (mid_x / 4.0);
hud_align_bottom_poly[3][1] = mid_y + (mid_y / 2.0);
hud_align_bottom_poly[3][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_EDGE, hud_align_bottom_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_bottom_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_EDGE;
return hud_align_bottom;
}
}
// Bottom Right.
{
hud_align_bottomright_poly[0][0] = mid_x + (mid_x / 2.0);
hud_align_bottomright_poly[0][1] = 2 * mid_y;
hud_align_bottomright_poly[0][2] = 0;
hud_align_bottomright_poly[1][0] = 2 * mid_x;
hud_align_bottomright_poly[1][1] = 2 * mid_y;
hud_align_bottomright_poly[1][2] = 0;
hud_align_bottomright_poly[2][0] = 2 * mid_x;
hud_align_bottomright_poly[2][1] = mid_y + (mid_y / 2.0);
hud_align_bottomright_poly[2][2] = 0;
hud_align_bottomright_poly[3][0] = mid_x + (mid_x / 2.0);
hud_align_bottomright_poly[3][1] = mid_y + (mid_y / 4.0);
hud_align_bottomright_poly[3][2] = 0;
hud_align_bottomright_poly[4][0] = mid_x + (mid_x / 4.0);
hud_align_bottomright_poly[4][1] = mid_y + (mid_y / 2.0);
hud_align_bottomright_poly[4][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CORNER, hud_align_bottomright_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_bottomright_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CORNER;
return hud_align_bottomright;
}
}
// Right.
{
hud_align_right_poly[0][0] = 2 * mid_x;
hud_align_right_poly[0][1] = mid_y + (mid_y / 2.0);
hud_align_right_poly[0][2] = 0;
hud_align_right_poly[1][0] = 2 * mid_x;
hud_align_right_poly[1][1] = mid_y / 2.0;
hud_align_right_poly[1][2] = 0;
hud_align_right_poly[2][0] = mid_x + (mid_x / 2.0);
hud_align_right_poly[2][1] = mid_y - (mid_y / 4.0);
hud_align_right_poly[2][2] = 0;
hud_align_right_poly[3][0] = mid_x + (mid_x / 2.0);
hud_align_right_poly[3][1] = mid_y + (mid_y / 4.0);
hud_align_right_poly[3][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_EDGE, hud_align_right_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_right_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_EDGE;
return hud_align_right;
}
}
// Center.
{
hud_align_center_poly[0][0] = mid_x - (mid_x / 4.0);
hud_align_center_poly[0][1] = mid_y / 2.0;
hud_align_center_poly[0][2] = 0;
hud_align_center_poly[1][0] = mid_x / 2.0;
hud_align_center_poly[1][1] = mid_y - (mid_y / 4.0);
hud_align_center_poly[1][2] = 0;
hud_align_center_poly[2][0] = mid_x / 2.0;
hud_align_center_poly[2][1] = mid_y + (mid_y / 4.0);
hud_align_center_poly[2][2] = 0;
hud_align_center_poly[3][0] = mid_x - (mid_x / 4.0);
hud_align_center_poly[3][1] = mid_y + (mid_y / 2.0);
hud_align_center_poly[3][2] = 0;
hud_align_center_poly[4][0] = mid_x + (mid_x / 4.0);
hud_align_center_poly[4][1] = mid_y + (mid_y / 2.0);
hud_align_center_poly[4][2] = 0;
hud_align_center_poly[5][0] = mid_x + (mid_x / 2.0);
hud_align_center_poly[5][1] = mid_y + (mid_y / 4.0);
hud_align_center_poly[5][2] = 0;
hud_align_center_poly[6][0] = mid_x + (mid_x / 2.0);
hud_align_center_poly[6][1] = mid_y - (mid_y / 4.0);
hud_align_center_poly[6][2] = 0;
hud_align_center_poly[7][0] = mid_x + (mid_x / 4.0);
hud_align_center_poly[7][1] = mid_y / 2.0;
hud_align_center_poly[7][2] = 0;
if (IsPointInPolygon(HUD_ALIGN_POLYCOUNT_CENTER, hud_align_center_poly, x - offset_x, y - offset_y))
{
hud_align_current_poly = hud_align_center_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CENTER;
return hud_align_center;
}
}
// Default to center.
hud_align_current_poly = hud_align_center_poly;
hud_align_current_polycount = HUD_ALIGN_POLYCOUNT_CENTER;
return hud_align_center;
}
//
// Finds the next child of the specified HUD element.
//
static hud_t *HUD_Editor_FindNextChild(hud_t *hud_element)
{
static hud_t *hud_it = NULL;
static hud_t *parent = NULL;
hud_t *hud_result = NULL;
// Reset everything if we're given a NULL argument.
if(!hud_element)
{
hud_it = NULL;
parent = NULL;
return NULL;
}
// There's a new parent so start searching from the beginning.
if(!parent || strcmp(parent->name, hud_element->name))
{
parent = hud_element;
hud_it = hud_huds;
}
while(hud_it)
{
// Check if this HUD is placed at the parent, if so we've found a child.
if(hud_it->place_hud && !strcmp(hud_it->place_hud->name, parent->name))
{
hud_result = hud_it;
hud_it = hud_it->next;
return hud_result;
}
hud_it = hud_it->next;
}
parent = NULL;
// No children found.
return NULL;
}
//
// Moves a HUD element.
//
static void HUD_Editor_Move(float dx, float dy, hud_t *hud_element)
{
if(!hud_element)
{
return;
}
Cvar_SetValue(hud_element->pos_x, hud_element->pos_x->value + dx);
Cvar_SetValue(hud_element->pos_y, hud_element->pos_y->value + dy);
}
//
// Draw the current alignment.
//
static void HUD_Editor_DrawAlignment(hud_t *hud_parent)
{
extern void Draw_Polygon(int x, int y, vec3_t *vertices, int num_vertices, qbool fill, color_t color);
color_t c = RGBA_TO_COLOR(255, 255, 0, 50);
if(hud_parent)
{
//Draw_Polygon(hud_parent->lx, hud_parent->ly, hud_align_current_poly, hud_align_current_polycount, true, RGBA_TO_COLOR(255, 255, 0, 50));
Draw_Polygon(hud_parent->lx, hud_parent->ly, hud_align_current_poly, hud_align_current_polycount, true, c);
}
else
{
//Draw_Polygon(0, 0, hud_align_current_poly, hud_align_current_polycount, true, RGBA_TO_COLOR(255, 255, 0, 50));
Draw_Polygon(0, 0, hud_align_current_poly, hud_align_current_polycount, true, c);
}
}
typedef struct hud_resize_handle_s
{
int x;
int y;
int width;
int height;
} hud_resize_handle_t;
#define HUD_RESIZEHANDLE_THICKNESS 5
#define HUD_RESIZEHANDLE_SIZEFACTOR 0.3
#define HUD_RESIZEHANDLE_COUNT 8
#define HUD_RESIZE_MAGICSCALE 200 // HACK : This seems to work nice though...
#define HUD_RESIZEHANDLE_NONE -1
#define HUD_RESIZEHANDLE_TOPLEFT 0
#define HUD_RESIZEHANDLE_TOP 1
#define HUD_RESIZEHANDLE_TOPRIGHT 2
#define HUD_RESIZEHANDLE_RIGHT 3
#define HUD_RESIZEHANDLE_BOTTOMRIGHT 4
#define HUD_RESIZEHANDLE_BOTTOM 5
#define HUD_RESIZEHANDLE_BOTTOMLEFT 6
#define HUD_RESIZEHANDLE_LEFT 7
//
// Resizes the height/width of a HUD element by a delta size and alignment.
//
static void HUD_Editor_ResizeDelta(cvar_t *size, float delta_size, hud_alignmode_t alignment)
{
if(!size)
{
return;
}
switch(alignment)
{
case hud_align_right :
case hud_align_bottom :
Cvar_SetValue(size, size->value + delta_size);
break;
case hud_align_left :
case hud_align_top :
Cvar_SetValue(size, size->value - delta_size);
break;
// unhandled
case hud_align_center:
case hud_align_topleft:
case hud_align_bottomleft:
case hud_align_bottomright:
case hud_align_topright:
case hud_align_consoleleft:
case hud_align_consoleright:
case hud_align_console:
break;
}
}
//
// Scales a HUD element.
//
static void HUD_EditorScaleDelta(cvar_t *scale, float delta_scale, hud_alignmode_t alignment)
{
if(!scale)
{
return;
}
switch(alignment)
{
case hud_align_topleft :
case hud_align_bottomleft :
Cvar_SetValue(scale, scale->value - delta_scale);
break;
case hud_align_topright :
case hud_align_bottomright :
Cvar_SetValue(scale, scale->value + delta_scale);
break;
// unhandled
case hud_align_center:
case hud_align_top:
case hud_align_left:
case hud_align_bottom:
case hud_align_right:
case hud_align_consoleleft:
case hud_align_consoleright:
case hud_align_console:
break;
}
if(scale->value < 0)
{
Cvar_SetValue(scale, 0);
}
}
//
// Checks if the HUD element we're hovering has any dimension variables
// and handles resizing for it if it does by drawing resize handles
// that the user can click.
//
static qbool HUD_Editor_Resizing(hud_t *hud_hover)
{
int i = 0;
qbool found_handle = false; // Did we find any handle under the cursor?
static cvar_t *width = NULL;