Live Scroll

Mac OSX specific forum
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Live Scroll

Post by spacebuddy »

Is there anyway to enable LiveScroll for the TrackBar GadGet?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Live Scroll

Post 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.
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Live Scroll

Post by Joris »

What is that NSSlider ?
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Live Scroll

Post 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.
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Live Scroll

Post 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.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Niffo
Enthusiast
Enthusiast
Posts: 504
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: Live Scroll

Post 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)
Niffo
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Live Scroll

Post 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
Last edited by wilbert on Fri Feb 08, 2013 6:58 pm, edited 1 time in total.
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Live Scroll

Post 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!
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Live Scroll

Post by wilbert »

You are right Shardik :)
I changed it.
Post Reply