-
Notifications
You must be signed in to change notification settings - Fork 71
/
class_Graphics.ahk
3884 lines (3354 loc) · 174 KB
/
class_Graphics.ahk
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
; Script: Graphics.ahk
; Author: iseahound
; License: GPLv3
; Version: August 2018 (not for public use.)
; Release: 2019-08-03
#include <Gdip_All> ; https://goo.gl/rUuEF5
; EqualImage() - Ensures that the pixel vaules of multiple images across mutiple formats are identical.
EqualImage(images*){
return Graphics.ImageRenderer.Equal(images*)
}
; PreprocessImage() - Converts an image of any type into any new type with cropping and scaling.
PreprocessImage(cotype, image, crop:="", scale:="", terms*){
return Graphics.ImageRenderer.Preprocess(cotype, image, crop, scale, terms*)
}
; RenderImage() - Displays an image in customizable styles on the screen.
RenderImage(image:="", style:="", polygons:=""){
return Graphics.ImageRenderer.Render(image, style, polygons)
}
; RenderImageI() - Allows the user to interact with the displayed image.
RenderImageI(image:="", style:="", polygons:="", keybinds:=""){
return new Graphics.INTERACTIVE(Graphics.ImageRenderer.Render(image, style, polygons), keybinds, 2)
}
; RenderImageS() - Creates a sequence of images that can be interacted with.
RenderImageS(image:="", style:="", polygons:="", keybinds:=""){
return new Graphics.SEQUENCER(new Graphics.INTERACTIVE(Graphics.ImageRenderer.Render(image, style, polygons), keybinds, 2, true))
}
; RenderPolygon() - Displays polygons in customizable styles on the screen.
RenderPolygon(polygon:="", style:=""){
return Graphics.PolygonRenderer.Render(polygon, style)
}
; RenderPolygonI() - Allows the user to interact with the displayed polygon.
RenderPolygonI(polygon:="", style:="", keybinds:=""){
return new Graphics.INTERACTIVE(Graphics.PolygonRenderer.Render(polygon, style), keybinds, 0)
}
; RenderPolygonS() - Creates a sequence of polygons that can be interacted with.
RenderPolygonS(polygon:="", style:="", keybinds:=""){
return new Graphics.SEQUENCER(new Graphics.INTERACTIVE(Graphics.PolygonRenderer.Render(polygon, style), keybinds, 0, true))
}
; RenderText() - Displays text in customizable styles on the screen.
RenderText(text:="", background_style:="", text_style:=""){
return Graphics.TextRenderer.Render(text, background_style, text_style)
}
; RenderTextI() - Allows the user to interact with the displayed text.
RenderTextI(text:="", background_style:="", text_style:="", keybinds:=""){
return new Graphics.INTERACTIVE(Graphics.TextRenderer.Render(text, background_style, text_style), keybinds, 2)
}
; RenderTextS() - Creates a sequence of text that can be interacted with.
RenderTextS(text:="", background_style:="", text_style:="", keybinds:=""){
return new Graphics.SEQUENCER(new Graphics.INTERACTIVE(Graphics.TextRenderer.Render(text, background_style, text_style), keybinds, 2, true))
}
class Graphics {
static pToken ; Pointer to an instance of the GDI+ library.
static renderers := 0 ; Number of active renderer objects currently being used.
; Duality #0 - Loads a local instance of the GDI+ library.
Startup() {
global pToken
if (this.renderers++ <= 0) {
; Thanks to jeeswg and majkinetor for showing how to create a custom window class.
vWinClass := "AutoHotkeyGraphics"
if (A_AhkVersion < 2) {
_fn := "RegisterCallback"
pWndProc := %_fn%(this.callback, "F",,&this)
} else {
_fn := "CallbackCreate"
pWndProc := %_fn%(this.callback, "F")
}
hCursor := DllCall("LoadCursor", "ptr",0, "ptr",32512, "ptr") ; IDC_ARROW := 32512
; struct tagWNDCLASSEXA - https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassexa
; struct tagWNDCLASSEXW - https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassexw
vSize := A_PtrSize=8 ? 80:48
VarSetCapacity(WNDCLASSEX, vSize, 0) ; sizeof(WNDCLASSEX) = 48 or 80
, NumPut( vSize, WNDCLASSEX, 0, "uint") ; cbSize
, NumPut( 3, WNDCLASSEX, 4, "uint") ; style
, NumPut( pWndProc, WNDCLASSEX, 8, "ptr") ; lpfnWndProc
, NumPut( 0, WNDCLASSEX, A_PtrSize=8 ? 16:12, "int") ; cbClsExtra
, NumPut( 0, WNDCLASSEX, A_PtrSize=8 ? 20:16, "int") ; cbWndExtra
, NumPut( 0, WNDCLASSEX, A_PtrSize=8 ? 24:20, "ptr") ; hInstance
, NumPut( 0, WNDCLASSEX, A_PtrSize=8 ? 32:24, "ptr") ; hIcon
, NumPut( hCursor, WNDCLASSEX, A_PtrSize=8 ? 40:28, "ptr") ; hCursor
, NumPut( 16, WNDCLASSEX, A_PtrSize=8 ? 48:32, "ptr") ; hbrBackground
, NumPut( 0, WNDCLASSEX, A_PtrSize=8 ? 56:36, "ptr") ; lpszMenuName
, NumPut( &vWinClass, WNDCLASSEX, A_PtrSize=8 ? 64:40, "ptr") ; lpszClassName
, NumPut( 0, WNDCLASSEX, A_PtrSize=8 ? 72:44, "ptr") ; hIconSm
; Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.
DllCall("RegisterClassEx", "ptr",&WNDCLASSEX, "ushort")
; Set pToken.
this.pToken := (pToken) ? pToken : Gdip_Startup()
}
return this.pToken
}
; Duality #0 - Releases a local instance of the GDI+ library.
Shutdown() {
global pToken
if (--this.renderers <= 0) {
DllCall("UnregisterClass", "str","AutoHotkeyGraphics", "ptr",0)
(pToken) ? pToken : Gdip_Shutdown(this.pToken)
}
return
}
Callback(uMsg, wParam, lParam) {
return DllCall("DefWindowProc", "ptr",this, "uint",uMsg, "uptr",wParam, "ptr",lParam, "ptr") ; hWnd := this
}
class parse {
color(c, default := 0xDD424242) {
static colorRGB := "^0x([0-9A-Fa-f]{6})$"
static colorARGB := "^0x([0-9A-Fa-f]{8})$"
static hex6 := "^([0-9A-Fa-f]{6})$"
static hex8 := "^([0-9A-Fa-f]{8})$"
if ObjGetCapacity([c], 1) {
c := (c ~= "^#") ? SubStr(c, 2) : c
c := ((___ := this.colorMap(c)) != "") ? ___ : c
c := (c ~= colorRGB) ? "0xFF" RegExReplace(c, colorRGB, "$1") : (c ~= hex8) ? "0x" c : (c ~= hex6) ? "0xFF" c : c
c := (c ~= colorARGB) ? c : default
}
return (c != "") ? c : default
}
colorMap(c) {
static map
if !(map) {
color := [] ; 73 LINES MAX
color["Clear"] := color["Off"] := color["None"] := color["Transparent"] := "0x00000000"
color["AliceBlue"] := "0xFFF0F8FF"
, color["AntiqueWhite"] := "0xFFFAEBD7"
, color["Aqua"] := "0xFF00FFFF"
, color["Aquamarine"] := "0xFF7FFFD4"
, color["Azure"] := "0xFFF0FFFF"
, color["Beige"] := "0xFFF5F5DC"
, color["Bisque"] := "0xFFFFE4C4"
, color["Black"] := "0xFF000000"
, color["BlanchedAlmond"] := "0xFFFFEBCD"
, color["Blue"] := "0xFF0000FF"
, color["BlueViolet"] := "0xFF8A2BE2"
, color["Brown"] := "0xFFA52A2A"
, color["BurlyWood"] := "0xFFDEB887"
, color["CadetBlue"] := "0xFF5F9EA0"
, color["Chartreuse"] := "0xFF7FFF00"
, color["Chocolate"] := "0xFFD2691E"
, color["Coral"] := "0xFFFF7F50"
, color["CornflowerBlue"] := "0xFF6495ED"
, color["Cornsilk"] := "0xFFFFF8DC"
, color["Crimson"] := "0xFFDC143C"
, color["Cyan"] := "0xFF00FFFF"
, color["DarkBlue"] := "0xFF00008B"
, color["DarkCyan"] := "0xFF008B8B"
, color["DarkGoldenRod"] := "0xFFB8860B"
, color["DarkGray"] := "0xFFA9A9A9"
, color["DarkGrey"] := "0xFFA9A9A9"
, color["DarkGreen"] := "0xFF006400"
, color["DarkKhaki"] := "0xFFBDB76B"
, color["DarkMagenta"] := "0xFF8B008B"
, color["DarkOliveGreen"] := "0xFF556B2F"
, color["DarkOrange"] := "0xFFFF8C00"
, color["DarkOrchid"] := "0xFF9932CC"
, color["DarkRed"] := "0xFF8B0000"
, color["DarkSalmon"] := "0xFFE9967A"
, color["DarkSeaGreen"] := "0xFF8FBC8F"
, color["DarkSlateBlue"] := "0xFF483D8B"
, color["DarkSlateGray"] := "0xFF2F4F4F"
, color["DarkSlateGrey"] := "0xFF2F4F4F"
, color["DarkTurquoise"] := "0xFF00CED1"
, color["DarkViolet"] := "0xFF9400D3"
, color["DeepPink"] := "0xFFFF1493"
, color["DeepSkyBlue"] := "0xFF00BFFF"
, color["DimGray"] := "0xFF696969"
, color["DimGrey"] := "0xFF696969"
, color["DodgerBlue"] := "0xFF1E90FF"
, color["FireBrick"] := "0xFFB22222"
, color["FloralWhite"] := "0xFFFFFAF0"
, color["ForestGreen"] := "0xFF228B22"
, color["Fuchsia"] := "0xFFFF00FF"
, color["Gainsboro"] := "0xFFDCDCDC"
, color["GhostWhite"] := "0xFFF8F8FF"
, color["Gold"] := "0xFFFFD700"
, color["GoldenRod"] := "0xFFDAA520"
, color["Gray"] := "0xFF808080"
, color["Grey"] := "0xFF808080"
, color["Green"] := "0xFF008000"
, color["GreenYellow"] := "0xFFADFF2F"
, color["HoneyDew"] := "0xFFF0FFF0"
, color["HotPink"] := "0xFFFF69B4"
, color["IndianRed"] := "0xFFCD5C5C"
, color["Indigo"] := "0xFF4B0082"
, color["Ivory"] := "0xFFFFFFF0"
, color["Khaki"] := "0xFFF0E68C"
, color["Lavender"] := "0xFFE6E6FA"
, color["LavenderBlush"] := "0xFFFFF0F5"
, color["LawnGreen"] := "0xFF7CFC00"
, color["LemonChiffon"] := "0xFFFFFACD"
, color["LightBlue"] := "0xFFADD8E6"
, color["LightCoral"] := "0xFFF08080"
, color["LightCyan"] := "0xFFE0FFFF"
, color["LightGoldenRodYellow"] := "0xFFFAFAD2"
, color["LightGray"] := "0xFFD3D3D3"
, color["LightGrey"] := "0xFFD3D3D3"
color["LightGreen"] := "0xFF90EE90"
, color["LightPink"] := "0xFFFFB6C1"
, color["LightSalmon"] := "0xFFFFA07A"
, color["LightSeaGreen"] := "0xFF20B2AA"
, color["LightSkyBlue"] := "0xFF87CEFA"
, color["LightSlateGray"] := "0xFF778899"
, color["LightSlateGrey"] := "0xFF778899"
, color["LightSteelBlue"] := "0xFFB0C4DE"
, color["LightYellow"] := "0xFFFFFFE0"
, color["Lime"] := "0xFF00FF00"
, color["LimeGreen"] := "0xFF32CD32"
, color["Linen"] := "0xFFFAF0E6"
, color["Magenta"] := "0xFFFF00FF"
, color["Maroon"] := "0xFF800000"
, color["MediumAquaMarine"] := "0xFF66CDAA"
, color["MediumBlue"] := "0xFF0000CD"
, color["MediumOrchid"] := "0xFFBA55D3"
, color["MediumPurple"] := "0xFF9370DB"
, color["MediumSeaGreen"] := "0xFF3CB371"
, color["MediumSlateBlue"] := "0xFF7B68EE"
, color["MediumSpringGreen"] := "0xFF00FA9A"
, color["MediumTurquoise"] := "0xFF48D1CC"
, color["MediumVioletRed"] := "0xFFC71585"
, color["MidnightBlue"] := "0xFF191970"
, color["MintCream"] := "0xFFF5FFFA"
, color["MistyRose"] := "0xFFFFE4E1"
, color["Moccasin"] := "0xFFFFE4B5"
, color["NavajoWhite"] := "0xFFFFDEAD"
, color["Navy"] := "0xFF000080"
, color["OldLace"] := "0xFFFDF5E6"
, color["Olive"] := "0xFF808000"
, color["OliveDrab"] := "0xFF6B8E23"
, color["Orange"] := "0xFFFFA500"
, color["OrangeRed"] := "0xFFFF4500"
, color["Orchid"] := "0xFFDA70D6"
, color["PaleGoldenRod"] := "0xFFEEE8AA"
, color["PaleGreen"] := "0xFF98FB98"
, color["PaleTurquoise"] := "0xFFAFEEEE"
, color["PaleVioletRed"] := "0xFFDB7093"
, color["PapayaWhip"] := "0xFFFFEFD5"
, color["PeachPuff"] := "0xFFFFDAB9"
, color["Peru"] := "0xFFCD853F"
, color["Pink"] := "0xFFFFC0CB"
, color["Plum"] := "0xFFDDA0DD"
, color["PowderBlue"] := "0xFFB0E0E6"
, color["Purple"] := "0xFF800080"
, color["RebeccaPurple"] := "0xFF663399"
, color["Red"] := "0xFFFF0000"
, color["RosyBrown"] := "0xFFBC8F8F"
, color["RoyalBlue"] := "0xFF4169E1"
, color["SaddleBrown"] := "0xFF8B4513"
, color["Salmon"] := "0xFFFA8072"
, color["SandyBrown"] := "0xFFF4A460"
, color["SeaGreen"] := "0xFF2E8B57"
, color["SeaShell"] := "0xFFFFF5EE"
, color["Sienna"] := "0xFFA0522D"
, color["Silver"] := "0xFFC0C0C0"
, color["SkyBlue"] := "0xFF87CEEB"
, color["SlateBlue"] := "0xFF6A5ACD"
, color["SlateGray"] := "0xFF708090"
, color["SlateGrey"] := "0xFF708090"
, color["Snow"] := "0xFFFFFAFA"
, color["SpringGreen"] := "0xFF00FF7F"
, color["SteelBlue"] := "0xFF4682B4"
, color["Tan"] := "0xFFD2B48C"
, color["Teal"] := "0xFF008080"
, color["Thistle"] := "0xFFD8BFD8"
, color["Tomato"] := "0xFFFF6347"
, color["Turquoise"] := "0xFF40E0D0"
, color["Violet"] := "0xFFEE82EE"
, color["Wheat"] := "0xFFF5DEB3"
, color["White"] := "0xFFFFFFFF"
, color["WhiteSmoke"] := "0xFFF5F5F5"
color["Yellow"] := "0xFFFFFF00"
, color["YellowGreen"] := "0xFF9ACD32"
map := color
}
return map[c]
}
dropShadow(d, vw, vh, width, height, font_size) {
static q1 := "(?i)^.*?\b(?<!:|:\s)\b"
static q2 := "(?!(?>\([^()]*\)|[^()]*)*\))(:\s*)?\(?(?<value>(?<=\()([\s:#%_a-z\-\.\d]+|\([\s:#%_a-z\-\.\d]*\))*(?=\))|[#%_a-z\-\.\d]+).*$"
static valid := "(?i)^\s*(\-?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+)))\s*(%|pt|px|vh|vmin|vw)?\s*$"
vmin := (vw < vh) ? vw : vh
if IsObject(d) {
d.1 := (d.horizontal != "") ? d.horizontal : (d.h != "") ? d.h : d.1
d.2 := (d.vertical != "") ? d.vertical : (d.v != "") ? d.h : d.2
d.3 := (d.blur != "") ? d.blur : (d.b != "") ? d.h : d.3
d.4 := (d.color != "") ? d.color : (d.c != "") ? d.h : d.4
d.5 := (d.opacity != "") ? d.opacity : (d.o != "") ? d.h : d.5
d.6 := (d.size != "") ? d.size : (d.s != "") ? d.h : d.6
} else if (d != "") {
_ := RegExReplace(d, ":\s+", ":")
_ := RegExReplace(_, "\s+", " ")
_ := StrSplit(_, " ")
_.1 := ((___ := RegExReplace(d, q1 "(h(orizontal)?)" q2, "${value}")) != d) ? ___ : _.1
_.2 := ((___ := RegExReplace(d, q1 "(v(ertical)?)" q2, "${value}")) != d) ? ___ : _.2
_.3 := ((___ := RegExReplace(d, q1 "(b(lur)?)" q2, "${value}")) != d) ? ___ : _.3
_.4 := ((___ := RegExReplace(d, q1 "(c(olor)?)" q2, "${value}")) != d) ? ___ : _.4
_.5 := ((___ := RegExReplace(d, q1 "(o(pacity)?)" q2, "${value}")) != d) ? ___ : _.5
_.6 := ((___ := RegExReplace(d, q1 "(s(ize)?)" q2, "${value}")) != d) ? ___ : _.6
d := _
}
else return {"void":true, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0}
for key, value in d {
if (key = 4) ; Don't mess with color data.
continue
d[key] := (d[key] ~= valid) ? RegExReplace(d[key], "\s", "") : 0 ; Default for everything is 0.
d[key] := (d[key] ~= "i)(pt|px)$") ? SubStr(d[key], 1, -2) : d[key]
d[key] := (d[key] ~= "i)vw$") ? RegExReplace(d[key], "i)vw$", "") * vw : d[key]
d[key] := (d[key] ~= "i)vh$") ? RegExReplace(d[key], "i)vh$", "") * vh : d[key]
d[key] := (d[key] ~= "i)vmin$") ? RegExReplace(d[key], "i)vmin$", "") * vmin : d[key]
}
d.1 := (d.1 ~= "%$") ? SubStr(d.1, 1, -1) * 0.01 * width : d.1
d.2 := (d.2 ~= "%$") ? SubStr(d.2, 1, -1) * 0.01 * height : d.2
d.3 := (d.3 ~= "%$") ? SubStr(d.3, 1, -1) * 0.01 * font_size : d.3
d.4 := this.color(d.4, 0xFFFF0000) ; Default color is red.
d.5 := (d.5 ~= "%$") ? SubStr(d.5, 1, -1) / 100 : d.5
d.5 := (d.5 <= 0 || d.5 > 1) ? 1 : d.5 ; Range Opacity is a float from 0-1.
d.6 := (d.6 ~= "%$") ? SubStr(d.6, 1, -1) * 0.01 * font_size : d.6
return d
}
font(f, default := "Arial"){
}
grayscale(sRGB) {
static rY := 0.212655
static gY := 0.715158
static bY := 0.072187
c1 := 255 & ( sRGB >> 16 )
c2 := 255 & ( sRGB >> 8 )
c3 := 255 & ( sRGB )
loop 3 {
c%A_Index% := c%A_Index% / 255
c%A_Index% := (c%A_Index% <= 0.04045) ? c%A_Index%/12.92 : ((c%A_Index%+0.055)/(1.055))**2.4
}
v := rY*c1 + gY*c2 + bY*c3
v := (v <= 0.0031308) ? v * 12.92 : 1.055*(v**(1.0/2.4))-0.055
return Round(v*255)
}
margin_and_padding(m, vw, vh, default := "") {
static q1 := "(?i)^.*?\b(?<!:|:\s)\b"
static q2 := "(?!(?>\([^()]*\)|[^()]*)*\))(:\s*)?\(?(?<value>(?<=\()([\s:#%_a-z\-\.\d]+|\([\s:#%_a-z\-\.\d]*\))*(?=\))|[#%_a-z\-\.\d]+).*$"
static valid := "(?i)^\s*(\-?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+)))\s*(%|pt|px|vh|vmin|vw)?\s*$"
vmin := (vw < vh) ? vw : vh
if IsObject(m) {
m.1 := (m.top != "") ? m.top : (m.t != "") ? m.t : m.1
m.2 := (m.right != "") ? m.right : (m.r != "") ? m.r : m.2
m.3 := (m.bottom != "") ? m.bottom : (m.b != "") ? m.b : m.3
m.4 := (m.left != "") ? m.left : (m.l != "") ? m.l : m.4
} else if (m != "") {
_ := RegExReplace(m, ":\s+", ":")
_ := RegExReplace(_, "\s+", " ")
_ := StrSplit(_, " ")
_.1 := ((___ := RegExReplace(m, q1 "(t(op)?)" q2, "${value}")) != m) ? ___ : _.1
_.2 := ((___ := RegExReplace(m, q1 "(r(ight)?)" q2, "${value}")) != m) ? ___ : _.2
_.3 := ((___ := RegExReplace(m, q1 "(b(ottom)?)" q2, "${value}")) != m) ? ___ : _.3
_.4 := ((___ := RegExReplace(m, q1 "(l(eft)?)" q2, "${value}")) != m) ? ___ : _.4
m := _
} else if (default != "")
m := {1:default, 2:default, 3:default, 4:default}
else return {"void":true, 1:0, 2:0, 3:0, 4:0}
; Follow CSS guidelines for margin!
if (m.2 == "" && m.3 == "" && m.4 == "")
m.4 := m.3 := m.2 := m.1, exception := true
if (m.3 == "" && m.4 == "")
m.4 := m.2, m.3 := m.1
if (m.4 == "")
m.4 := m.2
for key, value in m {
m[key] := (m[key] ~= valid) ? RegExReplace(m[key], "\s", "") : default
m[key] := (m[key] ~= "i)(pt|px)$") ? SubStr(m[key], 1, -2) : m[key]
m[key] := (m[key] ~= "i)vw$") ? RegExReplace(m[key], "i)vw$", "") * vw : m[key]
m[key] := (m[key] ~= "i)vh$") ? RegExReplace(m[key], "i)vh$", "") * vh : m[key]
m[key] := (m[key] ~= "i)vmin$") ? RegExReplace(m[key], "i)vmin$", "") * vmin : m[key]
}
m.1 := (m.1 ~= "%$") ? SubStr(m.1, 1, -1) * vh : m.1
m.2 := (m.2 ~= "%$") ? SubStr(m.2, 1, -1) * (exception ? vh : vw) : m.2
m.3 := (m.3 ~= "%$") ? SubStr(m.3, 1, -1) * vh : m.3
m.4 := (m.4 ~= "%$") ? SubStr(m.4, 1, -1) * (exception ? vh : vw) : m.4
return m
}
outline(o, vw, vh, font_size, font_color) {
static q1 := "(?i)^.*?\b(?<!:|:\s)\b"
static q2 := "(?!(?>\([^()]*\)|[^()]*)*\))(:\s*)?\(?(?<value>(?<=\()([\s:#%_a-z\-\.\d]+|\([\s:#%_a-z\-\.\d]*\))*(?=\))|[#%_a-z\-\.\d]+).*$"
static valid_positive := "(?i)^\s*((?:(?:\d+(?:\.\d*)?)|(?:\.\d+)))\s*(%|pt|px|vh|vmin|vw)?\s*$"
vmin := (vw < vh) ? vw : vh
if IsObject(o) {
o.1 := (o.stroke != "") ? o.stroke : (o.s != "") ? o.s : o.1
o.2 := (o.color != "") ? o.color : (o.c != "") ? o.c : o.2
o.3 := (o.glow != "") ? o.glow : (o.g != "") ? o.g : o.3
o.4 := (o.tint != "") ? o.tint : (o.t != "") ? o.t : o.4
} else if (o != "") {
_ := RegExReplace(o, ":\s+", ":")
_ := RegExReplace(_, "\s+", " ")
_ := StrSplit(_, " ")
_.1 := ((___ := RegExReplace(o, q1 "(s(troke)?)" q2, "${value}")) != o) ? ___ : _.1
_.2 := ((___ := RegExReplace(o, q1 "(c(olor)?)" q2, "${value}")) != o) ? ___ : _.2
_.3 := ((___ := RegExReplace(o, q1 "(g(low)?)" q2, "${value}")) != o) ? ___ : _.3
_.4 := ((___ := RegExReplace(o, q1 "(t(int)?)" q2, "${value}")) != o) ? ___ : _.4
o := _
}
else return {"void":true, 1:0, 2:0, 3:0, 4:0}
for key, value in o {
if (key = 2) || (key = 4) ; Don't mess with color data.
continue
o[key] := (o[key] ~= valid_positive) ? RegExReplace(o[key], "\s", "") : 0 ; Default for everything is 0.
o[key] := (o[key] ~= "i)(pt|px)$") ? SubStr(o[key], 1, -2) : o[key]
o[key] := (o[key] ~= "i)vw$") ? RegExReplace(o[key], "i)vw$", "") * vw : o[key]
o[key] := (o[key] ~= "i)vh$") ? RegExReplace(o[key], "i)vh$", "") * vh : o[key]
o[key] := (o[key] ~= "i)vmin$") ? RegExReplace(o[key], "i)vmin$", "") * vmin : o[key]
}
o.1 := (o.1 ~= "%$") ? SubStr(o.1, 1, -1) * 0.01 * font_size : o.1
o.2 := this.color(o.2, font_color) ; Default color is the text font color.
o.3 := (o.3 ~= "%$") ? SubStr(o.3, 1, -1) * 0.01 * font_size : o.3
o.4 := this.color(o.4, o.2) ; Default color is outline color.
return o
}
}
class filter {
GaussianBlur(ByRef pBitmap, radius, opacity := 1) {
static x86 := "
(LTrim
VYnlV1ZTg+xci0Uci30c2UUgx0WsAwAAAI1EAAGJRdiLRRAPr0UYicOJRdSLRRwP
r/sPr0UYiX2ki30UiUWoi0UQjVf/i30YSA+vRRgDRQgPr9ONPL0SAAAAiUWci0Uc
iX3Eg2XE8ECJVbCJRcCLRcSJZbToAAAAACnEi0XEiWXk6AAAAAApxItFxIllzOgA
AAAAKcSLRaiJZcjHRdwAAAAAx0W8AAAAAIlF0ItFvDtFFA+NcAEAAItV3DHAi12c
i3XQiVXgAdOLfQiLVdw7RRiNDDp9IQ+2FAGLTcyLfciJFIEPtgwDD69VwIkMh4tN
5IkUgUDr0THSO1UcfBKLXdwDXQzHRbgAAAAAK13Q6yAxwDtFGH0Ni33kD7YcAQEc
h0Dr7kIDTRjrz/9FuAN1GItF3CtF0AHwiceLRbg7RRx/LDHJO00YfeGLRQiLfcwB
8A+2BAgrBI+LfeQDBI+ZiQSPjTwz933YiAQPQevWi0UIK0Xci03AAfCJRbiLXRCJ
/itdHCt13AN14DnZfAgDdQwrdeDrSot1DDHbK3XcAf4DdeA7XRh9KItV4ItFuAHQ
A1UID7YEGA+2FBop0ItV5AMEmokEmpn3fdiIBB5D69OLRRhBAUXg66OLRRhDAUXg
O10QfTIxyTtNGH3ti33Ii0XgA0UID7YUCIsEjynQi1XkAwSKiQSKi1XgjTwWmfd9
2IgED0Hr0ItF1P9FvAFF3AFF0OmE/v//i0Wkx0XcAAAAAMdFvAAAAACJRdCLRbAD
RQyJRaCLRbw7RRAPjXABAACLTdwxwItdoIt10IlN4AHLi30Mi1XcO0UYjQw6fSEP
thQBi33MD7YMA4kUh4t9yA+vVcCJDIeLTeSJFIFA69Ex0jtVHHwSi13cA10Ix0W4
AAAAACtd0OsgMcA7RRh9DYt95A+2HAEBHIdA6+5CA03U68//RbgDddSLRdwrRdAB
8InHi0W4O0UcfywxyTtNGH3hi0UMi33MAfAPtgQIKwSPi33kAwSPmYkEj408M/d9
2IgED0Hr1otFDCtF3ItNwAHwiUW4i10Uif4rXRwrddwDdeA52XwIA3UIK3Xg60qL
dQgx2yt13AH+A3XgO10YfSiLVeCLRbgB0ANVDA+2BBgPthQaKdCLVeQDBJqJBJqZ
933YiAQeQ+vTi0XUQQFF4Ouji0XUQwFF4DtdFH0yMck7TRh97Yt9yItF4ANFDA+2
FAiLBI+LfeQp0ItV4AMEj4kEj408Fpn3fdiIBA9B69CLRRj/RbwBRdwBRdDphP7/
//9NrItltA+Fofz//9no3+l2PzHJMds7XRR9OotFGIt9CA+vwY1EBwMx/zt9EH0c
D7Yw2cBHVtoMJFrZXeTzDyx15InyiBADRRjr30MDTRDrxd3Y6wLd2I1l9DHAW15f
XcM=
)"
static x64 := "
(LTrim
VUFXQVZBVUFUV1ZTSIHsqAAAAEiNrCSAAAAARIutkAAAAIuFmAAAAESJxkiJVRhB
jVH/SYnPi42YAAAARInHQQ+v9Y1EAAErvZgAAABEiUUARIlN2IlFFEljxcdFtAMA
AABIY96LtZgAAABIiUUID6/TiV0ESIld4A+vy4udmAAAAIl9qPMPEI2gAAAAiVXQ
SI0UhRIAAABBD6/1/8OJTbBIiVXoSINl6PCJXdxBifaJdbxBjXD/SWPGQQ+v9UiJ
RZhIY8FIiUWQiXW4RInOK7WYAAAAiXWMSItF6EiJZcDoAAAAAEgpxEiLRehIieHo
AAAAAEgpxEiLRehIiWX46AAAAABIKcRIi0UYTYn6SIll8MdFEAAAAADHRdQAAAAA
SIlFyItF2DlF1A+NqgEAAESLTRAxwEWJyEQDTbhNY8lNAflBOcV+JUEPthQCSIt9
+EUPthwBSItd8IkUhw+vVdxEiRyDiRSBSP/A69aLVRBFMclEO42YAAAAfA9Ii0WY
RTHbMdtNjSQC6ytMY9oxwE0B+0E5xX4NQQ+2HAMBHIFI/8Dr7kH/wUQB6uvGTANd
CP/DRQHoO52YAAAAi0W8Ro00AH82SItFyEuNPCNFMclJjTQDRTnNftRIi1X4Qg+2
BA9CKwSKQgMEiZlCiQSJ930UQogEDkn/wevZi0UQSWP4SAN9GItd3E1j9kUx200B
/kQpwIlFrEiJfaCLdaiLRaxEAcA580GJ8XwRSGP4TWPAMdtMAf9MA0UY60tIi0Wg
S408Hk+NJBNFMclKjTQYRTnNfiFDD7YUDEIPtgQPKdBCAwSJmUKJBIn3fRRCiAQO
Sf/B69r/w0UB6EwDXQjrm0gDXQhB/8FEO00AfTRMjSQfSY00GEUx20U53X7jSItF
8EMPthQcQosEmCnQQgMEmZlCiQSZ930UQogEHkn/w+vXi0UEAUUQSItF4P9F1EgB
RchJAcLpSv7//0yLVRhMiX3Ix0UQAAAAAMdF1AAAAACLRQA5RdQPja0BAABEi00Q
McBFichEA03QTWPJTANNGEE5xX4lQQ+2FAJIi3X4RQ+2HAFIi33wiRSGD69V3ESJ
HIeJFIFI/8Dr1otVEEUxyUQ7jZgAAAB8D0iLRZBFMdsx202NJALrLUxj2kwDXRgx
wEE5xX4NQQ+2HAMBHIFI/8Dr7kH/wQNVBOvFRANFBEwDXeD/wzudmAAAAItFsEaN
NAB/NkiLRchLjTwjRTHJSY00A0U5zX7TSItV+EIPtgQPQisEikIDBImZQokEifd9
FEKIBA5J/8Hr2YtFEE1j9klj+EwDdRiLXdxFMdtEKcCJRaxJjQQ/SIlFoIt1jItF
rEQBwDnzQYnxfBFNY8BIY/gx20gDfRhNAfjrTEiLRaBLjTweT40kE0UxyUqNNBhF
Oc1+IUMPthQMQg+2BA8p0EIDBImZQokEifd9FEKIBA5J/8Hr2v/DRANFBEwDXeDr
mkgDXeBB/8FEO03YfTRMjSQfSY00GEUx20U53X7jSItF8EMPthQcQosEmCnQQgME
mZlCiQSZ930UQogEHkn/w+vXSItFCP9F1EQBbRBIAUXISQHC6Uf+////TbRIi2XA
D4Ui/P//8w8QBQAAAAAPLsF2TTHJRTHARDtF2H1Cicgx0kEPr8VImEgrRQhNjQwH
McBIA0UIO1UAfR1FD7ZUAQP/wvNBDyrC8w9ZwfNEDyzQRYhUAQPr2kH/wANNAOu4
McBIjWUoW15fQVxBXUFeQV9dw5CQkJCQkJCQkJCQkJAAAIA/
)"
width := Gdip_GetImageWidth(pBitmap)
height := Gdip_GetImageHeight(pBitmap)
clone := Gdip_CloneBitmapArea(pBitmap, 0, 0, width, height)
E1 := Gdip_LockBits(pBitmap, 0, 0, width, height, Stride1, Scan01, BitmapData1)
E2 := Gdip_LockBits(clone, 0, 0, width, height, Stride2, Scan02, BitmapData2)
DllCall("crypt32\CryptStringToBinary", "str",(A_PtrSize == 8) ? x64 : x86, "uint",0, "uint",0x1, "ptr",0, "uint*",s, "ptr",0, "ptr",0)
p := DllCall("GlobalAlloc", "uint",0, "ptr",s, "ptr")
if (A_PtrSize == 8)
DllCall("VirtualProtect", "ptr",p, "ptr",s, "uint",0x40, "uint*",op)
DllCall("crypt32\CryptStringToBinary", "str",(A_PtrSize == 8) ? x64 : x86, "uint",0, "uint",0x1, "ptr",p, "uint*",s, "ptr",0, "ptr",0)
value := DllCall(p, "ptr",Scan01, "ptr",Scan02, "uint",width, "uint",height, "uint",4, "uint",radius, "float",opacity)
DllCall("GlobalFree", "ptr", p)
Gdip_UnlockBits(pBitmap, BitmapData1)
Gdip_UnlockBits(clone, BitmapData2)
Gdip_DisposeImage(clone)
return value
}
}
class safe_bitmap {
outer[p:=""] {
get {
static period := ".", _period := (A_AhkVersion < 2) ? period : "period"
if ((__outer := RegExReplace(this.__class, "^(.*)\..*$", "$1")) != this.__class)
Loop Parse, __outer, %_period%
outer := (A_Index=1) ? %A_LoopField% : outer[A_LoopField]
return IsObject(outer) ? ((p) ? outer[p] : outer) : ((p) ? %p% : "")
}
}
__New(pBitmap) {
global pToken
if !(this.outer.Startup())
if !(pToken)
if !(this.pToken := Gdip_Startup())
throw Exception("Gdiplus failed to start. Please ensure you have gdiplus on your system.")
this.pBitmap := pBitmap
this.w := this.width := Gdip_GetImageWidth(pBitmap)
this.h := this.height := Gdip_GetImageHeight(pBitmap)
this.size := this.width * this.height
}
__Delete() {
Gdip_DisposeImage(this.pBitmap)
global pToken
if (this.outer.pToken)
return this.outer.Shutdown()
if (pToken)
return
if (this.pToken)
return Gdip_Shutdown(this.pToken)
}
Lock() {
this.isLockBits := true
Gdip_LockBits(this.pBitmap, 0, 0, this.width, this.height, Stride, Scan0, BitmapData)
this.BitmapData := BitmapData
this.Stride := Stride
this.Scan0 := Scan0+0
}
__Get(x, y:="", color:=""){
static pBitmap, Stride
if x is integer
{
if (y == "" && color == "" && (ARGB := NumGet(pBitmap, x, "uint")))
return ARGB
if (color == "" && (ARGB := NumGet(pBitmap, y*Stride + x, "uint")))
return ARGB
if (y == "" && color = "alpha" && (ARGB := NumGet(pBitmap, x, "uchar")))
return ARGB
if (y == "" && color = "red" && (ARGB := NumGet(pBitmap, x + 1, "uchar")))
return ARGB
if (y == "" && color = "green" && (ARGB := NumGet(pBitmap, x + 2, "uchar")))
return ARGB
if (y == "" && color = "blue" && (ARGB := NumGet(pBitmap, x + 3, "uchar")))
return ARGB
if (color = "alpha" && (ARGB := NumGet(pBitmap, y*Stride, "uchar")))
return ARGB
if (color = "red" && (ARGB := NumGet(pBitmap, y*Stride + x + 1, "uchar")))
return ARGB
if (color = "green" && (ARGB := NumGet(pBitmap, y*Stride + x + 2, "uchar")))
return ARGB
if (color = "blue" && (ARGB := NumGet(pBitmap, y*Stride + x + 3, "uchar")))
return ARGB
if !(pBitmap)
pBitmap := this.pBitmap
if !(this.isLockBits)
throw Exception("idgaf!") ; SET STRIDE, then this.Stride!
}
}
__Get2(x, y:="", color:="") {
; Get Bitmap[x,y] returns pixel.
if (y >= 0) {
if !(this.isLockBits) {
this.isLockBits := true
Gdip_LockBits(this.pBitmap, 0, 0, this.width, this.height, Stride, Scan0, BitmapData)
this.BitmapData := BitmapData
this.Stride := Stride
this.Scan0 := Scan0+0
}
return NumGet(this.Scan0, x*4 + y*this.Stride, "uint")
if !(y ~= "^\d+$") {
y := x // this.height
x := mod(x, this.height)
}
if !(color)
return NumGet(this.Scan0, x*4 + y*this.Stride, "uint")
ARGB := NumGet(this.Scan0, terms.1*4 + terms.2*this.Stride, "uint")
if !(terms.3)
return ARGB
if (terms.3 ~= "i)a(lpha)?")
return (ARGB & 0xFF000000) >> 24
if (terms.3 ~= "i)r(ed)?")
return (ARGB & 0x00FF0000) >> 16
if (terms.3 ~= "i)g(reen)?")
return (ARGB & 0x0000FF00) >> 8
if (terms.3 ~= "i)b(lue)?")
return (ARGB & 0x000000FF)
}
; Get Bitmap[] or Bitmap.ptr returns pBitmap.
if (x == "" || x = "ptr") {
if (this.isLockBits) {
this.isLockBits := false
this.Stride := this.Scan0 := ""
Gdip_UnlockBits(this.pBitmap, this.BitmapData)
}
return this.pBitmap
}
}
__Set(terms*) {
ARGB := terms.pop()
; Set Bitmap[x,y] to a pixel.
if (terms.1 ~= "^\d+$") {
if !(this.isLockBits) {
this.isLockBits := true
Gdip_LockBits(this.pBitmap, 0, 0, this.width, this.height, Stride, Scan0, BitmapData)
this.Stride := Stride
this.Scan0 := Scan0
this.BitmapData := BitmapData
this.size := this.Stride * this.height
}
if !(terms.3)
NumPut(ARGB, Scan0+0, terms.1*4 + terms.2*this.Stride, "uint")
if (terms.3 ~= "i)a(lpha)?")
NumPut(ARGB, Scan0+0, terms.1*4 + terms.2*this.Stride + 0, "uchar")
if (terms.3 ~= "i)r(ed)?")
NumPut(ARGB, Scan0+0, terms.1*4 + terms.2*this.Stride + 1, "uchar")
if (terms.3 ~= "i)g(reen)?")
NumPut(ARGB, Scan0+0, terms.1*4 + terms.2*this.Stride + 2, "uchar")
if (terms.3 ~= "i)b(lue)?")
NumPut(ARGB, Scan0+0, terms.1*4 + terms.2*this.Stride + 3, "uchar")
}
}
}
class memory {
__New(width, height){
this.hbm := CreateDIBSection(this.width := width, this.height := height)
this.hdc := CreateCompatibleDC()
this.obm := SelectObject(this.hdc, this.hbm)
this.gfx := Gdip_GraphicsFromHDC(this.hdc)
return this
}
__Delete(){
Gdip_DeleteGraphics(this.gfx)
SelectObject(this.hdc, this.obm)
DeleteObject(this.hbm)
DeleteDC(this.hdc)
return
}
}
class queue {
layers := []
fn := []
x := []
y := []
w := []
h := []
xx := []
yy := []
mx := []
my := []
x_mouse := ""
y_mouse := ""
New(function, x_mouse := "", y_mouse := ""){
if (function == this.fn.2)
return
if (this.fn.2 != "" && this.lacuna(2))
return
this.shift()
this.fn.2 := function
this.x_mouse := x_mouse
this.y_mouse := y_mouse
return true ; useful for allowing a new function to execute when x,y coordinates have remained the same.
}
; This function takes any number of inputs, from zero to 8. It will populate the inputs with their
; last known values if omitted. In the case of w & h it will check for a xx & yy input. In the case of
; xx & yy, it will check for a w & h input AND check w & h last known value. This means that if w, h, xx, yy
; are omitted, the width and height will remain constant, and the right and bottom values will change.
Queue(ByRef x:="", ByRef y:="", ByRef w:="", ByRef h:="", ByRef xx:="", ByRef yy:="", ByRef mx:="", ByRef my:=""){
; Store the last found w & h to check if size has changed, forcing a redraw.
old_w := (this.w.2 != "") ? this.w.2 : this.w.1
old_h := (this.h.2 != "") ? this.h.2 : this.h.1
; x & y are independent and mandatory inputs.
if (x != "")
this.x.2 := x
else if (this.x.2 == "" && this.x.1 != "")
this.x.2 := this.x.1
else if (this.x.2 == "")
throw Exception("x coordinate is a mandatory parameter.")
if (y != "")
this.y.2 := y
else if (this.y.2 == "" && this.y.1 != "")
this.y.2 := this.y.1
else if (this.y.2 == "")
throw Exception("y coordinate is a mandatory parameter.")
; w & h are dependent on this.x.2 and this.y.2
if (w != "")
this.w.2 := w
else if (xx != "")
this.w.2 := xx - this.x.2
else if (this.w.2 == "" && this.w.1 != "")
this.w.2 := this.w.1
if (h != "")
this.h.2 := h
else if (yy != "")
this.h.2 := yy - this.y.2
else if (this.h.2 == "" && this.h.1 != "")
this.h.2 := this.h.1
; xx & yy are dependent on this.x.2, this.y.2, this.w.2, and this.h.2
if (xx != "")
this.xx.2 := xx
else if (x != "")
this.xx.2 := this.w.2 + x
else if (w != "")
this.xx.2 := this.x.2 + w
else if (this.xx.2 == "" && this.xx.1 != "")
this.xx.2 := this.xx.1
if (yy != "")
this.yy.2 := yy
else if (y != "")
this.yy.2 := this.h.2 + y
else if (h != "")
this.yy.2 := this.y.2 + h
else if (this.yy.2 == "" && this.y.1 != "")
this.yy.2 := this.yy.1
; mx & my are independent variables.
if (mx != "")
this.mx.2 := mx
else if (this.mx.2 == "" && this.mx.1 != "")
this.mx.2 := this.mx.1
if (my != "")
this.my.2 := my
else if (this.my.2 == "" && this.my.1 != "")
this.my.2 := this.my.1
; Internal checking - can be commented out
if (this.xx.2 - this.x.2 != this.w.2)
throw Exception("Inconsistent width or x2.")
if (this.yy.2 - this.y.2 != this.h.2)
throw Exception("Inconsistent height or y2.")
; Detect if width or height has changed, requiring the image to be redrawn.
this.identical := (this.w.2 == old_w) && (this.h.2 == old_h)
; Return coordinate values by reference.
x := this.x.2, w := this.w.2, xx := this.xx.2, mx := this.mx.2
y := this.y.2, h := this.h.2, yy := this.yy.2, my := this.my.2
}
Shift(){
this.fn.RemoveAt(1)
this.x.RemoveAt(1)
this.y.RemoveAt(1)
this.w.RemoveAt(1)
this.h.RemoveAt(1)
this.xx.RemoveAt(1)
this.yy.RemoveAt(1)
this.mx.RemoveAt(1)
this.my.RemoveAt(1)
}
Lacuna(n := 2){
return (this.x[n] == "" || this.y[n] == "" || this.w[n] == "" || this.h[n] == ""
|| this.xx[n] == "" || this.yy[n] == "")
}
Debug(){
debug := "function: " this.fn.2
. "`nx: " this.x.2 "`ty: " this.y.2
. "`nw: " this.w.2 "`th: " this.h.2
. "`nx2: " this.xx.2 "`ty2: " this.yy.2
. "`nmx: " this.mx.2 "`tmy: " this.my.2
. "`nfunction: " this.fn.1
. "`nx: " this.x.1 "`ty: " this.y.1
. "`nw: " this.w.1 "`th: " this.h.1
. "`nx2: " this.xx.1 "`ty2: " this.yy.1
. "`nmx: " this.mx.1 "`tmy: " this.my.1
_debug := (A_AhkVersion < 2) ? debug : "debug"
Tooltip %_debug%
}
}
class renderer {
; IO - Capture input and internalize environmental data.
IO(terms*) {
static A_Frequency, f := DllCall("QueryPerformanceFrequency", "int64*",A_Frequency)
DllCall("QueryPerformanceCounter", "int64*",A_PreciseTime)
this.PreciseTime := A_PreciseTime
this.TickCount := A_TickCount
this.Frequency := A_Frequency
this.ScreenWidth := A_ScreenWidth
this.ScreenHeight := A_ScreenHeight
this.IsAdmin := A_IsAdmin
return this.arg := terms
}
; Duality #1 - Safe wrapper for the GDI+ library during object instantiation.
__New(terms*) {
this.IO(terms*)
global pToken
if !(this.outer.Startup())
if !(pToken)
if !(this.pToken := Gdip_Startup())
throw Exception("Gdiplus failed to start. Please ensure you have gdiplus on your system.")
return this.CreateWindow(terms*)
}
; Duality #1 - Safe wrapper for the GDI+ library during object garbage collection.
__Delete() {
if (this.hwnd)
this.DestroyWindow()
global pToken
if (this.outer.pToken)
return this.outer.Shutdown()
if (pToken)
return
if (this.pToken)
return Gdip_Shutdown(this.pToken)
}
; Duality #2 - Creates a window.
CreateWindow(title := "", window := "", activate := "") {
; Retrieve original arguments upon window creation.
title := (title != "") ? title : this.arg.1
window := (window != "") ? window : this.arg.2
activate := (activate != "") ? activate : this.arg.3
; Name the window by its inherited class. (Note: A_ThisFunc won't work.)
title := (title != "") ? title : RegExReplace(this.__class, "(.*\.)*(.*)$", "$2")
; Tokenize window styles.
window := RegExReplace(window, "\s+", " ")
window := StrSplit(window, " ")
for i, token in window {
;if (token ~= "i)")
}
;window := (window != "") ? window : " +AlwaysOnTop -Caption +ToolWindow"
;window .= " +LastFound -DPIScale +E0x80000 +hwndhwnd"
; Window Styles - https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles
; Extended Window Styles - https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
WS_OVERLAPPED := 0x0
WS_TILED := 0x0
WS_TABSTOP := 0x10000
WS_MAXIMIZEBOX := 0x10000
WS_MINIMIZEBOX := 0x20000
WS_GROUP := 0x20000
WS_SIZEBOX := 0x40000
WS_THICKFRAME := 0x40000
WS_SYSMENU := 0x80000
WS_HSCROLL := 0x100000
WS_VSCROLL := 0x200000
WS_DLGFRAME := 0x400000
WS_BORDER := 0x800000
WS_MAXIMIZE := 0x1000000
WS_CLIPCHILDREN := 0x2000000
WS_CLIPSIBLINGS := 0x4000000
WS_DISABLED := 0x8000000
WS_VISIBLE := 0x10000000
WS_ICONIC := 0x20000000
WS_MINIMIZE := 0x20000000
WS_CHILD := 0x40000000
WS_CHILDWINDOW := 0x40000000
WS_POPUP := 0x80000000
WS_CAPTION := 0xC00000
WS_OVERLAPPEDWINDOW := 0xCF0000
WS_TILEDWINDOW := 0xCF0000
WS_POPUPWINDOW := 0x80880000
WS_EX_LEFT := 0x0
WS_EX_LTRREADING := 0x0
WS_EX_RIGHTSCROLLBAR := 0x0
WS_EX_DLGMODALFRAME := 0x1
WS_EX_NOPARENTNOTIFY := 0x4
WS_EX_ALWAYSONTOP := 0x4 ; custom
WS_EX_TOPMOST := 0x8
WS_EX_ACCEPTFILES := 0x10
WS_EX_TRANSPARENT := 0x20
WS_EX_MDICHILD := 0x40
WS_EX_TOOLWINDOW := 0x80
WS_EX_WINDOWEDGE := 0x100
WS_EX_CLIENTEDGE := 0x200
WS_EX_CONTEXTHELP := 0x400
WS_EX_RIGHT := 0x1000
WS_EX_RTLREADING := 0x2000
WS_EX_LEFTSCROLLBAR := 0x4000
WS_EX_CONTROLPARENT := 0x10000
WS_EX_STATICEDGE := 0x20000
WS_EX_APPWINDOW := 0x40000
WS_EX_LAYERED := 0x80000
WS_EX_NOINHERITLAYOUT := 0x100000
WS_EX_NOREDIRECTIONBITMAP := 0x200000
WS_EX_LAYOUTRTL := 0x400000
WS_EX_COMPOSITED := 0x2000000
WS_EX_NOACTIVATE := 0x8000000
WS_EX_OVERLAPPEDWINDOW := 0x300
WS_EX_PALETTEWINDOW := 0x188
vWinStyle := WS_SYSMENU ; start off hidden with WS_VISIBLE off
vWinExStyle := WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_LAYERED
; The difference between the screen and the bitmap is that the screen defines the viewable area