View Single Post
Old 12 July 2021, 03:43   #1
Warty
Registered User
 
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
Using a Custom Image for Amiga A Shortcut Key in Menus

I wanted to use an "A" image for the menu shortcuts that didn't look smushed on 1:1 (640x400 eg) screens.

In the end, I got it working, but I think I am "doing it wrong", at least part of the way.

Process as I understood it:
1. Make an intuition image (image Struct*) with img.ImageData pointing to the custom image you want to use for shortcut.
2. When opening the window, set WA_AmigaKey, and point it at the image from step #1. (you also have to set WA_NewLookMenus=TRUE)
3. When laying out the menu, set GTMN_AmigaKey, and point it at the same image. (you also have to set GTMN_NewLookMenus =TRUE)
...
5. profit!

Reality in my case:
- The default "fat A" remained in place
- The spacing allocated for the image did shrink up to match my image (I used 16 px, I think the default is something like 28). You can see this in the screenshot where the "Select All" bit overlaps the "A". So partially, anyway, it was getting the message about the image.

Workaround:
- I'm definitely not saying this is the right way to do it.
- There is a reference to dri_AmigaKey in the screen's drawInfo struct. This is is what actually gets rendered (I take it), and is supposed to be a scaled version of the shortcut image.
- I tested a bit, and found that if I pointed that at my intuition image from #1 above, BEFORE opening the window, the image would show up in the menus.
- It doesn't scale of course.

... so what's the right away to have done it?

