-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisplay_c.cpp
More file actions
144 lines (124 loc) · 3.68 KB
/
display_c.cpp
File metadata and controls
144 lines (124 loc) · 3.68 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "display_c.h"
#include <cstring>
#include <memory>
#include "../display.h"
#include "string_utils_c.h"
using namespace nativeapi;
// Basic identification getters
FFI_PLUGIN_EXPORT
char* native_display_get_id(native_display_t display) {
if (!display)
return nullptr;
return to_c_str(static_cast<Display*>(display)->GetId());
}
FFI_PLUGIN_EXPORT
char* native_display_get_name(native_display_t display) {
if (!display)
return nullptr;
return to_c_str(static_cast<Display*>(display)->GetName());
}
// Physical properties getters
FFI_PLUGIN_EXPORT
native_point_t native_display_get_position(native_display_t display) {
native_point_t result = {0.0, 0.0};
if (!display)
return result;
auto pos = static_cast<Display*>(display)->GetPosition();
result.x = pos.x;
result.y = pos.y;
return result;
}
FFI_PLUGIN_EXPORT
native_size_t native_display_get_size(native_display_t display) {
native_size_t result = {0.0, 0.0};
if (!display)
return result;
auto size = static_cast<Display*>(display)->GetSize();
result.width = size.width;
result.height = size.height;
return result;
}
FFI_PLUGIN_EXPORT
native_rectangle_t native_display_get_work_area(native_display_t display) {
native_rectangle_t result = {0.0, 0.0, 0.0, 0.0};
if (!display)
return result;
Rectangle work_area = static_cast<Display*>(display)->GetWorkArea();
result.x = work_area.x;
result.y = work_area.y;
result.width = work_area.width;
result.height = work_area.height;
return result;
}
FFI_PLUGIN_EXPORT
double native_display_get_scale_factor(native_display_t display) {
if (!display)
return 1.0;
return static_cast<Display*>(display)->GetScaleFactor();
}
// Additional properties getters
FFI_PLUGIN_EXPORT
bool native_display_is_primary(native_display_t display) {
if (!display)
return false;
return static_cast<Display*>(display)->IsPrimary();
}
FFI_PLUGIN_EXPORT
native_display_orientation_t native_display_get_orientation(native_display_t display) {
if (!display)
return NATIVE_DISPLAY_ORIENTATION_PORTRAIT;
DisplayOrientation orientation = static_cast<Display*>(display)->GetOrientation();
switch (orientation) {
case DisplayOrientation::kPortrait:
return NATIVE_DISPLAY_ORIENTATION_PORTRAIT;
case DisplayOrientation::kLandscape:
return NATIVE_DISPLAY_ORIENTATION_LANDSCAPE;
case DisplayOrientation::kPortraitFlipped:
return NATIVE_DISPLAY_ORIENTATION_PORTRAIT_FLIPPED;
case DisplayOrientation::kLandscapeFlipped:
return NATIVE_DISPLAY_ORIENTATION_LANDSCAPE_FLIPPED;
default:
return NATIVE_DISPLAY_ORIENTATION_PORTRAIT;
}
}
FFI_PLUGIN_EXPORT
int native_display_get_refresh_rate(native_display_t display) {
if (!display)
return 0;
return static_cast<Display*>(display)->GetRefreshRate();
}
FFI_PLUGIN_EXPORT
int native_display_get_bit_depth(native_display_t display) {
if (!display)
return 0;
return static_cast<Display*>(display)->GetBitDepth();
}
// Platform-specific functions
FFI_PLUGIN_EXPORT
void* native_display_get_native_object(native_display_t display) {
if (!display)
return nullptr;
return static_cast<Display*>(display)->GetNativeObject();
}
// Memory management
FFI_PLUGIN_EXPORT
void native_display_free(native_display_t display) {
if (display) {
delete static_cast<Display*>(display);
}
}
FFI_PLUGIN_EXPORT
void native_display_list_free(native_display_list_t* list) {
if (!list || !list->displays)
return;
// Free individual display handles
for (long i = 0; i < list->count; i++) {
if (list->displays[i]) {
delete static_cast<Display*>(list->displays[i]);
}
}
// Free the displays array
delete[] list->displays;
list->displays = nullptr;
list->count = 0;
}