[MacRuby-devel] NSImage issue?
Brad Wilson
brad at lucky-dip.net
Thu Nov 13 02:13:09 PST 2008
Sorry few typos in there, the only one that really matters is that the
method call should be:
icon.drawInRect(rect, fromRect:NSZeroRect,
operation:NSCompositeSourceOver, fraction:1.0)
On 13/11/2008, at 9:09 PM, Brad Wilson wrote:
> I think there's a problem with your method call. If you look at the
> cocoa doc is has a selector with the signature:
> drawInRect:fromRect:operation:fraction.
>
> To call that from MacRuby you'd want to do something like:
> icon.drawInRect(rect, fromRect:NSZeroRect,
> operationNSCompositeSourceOver, fraction:1.0.
>
> See the way the named arguments line up? That'll work for any cocoa
> call. There's some discussion on the MacRuby tutorial under "Sending
> Messages" at http://www.macruby.org/trac/wiki/MacRubyTutorial
>
>
> Another tip I got from somebody on the list:
> object.methods(true, true) will give you a list of all methods on an
> object, including objective-c methods. That might help in future if
> you're not sure what the method call should be.
>
> Hope that helps.
>
> Brad
>
>
> On 13/11/2008, at 8:11 PM, pedro gutierrez wrote:
>
>> 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.
>>
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20081113/65e9bdd1/attachment.html>
More information about the MacRuby-devel
mailing list