void ClassicMfd::DefineMfdButtons(
UINT const texId,
UINT const fuctionAreaId, UINT const functionGroupId, RECT const functionRect,
UINT const sysAreaId, UINT const sysGroupId
)
{
SURFHANDLE const texDyn = oapiGetTextureHandle(meshhg_VC, texId);
oapiVCRegisterArea(fuctionAreaId, functionRect, PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN | PANEL_MOUSE_LBPRESSED | PANEL_MOUSE_ONREPLAY, PANEL_MAP_NONE, texDyn);
DefineStaticClickArea(oapiMeshGroup(meshhg_VC, functionGroupId), fuctionAreaId, true);
oapiVCRegisterArea(sysAreaId, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN | PANEL_MOUSE_ONREPLAY);
DefineStaticClickArea(oapiMeshGroup(meshhg_VC, sysGroupId), sysAreaId, true);
}
static int get_font_height(HDC const hDC)
{
TEXTMETRIC tm;
if (GetTextMetrics(hDC, &tm))
{
return abs(tm.tmAscent);
}
return 5; // Wild, crazy guessing
}
void ClassicMfd::RedrawMFDButtons(SURFHANDLE const surf, int const mfd)
{
int const btnWidth = buttonFnDim->width;
int const btnHeight = buttonFnDim->height;
RECT const draw_area = _R(0, 0, buttonFnRect[mfd].right - buttonFnRect[mfd].left, buttonFnRect[mfd].bottom - buttonFnRect[mfd].top);
HDC const hDC = oapiGetDC(surf);
SelectObject(hDC, buttonBrush);
SetBkMode(hDC, OPAQUE);
Rectangle(hDC, draw_area.left, draw_area.top, draw_area.right, draw_area.bottom);
HFONT pFont = (HFONT)SelectObject(hDC, labelFont);
SetTextColor(hDC, labelColor);
SetTextAlign(hDC, TA_CENTER);
int const half_font_height = get_font_height(hDC) / 2;
char const * label;
int const label_x_offset = (btnWidth / 2);
int const label_y_offset = (btnHeight / 2) - buttonFnDim->marginHeight - half_font_height;
for (int i = 0; i < 12; i++) {
int const x = i / 6;
int const y = i % 6;
if (label = oapiMFDButtonLabel(mfd, i)) {
int const xwidth = (x * btnWidth);
int const yheight = (y * btnHeight);
SelectObject(hDC, buttonLabelBrush);
SetBkMode(hDC, OPAQUE);
Rectangle(hDC,
draw_area.left + xwidth + buttonFnDim->marginWidth,
draw_area.top + yheight + buttonFnDim->marginHeight,
draw_area.left + xwidth + btnWidth - buttonFnDim->marginWidth,
draw_area.top + yheight + btnHeight - buttonFnDim->marginHeight
);
SetBkMode(hDC, TRANSPARENT);
TextOut(hDC, draw_area.left + xwidth + label_x_offset, draw_area.top + yheight + label_y_offset, label, strlen(label));
}
else break;
}
SelectObject(hDC, pFont);
oapiReleaseDC(surf, hDC);
}