Skip to content

Commit 3c19d7d

Browse files
authored
Merge pull request #3 from EvenAR/custom-menu-style
Custom menu style
2 parents d77d8f9 + 7cad450 commit 3c19d7d

36 files changed

+1013
-567
lines changed

ILS_Window_Plugin/ILS_Window_Plugin.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<ItemGroup>
118118
<ClCompile Include="IWCdeMenuBtn.cpp" />
119119
<ClCompile Include="IWCdeWindow.cpp" />
120+
<ClCompile Include="IWSettings.cpp" />
120121
<ClCompile Include="IWX11IconifyBtn.cpp" />
121122
<ClCompile Include="IWCdeIconifyBtn.cpp" />
122123
<ClCompile Include="IWX11MenuBtn.cpp" />
@@ -129,11 +130,13 @@
129130
<ClCompile Include="IWCdeTitleBar.cpp" />
130131
<ClCompile Include="IWVisualization.cpp" />
131132
<ClCompile Include="IWX11TitleBar.cpp" />
133+
<ClCompile Include="IWX11TitleBarBtnBase.cpp" />
132134
<ClCompile Include="IWX11Window.cpp" />
133135
<ClCompile Include="pch.cpp">
134136
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
135137
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
136138
</ClCompile>
139+
<ClCompile Include="IWWindowManager.cpp" />
137140
</ItemGroup>
138141
<ItemGroup>
139142
<None Include="ILS_Window_Plugin.def" />
@@ -145,6 +148,8 @@
145148
<ClInclude Include="framework.h" />
146149
<ClInclude Include="IWCdeMenuBtn.h" />
147150
<ClInclude Include="IWCdeWindow.h" />
151+
<ClInclude Include="IWContextMenu.h" />
152+
<ClInclude Include="IWSettings.h" />
148153
<ClInclude Include="IWX11IconifyBtn.h" />
149154
<ClInclude Include="IWCdeIconifyBtn.h" />
150155
<ClInclude Include="IWX11MenuBtn.h" />
@@ -158,12 +163,14 @@
158163
<ClInclude Include="IWCdeTitleBar.h" />
159164
<ClInclude Include="IWVisualization.h" />
160165
<ClInclude Include="IWX11TitleBar.h" />
166+
<ClInclude Include="IWX11TitleBarBtnBase.h" />
161167
<ClInclude Include="IWX11Window.h" />
162168
<ClInclude Include="pch.h" />
163169
<ClInclude Include="RenderUtils.h" />
164170
<ClInclude Include="Resource.h" />
165171
<ClInclude Include="targetver.h" />
166172
<ClInclude Include="IWUtils.h" />
173+
<ClInclude Include="IWWindowManager.h" />
167174
</ItemGroup>
168175
<ItemGroup>
169176
<ResourceCompile Include="ILS_Window_Plugin.rc" />

ILS_Window_Plugin/ILS_Window_Plugin.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
<ClCompile Include="IWX11Window.cpp">
8282
<Filter>Source Files\Theme\X11</Filter>
8383
</ClCompile>
84+
<ClCompile Include="IWContextMenu.cpp">
85+
<Filter>Source Files</Filter>
86+
</ClCompile>
8487
</ItemGroup>
8588
<ItemGroup>
8689
<None Include="ILS_Window_Plugin.def">
@@ -163,6 +166,9 @@
163166
<ClInclude Include="IWX11Window.h">
164167
<Filter>Header Files\Theme\X11</Filter>
165168
</ClInclude>
169+
<ClInclude Include="IWContextMenu.h">
170+
<Filter>Header Files</Filter>
171+
</ClInclude>
166172
</ItemGroup>
167173
<ItemGroup>
168174
<ResourceCompile Include="ILS_Window_Plugin.rc">

ILS_Window_Plugin/IWCdeIconifyBtn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ void IWCdeIconifyBtn::DrawSymbol(CDC* pdc, CRect rect)
1919
icon.top = buttonFrame.top + buttonFrame.Width() * 0.4;
2020
icon.bottom = buttonFrame.bottom - buttonFrame.Width() * 0.4;
2121

22-
Draw3dRect(pdc, buttonFrame, 1, lightColor, darkColor);
23-
Draw3dRect(pdc, icon, 1, lightColor, darkColor);
22+
DrawThick3dRect(pdc, buttonFrame, 1, lightColor, darkColor);
23+
DrawThick3dRect(pdc, icon, 1, lightColor, darkColor);
2424
}

ILS_Window_Plugin/IWCdeMenuBtn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ void IWCdeMenuBtn::DrawSymbol(CDC* pdc, CRect rect)
1616
barIcon.top = rect.top + rect.Height() / 2 - 2;
1717
barIcon.bottom = barIcon.top + 4;
1818

