Page 6 of 7

Re: [PB Cocoa] Cocoa companion library

Posted: Fri Mar 21, 2014 3:40 pm
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

Re: [PB Cocoa] Cocoa companion library

Posted: Fri Mar 21, 2014 3:56 pm
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.

Re: [PB Cocoa] Cocoa companion library

Posted: Mon Mar 24, 2014 9:21 pm
by metalos
Ok thanks

Re: [PB Cocoa] Cocoa companion library

Posted: Thu Apr 17, 2014 12:39 am
by J. Baker
Could someone sticky this? I think it's a must have for OS X users.

Re: [PB Cocoa] Cocoa companion library

Posted: Thu May 15, 2014 9:49 am
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

Re: [PB Cocoa] Cocoa companion library

Posted: Fri May 16, 2014 5:48 am
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.

Re: [PB Cocoa] Cocoa companion library

Posted: Fri May 16, 2014 2:58 pm
by metalos
I just mentioned. Thank you.

Re: [PB Cocoa] Cocoa companion library

Posted: Mon Jun 09, 2014 10:43 pm
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]

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Jun 10, 2014 5:19 am
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.

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Jun 10, 2014 5:32 am
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?

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Jun 10, 2014 6:32 pm
by J. Baker
removed

EDIT: I got it. I had to remove the fullscreen code as I'm using an earlier version of xcode. ;)

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Jun 10, 2014 6:50 pm
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.

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Jun 10, 2014 7:13 pm
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. ;)

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Jun 10, 2014 7:19 pm
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 ?

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Jun 10, 2014 7:36 pm
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.