ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5


4 - The Internals

Although the list box does the actual drawing, the calling function verifies and sets up the data structure passed to the list box:

const FONT *PopUp_FontSelect(void)

{
const FONTGROUP *group=GUI_GetFontGroup();
unsigned int total=0, i=0, n=0;
while (group[total].size) // count group size - last entry has zero size
++total;
const FONTGROUP **array=new const FONTGROUP *[total];
for (i=0;i<total;i++)
{
if ( group[i].size<48 && group[i].style<=CTRL_SMALL && group[i].font )
array[n++]=&group[i];
}
// call popup
GUI_EventLoop(new CStructuredPopUp(10,10,180,210,group,array,n,"Select a Font"));
int choice=CStructuredPopUp::Choice();
const FONT *font=0;
if (choice>=0) // selection made?
font=(const FONT *)(((char *)group)+array[choice]->font);
delete[] array;
return font;
}
The default font group (and currently the only one) is obtained via GUI_GetFontGroup(). We then walk through this array copying valid entries into a pointer array, which is then passed to the list box. Before copying, we run a few sanity checks to prevent invalid entries to be displayed. At a minimum, we check for unusual sizes, that the style is valid (CTRL_SMALL is the largest valid value permissible), and that the font offset is non-zero (zero indicates a non-existent font). If valid, we add the entry to our list. This array and the FONTGROUP base pointer are then used by the list box for drawing. The DrawRow() function simply sets the font from the passed font entry (to avoid extra casting, the list box stores the base value in m_base as a char *):

const FONT *font=(const FONT *)&m_base[m_array[row]->font];
m_window->DrawText( buff, rect->x, rect->y+3, font );
As well, the font display can have adjustable row heights, based on the specific font size (from the size variable of m_array[row]).

Unless Cancel is selected, the result of this dialog is a FONT pointer, which is then passed to SetFont(), and sets the font for all subsequent default displaying. Note that the displayed text isn't centered anymore, and serves as a reminder that you'll need to pay special attention to text formatting when changing fonts.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice