Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/CoreGraphics Overlay Window/Mac and Win Transparent Splash/SplashScreen
Required plugins for this example: MBS Images Plugin, MBS MacCG Plugin, MBS Picture Plugin, MBS Util Plugin, MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CoreGraphics Overlay Window/Mac and Win Transparent Splash/SplashScreen
This example is the version from Sun, 10th Dec 2016.
Project "SplashScreen.rbp"
Filetype text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() SplashScreen.Show End EventHandler
End Class
Class SplashScreen Inherits Window
Control DemoButton Inherits PushButton
ControlInstance DemoButton Inherits PushButton
EventHandler Sub Action() Quit End EventHandler
End Control
Control BuyNowButton Inherits PushButton
ControlInstance BuyNowButton Inherits PushButton
EventHandler Sub Action() Quit End EventHandler
End Control
Control EnterRegButton Inherits PushButton
ControlInstance EnterRegButton Inherits PushButton
EventHandler Sub Action() Quit End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
EventHandler Sub Open() Dim d As New Date Me.Text = ReplaceAll(Me.Text, "[YEAR]", Str(d.Year)) End EventHandler
End Control
EventHandler Sub Open() // I like using Tiff files, because they contain the mask also. // Here the TiffPictureMBS class alows me to extract each element // and create a single Picture object which contains both. Dim t As TiffPictureMBS, p As Picture t = FindFile("SplashScreen.tif").OpenAsTiffMBS If t <> Nil Then p = new Picture(t.Width, t.Height, 32) p.Graphics.DrawPicture t.Pict, 0, 0 p.Mask.Graphics.DrawPicture t.Mask, 0, 0 Pic = p Else // Error reading the file: bail out. Quit End If // Now call the InitSplash function. It expects Pic to have a Picture // and a mask stored in it. InitSplash End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) Dim c As CGContextMBS, r As CGRectMBS if TargetMachO then // We have a CGImage to render if cg<>Nil then r = CGMakeRectMBS( 0, 0, g.Width, g.Height ) #if TargetCocoa c = GetCurrentCGContextMBS #else c = self.CGContextMBS #endif c.ClearRect( r ) c.DrawPicture( cg, r ) c.Flush end if ElseIf Pic <> nil Then // No CGImage (probably coz we're on Win32) fallback by drawing Pic to the screen g.ClearRect 0, 0, g.Width, g.Height g.DrawPicture pic,0,0 End if End EventHandler
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Sub InitSplash() If Pic = Nil Then // Check we have a picture to play with Return End If // Set the dimentions of the window If TargetMacOS then If 0 = Me.MakeTransparentMBS Then MsgBox "Couldn't make window transparent" Return End If cg = CGCreateImageMBS( Pic, Pic.Mask ) ElseIf TargetWin32 then Dim p, m As Picture dim x, y as integer p = Pic m = p.Mask // you may improve the mask more to make more parts behind visible, // as the screenshot can't be updated, but windows behind may change // and you only see this updated graphics if you make a better mask for the window m = new picture(p.Width+2,p.Height+2,32) m.Graphics.ForeColor=rgb(0,0,0) x=m.Width-1 y=m.Height-1 m.Graphics.DrawLine 0,0,x,0 m.Graphics.DrawLine 0,y,x,y m.Graphics.DrawLine x,0,x,y m.Graphics.DrawLine 0,0,0,y If NOT Me.SetWindowMaskMBS(m, false, RGB(0,0,0)) Then MsgBox "Couldn't set window mask" Return End If p = new Picture(p.Width, p.Height, 32) p.Graphics.DrawPicture ScreenshotRectMBS(left,top,width,height),0,0 p.Graphics.DrawPicture Pic, 0, 0 Me.pic = p end if Me.Width = Pic.Width Me.Height = Pic.Height Me.Left = (Screen(0).Width - Me.Width) / 2 End Sub
Property Pic As Picture
Property cg As CGImageMBS
End Class
End Project

See also:

Feedback, Comments & Corrections

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

MBS FileMaker Plugins