Using Wimp_CreateIcon with outline font
Gavin (560) 32 posts |
I’m creating some icons dynamically at run-time using Wimp_CreateIcon. I want to set the icon to use an outline font (Homerton.Medium 10pt). So I would set bit 6 of the icon flags, which means 24-31 is the font handle. Do I have to first use Font_FindFont to get the required font handle to place in bits 24-31? If that is the case then that may prove to be difficult as I’m creating an Ovation Pro applet, so I’m not within a usual wimp programming environment. Normally, I would set the font details for the icon in the template file and everything is taken care of. |
Steffen Huber (91) 1953 posts |
Put one icon readily configured into the template, and then at runtime read out its font handle and use it for the dynamically generated icons? Note that I am absolutely ignorant about the details:
|
Martin Avison (27) 1494 posts |
When fonts are set in a Templates file, the font names & sizes are stored in a list in the Templates file, and the icons reference their position in the list. Wimp_LoadTemplate uses the font names to do a Font_FindFont, and replaces the font number in the icon with the real one. If you are creating an icon dynamically, them you need to do the FindFont and put the handle in the icon yourself. In both cases, you need to keep track of fonts used and make sure there is always a LoseFont for every FindFont when they are no longer required. If you do not, fonts are ‘leaked’. Whether you can do this in an OPro applet, I have no idea. |
Gavin (560) 32 posts |
@Steffen @Martin I think that using the FindFont / LoseFont approach would be more work to accomplish within the OPro script language than using Steffen’s approach of reading the handle from an existing icon. The Window itself is defined in a template file, so I can create a sample icon to read. I would then just need to implement a way of getting the data from Wimp_GetIconState. Thanks for the replies and suggestions. |
André Timmermans (100) 655 posts |
With outline fonts fun things happens when you switch to a screen mode with different EX or EY factors, so you have to patch in new font handles on mode changes because the Wimp doesn’t do it for you. This means that you have to scan the windows to obtain the font handle of each icon, use Font_ReadDefn to obtain its definition, loose the font, obtain a new font handle for the dpi settings and update the icon’s font handle with Wimp_SetIconState. |
Paul Sprangers (346) 524 posts |
That’s something that I’m seriously beginning to doubt. I use only one single font in my program, but if I don’t FindFont it every time that I actually use it, weird things can happen. Is that the ‘leak’ that Martin mentions? (I only do LoseFont at terminating the program.) |
Martin Avison (27) 1494 posts |
Every FindFont must have a matching LoseFont – even if there are mutiple finds for the same font. The count of each font usage (by all applications)can be seen increasing & decreasing with the *FontList command, which is useful for checking for font leaks. When Wimp_LoadTemplate does a FindFont, it increases a count in an array of fonts you have to provide to LoadTemplate. When you close the template you should do a LoseFont for each entry in the array, and repeat until the array count for that font is zero. A font handle that has been found can be used as many times as you like, until the LoseFont has been done. |