Detecting Retina question

You sound as helpful as ever. As for MBS, with my personal esteem for Christian, I dont use the Monkey plugins.
I’ll try Jim’s approch. He too is very helful and knows his ways among declares.

[quote=206779:@Carlo Rubini]You sound as helpful as ever. As for MBS, with my personal esteem for Christian, I dont use the Monkey plugins.
I’ll try Jim’s approch. He too is very helful and knows his ways among declares.[/quote]
I’m sorry that I cannot provide advice on how to use toolkits that I myself do not use, I’m mealy aware that they exist and guessing on their coverage I’m certain that they’ll enable a Xojo developer to correctly ‘Retinaize’ their application without having to apply hacks and tricks to work around a solution that Apple themselves advise developers not to use.

[quote=206769:@Carlo Rubini]1. in the open event of the NSwindow example:
dim factor as double = m_NSWindow.BackingScaleFactor[/quote]

This is a bad idea since a window can be created on a retina screen then moved to a non-retina screen. It’s better to recompute this value every time in the Paint event before you draw.

@Carlo: this macoslib function?

 Shared Function LoadByName(name as String) As NSImage
  #if targetMacOS
    declare function imageNamed lib CocoaLib selector "imageNamed:" (class_id as Ptr, name as CFStringRef) as Ptr
    
    dim p as Ptr = imageNamed(ClassRef, name)
    if p <> nil then
      return new NSImage(p)
    else
      return nil
    end if
  #endif
End Function

Hi @jim mckay ,

I’ve had someone report a crash while using the RetinaNotifier, getting a KeyNotFoundException. The method NotificationDelegate in your code is this:

[code] if classrefs=nil then Return
if weakref(classrefs.Value(obj)).value=nil then
classrefs.remove(obj)
Return
end if

if classrefs.HasKey(obj) then

dim rn as RetinaNotifier=RetinaNotifier(weakref(classrefs.Value(obj)).value)
rn.BackingScaleFactor=rn.GetBackingScaleFactor

end if[/code]

and I think that the test for classRefs.HasKey should also wrap the first if statement, thus:

[code]
if classrefs=nil then Return
if classrefs.HasKey(obj) then
if weakref(classrefs.Value(obj)).value=nil then
classrefs.remove(obj)
Return
end if
end if

if classrefs.HasKey(obj) then
dim rn as RetinaNotifier=RetinaNotifier(weakref(classrefs.Value(obj)).value)
rn.BackingScaleFactor=rn.GetBackingScaleFactor
end if[/code]

Yes, but for simplicity, it should be written:

[code]

if classrefs<>nil and classrefs.HasKey(obj) then

if weakref(classrefs.Value(obj)).value=nil then
  classrefs.remove(obj)
  Return
end if

dim rn as RetinaNotifier=RetinaNotifier(weakref(classrefs.Value(obj)).value)
rn.BackingScaleFactor=rn.GetBackingScaleFactor

end if[/code]

Also, I think you may have an old version before the close event was added. Be sure you have the following in the close event.

[code] declare function NSClassFromString lib “Cocoa” (classname as CFStringRef) as ptr
declare function defaultCenter lib “Cocoa” selector “defaultCenter” (obj as ptr) as Ptr
Declare Sub removeObserver lib “Cocoa” selector “removeObserver:” (obj_ref as ptr,notificationObserver as Ptr)

removeObserver(defaultCenter(NSClassFromString(“NSNotificationCenter”)),myNotificationReceiver)[/code]

Hi there,
I think that this line:

  if classrefs<>nil and classrefs.HasKey(obj) then

will still go boom if classrefs is nil, because you’re relying on it not being nil for the HasKey test.
So, I think it should be this:

if classrefs<>nil then if classrefs.HasKey(obj) then if weakref(classrefs.Value(obj)).value=nil then classrefs.remove(obj) Return end if dim rn as RetinaNotifier=RetinaNotifier(weakref(classrefs.Value(obj)).value) rn.BackingScaleFactor=rn.GetBackingScaleFactor end if
Close event code noted.

What are you doing that you need to be notified when the backing properties changes?

Either way will work, but the haskey will never be tested if classrefs=nil due to the way ‘and’ is evaluated.

@Sam Rowlands : I’m drawing toolbar icons as either normal or Retina, because they don’t have a Paint event. I note in August you said this was possible with MBS plugins; further info received with interest, because we have the full MBS suite.

@jim mckay : I could’ve sworn I’ve seen errors caused by this before, but that’s good to know. Thanks.

I don’t know the exact details of of doing retina via the MBS, I know it has the fundamentals for doing it correctly.

What you need to look for is a way to use the “imageNamed” function of NSImage and then to set that NSImage as the icon of the toolbar item.

me.seticon 1, retinaKit.imageNamed( "aw3" )

Is the code used with the Retina Kit to set a NSImage onto the toolbar icon, when using the “imageNamed” function you do not specify a file extension, the OS will load the correct artwork when it needs to do so.

Thanks for this. I’m struggling with MBS, I have to say; the toolbar item won’t accept an NSImage as its icon (only a Picture). I’m wondering if I have to make the toolbar as an NSToolbarMBS, then its items as NSToolbarItemMBS, and so on. If so, that’s a bit of a pain, because then I’ll have to have separate code for Mac and Windows.

I think you do it like (MBS)

myWindow.NSToolBarMBS.Items(1).image=myNSImageMBS

Maybe Christian can chime in…

Yes, I seem to at least be able to do that without any exceptions, but sadly the relevant image isn’t drawn in the toolbar. I’m probably staring at the obvious but after a day looking at Retina icons I’m a bit frazzled, so I’ll sleep on it and see if I can work out what’s going on in the morning. Thanks for the help.

If you’re still struggling with Retina in the morning, you can download a trial version of the Retina Kit from http://www.ohanaware.com/retinakit/