Ocean
Loading...
Searching...
No Matches
platform/apple/macos/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_APPLE_MACOS_UTILITIES_H
9#define META_OCEAN_PLATFORM_APPLE_MACOS_UTILITIES_H
10
12
13#include "ocean/base/Frame.h"
14
15#include <CoreFoundation/CoreFoundation.h>
16
17#ifdef __OBJC__
19
20 #include <AppKit/AppKit.h>
21#endif
22
23namespace Ocean
24{
25
26namespace Platform
27{
28
29namespace Apple
30{
31
32namespace MacOS
33{
34
35/**
36 * This class implements utilitiy functions for MacOS platforms.
37 * @ingroup platformapplemacos
38 */
40{
41 public:
42
43 /**
44 * Definition of a vector holding application commands.
45 */
46 typedef std::vector<std::wstring> Commands;
47
48 /**
49 * Forward declaration of a manager for frame windows.
50 */
51 class FrameWindowManager;
52
53 public:
54
55 /**
56 * Returns the command arguments that have been passed during the start of the application.
57 * The first argument is really the first argument that has been passed by the user/caller.<br>
58 * Therefore, the first argument is not the filename (and path) of the executable.
59 * @return The individual commands
60 */
62
63#ifdef __OBJC__
64
65 /**
66 * Prints a text into a given image.
67 * @param image The image in which the text will be printed, must be valid
68 * @param x Horizontal location of the text within the image, with range (-infinity, infinity)
69 * @param y Vertical location of the text within the image, with range (-infinity, infinity)
70 * @param text The text to be printed
71 * @param fontSize The size of the font in points, with range (0, infinity)
72 */
73 static void imageTextOutput(NSImage* image, const int x, const int y, const std::string& text, const double fontSize = 14.0);
74
75 /**
76 * Prints a text into a given image.
77 * @param image The image in which the text will be printed, must be valid
78 * @param x Horizontal location of the text within the image, with range (-infinity, infinity)
79 * @param y Vertical location of the text within the image, with range (-infinity, infinity)
80 * @param text The text to be printed
81 * @param fontSize The size of the font in points, with range (0, infinity)
82 */
83 static void imageTextOutput(Image& image, const int x, const int y, const std::string& text, const double fontSize = 14.0);
84
85#endif // __OBJC__
86
87 /**
88 * Creates a window and paints a frame into the window.
89 * If the application is a window application, the new window will be created non-modal.<br>
90 * Instead, if the application is a console application, the new window will be created in a modal manner by default.<br>
91 * For console applications, this function must be called out of the main thread.<br>
92 * However, even in a console application the window can be created in a non modal manner - see 'modalIfSuitable',<br>
93 * e.g., to create/show two or more individual frames concurrently - so that they can be compared:
94 * @code
95 *
96 * // function creating two individual windows, the first non-modal, the second modal
97 * void functionInConsoleApplication()
98 * {
99 * /// we visualize the first frame in a non-modal manner
100 * Utilities::windowFrameOutput(10.0, 10.0, firstFrame, "First frame", false);
101 *
102 * /// we can do something here ...
103 *
104 * /// now we visualize the second frame in a modal manner,
105 * /// so that we can interact with both frames
106 * Utilities::windowFrameOutput(500.0, 10.0, secondFrame, "Second frame");
107 *
108 * /// we proceed when both windows have been closed by the user ...
109 * }
110 *
111 * // function creating one windows and constantly updating the frame
112 * void functionInConsoleApplication()
113 * {
114 * while (untilStop)
115 * {
116 * // a frame with updated image content
117 * Frame updatedFrame = ...
118 *
119 * // we update the frame in the single window
120 * Utilities::windowFrameOUtput(10.0, 10.0, updatedFrame, "Unique name", false);
121 * }
122 *
123 * // we wait here until the user has close the windows (e.g., to end the application)
124 * Utilities::waitForFrameOutput();
125 * }
126 * @endcode
127 * @param x Horizontal position of the window, in screen coordinates
128 * @param y Vertical position of the window, in screen coordinates
129 * @param frame The frame to be painted, must be valid
130 * @param title Optional title of the window displaying the frame, must be defined if a non-modal windows is supposed to be updated with new frames
131 * @param modalIfSuitable True, to create a modal window whenever suitable/necessary; False, to create a non-modal in any case while accepting that the window may not be maintainable as long as another windows in modal manner is created
132 * @param width Optional explicit width of the window painting the frame, in screen coordinates, 0 to use the width of the frame, with range [0, infinity)
133 * @param height Optional explicit height of the windows painting the frame, in screen coordinates, 0 to use the height of the frame, with range [0, infinity)
134 * @return True, if succeeded
135 * @see waitForFrameOutput().
136 */
137 static bool windowFrameOutput(const double x, const double y, const Frame& frame, const std::string& title = std::string(), const bool modalIfSuitable = true, const double width = 0.0, const double height = 0.0);
138
139 /**
140 * This function waits until all windows which have been created with `windowFrameOutput()` have been closed.
141 * @see windowFrameOutput().
142 */
143 static void waitForFrameOutput();
144};
145
146}
147
148}
149
150}
151
152}
153
154#endif // META_OCEAN_PLATFORM_APPLE_MACOS_UTILITIES_H
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements a wrapper for the NSImage object.
Definition platform/apple/macos/Image.h:38
This class implements utilitiy functions for MacOS platforms.
Definition platform/apple/macos/Utilities.h:40
static void imageTextOutput(Image &image, const int x, const int y, const std::string &text, const double fontSize=14.0)
Prints a text into a given image.
static void imageTextOutput(NSImage *image, const int x, const int y, const std::string &text, const double fontSize=14.0)
Prints a text into a given image.
static void waitForFrameOutput()
This function waits until all windows which have been created with windowFrameOutput() have been clos...
static bool windowFrameOutput(const double x, const double y, const Frame &frame, const std::string &title=std::string(), const bool modalIfSuitable=true, const double width=0.0, const double height=0.0)
Creates a window and paints a frame into the window.
static Commands commandArguments()
Returns the command arguments that have been passed during the start of the application.
std::vector< std::wstring > Commands
Definition of a vector holding application commands.
Definition platform/apple/macos/Utilities.h:46
The namespace covering the entire Ocean framework.
Definition Accessor.h:15