Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacBase Plugin, MBS MacFrameworks Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/SetFrame Animated
This example is the version from Mon, 22th Nov 2015.
Project "SetFrame Animated.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
CocoaWindowFrameAnim.Move self, 20, 10
End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
CocoaWindowFrameAnim.MoveResize self, -20, 00, 40, 00
End EventHandler
End Control
EventHandler Sub Open()
self.Top = (Screen(0).Height - self.Height) \ 2
self.Left = (Screen(0).Width - self.Width) \ 2
End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class CocoaWindowFrameAnim Inherits NSAnimationMBS
EventHandler Sub CurrentProgressChanged(progress as double)
dim f as new NSRectMBS
f.Origin = NSMakePointMBS (origFrame.X + dL * progress, origFrame.Y + dT * progress)
f.Size = NSMakeSizeMBS (origFrame.Width + dW * progress, origFrame.Height + dH * progress)
win.NSWindowMBS.setFrame (f, true, true)
if progress = 1 then
' done
end
End EventHandler
Shared Sub Move(w as Window, deltaLeft as Integer, deltaTop as Integer, duration as Double = 0.25)
MoveResize w, deltaLeft, deltaTop, 0, 0, duration
End Sub
Shared Sub MoveResize(w as Window, deltaLeft as Integer, deltaTop as Integer, deltaWidth as Integer, deltaHeight as Integer, duration as Double = 0.25)
dim anim as new CocoaWindowFrameAnim (duration, NSAnimationEaseInOut)
anim.SetWindowDeltaLeftTopWidthHeight w, deltaLeft, deltaTop, deltaWidth, deltaHeight
anim.animationBlockingMode = NSAnimationBlocking // -> startAnimation returns only after animation is complete
anim.frameRate = 30 // frames per second
anim.startAnimation
End Sub
Shared Sub Resize(w as Window, deltaWidth as Integer, deltaHeight as Integer, duration as Double = 0.25)
MoveResize w, 0, 0, deltaWidth, deltaHeight, duration
End Sub
Sub SetWindowDeltaLeftTopWidthHeight(w as Window, dl as Integer, dt as Integer, dw as Integer, dh as Integer)
self.win = w
self.origFrame = w.NSWindowMBS.frame
self.dT = -dt-dh ' because NSRect uses inverted coordinates
self.dL = dl
self.dW = dw
self.dH = dh
End Sub
Property Private dH As Integer
Property Private dL As Integer
Property Private dT As Integer
Property Private dW As Integer
Property Private origFrame As NSRectMBS
Property Private win As Window
End Class
End Project
The items on this page are in the following plugins: MBS MacCocoa Plugin.