-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4coder_fancy.cpp
More file actions
851 lines (796 loc) · 29.5 KB
/
4coder_fancy.cpp
File metadata and controls
851 lines (796 loc) · 29.5 KB
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
/*
* Fancy string - immediate mode renderer for colored strings
*/
// TOP
function FColor
fcolor_argb(ARGB_Color color){
FColor result = {};
result.argb = color;
if (result.a_byte == 0){
result.argb = 0;
}
return(result);
}
function FColor
fcolor_argb(Vec4_f32 color){
return(fcolor_argb(pack_color(color)));
}
function FColor
fcolor_argb(f32 r, f32 g, f32 b, f32 a){
return(fcolor_argb(pack_color(V4f32(r, g, b, a))));
}
function FColor
fcolor_id(Managed_ID id){
FColor result = {};
result.id = (ID_Color)id;
return(result);
}
function FColor
fcolor_id(Managed_ID id, u32 sub_index){
FColor result = {};
result.id = (ID_Color)id;
result.sub_index = (u8)sub_index;
return(result);
}
function ARGB_Color
argb_color_blend(ARGB_Color a, f32 at, ARGB_Color b, f32 bt){
Vec4_f32 av = unpack_color(a);
Vec4_f32 bv = unpack_color(b);
Vec4_f32 value = at*av + bt*bv;
return(pack_color(value));
}
function ARGB_Color
argb_color_blend(ARGB_Color a, f32 t, ARGB_Color b){
return(argb_color_blend(a, 1.f - t, b, t));
}
function ARGB_Color
fcolor_resolve(FColor color){
ARGB_Color result = 0;
if (color.a_byte == 0){
if (color.id != 0){
result = finalize_color(color.id, color.sub_index);
}
}
else{
result = color.argb;
}
return(result);
}
function FColor
fcolor_change_alpha(FColor color, f32 alpha){
Vec4_f32 v = unpack_color(fcolor_resolve(color));
v.a = alpha;
return(fcolor_argb(pack_color(v)));
}
function FColor
fcolor_blend(FColor a, f32 at, FColor b, f32 bt){
ARGB_Color a_argb = fcolor_resolve(a);
ARGB_Color b_argb = fcolor_resolve(b);
return(fcolor_argb(argb_color_blend(a_argb, at, b_argb, bt)));
}
function FColor
fcolor_blend(FColor a, f32 t, FColor b){
return(fcolor_blend(a, 1.f - t, b, t));
}
function FColor
fcolor_zero(void){
FColor result = {};
return(result);
}
function b32
fcolor_is_valid(FColor color){
return(color.argb != 0);
}
////////////////////////////////
function void
push_fancy_string(Fancy_Line *line, Fancy_String *string){
sll_queue_push(line->first, line->last, string);
}
function void
push_fancy_line(Fancy_Block *block, Fancy_Line *line){
sll_queue_push(block->first, block->last, line);
block->line_count += 1;
}
////////////////////////////////
function Fancy_String*
fill_fancy_string(Fancy_String *ptr, Face_ID face, FColor fore, f32 pre_margin, f32 post_margin,
String_Const_u8 value){
ptr->value = value;
ptr->face = face;
ptr->fore = fore;
ptr->pre_margin = pre_margin;
ptr->post_margin = post_margin;
return(ptr);
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
f32 pre_margin, f32 post_margin, String_Const_u8 value){
Fancy_String *result = push_array_zero(arena, Fancy_String, 1);
fill_fancy_string(result, face, fore, pre_margin, post_margin, value);
if (line != 0){
push_fancy_string(line, result);
}
return(result);
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
String_Const_u8 value){
return(push_fancy_string(arena, line, face, fore, 0, 0, value));
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, Face_ID face,
f32 pre_margin, f32 post_margin, String_Const_u8 value){
return(push_fancy_string(arena, line, face, fcolor_zero(),
pre_margin, post_margin, value));
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, FColor fore,
f32 pre_margin, f32 post_margin, String_Const_u8 value){
return(push_fancy_string(arena, line, 0, fore, pre_margin, post_margin, value));
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, Face_ID face, String_Const_u8 value){
return(push_fancy_string(arena, line, face, fcolor_zero(), 0, 0, value));
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, FColor color, String_Const_u8 value){
return(push_fancy_string(arena, line, 0, color, 0, 0, value));
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, f32 pre_margin, f32 post_margin,
String_Const_u8 value){
return(push_fancy_string(arena, line, 0, fcolor_zero(), pre_margin, post_margin,
value));
}
function Fancy_String*
push_fancy_string(Arena *arena, Fancy_Line *line, String_Const_u8 value){
return(push_fancy_string(arena, line, 0, fcolor_zero(), 0, 0, value));
}
////////////////////////////////
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
f32 pre_margin, f32 post_margin,
char *format, va_list args){
return(push_fancy_string(arena, line, face, fore, pre_margin, post_margin,
push_u8_stringfv(arena, format, args)));
}
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
char *format, va_list args){
return(push_fancy_stringfv(arena, line, face, fore, 0, 0, format, args));
}
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line, Face_ID face,
f32 pre_margin, f32 post_margin,
char *format, va_list args){
return(push_fancy_stringfv(arena, line, face, fcolor_zero(),
pre_margin, post_margin, format, args));
}
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line, FColor fore,
f32 pre_margin, f32 post_margin,
char *format, va_list args){
return(push_fancy_stringfv(arena, line, 0, fore, pre_margin, post_margin,
format, args));
}
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line, Face_ID face,
char *format, va_list args){
return(push_fancy_stringfv(arena, line, face, fcolor_zero(), 0, 0,
format, args));
}
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line, FColor color,
char *format, va_list args){
return(push_fancy_stringfv(arena, line, 0, color, 0, 0, format, args));
}
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line, f32 pre_margin, f32 post_margin,
char *format, va_list args){
return(push_fancy_stringfv(arena, line, 0, fcolor_zero(), pre_margin, post_margin,
format, args));
}
function Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_Line *line,
char *format, va_list args){
return(push_fancy_stringfv(arena, line, 0, fcolor_zero(), 0, 0, format, args));
}
#define StringFBegin() va_list args; va_start(args, format)
#define StringFPass(N) Fancy_String *result = N
#define StringFEnd() va_end(args); return(result)
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
f32 pre_margin, f32 post_margin,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_string(arena, line, face, fore, pre_margin, post_margin,
push_u8_stringfv(arena, format, args)));
StringFEnd();
}
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_stringfv(arena, line, face, fore, 0, 0, format, args));
StringFEnd();
}
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line, Face_ID face,
f32 pre_margin, f32 post_margin,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_stringfv(arena, line, face, fcolor_zero(),
pre_margin, post_margin, format, args));
StringFEnd();
}
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line, FColor fore,
f32 pre_margin, f32 post_margin,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_stringfv(arena, line, 0, fore, pre_margin, post_margin,
format, args));
StringFEnd();
}
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line, Face_ID face,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_stringfv(arena, line, face, fcolor_zero(), 0, 0,
format, args));
StringFEnd();
}
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line, FColor color,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_stringfv(arena, line, 0, color, 0, 0, format, args));
StringFEnd();
}
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line, f32 pre_margin, f32 post_margin,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_stringfv(arena, line, 0, fcolor_zero(),
pre_margin, post_margin, format, args));
StringFEnd();
}
function Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_Line *line,
char *format, ...){
StringFBegin();
StringFPass(push_fancy_stringfv(arena, line, 0, fcolor_zero(), 0, 0, format, args));
StringFEnd();
}
////////////////////////////////
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
f32 pre_margin, f32 post_margin,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fore, pre_margin, post_margin,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fore, pre_margin, post_margin,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fore, 0.f, 0.f,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fore, 0.f, 0.f,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line, Face_ID face,
f32 pre_margin, f32 post_margin, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fcolor_zero(),
pre_margin, post_margin,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fcolor_zero(),
pre_margin, post_margin,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line, FColor fore,
f32 pre_margin, f32 post_margin, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, 0, fore, pre_margin, post_margin,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, 0, fore, pre_margin, post_margin,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line, Face_ID face,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fcolor_zero(), 0.f, 0.f,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fcolor_zero(), 0.f, 0.f,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line, FColor fore,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, (Face_ID)0, fore, 0.f, 0.f,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, (Face_ID)0, fore, 0.f, 0.f,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line,
f32 pre_margin, f32 post_margin, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(),
pre_margin, post_margin,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(),
pre_margin, post_margin,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_fixed(Arena *arena, Fancy_Line *line, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(), 0.f, 0.f,
"%-*.*s", max, string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(), 0.f, 0.f,
"%-*.*s...", max - 3, string_expand(value)));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
f32 pre_margin, f32 post_margin,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fore, pre_margin, post_margin,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fore, pre_margin, post_margin,
"%.*s...", max - 3, value.str));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line, Face_ID face, FColor fore,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fore, 0.f, 0.f,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fore, 0.f, 0.f,
"%.*s...", max - 3, value.str));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line, Face_ID face,
f32 pre_margin, f32 post_margin, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fcolor_zero(),
pre_margin, post_margin,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fcolor_zero(),
pre_margin, post_margin,
"%.*s...", max - 3, value.str));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line, FColor fore,
f32 pre_margin, f32 post_margin, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, 0, fore, pre_margin, post_margin,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, 0, fore, pre_margin, post_margin,
"%.*s...", max - 3, value.str));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line, Face_ID face,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, face, fcolor_zero(), 0.f, 0.f,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, face, fcolor_zero(), 0.f, 0.f,
"%.*s...", max - 3, value.str));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line, FColor fore,
String_Const_u8 value, i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, (Face_ID)0, fore, 0.f, 0.f,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, (Face_ID)0, fore, 0.f, 0.f,
"%.*s...", max - 3, value.str));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line,
f32 pre_margin, f32 post_margin, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(),
pre_margin, post_margin,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(),
pre_margin, post_margin,
"%.*s...", max - 3, value.str));
}
}
function Fancy_String*
push_fancy_string_trunc(Arena *arena, Fancy_Line *line, String_Const_u8 value,
i32 max){
if (value.size <= max){
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(), 0.f, 0.f,
"%.*s", string_expand(value)));
}
else{
return(push_fancy_stringf(arena, line, (Face_ID)0, fcolor_zero(), 0.f, 0.f,
"%.*s...", max - 3, value.str));
}
}
////////////////////////////////
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block, Face_ID face, FColor fore,
String_Const_u8 text){
Fancy_Line *line = push_array_zero(arena, Fancy_Line, 1);
line->face = face;
line->fore = fore;
if (text.size != 0){
push_fancy_string(arena, line, text);
}
if (block != 0){
push_fancy_line(block, line);
}
return(line);
}
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block, Face_ID face, FColor fcolor){
return(push_fancy_line(arena, block, face, fcolor, SCu8()));
}
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block, Face_ID face, String_Const_u8 val){
return(push_fancy_line(arena, block, face, fcolor_zero(), val));
}
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block, FColor color, String_Const_u8 val){
return(push_fancy_line(arena, block, 0, color, val));
}
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block, Face_ID face){
return(push_fancy_line(arena, block, face, fcolor_zero(), SCu8()));
}
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block, FColor color){
return(push_fancy_line(arena, block, 0, color, SCu8()));
}
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block, String_Const_u8 val){
return(push_fancy_line(arena, block, 0, fcolor_zero(), val));
}
function Fancy_Line*
push_fancy_line(Arena *arena, Fancy_Block *block){
return(push_fancy_line(arena, block, 0, fcolor_zero(), SCu8()));
}
////////////////////////////////
function f32
get_fancy_string_width__inner(Application_Links *app, Face_ID face,
Fancy_String *string){
f32 result = 0.f;
for (;string != 0;
string = string->next){
Face_ID use_face = face;
if (string->face != 0){
use_face = string->face;
}
if (use_face != 0){
result += get_string_advance(app, use_face, string->value);
Face_Metrics metrics = get_face_metrics(app, use_face);
f32 normal_advance = metrics.normal_advance;
result += (string->pre_margin + string->post_margin)*normal_advance;
}
}
return(result);
}
function f32
get_fancy_string_height__inner(Application_Links *app, Face_ID face, Fancy_String *string){
f32 result = 0.f;
if (face != 0){
Face_Metrics metrics = get_face_metrics(app, face);
result = metrics.line_height;
}
for (;string != 0;
string = string->next){
if (string->face != 0){
Face_ID use_face = string->face;
Face_Metrics metrics = get_face_metrics(app, use_face);
result = Max(result, metrics.line_height);
}
}
return(result);
}
function f32
get_fancy_string_text_height__inner(Application_Links *app, Face_ID face, Fancy_String *string){
f32 result = 0.f;
if (face != 0){
Face_Metrics metrics = get_face_metrics(app, face);
result = metrics.text_height;
}
for (;string != 0;
string = string->next){
if (string->face != 0){
Face_ID use_face = string->face;
Face_Metrics metrics = get_face_metrics(app, use_face);
result = Max(result, metrics.text_height);
}
}
return(result);
}
function Vec2_f32
draw_fancy_string__inner(Application_Links *app, Face_ID face, FColor fore, Fancy_String *first_string, Vec2_f32 p, u32 flags, Vec2_f32 delta){
f32 base_line = 0.f;
for (Fancy_String *string = first_string;
string != 0;
string = string->next){
Face_ID use_face = face;
if (string->face != 0){
use_face = string->face;
}
if (use_face != 0){
Face_Metrics metrics = get_face_metrics(app, use_face);
base_line = Max(base_line, metrics.ascent);
}
}
Vec2_f32 down_delta = V2f32(-delta.y, delta.x);
for (Fancy_String *string = first_string;
string != 0;
string = string->next){
Face_ID use_face = face;
if (string->face != 0){
use_face = string->face;
}
FColor use_fore = fore;
if (fcolor_is_valid(string->fore)){
use_fore = string->fore;
}
if (use_face != 0){
ARGB_Color use_argb = fcolor_resolve(use_fore);
Face_Metrics metrics = get_face_metrics(app, use_face);
f32 down_shift = (base_line - metrics.ascent);
down_shift = clamp_bot(0.f, down_shift);
Vec2_f32 p_shift = down_shift*down_delta;
Vec2_f32 p_shifted = p + p_shift;
if (fcolor_is_valid(use_fore)){
Vec2_f32 margin_delta = delta*metrics.normal_advance;
p_shifted += margin_delta*string->pre_margin;
p_shifted = draw_string_oriented(app, use_face, use_argb, string->value, p_shifted, flags, delta);
p_shifted += margin_delta*string->post_margin;
}
else{
f32 adv =
(string->pre_margin + string->post_margin)*metrics.normal_advance;
adv += get_string_advance(app, use_face, string->value);
p_shifted += adv*delta;
}
p = p_shifted - p_shift;
}
}
return(p);
}
function f32
get_fancy_string_width(Application_Links *app, Face_ID face,
Fancy_String *string){
Fancy_String *next = string->next;
string->next = 0;
f32 result = get_fancy_string_width__inner(app, face, string);
string->next = next;
return(result);
}
function f32
get_fancy_string_height(Application_Links *app, Face_ID face,
Fancy_String *string){
Fancy_String *next = string->next;
string->next = 0;
f32 result = get_fancy_string_height__inner(app, face, string);
string->next = next;
return(result);
}
function f32
get_fancy_string_text_height(Application_Links *app, Face_ID face,
Fancy_String *string){
Fancy_String *next = string->next;
string->next = 0;
f32 result = get_fancy_string_text_height__inner(app, face, string);
string->next = next;
return(result);
}
function Vec2_f32
get_fancy_string_dim(Application_Links *app, Face_ID face, Fancy_String *string){
Fancy_String *next = string->next;
string->next = 0;
Vec2_f32 result = V2f32(get_fancy_string_width__inner(app, face, string),
get_fancy_string_height__inner(app, face, string));
string->next = next;
return(result);
}
function Vec2_f32
draw_fancy_string(Application_Links *app, Face_ID face, FColor fore,
Fancy_String *string, Vec2_f32 p, u32 flags, Vec2_f32 delta){
Fancy_String *next = string->next;
string->next = 0;
Vec2_f32 result = draw_fancy_string__inner(app, face, fore, string, p, flags, delta);
string->next = next;
return(result);
}
function f32
get_fancy_line_width(Application_Links *app, Face_ID face, Fancy_Line *line){
f32 result = 0.f;
if (line != 0){
if (line->face != 0){
face = line->face;
}
result = get_fancy_string_width__inner(app, face, line->first);
}
return(result);
}
function f32
get_fancy_line_height(Application_Links *app, Face_ID face, Fancy_Line *line){
f32 result = 0.f;
if (line != 0){
if (line->face != 0){
face = line->face;
}
result = get_fancy_string_height__inner(app, face, line->first);
}
return(result);
}
function f32
get_fancy_line_text_height(Application_Links *app, Face_ID face, Fancy_Line *line){
f32 result = 0.f;
if (line != 0){
if (line->face != 0){
face = line->face;
}
result = get_fancy_string_text_height__inner(app, face, line->first);
}
return(result);
}
function Vec2_f32
get_fancy_line_dim(Application_Links *app, Face_ID face, Fancy_Line *line){
Vec2_f32 result = {};
if (line != 0){
if (line->face != 0){
face = line->face;
}
result = V2f32(get_fancy_string_width__inner(app, face, line->first), get_fancy_string_height__inner(app, face, line->first));
}
return(result);
}
function Vec2_f32
draw_fancy_line(Application_Links *app, Face_ID face, FColor fore,
Fancy_Line *line, Vec2_f32 p, u32 flags, Vec2_f32 delta){
Vec2_f32 result = {};
if (line != 0){
if (line->face != 0){
face = line->face;
}
if (fcolor_is_valid(line->fore)){
fore = line->fore;
}
result = draw_fancy_string__inner(app, face, fore, line->first, p, flags, delta);
}
return(result);
}
function f32
get_fancy_block_width(Application_Links *app, Face_ID face, Fancy_Block *block){
f32 width = 0.f;
for (Fancy_Line *node = block->first;
node != 0;
node = node->next){
f32 w = get_fancy_line_width(app, face, node);
width = Max(width, w);
}
return(width);
}
function f32
get_fancy_block_height(Application_Links *app, Face_ID face, Fancy_Block *block){
f32 height = 0.f;
for (Fancy_Line *node = block->first;
node != 0;
node = node->next){
height += get_fancy_line_height(app, face, node);
}
return(height);
}
function Vec2_f32
get_fancy_block_dim(Application_Links *app, Face_ID face, Fancy_Block *block){
Vec2_f32 result = {};
result.x = get_fancy_block_width(app, face, block);
result.y = get_fancy_block_height(app, face, block);
return(result);
}
function void
draw_fancy_block(Application_Links *app, Face_ID face, FColor fore,
Fancy_Block *block, Vec2_f32 p, u32 flags, Vec2_f32 delta){
for (Fancy_Line *node = block->first;
node != 0;
node = node->next){
draw_fancy_line(app, face, fore, node, p, flags, delta);
p.y += get_fancy_line_height(app, face, node);
}
}
function Vec2_f32
draw_fancy_string(Application_Links *app, Face_ID face, FColor fore,
Fancy_String *string, Vec2_f32 p){
return(draw_fancy_string(app, face, fore, string, p, 0, V2f32(1.f, 0.f)));
}
function Vec2_f32
draw_fancy_string(Application_Links *app, Fancy_String *string, Vec2_f32 p){
return(draw_fancy_string(app, 0, fcolor_zero(), string, p, 0, V2f32(1.f, 0.f)));
}
function Vec2_f32
draw_fancy_line(Application_Links *app, Face_ID face, FColor fore,
Fancy_Line *line, Vec2_f32 p){
return(draw_fancy_line(app, face, fore, line, p, 0, V2f32(1.f, 0.f)));
}
function void
draw_fancy_block(Application_Links *app, Face_ID face, FColor fore,
Fancy_Block *block, Vec2_f32 p){
draw_fancy_block(app, face, fore, block, p, 0, V2f32(1.f, 0.f));
}
////////////////////////////////
// TODO(allen): beta: color palette
global FColor f_white = fcolor_argb(1.0f, 1.0f, 1.0f, 1.0f);
global FColor f_light_gray = fcolor_argb(0.7f, 0.7f, 0.7f, 1.0f);
global FColor f_gray = fcolor_argb(0.5f, 0.5f, 0.5f, 1.0f);
global FColor f_dark_gray = fcolor_argb(0.3f, 0.3f, 0.3f, 1.0f);
global FColor f_black = fcolor_argb(0.0f, 0.0f, 0.0f, 1.0f);
global FColor f_red = fcolor_argb(1.0f, 0.0f, 0.0f, 1.0f);
global FColor f_green = fcolor_argb(0.0f, 1.0f, 0.0f, 1.0f);
global FColor f_blue = fcolor_argb(0.0f, 0.0f, 1.0f, 1.0f);
global FColor f_yellow = fcolor_argb(1.0f, 1.0f, 0.0f, 1.0f);
global FColor f_pink = fcolor_argb(1.0f, 0.0f, 1.0f, 1.0f);
global FColor f_cyan = fcolor_argb(0.0f, 1.0f, 1.0f, 1.0f);
// BOTTOM