-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvclrpicker.ahk
2335 lines (1840 loc) · 88.4 KB
/
advclrpicker.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
;*************************************************************************************************************************
;*************************************************************************************************************************
;*************************************************************************************************************************
;Written By: Hellbent
;Date Started: Nov 21st 2019
;Name: Not Named Yet
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
; HOTKEYS:
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;~ Hotkey , *^ESC , GuiClose ; Ctrl + Esc to exit ;<------------------------------ Activate to use.
Hotkey, Numpad1 , Take_ScreenShot ;<--------------------- Take screenshot of pre-selected area.
;*************************************************************************************************************************
;Auto-Execute Section
;The following code executes as soon as the script is run.
;Setup of script settings and options.
;Declaration of global and other variables used throughout the script.
;Creation of the main gui.
;Creation of the folder to store saved screenshots.
;*************************************************************************************************************************
;Set the script to exit the previous instance if it is run again while it is already running
#SingleInstance, Force
;Set the script to use no environment variables
#NoEnv
;Set the script to run at top speed
SetBatchLines, -1
;Set the coordmode used when selecting pixel positions to be related to the screen
CoordMode, Pixel , Screen
;Set the coordmode used when selecting cursor positions to be related to the screen
CoordMode, Mouse , Screen
;Start using Gdip.
Gdip_Startup()
IfNotExist, %A_ScriptDir%\Screen Shots
;If the folder to hold the saved screenshots doen't already exist.
;Create a folder to hold the saved screenshots.
FileCreateDir, %A_ScriptDir%\Screen Shots
;Set the working dir to be the folder that will hold any screenshots taken.
SetWorkingDir, %A_ScriptDir%\Screen Shots
;Declaration of global variables used throughout the execution of the script.
;****************************************************************************************************
global CapActive := 0 , SP , XCAP , YCAP , WCAP , HCAP , OB := 0
global CapWin := {} , Monitors := New MonitorClass()
;~ global TXC , TYC , BB := New_Brush( "000000" , "88" ) , GB := New_Brush( "00ff00" , "55" ) , RB := New_Brush( "ff0000" , "55" )
global TXC , TYC , BB := New_Brush( "000000" , "ff" ) , GB := New_Brush( "00ff00" , "55" ) , RB := New_Brush( "ff0000" , "55" )
global ShowWin := {} , ImageList1 := [] , ZoomWindow := {}
global Index := 1 , Frame1 , Detached , Message
global OutColor := "3399FF"
;****************************************************************************************************
;###################################################################################################
;Added Jan 7th, 2020
;Check if there are any saved colors and dump them into a variable.
IfNotExist, %A_ScriptDir%\Saved Colors.txt
FileAppend,3399FF`,3399FF`,3399FF`,3399FF,%A_ScriptDir%\Saved Colors.txt
FileRead, SavedColors, %A_ScriptDir%\Saved Colors.txt
global SavedColors:=StrSplit(SavedColors,",")
;~ ToolTip,% SavedColors[1] "`n" SavedColors[2] "`n" SavedColors[3] "`n" SavedColors[4]
;###################################################################################################
;Create a instance of a layered window for the main gui
global CDisplay := Layered_Window_SetUp( 4 , A_ScreenWidth - 250 , 50 , 200 , 200 , 1 , "-Caption -DPIScale +ToolWindow +AlwaysOnTop" )
;Add a text control to act as a trigger for moving the window
Gui, 1: Add , Text , x0 y0 w200 h40 gMove_Window hwndForumTestHwnd
;Add a text control to act as a trigger for getting a color from the screen
Gui, 1: Add , Text , x45 y75 w110 h30 gGetColor
;Add a text control to act as a trigger for running the setting menu.
Gui, 1: Add , Text , x45 y103 w110 h30 gGetColor
;Add a text control to act as a trigger for taking a screenshot.
Gui, 1: Add , Text , x45 y135 w20 h20 gCreate_Capture_Size_Window
;Add a text control to act as a trigger for displaying the screenshots saved in the scripts folder.
Gui, 1: Add , Text , x75 y135 w20 h20 gShowPics
;Add a text control to act as a trigger for launching the 3rd function.
Gui, 1: Add , Text , x105 y135 w20 h20 gTemp1
;Add a text control to act as a trigger for launching the 4th function.
Gui, 1: Add , Text , x135 y135 w20 h20 gTemp2
;Draw the main windows background to the graphics.
Gdip_DrawImage( CDisplay.G , HB_BITMAP_MAKER() , 0 , 0 , CDisplay.w , CDisplay.h )
;Draw the Get Color button to the graphics.
Gdip_DrawImage( CDisplay.G , _Create_Default_Bitmap( 110 , 30 , "0xFF2D2F33" , "0xFF000000" , "0xFF3399FF" , "Get Color" , "12 Bold" , "0" , "Segoe UI" ) , 45 , 75 , 110 , 30 )
;Draw the Settings button to the graphics.
Gdip_DrawImage( CDisplay.G , _Create_Default_Bitmap( 110 , 30 , "0xFF2D2F33" , "0xFF000000" , "0xFF3399FF" , "Settings" , "12 Bold" , "0" , "Segoe UI" ) , 45 , 103 , 110 , 30 )
;Draw the graphics to the main window and set its default size and positioning.
UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc , CDisplay.x , CDisplay.y , CDisplay.w , CDisplay.h )
;Create a new brush
Brush := Gdip_BrushCreateSolid( "0xFF2D2F33" )
;Use the brush to cover the section of the graphics that will contain the text displaying the color.
Gdip_FillRectangle( CDisplay.G , Brush , 45 , 55 , 110 , 20 )
;Delete the brush.
Gdip_DeleteBrush( Brush )
;Add text to the graphics containing the color.
Gdip_TextToGraphics( CDisplay.G , OutColor := "0x3399ff" , "s12 Bold Center vCenter cFF3399FF x45 y50" , "Segoe UI" , 110 , 30 )
;Show the window hidden to set its default width and height.
Gui, 1: Show , hide w200 h200 , Gadget
;Show the window with its tabbed size.
Gui, 1: Show , % "h" 45
;Draw the graphics to the main window.
UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )
;###################################################################################################
;Added Jan 7th, 2020
;Update the main window with the saved colors
Loop, 4 {
OutColor := SavedColors[A_Index]
ChangeColor(A_Index)
}
;###################################################################################################
;Set a timer that will keep the main window on top of all other windows
SetTimer, Always , 2000
;End of the Auto-Execute Section.
return
;*************************************************************************************************************************
;Subroutine: GuiClose
;Triggered by press the close button on a gui or by pressing the Hotkey Escape
;Once called the script will exit.
;*************************************************************************************************************************
GuiClose:
;~ *Esc::
ExitApp
;*************************************************************************************************************************
;Function: Move_Window
;Called whenever the trigger text control at the top of the main gui or the sides of the Display Window are clicked.
;Allows the window to be moved around. Thinking about having the Display window follow the main window if it hasn't been moved yet.
;*************************************************************************************************************************
Move_Window(){
;Post WM_NCLBUTTONDOWN message to allow the active window to be dragged to a new location
PostMessage, 0xA1 , 2
;Redraw the graphics
UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )
}
;*************************************************************************************************************************
;Function: Temp1
;A placeholder function for button 3
;*************************************************************************************************************************
Temp1(){
if(GetKeyState("Shift")){
;If Shift is being held
;Change the color of this button on the main gui to the one currently in the main color display.
ChangeColor(3)
;Write the new list of saved colors to file.
WriteColors(3)
;exit this thread
return
}
}
;*************************************************************************************************************************
;Function: Temp2
;A placeholder function for button 4
;*************************************************************************************************************************
Temp2(){
if(GetKeyState("Shift")){
;If Shift is being held
;Change the color of this button on the main gui to the one currently in the main color display.
ChangeColor(4)
;Write the new list of saved colors to file.
WriteColors(4)
;exit this thread
return
}
}
;*************************************************************************************************************************
;Function: Always
;A timed function that puts the main gui on top of any other window ( even ones that are using the AlwaysOnTop setting )
;*************************************************************************************************************************
Always(){
;Draw the window on top of all other windows
Gui,1:Show,NA
}
;*************************************************************************************************************************
;Function: WriteColors
;This function is called every time one of the four saved colors is changed.
;Deletes the old file and then writes a new one with the updated saved colors.
;*************************************************************************************************************************
WriteColors(Position){
SavedColors[Position] := OutColor
FileDelete,%A_ScriptDir%\Saved Colors.txt
Loop, 4 {
FileAppend,% SavedColors[A_Index]",",%A_ScriptDir%\Saved Colors.txt
}
}
;*************************************************************************************************************************
;Function: GuiContextMenu
;Triggered by right clicking the main gui.
;Toggles between showing the main window at full size or tab sized.
;*************************************************************************************************************************
GuiContextMenu(){
;Create a static variable to maintain the value of the toggle state
static Tog := 1
if( Tog := !Tog )
;test if the inverted value is true while also setting it as the value
;Show the main window with the tab sized height
Gui , 1: Show , % "h" 45
else {
;if the value of the toggle is false
;Show the full sized main window
Gui, 1: Show , % "h" 200
}
;Redraw the graphics
UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )
}
;*************************************************************************************************************************
;Function: ShowPics
;Triggered by pressing the Second Square on the main gui.
;This function is a hub for a number of actions that can happen depending on the keys that are being pressed when the button is pressed.
;Shows a timed tooltip displaying the main function of this button.
;*************************************************************************************************************************
ShowPics(){
;Set the value for the message that contains the name of the main operation for this button
Message := "View ScreenShots"
;Set a timer to show the tooltip containing the message quickly following the mouse until the other timer turns it off.
SetTimer, TooltipFollow , 30
;Set a one time timer to turn off the tooltip timers
SetTimer, TooltipOff , -900
if( GetKeyState( "Shift" ) )
;if the key shift is being held down when the button is pressed
;Call the function to change the color on the button for this function ( Button 2 ), return and then write the new colors
return ChangeColor( 2 ) , WriteColors( 2 )
else if( GetKeyState( "ctrl" ) )
;If Control is being held when the button is pressed.
;No action currently assigned for this key... yet.
return
;Get the x and y positions of the main gui to be used for the positioning of the Display Window.
WingetPos, tx , ty ,,, % "ahk_ID " CDisplay.Hwnd
;Call the function to create the Display Window, passing it the x and y coords.
Create_Display_Window( tx , ty + 190 )
}
;*************************************************************************************************************************
;Function: TooltipFollow
;A timed function that displays a tooltip at the current cursor location rapidly.
;This timer is terminated by another timer.
;*************************************************************************************************************************
TooltipFollow(){
;Set the owner of the tooltip to the main gui so that the tooltip will always show above all windows.
Gui, 1: +OwnDialogs
;Display the tooltip containing the message.
Tooltip, % Message
}
;*************************************************************************************************************************
;Function: TooltipOff
;A timed function that displays a tooltip at the current cursor location rapidly.
;This timer is terminated by another timer.
;*************************************************************************************************************************
TooltipOff(){
;Turn off the timer for the message tooltip.
SetTimer, TooltipFollow , Off
;Turn off any active tooltips
ToolTip,
}
;*************************************************************************************************************************
;Function: Create_Display_Window
;Create a small window that displays the screenshots taken with this device.
;*************************************************************************************************************************
Create_Display_Window( tx := "" , ty := "" ){
;Select the object
SelectObject( ShowWin.hdc , ShowWin.obm )
;Delete the object
DeleteObject( ShowWin.hbm )
;Delete the device context
DeleteDC( ShowWin.hdc )
;Delete the graphics
Gdip_deleteGraphics( ShowWin.G )
;Destroy the Display Window if it already exists. I could just use the "New" option, but destroying the window is more fun.
Gui,5:Destroy
;Create a new layered window.
ShowWin := Layered_Window_SetUp( 3 , 0 , 0 , 970 , 220 , "5" , "+AlwaysOnTop -DPIScale -Caption +Owner1" )
;Draw the graphics to the Display Window and set its default size and positioning.
UpdateLayeredWindow( ShowWin.hwnd , ShowWin.hdc , ShowWin.x , ShowWin.y , ShowWin.w , ShowWin.h )
;Draw the background onto the graphics.
Gdip_DrawImage(ShowWin.G, DW := DisplayWindow(), 0, 0, ShowWin.w, ShowWin.h)
;Delete the Background bitmap.
Gdip_DisposeImage(DW)
;Add a text control to act as a trigger for moving this window.
Gui,5:Add,Text,x0 y0 w43 h220 gMove_Window
;Add a text control to act as a trigger for moving this window.
Gui,5:Add,Text,x927 y0 w43 h220 gMove_Window
;Add a text control to act as a trigger for closing this window.
Gui,5:Add,Text,x904 y40 w20 h110 g5GuiClose
;Add a text control to act as a trigger for moving forward in the image list.
Gui,5:Add,Text,x691 y176 w112 h19 gMoveForward
;Add a text control to act as a trigger for moving Backward in the image list.
Gui,5:Add,Text,x181 y176 w112 h19 gMoveBackward
;Add a text control to act as a trigger for refreshing the image list and updating the Dispaly Window.
Gui,5:Add,Text,x47 y42 w16 h106 gRefresh
;Add a text control to act as a trigger for the center frame of the Display Window.
Gui,5:Add,Text,x411 y21 w150 h150 hwndFrame1 gGetInfo1
;Add a text control to act as a trigger for moving Backward in the image list. (this may change, currently attached to one of the frames)
Gui,5:Add,Text,x241 y21 w150 h150 hwndFrame2 gMoveBackward
;Add a text control to act as a trigger for moving Backward in the image list. (this may change, currently attached to one of the frames)
Gui,5:Add,Text,x71 y21 w150 h150 hwndFrame3 gMoveBackward
;Add a text control to act as a trigger for moving Forward in the image list. (this may change, currently attached to one of the frames)
Gui,5:Add,Text,x581 y21 w150 h150 hwndFrame4 gMoveforward
;Add a text control to act as a trigger for moving Forward in the image list. (this may change, currently attached to one of the frames)
Gui,5:Add,Text,x751 y21 w150 h150 hwndFrame5 gMoveforward
;Get the size of the monitor that the cursor is currently in.
;This is used in position the Display Window when it is first created.
;Purpose is to have the Dispaly Window line up with the left edge of the main gui when possible or line up with the right side of the monitor when not.
temp:=Monitors.Get_New_Window_Position(Monitors.Get_Current_Monitor(),0,0,2,2)
;Get the current position of the main gui
WinGetPos , tX, tY,,, % "ahk_ID " CDisplay.hwnd
;Calculate if the Dispaly Window can be popped up at the same x position as the main gui, or if it needs to line up along the right side of the monitor
(tx+970>temp.x)?(ntx := temp.x - 970 ):(ntx := tx)
;Calculate if the Display Window can sit below the main gui, or if it needs to be placed above it.
(ty+200+220+10 > temp.y)?(nty := (ty - 220) -10 ):(nty := ty + 200 + 10)
;Show the Dispaly Window at the calculated position
Gui, 5: Show , % "x" ntx " y" nty " w970 h220 NA"
;Draw the graphics onto the Dispaly Window
UpdateLayeredWindow( ShowWin.hwnd , ShowWin.hdc )
;Create a new List of all the images in the target folder
ImageList1 := "" , ImageList1 := Get_File_List()
;Draw a group of the images from the list to the Display Window Frames. (Based around the current value of "Index")
UpdateWheel( Index , ImageList1 )
;Start a timer to watch for the cursor moving over the center frame. This will cause a small window to pop up above the Display Window containing the Indexed Image
SetTimer, ImageZoom , 300
}
;*************************************************************************************************************************
;Function: UpdateWheel
;Update the Display Window with the images found in the screenshot folder
;*************************************************************************************************************************
UpdateWheel( Index , ImageList1 ){
if( !ImageList1 )
;If there are no images in the folder
;exit the function
Return
;Set an array with the positions for images to be placed.
Positions := [ { x : 411 , y: 21 } , { x : 241 , y: 21 } , { x : 71 , y: 21 } , { x : 581 , y: 21 } , { x : 751 , y: 21 } ]
;Create some variable / arrays to help in determining which image needs to get placed and what size it should be.
Images := [] , PB := [] , caseit := [ 0 , -1 , -2 , +1 , +2 ] , Set := [ 150 , 70 , 70 , 70 , 70 ]
Loop, 5 {
;Loop once for every frame in the Display Window.
;Create a new brush, use it to redraw over each frame to remove any previous images, then delete the brush.
Brush := Gdip_BrushCreateSolid( "0xFF000000" ) , Gdip_FillRectangle( ShowWin.G , Brush , Positions[A_Index].X , Positions[A_Index].Y , 150 , 150 ) , Gdip_DeleteBrush( Brush )
;Create bitmaps of the images that need to be dispalyed.
PB[ A_Index ] := Gdip_CreateBitmapFromFile( ImageList1[Index + caseit[ A_Index ] ] )
;Resize each of the bitmaps to fit within the allotted space while maintaining the same aspect ratio
Centering := ResizeIt( PB[ A_Index ] , Width , Height , Set[ A_Index ] )
;Check if there is a bitmap for the current index, and if there is, Draw it to the graphics
( PB[ A_Index ] ) ? ( Gdip_DrawImage( ShowWin.G , PB[ A_Index ] , Positions[ A_Index ].X , Positions[ A_Index ].Y , Width , Height ) )
;Delete the bitmaps to free up the memory
Gdip_DisposeImage( PB[ A_Index ] )
}
;Create a new brush, paint over the area that contains the "Index" text, then delete the brush.
Brush := Gdip_BrushCreateSolid( "0xff333333" ),Gdip_FillRectangle( ShowWin.G , Brush , 810 , 174 , 80 , 20 ),Gdip_DeleteBrush( Brush )
;Create a new brush, paint the "Index" number, then delete the brush (Bottom layer of the text).
Brush := Gdip_BrushCreateSolid( "0xff000000" ),Gdip_TextToGraphics( ShowWin.G , Index , "s18 Center vCenter Bold c" Brush " x800 y175" , "Segoe UI" , 100 , 20 ),Gdip_DeleteBrush( Brush )
;Create a new brush, paint the "Index" number, then delete the brush (Top layer of the text).
Brush := Gdip_BrushCreateSolid( "0xff3399FF" ),Gdip_TextToGraphics( ShowWin.G , Index , "s18 Center vCenter Bold c" Brush " x801 y176" , "Segoe UI" , 100 , 20 ),Gdip_DeleteBrush( Brush )
;Draw the graphics to the Display Window.
UpdateLayeredWindow( ShowWin.hwnd , ShowWin.hdc )
}
;*************************************************************************************************************************
;Function: ImageZoom
;A timed routine that checks if the cursor is over the center image display frame in the Display Window ("ShowWin")
;If it is, create a small window with a larger example of the center image ("Index")
;*************************************************************************************************************************
ImageZoom(){
;create a static control variable to help with flow of control
static ActiveFrame
;get the hwnd of the control under the cursor
MouseGetPos,,,, ctrl, 2
if( !ActiveFrame && ctrl = Frame1 ) {
;if the image display is not already active and if the control under the cursor is the center frame panel
;create a display window containing the image from the center frame ("Index")
;create a bitmap of the image (.png) saved in the folder
pBit := Gdip_CreateBitmapFromFile( ImageList1[ Index ] )
;resize and scale the image to its new size
ResizeIt( pBit, Width, Height, 400 )
;Create a new floating window directly above the center frame containing the selected image
CreateZoomWindow( pBit, Width, Height )
;Once drawn to the graphics, the bitmap can get deleted.
Gdip_DisposeImage(pBit)
;Set control variable to 1 so this part gets skipped until the control under the cursor is no longer the correct one.
ActiveFrame := 1
}else if( ActiveFrame && ctrl != Frame1 ){
;if the image display is already active and if the control under the cursor is not the center frame panel
;Destroy the zoom window and swap the value of the control variable
;Destroy the Zoom Window
Gui,6:Destroy
;Set the control variable back to 0 so that the routine can begin waiting for the cursor can be back over the center frame again
ActiveFrame := 0
}
}
;*************************************************************************************************************************
;Function: CreateZoomWindow
; Create a window containing the selected image and display it directly above the certer frame of the Display Window ("ShowWin")
; Takes: pointer to the selected Bitmap, and the resized Width and Height.
;*************************************************************************************************************************
CreateZoomWindow( pBit, Width, Height ){
;if this window already exists, destory it ( destroying things is fun! ).
Gui, 6: Destroy
;Select the object
SelectObject( ZoomWindow.hdc,ZoomWindow.obm)
;Delete the object
DeleteObject(ZoomWindow.hbm)
;Delete the device context
DeleteDC(ZoomWindow.hdc)
;Delete the graphics
Gdip_deleteGraphics(ZoomWindow.G)
;Create a new Layered window to display the image on
ZoomWindow := Layered_Window_SetUp( 2 , 0 , 0 , Width , Height , "6" , "+AlwaysOnTop -DPIScale -Caption +Owner5" )
;Create a brush for the background of the Layered Window
Brush := Gdip_CreateLineBrushFromRect( 0 , 0 , Width , Height , "0xFF777777" , "0xFF000000" , 1 , 1 )
;Paint the background of the window
Gdip_FillRectangle( ZoomWindow.G , Brush , 0 , 0 , Width , Height )
;Delete the brush to free up the memory
Gdip_DeleteBrush( Brush )
;Draw the bitmap of the selected image to onto the Graphics for the Layered Window
Gdip_DrawImage(ZoomWindow.G, pBit, 1, 1, ZoomWindow.w-2, ZoomWindow.h-2)
;~ Gdip_DisposeImage(pBit)
;Update (Redraw) the Layered Window with the newly changed Graphics
UpdateLayeredWindow(ZoomWindow.hwnd, ZoomWindow.hdc, ZoomWindow.x, ZoomWindow.y, ZoomWindow.w, ZoomWindow.h)
;Get the position of the Dispaly Window
WinGetPos,tx,ty,,,% "ahk_ID " ShowWin.Hwnd
;Display the ZoomWindow offset from the Display Window
Gui,6:Show,% "x" ( tx + 411 + 75 - Width // 2 ) " y" ( ty + 21 - height - 20 ) " w" Width " h" Height " NA"
}
;*************************************************************************************************************************
;Function: ResizeIt
; Get the dimensions from a bitmap and then resize it so that the scale is maintained but the size is adjusted to fit in a defined space
; Takes: Pointer to a bitmap, defined Width and Height variable, The size of the defined area.
;*************************************************************************************************************************
ResizeIt( PB , ByRef tWidth , ByRef tHeight , InputValue ){
;Get the Width and Height of the bitmap.
Gdip_GetDimensions( PB , tWidth , tHeight )
if( tWidth > InputValue && tWidth >= tHeight )
;If the width is greater than the defined area and the width is greater than or equal to the height
;Set the scale ratio to be the height divided by the width, set the width to be the max size, set the height to be the scaled value.
Ratio := tHeight / tWidth , tWidth := InputValue , tHeight := InputValue * Ratio
else if( tHeight > InputValue && tHeight >= tWidth )
;If the height is greater than the defined area and the height is greater than or equal to the width
;Set the scale ratio to be the width divided by the height, set the height to be the max size, set the width to be the scaled value.
Ratio := tWidth / tHeight , tHeight := InputValue , tWidth := InputValue * Ratio
else if( tWidth > InputValue && tWidth <= tHeight )
;If the width is greater than the defined area and the Height is greater than or equal to the Width
;Set the scale ratio to be the width divided by the height, set the height to be the max size, set the width to be the scaled value.
Ratio := tWidth / tHeight , tHeight := InputValue , tWidth := InputValue * Ratio
}
;*************************************************************************************************************************
;Function: Refresh
; Creates a new list of the images in the target folder and then displays the newly updated list in the display window.
;*************************************************************************************************************************
Refresh(){
;Create a list of all the full paths of images in a folder
ImageList1 := "" , ImageList1 := Get_File_List()
;Draw the images on to the display window with the selected image in the center frame
UpdateWheel( Index , ImageList1 )
}
;*************************************************************************************************************************
;Function: GetInfo1
; This is a hub for a number of actions that are connected to the center frame of the Display Window.
; Depending on the keys being pressed, different actions will occur.
;*************************************************************************************************************************
GetInfo1(){
if( GetKeyState( "ctrl" ) && GetKeyState( "Shift" ) )
;If both the shift and control keys are being pressed when the frame is clicked
;Remove the image from the Display Window and delete the image file in the target folder.
RemoveImage( Index )
else if( GetKeyState( "Shift" ) )
;If only the shift key is being pressed when the center frame is click
Try
;Try to do a action, if it fails, do so silently
;Run the center image in windows image viewer
Run, % ImageList1[ Index ]
else
;If no keys are being pressed.
;Put the full path of the image into the clipboard.
Clipboard := ImageList1[ Index ]
}
;*************************************************************************************************************************
;Function: RemoveImage
;Delete the selected image file from the screenshot folder and then refresh the Dispaly Window and update the image list.
;Takes: The current index for the image in the center frame of the Display Window
;*************************************************************************************************************************
RemoveImage( inVal ){
;Delete the selected file
FileDelete, % ImageList1[ inVal ]
;Refresh the Display Window
Refresh()
}
;*************************************************************************************************************************
;Subroutine: MoveForward
;Triggered by pressing either the forward arrow button or by clicking on one of the frames to the right of the center frame in the Display Window
;*************************************************************************************************************************
MoveForward:
if( GetKeyState( "Shift" ) ){
;If shift is being held when the button/buttons are pressed.
;Check to see if the length of the image list is greater than the current index + 10, if it is, move forward 10, else set the index to the last position.
( Index + 10 > ImageList1.Length() ) ? ( Index := ImageList1.Length() ) : ( Index += 10 )
;Draw the newly selected batch of 5 images to the Display Window.
UpdateWheel( Index , ImageList1 )
;Exit thread
return
}
if( Index >= ImageList1.Length() )
;If the current value of "Index" is already at the end of the list.
;Exit thread
return
;Add one to the value of "Index" and then draw the newly selected batch of 5 images to the Display Window.
UpdateWheel( Index += 1 , ImageList1 )
return
;*************************************************************************************************************************
;Subroutine: MoveBackward
;Triggered by pressing either the back arrow button or by clicking on one of the frames to the left of the center frame in the Display Window
;*************************************************************************************************************************
MoveBackward:
if( GetKeyState( "Shift" ) ){
;If shift is being held when the button/buttons are pressed.
;Check to see if subtracting 10 from the current value of "Index" will be less than 1, if it is, set "Index" to 1, else set it to the current value - 10.
( Index - 10 < 1 ) ? ( Index := 1 ) : ( Index -= 10 )
;Draw the newly selected batch of 5 images to the Display Window.
UpdateWheel( Index , ImageList1 )
;Exit thread
return
}
if( Index - 1 <= 0 )
;If the value of "Index" is already at 1 or less
;Exit thread
return
;Subtract one from the value of "Index" and then draw the newly selected batch of 5 images to the Display Window.
UpdateWheel( Index -= 1 , ImageList1 )
return
;*************************************************************************************************************************
;Function: Get_File_List
;Creates a list containing the full path to all .pngs in the screenshot folder
;*************************************************************************************************************************
Get_File_List(){
;Create a array to hold the file paths, set the loop index to 0
Full_Path := [] , Index2 := 0
Loop, %A_ScriptDir%\Screen Shots\*.png
;Loop through the contents of the screenshot folder and sort for the ones with a .png extention.
;Add the full path for each found file with the .png extention to the array.
Full_Path[ ++Index2 ] := A_LoopFileFullPath
;return the array to the caller.
return Full_Path
}
;*************************************************************************************************************************
;Subroutine/s: 5GuiClose - 5GuiContextMenu
;Triggered by press the close button on the Display Window or by right clicking the window
;Once called the Display Window will be closed and related timers are turned off.
;*************************************************************************************************************************
5GuiClose:
5GuiContextMenu:
;Select the object
SelectObject( ShowWin.hdc,ShowWin.obm)
;Delete the object
DeleteObject(ShowWin.hbm)
;Delete the device context
DeleteDC(ShowWin.hdc)
;Delete the graphics
Gdip_deleteGraphics(ShowWin.G)
;Destroy the Display Window
Gui, 5: Destroy
return
;*************************************************************************************************************************
;Function: Create_Capture_Size_Window
;Create a layered window that will be used to draw the cross lines for setting the capture area for the screenshot.
;*************************************************************************************************************************
Create_Capture_Size_Window(){
;Create a static variable that is used to check if this is the first time this function is being called. Default = null / 0 / ""
static ft
;Set the main gui as the owner of the any tooltips so that they stay on top of all other windows
Gui, 1: +OwnDialogs
;Display a tooltip containing a message about what this button does ( its main function ).
Tooltip, % Message := "Take ScreenShot"
;Start a timer that once expired will turn off the other timer
SetTimer, TooltipOff , -1800
;Start a timer that will repeatedly display the message under the cursor
SetTimer, TooltipFollow , 30
if( GetKeyState( "Shift" ) ){
;if the Shift key is being held when the button is pressed.
;Change the color of this button on the main gui to the one currently in the main color display.
ChangeColor( 1 )
;Write the new list of saved colors to file.
WriteColors( 1 )
;Exit thread
return
}
;If this window already exists, destroy it.
Gui, 2: Destroy
;Create a new Layered window to display the capture area lines
CapWin := Layered_Window_SetUp( 3 , 0 , 0 , A_ScreenWidth , A_ScreenHeight , "2" , "+AlwaysOnTop -DPIScale -Caption +Owner1" )
if( !ft )
;If this is the first time running this function
;Set the static variable to 1 so that this only happens the first time this function is called.
;Create a timer that moves the drawing area to cover the current monitor.
Monitors.Set_Window_Move_Timer( GUINAME := 2 , GUIHWND := CapWin.hwnd , TCount := 300 , xpOff := 0 , ypOff := 0 , xr := 1 , yr := 1 , Fill_Screen := 1 ) , ft := 1
else
;If this isn't the first time.
;Turn on the timer for moving the drawing area to cover the current monitor
Monitors.Window_Move_Obj.GUIHWND := CapWin.hwnd , Monitors.Turn_On_Window_Move_Timer()
;Show the window
Gui, 2: Show
;Set the control variables used in the flow of the drawing function.
CapActive := 1 , SP := 0 , OB := 0
;Set a timer to be used for drawing the lines of the capture area.
SetTimer, Set_Positions , 10
}
;*************************************************************************************************************************
;Function: ChangeColor
;Changes the color of one of the 4 colored buttons on the main gui
;Takes: The position of the button being changed
;*************************************************************************************************************************
ChangeColor( Value ){
;Create a local array with the x position of the colored buttons.
local tempArr := [ 48 , 78 , 108 , 138 ]
;Create a brush, and then paint the button with the color in the main color display, then delete the brush.
Brush := Gdip_BrushCreateSolid( "0xFF" SubStr( OutColor , 3 ) ) , Gdip_FillRectangle( CDisplay.G , Brush , tempArr[ Value ] , 139 , 14 , 12 ) , Gdip_DeleteBrush( Brush )
;Create a line brush ( gradient brush ).
Brush := Gdip_CreateLineBrushFromRect( tempArr[ Value ] , 139 , 14 , 12 , "0xFF000000" , "0xFF777777" , 1 , 1 )
;Create a pen from the brush.
Pen := Gdip_CreatePenFromBrush( Brush , 1 )
;Delete the brush.
Gdip_DeleteBrush( Brush )
;Use the pen to draw a border around the new color.
Gdip_DrawRectangle( CDisplay.G , Pen , tempArr[ Value ] , 139 , 14 , 12 )
;Delete the pen.
Gdip_DeletePen( Pen )
;Draw the graphics to the window.
UpdateLayeredWindow( CDisplay.hwnd , CDisplay.hdc )
}
;*************************************************************************************************************************
;Function: Set_Positions
;A timed function that draws lines onto the screen.
;Used for setting the capture area of a screenshot.
;*************************************************************************************************************************
Set_Positions(){
;Set the coordmode used for tarcking the mouse position to be relative to the active window.
Coordmode, Mouse , Window
;Activate the capture window.
WinActivate,% "ahk_ID " CapWin.Hwnd
;Clear the graphics so that they can be redrawn in their new positions.
Gdip_GraphicsClear(CapWin.g)
;Get the current cursor position.
MouseGetPos, tx , ty
if(SP=0){
;If setting the first position of the capture area.