// COPILOT Right
DefineMfdButtons(
TEX_NEWRANGER17VC_MFD_DYNAMIC_05,
AID_COPILOT_MFD_RIGHT_BTNS_FN, GRP_NEWRANGER17VC_COPILOT_MFD_RIGHT_BTNS_FN, buttonFnRect[MFD_COPILOT_RIGHT],
AID_COPILOT_MFD_RIGHT_BTNS_SYS, GRP_NEWRANGER17VC_COPILOT_MFD_RIGHT_BTNS_SYS
);
}
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);
}
void ClassicMfd::DefineStaticClickArea(MESHGROUP const * const gr, int const id, bool const rect, const VECTOR3& revert, const VECTOR3& maxShift)
{
float minX, maxX, minY, maxY, minZ, maxZ, x, y, z;
minX = minY = minZ = 1000.0f;
maxX = maxY = maxZ = -1000.0f;
for (DWORD i = 0; i < gr->nVtx; i++) {
x = gr->Vtx[i].x;
y = gr->Vtx[i].y;
z = gr->Vtx[i].z;
if (x < minX) minX = x;
if (y < minY) minY = y;
if (z < minZ) minZ = z;
if (x > maxX) maxX = x + (float)maxShift.x;
if (y > maxY) maxY = y + (float)maxShift.y;
if (z > maxZ) maxZ = z + (float)maxShift.z;
}
if (rect) {
VECTOR3 p1 = _V(revert.x > 0 ? maxX : minX, revert.y > 0 ? minY : maxY, revert.z > 0 ? minZ : maxZ);
VECTOR3 p2 = _V(revert.x > 0 ? minX : maxX, revert.y > 0 ? minY : maxY, revert.z > 0 ? minZ : maxZ);
VECTOR3 p3 = _V(revert.x > 0 ? maxX : minX, revert.y > 0 ? maxY : minY, revert.z > 0 ? maxZ : minZ);
VECTOR3 p4 = _V(revert.x > 0 ? minX : maxX, revert.y > 0 ? maxY : minY, revert.z > 0 ? maxZ : minZ);
oapiVCSetAreaClickmode_Quadrilateral(id, p1, p2, p3, p4);
}
else {
double distX = Distance(minX, maxX);
double distY = Distance(minY, maxY);
double distZ = Distance(minZ, maxZ);
VECTOR3 center = _V(minX + distX / 2.0f, minY + distY / 2.0f, minZ + distZ / 2.0f);
double rad = max(distX, max(distY, distZ)) / 2.0;
oapiVCSetAreaClickmode_Spherical(id, center, rad);
}
}