[Implemented] Native Icons/Bitmaps/Images in Menu Items

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

[Implemented] Native Icons/Bitmaps/Images in Menu Items

Post by Straker »

It would be nice if we could do something like:

Code: Select all

MyImage.l = LoadImage(#PB_Any, "~/myimage.png")
MenuItem(1, "Open", MyImage.l)
I know there are a lot of examples for Windows but I have been unable to get this to work in Linux. Since ICONS/BITMAPS are native in GTK menus, it only seems logical that they can be added.

If I am way off base or missing something, please let me know. Or if you agree with me, please reply below.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Yes i agree with this request, maybe for PB4.1...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The problem is on windows, to add Icons you have to draw the entire menu yourself.
(and account for any system setting that may change menu looks & behaviour.)

I did it for the IDE, and it was a pain to do and still some people claim it does not look/react like other menus.
So i think it won't be added, sorry.
quidquid Latine dictum sit altum videtur
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Native, not ownerdrawn menu with icons in Windows. :twisted:

Code: Select all

Global Current

Procedure MenuItemEx(MenuItemID, Text$, MemoryAddress)
  Current = MenuItemID
  MenuItem(MenuItemID, Text$)
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    If MemoryAddress <> 0
      myBitmap = CatchImage(#PB_Any, MemoryAddress)
      myBitmap = ResizeImage(myBitmap, GetSystemMetrics_(#SM_CXMENUCHECK), GetSystemMetrics_(#SM_CYMENUCHECK), #PB_Image_Smooth)
      SetMenuItemBitmaps_(MenuID(), MenuItemID, 0, myBitmap, myBitmap)
    EndIf
  CompilerEndIf
EndProcedure

OpenWindow(0, 150, 150, 320, 240, #PB_Window_SystemMenu, "PureBasic - Windows BMP Menu")

If CreateMenu(0, WindowID())
  MenuTitle("&File")
    MenuItemEx( 1, "&Load...",    ?IconOpen)
    MenuItemEx( 2, "&Save",       ?IconSave)
    MenuItemEx( 3, "Save &As...", 0)
    MenuBar()
    MenuItemEx( 4, "&Quit",       ?IconQuit)
  MenuTitle("&Edit")
    OpenSubMenuEx("Basic",        ?IconCut)
      MenuItemEx( 5, "Cut",       ?IconCut)
      MenuItemEx( 6, "Copy",      ?IconCopy)
      MenuItemEx( 7, "Paste",     ?IconPaste)
    CloseSubMenu()
    OpenSubMenu("Font")
      MenuItemEx( 8, "Tahoma",    0)
  MenuTitle("&Information")
    MenuItemEx(11, "&About",      ?IconAbout)
EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_EventMenu
      Select EventMenuID()
        Case 11 ;About
          MessageRequester("About", "Really Cool Menu Example", 64)
        Case 7 ;Quit
          Quit = 1       
        Default
          MessageRequester("Info", "MenuItem: "+Str(EventMenuID()), 0)
      EndSelect

      Case #PB_Event_CloseWindow
        Quit = 1
  EndSelect
Until Quit = 1

End


IconSave: IncludeBinary "save.bmp"
IconOpen: IncludeBinary "open.bmp"
IconQuit: IncludeBinary "quit.bmp"
IconAbout:IncludeBinary "about.bmp"
IconCut:  IncludeBinary "cut.bmp"
IconCopy: IncludeBinary "copy.bmp"
IconPaste:IncludeBinary "paste.bmp"
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

@freak: I understand, just give me a little help in the future when I post my experiments with GTK menus. Will PB 4 for Linux use GTK 2.0 Menu, so we can potentially use "GtkImageMenuItem()" ?


@Trond: Thanks, I have used that in the past.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Trond wrote:Native, not ownerdrawn menu with icons in Windows. :twisted:
Are you of all people trying to tell me that this looks acceptable? I cannot beleive that :P

SetMenuItemBitmaps_() is intended to be used to set a custom check mark,
not place an image next to the text. For one thing it does not look good that
way, and it also renders SetMenuItemState() useless.

Also better read this:
MS Platform SDK wrote:The selected and clear bitmaps should be monochrome. The system uses the Boolean AND operator to combine bitmaps with the menu so that the white part becomes transparent and the black part becomes the menu-item color. If you use color bitmaps, the results may be undesirable.
quidquid Latine dictum sit altum videtur
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It DOES look like rubbish, but it doesn't render the check mark state useless in any way, and my documentation says nothing about whether it should be monochrome or not. Sure, mine is older. In other words, if Microsoft doesn't want to destroy old programs, they need to continue to support my manual with colour bitmaps.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Code: Select all

I did it for the IDE, and it was a pain to do
Maybe it has something to do with a defunct MenuID() in the last stable version?
Post Reply