Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/HUDObjects/HUDControls
Function:
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/HUDObjects/HUDControls
This example is the version from Sun, 17th Mar 2012.
Project "HUDControls.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() if not TargetCocoa then MsgBox "This example requires Cocoa." end if End EventHandler
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Window2.show End EventHandler
End Control
End Class
Class Window2 Inherits Window
Control HUDPopupMenu1 Inherits HUDPopupMenu
ControlInstance HUDPopupMenu1 Inherits HUDPopupMenu
End Control
Control HUDPopupMenu2 Inherits HUDPopupMenu
ControlInstance HUDPopupMenu2 Inherits HUDPopupMenu
End Control
Control HUDCheckbox1 Inherits HUDCheckbox
ControlInstance HUDCheckbox1 Inherits HUDCheckbox
End Control
Control HUDSlider1 Inherits HUDSlider
ControlInstance HUDSlider1 Inherits HUDSlider
EventHandler Sub valueChanged(mvalue as single) Label1.Text=str(me.Value) End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control HUDButton1 Inherits HUDButton
ControlInstance HUDButton1 Inherits HUDButton
EventHandler Sub Action() msgbox "ok" End EventHandler
End Control
Control HUDButton2 Inherits HUDButton
ControlInstance HUDButton2 Inherits HUDButton
EventHandler Sub Action() window2.close End EventHandler
End Control
Control HUDButton3 Inherits HUDButton
ControlInstance HUDButton3 Inherits HUDButton
EventHandler Sub Action() msgbox str(HUDPopupMenu1.ListIndex) End EventHandler
End Control
Control HUDButton4 Inherits HUDButton
ControlInstance HUDButton4 Inherits HUDButton
EventHandler Sub Action() HUDPopupMenu1.ListIndex=1 End EventHandler
End Control
Control HUDButton5 Inherits HUDButton
ControlInstance HUDButton5 Inherits HUDButton
EventHandler Sub Action() HUDCheckbox1.Value=not HUDCheckbox1.Value End EventHandler
End Control
Control HUDButton6 Inherits HUDButton
ControlInstance HUDButton6 Inherits HUDButton
EventHandler Sub Action() HUDSlider1.Minimum=25 End EventHandler
End Control
Control HUDButton7 Inherits HUDButton
ControlInstance HUDButton7 Inherits HUDButton
EventHandler Sub Action() HUDSlider1.Value=50 End EventHandler
End Control
Control HUDButton8 Inherits HUDButton
ControlInstance HUDButton8 Inherits HUDButton
EventHandler Sub Action() HUDPopupMenu1.AddRows (array("rijtje extra","weer eentje","jawel nog eentje")) End EventHandler
End Control
Control HUDButton9 Inherits HUDButton
ControlInstance HUDButton9 Inherits HUDButton
EventHandler Sub Action() HUDPopupMenu1.DeleteAllRows End EventHandler
End Control
Control HUDButton10 Inherits HUDButton
ControlInstance HUDButton10 Inherits HUDButton
EventHandler Sub Action() msgbox str(HUDSlider1.Value) End EventHandler
End Control
Control HUDButton11 Inherits HUDButton
ControlInstance HUDButton11 Inherits HUDButton
EventHandler Sub Action() HUDSlider1.Value=0 End EventHandler
End Control
Control HUDButton12 Inherits HUDButton
ControlInstance HUDButton12 Inherits HUDButton
EventHandler Sub Action() HUDSlider1.Maximum=75 End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() msgbox str(HUDPopupMenu1.ListCount) End EventHandler
End Control
Sub Constructor() // Calling the overridden superclass constructor. Super.Constructor dim styleMask as integer dim BackingStoreType as integer=2 styleMask = BitwiseOr(styleMask, NSWindowMBS.NSTitledWindowMask) // with title bar styleMask = BitwiseOr(styleMask, NSWindowMBS.NSClosableWindowMask) // with close button styleMask = BitwiseOr(styleMask, NSWindowMBS.NSMiniaturizableWindowMask) // with minimize button styleMask = BitwiseOr(styleMask, NSWindowMBS.NSResizableWindowMask) // with resize gadget styleMask = BitwiseOr(styleMask, NSPanelMBS.NSHUDWindowMask) // make it HUD styleMask = BitwiseOr(styleMask, NSPanelMBS.NSUtilityWindowMask) // and make it a palette // This project requires Mac OS X 10.6 or newer. Self.NSWindowMBS.styleMask=styleMask Self.NSWindowMBS.backingType=BackingStoreType Self.NSWindowMBS.setContentBorderThickness( 4.0, NSWindowMBS.NSMinYEdge ) End Sub
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 HUDPopupMenu Inherits Canvas
ComputedProperty ListIndex As Integer
Sub Set() mListIndex = value ActiveName=NthField(InitialValue,endofline,mListIndex+1) me.Invalidate End Set
Sub Get() return mListIndex End Get
End ComputedProperty
ComputedProperty Text As String
Sub Get() return ActiveName End Get
End ComputedProperty
Event Change() End Event
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean Pushed=true me.Invalidate dim last as integer // // initialize items // Dim MyMenu as New MenuItem last=CountFields(InitialValue,endofline) For i as integer=1 to last MyMenu.Append(new MenuItem(NthField(InitialValue,endofline,i))) if i-1 = ListIndex then MyMenu.item(i-1).Checked=true else MyMenu.item(i-1).Checked=false end if Next Dim Item as MenuItem = MyMenu.PopUp(window2.left+self.left+2,window2.top+self.top+6) // // initialize items // Pushed=false me.Invalidate If not (Item = Nil) Then for tel as integer = 0 to MyMenu.Count-1 if item.text = MyMenu.Item(tel).Text then mListIndex=tel ActiveName=item.text exit end if next tel end if return true End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer) Change() End EventHandler
EventHandler Sub Open() ActiveName=NthField(InitialValue,endofline,mlistindex+1) ListCount=CountFields(InitialValue,endofline) End EventHandler
EventHandler Sub Paint(g As Graphics) if not self.pushed then g.DrawPicture hudpopupleftactive,0,0 for x as integer = 6 to me.width-20 g.DrawPicture hudpopupmiddleactive,x,0 next x g.DrawPicture hudpopuprightactive,me.width-19,0 else g.DrawPicture hudpopupleftpush,0,0 for x as integer = 6 to me.width-20 g.DrawPicture hudpopupmiddlepush,x,0 next x g.DrawPicture hudpopuprightpush,me.width-19,0 end if g.ForeColor = rgb(240,240,240) //g.TextFont="SmallSystem" g.TextSize=10 g.DrawString ActiveName,10,13,me.width-25,true End EventHandler
Sub AddRow(newItem as string) If InitialValue = "" then InitialValue=InitialValue+newItem ActiveName=newItem else InitialValue=InitialValue+endofline+newItem end if ListCount=CountFields(InitialValue,endofline) me.Invalidate End Sub
Sub AddRows(lijst() as string) For i as integer =0 to Ubound(lijst) if InitialValue="" then InitialValue=InitialValue+lijst(i) else InitialValue=InitialValue+endofline+lijst(i) end if Next ActiveName=NthField(InitialValue,endofline,mListIndex+1) ListCount=CountFields(InitialValue,endofline) me.Invalidate End Sub
Sub DeleteAllRows() InitialValue="" Activename="" ListIndex=0 ListCount=CountFields(InitialValue,endofline) me.Invalidate End Sub
Note "Info"
Code by Christophe De Vocht You may use this in your apps as long you give credits. :-) If you add other controls or improvements : please send it to christophe.devocht@telenet.be
Property ActiveName As string
Property InitialValue As string
Property ListCount As Integer
Property Pushed As Boolean
Property Private mListIndex As Integer
End Class
Class HUDCheckbox Inherits Canvas
ComputedProperty Value As Boolean
Sub Set() mValue = value me.Invalidate End Set
Sub Get() return mValue End Get
End ComputedProperty
Event Action() End Event
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean me.pushed=true me.Invalidate app.DoEvents(35) me.Pushed=false me.mValue= not me.mValue me.Invalidate return true End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer) action() End EventHandler
EventHandler Sub Paint(g As Graphics) if not self.mvalue then if pushed then g.DrawPicture HUDCheckboxOFFPushed,0,0 end if g.DrawPicture HUDCheckboxOFFActive,0,0 else if pushed then g.DrawPicture HUDCheckboxONPushed,0,0 end if g.DrawPicture HUDCheckboxONActive,0,0 end if g.ForeColor = rgb(240,240,240) g.DrawString Caption,20,11,self.width-57,true End EventHandler
Note "Info"
Code by Christophe De Vocht You may use this in your apps as long you give credits. :-) If you add other controls or improvements : please send it to christophe.devocht@telenet.be
Property Caption As string
Property Pushed As Boolean
Property Private mValue As Boolean
End Class
Class HUDSlider Inherits Canvas
ComputedProperty Maximum As single
Sub Set() try mMaximum = value knobX=(mvalue-mminimum)*(width-HUDSliderKnobRound.width)/(mmaximum-mminimum) UpdateValueSetter me.Invalidate catch end try End Set
Sub Get() return mMaximum End Get
End ComputedProperty
ComputedProperty Minimum As single
Sub Set() try mMinimum = value knobX=(mvalue-mminimum)*(width-HUDSliderKnobRound.width)/(mmaximum-mminimum) UpdateValueSetter me.Invalidate catch end try End Set
Sub Get() return mMinimum End Get
End ComputedProperty
ComputedProperty value As Integer
Sub Set() try if value < mMinimum then mvalue=mMinimum else mvalue = value end if //msgbox str(mvalue) knobX=(mvalue-mminimum)*(width-HUDSliderKnobRound.width)/(mmaximum-mminimum) UpdateValueSetter me.Invalidate catch end try End Set
Sub Get() return mvalue End Get
End ComputedProperty
Event valueChanged(mvalue as single) End Event
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean return true End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer) knobX=X-HUDSliderKnobRound.width/2 if knobX<0 then knobX=0 if knobX>width-HUDSliderKnobRound.width then knobX=width-HUDSliderKnobRound.width UpdateValue End EventHandler
EventHandler Sub Open() mvalue = value lastValue=-1 //knobX=mvalue*(mmaximum-mminimum)/(width-HUDSliderKnobRound.width)+mminimum knobX=mvalue*((width-HUDSliderKnobRound.width)+mminimum)/(mmaximum-mminimum) UpdateValueSetter End EventHandler
EventHandler Sub Paint(g As Graphics) g.DrawPicture HUDSliderTrackleftCap,0,3 for x as integer = 3 to me.width-4 g.DrawPicture HUDSliderTrackfill,x,3 next x g.DrawPicture HUDSliderTrackrightCap,me.width-3,3 g.DrawPicture HUDSliderKnobRound,knobX,0 End EventHandler
Private Sub UpdateValue() mvalue=knobX*(mmaximum-mminimum)/(width-HUDSliderKnobRound.width)+mminimum if mvalue<>lastValue then valueChanged(mvalue) lastValue=mvalue me.Invalidate end if End Sub
Private Sub UpdateValueSetter() if mvalue<>lastValue then valueChanged(mvalue) lastValue=mvalue me.Invalidate end if End Sub
Note "Info"
Code by Christophe De Vocht You may use this in your apps as long you give credits. :-) If you add other controls or improvements : please send it to christophe.devocht@telenet.be
Property Knobx As single
Property Private lastValue As single
Property Private mMaximum As single
Property Private mMinimum As single
Property Private mvalue As Integer
End Class
Class HUDButton Inherits canvas
Event Action() End Event
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean pushed=true me.Invalidate app.DoEvents(10) pushed=false me.Invalidate return true End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer) action() End EventHandler
EventHandler Sub Paint(g As Graphics) if not pushed then g.DrawPicture butleftactive,0,0 for a as integer = 10 to me.Width-11 g.DrawPicture butmiddleactive,a,0 next a g.DrawPicture butrightactive,me.width-10,0 else g.DrawPicture butleftpush,0,0 for a as integer = 10 to me.Width-11 g.DrawPicture butmiddlepush,a,0 next a g.DrawPicture butrightpush,me.width-10,0 end if g.ForeColor = rgb(240,240,240) g.DrawString Caption,me.width/2-g.StringWidth(Caption)/2,13 End EventHandler
Note "Info"
Code by Christophe De Vocht You may use this in your apps as long you give credits. :-) If you add other controls or improvements : please send it to christophe.devocht@telenet.be
Property Caption As String
Property Pushed As Boolean
End Class
ExternalFile butleftactive
End ExternalFile
ExternalFile butleftpush
End ExternalFile
ExternalFile butmiddleactive
End ExternalFile
ExternalFile butmiddlepush
End ExternalFile
ExternalFile butrightactive
End ExternalFile
ExternalFile butrightpush
End ExternalFile
ExternalFile HUDCheckboxOFFActive
End ExternalFile
ExternalFile HUDCheckboxOFFPushed
End ExternalFile
ExternalFile HUDCheckboxONActive
End ExternalFile
ExternalFile HUDCheckboxONPushed
End ExternalFile
ExternalFile hudpopupleftactive
End ExternalFile
ExternalFile hudpopupleftpush
End ExternalFile
ExternalFile hudpopupmiddleactive
End ExternalFile
ExternalFile hudpopupmiddlepush
End ExternalFile
ExternalFile hudpopuprightactive
End ExternalFile
ExternalFile hudpopuprightpush
End ExternalFile
ExternalFile HUDSliderTrackfill
End ExternalFile
ExternalFile HUDSliderTrackleftCap
End ExternalFile
ExternalFile HUDSliderTrackrightCap
End ExternalFile
ExternalFile HUDSliderKnobRound
End ExternalFile
End Project

Feedback, Comments & Corrections

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





Links
MBS Xojo Chart Plugins