[Openmcl-devel] NSSlider not responsive
osei.poku at gmail.com
Sat Feb 2 06:56:23 UTC 2008
I have two objects on my window.
(a) A custom view that I subclass as Model and successfully draw a
(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))
(objc:defmethod (#/drawRect: :void) ((self model) (rect :<NSR>ect))
(let ((r (ns:make-ns-rect 10 10 (model-value self) 100)))
(#/setFill (#/blueColor ns:ns-color))
(#/setStroke (#/redColor ns:ns-color))
(#/strokeRect: ns:ns-bezier-path r))))
(defclass window-controller (ns:ns-object)
((model :foreign-type :id :accessor model)
(slider :foreign-type :id :accessor slider))
(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.
More information about the Openmcl-devel