Page 1 of 1
[Implemented] Native Icons/Bitmaps/Images in Menu Items
Posted: Wed Feb 22, 2006 1:01 am
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.
Posted: Wed Feb 22, 2006 8:29 am
by Flype
Yes i agree with this request, maybe for PB4.1...
Posted: Wed Feb 22, 2006 1:39 pm
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.
Posted: Wed Feb 22, 2006 4:17 pm
by Trond
Native, not ownerdrawn menu with icons in Windows.
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"
Posted: Wed Feb 22, 2006 4:46 pm
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.
Posted: Wed Feb 22, 2006 5:33 pm
by freak
Trond wrote:Native, not ownerdrawn menu with icons in Windows.
Are you of all people trying to tell me that this looks acceptable? I cannot beleive that
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.
Posted: Wed Feb 22, 2006 6:34 pm
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.
Posted: Thu Feb 23, 2006 6:22 pm
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?