Repository navigation
Expand file tree
/
Copy pathExample3.ahk
More file actions
426 lines (340 loc) · 10.9 KB
/
Copy pathExample3.ahk
File metadata and controls
426 lines (340 loc) · 10.9 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
#SingleInstance,Off
#Include LibCon.ahk ;Needed
#NoTrayIcon ;Suggested
SetBatchLines,-1 ;suggested
LibConDebug:=1 ;let the user know about errors
StartConsole() ;Shows the Console (new/seperate) and 'initializes' the library
AutoTrim, Off ;needed for this example
SetWinDelay,0 ;optional
;<<<<<<<< HEADER END >>>>>>>>>
if LibConVersion < 1.0.4.2
{
puts("sorry... LibCon v1.0.4.2 and Up is required to run this script.")
Pause(0)
ExitApp
}
;Create self-referrer
self:="ahk_pid " DllCall("GetCurrentProcessId") ;or use: ahk_id with getConsoleHandle()
;Save the original console size
GetConsoleSize(ocW,ocH)
;Save the original window size
WinGetPos,,,owW,owH,%self%
;Set the text (foreground) color to yellow on black
setcolor(Yellow,0)
;save the color
oc:=getcolor()
;Save original cursor settings
getconsoleCursorInfo(oCurSz,oCurSw)
;Save the original console "mode"
getConsoleMode(oCMode)
;Save Font size
fH:=GetFontHeight()
fW:=GetFontWidth()
;set vars
cH:=31
cW:=80
title:="Untitled GUI"
INT_MAX:=32768
lastcolor_at_cursor:=-1
print_n:=0
;set gui colors -- Note: Blue, Gray, Black, DarkGray are defined in LibCon.ahk
consoleGUI.BgColor:=Blue
consoleGUI.FgColor:=Gray
consoleGUI.cFgColor:=Black ;ClientArea
consoleGUI.cBgColor:=DarkGray ;ClientArea
;print start/intro message
puts( "Testing ConsoleWindow_FakeGUI...`n`n")
puts( "`t Window Specifications")
puts( "`t_______________________________")
putsf( "`t Title: ""%s""",title)
putsf("`t Colums: %s",cW)
putsf("`t Rows: %s",cH)
puts( "`t_______________________________`n")
puts( "`nNOTICE: The Loading Message is fake...")
newline()
;Wait for key press
pause()
KeyWait Space ;is a used 'key' / blocked for later
;enable selection "mode"
SetConsoleMode((0x0040|0x0080))
;Hide the cursor
setconsoleCursorInfo(oCurSz,0)
;Clear the screen, prepare for draw routine
;and set cursor to (0,0)
clearscreen()
;Set the console size
;and height+1 to correctly draw later
setconsolesize(cW,cH+1)
;Correctly size the window accordingly (max the window size)
WinMove,%self%,,,,%INT_MAX%,%INT_MAX%
;draw the gui (background)
consoleGUI.Draw(title)
;set cursor back to (0,0)
setConsoleCursorPos(0,0)
;Set the console size
;now to correct, after gui draw routine
setconsolesize(cW,cH)
;Correctly size the window accordingly (max the window size)
WinMove,%self%,,,,%INT_MAX%,%INT_MAX%
;draw the "tip!" message
gosub print_tip
;Load Pages into memory // Load Text into vars
gosub Load_txt
;Start Draw Update routine
update_draw:
;Determine which page to print (print_n is print number)
if (print_n==1)
consoleGUI.print_page("The Zlib License",ZLIB,4)
else if (print_n==2)
consoleGUI.print_page("Lorem Ipsum",LOREMIPSUM,6)
else
consoleGUI.print_page("The MIT License",MIT,4)
;switch the print number for next page switch // the "page switcher"
print_n:=(print_n==1)?2:(print_n==2)?3:1
;set the color for the "status bar"
setcolor(Black,consoleGUI.FgColor)
;the Coordmode of the mouse relative to the "console gui" area
CoordMode,Mouse,Client
;Draw/Prepare the status bar at the bottom of the gui
setConsoleCursorPos(24,cH-2)
printf(" Size: [%s,%s] ",cW,cH)
setConsoleCursorPos(cW-strlen(quit_msg:=" Press Esc to quit ")-1,cH-2)
print(quit_msg)
setConsoleCursorPos(1,cH-2)
print(" Mouse coords: ")
;Redraw to correct graphic issues, if any
WinSet, Redraw,,%self%
;Start internal draw loop
Loop {
Sleep 10 ;avoid CPU overload
;make the loop take action only when the window is active
if (!WinActive(self))
continue
;get the mouse position
MouseGetPos,mx,my
;Set the quit "hotkey"
if (GetKeyState("Esc","P"))
break
;set the change page "hotkey"
if (GetKeyState("Space","P"))
{
KeyWait Space
;Draw next page
goto update_draw
}
;if the mouse moved, redraw the cursor and mouse position in status bar
if ( (mx!=lmx) || (my!=lmy) )
{
;set cursor to mouse coords (draw area) in statusbar
setConsoleCursorPos(16,cH-2)
;Calculate mouse position, relative to the console 'chars'
_mx:=(mx//fw)
_my:=(my//fh)
_mx:=(_mx>cW-1)?cW-1:((_mx<0)?0:_mx) ;-1 is used, because the console's
_my:=(_my>cH-1)?cH-1:((_my<0)?0:_my) ;... cursor position origin is (0,0)
;Draw The cursor
;if the cursor position and colors (the vars) are valid
;Erase last cursor drawn at position (essentially reset to original colors at last position)
if ( (_lmx!="") && (_lmy!="") && (lastcolor_at_cursor>=0) )
SetColorPos(lastcolor_at_cursor,_lmx,_lmy) ;FillConsoleOutputAttribute(lastcolor_at_cursor,1,_lmx,_lmy)
;save the current position's colors for reset later, before drawing new cursor
lastcolor_at_cursor:=GetColorPos(_mx,_my) ;ReadConsoleOutputAttribute(lastcolor_at_cursor,1,_mx,_my)
;set/draw the cursor
SetColorPos((Yellow*16)+Black,_mx,_my) ;FillConsoleOutputAttribute((Yellow*16)+Black,1,_mx,_my)
;Print mouse coords in "statusbar"
printf("[%s,%s] ",_mx,_my)
;save mouse info for later
lmx:=mx
lmy:=my
_lmx:=_mx
_lmy:=_my
;Redraw to correct graphic issues, if any
WinSet, Redraw,,%self%
}
}
;Quit key was pressed. Reset everything.
;Reset original colors
setcolor(oc,0)
;Clear the screen
clearscreen()
;Reset console size
setConsoleSize(ocW,ocH)
;Reset window size
WinMove,%self%,,,,%owW%,%owH%
;Reset cursor visibility
setconsoleCursorInfo(oCurSz,oCurSw)
;Reset console mode
getConsoleMode(oCMode)
;print end/quit message
puts("Execution over.")
;Wait for keypress
Pause()
;Exit program
ExitApp
return
print_tip:
;save the color, for reset later
before_tip_color:=getcolor()
;Set the color for the tip message
setcolor(Black,DarkGreen)
;Draw the tip in the top right corner
setConsoleCursorPos(cW-strlen(tip_msg:=" TIP! : Press Space for Next Page ")-1,1)
printf(tip_msg)
setConsoleCursorPos(cW-strlen(tip_msg:=" LClick=Select RClick=Copy ")-1,2)
printf(tip_msg)
;reset color to what was before the tip
setcolor(before_tip_color,0)
return
Load_txt:
;Initialize vars with content
MIT =
(
The MIT License (MIT)
Copyright (c) Joe DF (joedf@users.sourceforge.net)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
)
ZLIB =
(
The zlib/libpng License (Zlib)
Copyright (c) <year> <copyright holders>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
)
LOREMIPSUM =
(
%A_space% - Lorem Ipsum -
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet,
%A_space% consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and
%A_space% wants to have it, simply because it is pain..."
The standard Lorem Ipsum passage, used since the 1500s
" Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum. "
%A_space% http://www.lipsum.com/ (November, 2013)
)
return
;consoleGUI functions
class consoleGUI {
;Gui colors
static BgColor
static FgColor
static cFgColor ;ClientArea
static cBgColor ;ClientArea
Draw(title="Untitled GUI") {
setConsoleCursorPos(0,0) ;bring back up
this.HorizontalBar(title)
Loop % ((GetConsoleClientHeight()//GetFontHeight())-3)
this.VerticalBar()
this.HorizontalBar("") ;bottom
}
print_page(title,text,y) {
;clean the gui in case it contains anything
this.print_clean()
offset_txt:=6
setConsoleCursorPos(0,0)
this.HorizontalBar(title)
setcolor(this.cFgColor,this.cBgColor)
setConsoleCursorPos(offset_txt,y)
Loop, parse, text, `n, `r
{
setConsoleCursorPos(offset_txt)
puts(A_LoopField)
}
}
print_clean(delay=250) {
setcolor(this.cFgColor,this.cBgColor)
setConsoleCursorPos(offset_txt:=6,4)
spaces:=" "
Loop, 22
{
;msgbox Line number %A_Index% is %A_LoopField%
setConsoleCursorPos(offset_txt)
if (A_Index==11)
puts(" Loading... ")
else
puts(spaces)
}
Sleep %delay%
setConsoleCursorPos(offset_txt,14)
puts(spaces)
}
HorizontalBar(Text="") {
if ((l:=StrLen(text))>0) {
l+=4, w:=((x:=getconsolewidth())-l)//2, z:=(u:="")
loop % w
u=%u%_
fs=%u%
fm=[ %text% ]
fe=%u%
f=%fs%%fm%%fe%
Loop % abs(x-StrLen(f))
z=%z%_
fe=%fe%%z%
oc:=getcolor()
setcolor(this.FgColor,this.BgColor)
print(fs)
setcolor(this.BgColor,this.FgColor)
print(fm)
setcolor(this.FgColor,this.BgColor)
print(fe)
setcolor(oc,0)
return
} else {
u:=""
loop % getconsolewidth()
u=%u%_
oc:=getcolor()
setcolor(this.FgColor,this.BgColor)
print(u)
setcolor(oc,0)
return
}
}
VerticalBar() {
x:=getconsolewidth()
oc:=getcolor()
setcolor(this.FgColor,this.BgColor)
print("|")
b:=""
Loop % (x-2)
b=%b%%A_space%
setcolor(this.cBgColor,this.cBgColor)
print(b)
setcolor(this.FgColor,this.BgColor)
print("|")
setcolor(oc,0)
}
}