116{
117 if (
labels[0].IsEmpty()) {
120 }
121 else {
123#ifdef __WXOSX__
125 int BS = (int)
scale;
126#else
127 constexpr int BS = 1;
128#endif
129 wxSize thumbSize;
130 wxSize trackSize;
131 wxClientDC dc(this);
132#ifdef __WXOSX__
133 dc.SetFont(dc.GetFont().Scaled(
scale));
134#endif
135 wxSize textSize[2];
136 {
137 textSize[0] = dc.GetTextExtent(
labels[0]);
138 textSize[1] = dc.GetTextExtent(
labels[1]);
139 }
140 float fontScale = 0;
141 {
142 thumbSize = textSize[0];
143 auto size = textSize[1];
144 if (size.x > thumbSize.x) thumbSize.x = size.x;
145 else size.x = thumbSize.x;
146 thumbSize.x += BS * 12;
147 thumbSize.y += BS * 6;
148 trackSize.x = thumbSize.x + size.x + BS * 10;
149 trackSize.y = thumbSize.y + BS * 2;
150 auto maxWidth = GetMaxWidth();
151#ifdef __WXOSX__
153#endif
154 if (trackSize.x > maxWidth) {
155 fontScale = float(maxWidth) / trackSize.x;
156 thumbSize.x -= (trackSize.x - maxWidth) / 2;
157 trackSize.x = maxWidth;
158 }
159 }
160 for (int i = 0; i < 2; ++i) {
161 wxMemoryDC memdc(&dc);
162 wxImage image(trackSize);
163#ifndef __WXMSW__
164 image.InitAlpha();
165 memset(image.GetAlpha(), 0, trackSize.GetWidth() * trackSize.GetHeight());
166#endif
167 wxBitmap bmp(std::move(image));
168 memdc.SelectObject(bmp);
169#ifdef __WXMSW__
170 memdc.SetBackground(wxBrush(GetBackgroundColour()));
171 memdc.Clear();
172#endif
173 memdc.SetFont(dc.GetFont());
174#ifdef __WXMSW__
175 const double scale = GetDPIScaleFactor();
177#endif
178 if (fontScale) {
179 memdc.SetFont(dc.GetFont().Scaled(fontScale));
180 textSize[0] = memdc.GetTextExtent(
labels[0]);
181 textSize[1] = memdc.GetTextExtent(
labels[1]);
182 }
184 {
185#ifdef __WXMSW__
186 wxGCDC dc2(memdc);
187#else
188 wxDC &dc2(memdc);
189#endif
190 dc2.SetBrush(wxBrush(
track_color.colorForStates(state)));
191 dc2.SetPen(wxPen(
track_color.colorForStates(state)));
192 dc2.DrawRoundedRectangle(wxRect({0, 0}, trackSize), trackSize.y / 2.0);
195 dc2.DrawRoundedRectangle(wxRect({ i == 0 ? BS : (trackSize.x - thumbSize.x - BS), BS}, thumbSize), thumbSize.y / 2.0);
196 }
198 auto text_y = BS + (thumbSize.y - textSize[0].y) / 2;
199#ifdef __APPLE__
201 text_y -= FromDIP(2);
202 }
203#endif
204 memdc.DrawText(
labels[0], {BS + (thumbSize.x - textSize[0].x) / 2, text_y});
206 auto text_y_1 = BS + (thumbSize.y - textSize[1].y) / 2;
207#ifdef __APPLE__
209 text_y_1 -= FromDIP(2);
210 }
211#endif
212 memdc.DrawText(
labels[1], {trackSize.x - thumbSize.x - BS + (thumbSize.x - textSize[1].x) / 2, text_y_1});
213 memdc.SelectObject(wxNullBitmap);
214#ifdef __WXOSX__
215 bmp = wxBitmap(bmp.ConvertToImage(), -1,
scale);
216#elif defined(__WXMSW__)
217 bmp.SetScaleFactor(
scale);
218#endif
220 }
221 }
223#ifdef __WXGTK__
224 wxSize bestSize = GetBestSize();
225 bestSize.IncTo(
m_on.GetBmpSize());
226 SetSize(bestSize);
227 SetMinSize(bestSize);
228#else
229 SetSize(
m_on.GetBmpSize());
230#endif
231}
int scale(const int val)
Definition WipeTowerDialog.cpp:58
@ Enabled
Definition StateColor.hpp:17
double mac_max_scaling_factor()
Definition MacDarkMode.mm:35
int is_mac_version_15()
Definition MacUtils.mm:15