19-
Draw3dRect(pdc, rect, 1, lightColor, darkColor);
20-
Draw3dRect(pdc, barIcon, 1, lightColor, darkColor);
19+
DrawThick3dRect(pdc, rect, 1, lightColor, darkColor);
20+
DrawThick3dRect(pdc, barIcon, 1, lightColor, darkColor);
2121
}

ILS_Window_Plugin/IWCdeTitleBar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ IWCdeTitleBar::IWCdeTitleBar(COLORREF backgroundColor, COLORREF textColor, COLOR
1414

1515
this->iconifyButton = new IWCdeIconifyBtn(backgroundColor, lightColor, darkColor);
1616
this->menuButton = new IWCdeMenuBtn(backgroundColor, lightColor, darkColor);
17-
this->resizeButton = new IWX11ResizeBtn(backgroundColor);
17+
this->resizeButton = new IWX11ResizeBtn(backgroundColor, textColor);
1818
}
1919

2020
void IWCdeTitleBar::PositionButtons(const CRect& rect)
@@ -34,9 +34,9 @@ void IWCdeTitleBar::PositionButtons(const CRect& rect)
3434

3535
void IWCdeTitleBar::DrawTitle(CDC* pdc, CRect rect, CString title)
3636
{
37-
Draw3dRect(pdc, titleArea, 1, lightColor, darkColor);
37+
DrawThick3dRect(pdc, titleArea, 1, lightColor, darkColor);
3838

39-
auto oldFont = pdc->SelectObject(this->font);
39+
auto oldFont = pdc->SelectObject(this->mainFont);
4040
pdc->SetTextColor(this->textColor);
4141
pdc->SetBkMode(TRANSPARENT);
4242
pdc->DrawText(_T(title), -1, titleArea, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

ILS_Window_Plugin/IWCdeWindow.cpp

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ IWCdeWindow::IWCdeWindow(IWApproachDefinition selectedApproach, IWStyling stylin
88
, lightColor(AdjustColorBrightness(styling.windowFrameColor, 1.4))
99
, darkColor(AdjustColorBrightness(styling.windowFrameColor, 0.4))
1010
{
11-
COLORREF textColor = RGB(styling.windowFrameTextColor.r, styling.windowFrameTextColor.g, styling.windowFrameTextColor.b);
12-
this->titleBar = new IWCdeTitleBar(windowBorderColor, textColor, lightColor, darkColor, this);
11+
this->titleBar = new IWCdeTitleBar(windowBorderColor, styling.windowFrameTextColor, lightColor, darkColor, this);
12+
this->extraMenuItemWidth = 20;
1313
}
1414

1515
int IWCdeWindow::GetEdgeCursorPosition(CPoint point)
@@ -76,28 +76,28 @@ void IWCdeWindow::DrawBorder(CDC* pdc, CRect rect)
7676
leftBorderRect.left = leftBorderRect.left + 1;
7777
leftBorderRect.right = leftBorderRect.left + WINDOW_BORDER_THICKNESS - 1;
7878
leftBorderRect.bottom = leftBorderRect.bottom - TITLE_BAR_HEIGHT;
79-
Draw3dRect(pdc, leftBorderRect, border3dSteps, lightColor, darkColor);
79+
DrawThick3dRect(pdc, leftBorderRect, border3dSteps, lightColor, darkColor);
8080

8181
CRect bottomBorderRect = rect;
8282
bottomBorderRect.top = bottomBorderRect.bottom - WINDOW_BORDER_THICKNESS;
8383
bottomBorderRect.left = bottomBorderRect.left + TITLE_BAR_HEIGHT;
8484
bottomBorderRect.right = bottomBorderRect.right - TITLE_BAR_HEIGHT;
8585
bottomBorderRect.bottom = bottomBorderRect.bottom - 1;
86-
Draw3dRect(pdc, bottomBorderRect, border3dSteps, lightColor, darkColor);
86+
DrawThick3dRect(pdc, bottomBorderRect, border3dSteps, lightColor, darkColor);
8787

8888
CRect rightBorderRect = rect;
8989
rightBorderRect.top = rightBorderRect.top + TITLE_BAR_HEIGHT;
9090
rightBorderRect.left = rightBorderRect.right - WINDOW_BORDER_THICKNESS;
9191
rightBorderRect.right = rightBorderRect.right - 1;
9292
rightBorderRect.bottom = rightBorderRect.bottom - TITLE_BAR_HEIGHT;
93-
Draw3dRect(pdc, rightBorderRect, border3dSteps, lightColor, darkColor);
93+
DrawThick3dRect(pdc, rightBorderRect, border3dSteps, lightColor, darkColor);
9494

9595
CRect topBorderRect = rect;
9696
topBorderRect.top = topBorderRect.top + 1;
9797
topBorderRect.left = topBorderRect.left + TITLE_BAR_HEIGHT;
9898
topBorderRect.right = topBorderRect.right - TITLE_BAR_HEIGHT;
9999
topBorderRect.bottom = topBorderRect.top + WINDOW_BORDER_THICKNESS - 1;
100-
Draw3dRect(pdc, topBorderRect, border3dSteps, lightColor, darkColor);
100+
DrawThick3dRect(pdc, topBorderRect, border3dSteps, lightColor, darkColor);
101101

102102
// Corners
103103

@@ -106,36 +106,38 @@ void IWCdeWindow::DrawBorder(CDC* pdc, CRect rect)
106106
topLeftCornerRect.left = topLeftCornerRect.left + 1;
107107
topLeftCornerRect.right = topLeftCornerRect.left + TITLE_BAR_HEIGHT - 2;
108108
topLeftCornerRect.bottom = topLeftCornerRect.top + TITLE_BAR_HEIGHT - 2;
109-
Draw3dCorner(pdc, topLeftCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, true, true);
109+
DrawThick3dCorner(pdc, topLeftCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, true, true);
110110

111111
CRect topRightCornerRect = rect;
112112
topRightCornerRect.top = topRightCornerRect.top + 1;
113113
topRightCornerRect.left = topRightCornerRect.right - TITLE_BAR_HEIGHT;
114114
topRightCornerRect.right = topRightCornerRect.right - 2;
115115
topRightCornerRect.bottom = topRightCornerRect.top + TITLE_BAR_HEIGHT - 2;
116-
Draw3dCorner(pdc, topRightCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, true, false);
116+
DrawThick3dCorner(pdc, topRightCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, true, false);
117117

118118
CRect bottomRightCornerRect = rect;
119119
bottomRightCornerRect.top = bottomRightCornerRect.bottom - TITLE_BAR_HEIGHT;
120120
bottomRightCornerRect.left = bottomRightCornerRect.right - TITLE_BAR_HEIGHT;
121121
bottomRightCornerRect.right = bottomRightCornerRect.right - 2;
122122
bottomRightCornerRect.bottom = bottomRightCornerRect.bottom - 2;
123-
Draw3dCorner(pdc, bottomRightCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, false, false);
123+
DrawThick3dCorner(pdc, bottomRightCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, false, false);
124124

125125
CRect bottomLeftCornerRect = rect;
126126
bottomLeftCornerRect.top = bottomLeftCornerRect.bottom - TITLE_BAR_HEIGHT;
127127
bottomLeftCornerRect.left = bottomLeftCornerRect.left + 1;
128128
bottomLeftCornerRect.right = bottomLeftCornerRect.left + TITLE_BAR_HEIGHT - 2;
129129
bottomLeftCornerRect.bottom = bottomLeftCornerRect.bottom - 2;
130-
Draw3dCorner(pdc, bottomLeftCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, false, true);
130+
DrawThick3dCorner(pdc, bottomLeftCornerRect, WINDOW_BORDER_THICKNESS, border3dSteps, lightColor, darkColor, false, true);
131131
}
132132

133-
COLORREF IWCdeWindow::AdjustColorBrightness(RGB color, double factor)
133+
COLORREF IWCdeWindow::AdjustColorBrightness(COLORREF color, double factor)
134134
{
135+
GetRValue(color);
136+
135137
// Adjust each component
136-
int red = static_cast<int>(color.r * factor);
137-
int green = static_cast<int>(color.g * factor);
138-
int blue = static_cast<int>(color.b * factor);
138+
int red = GetRValue(color) * factor;
139+
int green = GetGValue(color) * factor;
140+
int blue = GetBValue(color) * factor;
139141

140142
// Ensure the components are within the valid range
141143
red = max(0, min(255, red));
@@ -145,3 +147,32 @@ COLORREF IWCdeWindow::AdjustColorBrightness(RGB color, double factor)
145147
// Combine them back into a COLORREF
146148
return RGB(red, green, blue);
147149
}
150+
151+
void IWCdeWindow::DrawMenuItem(CDC* pdc, CRect bounds, CString text, bool isHovered, bool isChecked)
152+
{
153+
COLORREF bgColor = isHovered ? RGB(130, 130, 130) : RGB(152, 152, 152);
154+
COLORREF textColor = RGB(255, 255, 255); // White text
155+
156+
std::string fullText = isChecked ? "¤ " : " ";
157+
fullText += text;
158+
159+
CBrush brush(bgColor);
160+
pdc->FillRect(&bounds, &brush);
161+
162+
if (isHovered) {
163+
COLORREF darkened = AdjustColorBrightness(bgColor, 0.6);
164+
COLORREF lightened = AdjustColorBrightness(bgColor, 1.4);
165+
DrawThick3dRect(pdc, bounds, 2, darkened, lightened);
166+
}
167+
168+
// Draw text
169+
pdc->SetTextColor(textColor);
170+
pdc->SetBkMode(TRANSPARENT);
171+
172+
CRect textArea = bounds;
173+
textArea.left += 10;
174+
175+
CFont* oldFont = pdc->SelectObject(&mainFont);
176+
pdc->DrawText(fullText.c_str(), &textArea, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
177+
pdc->SelectObject(&oldFont);
178+
}

ILS_Window_Plugin/IWCdeWindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ class IWCdeWindow :
99

1010
private:
1111
void DrawBorder(CDC* pdc, CRect rect) override;
12-
COLORREF AdjustColorBrightness(RGB color, double factor);
12+
void DrawMenuItem(CDC* pdc, CRect bounds, CString text, bool isHovered, bool isChecked) override;
1313
virtual int GetEdgeCursorPosition(CPoint point) override;
1414

15+
COLORREF AdjustColorBrightness(COLORREF color, double factor);
16+
1517
const COLORREF lightColor;
1618
const COLORREF darkColor;
1719
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "pch.h"
2+
#include "IWContextMenu.h"
3+
4+
BEGIN_MESSAGE_MAP(IWContextMenu, CWnd)
5+
ON_WM_PAINT()
6+
END_MESSAGE_MAP()
7+
8+
void IWContextMenu::SubclassMenu(HWND hMenuWnd)
9+
{
10+
// Attach to the existing menu window
11+
Attach(hMenuWnd);
12+
}
13+
14+
void IWContextMenu::OnPaint()
15+
{
16+
CPaintDC dc(this); // Get device context
17+
18+
// Get the menu window's size
19+
CRect rect;
20+
GetClientRect(&rect);
21+
22+
// Draw the default menu first
23+
DefWindowProc(WM_PAINT, (WPARAM)dc.m_hDC, 0);
24+
25+
// Draw custom border
26+
COLORREF borderColor = RGB(255, 0, 0); // Red border
27+
int borderWidth = 2;
28+
29+
CBrush borderBrush(borderColor);
30+
dc.FrameRect(&rect, &borderBrush);
31+
32+
// You can also use dc.DrawEdge() for different styles
33+
}

ILS_Window_Plugin/IWContextMenu.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
#include <afxwin.h>
3+
4+
class IWContextMenu : public CWnd
5+
{
6+
public:
7+
void SubclassMenu(HWND hMenuWnd);
8+
9+
protected:
10+
afx_msg void OnPaint();
11+
DECLARE_MESSAGE_MAP()
12+
};

ILS_Window_Plugin/IWDataTypes.h

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
class IWWindow;
99

10-
struct RGB {
11-
int r, g, b;
12-
};
13-
1410
struct IWTargetPosition {
1511
int trueAltitude;
1612
double latitude;
@@ -49,17 +45,22 @@ enum IWTagMode {
4945
Callsign
5046
};
5147

48+
enum IWTheme {
49+
CDE,
50+
X11
51+
};
52+
5253
struct IWStyling {
53-
RGB windowFrameColor;
54-
RGB windowFrameTextColor;
55-
RGB windowOuterFrameColor;
56-
RGB backgroundColor;
57-
RGB glideslopeColor;
58-
RGB localizerColor;
59-
RGB radarTargetColor;
60-
RGB historyTrailColor;
61-
RGB targetLabelColor;
62-
RGB rangeStatusTextColor;
54+
COLORREF windowFrameColor;
55+
COLORREF windowFrameTextColor;
56+
COLORREF windowOuterFrameColor;
57+
COLORREF backgroundColor;
58+
COLORREF glideslopeColor;
59+
COLORREF localizerColor;
60+
COLORREF radarTargetColor;
61+
COLORREF historyTrailColor;
62+
COLORREF targetLabelColor;
63+
COLORREF rangeStatusTextColor;
6364
unsigned int fontSize;
6465
bool showTagByDefault;
6566
IWTagMode defaultTagMode;
@@ -68,4 +69,14 @@ struct IWStyling {
6869
struct IWBehaviourSettings {
6970
bool openWindowsBasedOnActiveRunways;
7071
std::string windowStyle;
72+
};
73+
74+
struct IWConfig {
75+
IWStyling styling;
76+
IWBehaviourSettings behaviour;
77+
};
78+
79+
struct IWActiveRunway {
80+
std::string airport;
81+
std::string runway;
7182
};

0 commit comments

Comments
 (0)