-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (88 loc) · 3.61 KB
/
Copy pathmain.cpp
File metadata and controls
112 lines (88 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iomanip>
#include <iostream>
#include <sstream>
#include "nativeapi.h"
using nativeapi::Display;
using nativeapi::DisplayManager;
using nativeapi::DisplayOrientation;
using nativeapi::Point;
using nativeapi::Rectangle;
using nativeapi::Size;
// Helper function to convert orientation enum to string
std::string orientationToString(DisplayOrientation orientation) {
switch (orientation) {
case DisplayOrientation::kPortrait:
return "Portrait (0°)";
case DisplayOrientation::kLandscape:
return "Landscape (90°)";
case DisplayOrientation::kPortraitFlipped:
return "Portrait Flipped (180°)";
case DisplayOrientation::kLandscapeFlipped:
return "Landscape Flipped (270°)";
default:
return "Unknown";
}
}
int main() {
try {
std::cout << "=== Native API C++ Display Example ===" << std::endl << std::endl;
DisplayManager& displayManager = DisplayManager::GetInstance();
// Test getting all displays
std::vector<Display> displays = displayManager.GetAll();
if (!displays.empty()) {
std::cout << "Found " << displays.size() << " display(s):" << std::endl << std::endl;
for (size_t i = 0; i < displays.size(); i++) {
const Display& display = displays[i];
std::cout << "Display " << (i + 1) << ":" << std::endl;
// Name
std::cout << " Name: " << display.GetName() << std::endl;
// ID
std::cout << " ID: " << display.GetId() << std::endl;
// Position
Point position = display.GetPosition();
std::cout << " Position: (" << (int)position.x << ", " << (int)position.y << ")"
<< std::endl;
// Size
Size size = display.GetSize();
std::cout << " Size: " << (int)size.width << " x " << (int)size.height << std::endl;
// Work Area
Rectangle workArea = display.GetWorkArea();
std::cout << " Work Area: (" << (int)workArea.x << ", " << (int)workArea.y << ") "
<< (int)workArea.width << " x " << (int)workArea.height << std::endl;
// Scale Factor
std::cout << " Scale Factor: " << std::fixed << std::setprecision(2)
<< display.GetScaleFactor() << std::endl;
// Primary
std::cout << " Primary: " << (display.IsPrimary() ? "Yes" : "No") << std::endl;
// Orientation
std::cout << " Orientation: " << orientationToString(display.GetOrientation())
<< std::endl;
// Refresh Rate
std::cout << " Refresh Rate: " << display.GetRefreshRate() << " Hz" << std::endl;
// Bit Depth
std::cout << " Bit Depth: " << display.GetBitDepth() << " bits" << std::endl;
std::cout << std::endl;
}
} else {
std::cout << "No displays found or error occurred" << std::endl;
}
// Test getting primary display
std::cout << "=== Primary Display ===" << std::endl;
Display primary = displayManager.GetPrimary();
std::cout << "Primary display: " << primary.GetName() << std::endl;
Size size = primary.GetSize();
std::cout << "Size: " << (int)size.width << " x " << (int)size.height << std::endl;
// Test getting cursor position
std::cout << std::endl << "=== Cursor Position ===" << std::endl;
Point cursorPos = displayManager.GetCursorPosition();
std::cout << "Cursor position: (" << (int)cursorPos.x << ", " << (int)cursorPos.y << ")"
<< std::endl;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "Unknown error occurred" << std::endl;
return 1;
}
return 0;
}