|
From: Joe J. <dar...@gm...> - 2006-11-12 02:09:35
|
OK, I had to remove the NSView. prefix from the bounds call to get
that line to compile. However, the next line tells me that :
EPView.hs:20:30: Not in scope: `set'
And I'm not sure why it's not in scope because set IS a method of
AppKit.NSColor.
On 11/11/06, David Christensen <dw...@dw...> wrote:
> Joe wrote:
>
> > I am trying to create a custom NSView subclass that, specifically one
> > that overrides drawRect. What I am having a problem with is
> > understanding how to override this function and how to actually get
> > some custom drawing done. Actually, I;m not even sure if my class is
> > being instantiated. I slapped a view into the ExpressionParser window,
> > gave it a custom class with the same name as my class (which would
> > normally be all I would need to do in Cocoa).
>
> Joe,
>
> Here's the source for a more complex view that I wrote in Haskell. I
> can't remember if this compiles/works correctly (it was working at
> one point, but I started tinkering more), but it should give you
> something to go on as far as showing how to declare the draw_rect
> function appropriately.
>
> Of particular note, I believe that I had to export the info_drawRect
> in the $(exportClass) directive in order for the Cocoa system to be
> able to call the haskellized replacement function.
>
> (Also a style note, I was experimenting with some utility functions
> which use unsafePerformIO; said usage is not recommended... :-D)
> Additional disclaimer: this code was written about a year ago, so I'm
> sure there are general improvements which could be made in general.
>
> I might make the following changes to your view, just to see if it
> gives you what you are expecting:
>
> ---
> {-# OPTIONS -fglasgow-exts -fth #-}
>
> module EPView where
>
> import Cocoa
> import AppKit.NSView as NSView hiding (print)
>
> $(declareClass "EPView" "NSView")
>
> $(exportClass "EPView" "ev_"
> [
> InstanceMethod info_drawRect
> ]
> )
>
> obj #. var = obj # getIVar var
>
> ev_drawRect rect self = do
> r <- self # NSView.bounds -- proper instance selection.
> _NSColor # blackColor >>= set -- class selector
> nsRectFill r
> return ()
> ---
>
> Regards,
>
> David Christensen
>
>
>
>
|