[PB Cocoa] Cocoa companion library

Mac OSX specific forum
User avatar
Shardik
Addict
Addict
Posts: 2064
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [PB Cocoa] Cocoa companion library

Post by Shardik »

As Wilbert correctly describes it, it's really a bit complicated because of PureBasic's internal toolbar implementation. PureBasic always adds a flexible space, a space and a separator (on Snow Leopard but not on Mavericks!) behind the last visible toolbar button. You may inspect this by executing the following code which enables you to customize your toolbar and by the way see all visible and invisible items which PureBasic always adds to your toolbar:

Code: Select all

#SilkThemePath = #PB_Compiler_Home + "Themes/"
#IconNameList = "disk.png+delete.png+arrow_left.png+arrow_right.png"

UsePNGImageDecoder()
UseZipPacker()

OpenWindow(0, 270, 100, 290, 50, "Customizable toolbar")
CreateToolBar(0, WindowID(0))

If OpenPack(0, #SilkThemePath + "SilkTheme.zip")
  *ImageBuffer = AllocateMemory(1024)

  If ExaminePack(0)
    For i = 0 To CountString(#IconNameList, "+")
      ImageSize = UncompressPackMemory(0, *ImageBuffer, MemorySize(*ImageBuffer),
        StringField(#IconNameList, i + 1, "+"))

      If ImageSize > 0
        If CatchImage(i, *ImageBuffer, ImageSize)
          ToolBarImageButton(i, ImageID(i))

          If i = 2
            ToolBarSeparator()
          EndIf
        EndIf
      EndIf
    Next i
  EndIf

  FreeMemory(*ImageBuffer)
EndIf

; ----- Display dialog to customize toolbar
CocoaMessage(0, ToolBarID(0), "runCustomizationPalette:", ToolBarID(0))

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Also keep in mind that these PureBasic internals may change with new releases, so please use the following hackish solution with care:

Code: Select all

#NSToolbarSizeModeRegular = 1

OpenWindow(0, 270, 100, 350, 200, "ToolBar with button at right end")

CreateImage(0, 24, 24)

StartDrawing(ImageOutput(0))
  Box(0, 0, 24, 24, $FF0000)
  Box(4, 4, 16, 16, $FFFF)
StopDrawing()

CreateImage(1, 24, 24)

StartDrawing(ImageOutput(1))
  Box(0, 0, 24, 24, $FF)
  Box(4, 4, 16, 16, $FFFF)
StopDrawing()

CreateToolBar(0, WindowID(0))

CocoaMessage(0, ToolBarID(0), "setSizeMode:", #NSToolbarSizeModeRegular)

ToolBarImageButton(0, ImageID(0))
ToolBarImageButton(1, ImageID(1))

; ----- Count visible and invisible toolbar items
ItemCount = CocoaMessage(0, CocoaMessage(0, ToolBarID(0), "items"), "count")

If OSVersion() <= #PB_OS_MacOSX_10_6
  ; ----- Remove rightmost separator
  CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
  ItemCount - 1
EndIf

; ----- Remove rightmost space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1

; ----- Remove rightmost flexible space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1

; ----- Insert flexible space between 1st and 2nd button
CocoaMessage(0, ToolBarID(0),
  "insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem",
  "atIndex:", 1)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

Another option might be to create a Toolbar yourself from the NSToolbar class but that also means defining all the required delegate methods.
Windows (x64)
Raspberry Pi OS (Arm64)
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

Ok thanks
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

Could someone sticky this? I think it's a must have for OS X users.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

Hello,

I returned to you because when I add the parameter # PB_ToolBar_Toggle my ToolBarImageButton () it does not seem to work. Do you have an idea of the problem? Thank you in advance.

Code: Select all

If OpenWindow(0, 0, 0, 600, 200, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  StringGadget(0, 0, 0, 96, 32, "")
  
  CreateImage(0, 32, 32)
  StartDrawing(ImageOutput(0))
  Box(0,0,32,32,RGB(255,255,255))
  Box(4,4,24,24,RGB(255,0,0))
  StopDrawing()
  
  CreateToolBar(0, WindowID(0))
  TB_ID = ToolBarID(0)
  ToolBar_SetMode(TB_ID, 1, 1)
  
  ToolBarImageButton(0, ImageID(0), #PB_ToolBar_Toggle)
  Item = ToolBar_ItemAtIndex(TB_ID, 0)
  ToolBar_SetItemLabel(Item, "Button")
  
  ToolBarImageButton(1, ImageID(0))
  Item = ToolBar_ItemAtIndex(TB_ID, 1)
  ToolBar_SetItemLabel(Item, "String gadget")
  ToolBar_SetItemGadget(Item, GadgetID(0))
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
  
EndIf
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

metalos wrote:when I add the parameter # PB_ToolBar_Toggle my ToolBarImageButton () it does not seem to work.
It looks like this is a PureBasic bug.
The optional #PB_ToolBar_Toggle doesn't seem to do anything.
You could post a bug report in the bugs section of the forum.
Windows (x64)
Raspberry Pi OS (Arm64)
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

I just mentioned. Thank you.
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

Missing a couple of files on build...

Code: Select all

Last login: Mon Jun  9 17:34:56 on ttys000
Joseph-Bakers-MacBook-Air:~ jbaker$ /Users/jbaker/Documents/Cocoa/PBCocoa64/PBUserlib/build.command ; exit;
cp: /Users/jbaker/Documents/Cocoa/PBCocoa64/build/PBCocoa.build/Release/PBCocoa.build/Objects-normal/i386/libPBCocoa.a: No such file or directory
cp: /Users/jbaker/Documents/Cocoa/PBCocoa64/build/PBCocoa.build/Release/PBCocoa.build/Objects-normal/x86_64/libPBCocoa.a: No such file or directory
Can't open the main file: libPBCocoa_x86.a
Can't open the main file: libPBCocoa_x64.a
rm: *.zip: No such file or directory
  adding: libPBCocoa_x64 (deflated 66%)
  adding: libPBCocoa_x86 (deflated 66%)
logout

[Process completed]
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

J. Baker wrote:Missing a couple of files on build...
Do you also have this problem with other user libraries Joe ?
Maybe it is related to using Yosemite.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

wilbert wrote:
J. Baker wrote:Missing a couple of files on build...
Do you also have this problem with other user libraries Joe ?
Maybe it is related to using Yosemite.
The last lib I tried was with TailBite. That's been a while. I'm actually on Snow Leopard. I thought that maybe those directories and files were missing from the source? Or is there something else I'm missing or should be doing?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

removed

EDIT: I got it. I had to remove the fullscreen code as I'm using an earlier version of xcode. ;)
Last edited by J. Baker on Tue Jun 10, 2014 6:53 pm, edited 1 time in total.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

I haven't compiled the libs in a while.
It's possible with a new version of XCode the file locations changed where the .a files are put.
I'll take a look at it tomorrow.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

wilbert wrote:I haven't compiled the libs in a while.
It's possible with a new version of XCode the file locations changed where the .a files are put.
I'll take a look at it tomorrow.
No worries Wilbert, I got it. The fullscreen code was giving me error since I was using Xcode 3.2.6 on Snow Leopard, so I removed it. All is fine now. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

I'm not exactly sure what you are saying Joe.
Did you solve it by not using the library and use CocoaMessage instead for the fullscreen or did you got the library to compile after all ?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

wilbert wrote:I'm not exactly sure what you are saying Joe.
Did you solve it by not using the library and use CocoaMessage instead for the fullscreen or did you got the library to compile after all ?
I rebuilt the lib but had to remove the fullscreen code. It was giving me error but I didn't need it anyway. The fullscreen code probably just needed modified as you gave me a fullscreen code for Sprite Monkey a while back that compiles just fine in Snow Leopard.

The reasoning on compiling a new lib was to change the OSD backgrounds alpha from 0.4 to 0.8. It was just too transparent and sometimes I couldn't read the text depending on what was in the background. Now when you save a project or script in Sprite Monkey, you don't have to click "ok" on a message requester. The OSD displays either "Project Saved" or "Script Saved" for a second.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply