Platforms to show: All Mac Windows Linux Cross-Platform

/MacBase/Custom NSWindows/NSWindow with Pattern/Pattern NSWindow


Required plugins for this example: MBS MacControls Plugin, MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacBase/Custom NSWindows/NSWindow with Pattern/Pattern NSWindow

This example is the version from Tue, 2nd Apr 2012.

Project "Pattern NSWindow.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "Effacer"
Const kFileQuit = "Quitter"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics) dim w1,w2,c As Integer c=20 // corner size w1=g.Width/2 w2=g.Width-w1 g.DrawPicture BookPagesTopLeftCorner, 0,0 // Top Left Corner g.DrawPicture BookPagesTopRightCorner, g.Width-c,0 // Top Right Corner g.DrawPicture BookPagesBottomLeftCorner, 0,g.Height-c // Bottom Left Corner g.DrawPicture BookPagesBottomRightCorner, g.Width-c,g.Height-c // Top Bottom Corner g.DrawPicture BookPagesTopLeftCorner, 0,c, c,g.Height-c-c, 0,c-1, c,1 // Left g.DrawPicture BookPagesTopRightCorner, g.Width-c,c, c,g.Height-c-c, 0,c-1, c,1 // Right g.DrawPicture BookPagesTopLeft, c,0, w1-c,c, 0,0, 268,20 // Top Left g.DrawPicture BookPagesTopRight, w1,0, w2-c,c, 0,0, 268,20 // Top Right g.DrawPicture BookPagesTopLeft, c,c, w1-c,g.Height-c-c, 0,c-1, 268,1 // Left g.DrawPicture BookPagesTopRight, w1,c, w2-c,g.Height-c-c, 0,c-1, 268,1 // Right g.DrawPicture BookPagesBottomLeft, c,g.Height-c, w1-c,c, 0,0, 268,20 // Bottom Left g.DrawPicture BookPagesBottomRight, w1,g.Height-c, w2-c,c, 0,0, 268,20 // Bottom Right End EventHandler
End Control
EventHandler Sub Open() //———————— // Current window //———————— dim w As New NSWindowMBS( Self ) w.backgroundColor = NSColorMBS.colorWithPatternImage( New NSImageMBS( LoopPatternImage ) ) w.acceptsMouseMovedEvents=true dim themeFrame As NSViewMBS = w.contentView.superview dim sa(-1) as NSViewMBS = themeFrame.subviews dim h As Integer = themeFrame.frameHeight //——————————— // Custom Titlebar view //——————————— customFrame = New CustomWindowFrame( 0,0,Self.Width,h ) customFrame.autoresizingMask = NSViewMBS.NSViewWidthSizable+NSViewMBS.NSViewHeightSizable customFrame.BorderImage = New NSImageMBS( FrameBorderImage ) customFrame.BackColor = &cD9A75A00 customFrame.TitleColor = &c4A382000 customFrame.TitleShadowColor = &cF1D3AB00 customFrame.TitleShadowDeltaY = 1 customFrame.TitleTopPadding = 21 customFrame.TitleText = "My Book" themeFrame.addSubview customFrame, NSWindowMBS.NSWindowBelow, sa(0) //—————————— // Titlebar SearchField //—————————— SearchField=New NSSearchFieldMBS( Self.Width-160,h-28,150,20 ) SearchField.autoresizingMask=NSViewMBS.NSViewMinXMargin+NSViewMBS.NSViewMinYMargin themeFrame.addSubview( SearchField ) End EventHandler
Property SearchField As NSSearchFieldMBS
Property Protected customFrame As CustomWindowFrame
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Fichier"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "Edition"
MenuItem EditUndo = "Annuler"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Couper"
MenuItem EditCopy = "&Copier"
MenuItem EditPaste = "Coller"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Tout Sélectionner"
End MenuBar
Class CustomWindowFrame Inherits CustomNSViewMBS
EventHandler Sub DrawRect(g as NSGraphicsMBS, left as double, top as double, width as double, height as double) g.saveGraphicsState dim iw,ih,c,w,y,h As Integer // Border image if BorderImage<>Nil then iw=BorderImage.Width ih=BorderImage.height w=frameWidth h=frameHeight c=22 y=frameHeight-c g.drawInRect BorderImage, 0,y, c,c, 0,ih-c, c,c, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // top left part g.drawInRect BorderImage, c,y, w-c-c,c, c,ih-c, 1,c, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // top middle part g.drawInRect BorderImage, w-c,y, c,c, iw-c,ih-c, c,c, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // top right part y=c g.drawInRect BorderImage, 0,y, c,h-c-c, 0,c, c,1, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // left part g.drawInRect BorderImage, w-c,y, c,h-c-c, iw-c,c, c,1, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // right part y=0 g.drawInRect BorderImage, 0,y, c,c, 0,0, c,c, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // bottom left part g.drawInRect BorderImage, c,y, w-c-c,c, c,0, 1,c, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // bottom middle part g.drawInRect BorderImage, w-c,y, c,c, iw-c,0, c,c, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // bottom right part end if // Window title + icon if TitleText<>"" then w=g.sizeWithAttributes( TitleText, TitleAttributes ).Width + TitleIconSpace if TitleIcon<>Nil then TitleIconSpace=19 else TitleIconSpace=0 if w<width-130 then dim pos As New NSPointMBS pos.X=(width/2)-(w/2)+TitleIconSpace pos.Y=frameHeight-TitleTopPadding g.drawAtPoint TitleText, pos, TitleShadowAttributes pos.Y=pos.Y+TitleShadowDeltaY g.drawAtPoint TitleText, pos, TitleAttributes if TitleIcon<>Nil then pos.X=pos.X-TitleIconSpace pos.Y=frameHeight-TitleTopPadding-1 g.drawAtPoint TitleIcon, pos.X,pos.Y, 0,0, 16,16, NSGraphicsMBS.NSCompositeSourceAtop, 1.0 end if end if end if g.restoreGraphicsState End EventHandler
EventHandler Function acceptsFirstMouse(e as NSEventMBS) As boolean Return True End EventHandler
EventHandler Function acceptsFirstResponder() As boolean Return True End EventHandler
EventHandler Function mouseMoved(e as NSEventMBS, x as double, y as double) As boolean if x>8 and x<70 and y>0 then needsDisplay=true end if End EventHandler
EventHandler Sub viewDidMoveToWindow() Dim tx,ts As NSColorMBS Dim NSFont as NSFontMBS = NSFontMBS.boldSystemFontOfSize(0) TitleAttributes = New Dictionary tx=NSColorMBS.colorWithDeviceHSV( TitleColor.Hue, TitleColor.Saturation, TitleColor.Value, 1.0 ) TitleAttributes.Value( NSAttributedStringMBS.NSFontAttributeName )=NSFont TitleAttributes.Value( NSAttributedStringMBS.NSForegroundColorAttributeName )=tx TitleShadowAttributes = New Dictionary ts=NSColorMBS.colorWithDeviceHSV( TitleShadowColor.Hue, TitleShadowColor.Saturation, TitleShadowColor.Value, 1.0 ) TitleShadowAttributes.Value( NSAttributedStringMBS.NSFontAttributeName )=NSFont TitleShadowAttributes.Value( NSAttributedStringMBS.NSForegroundColorAttributeName )=ts if window<>Nil then window.initialFirstResponder = Self end if End EventHandler
Note "Thanks"
Thanks to David Della Rocca for providing this example.
Property BackColor As Color
Property BorderImage As NSImageMBS
Property TitleAttributes As Dictionary
Property TitleColor As Color
Property TitleIcon As NSImageMBS
Property TitleIconSpace As Integer
Property TitleShadowAttributes As Dictionary
Property TitleShadowColor As Color
Property TitleShadowDeltaY As Integer = 1
Property TitleText As String
Property TitleTopPadding As Integer = 19
End Class
ExternalFile LoopPatternImage
End ExternalFile
ExternalFile FrameBorderImage
End ExternalFile
ExternalFile BookPagesBottomLeft
End ExternalFile
ExternalFile BookPagesBottomLeftCorner
End ExternalFile
ExternalFile BookPagesBottomRight
End ExternalFile
ExternalFile BookPagesBottomRightCorner
End ExternalFile
ExternalFile BookPagesTopLeft
End ExternalFile
ExternalFile BookPagesTopLeftCorner
End ExternalFile
ExternalFile BookPagesTopRight
End ExternalFile
ExternalFile BookPagesTopRightCorner
End ExternalFile
End Project

See also:

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


The biggest plugin in space...