-
Notifications
You must be signed in to change notification settings - Fork 1
/
cwOverlay.cls
494 lines (383 loc) · 16.1 KB
/
cwOverlay.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "cwOverlay"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'@IgnoreModule IntegerDataType, ModuleWithoutFolder
'---------------------------------------------------------------------------------------
' Module : cwOverlay
' Author : beededea
' Date : 31/07/2023
' Purpose : create a fully click-through Widget, which allows for all kind of
' things to render on top of the PSD-generated Widgets created in cfAlpha
'---------------------------------------------------------------------------------------
Option Explicit
'these Public Properties are set in the Parent (here, cfAlpha)
Public cCollOverlayImages As cCollection
Public cxPerc As Single
Public cyPerc As Single
Private WithEvents W As cWidgetBase
Attribute W.VB_VarHelpID = -1
Private WithEvents tmrClock As cTimer
Attribute tmrClock.VB_VarHelpID = -1
Private HDeg As Double
Private MDeg As Double
Private SDeg As Double
Private MsDeg As Double
'------------------------------------------------------ STARTS
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
bias As Long
StandardName(0 To 63) As Byte
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 63) As Byte
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
'------------------------------------------------------ ENDS
Private mTicking As Boolean ' property Ticking
Private mSmoothSecondHand As Boolean ' property SmoothSecondHand
Private mLocked As Boolean ' property Locked
Private mHidden As Boolean ' property Hidden
Private storeTxtDayNumber As String
'---------------------------------------------------------------------------------------
' Procedure : Class_Initialize
' Author : olaf schmidt
' Date : 31/07/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Private Sub Class_Initialize()
Dim intervalValue As Integer: intervalValue = 0
On Error GoTo Class_Initialize_Error
Set W = Cairo.WidgetBase
W.BackColor = -1 'we don't use any BackColor here, transparent
W.ImplementsHitTest = True 'when at False, no HitTest-Event would be triggered
intervalValue = 500
Set tmrClock = Nothing
Set tmrClock = New_c.Timer(intervalValue, mTicking)
On Error GoTo 0
Exit Sub
Class_Initialize_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Class_Initialize of Class Module cwOverlay"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : Widget
' Author : olaf schmidt
' Date : 21/09/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Get Widget() As cWidgetBase
On Error GoTo Widget_Error
Set Widget = W
On Error GoTo 0
Exit Property
Widget_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Widget of Class Module cwOverlay"
End Property
'---------------------------------------------------------------------------------------
' Procedure : Widgets
' Author : olaf schmidt
' Date : 21/09/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Get Widgets() As cWidgets
On Error GoTo Widgets_Error
Set Widgets = W.Widgets
On Error GoTo 0
Exit Property
Widgets_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Widgets of Class Module cwOverlay"
End Property
'---------------------------------------------------------------------------------------
' Property : Ticking
' Author : beededea
' Date : 17/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Get Ticking() As Boolean
On Error GoTo TickingGet_Error
Ticking = mTicking
On Error GoTo 0
Exit Property
TickingGet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property Ticking of Class Module cwOverlay"
End Property
'---------------------------------------------------------------------------------------
' Property : Ticking
' Author :
' Date : 09/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Let Ticking(ByVal newValue As Boolean)
'Dim intervalValue As Integer: intervalValue = 0
On Error GoTo TickingLet_Error
If mTicking <> newValue Then mTicking = newValue Else Exit Property
If mTicking Then
' If mSmoothSecondHand Then
' 'intervalValue = 100
' Else
' 'intervalValue = 500
' End If
tmrClock.Enabled = True
Else
tmrClock.Enabled = False
End If
On Error GoTo 0
Exit Property
TickingLet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property Ticking of Class Module cwOverlay"
End Property ' the earth Ticking flag
'---------------------------------------------------------------------------------------
' Property : SmoothSecondHand
' Author : beededea
' Date : 17/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Get SmoothSecondHand() As Boolean
On Error GoTo SmoothSecondHandGet_Error
SmoothSecondHand = mSmoothSecondHand
On Error GoTo 0
Exit Property
SmoothSecondHandGet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property SmoothSecondHand of Class Module cwOverlay"
End Property
'---------------------------------------------------------------------------------------
' Property : SmoothSecondHand
' Author :
' Date : 09/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Let SmoothSecondHand(ByVal newValue As Boolean)
Dim intervalValue As Integer: intervalValue = 0
On Error GoTo SmoothSecondHandLet_Error
If mSmoothSecondHand <> newValue Then mSmoothSecondHand = newValue Else Exit Property
If mSmoothSecondHand Then
intervalValue = 100
Else
intervalValue = 500
End If
tmrClock.Interval = intervalValue
On Error GoTo 0
Exit Property
SmoothSecondHandLet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property SmoothSecondHand of Class Module cwOverlay"
End Property ' the earth SmoothSecondHand flag
'---------------------------------------------------------------------------------------
' Property : Locked
' Author : beededea
' Date : 17/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Get Locked() As Boolean
On Error GoTo LockedGet_Error
Locked = mLocked
On Error GoTo 0
Exit Property
LockedGet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property Locked of Class Module cwGlobe"
End Property
'---------------------------------------------------------------------------------------
' Property : Locked
' Author : beededea
' Date : 17/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Let Locked(ByVal newValue As Boolean)
On Error GoTo LockedLet_Error
If mLocked <> newValue Then mLocked = newValue Else Exit Property
On Error GoTo 0
Exit Property
LockedLet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property Locked of Class Module cwGlobe"
End Property
'---------------------------------------------------------------------------------------
' Property : Hidden
' Author : beededea
' Date : 17/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Get Hidden() As Boolean
On Error GoTo HiddenGet_Error
Hidden = mHidden
On Error GoTo 0
Exit Property
HiddenGet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property Hidden of Class Module cwGlobe"
End Property
'---------------------------------------------------------------------------------------
' Property : Hidden
' Author : beededea
' Date : 10/05/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Property Let Hidden(ByVal newValue As Boolean)
On Error GoTo HiddenLet_Error
If mHidden <> newValue Then mHidden = newValue Else Exit Property
If mHidden = True Then
W.Visible = False
W.Refresh
Else
W.Visible = True
W.Refresh
End If
On Error GoTo 0
Exit Property
HiddenLet_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Property Hidden of Class Module cwGlobe"
End Property
'
'---------------------------------------------------------------------------------------------
' Procedure : W_HitTest
' Author : olaf schmidt
' Date : 01/08/2023
' Purpose : This is run continuously for the whole widget.
' For this Overlay-Widget alone, we make everything "fully click-through"
'---------------------------------------------------------------------------------------------
'
Private Sub W_HitTest(ByVal x As Single, ByVal y As Single, HitResultHit As Boolean) 'ensure ClickThrough-behaviour in ImagePixels which are "fully Alpha"
On Error GoTo W_HitTest_Error
HitResultHit = False
On Error GoTo 0
Exit Sub
W_HitTest_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure W_HitTest of Class Module cwOverlay"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : W_Paint
' Author : olaf schmidt
' Date : 01/08/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Private Sub W_Paint(CC As RC6.cCairoContext, ByVal xAbs As Single, ByVal yAbs As Single, ByVal dx_Aligned As Single, ByVal dy_Aligned As Single, UserObj As Object)
Dim I As Long: I = 0
Dim Arr As Variant
Dim Key As String: Key = vbNullString
Dim Pat As cCairoPattern
Dim txtDayNumber As String: txtDayNumber = vbNullString
Dim txtMonthNumber As String: txtMonthNumber = vbNullString
Dim textDrawn As Boolean: textDrawn = False
Dim thisOpacity As Double: thisOpacity = 0
Dim cream As String: cream = vbNullString
cream = RGB(235, 217, 179) ' cannot create a constant from an RGB value
On Error GoTo W_Paint_Error
'set some Font- and ForeColor-Properties and draw some Text on the Widget
W.FontName = "arial"
W.ForeColor = cream
W.FontSize = 18
W.FontBold = True
W.SelectFontSettingsInto CC
W.Refresh
thisOpacity = (Val(PzGOpacity) / 100) * 0.75
storeTxtDayNumber = txtDayNumber
txtDayNumber = Day(DateAdd("m", tzDelta, Now))
If storeTxtDayNumber <> txtDayNumber Then textDrawn = False ' trigger a redraw of the day and month within the boxes
txtMonthNumber = Month(DateAdd("m", tzDelta, Now))
For I = 0 To cCollOverlayImages.Count - 1 ' this is the ExcludedPaths collection populated in cfAlpha by duplicating collPSDNonUIElements.
Arr = cCollOverlayImages.ItemByIndex(I)
Key = cCollOverlayImages.KeyByIndex(I)
If IsArray(Arr) Then
CC.Save
'derive a Pattern-Obj from each retrieved ImageList-Surface-reference
Set Pat = Cairo.ImageList(Key).CreateSurfacePattern
' for specific keys perform rotation actions, clock hands &c
Select Case Key
Case "hourshadow", "hourhand" 'hours-shadow- and hour-hand
' draw the date and day in the windows just once to retain opacity
If textDrawn = False Then ' has to be here to be underneath all the hands and only run once
CC.DrawText 260, 105, 200, 200, txtDayNumber, , , 2, True, , thisOpacity
CC.DrawText 461, 309, 200, 200, txtMonthNumber, , , 2, True, , thisOpacity
textDrawn = True
End If
Set Pat.Matrix = Pat.Matrix.TranslateCoords(19, 160) 'shift to the "rotation-point" within the Pattern
CC.TranslateDrawings W.Width * cxPerc, W.Height * cyPerc 'shift to the center-point of the Overlay-Widget-area
CC.RotateDrawingsDeg -7 + HDeg 'now we can rotate (the leading negative degrees are the rotation-offsets for 12 o'clock)
Case "minuteshadow", "minutehand" 'minutes-shadow- and minutes-hand
Set Pat.Matrix = Pat.Matrix.TranslateCoords(44, 105) 'shift to the "rotation-point" within the Pattern
CC.TranslateDrawings W.Width * cxPerc, W.Height * cyPerc 'shift to the center-point of the Overlay-Widget-area
CC.RotateDrawingsDeg -61 + MDeg
Case "secondshadow", "secondhand" 'seconds-shadow- and seconds-hand
Set Pat.Matrix = Pat.Matrix.TranslateCoords(60, 160) 'shift to the "rotation-point" within the Pattern
CC.TranslateDrawings W.Width * cxPerc, W.Height * cyPerc 'shift to the center-point of the Overlay-Widget-area
CC.RotateDrawingsDeg -50 + SDeg + MsDeg
Case Else 'plain output for everything else ... this includes the reflection-layers,
Set Pat.Matrix = Pat.Matrix.TranslateCoords(-Arr(0), -Arr(1)) 'here we only shift the Pattern via the original PSD-Offsets (stored in Arr(0) and Arr(1))
End Select
CC.Paint Arr(2), Pat 'finally we render the Pattern with the current PSD-LayerAlpha, present in Arr(2)
CC.Restore
End If
Next
On Error GoTo 0
Exit Sub
W_Paint_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure W_Paint of Class Module cwOverlay"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : tmrClock_Timer
' Author : olaf schmidt
' Date : 30/07/2023
' Purpose :
'---------------------------------------------------------------------------------------
'
Private Sub tmrClock_Timer() 'update the private "Degree-Variables" for Hour-, Minute- and Second-Hands + Refresh
Dim currentLocaltime As SYSTEMTIME
Static T As Date: T = Time
On Error GoTo tmrClock_Timer_Error
GetSystemTime currentLocaltime
' every 15 mins approx. update DaylightSavings and determine the time bias
If (Minute(T) Mod 15 = 0) And (Second(T) = 0) And (currentLocaltime.wMilliseconds < 100) Then
Call obtainDaylightSavings
End If
' Debug.Print ("%updateTime-I tzDelta " & tzDelta)
HDeg = 30 * (Hour(T) Mod 12 + (Minute(T) + tzDelta) / 60)
MDeg = 6 * ((Minute(T) + tzDelta) + (Second(T) / 60))
If mSmoothSecondHand = True Then
SDeg = 6 * Second(T)
With currentLocaltime
MsDeg = 6 * (.wMilliseconds / 1000)
End With
' always refresh
Else
If SDeg <> 6 * Second(T) Then
SDeg = 6 * Second(T)
MsDeg = 0
Else
Exit Sub 'only refresh when SDeg has changed to a new value
End If
End If
W.Parent.Refresh
On Error GoTo 0
Exit Sub
tmrClock_Timer_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure tmrClock_Timer of Class Module cwOverlay"
End Sub