-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathzoom-to-cursor.bmx
385 lines (220 loc) · 6.17 KB
/
zoom-to-cursor.bmx
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
SuperStrict
Import maxgui.drivers
Import BRL.PNGLoader
Import BRL.BMPLoader
Function Rand!( lo!, hi! )
Return lo + Rnd(lo + hi) + 1
EndFunction
Type obj
Global List:TList
Field X:Float
Field Y:Float
Field Size:Float
Field HalfSize:Float
Field R:Int
Field G:Int
Field B:Int
Method New()
X = Rand(0 , GW)
Y = Rand(0 , GH)
Size = Rnd(0 , 1)
Size = size^3
HalfSize = Size / 2.0
R = Rand(0,255)
G = Rand(0,255)
B = Rand(0 , 255)
If Not List Then List = New TList
List.AddLast(Self)
End Method
Method Draw(ZoomOriginX:Float,ZoomOriginY:Float,_VIEWSCALE:Float)
SetColor(r,g,b)
Local drawx:Float = ( (X - ZoomOriginX ) * _viewscale)
Local drawy:Float = ((Y- ZoomOriginY ) * _viewscale)
DrawRect(drawX-HalfSize,drawY-HalfSize,size+1,size+1)
End Method
End Type
Global GW:Int = ClientWidth(Desktop())
Global GH:Int = ClientHeight(Desktop())
Global GHW:Float = GW/2.0
Global GHH:Float = GH/2.0
Global Dragging:Byte = 0
Global MSX:Int
Global MSY:Int
Global MPosX:Int
Global MPosY:Int
Global DoubleClickTime:Int
Global DoubleClickDelay:Int = 300
Global Viewscale:Float = 1.0
Global WorldViewOriginX:Float = GHW
Global WorldViewOriginY:Float = GHH
Global ZoomTargetX:Float = GHW
Global ZoomTargetY:Float = GHH
Global ZoomTargetScale:Float = 1
Global ZoomFactor:Float = 1.25
Global ZoomMAX:Float = 30.0
Global ZoomMin:Float = 0.50
'Global RootDir:String = CurrentDir()
AddHook EmitEventHook, EventHook
SetGraphicsDriver(GLMax2DDriver() )
?Debug
Global GraphicsContext:TGraphics = CreateGraphics(GW , GH , 0 , 60 , Graphics_BACKBUFFER)
?Not Debug
Global GraphicsContext:TGraphics = CreateGraphics(GW , GH , 32 , 60 , Graphics_BACKBUFFER)
?
SetGraphics(GraphicsContext)
HideMouse()
For Local i:Int = 0 To 3000
Local temp:obj = New obj
Next
Local ms:Int,time:Int,dt:Float
While Not KeyHit(KEY_ESCAPE)
'ms = MilliSecs()
'dt = ms - time
'time = ms
'Print 1000.0/dt
Cls
SetScale(1 , 1)
SetOrigin(GHW,GHH)
SetColor(255 , 255 , 0)
SetLineWidth(5)
Local tempx:Float = (-WorldViewOriginX * viewscale)
Local tempy:Float = (-WorldViewOriginY * viewscale )
Local tempx2:Float = tempx+(GW*viewscale)
Local tempy2:Float = tempy+(GH*viewscale)
DrawLine(tempx , tempy , tempx2 , tempy)
DrawLine(tempx2, tempy , tempx2 , tempy2)
DrawLine(Tempx2 , tempy2 , tempx , tempy2)
DrawLine(tempx , tempy2 , tempx , tempy)
SetLineWidth(1)
SetColor(255 , 255 , 255)
SetViewScale()
For Local t:obj = EachIn Obj.List
t.draw(WorldViewOriginX, WorldViewOriginY, viewscale)
Next
SetScale(1 , 1)
SetOrigin(0 , 0)
SetBlend(LightBlend)
SetAlpha(0.4)
SetColor(255 , 155 , 0)
SetLineWidth(2)
DrawLine(MPosX- 15 , MPosY, MPosX+ 15 , MPosY)
DrawLine(MPosX, MPosY- 15 , MPosX, MPosY+ 15 )
SetLineWidth(1)
SetBlend(SolidBlend)
SetColor(255 , 255 , 255)
DrawText("SCALE: " + viewscale , 50 , 50)
Flip 0
Wend
Function SetViewScale()
WorldViewOriginX = ZoomTargetX
WorldViewOriginY = ZoomTargetY
ViewScale = ZoomTargetScale
SetScale(Viewscale , Viewscale)
End Function
Function ZoomIn(MouseScreenX:Int , MouseScreenY:Int)
If Not (ZoomTargetScale >= ZoomMax)
Local mx:Float = (MouseScreenX - GHW) /ZoomTargetScale
Local my:Float = (MouseScreenY - GHH) /ZoomTargetScale
Local z:Float = 1.0 - (1.0/ZoomFactor)
ZoomTargetX = (mx)*(z) + WorldViewOriginX
ZoomTargetY = (my)*(z) + WorldViewOriginY
If ZoomTargetX > GW
ZoomTargetX = GW
Else If ZoomTargetX < 0
ZoomTargetX = 0
EndIf
If ZoomTargetY > GH
ZoomTargetY = GH
Else If ZoomTargetY < 0
ZoomTargetY = 0
EndIf
ZoomTargetScale:* ZoomFactor
If ZoomTargetScale > ZoomMax Then ZoomTargetScale = ZoomMax
EndIf
End Function
Function ZoomOut(MouseScreenX:Int , MouseScreenY:Int)
If Not (ZoomTargetScale =< ZoomMin)
Local mx:Float = (MouseScreenX - GHW) / ZoomTargetScale
Local my:Float = (MouseScreenY - GHH) / ZoomTargetScale
Local z:Float = 1.0 - ZoomFactor
ZoomTargetX = mx*(z)+ WorldViewOriginX
ZoomTargetY = my*(z)+ WorldViewOriginY
ZoomTargetScale:/ ZoomFactor
If ZoomTargetScale < ZoomMin Then ZoomTargetScale = ZoomMin
EndIf
End Function
Function DoubleClick(button:Int , MouseScreenX:Int , MouseScreenY:Int)
ZoomTargetX = WorldViewOriginX + (MouseScreenX - GHW) / ZoomTargetScale
ZoomTargetY = WorldViewOriginY + (MouseScreenY - GHH) / ZoomTargetScale
ZoomTargetScale = ZoomMax
End Function
Function Drag(MouseScreenX:Int , MouseScreenY:Int)
Local dx:Float = (MouseScreenX - MSX) / viewscale
Local dy:Float = (MouseScreenY - MSY) / viewscale
WorldViewOriginX:- dx
WorldViewOriginY:- dy
ZoomTargetX:- dx
ZoomTargetY:- dy
MSX = MouseScreenX
MSY = MouseScreenY
If WorldViewOriginX < 0
WorldViewOriginX = 0
ZoomTargetX = 0
Else If WorldViewOriginX > GW
WorldViewOriginX = GW
ZoomTargetX = GW
EndIf
If WorldViewOriginY < 0
WorldViewOriginY = 0
ZoomTargetY = 0
Else If WorldViewOriginY > GH
WorldViewOriginY = GH
ZoomTargetY = GH
EndIf
End Function
Function EventHook:Object(ID:Int , Data:Object , Context:Object)
Local Event:TEvent = TEvent(data)
If Event = Null Then Return event
Select event.id
Case EVENT_MOUSEWHEEL
If Event.Data > 0
ZoomIn(event.x,Event.Y)
Else
ZoomOut(event.x,Event.Y)
EndIf
Case EVENT_APPTERMINATE
End
Case EVENT_KEYDOWN
Select Event.Data
Case KEY_ESCAPE End
End Select
Case EVENT_MOUSEDOWN
Local ms:Int = MilliSecs()
If ms - DoubleClickTime =< DoubleClickDelay
DoubleClick(event.Data , event.X , event.Y)
Return Null
Else DoubleClickTime = ms
EndIf
Select Event.data
Case 1
Dragging = 1
MSX = Event.X
MSY = Event.Y
Case 3
Dragging = 1
MSX = Event.X
MSY = Event.Y
End Select
Case EVENT_MOUSEUP
Select Event.data
Case 1,3
Dragging = 0
End Select
Case EVENT_MOUSEMOVE
MPosx = Event.x
MPosY = Event.y
If Dragging
Drag(event.x,event.y)
EndIf
End Select
End Function