Page 1 of 1

Live Scroll

Posted: Tue Feb 05, 2013 12:27 am
by spacebuddy
Is there anyway to enable LiveScroll for the TrackBar GadGet?

Re: Live Scroll

Posted: Tue Feb 05, 2013 8:37 am
by wilbert
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.

Re: Live Scroll

Posted: Tue Feb 05, 2013 9:42 am
by Joris
What is that NSSlider ?

Re: Live Scroll

Posted: Tue Feb 05, 2013 10:14 am
by wilbert
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.

Re: Live Scroll

Posted: Tue Feb 05, 2013 11:22 am
by Joris
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.

Re: Live Scroll

Posted: Fri Feb 08, 2013 12:12 pm
by Niffo

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)

Re: Live Scroll

Posted: Fri Feb 08, 2013 3:24 pm
by wilbert
With different callbacks

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_CloseWindow
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 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

Re: Live Scroll

Posted: Fri Feb 08, 2013 6:57 pm
by Shardik
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!

Re: Live Scroll

Posted: Fri Feb 08, 2013 7:00 pm
by wilbert
You are right Shardik :)
I changed it.