References:
https://wiki.amigaos.net/wiki/GadTools_Menus
EAB post: Is there an app to change the workbench menu imagery?
AutoDoc for OpenWindow
Quote:
WA_AmigaKey - (ti_Data is struct Image *) Image to use as
the Amiga-key symbol in menus. If WA_NewLookMenus is not
specified, the default will be the traditional Amiga-key
symbol in the original colors. If you've requested
WA_NewLookMenus, then the default will be an appropriately
colored Amiga-key scaled to the screen's font.
Alternately, you can provide a custom one, which you can
design yourself or get from sysiclass (use this if your
menu-font is different from the screen's font). (V39)
AutoDoc for LayoutMenus
Quote:
GTMN_NewLookMenus (BOOL) - If you ask for WA_NewLookMenus for your
window, you should ask for this tag as well. This informs GadTools
to use the appropriate checkmark, Amiga-key, and colors. (V39)
GTMN_AmigaKey (struct Image *) - If you are using a custom image for
the Amiga-key in menus (WA_AmigaKey), also pass it to GadTools, so
it can lay the menus out accordingly. (V39)
Code for Creating the image (I load from an IFF, but you can just point ImageData at whatever)
Code:
// load the menu shortcut key image "A"
boolean App_LoadShortCutKeyImage(void)
{
	UBYTE*	shortcut_path = "PROGDIR:resources/menu_shortcutw16_8c.iff";

	global_app->shortcut_image_.LeftEdge = 		0;
	global_app->shortcut_image_.TopEdge = 		0;
	global_app->shortcut_image_.Width = 		16;
	global_app->shortcut_image_.Height = 		8;
	global_app->shortcut_image_.Depth = 		3;
	global_app->shortcut_image_.ImageData =		NULL;
	global_app->shortcut_image_.PlanePick =		0x07;
	global_app->shortcut_image_.PlaneOnOff =	0x00;
	global_app->shortcut_image_.NextImage =		NULL;
	
	if (General_LoadIFFintoIntuitionImage(shortcut_path, &global_app->shortcut_image_, global_app->pref_depth_) == false)
	{
		LOG_ERR(("Window_MakeApp_LoadShortCutKeyImageSpeedBarList %d: loading IFF for menu shortcut key failed", __LINE__));
		return false;
	}
Code for opening window
Quote:
// private: open the backdrop window
boolean Window_OpenBackdrop(WB2KWindow* the_surface, struct Screen* the_screen, struct MsgPort* the_user_port)
{
//UWORD checkered_fill_pattern[] = { 0x5555, 0xAAAA };

if ( (the_surface->draw_info_ = GetScreenDrawInfo(the_screen)) == NULL )
{
LOG_ERR(("Window_OpenBackdrop %d: System request to acquire draw info for gadgets failed", __LINE__));
goto error;
}

// hack attack: try to set dri_AmigaKey myself.
// don't think this is supposed to be how it works. also, this is supposed to point to a pre-scaled image. shortcut_image_ is not scaled.
DEBUG_OUT(("Window_OpenBackdrop: %d: dri_AmigaKey before trying to change: %p", __LINE__, the_surface->draw_info_->dri_AmigaKey));
the_surface->draw_info_->dri_AmigaKey = &global_app->shortcut_image_;
DEBUG_OUT(("Window_OpenBackdrop: %d: dri_AmigaKey after change: %p", __LINE__, the_surface->draw_info_->dri_AmigaKey));
// end hack attack

// Create the window object
the_surface->objects_[MAIN_OID_PRIMARY] = WindowObject,
WA_PubScreen, the_screen,
WA_Title, the_surface->title_,
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
WA_Left, 0,
WA_Top, 0,
WA_Width, the_surface->width_,
WA_Height, the_surface->height_,
WA_MinHeight, WIN_MIN_HEIGHT,
WA_MinWidth, WIN_MIN_WIDTH,
WA_MaxHeight, ~0,
WA_MaxWidth, ~0,
WA_ReportMouse, TRUE,
WA_AutoAdjust, TRUE,
WA_NewLookMenus, TRUE,
WA_Backdrop, TRUE,
WA_Borderless, TRUE,
WA_DetailPen, colorPenPrimary,
WA_BlockPen, colorPenBackground,
WA_SmartRefresh, TRUE,
WA_AmigaKey, (ULONG*)&global_app->shortcut_image_,
WA_IDCMP, IDCMP_VANILLAKEY | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_REFRESHWINDOW | IDCMP_MENUPICK,
WINDOW_AppPort, global_app->launched_app_reply_port_,
WINDOW_SharedPort, the_user_port,
WINDOW_ParentGroup, VGroupObject,
LAYOUT_SpaceOuter, FALSE,
LAYOUT_SpaceInner, FALSE,
LAYOUT_DeferLayout, FALSE,
LAYOUT_BevelStyle, BVS_NONE,
//LAYOUT_FillPattern, &checkered_fill_pattern,
EndGroup,
EndWindow;

// Object creation successful?
if (the_surface->objects_[MAIN_OID_PRIMARY] == NULL)
{
LOG_ERR(("Window_OpenBackdrop %d: Couldn't create window object", __LINE__));
goto error;
}

// Open the window.
if ( (the_surface->window_ = (struct Window*) RA_OpenWindow(the_surface->objects_[MAIN_OID_PRIMARY])) == NULL)
{
LOG_ERR(("Window_OpenBackdrop %d: Couldn't open backdrop window", __LINE__));
goto error;
}

// build menus
if (Menu_BuildMenus(the_surface) == false)
{
LOG_ERR(("Window_OpenBackdrop %d: Build Menus failed", __LINE__));
goto error;
}

// remember the parent surface within the Intuition window structure, so we can get back to it from event handlers
the_surface->window_->UserData = (void*)the_surface;

return true;

error:
return false;
}
Code for building menus
Code:
// build the menus. returns false on any failure. 
boolean Menu_BuildMenus(WB2KWindow* the_surface)
{
	struct Window*	the_window = the_surface->window_;
	
	struct NewMenu	the_menu[] =
	{
		{ NM_TITLE, (const STRPTR)MSG_MenuWorkbench, 		0, 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuWorkbenchAbout, 	0, 0, 0, (APTR)&Menu_HandleWorkbenchAbout},
		{ NM_ITEM, (const STRPTR)MSG_Quit, 					"Q", 0, 0, (APTR)&App_Destroy},

		{ NM_TITLE, (const STRPTR)MSG_MenuFile, 			0, 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileNewFolder,		"N", 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileNew, 			"M", 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileOpen, 			"O", 0, 0, (APTR)&Menu_HandleFileOpen},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileClose, 		"W", 0, 0, (APTR)&Menu_HandleFileClose},
		{ NM_ITEM, NM_BARLABEL, 							0, 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileGetInfo, 		"I", 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileRename, 		"R", 0, 0, (APTR)&Menu_HandleFileRename},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileDuplicate,		"E", 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileDelete, 		"D", 0, 0, 0},
		{ NM_ITEM, NM_BARLABEL, 							0, 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuFileFind,			"F", 0, 0, 0},

		{ NM_TITLE, (const STRPTR)MSG_MenuEdit, 			0, 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuEditCut, 			"X", 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuEditCopy, 			"C", 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuEditPaste, 		"V", 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuEditSelectAll, 	"A", 0, 0, 0},
	
		{ NM_TITLE, (const STRPTR)MSG_MenuView, 			0, 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuViewAsColumns, 	"1", CHECKIT | MENUTOGGLE, 0x0006, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuViewAsList, 		"2", CHECKIT | MENUTOGGLE, 0x0005, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuViewAsIcons, 		"3", CHECKIT | MENUTOGGLE | CHECKED, 0x0003, 0},
	
		{ NM_TITLE, (const STRPTR)MSG_MenuWindow, 				0, 0, 0, 0},
		{ NM_ITEM, (const STRPTR)MSG_MenuWindowPreviousWindow, 	"[", 0, 0, (APTR)&Window_HandlePreviousWindow},
		{ NM_ITEM, (const STRPTR)MSG_MenuWindowNextWindow, 		"]", 0, 0, (APTR)&Window_HandleNextWindow},
		{ NM_ITEM, (const STRPTR)MSG_MenuWindowIconize, 		"L", 0, 0, 0},
	
		{ NM_END, NULL,	0, 0, 0, 0},
	};
	
	if (the_window == NULL)
	{
		LOG_ERR(("Menu_BuildMenus %d: surface's window struct was NULL", __LINE__));
		goto error;
	}
	
	if ((the_surface->menu_ = CreateMenus(the_menu, GTMN_FrontPen, 1, TAG_END)) == NULL)
	{
		LOG_ERR(("Menu_BuildMenus %d: CreateMenus failed", __LINE__));
		goto error;
	}

	if (LayoutMenus(the_surface->menu_, global_app->visual_info_, GTMN_NewLookMenus, TRUE, GTMN_AmigaKey, &global_app->shortcut_image_, TAG_END) == false)
	{
		LOG_ERR(("Menu_BuildMenus %d: LayoutMenus failed", __LINE__));
		goto error;
	}

	if (SetMenuStrip(the_window, the_surface->menu_) == false)
	{
		LOG_ERR(("Menu_BuildMenus %d: SetMenuStrip failedL", __LINE__));
		goto error;
	}

	return true;
	
error:
	return false;
}
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2021-07-11 wb2k amiga key 2.png
Views:	109
Size:	8.0 KB
ID:	72522   Click image for larger version

Name:	Screen Shot 2021-07-11 wb2k amiga key 3.png
Views:	119
Size:	8.4 KB
ID:	72523  
Warty is offline  
 
Page generated in 0.05915 seconds with 12 queries