-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuiWithOverlay.ahk
409 lines (347 loc) · 13 KB
/
GuiWithOverlay.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
#Requires AutoHotkey v2.0
#SingleInstance
#INCLUDE ..\
#INCLUDE WindowNotifyOverlay.ahk
#INCLUDE WindowNotifyOverlay_Icons.ahk
; #INCLUDE AutoXYWH_hashed.ahk ; v2 version of this library is broken
#MaxThreads 69
Main := Gui(" +Resize")
Main.AddText("xm ym w300 0x200", "Static Control")
Main.AddEdit("xm y+10 w300", "Edit Control")
Main.AddEdit("xm y+10 w300", "Edit Control + UpDown")
Main.AddUpDown()
Main.AddEdit("xm y+10 w300 r3", "Multi-Line Edit Control")
Main.AddDropDownList("xm y+10 w300 Choose1", ["DDL Control", "DDL 2", "DDL 3"])
Main.AddComboBox("xm y+10 w300 Choose1", ["CB Control", "CB 2", "CB 3"])
Main.AddCheckBox("xm y+10 w300", "CheckBox")
SGW := SysGet(SM_CXMENUCHECK := 71)
SGH := SysGet(SM_CYMENUCHECK := 72)
Main.AddCheckBox("xm y+10 Checked h" SGH " w" SGW)
Main.AddText("x+1 yp 0x200 h" SGH, "Fake Checkbox")
Main.AddCheckBox("xm y+10 w300 Check3 CheckedGray", "CheckBox CheckedGray")
Main.AddButton("xm y+10 w300", "Button")
.OnEvent("Click", (*) => MainOverlay.popupSimple("Time is " FormatTime(A_Now, "HH:mm:ss"),,"I"))
;.OnEvent("Click", (*) => InWindowNotify(Main,String(A_TickCount),"TITLE","ii alignBL d30"))
Main.AddRadio("xm y+10 w300 Group Checked", "DarkMode") ;.OnEvent("Click", ToggleTheme)
Main.AddRadio("xm y+10 w300", "LightMode") ; .OnEvent("Click", ToggleTheme)
mtab := Main.AddTab3("x+10 ym vTab",["List","Props","CSS","Test","Create"])
mtab.UseTab(1)
LV := Main.AddListView("w300 r10", ["LV 1", "LV 2", "LV 3"])
loop 11
LV.Add("", A_Index, A_Index, A_Index)
LB_Entries := Array()
; loop 11
; LB_Entries.Push("LB " A_Index)
global lb := Main.AddListBox("xp y+10 w300 r10", LB_Entries)
Main.OnEvent("Close", (*) => ExitApp())
Main.OnEvent("Size", Main_Size)
MainOverlay := WindowNotifyOverlay(Main)
MainOverlay.opacity := 240
; desktopHwnd := WinGetId("ahk_class Progman")
; yyy := WindowNotifyOverlay(desktopHwnd)
;pad := [
MainOverlay.Popup("padding1",,,,"TL").Show() ;,
MainOverlay.Popup("padding2",,,,"TL").Show()
;]
test := MainOverlay.Popup("HTML:TEST and a <a href='#asdf'>link</a>","TITLE","InformationOutline",,"TL")
.SetFont("italic","cursive","title")
.Show()
.OnEvent("LinkClick", (inst,e,el,*)=> MsgBox("link clicked!`n" el.href))
.OnEvent("Click", (inst,e,el,*)=> MsgBox("clicked!`n" el.id))
;.OnEvent("ContextMenu", (inst,e,el,*)=> MsgBox("Context menu?`n" el.id))
mtab.UseTab(2)
Main.AddText("w100 section", "Stacking order")
CtrlBind(Main.AddRadio("x+0 w100 vpropStackOrder","Start of stack"),
MainOverlay, "StackOrder", (v)=>v=0, (v)=>0)
CtrlBind(Main.AddRadio("x+0 w100","End of stack"),
MainOverlay, "StackOrder", (v)=>v=1, (v)=>1)
Main.AddText("xs y+m w100","Transparent colour")
CtrlBind(
Main.AddComboBox("x+0 w100 vpropTransColor",MapGetKeys(WindowNotifyOverlay.COLOR_MAP)),
MainOverlay, "TransColor"
)
Main.AddText("xs y+m w70","Opacity")
Main.AddText("x+0 w25 right 0x200 vopacityText", MainOverlay.opacity)
Main.AddSlider("x+5 w200 range0-255 AltSubmit TickInterval16 ToolTip",
MainOverlay.opacity)
.OnEvent("Change",opacitySlider_Change)
Main.AddText("xs y+m w100", "List of popups")
LVPopups := Main.AddListView("xs y+m w300 R10 vLVPopupList",
["ID","Pos","Title","Text"])
SetTimer PopupListViewUpdate.Bind(Main,MainOverlay,LVPopups), 250
PopupListViewUpdate(Main, MainOverlay, LV) {
If Main["Tab"].Value != 2
return
NewItems := ""
For ID, item in MainOverlay.Popups
NewItems .= ID "|"
KillItems := [], UpdateItems := Map()
Loop LV.GetCount()
If RegExMatch(NewItems, thisID := LV.GetText(A_Index),&m) {
NewItems := StrReplace(NewItems, thisID "|")
UpdateItems[thisID] := A_Index
}
Else
KillItems.InsertAt(1,A_Index)
For row in KillItems
LV.Delete(row)
For id, row in UpdateItems
LV.Modify(row,"Col2",
MainOverlay.Popups[id].Pos,
MainOverlay.Popups[id].SubElement["title"].innerText,
MainOverlay.Popups[id].SubElement["content"].innerText
)
For id in StrSplit(NewItems,"|")
if StrLen(id)
LV.Add(,ID,
MainOverlay.Popups[id].Pos,
MainOverlay.Popups[id].SubElement["title"].innerText,
MainOverlay.Popups[id].SubElement["content"].innerText
)
}
opacitySlider_Change(ctrl,*) {
MainOverlay.opacity := ctrl.Value
ctrl.gui["opacityText"].Value := ctrl.Value
}
mtab.UseTab(3)
global csspad
main.SetFont(,"Fira Code")
(csspad := Main.AddEdit("w300 r18 -wrap +hscroll +wantTab multi vCSS",))
.OnEvent("Change",CSS_Edit)
main.SetFont()
Main.AddButton("y+m vbtnCssPad", "Open in new window").OnEvent("Click",(*)=>CssGui.Show())
global CssGui := Gui("+Resize","CSS Pad")
CssGui.MarginX := CssGui.MarginY := 0
CssGui.SetFont(,"Fira Code")
CssGui.AddEdit("w640 r25 -wrap +hscroll +wantTab cC0C0C0 Background202020 vCSS",)
.OnEvent("Change",CSS_Edit)
CssGui.OnEvent("Size",CssGui_Size)
CssGui_Size(cssGui, *) {
cssGui.GetClientPos(,,&W,&H)
cssGui["CSS"].Move(,,W,H)
}
global cssEdit_semaphore := false
CSS_Edit(ctrl,*) {
global MainOverlay, cssEdit_semaphore
if cssEdit_semaphore
return
cssEdit_semaphore := True
if ctrl = csspad
CssGui["CSS"].Value := ctrl.value
else if ctrl = CssGui["CSS"]
csspad.Value := ctrl.value
MainOverlay.CSS := ctrl.Value
cssEdit_semaphore := false
}
CssGui["CSS"].Value := csspad.Value := WindowNotifyOverlay.DEFAULT_CSS
mtab.UseTab(4)
main.marginx := main.marginy := 4
main.SetFont("underline s8","Fira Code")
main.AddText("w150 section","Class")
main.AddText("x+m w150 vlblText","Text")
main.SetFont("norm","Fira Code")
;main.AddText("xs y+4 w150","popupSlot")
CtrlBind(main.AddEdit("xs y+m w300 vpopupSlotClass"), test.SubElement["popupSlot"],"className")
; main.AddEdit("xs yp w100 vpopupSlot")
;main.AddText("xs y+m w150","popup")
CtrlBind(main.AddEdit("xs y+m w300 vpopupClass"), test.SubElement["popup"],"className")
; main.AddEdit("x+4 yp w100 vPopup")
;main.AddText("xs y+m w150","side")
CtrlBind(main.AddEdit("xs y+m w150 vsideClass"), test.SubElement["side"],"className")
CtrlBind(main.AddEdit("x+m yp w150 r3 vsideHtml"), test.SubElement["side"],"innerHtml")
;main.AddText("xs y+m w150","title")
CtrlBind(main.AddEdit("xs y+m w150 vtitleClass"), test.SubElement["title"],"className")
CtrlBind(main.AddEdit("x+m yp w150 vtitleHtml"), test.SubElement["title"],"innerHtml")
;main.AddText("xs y+m w150","content")
CtrlBind(main.AddEdit("xs y+m w150 vcontentClass"), test.SubElement["content"],"className")
CtrlBind(main.AddEdit("x+m yp w150 vcontentHtml"), test.SubElement["content"],"innerHtml")
main.AddText("xs y+m w150","Style")
main.AddEdit("x+m yp w150 readOnly vpopupID", test.ID)
CtrlBind(main.AddEdit("xs y+m w300 r5 -wrap +hscroll +vscroll vStyleText"),
test.SubElement["styleEl"],"innerText")
CtrlBind(main.AddDDL("xs y+m -sort vPos",StrSplit("tl tc tr bl bc br",A_Space)),
test,"pos")
main.SetFont()
mtab.UseTab(5)
createTabGui()
createTabGui() {
global main, MainOverlay
static svgList := []
for k in MainOverlay.__Static.SvgIconMap
svgList.Push(k)
static themeList := StrSplit("info|message|warning|error|default","|")
static posList := ["tl","tc","tr","bl","bc","br"]
main.marginx := main.marginy := 8
main.AddText("section w40", "Title")
main.AddEdit("x+5 w200 vnewTitle", )
main.AddCheckBox("x+5 w50 yp+4 vnewTitleHTML", "HTML")
main.AddText("xs w40", "Text")
main.AddEdit("x+5 w200 vnewText r3", "Hello!")
main.AddCheckBox("x+5 w50 yp+4 vnewTextHTML", "HTML")
main.AddText("xs w40", "Icon")
main.AddComboBox("x+5 w200 vnewIcon", svgList)
main.AddCheckBox("x+5 w50 yp+4 vnewIconRnd", "Rnd")
main.AddText("xs w40", "Theme")
main.AddComboBox("x+5 w200 vnewTheme", ["",themeList*])
main.AddCheckBox("x+5 w50 yp+4 vnewThemeRnd", "Rnd")
main.AddText("xs w40", "Position")
main.AddRadio("x+5 w60 vnewPos", "TL")
main.AddRadio("x+5 w60", "TC")
main.AddRadio("x+5 w60", "TR")
main.AddRadio("xs+45 y+m w60 checked", "BL")
main.AddRadio("x+5 w60", "BC")
main.AddRadio("x+5 w60", "BR")
main.AddCheckBox("xs+250 yp-21 w50 vnewPosRnd","Rnd")
main.AddText("xs w40", "Show ")
main.AddComboBox("x+5 w200 vnewShowAnim", ["", "auto",
"in-slide-t", "in-slide-b", "in-slide-l", "in-slide-r",
"in-roll-h" , "in-roll-v" ,
"in-roll-t" , "in-roll-b" , "in-roll-l" , "in-roll-r" ,
"in-zoom" ])
main.AddEdit("x+5 w50 vnewShowDur number",300)
main.AddText("xs w40", "Hold")
main.AddEdit("x+210 w50 vnewDur number",3000)
main.AddCheckbox("xp-50 yp w50 vnewStay","Stay")
main.AddText("xs w40", "Hide ")
main.AddComboBox("x+5 w200 vnewHideAnim", ["", "auto",
"out-slide-t", "out-slide-b", "out-slide-l", "out-slide-r",
"out-roll-h" , "out-roll-v" ,
"out-roll-t" , "out-roll-b" , "out-roll-l" , "out-roll-r" ,
"out-zoom" ])
main.AddEdit("x+5 w50 vnewHideDur",300)
main.AddText("xs w40", "Events")
main.AddCheckbox("x+5 w100 vnewClickEvent","Click event")
main.AddCheckbox("x+0 wp vnewLinkClickEvent","LinkClick event")
(btnSimple := main.AddButton("xs+45","Add Simple"))
.OnEvent("Click", newPopupTimer)
(btnAdvance := main.AddButton("x+5","Add-vanced"))
.OnEvent("Click", newPopupTimer)
newPopupTimer(ctrl,props) {
local myPopup
props := main.submit(0)
SetTimer newPopup.Bind(ctrl, props), -1
}
newPopup(ctrl,props) {
title := (props.newTitleHTML ? "HTML:" : "") props.newTitle
text := (props.newTextHTML ? "HTML:" : "") props.newText
icon := props.newIconRnd ? svgList[Random(1,svgList.length)] : props.newIcon
theme := props.newThemeRnd ? themeList[Random(1,themeList.length)] : props.newTheme
pos := props.newPosRnd ? posList[Random(1,posList.length)] : posList[props.newPos]
if ctrl=btnSimple
MainOverlay.popupSimple(text,title,icon,theme,pos)
else {
myPopup := MainOverlay.Popup(text,title,icon,theme,pos)
if props.newClickEvent
myPopup.OnEvent("Click",clickEvent.Bind("Click"))
if props.newLinkClickEvent
myPopup.OnEvent("LinkClick",clickEvent.Bind("LinkClick"))
myPopup.Show(props.newShowAnim,props.newShowDur)
If !props.newStay
myPopup.After(props.newDur,
(p)=>p.Hide(props.newHideAnim,props.newHideDur)
)
}
clickEvent(which,instance,event,element,*) {
data := (which = "linkclick") ? element.href : element.id
If MsgBox(which " event dispatched.`ndata: " data "`nKeep the popup?",
,"YN") = "no"
instance.Remove()
}
}
}
mtab.UseTab()
global TabDlgHwnd
getTabDlgHwnd(mtab, &TabDlgHwnd)
getTabDlgHwnd(tabCtrl, &targetHwnd) {
local nextIsTarget := false, cbPtr
EnumCb(hwnd,*) {
if nextIsTarget {
targetHwnd := hwnd
CallbackFree(cbPtr)
return false
}
else if hwnd == tabCtrl.hwnd
nextIsTarget := True
return true
}
cbPtr := CallbackCreate(EnumCb)
DllCall("EnumChildWindows", "Ptr", tabCtrl.Gui.hwnd, "Ptr", cbPtr, "Ptr", 0)
}
Main.Show("AutoSize")
mTab.Value := 4 ; test
Main_Size(main, minmax, *) {
critical
global mtab, TabDlgHwnd
;static WM_SETREDRAW := 0xB
;SendMessage(WM_SETREDRAW, false, 0, TabDlgHwnd) ; disable redraw
If minmax = -1
return ; do nothing for minimized window
;AutoXYWH("wh", mtab)
;AutoXYWH("twh", csspad)
Main.GetClientPos(,,&winW,&winH)
main["Tab"].GetPos(&oTabX,&oTabY)
main["Tab"].Move(,, winW-oTabX-8, winH-oTabY-8)
; dpi-agnostic resizing
WinGetClientPos(&winX,&winY,,, main)
WinGetClientPos(&tabX,&tabY,&tabW,&tabH, TabDlgHwnd)
ControlMove(,, tabW-16, tabH-40, main["CSS"])
ControlMove(, tabY+tabH-winY-28,,, main["btnCssPad"])
static testTabResizeBound := testTabResize.bind(main,TabDlgHwnd)
If mTab.Value = 3
testTabResizeBound()
Else ; defer if not on Test tab
SetTimer testTabResizeBound, -100, -1
testTabResize(main,TabDlgHwnd) {
main["Tab"].Opt("-Redraw")
WinGetClientPos(&winX,,,,main)
WinGetClientPos(&tabX,,&tabW,&tabH,TabDlgHwnd)
;ControlGetPos(&tabBaseX,,,,main["sideClass"])
xHalf := tabX-winX + (tabW/2 + 2) ; * 96 // A_ScreenDPI
wFull := (tabW - 8 ) ; * 96 // A_ScreenDPI
wHalf := (tabW/2 - 6) ; * 96 // A_ScreenDPI
for ctrl in [main["sideClass"],main["titleClass"],main["contentClass"]]
ControlMove(,,wHalf,,ctrl)
for ctrl in [main["popupSlotClass"], main["popupClass"],main["StyleText"]]
ControlMove(,,wFull,,ctrl)
for ctrl in [main["lblText"], main["sideHtml"], main["titleHtml"], main["contentHtml"], main["popupID"]]
ControlMove(xHalf,,wHalf,,ctrl, TabDlgHwnd)
main["Tab"].Opt("+Redraw")
main["Tab"].Redraw()
}
;DllCall("RedrawWindow","Ptr",TabDlgHwnd,"Ptr",0,"Ptr",0,"UInt",RDW_INVALIDATE := 0x1, "Uint")
;SendMessage(WM_SETREDRAW, True, 0, TabDlgHwnd) ; enable redraw
}
CtrlBind(Ctrl, obj, prop, getter?, setter?) {
static focusGettingValue
OnFocus()
ctrl.OnEvent("Focus", OnFocus)
ctrl.OnEvent(ctrl.Type="Radio" ? "Click" : "Change", OnChange)
OnFocus(*) {
focusGettingValue := true
value := isset(getter) ? getter(obj.%prop%) : obj.%prop%
If ctrl.Type ~= "Edit|DDL|ComboBox"
ctrl.Text := value
Else
ctrl.Value := value
focusGettingValue := false
}
OnChange(*) {
If focusGettingValue
return
If ctrl.Type ~= "Edit|DDL|ComboBox"
value := StrReplace(ctrl.Text,"`n","`r`n")
Else
value := ctrl.Value
obj.%prop% := isset(setter) ? setter(value) : value
}
}
MapGetKeys(iMap) {
result := []
enumerable := iMap is Object ? iMap.OwnProps() : iMap
for key, _ in enumerable
result.Push(key)
return result
}
#HotIf WinActive(Main) || WinActive(CssGui)
F9::Reload()
#HotIf