Platforms to show: All Mac Windows Linux Cross-Platform

/Overlay/Overlay with Draw Event


Required plugins for this example: MBS Overlay Plugin, MBS MacCG Plugin, MBS MacCF Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Overlay/Overlay with Draw Event

This example is the version from Sat, 27th Jul 2018.

Project "Overlay with Draw Event.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() create End EventHandler
End Control
Control AnimationTimer Inherits Timer
ControlInstance AnimationTimer Inherits Timer
EventHandler Sub Action() if o <> nil then if o.growing then o.pos = o.pos + 1 if o.pos > o.Width / 2 then o.growing = false end if o.Update else if o.pos = 0 then o.growing = true else o.pos = o.pos - 1 o.Update end if end if end if End EventHandler
End Control
EventHandler Function KeyDown(Key As String) As Boolean Select case asc(key) case 28 'left move -10,0 Return true case 29 'right move 10,0 Return true case 30 'top move 0,-10 Return true case 31 'down move 0,10 Return true end Select End EventHandler
Sub Create() o = new MyOverlay(500,100,200,200) // No picture sert as we use draw event o.hasShadow = false o.Show End Sub
Private Sub move(x as integer, y as integer) o.Move o.Left+x,o.top+y End Sub
Property DummyNSException As NSExceptionMBS
Property Private counter As Integer
Property Private o As MyOverlay
Property Private p As picture
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 MyOverlay Inherits OverlayMBS
EventHandler Sub Draw(CGContext as Variant, NSGraphicsContext as Variant) dim c as CGContextMBS = CGContext 'dim n as NSGraphicsMBS = NSGraphicsContext dim red as CGColorMBS = CGColorMBS.CreateGenericRGB(1, 0, 0) dim white as CGColorMBS = CGColorMBS.CreateGenericRGB(1, 1, 1) dim w as integer = me.Width dim h as integer = me.Height dim r1 as new CGRectMBS(0,0, w, h) dim r2 as new CGRectMBS(pos,pos, w/2, h/2) c.SetFillColor white c.FillEllipseInRect r1 c.SetFillColor red c.FillEllipseInRect r2 'c.Flush End EventHandler
EventHandler Function MouseDown(x as integer, y as integer, modifiers as integer) As boolean log CurrentMethodName+" "+str(x)+" "+str(y) End EventHandler
EventHandler Sub MouseEnter(x as integer, y as integer, modifiers as integer) log CurrentMethodName+" "+str(x)+" "+str(y) End EventHandler
EventHandler Sub MouseExit(x as integer, y as integer, modifiers as integer) log CurrentMethodName+" "+str(x)+" "+str(y) End EventHandler
EventHandler Function MouseUp(x as integer, y as integer, modifiers as integer) As boolean log CurrentMethodName+" "+str(x)+" "+str(y) End EventHandler
EventHandler Sub MouseWheel(x as integer, y as integer, dx as double, dy as double, modifiers as integer) log CurrentMethodName+" "+str(x)+" "+str(y)+", delta "+str(dx)+"/"+str(dy) End EventHandler
EventHandler Sub WindowBoundsChanged() log "windowboundschanged" End EventHandler
EventHandler Sub WindowClosed() log "windowclosed" MainWindow.AnimationTimer.Mode = timer.ModeOff End EventHandler
EventHandler Sub WindowHidden() log "windowhidden" End EventHandler
EventHandler Sub WindowShown() log "windowShown" MainWindow.AnimationTimer.Mode = timer.ModeMultiple End EventHandler
Private Function Window1open() As Boolean dim i,c as integer c=WindowCount-1 for i=0 to c if window(i) isa MainWindow then Return true end if next End Function
Private Sub log(s as string) System.DebugLog s if Window1open then MainWindow.Listbox1.InsertRow 0,s end if End Sub
Property growing As Boolean
Property pos As Integer
End Class
End Project

See also:

The items on this page are in the following plugins: MBS Overlay Plugin.


The biggest plugin in space...