[MacRuby-devel] NSImage issue?

pedro gutierrez pedrogutierrez at mac.com
Thu Nov 13 01:11:50 PST 2008


Hi everybody,

This is my first message to the mailing list, I am a newbie in Cocoa  
so please bear with me...

In my first serious MacRuby project,  I have subclassed  
NSTextFieldCell and I have redefined drawInteriorWithFrame with the  
following code:

	def drawInteriorWithFrame( rect, inView:view )
		
		icon = NSImage.imageNamed( "example" )
		
		puts icon.methods.join( " " )
		puts "icon is valid: #{icon.isValid} and has size #{icon.size}"
		
		icon.drawInRect( rect, NSZeroRect, NSCompositeSourceOver, 1.0 )
	
	end

(i.e: I am just trying to draw an icon)

Here is what I get from the console:

[Session started at 2008-11-13 09:01:01 +0000.]
gem __super_objc_send__ enum_for to_enum object_id __id__  
define_singleton_method public_method method display extend  
respond_to? public_send send __send__ instance_exec instance_eval  
__native__? tap is_a? kind_of? instance_of? instance_variable_defined?  
instance_variable_set instance_variable_get instance_variables  
public_methods private_methods protected_methods singleton_methods  
methods inspect to_s frozen? freeze untaint tainted? taint dup clone  
eql? !~ =~ === nil? != ! equal? == hash
icon is valid: true and has size #<NSSize width=30.0 height=24.0>
/Users/sicozu/Projects/iAmbient/build/Release/iAmbient.app/Contents/ 
Resources/PlaylistCell.rb:26:in `drawInteriorWithFrame:inView:':  
undefined method `drawInRect' for #<NSImage:0x10f2480> (NoMethodError)
	from /Users/sicozu/Projects/iAmbient/build/Release/iAmbient.app/ 
Contents/Resources/PlaylistCell.rb:15:in `drawWithFrame:inView:'
	from /Users/sicozu/Projects/iAmbient/build/Release/iAmbient.app/ 
Contents/Resources/PlaylistCell.rb:15:in `drawWithFrame:inView:'
	from /Users/sicozu/Projects/iAmbient/build/Release/iAmbient.app/ 
Contents/Resources/rb_main.rb:22:in `NSApplicationMain'
	from /Users/sicozu/Projects/iAmbient/build/Release/iAmbient.app/ 
Contents/Resources/rb_main.rb:22:in `<main>'

Can anybody please give me a hint of what I am doing wrong? Shouldn't  
I expect my instance of NSImage to respond to :drawInRect?

And by the way,  thanks a lot for this sweet MacRuby project !!
Cheers,
Pedro.




More information about the MacRuby-devel mailing list