Skip to content

Instantly share code, notes, and snippets.

@Airr
Last active December 5, 2016 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Airr/02ed2ff4bf8f4eef1f1a14088a31dfc0 to your computer and use it in GitHub Desktop.
Save Airr/02ed2ff4bf8f4eef1f1a14088a31dfc0 to your computer and use it in GitHub Desktop.
Purebasic OSX Gadget Resize Demo
Enumeration
#akNone
#akRight ; anchor to right side of Window, no resize
#akWidth ; resize width of Gadget, based on width of Window
#akLeft = 4 ; anchor to left side of Window, no resize
#akTop = 8 ; anchor RELATIVE to top of Window, no resize
#akHeight = 16 ; resize height of Gadget, based on height of Window
#akFull = #akWidth | #akHeight ; resize width/height of Gadget, based on width/height of Window
EndEnumeration
Procedure Anchor (handle, value)
Define tmp
Select GadgetType(handle)
Case #PB_GadgetType_Editor, #PB_GadgetType_ListView, #PB_GadgetType_ListIcon, #PB_GadgetType_Tree
; THE GADGETS ABOVE ARE COMPOSED OF PBGADGET->NSCLIPVIEW->NSSCROLLVIEW HIERARCHY
; So we have to retrieve the actual NSScrollView object to resize
tmp = CocoaMessage(0, GadgetID(handle),"enclosingScrollView")
Case #PB_GadgetType_Image
; This will cause the image to scale proportionally
; To scale-to-fit, use "1"
CocoaMessage(0,GadgetID(handle),"setImageScaling:",1)
tmp = GadgetID(handle) ; Live Gadget Auto Resizing Demo
Default
; This is the "CatchAll" for typical PBGadgets
tmp = GadgetID(handle)
EndSelect
; Set the AutoresizingMask for the Gadget
CocoaMessage(0,tmp, "setAutoresizingMask:", value)
EndProcedure
;
; ------------------------------------------------------------
;
; PureBasic - Gadget example file
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
IncludeFile "anchor.pbi"
#WindowWidth = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
WindowBounds(0, #WindowWidth, #WindowHeight, #PB_Default, #PB_Default)
Top = 10
GadgetHeight = 24
FrameGadget(99, 10, Top, 370, 290, "Player...") : Top+20
Anchor(99, #akFull)
StringGadget(0, 20, Top, 200, GadgetHeight, "")
ButtonGadget(1, 223, Top, 72, GadgetHeight, "Play")
ButtonGadget(2, 295, Top, 72, GadgetHeight, "Stop") : Top+35
Anchor(0, #akWidth)
Anchor(1, #akRight)
Anchor(2, #akRight)
DisableGadget(2,1)
GadgetToolTip(1,"Play the current song")
PanelGadget(3, 20, Top, #WindowWidth-40, #WindowHeight-Top-50)
Anchor(3, #akFull)
AddGadgetItem(3, 0, "MP3 PlayList")
ListViewGadget(4, 6, 10, 230, 148)
Anchor(4, #akFull)
For k=0 To 30
AddGadgetItem(4, -1, "Music Song n° "+Str(k))
Next
ButtonGadget(5, 250, 10, 80, GadgetHeight, "Add")
ButtonGadget(6, 250, 38, 80, GadgetHeight, "Remove")
ButtonGadget(7, 250, 66, 80, GadgetHeight, "Select")
Anchor(5, #akRight)
Anchor(6, #akRight)
Anchor(7, #akRight)
GadgetToolTip(7, "Select the current song")
TrackBarGadget(17, 10, 168, 310, 25, 0, 100)
Anchor(17, #akTop | #akWidth)
AddGadgetItem(3, 1, "Options")
Top = 10
CheckBoxGadget(10, 10, Top, 250, GadgetHeight, "Enable low-pass filter") : Top+30
CheckBoxGadget(11, 10, Top, 250, GadgetHeight, "Enable visual plug-in") : Top+30
ComboBoxGadget(12, 10, Top, 250, 21) : Top+30
AddGadgetItem(12, -1, "FireWorks")
AddGadgetItem(12, -1, "OpenGL spectrum")
AddGadgetItem(12, -1, "Bump bass")
SetGadgetState(12,0)
DisableGadget(12,1)
OptionGadget(13, 10, Top, 80, GadgetHeight, "640*480") : Top+20
OptionGadget(14, 10, Top, 80, GadgetHeight, "800*600") : Top+20
OptionGadget(15, 10, Top, 80, GadgetHeight, "1024*768")
SetGadgetState(13, 1)
ButtonGadget(16, 150, Top, 80, GadgetHeight, "Info")
CloseGadgetList()
TextGadget (9, 10, #WindowHeight-30, 250, 24, "PureBasic - Gadget demonstration")
Anchor(9, #akTop)
ButtonGadget(8, #WindowWidth-100, #WindowHeight-36, 80, 24, "Quit")
Anchor(8,#akRight|#akTop)
SetGadgetState(3, 0)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_ReturnKey
MessageRequester("Info", "Return key pressed", 0)
SetActiveGadget(0)
EndIf
Case 1 ; Play
DisableGadget(2,0) ; Enable the 'Stop' gadget
DisableGadget(1,1) ; Disable the 'Play' Gadget
Case 2 ; Stop
DisableGadget(1,0) ; Enable the 'Play' gadget
DisableGadget(2,1) ; Disable the 'Stop' Gadget
Case 4
If EventType() = 2
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
EndIf
Case 5 ; Add
AddGadgetItem(4, -1, "New Item Added...")
Case 6 ; Remove
RemoveGadgetItem(4, GetGadgetState(4)) ; Remove the current element of the ListView
Case 7 ; Select
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
Case 8 ; Quit...
Event = #PB_Event_CloseWindow
Case 11 ; Enable PlugIn..
DisableGadget(12, 1-GetGadgetState(11))
Case 16 ;
If GetGadgetState(13) : Result$ = GetGadgetText(13) : EndIf
If GetGadgetState(14) : Result$ = GetGadgetText(14) : EndIf
If GetGadgetState(15) : Result$ = GetGadgetText(15) : EndIf
MessageRequester("Info", "Selected screen mode: "+Result$, 0)
Case 17
SetGadgetText(0, Str(GetGadgetState(17)))
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment