-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListView.ahk
247 lines (227 loc) · 8.51 KB
/
ListView.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
Class PlanList {
static ACCENT:= {"-1":"ffffff" ; MAIN ACCENT 4D5565
,"0":"DC3545" ; OFF ACCENT
,"1":"6eff74"} ; ON ACCENT 007BFF
static selectedScheme := ""
__New(pos:="", excludeFullscreen:=0, posEditorCallback:=""){
this.excludeFullscreen:= excludeFullscreen
this.state:= 0
;get the primary monitor resolution
SysGet, resWorkArea, MonitorWorkArea
this.screenHeight:= resWorkAreaBottom
this.screenWidth:= resWorkAreaRight
;get the primary monitor scaling
this.scale:= A_ScreenDPI/96
;set the PlanList width and height
this.width:= Format("{:i}", 200 * this.scale)
this.height:= Format("{:i}", 40 * this.scale)
;set the default pos object
pos:= pos? pos : {x:-1,y:-1}
;get the final pos object
this.pos:= this.getPosObj(pos.x, pos.y)
;set up bound func objects
this.hideFunc:= objBindMethod(this, "hide")
this.selfDestroy:= objBindMethod(this, "destroy")
this.posEditorCallback:= posEditorCallback
;set the initial PlanList theme
this.setTheme(0)
;create the PlanList window
this.create()
}
; creates the PlanList window
create(){
Gui, New, +Hwndhwnd, PlanList
this.hwnd:= hwnd
Gui, +AlwaysOnTop -SysMenu +ToolWindow -caption -Border
; Gui, Margin, 15
Gui, Color, % this.theme, % PlanList.ACCENT["-1"]
Gui, Font,% Format("s{:i} w500 c{}", 12*this.scale, PlanList.ACCENT["-1"]), Segoe UI
this.hwndTxt:= txtHwnd
}
; hides and destroys the PlanList window
destroy(){
Gui,% this.hwnd ":Default"
this.hide()
Gui, Destroy
this.hwnd:= ""
this.hwndTxt:=""
PlanList.selectedScheme := ""
}
; shows the PlanList window with the specified text and accent
show(powerSchemeArray,accent:=-1){
;if the window can't be shown -> return
if(!this.canShow())
return
;if the window does not exist -> create it first
if(!this.hwnd)
this.create()
Gui, % this.hwnd ":Default" ;set the default window
Gui, Margin, 0, 0
;set the accent/theme colors
if(color:=PlanList.ACCENT[accent ""])
accent:=color
Gui, Color, % this.theme, % accent
Gui, Font,% Format("s{:i} w500 c{}", 9*this.scale, accent)
GuiControl, Font, % this.hwndTxt
; GuiControl, Text, % this.hwndTxt, %text%
ListViewHeightTemp := powerSchemeArray.MaxIndex()-1
widthTemp := this.width
Gui, Add, ListView, r%ListViewHeightTemp% w%widthTemp% gMyListView Background385b92 -Hdr -Multi altsubmit LV0x40 x+0 y+0, Battery Modes
Loop % powerSchemeArray.MaxIndex() - 1{
; MsgBox % powerSchemeArray.MaxIndex()
stringTemp := powerSchemeArray[A_Index]
if (stringTemp != ""){
if (stringTemp = powerSchemeArray[powerSchemeArray.MaxIndex()]){
this.currentFocusedScheme := stringTemp
this.currentFocusedIndex:=A_Index
stringTemp := this.addIcon(stringTemp)
LV_Add("Select", stringTemp)
}
else {
stringTemp := this.addIcon(stringTemp)
LV_Add("", stringTemp)
}
}
; MsgBox, %stringTemp%
}
; LV_ModifyCol(1, "Center")
Gui, +LastFound
Winset, Redraw
;show the PlanList
Gui, Show, % Format("NoActivate NA x{} y{}", this.pos.x - (widthTemp) * this.scale, this.pos.y - this.scale * (ListViewHeightTemp * 35))
; make the PlanList corners rounded
WinGetPos,,,Width, Height, % "ahk_id " . this.hwnd
WinSet, Region, % Format("w{} h{} 10-5 R{3:i}-{3:i}", Width - 10, Height - 5, 15*this.scale), % "ahk_id " . this.hwnd
;set the PlanList transparency
; WinSet, Transparent, 200, % "ahk_id " . this.hwnd
SetWinDelay -1
this.destinationX := this.pos.x - (widthTemp) * this.scale
this.destinationY := this.pos.y - this.scale * (ListViewHeightTemp * 35)
moveX := widthTemp / 2
startX := this.destinationX + moveX
duration := 100
MaxTemp := 200
N := 10
Loop %N%{
currentTp := Round(A_Index * (MaxTemp / N))
WinMove, % "ahk_id " . this.hwnd, , % startX - moveX / N * A_Index, destinationY
WinSet, Transparent, %currentTp%, % "ahk_id " . this.hwnd
Sleep % duration / N
}
powerSchemeArray.Remove(powerSchemeArray.MaxIndex())
this.powerSchemeArray:=powerSchemeArray
MyListView:
if (A_GuiEvent = "Normal")
{
LV_GetText(stringTemp, A_EventInfo) ; Get the text from the row's first field.
if (stringTemp = " 🍃 Power saver"){
PlanList.selectedScheme := "Power Saver"
}
else if (stringTemp = " 🍃 节能"){
PlanList.selectedScheme := "节能"
}
else if (stringTemp = " 🚀 RapidOS Optimized"){
PlanList.selectedScheme := "RapidOS Optimized"
}
else if (stringTemp = " ☢ RapidOS Competitive"){
PlanList.selectedScheme := "RapidOS Competitive"
}
; else if (stringTemp = " ☢ 卓越性能"){
; PlanList.selectedScheme := "卓越性能"
; }
else {
PlanList.selectedScheme := LTrim(stringTemp, " `t")
}
}
return
return this.state:= 1
}
addIcon(stringTemp){
if (stringTemp = "Power saver"){
return " 🍃 Power Saver"
}
else if (stringTemp = "节能"){
return " 🍃 节能"
}
else if (stringTemp = "RapidOS Optimized"){
return " 🚀 RapidOS Optimized"
}
else if (stringTemp = "RapidOS Competitive"){
return " ☢ RapidOS Competitive"
}
; else if (stringTemp = "卓越性能"){
; return " ☢ 卓越性能"
; }
else {
return " " . stringTemp
}
}
getSelectedScheme(){
return PlanList.selectedScheme
}
getCurrentFocusedScheme(){
return this.currentFocusedScheme
}
setNextFocusedScheme(){
; Gui, +LastFound
Gui, % this.hwnd ":Default"
; LV_Modify(this.currentFocusedIndex, "-Select")
this.currentFocusedIndex := Mod((this.currentFocusedIndex + 1), this.powerSchemeArray.MaxIndex() + 1)
if (this.currentFocusedIndex = 0){
this.currentFocusedIndex += 1
}
this.currentFocusedScheme := this.powerSchemeArray[this.currentFocusedIndex]
LV_Modify(this.currentFocusedIndex, "Select")
; MsgBox % this.currentFocusedIndex
; Winset, Redraw
return this.currentFocusedScheme
}
getID(){
return this.hwnd
}
; hides the PlanList window
hide(){
if(!this.hwnd)
return
Gui, % this.hwnd ":Default"
OnMessage(0x201, this.onDragFunc, 0)
OnMessage(0x205, this.onRClickFunc, 0)
SetWinDelay -1
moveX := this.width / 2
this.destinationX += moveX
startX := this.destinationX
duration := 100
MaxTemp := 200
N := 10
Loop %N%{
currentTp := Round(MaxTemp - A_Index * (255 / N))
WinSet, Transparent, %currentTp%, % "ahk_id " . this.hwnd
WinMove, % "ahk_id " . this.hwnd, , % startX + moveX / N * A_Index, this.destinationY
Sleep % duration / N
}
Gui, Hide
this.state:= 0
}
canShow(){
return this.excludeFullscreen? !this.isWindowFullscreen() : 1
}
setTheme(theme:=""){
if(theme != this.theme)
this.theme:= theme? (theme=1? "232323" : theme) : "385b92" ; f2f2f2
}
isWindowFullscreen(win:="A"){
winID := WinExist(win)
if(!winID)
return 0
WinGet style, Style, ahk_id %WinID%
WinGetPos ,,,winW,winH, %winTitle%
return !((style & 0x20800000) or WinActive("ahk_class Progman")
or WinActive("ahk_class WorkerW") or winH < A_ScreenHeight or winW < A_ScreenWidth)
}
getPosObj(x:=-1,y:=-1){
p_obj:= {}
p_obj.x:= x=-1? Round(this.screenWidth) : x
p_obj.y:= y=-1? this.screenHeight : y ; 0.68
return p_obj
}
}