Platforms to show: All Mac Windows Linux Cross-Platform
/MacFrameworks/CustomNSScroller/Dark scrollbar
Required plugins for this example: MBS MacFrameworks Plugin, MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Main Plugin, MBS MacControls Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/CustomNSScroller/Dark scrollbar
This example is the version from Sun, 17th Mar 2012.
Project "Dark scrollbar.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "Effacer"
Const kFileQuit = "Quitter"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
if not TargetCocoa then
MsgBox "This example requires Cocoa target."
quit
end if
End EventHandler
End Class
Class Window1 Inherits Window
Const a_big_text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. \r\rVestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit. Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. \rAenean ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. \r\rMauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna. Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien. Vivamus leo. Aliquam euismod libero eu enim. Nulla nec felis sed leo placerat imperdiet. Aenean suscipit nulla in justo. Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet."
Control CocoaControlMBS1 Inherits CocoaControlMBS
ControlInstance CocoaControlMBS1 Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS
scrollview = New NSScrollViewMBS( 0,0,Me.Width,Me.Height )
// We create and add our custom NSScroller to the NSScrollView.
// the scroller must be stored in a property in order to work.
VScroller = New MyCustomNSScroller( 0,0,15,Me.Height )
VScroller.knobSlotImage = New NSImageMBS( CustomNSscrollerDarkKnobSlot )
VScroller.knobImage = New NSImageMBS( CustomNSscrollerDarkKnob )
VScroller.IncrArrowImage = New NSImageMBS( CustomNSscrollerDarkIncrArrow )
VScroller.DecrArrowImage = New NSImageMBS( CustomNSscrollerDarkDecrArrow )
VScroller.BackColor = NSColorMBS.colorWithDeviceHSV(0.0, 0.0, 0.22, 1.0)
scrollview.verticalScroller = VScroller
// We create and add a text field to the NSScrollView.
textView=New NSTextViewMBS( 0,0,Me.Width,Me.Height )
dim tPadding As New NSSizeMBS( 15,15 )
textView.ContinuousSpellCheckingEnabled = false
textView.allowsUndo = true
textView.autoresizingMask = textView.NSViewHeightSizable+textView.NSViewWidthSizable
textView.textContainerInset = tPadding
textView.backgroundColor = NSColorMBS.colorWithDeviceHSV(0.0, 0.0, 0.22, 1.0)
textView.textColor = NSColorMBS.whiteColor
textView.text = a_big_text
scrollview.documentView = textView
scrollview.hasHorizontalScroller = false
scrollview.hasVerticalScroller = true
scrollview.autohidesScrollers = true
Return scrollview
End EventHandler
End Control
EventHandler Sub Open()
if not CocoaControlMBS1.Available then
MsgBox "This example requires Mac OS X 10.5."
quit
end if
End EventHandler
Property VScroller As MyCustomNSScroller
Property scrollview As nsscrollViewMBS
Property textView As NSTextViewMBS
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 MyCustomNSScroller Inherits CustomNSScrollerMBS
EventHandler Sub drawArrow(g as NSGraphicsMBS, Arrow as integer, highlight as boolean)
dim w,h,dx As Integer
if Arrow=NSScrollerIncrementArrow then
if IncrArrowImage<>Nil then
// Arrow size and position
IncrArrowRect=Self.rectForPart( NSScrollerIncrementArrow )
// Draw arrow image
w=IncrArrowImage.width
h=IncrArrowImage.height
if highlight then dx=w/2
g.drawInRect IncrArrowImage, DecrArrowRect.X,DecrArrowRect.Y, w,h, dx,0, w,h, NSGraphicsMBS.NSCompositeSourceOver, 1.0
end if
elseif Arrow=NSScrollerDecrementArrow then
if DecrArrowImage<>Nil then
// Arrow size and position
DecrArrowRect=Self.rectForPart( NSScrollerDecrementArrow )
// Draw arrow image
w=IncrArrowImage.width
h=IncrArrowImage.height
if highlight then dx=w/2
g.drawInRect IncrArrowImage, DecrArrowRect.X,DecrArrowRect.Y, w,h, dx,0, w,h, NSGraphicsMBS.NSCompositeSourceOver, 1.0
end if
end if
End EventHandler
EventHandler Sub drawKnob(g as NSGraphicsMBS)
// Knob size and position
knobRect=Self.rectForPart( NSScrollerKnob )
// Draw knob image
if knobImage<>Nil then
dim w,h,hm,rh As Integer
w=knobImage.width
h=knobImage.height
hm=Floor( h/2 )
rh=knobRect.Height
if rh>h then
g.drawInRect knobImage, knobRect.X,knobRect.Y, w,hm, 0,0, w,hm, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // bottom part
g.drawInRect knobImage, knobRect.X,knobRect.Y+hm, w,rh-(hm*2), 0,hm, w,1, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // middle part
g.drawInRect knobImage, knobRect.X,knobRect.Y+rh-hm, w,hm, 0,h-hm, w,hm, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // top part
end if
end if
End EventHandler
EventHandler Sub drawKnobSlotInRect(g as NSGraphicsMBS, slotRect as NSRectMBS, highlight as boolean)
// Draw knob slot image
if knobSlotImage<>Nil then
dim w,h,hm,rh As Integer
w=knobSlotImage.width
h=knobSlotImage.height
hm=Floor( h/2 )
rh=slotRect.Height
if BackColor<>Nil then
g.SetColor BackColor
g.fillRect slotRect.X, slotRect.Y, slotRect.Width, slotRect.Height
end if
if rh>h then
g.drawInRect knobSlotImage, slotRect.X,slotRect.Y, w,hm, 0,0, w,hm, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // bottom part
g.drawInRect knobSlotImage, slotRect.X,slotRect.Y+hm, w,rh-(hm*2), 0,hm, w,1, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // middle part
g.drawInRect knobSlotImage, slotRect.X,slotRect.Y+rh-hm, w,hm, 0,h-hm, w,hm, NSGraphicsMBS.NSCompositeSourceOver, 1.0 // top part
end if
end if
End EventHandler
Note "Thanks"
Thanks to David Della Rocca for sharing this example with us.
Property BackColor As NSColorMBS
Property DecrArrowImage As NSImageMBS
Property Private DecrArrowRect As NSRectMBS
Property IncrArrowImage As NSImageMBS
Property Private IncrArrowRect As NSRectMBS
Property knobImage As NSImageMBS
Property Private knobRect As NSRectMBS
Property knobSlotImage As NSImageMBS
End Class
ExternalFile CustomNSscrollerDarkDecrArrow
End ExternalFile
ExternalFile CustomNSscrollerDarkIncrArrow
End ExternalFile
ExternalFile CustomNSscrollerDarkKnob
End ExternalFile
ExternalFile CustomNSscrollerDarkKnobSlot
End ExternalFile
End Project
The items on this page are in the following plugins: MBS MacFrameworks Plugin.