Skip to content

Commit cff5617

Browse files
committed
Added first line text size to inset window
1 parent 3434538 commit cff5617

File tree

2 files changed

+138
-61
lines changed

2 files changed

+138
-61
lines changed

vSMR/InsetWindow.cpp

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,39 @@ void CInsetWindow::render(HDC hDC, CSMRRadar * radar_screen, Graphics* gdi, POIN
448448
ColorTagType = CSMRRadar::TagTypes::Uncorrelated;
449449
}
450450

451-
// First we need to figure out the tag size
451+
// Get the TAG label settings
452+
const Value& LabelsSettings = radar_screen->CurrentConfig->getActiveProfile()["labels"];
452453

453-
int TagWidth = 0, TagHeight = 0;
454+
// First we need to figure out the tag size
455+
Gdiplus::REAL TagWidth = 0, TagHeight = 0;
454456
RectF mesureRect;
455457
gdi->MeasureString(L" ", wcslen(L" "), radar_screen->customFonts[radar_screen->currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
456-
int blankWidth = (int)mesureRect.GetRight();
458+
auto blankWidth = mesureRect.GetRight();
459+
460+
// default font size
461+
mesureRect = RectF(0, 0, 0, 0);
462+
gdi->MeasureString(L"AZERTYUIOPQSDFGHJKLMWXCVBN", wcslen(L"AZERTYUIOPQSDFGHJKLMWXCVBN"), radar_screen->customFonts[radar_screen->currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
463+
auto oneLineHeight = mesureRect.GetBottom();
464+
465+
// bigger font size if used for 1st TAG line
466+
string font_name = radar_screen->CurrentConfig->getActiveProfile()["font"]["font_name"].GetString();
467+
wstring wide_font_name = wstring(font_name.begin(), font_name.end());
468+
469+
float fontsize = radar_screen->customFonts[radar_screen->currentFontSize]->GetSize();
470+
double fontSizeScaling = 1.0;
471+
if (LabelsSettings[Utils::getEnumString(ColorTagType).c_str()].HasMember("first_line_font_factor")) {
472+
fontSizeScaling = LabelsSettings[Utils::getEnumString(ColorTagType).c_str()]["first_line_font_factor"].GetDouble();
473+
auto test = radar_screen->customFonts[radar_screen->currentFontSize]->GetSize();
474+
fontsize = round((float)fontSizeScaling * (float)test);
475+
}
476+
Gdiplus::Font* firstLineFont = new Gdiplus::Font(wide_font_name.c_str(), Gdiplus::REAL(fontsize), radar_screen->customFonts[radar_screen->currentFontSize]->GetStyle(), Gdiplus::UnitPixel); ;
457477

458478
mesureRect = RectF(0, 0, 0, 0);
459479
gdi->MeasureString(L"AZERTYUIOPQSDFGHJKLMWXCVBN", wcslen(L"AZERTYUIOPQSDFGHJKLMWXCVBN"),
460-
radar_screen->customFonts[radar_screen->currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
461-
int oneLineHeight = (int)mesureRect.GetBottom();
480+
firstLineFont, PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
481+
auto firstLineHeight = mesureRect.GetBottom();
462482

463-
const Value& LabelsSettings = radar_screen->CurrentConfig->getActiveProfile()["labels"];
483+
// get label lines definitions
464484
const Value& LabelLines = LabelsSettings[Utils::getEnumString(TagType).c_str()]["definition"];
465485
vector<vector<string>> ReplacedLabelLines;
466486

@@ -474,9 +494,14 @@ void CInsetWindow::render(HDC hDC, CSMRRadar * radar_screen, Graphics* gdi, POIN
474494
vector<string> lineStringArray;
475495

476496
// Adds one line height
477-
TagHeight += oneLineHeight;
497+
if (i == 0) {
498+
TagHeight += firstLineHeight; // special case 1st line
499+
}
500+
else {
501+
TagHeight += oneLineHeight;
502+
}
478503

479-
int TempTagWidth = 0;
504+
Gdiplus::REAL TempTagWidth = 0;
480505

481506
for (unsigned int j = 0; j < line.Size(); j++)
482507
{
@@ -489,13 +514,16 @@ void CInsetWindow::render(HDC hDC, CSMRRadar * radar_screen, Graphics* gdi, POIN
489514
lineStringArray.push_back(element);
490515

491516
wstring wstr = wstring(element.begin(), element.end());
492-
gdi->MeasureString(wstr.c_str(), wcslen(wstr.c_str()),
493-
radar_screen->customFonts[radar_screen->currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
494-
495-
TempTagWidth += (int) mesureRect.GetRight();
517+
if (i == 0) {
518+
gdi->MeasureString(wstr.c_str(), wcslen(wstr.c_str()), firstLineFont, PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect); // special case for first line
519+
}
520+
else {
521+
gdi->MeasureString(wstr.c_str(), wcslen(wstr.c_str()), radar_screen->customFonts[radar_screen->currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
522+
}
523+
TempTagWidth += mesureRect.GetRight();
496524

497525
if (j != line.Size() - 1)
498-
TempTagWidth += (int) blankWidth;
526+
TempTagWidth += blankWidth;
499527
}
500528

501529
TagWidth = max(TagWidth, TempTagWidth);
@@ -535,7 +563,7 @@ void CInsetWindow::render(HDC hDC, CSMRRadar * radar_screen, Graphics* gdi, POIN
535563
definedBackgroundColor,
536564
radar_screen->CurrentConfig->getConfigColor(LabelsSettings[Utils::getEnumString(ColorTagType).c_str()]["background_color_on_runway"]));
537565

538-
CRect TagBackgroundRect(TagCenter.x - (TagWidth / 2), TagCenter.y - (TagHeight / 2), TagCenter.x + (TagWidth / 2), TagCenter.y + (TagHeight / 2));
566+
CRect TagBackgroundRect((int)(TagCenter.x - (TagWidth / 2.0)), (int)(TagCenter.y - (TagHeight / 2.0)), (int)(TagCenter.x + (TagWidth / 2.0)), (int)(TagCenter.y + (TagHeight / 2.0)));
539567

540568
if (Is_Inside(TagBackgroundRect.TopLeft(), appAreaVect) &&
541569
Is_Inside(RtPoint, appAreaVect) &&
@@ -550,10 +578,10 @@ void CInsetWindow::render(HDC hDC, CSMRRadar * radar_screen, Graphics* gdi, POIN
550578
radar_screen->CurrentConfig->getConfigColor(LabelsSettings["squawk_error_color"])));
551579
SolidBrush RimcasTextColor(radar_screen->CurrentConfig->getConfigColor(radar_screen->CurrentConfig->getActiveProfile()["rimcas"]["alert_text_color"]));
552580

553-
int heightOffset = 0;
581+
Gdiplus::REAL heightOffset = 0;
554582
for (auto&& line : ReplacedLabelLines)
555583
{
556-
int widthOffset = 0;
584+
Gdiplus::REAL widthOffset = 0;
557585
for (auto&& element : line)
558586
{
559587
SolidBrush* color = &FontColor;
@@ -564,23 +592,31 @@ void CInsetWindow::render(HDC hDC, CSMRRadar * radar_screen, Graphics* gdi, POIN
564592
color = &RimcasTextColor;
565593

566594
RectF mRect(0, 0, 0, 0);
567-
568595
wstring welement = wstring(element.begin(), element.end());
569596

570-
gdi->DrawString(welement.c_str(), wcslen(welement.c_str()), radar_screen->customFonts[radar_screen->currentFontSize],
571-
PointF(Gdiplus::REAL(TagBackgroundRect.left + widthOffset), Gdiplus::REAL(TagBackgroundRect.top + heightOffset)),
572-
&Gdiplus::StringFormat(), color);
597+
if (heightOffset == 0) { // first line
598+
gdi->DrawString(welement.c_str(), wcslen(welement.c_str()), firstLineFont,
599+
PointF(Gdiplus::REAL(TagBackgroundRect.left) + widthOffset, Gdiplus::REAL(TagBackgroundRect.top) + heightOffset),
600+
&Gdiplus::StringFormat(), color);
573601

602+
gdi->MeasureString(welement.c_str(), wcslen(welement.c_str()), firstLineFont,
603+
PointF(0, 0), &Gdiplus::StringFormat(), &mRect);
604+
}
605+
else {
606+
gdi->DrawString(welement.c_str(), wcslen(welement.c_str()), radar_screen->customFonts[radar_screen->currentFontSize],
607+
PointF(Gdiplus::REAL(TagBackgroundRect.left) + widthOffset, Gdiplus::REAL(TagBackgroundRect.top) + heightOffset),
608+
&Gdiplus::StringFormat(), color);
574609

575-
gdi->MeasureString(welement.c_str(), wcslen(welement.c_str()),
576-
radar_screen->customFonts[radar_screen->currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mRect);
610+
gdi->MeasureString(welement.c_str(), wcslen(welement.c_str()), radar_screen->customFonts[radar_screen->currentFontSize],
611+
PointF(0, 0), &Gdiplus::StringFormat(), &mRect);
612+
}
577613

578-
CRect ItemRect(TagBackgroundRect.left + widthOffset, TagBackgroundRect.top + heightOffset,
579-
TagBackgroundRect.left + widthOffset + (int)mRect.GetRight(), TagBackgroundRect.top + heightOffset + (int)mRect.GetBottom());
614+
CRect ItemRect((int)(TagBackgroundRect.left + widthOffset), (int)(TagBackgroundRect.top + heightOffset),
615+
(int)(TagBackgroundRect.left + widthOffset + mRect.GetRight()), (int)(TagBackgroundRect.top + heightOffset + mRect.GetBottom()));
580616

581617
radar_screen->AddScreenObject(TagClickableMap[element], rt.GetCallsign(), ItemRect, false, radar_screen->GetBottomLine(rt.GetCallsign()).c_str());
582618

583-
widthOffset += (int)mRect.GetRight();
619+
widthOffset += mRect.GetRight();
584620
widthOffset += blankWidth;
585621
}
586622

vSMR/SMRRadar.cpp

Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,19 +2112,39 @@ void CSMRRadar::OnRefresh(HDC hDC, int Phase)
21122112
// ----- Now the hard part, drawing (using gdi+) -------
21132113
//
21142114

2115-
// First we need to figure out the tag size
2115+
// Get the TAG label settings
2116+
const Value& LabelsSettings = CurrentConfig->getActiveProfile()["labels"];
21162117

2117-
int TagWidth = 0, TagHeight = 0;
2118+
// First we need to figure out the tag size
2119+
Gdiplus::REAL TagWidth = 0, TagHeight = 0;
21182120
RectF mesureRect;
21192121
graphics.MeasureString(L" ", wcslen(L" "), customFonts[currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
2120-
int blankWidth = (int)mesureRect.GetRight();
2122+
auto blankWidth = mesureRect.GetRight();
2123+
2124+
// default font size
2125+
mesureRect = RectF(0, 0, 0, 0);
2126+
graphics.MeasureString(L"AZERTYUIOPQSDFGHJKLMWXCVBN", wcslen(L"AZERTYUIOPQSDFGHJKLMWXCVBN"), customFonts[currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
2127+
auto oneLineHeight = mesureRect.GetBottom();
2128+
2129+
// bigger font size if used for 1st TAG line
2130+
string font_name = CurrentConfig->getActiveProfile()["font"]["font_name"].GetString();
2131+
wstring wide_font_name = wstring(font_name.begin(), font_name.end());
2132+
2133+
float fontsize = customFonts[currentFontSize]->GetSize();
2134+
double fontSizeScaling = 1.0;
2135+
if (LabelsSettings[Utils::getEnumString(ColorTagType).c_str()].HasMember("first_line_font_factor")) {
2136+
fontSizeScaling = LabelsSettings[Utils::getEnumString(ColorTagType).c_str()]["first_line_font_factor"].GetDouble();
2137+
auto test = customFonts[currentFontSize]->GetSize();
2138+
fontsize = round((float)fontSizeScaling * (float)test);
2139+
}
2140+
Gdiplus::Font* firstLineFont = new Gdiplus::Font(wide_font_name.c_str(), Gdiplus::REAL(fontsize), customFonts[currentFontSize]->GetStyle(), Gdiplus::UnitPixel); ;
21212141

21222142
mesureRect = RectF(0, 0, 0, 0);
21232143
graphics.MeasureString(L"AZERTYUIOPQSDFGHJKLMWXCVBN", wcslen(L"AZERTYUIOPQSDFGHJKLMWXCVBN"),
2124-
customFonts[currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
2125-
int oneLineHeight = (int)mesureRect.GetBottom();
2144+
firstLineFont, PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
2145+
auto firstLineHeight = mesureRect.GetBottom();
21262146

2127-
const Value& LabelsSettings = CurrentConfig->getActiveProfile()["labels"];
2147+
// get label lines definitions
21282148
const Value& LabelLines = LabelsSettings[Utils::getEnumString(TagType).c_str()]["definition"];
21292149
vector<vector<string>> ReplacedLabelLines;
21302150

@@ -2138,9 +2158,14 @@ void CSMRRadar::OnRefresh(HDC hDC, int Phase)
21382158
vector<string> lineStringArray;
21392159

21402160
// Adds one line height
2141-
TagHeight += oneLineHeight;
2161+
if (i == 0) {
2162+
TagHeight += firstLineHeight; // special case 1st line
2163+
}
2164+
else {
2165+
TagHeight += oneLineHeight;
2166+
}
21422167

2143-
int TempTagWidth = 0;
2168+
Gdiplus::REAL TempTagWidth = 0;
21442169

21452170
for(unsigned int j = 0; j < line.Size(); j++)
21462171
{
@@ -2153,13 +2178,16 @@ void CSMRRadar::OnRefresh(HDC hDC, int Phase)
21532178
lineStringArray.push_back(element);
21542179

21552180
wstring wstr = wstring(element.begin(), element.end());
2156-
graphics.MeasureString(wstr.c_str(), wcslen(wstr.c_str()),
2157-
customFonts[currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
2158-
2159-
TempTagWidth += (int) mesureRect.GetRight();
2181+
if (i == 0) {
2182+
graphics.MeasureString(wstr.c_str(), wcslen(wstr.c_str()), firstLineFont, PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect); // special case for first line
2183+
}
2184+
else {
2185+
graphics.MeasureString(wstr.c_str(), wcslen(wstr.c_str()), customFonts[currentFontSize], PointF(0, 0), &Gdiplus::StringFormat(), &mesureRect);
2186+
}
2187+
TempTagWidth += mesureRect.GetRight();
21602188

21612189
if (j != line.Size() - 1)
2162-
TempTagWidth += (int) blankWidth;
2190+
TempTagWidth += blankWidth;
21632191
}
21642192

21652193
TagWidth = max(TagWidth, TempTagWidth);
@@ -2201,7 +2229,7 @@ void CSMRRadar::OnRefresh(HDC hDC, int Phase)
22012229

22022230
// Drawing the tag background
22032231

2204-
CRect TagBackgroundRect(TagCenter.x - (TagWidth / 2), TagCenter.y - (TagHeight / 2), TagCenter.x + (TagWidth / 2), TagCenter.y + (TagHeight / 2));
2232+
CRect TagBackgroundRect((int)(TagCenter.x - (TagWidth / 2.0)), (int)(TagCenter.y - (TagHeight / 2.0)), (int)(TagCenter.x + (TagWidth / 2.0)), (int)(TagCenter.y + (TagHeight / 2.0)));
22052233
SolidBrush TagBackgroundBrush(TagBackgroundColor);
22062234
graphics.FillRectangle(&TagBackgroundBrush, CopyRect(TagBackgroundRect));
22072235
if (mouseWithin(TagBackgroundRect) || IsTagBeingDragged(rt.GetCallsign()))
@@ -2212,18 +2240,18 @@ void CSMRRadar::OnRefresh(HDC hDC, int Phase)
22122240

22132241
// Drawing the tag text
22142242

2215-
SolidBrush FontColor(ColorManager->get_corrected_color("label",
2216-
CurrentConfig->getConfigColor(LabelsSettings[Utils::getEnumString(ColorTagType).c_str()]["text_color"])));
2217-
SolidBrush SquawkErrorColor(ColorManager->get_corrected_color("label",
2218-
CurrentConfig->getConfigColor(LabelsSettings["squawk_error_color"])));
2243+
SolidBrush FontColor(ColorManager->get_corrected_color("label", CurrentConfig->getConfigColor(LabelsSettings[Utils::getEnumString(ColorTagType).c_str()]["text_color"])));
2244+
SolidBrush SquawkErrorColor(ColorManager->get_corrected_color("label", CurrentConfig->getConfigColor(LabelsSettings["squawk_error_color"])));
22192245
SolidBrush RimcasTextColor(CurrentConfig->getConfigColor(CurrentConfig->getActiveProfile()["rimcas"]["alert_text_color"]));
2220-
SolidBrush GroundPushColor(ColorManager->get_corrected_color("label",
2221-
CurrentConfig->getConfigColor(LabelsSettings["groundstatus_colors"]["push"])));
2222-
SolidBrush GroundTaxiColor(ColorManager->get_corrected_color("label",
2223-
CurrentConfig->getConfigColor(LabelsSettings["groundstatus_colors"]["taxi"])));
2224-
SolidBrush GroundDepaColor(ColorManager->get_corrected_color("label",
2225-
CurrentConfig->getConfigColor(LabelsSettings["groundstatus_colors"]["depa"])));
22262246

2247+
SolidBrush GroundPushColor(TagBackgroundColor);
2248+
SolidBrush GroundTaxiColor(TagBackgroundColor);
2249+
SolidBrush GroundDepaColor(TagBackgroundColor);
2250+
if (LabelsSettings.HasMember("groundstatus_colors")) {
2251+
GroundPushColor.SetColor(ColorManager->get_corrected_color("label", CurrentConfig->getConfigColor(LabelsSettings["groundstatus_colors"]["push"])));
2252+
GroundTaxiColor.SetColor(ColorManager->get_corrected_color("label", CurrentConfig->getConfigColor(LabelsSettings["groundstatus_colors"]["taxi"])));
2253+
GroundDepaColor.SetColor(ColorManager->get_corrected_color("label", CurrentConfig->getConfigColor(LabelsSettings["groundstatus_colors"]["depa"])));
2254+
}
22272255

22282256
// Drawing the leader line
22292257
RECT TagBackRectData = TagBackgroundRect;
@@ -2272,10 +2300,10 @@ void CSMRRadar::OnRefresh(HDC hDC, int Phase)
22722300
TagBackgroundRect = oldCrectSave;
22732301

22742302
// Clickable zones
2275-
int heightOffset = 0;
2303+
Gdiplus::REAL heightOffset = 0;
22762304
for (auto&& line : ReplacedLabelLines)
22772305
{
2278-
int widthOffset = 0;
2306+
Gdiplus::REAL widthOffset = 0;
22792307
for (auto&& element : line)
22802308
{
22812309
SolidBrush* color = &FontColor;
@@ -2294,27 +2322,40 @@ void CSMRRadar::OnRefresh(HDC hDC, int Phase)
22942322
color = &GroundDepaColor;
22952323

22962324
RectF mRect(0, 0, 0, 0);
2297-
22982325
wstring welement = wstring(element.begin(), element.end());
22992326

2300-
graphics.DrawString(welement.c_str(), wcslen(welement.c_str()), customFonts[currentFontSize],
2301-
PointF(Gdiplus::REAL(TagBackgroundRect.left + widthOffset), Gdiplus::REAL(TagBackgroundRect.top + heightOffset)),
2302-
&Gdiplus::StringFormat(), color);
2327+
if (heightOffset == 0) { // first line
2328+
graphics.DrawString(welement.c_str(), wcslen(welement.c_str()), firstLineFont,
2329+
PointF(Gdiplus::REAL(TagBackgroundRect.left) + widthOffset, Gdiplus::REAL(TagBackgroundRect.top) + heightOffset),
2330+
&Gdiplus::StringFormat(), color);
23032331

2332+
graphics.MeasureString(welement.c_str(), wcslen(welement.c_str()), firstLineFont,
2333+
PointF(0, 0), &Gdiplus::StringFormat(), &mRect);
2334+
}
2335+
else {
2336+
graphics.DrawString(welement.c_str(), wcslen(welement.c_str()), customFonts[currentFontSize],
2337+
PointF(Gdiplus::REAL(TagBackgroundRect.left) + widthOffset, Gdiplus::REAL(TagBackgroundRect.top) + heightOffset),
2338+
&Gdiplus::StringFormat(), color);
23042339

2305-
graphics.MeasureString(welement.c_str(), wcslen(welement.c_str()), customFonts[currentFontSize],
2306-
PointF(0, 0), &Gdiplus::StringFormat(), &mRect);
2340+
graphics.MeasureString(welement.c_str(), wcslen(welement.c_str()), customFonts[currentFontSize],
2341+
PointF(0, 0), &Gdiplus::StringFormat(), &mRect);
2342+
}
23072343

2308-
CRect ItemRect(TagBackgroundRect.left + widthOffset, TagBackgroundRect.top + heightOffset,
2309-
TagBackgroundRect.left + widthOffset + (int)mRect.GetRight(), TagBackgroundRect.top + heightOffset + (int)mRect.GetBottom());
2344+
CRect ItemRect((int)(TagBackgroundRect.left + widthOffset), (int)(TagBackgroundRect.top + heightOffset),
2345+
(int)(TagBackgroundRect.left + widthOffset + mRect.GetRight()), (int)(TagBackgroundRect.top + heightOffset + mRect.GetBottom()));
23102346

23112347
AddScreenObject(TagClickableMap[element], rt.GetCallsign(), ItemRect, true, GetBottomLine(rt.GetCallsign()).c_str());
23122348

2313-
widthOffset += (int)mRect.GetRight();
2349+
widthOffset += mRect.GetRight();
23142350
widthOffset += blankWidth;
23152351
}
23162352

2317-
heightOffset += oneLineHeight;
2353+
if (heightOffset == 0) {
2354+
heightOffset += firstLineHeight;
2355+
}
2356+
else {
2357+
heightOffset += oneLineHeight;
2358+
}
23182359
}
23192360

23202361

0 commit comments

Comments
 (0)