From: Joe J. <dar...@gm...> - 2006-11-12 00:39:27
|
Cool, I'll give that a shot. I didn't know about the AppKit import so I'll add that as well. A few questions: 1) (Serious newbie q) What does the # stand for? I haven't seen that yet in what I have read. 2) For the general audience: Is there any way to make the getIvar code (obj #. var = obj # getIVar var) disappear? This appears in every class and seems like something that could be part of a base class, or part of the template definition (note that I have no idea how the template stuff works so...). 3) In general are all of the NSXxxx functions in Cocoa/Foundation/AppKit prefaced with nsXxxx in Haskell? Thanx, joe 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 > > > > |