Live Scroll
-
spacebuddy
- Enthusiast

- Posts: 364
- Joined: Thu Jul 02, 2009 5:42 am
Live Scroll
Is there anyway to enable LiveScroll for the TrackBar GadGet?
Re: Live Scroll
Unfortunately not. OS X supports it but PureBasic doesn't.
As far as I know you can only accomplish this at the moment by using a NSSlider instance instead of a PureBasic gadget.
As far as I know you can only accomplish this at the moment by using a NSSlider instance instead of a PureBasic gadget.
Re: Live Scroll
What is that NSSlider ?
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Live Scroll
When using Cocoa (the default on OS X since PB 5.00), PureBasic extends Cocoa classes to create PureBasic gadgets.
The TrackBar gadget is based on NSSlider ( http://developer.apple.com/library/mac/ ... rence.html ).
NSSlider is able to perform an action when you change it's value. PureBasic uses this to create a PureBasic event but is only able to do so when the mouse button is released.
By using a NSSlider instance directly, you can set your own action method. The drawback is that is more difficult and works outside the PureBasic event loop but the advantage is that you can get change values while keeping the mouse button pressed and dragging the mouse.
The TrackBar gadget is based on NSSlider ( http://developer.apple.com/library/mac/ ... rence.html ).
NSSlider is able to perform an action when you change it's value. PureBasic uses this to create a PureBasic event but is only able to do so when the mouse button is released.
By using a NSSlider instance directly, you can set your own action method. The drawback is that is more difficult and works outside the PureBasic event loop but the advantage is that you can get change values while keeping the mouse button pressed and dragging the mouse.
Re: Live Scroll
This all sound quit similar to what I try to recreate (on XP) in PB-DLL's.
Those should replace similar working stuff of mine already made in GFA32.
(It's not possible to create DLL's in GFA32 and so all is in libraries there.)
Now yeah, just a short story.
Those should replace similar working stuff of mine already made in GFA32.
(It's not possible to create DLL's in GFA32 and so all is in libraries there.)
Now yeah, just a short story.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Live Scroll
Code: Select all
OpenWindow(0, 100, 100, 300, 200, "Test")
ScrollBarGadget(0, 10, 10, 200, 20, 0, 100, 10)
ImportC ""
sel_registerName(str.p-ascii)
class_addMethod(class, selector, imp, types.p-ascii)
EndImport
Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")
ProcedureC Callback(obj, sel, notification)
Debug "Callback()"
EndProcedure
selector = sel_registerName("Callback:")
class_addMethod(delegateClass, selector, @Callback(), "v@:@")
;CocoaMessage(0, GadgetID(0), "setTag:", @Callback())
CocoaMessage(0, GadgetID(0), "setTarget:", appDelegate)
CocoaMessage(0, GadgetID(0), "setAction:", selector)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
CocoaMessage(0, GadgetID(0), "setTarget:", #Null)
CocoaMessage(0, GadgetID(0), "setAction:", #Null)
Niffo
Re: Live Scroll
With different callbacks
With a single callback
Code: Select all
ImportC ""
sel_registerName(str.p-ascii)
class_addMethod(class, selector, imp, types.p-ascii)
EndImport
Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")
PrototypeC ProtoCallback(sender)
ProcedureC ForwardAction(obj, sel, sender)
Protected Callback.ProtoCallback = CocoaMessage(0, sender, "tag")
Callback(sender)
EndProcedure
Global selForwardAction = sel_registerName("forwardAction:")
class_addMethod(delegateClass, selForwardAction, @ForwardAction(), "v@:@")
Procedure SetTargetActionCallback(control, *cbfunction)
CocoaMessage(0, control, "setTag:", *cbfunction)
CocoaMessage(0, control, "setTarget:", appDelegate)
CocoaMessage(0, control, "setAction:", selForwardAction)
EndProcedure
; *** demo ***
ProcedureC TrackBar0Callback(sender)
Debug GetGadgetState(0)
EndProcedure
ProcedureC TrackBar1Callback(sender)
Debug GetGadgetState(1)
EndProcedure
OpenWindow(0, 100, 100, 300, 200, "Test")
TrackBarGadget(0, 10, 10, 200, 20, 0, 100)
TrackBarGadget(1, 10, 40, 200, 20, 0, 10)
SetTargetActionCallback(GadgetID(0), @TrackBar0Callback())
SetTargetActionCallback(GadgetID(1), @TrackBar1Callback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindowCode: Select all
ImportC ""
sel_registerName(str.p-ascii)
class_addMethod(class, selector, imp, types.p-ascii)
EndImport
Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")
PrototypeC ProtoCallback(sender)
ProcedureC ForwardAction(obj, sel, sender)
Protected Callback.ProtoCallback = CocoaMessage(0, sender, "tag")
Callback(sender)
EndProcedure
Global selForwardAction = sel_registerName("forwardAction:")
class_addMethod(delegateClass, selForwardAction, @ForwardAction(), "v@:@")
Procedure SetTargetActionCallback(control, *cbfunction)
CocoaMessage(0, control, "setTag:", *cbfunction)
CocoaMessage(0, control, "setTarget:", appDelegate)
CocoaMessage(0, control, "setAction:", selForwardAction)
EndProcedure
; *** demo ***
ProcedureC Callback(sender)
If sender = GadgetID(0)
Debug "TrackBarGadget 0"
ElseIf sender = GadgetID(1)
Debug "TrackBarGadget 1"
EndIf
EndProcedure
OpenWindow(0, 100, 100, 300, 200, "Test")
TrackBarGadget(0, 10, 10, 200, 20, 0, 100)
TrackBarGadget(1, 10, 40, 200, 20, 0, 10)
SetTargetActionCallback(GadgetID(0), @Callback())
SetTargetActionCallback(GadgetID(1), @Callback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Last edited by wilbert on Fri Feb 08, 2013 6:58 pm, edited 1 time in total.
Re: Live Scroll
Niffo and Wilbert,
thank you for your nice examples. But a small hint for Wilbert's examples: Prototype should be changed to PrototypeC because otherwise both examples will crash on PB 5.10 x86!
thank you for your nice examples. But a small hint for Wilbert's examples: Prototype should be changed to PrototypeC because otherwise both examples will crash on PB 5.10 x86!
Re: Live Scroll
You are right Shardik
I changed it.
I changed it.

