[Openmcl-devel] NSSlider not responsive

Osei Poku osei.poku at gmail.com
Sat Feb 2 06:56:23 UTC 2008


Hi,

I have two objects on my window.
(a) A custom view that I subclass as Model and successfully draw a  
rectangle inside.
(b) A slider

The simple idea is that the slider value controls the width of the  
rectangle.  This basically works fine however, I cannot drag the  
slider.  I can only click at the value I want it to be and the  
rectangle adjust accordingly.

This is my code.  When the view redraws, the width of the rectangle  
becomes the VALUE slot inside model.  This value slot is set using the  
#/slide method at the bottom. The window controller class is contains  
the two objects in the window (model<my custom view> and slider ).

(defclass model (ns:ns-view)
   ((value :initform 10.0D0 :accessor model-value))
   (:metaclass ns:+ns-object))

(objc:defmethod (#/drawRect: :void) ((self model) (rect :<NSR>ect))
   (ccl::with-autorelease-pool
    (let ((r (ns:make-ns-rect 10 10 (model-value self) 100)))
      (#/setFill (#/blueColor ns:ns-color))
      (#/setStroke (#/redColor ns:ns-color))
      (#_NSRectFill r)
      (#/strokeRect: ns:ns-bezier-path r))))

(defclass window-controller (ns:ns-object)
   ((model :foreign-type :id :accessor model)
    (slider :foreign-type :id :accessor slider))
   (:metaclass ns:+ns-object))

(objc:defmethod #/slide: ((self window-controller) sender)
   (let ((val (#/floatValue sender)))
     (setf (model-value (model self)) val)
     (#/setNeedsDisplay: (model self) t)))

Additionally, any comments about possible memory leaks and in general  
bad openmcl/cocoa bridge/lisp programming are very welcome.

Thanks,

Osei



More information about the Openmcl-devel mailing list