Page 1 of 1

[Mac] Drawing iconForFileType ???

Posted: Mon Mar 07, 2016 11:37 pm
by kenmo
Any Cocoa experts know why this code seems to work in PB 5.31, but not in PB 5.41-42 ???

The ImageID is not null, so maybe it's not a Cocoa Icon issue, maybe it's a PB DrawImage() issue?

Code: Select all

Size = 128
OpenWindow(0, 0, 0, Size, Size, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ImageID = CocoaMessage(0, CocoaMessage(0, 0, "NSWorkspace sharedWorkspace"), "iconForFileType:$", @"txt")
If Not ImageID
  Debug "Failed to get image"
  End
EndIf

CreateImage(0, Size, Size, 32, $c0c0c0)
If StartDrawing(ImageOutput(0))
  DrawImage(ImageID, 0, 0, OutputWidth(), OutputHeight())
  StopDrawing()
EndIf
ImageGadget(0, 0, 0, Size, Size, ImageID(0))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: [Mac] Drawing iconForFileType ???

Posted: Tue Mar 08, 2016 5:42 am
by wilbert
It might be a bug since it works fine with the Vector library.
Maybe Fred can take a look at it.

Working example with Vector library

Code: Select all

Size = 128
OpenWindow(0, 0, 0, Size, Size, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ImageID = CocoaMessage(0, CocoaMessage(0, 0, "NSWorkspace sharedWorkspace"), "iconForFileType:$", @"txt")
If Not ImageID
  Debug "Failed to get image"
  End
EndIf

CreateImage(0, Size, Size, 32, $ffc0c0c0)
If StartVectorDrawing(ImageVectorOutput(0))
  DrawVectorImage(ImageID, 255, VectorOutputWidth(), VectorOutputHeight())
  StopVectorDrawing()
EndIf

ImageGadget(0, 0, 0, Size, Size, ImageID(0))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: [Mac] Drawing iconForFileType ???

Posted: Tue Mar 08, 2016 6:33 pm
by kenmo
I will try DrawVectorImage() on my Mac tonight.

Maybe DrawImage() expects a different Cocoa object now?
NSImage instead of CGImageRef? (I'm just guessing.)

Re: [Mac] Drawing iconForFileType ???

Posted: Tue Mar 08, 2016 9:22 pm
by Shardik
wilbert wrote:It might be a bug since it works fine with the Vector library.
It seems indeed to be a bug in PB 5.42 x86 and x64 because kenmo's example works like a charm in PB 5.31 x86 and x64 (tested on OS X 10.9.5 / Mavericks).

Re: [Mac] Drawing iconForFileType ???

Posted: Thu Apr 21, 2016 3:11 pm
by kenmo
Can this be moved to Mac - Bug Reports?

Thanks again Wilbert for the DrawVectorImage() suggestion.