Ocean
Loading...
Searching...
No Matches
platform/win/Utilities.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_WIN_UTILITIES_H
9#define META_OCEAN_PLATFORM_WIN_UTILITIES_H
10
13
14#include "ocean/base/Frame.h"
15
17
18#ifdef OCEAN_COMPILER_MSC
19 #pragma managed(push, off)
20#endif
21
22#include "ocean/base/String.h"
23
24#ifdef OCEAN_COMPILER_MSC
25 #pragma managed(pop)
26#endif
27
28namespace Ocean
29{
30
31namespace Platform
32{
33
34namespace Win
35{
36
37/**
38 * This class implements utilities and helper functions.
39 * @ingroup platformwin
40 */
41class OCEAN_PLATFORM_WIN_EXPORT Utilities
42{
43 public:
44
45 /**
46 * Definition of anchor positions for text rendering.
47 */
48 enum AnchorPosition : uint32_t
49 {
50 /// Text is anchored at the top-left corner
52 /// Text is anchored at the top-right corner
54 /// Text is anchored at the bottom-left corner
56 /// Text is anchored at the bottom-right corner
58 /// Text is centered
59 AP_CENTER
60 };
61
62 public:
63
64 /**
65 * Prints a text on the given device context.
66 * @param dc The device context on which the text will be drawn
67 * @param x Horizontal output position
68 * @param y Vertical output position
69 * @param text Text to be printed
70 */
71 static void textOutput(HDC dc, const int x, const int y, const std::string& text);
72
73 /**
74 * Draws styled text on a device context with customizable font, anchor position, and colors.
75 * The text can be positioned using anchor points relative to the window dimensions, with optional shadow for better visibility.
76 * @param deviceContext The device context on which the text will be drawn
77 * @param text The text to be drawn
78 * @param font The name of the font to use (e.g., "Arial")
79 * @param fontSize The height of the font in pixels
80 * @param bold True to use bold font weight; False for normal weight
81 * @param anchorPosition The anchor position for the text
82 * @param windowWidth The width of the window, used for anchor calculations
83 * @param windowHeight The height of the window, used for anchor calculations
84 * @param foregroundColor The color of the text (RGB value)
85 * @param backgroundColor The background color of the text, or -1 for transparent background
86 * @param shadowColor The color of the shadow, or -1 to disable shadow
87 * @param shadowOffsetX The horizontal offset of the shadow in pixels, with range [0, infinity)
88 * @param shadowOffsetY The vertical offset of the shadow in pixels, with range [0, infinity)
89 * @param marginX The horizontal margin from the window edge in pixels, with range [0, infinity)
90 * @param marginY The vertical margin from the window edge in pixels, with range [0, infinity)
91 */
92 static void textOutput(HDC deviceContext, const std::wstring& text, const std::wstring& font, const unsigned int fontSize, const bool bold, const AnchorPosition anchorPosition, const unsigned int windowWidth, const unsigned int windowHeight, const int32_t foregroundColor, const int32_t backgroundColor = -1, const int32_t shadowColor = -1, const unsigned int shadowOffsetX = 2u, const unsigned int shadowOffsetY = 2u, const unsigned int marginX = 20u, const unsigned int marginY = 20u);
93
94 /**
95 * Prints a text on the desktop.
96 * @param x Horizontal output position
97 * @param y Vertical output position
98 * @param text Text to be printed
99 */
100 static void desktopTextOutput(const int x, const int y, const std::string& text);
101
102 /**
103 * Prints a frame on the given device context.
104 * @param dc Device context receiving the frame
105 * @param x Horizontal output position
106 * @param y Vertical output position
107 * @param frame The frame to be printed
108 */
109 static void frameOutput(HDC dc, const int x, const int y, const Frame& frame);
110
111 /**
112 * Prints a frame on the given device context.
113 * @param dc Device context receiving the text
114 * @param x Horizontal output position
115 * @param y Vertical output position
116 * @param width Output width in pixel
117 * @param height Output height in pixel
118 * @param frame The frame to be printed
119 */
120 static void frameOutput(HDC dc, const int x, const int y, const unsigned int width, const unsigned int height, const Frame& frame);
121
122 /**
123 * Prints a given frame on the Windows' main desktop at a specified location.
124 * You do not need to have a GUI application to use this function.<br>
125 * Call this function from any application and from any thread.<br>
126 * The painted frame will disappear immediately when Windows receives any repaint event.<br>
127 * This function is intended for debugging purposes only.
128 * @param x Horizontal output position, with range (-infinity, infinity)
129 * @param y Vertical output position, with range (-infinity, infinity)
130 * @param frame The frame to be printed
131 */
132 static void desktopFrameOutput(const int x, const int y, const Frame& frame);
133
134 /**
135 * Prints a given frame on the Windows' main desktop at a specified location.
136 * You do not need to have a GUI application to use this function.<br>
137 * Call this function from any application and from any thread.<br>
138 * The painted frame will disappear immediately when Windows receives any repaint event.<br>
139 * This function is intended for debugging purposes only.
140 * @param x Horizontal output position, with range (-infinity, infinity)
141 * @param y Vertical output position, with range (-infinity, infinity)
142 * @param scale The scale that is applied to the frame, a factor of 2 will increase the painted frame by two, with range [1, infinity)
143 * @param frame The frame to be printed
144 */
145 static inline void desktopFrameOutput(const int x, const int y, const unsigned int scale, const Frame& frame);
146
147 /**
148 * Prints a given frame on the Windows' main desktop at a specified location.
149 * You do not need to have a GUI application to use this function.<br>
150 * Call this function from any application and from any thread.<br>
151 * The painted frame will disappear immediately when Windows receives any repaint event.<br>
152 * This function is intended for debugging purposes only.
153 * @param x Horizontal output position, with range (-infinity, infinity)
154 * @param y Vertical output position, with range (-infinity, infinity)
155 * @param width The width of the painted frame in the domain of the desktop, in pixel, with range [1, infinity)
156 * @param height The height of the painted frame in the domain of the desktop, in pixel, with range [1, infinity)
157 * @param frame The frame to be printed
158 */
159 static void desktopFrameOutput(const int x, const int y, const unsigned int width, const unsigned int height, const Frame& frame);
160
161 /**
162 * Prints a bitmap on the given device context.
163 * @param dc Device context receiving the bitmap
164 * @param x Horizontal output position
165 * @param y Vertical output position
166 * @param bitmap bitmap to be printed
167 */
168 static void bitmapOutput(HDC dc, const int x, const int y, const Bitmap& bitmap);
169
170 /**
171 * Prints a bitmap on the desktop.
172 * @param x Horizontal output position
173 * @param y Vertical output position
174 * @param scale Scale of the output bitmap
175 * @param bitmap Bitmap to be printed
176 */
177 static inline void desktopBitmapOutput(const int x, const int y, const unsigned int scale, const Bitmap& bitmap);
178
179 /**
180 * Prints a bitmap on the given device context.
181 * @param dc Device context receiving the text
182 * @param x Horizontal output position
183 * @param y Vertical output position
184 * @param width Output width in pixel
185 * @param height Output height in pixel
186 * @param bitmap bitmap to be printed
187 */
188 static void bitmapOutput(HDC dc, const int x, const int y, const unsigned int width, const unsigned int height, const Bitmap& bitmap);
189
190 /**
191 * Prints a bitmap on the desktop.
192 * @param x Horizontal output position
193 * @param y Vertical output position
194 * @param bitmap bitmap to be printed
195 */
196 static void desktopBitmapOutput(const int x, const int y, const Bitmap& bitmap);
197
198 /**
199 * Prints a bitmap on the desktop.
200 * @param x Horizontal output position
201 * @param y Vertical output position
202 * @param width Output width in pixel
203 * @param height Output height in pixel
204 * @param bitmap bitmap to be printed
205 */
206 static void desktopBitmapOutput(const int x, const int y, const unsigned int width, const unsigned int height, const Bitmap& bitmap);
207
208 /**
209 * Determines the bounding box of a given string with specified font and font size.
210 * @param value The string for which the bounding box will be determined
211 * @param font The name of the font which will be applied
212 * @param size The size of the font
213 * @return The bounding box of the given string
214 */
215 static CV::PixelBoundingBox textBoundingBox(const std::string& value, const std::string& font = std::string(), const unsigned int size = 0u);
216
217 /**
218 * Determines the bounding box of a given string with specified font and font size.
219 * @param value The string for which the bounding box will be determined
220 * @param font The name of the font which will be applied
221 * @param size The size of the font
222 * @return The bounding box of the given string
223 */
224 static CV::PixelBoundingBox textBoundingBox(const std::wstring& value, const std::wstring& font = std::wstring(), const unsigned int size = 0u);
225
226};
227
228/**
229 * This class implements a scoped device context.
230 * The device context is acquired for a given window, or for the entire screen if no window is given, and is released again once the object is disposed.<br>
231 * The window handle is kept alongside the device context, as it is needed to release it again.
232 * @ingroup platformwin
233 */
234class OCEAN_PLATFORM_WIN_EXPORT ScopedDC
235{
236 public:
237
238 /**
239 * Creates an object not holding a device context.
240 */
241 ScopedDC() = default;
242
243 /**
244 * Move constructor.
245 * @param scopedDC The object to be moved
246 */
247 inline ScopedDC(ScopedDC&& scopedDC) noexcept;
248
249 /**
250 * Acquires the device context of a given window.
251 * In case the device context cannot be acquired, the resulting object will be invalid.
252 * @param window The window for which the device context will be acquired, nullptr to acquire the device context of the entire screen
253 */
254 explicit inline ScopedDC(const HWND window);
255
256 /**
257 * Destructs this object and releases the device context.
258 */
259 inline ~ScopedDC();
260
261 /**
262 * Returns whether this object holds a device context.
263 * @return True, if so
264 */
265 inline bool isValid() const;
266
267 /**
268 * Returns the wrapped device context.
269 * Ensure that this object holds a device context before calling this operator.
270 * @return The wrapped device context
271 * @see isValid().
272 */
273 inline HDC operator*() const;
274
275 /**
276 * Explicitly releases the device context.
277 */
278 inline void release();
279
280 /**
281 * Move operator.
282 * @param scopedDC The object to be moved
283 * @return Reference to this object
284 */
285 inline ScopedDC& operator=(ScopedDC&& scopedDC) noexcept;
286
287 protected:
288
289 /**
290 * Disabled copy constructor.
291 */
292 ScopedDC(const ScopedDC&) = delete;
293
294 /**
295 * Disabled assign operator.
296 * @return Reference to this object
297 */
298 ScopedDC& operator=(const ScopedDC&) = delete;
299
300 protected:
301
302 /// The window for which the device context has been acquired, nullptr for the entire screen or if this object is invalid.
303 HWND window_ = nullptr;
304
305 /// The wrapped device context, nullptr if this object does not hold one.
306 HDC dc_ = nullptr;
307};
308
309/**
310 * This class implements a scoped font which is selected into a device context.
311 * The font is created and selected when the object is created, and is deselected and deleted once the object is disposed.<br>
312 * A font cannot be deleted while it is still selected into a device context, so both steps belong together.
313 * @ingroup platformwin
314 */
315class OCEAN_PLATFORM_WIN_EXPORT ScopedFont
316{
317 public:
318
319 /**
320 * Creates an object not holding a font.
321 */
322 ScopedFont() = default;
323
324 /**
325 * Move constructor.
326 * @param scopedFont The object to be moved
327 */
328 inline ScopedFont(ScopedFont&& scopedFont) noexcept;
329
330 /**
331 * Selects an existing font into a given device context and takes ownership of the font.
332 * In case the given font is invalid, the resulting object will be invalid.
333 * @param dc The device context into which the font will be selected, must be valid
334 * @param font The font to be selected, will be owned by this object
335 */
336 ScopedFont(HDC dc, HFONT font);
337
338 /**
339 * Creates a new font and selects it into a given device context.
340 * In case the font cannot be created, the resulting object will be invalid.
341 * @param dc The device context into which the new font will be selected, must be valid
342 * @param logFont The description of the font to be created
343 */
344 ScopedFont(HDC dc, const LOGFONTW& logFont);
345
346 /**
347 * Destructs this object, deselects the font and deletes it.
348 */
349 inline ~ScopedFont();
350
351 /**
352 * Returns whether this object holds a font.
353 * @return True, if so
354 */
355 inline bool isValid() const;
356
357 /**
358 * Returns the wrapped font.
359 * Ensure that this object holds a font before calling this operator.
360 * @return The wrapped font
361 * @see isValid().
362 */
363 inline HFONT operator*() const;
364
365 /**
366 * Explicitly deselects and deletes the font.
367 */
368 void release();
369
370 /**
371 * Move operator.
372 * @param scopedFont The object to be moved
373 * @return Reference to this object
374 */
375 inline ScopedFont& operator=(ScopedFont&& scopedFont) noexcept;
376
377 protected:
378
379 /**
380 * Disabled copy constructor.
381 */
382 ScopedFont(const ScopedFont&) = delete;
383
384 /**
385 * Disabled assign operator.
386 * @return Reference to this object
387 */
388 ScopedFont& operator=(const ScopedFont&) = delete;
389
390 protected:
391
392 /// The device context into which the font is selected, nullptr if this object does not hold a font.
393 HDC dc_ = nullptr;
394
395 /// The font which is selected into the device context, nullptr if this object does not hold a font.
396 HFONT font_ = nullptr;
397
398 /// The font which was selected into the device context before, nullptr if none was selected.
399 HFONT previousFont_ = nullptr;
400};
401
402/**
403 * This class implements a nested scoped object which disables a window object until the scope of all nested elements ends (or until all nested object are released explicitly).
404 * The creation of the first nested object disables the window.<br>
405 * Following nested objects only increase the internal counter while do not have any further consequence.<br>
406 * @ingroup platformwin
407 */
409{
410 protected:
411
412 /**
413 * This class implements a simple counter for nested disable window objects.
414 */
415 class DisableWindowCounter : public Singleton<DisableWindowCounter>
416 {
417 friend class Singleton<DisableWindowCounter>;
419
420 protected:
421
422 /**
423 * Definition of a map mapping window handles to counters.
424 */
425 using CounterMap = std::unordered_map<HWND, unsigned int>;
426
427 protected:
428
429 /**
430 * Creates a new DisableWindowCounter object.
431 */
432 inline DisableWindowCounter();
433
434 /**
435 * Destructs a DisableWindowCounter object.
436 */
437 inline ~DisableWindowCounter();
438
439 /**
440 * Increases the counter of this object.
441 * @return True, if the counter was zero before the counter has been increased
442 */
443 inline bool increase(const HWND windowHandle);
444
445 /**
446 * Decreases the counter of this object.
447 * @return True, if the counter is zero after it has been decreased
448 */
449 inline bool decrease(const HWND windowHandle);
450
451 /**
452 * Returns whether the counter is zero.
453 * @return True, if so
454 */
455 inline bool isZero(const HWND windowHandle);
456
457 /**
458 * Returns the lock object.
459 * @return Lock object
460 */
461 inline Lock& lock();
462
463 protected:
464
465 /// Disable window counter.
467
468 /// Disable window lock.
470 };
471
472 public:
473
474 /**
475 * Creates a new scoped object and disables the associated window.
476 * @param windowHandle Handle of the window to disable, this window must not be disposed before this scoped object is disposed
477 */
478 explicit ScopedDisableWindow(const HWND windowHandle);
479
480 /**
481 * Destructs this scoped object and enables the associated window.
482 */
483 inline ~ScopedDisableWindow();
484
485 /**
486 * Explicitly releases the scoped object and enables the associated window (already before the scope ends).
487 */
488 void release();
489
490 protected:
491
492 /**
493 * Disabled copy constructor.
494 * @param window The window that would be copied
495 */
497
498 /**
499 * Disabled assign operator.
500 * @param window The window that would be assigned
501 */
503
504 protected:
505
506 /// The associated window, nullptr if the object has been released already.
507 HWND handle_ = nullptr;
508};
509
510#if defined(OCEAN_COMPILER_MSC) && defined(_MANAGED)
511
512inline System::String^ toString(const std::string& value)
513{
514 return gcnew System::String(value.c_str());
515}
516
517inline System::String^ toString(const char* value)
518{
519 return gcnew System::String(value);
520}
521
522inline System::String^ toString(const std::wstring& value)
523{
524 return gcnew System::String(value.c_str());
525}
526
527inline System::String^ toString(const wchar_t* value)
528{
529 return gcnew System::String(value);
530}
531
532inline std::string toAString(System::String^ value)
533{
534 char* str = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(value);
535 std::string result(str);
536
537 System::Runtime::InteropServices::Marshal::FreeHGlobal(System::IntPtr(str));
538
539 return result;
540}
541
542inline std::wstring toWString(System::String^ value)
543{
544 char* str = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(value);
545 std::string result(str);
546
547 System::Runtime::InteropServices::Marshal::FreeHGlobal(System::IntPtr(str));
548
549 return Ocean::String::toWString(result);
550}
551
552#endif // OCEAN_COMPILER_MSC && _MANAGED
553
554inline void Utilities::desktopFrameOutput(const int x, const int y, const unsigned int scale, const Frame& frame)
555{
556 desktopFrameOutput(x, y, frame.width() * scale, frame.height() * scale, frame);
557}
558
559inline void Utilities::desktopBitmapOutput(const int x, const int y, const unsigned int scale, const Bitmap& bitmap)
560{
561 desktopBitmapOutput(x, y, bitmap.width() * scale, bitmap.height() * scale, bitmap);
562}
563
564inline ScopedDC::ScopedDC(ScopedDC&& scopedDC) noexcept
565{
566 *this = std::move(scopedDC);
567}
568
569inline ScopedDC::ScopedDC(const HWND window) :
570 window_(window),
571 dc_(GetDC(window))
572{
573 // nothing to do here
574}
575
577{
578 release();
579}
580
581inline bool ScopedDC::isValid() const
582{
583 return dc_ != nullptr;
584}
585
586inline HDC ScopedDC::operator*() const
587{
588 ocean_assert(isValid());
589
590 return dc_;
591}
592
593inline void ScopedDC::release()
594{
595 if (dc_ != nullptr)
596 {
597 ReleaseDC(window_, dc_);
598
599 window_ = nullptr;
600 dc_ = nullptr;
601 }
602}
603
604inline ScopedDC& ScopedDC::operator=(ScopedDC&& scopedDC) noexcept
605{
606 if (this != &scopedDC)
607 {
608 release();
609
610 window_ = scopedDC.window_;
611 dc_ = scopedDC.dc_;
612
613 scopedDC.window_ = nullptr;
614 scopedDC.dc_ = nullptr;
615 }
616
617 return *this;
618}
619
620inline ScopedFont::ScopedFont(ScopedFont&& scopedFont) noexcept
621{
622 *this = std::move(scopedFont);
623}
624
626{
627 release();
628}
629
630inline bool ScopedFont::isValid() const
631{
632 return font_ != nullptr;
633}
634
635inline HFONT ScopedFont::operator*() const
636{
637 ocean_assert(isValid());
638
639 return font_;
640}
641
642inline ScopedFont& ScopedFont::operator=(ScopedFont&& scopedFont) noexcept
643{
644 if (this != &scopedFont)
645 {
646 release();
647
648 dc_ = scopedFont.dc_;
649 font_ = scopedFont.font_;
650 previousFont_ = scopedFont.previousFont_;
651
652 scopedFont.dc_ = nullptr;
653 scopedFont.font_ = nullptr;
654 scopedFont.previousFont_ = nullptr;
655 }
656
657 return *this;
658}
659
661{
662 // nothing to do here
663}
664
666{
667#ifdef OCEAN_DEBUG
668
669 for (CounterMap::value_type& counterPair : counterMap_)
670 {
671 ocean_assert(counterPair.second == 0u);
672 }
673
674#endif
675}
676
677inline bool ScopedDisableWindow::DisableWindowCounter::increase(const HWND windowHandle)
678{
679 counterMap_[windowHandle]++;
680
681 return counterMap_[windowHandle] == 1u;
682}
683
684inline bool ScopedDisableWindow::DisableWindowCounter::decrease(const HWND windowHandle)
685{
686 ocean_assert(counterMap_.find(windowHandle) != counterMap_.end());
687 ocean_assert(counterMap_[windowHandle] >= 1u);
688
689 counterMap_[windowHandle]--;
690
691 return counterMap_[windowHandle] == 0u;
692}
693
694inline bool ScopedDisableWindow::DisableWindowCounter::isZero(const HWND windowHandle)
695{
696 return counterMap_[windowHandle] == 0u;
697}
698
700{
701 return windowLock_;
702}
703
708
709}
710
711}
712
713}
714
715#endif // META_OCEAN_PLATFORM_WIN_UTILITIES_H
This class implements Ocean's image class.
Definition Frame.h:1969
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3334
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3339
This class implements a recursive lock object.
Definition Lock.h:31
This class implements a Windows device independent bitmap.
Definition win/Bitmap.h:30
unsigned int width() const
Returns the width of the bitmap.
Definition win/Bitmap.h:267
unsigned int height() const
Returns the height of the bitmap.
Definition win/Bitmap.h:272
This class implements a scoped device context.
Definition platform/win/Utilities.h:235
HDC operator*() const
Returns the wrapped device context.
Definition platform/win/Utilities.h:586
HDC dc_
The wrapped device context, nullptr if this object does not hold one.
Definition platform/win/Utilities.h:306
ScopedDC(const ScopedDC &)=delete
Disabled copy constructor.
bool isValid() const
Returns whether this object holds a device context.
Definition platform/win/Utilities.h:581
HWND window_
The window for which the device context has been acquired, nullptr for the entire screen or if this o...
Definition platform/win/Utilities.h:303
void release()
Explicitly releases the device context.
Definition platform/win/Utilities.h:593
ScopedDC()=default
Creates an object not holding a device context.
ScopedDC & operator=(const ScopedDC &)=delete
Disabled assign operator.
~ScopedDC()
Destructs this object and releases the device context.
Definition platform/win/Utilities.h:576
ScopedDC & operator=(ScopedDC &&scopedDC) noexcept
Move operator.
Definition platform/win/Utilities.h:604
This class implements a simple counter for nested disable window objects.
Definition platform/win/Utilities.h:416
CounterMap counterMap_
Disable window counter.
Definition platform/win/Utilities.h:466
~DisableWindowCounter()
Destructs a DisableWindowCounter object.
Definition platform/win/Utilities.h:665
Lock windowLock_
Disable window lock.
Definition platform/win/Utilities.h:469
bool isZero(const HWND windowHandle)
Returns whether the counter is zero.
Definition platform/win/Utilities.h:694
DisableWindowCounter()
Creates a new DisableWindowCounter object.
Definition platform/win/Utilities.h:660
std::unordered_map< HWND, unsigned int > CounterMap
Definition of a map mapping window handles to counters.
Definition platform/win/Utilities.h:425
Lock & lock()
Returns the lock object.
Definition platform/win/Utilities.h:699
bool increase(const HWND windowHandle)
Increases the counter of this object.
Definition platform/win/Utilities.h:677
bool decrease(const HWND windowHandle)
Decreases the counter of this object.
Definition platform/win/Utilities.h:684
This class implements a nested scoped object which disables a window object until the scope of all ne...
Definition platform/win/Utilities.h:409
ScopedDisableWindow(const ScopedDisableWindow &window)=delete
Disabled copy constructor.
HWND handle_
The associated window, nullptr if the object has been released already.
Definition platform/win/Utilities.h:507
~ScopedDisableWindow()
Destructs this scoped object and enables the associated window.
Definition platform/win/Utilities.h:704
ScopedDisableWindow(const HWND windowHandle)
Creates a new scoped object and disables the associated window.
ScopedDisableWindow & operator=(const ScopedDisableWindow &window)=delete
Disabled assign operator.
void release()
Explicitly releases the scoped object and enables the associated window (already before the scope end...
This class implements a scoped font which is selected into a device context.
Definition platform/win/Utilities.h:316
ScopedFont(const ScopedFont &)=delete
Disabled copy constructor.
bool isValid() const
Returns whether this object holds a font.
Definition platform/win/Utilities.h:630
ScopedFont & operator=(ScopedFont &&scopedFont) noexcept
Move operator.
Definition platform/win/Utilities.h:642
ScopedFont & operator=(const ScopedFont &)=delete
Disabled assign operator.
HFONT operator*() const
Returns the wrapped font.
Definition platform/win/Utilities.h:635
ScopedFont(HDC dc, HFONT font)
Selects an existing font into a given device context and takes ownership of the font.
~ScopedFont()
Destructs this object, deselects the font and deletes it.
Definition platform/win/Utilities.h:625
ScopedFont()=default
Creates an object not holding a font.
void release()
Explicitly deselects and deletes the font.
HFONT font_
The font which is selected into the device context, nullptr if this object does not hold a font.
Definition platform/win/Utilities.h:396
ScopedFont(HDC dc, const LOGFONTW &logFont)
Creates a new font and selects it into a given device context.
This class implements utilities and helper functions.
Definition platform/win/Utilities.h:42
static void bitmapOutput(HDC dc, const int x, const int y, const unsigned int width, const unsigned int height, const Bitmap &bitmap)
Prints a bitmap on the given device context.
static void frameOutput(HDC dc, const int x, const int y, const Frame &frame)
Prints a frame on the given device context.
static void frameOutput(HDC dc, const int x, const int y, const unsigned int width, const unsigned int height, const Frame &frame)
Prints a frame on the given device context.
static void desktopFrameOutput(const int x, const int y, const Frame &frame)
Prints a given frame on the Windows' main desktop at a specified location.
static void textOutput(HDC dc, const int x, const int y, const std::string &text)
Prints a text on the given device context.
static CV::PixelBoundingBox textBoundingBox(const std::string &value, const std::string &font=std::string(), const unsigned int size=0u)
Determines the bounding box of a given string with specified font and font size.
static void desktopTextOutput(const int x, const int y, const std::string &text)
Prints a text on the desktop.
static void textOutput(HDC deviceContext, const std::wstring &text, const std::wstring &font, const unsigned int fontSize, const bool bold, const AnchorPosition anchorPosition, const unsigned int windowWidth, const unsigned int windowHeight, const int32_t foregroundColor, const int32_t backgroundColor=-1, const int32_t shadowColor=-1, const unsigned int shadowOffsetX=2u, const unsigned int shadowOffsetY=2u, const unsigned int marginX=20u, const unsigned int marginY=20u)
Draws styled text on a device context with customizable font, anchor position, and colors.
static CV::PixelBoundingBox textBoundingBox(const std::wstring &value, const std::wstring &font=std::wstring(), const unsigned int size=0u)
Determines the bounding box of a given string with specified font and font size.
AnchorPosition
Definition of anchor positions for text rendering.
Definition platform/win/Utilities.h:49
@ AP_BOTTOM_RIGHT
Text is anchored at the bottom-right corner.
Definition platform/win/Utilities.h:57
@ AP_BOTTOM_LEFT
Text is anchored at the bottom-left corner.
Definition platform/win/Utilities.h:55
@ AP_TOP_RIGHT
Text is anchored at the top-right corner.
Definition platform/win/Utilities.h:53
@ AP_TOP_LEFT
Text is anchored at the top-left corner.
Definition platform/win/Utilities.h:51
static void desktopBitmapOutput(const int x, const int y, const unsigned int width, const unsigned int height, const Bitmap &bitmap)
Prints a bitmap on the desktop.
static void bitmapOutput(HDC dc, const int x, const int y, const Bitmap &bitmap)
Prints a bitmap on the given device context.
static void desktopFrameOutput(const int x, const int y, const unsigned int width, const unsigned int height, const Frame &frame)
Prints a given frame on the Windows' main desktop at a specified location.
static void desktopBitmapOutput(const int x, const int y, const Bitmap &bitmap)
Prints a bitmap on the desktop.
static void desktopBitmapOutput(const int x, const int y, const unsigned int scale, const Bitmap &bitmap)
Prints a bitmap on the desktop.
Definition platform/win/Utilities.h:559
This template class is the base class for all singleton objects.
Definition Singleton.h:71
static std::wstring toWString(const char value)
Converts a value to a wstring.
std::string toAString(System::String^ value)
Definition platform/win/Utilities.h:532
std::wstring toWString(System::String^ value)
Definition platform/win/Utilities.h:542
System::String toString(const std::string &value)
Definition platform/win/Utilities.h:512
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
AutomaticDifferentiationT< T1, TNumeric1 > operator*(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:528