[Mac] Drawing iconForFileType ???

Mac OSX specific forum
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

[Mac] Drawing iconForFileType ???

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [Mac] Drawing iconForFileType ???

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: [Mac] Drawing iconForFileType ???

Post 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.)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [Mac] Drawing iconForFileType ???

Post 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).
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: [Mac] Drawing iconForFileType ???

Post by kenmo »

Can this be moved to Mac - Bug Reports?

Thanks again Wilbert for the DrawVectorImage() suggestion.
Post Reply