Skip to content

Commit ace3a00

Browse files
author
eddyStreamlabs
authored
Merge pull request #76 from stream-labs/display-creation
Add size and position on display creation
2 parents b1ce244 + e1248cf commit ace3a00

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

obs-studio-client/source/nodeobs_display.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ void display::OBS_content_createDisplay(const v8::FunctionCallbackInfo<v8::Value
4141
FixChromeD3DIssue((HWND)windowHandle);
4242

4343
std::string key;
44+
uint32_t width, height, positionX, positionY;
4445
ASSERT_GET_VALUE(args[1], key);
46+
ASSERT_GET_VALUE(args[2], width);
47+
ASSERT_GET_VALUE(args[3], height);
48+
ASSERT_GET_VALUE(args[4], positionX);
49+
ASSERT_GET_VALUE(args[5], positionY);
4550

4651
auto conn = GetConnection();
4752
if (!conn) return;
4853

4954
std::vector<ipc::value> response =
5055
conn->call_synchronous_helper("Display", "OBS_content_createDisplay",
51-
{ ipc::value(windowHandle), ipc::value(key) });
56+
{ ipc::value(windowHandle), ipc::value(key),
57+
ipc::value(width), ipc::value(height), ipc::value(positionX), ipc::value(positionY) });
5258

5359
ValidateResponse(response);
5460
}
@@ -127,15 +133,21 @@ void display::OBS_content_createSourcePreviewDisplay(const v8::FunctionCallbackI
127133
FixChromeD3DIssue((HWND)windowHandle);
128134

129135
std::string sourceName, key;
136+
uint32_t width, height, positionX, positionY;
130137
ASSERT_GET_VALUE(args[1], sourceName);
131138
ASSERT_GET_VALUE(args[2], key);
139+
ASSERT_GET_VALUE(args[3], width);
140+
ASSERT_GET_VALUE(args[4], height);
141+
ASSERT_GET_VALUE(args[5], positionX);
142+
ASSERT_GET_VALUE(args[6], positionY);
132143

133144
auto conn = GetConnection();
134145
if (!conn) return;
135146

136147
std::vector<ipc::value> response =
137148
conn->call_synchronous_helper("Display", "OBS_content_createSourcePreviewDisplay",
138-
{ ipc::value(windowHandle), ipc::value(sourceName), ipc::value(key) });
149+
{ ipc::value(windowHandle), ipc::value(sourceName), ipc::value(key),
150+
ipc::value(width), ipc::value(height), ipc::value(positionX), ipc::value(positionY) });
139151

140152
ValidateResponse(response);
141153
}

obs-studio-server/source/nodeobs_common.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ void OBS_content::Register(ipc::server& srv) {
109109
std::shared_ptr<ipc::collection> cls = std::make_shared<ipc::collection>("Display");
110110

111111
cls->register_function(std::make_shared<ipc::function>("OBS_content_createDisplay",
112-
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String}, OBS_content_createDisplay));
112+
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String, ipc::type::UInt32, ipc::type::UInt32,
113+
ipc::type::UInt32, ipc::type::UInt32}, OBS_content_createDisplay));
113114

114115
cls->register_function(std::make_shared<ipc::function>("OBS_content_destroyDisplay",
115116
std::vector<ipc::type>{ipc::type::String}, OBS_content_destroyDisplay));
@@ -121,7 +122,9 @@ void OBS_content::Register(ipc::server& srv) {
121122
std::vector<ipc::type>{ipc::type::String}, OBS_content_getDisplayPreviewSize));
122123

123124
cls->register_function(std::make_shared<ipc::function>("OBS_content_createSourcePreviewDisplay",
124-
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String, ipc::type::String}, OBS_content_createSourcePreviewDisplay));
125+
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String, ipc::type::String,
126+
ipc::type::UInt32, ipc::type::UInt32, ipc::type::UInt32, ipc::type::UInt32},
127+
OBS_content_createSourcePreviewDisplay));
125128

126129
cls->register_function(std::make_shared<ipc::function>("OBS_content_resizeDisplay",
127130
std::vector<ipc::type>{ipc::type::String, ipc::type::UInt32, ipc::type::UInt32}, OBS_content_resizeDisplay));
@@ -185,7 +188,9 @@ void OBS_content::OBS_content_createDisplay(void* data, const int64_t id, const
185188
return;
186189
}
187190

188-
displays.insert_or_assign(args[1].value_str, new OBS::Display(windowHandle));
191+
displays.insert_or_assign(args[1].value_str, new OBS::Display(windowHandle,
192+
args[2].value_union.ui32, args[3].value_union.ui32,
193+
args[4].value_union.ui32, args[5].value_union.ui32));
189194
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
190195
AUTO_DEBUG;
191196
}
@@ -217,7 +222,9 @@ void OBS_content::OBS_content_createSourcePreviewDisplay(void* data, const int64
217222
std::cout << "Duplicate key provided to createDisplay!" << std::endl;
218223
return;
219224
}
220-
displays.insert_or_assign(args[2].value_str, new OBS::Display(windowHandle, args[1].value_str));
225+
displays.insert_or_assign(args[2].value_str, new OBS::Display(windowHandle, args[3].value_union.ui32,
226+
args[4].value_union.ui32, args[5].value_union.ui32,
227+
args[6].value_union.ui32, args[1].value_str));
221228
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
222229
AUTO_DEBUG;
223230
}

obs-studio-server/source/nodeobs_display.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ OBS::Display::Display() {
256256
m_drawGuideLines = true;
257257
}
258258

259-
OBS::Display::Display(uint64_t windowHandle) : Display() {
259+
OBS::Display::Display(uint64_t windowHandle,
260+
uint32_t width, uint32_t height, uint32_t positionX, uint32_t positionY) : Display() {
260261
#ifdef _WIN32
261262
CreateWindowMessageQuestion question;
262263
CreateWindowMessageAnswer answer;
@@ -291,9 +292,13 @@ OBS::Display::Display(uint64_t windowHandle) : Display() {
291292

292293
obs_display_add_draw_callback(m_display, DisplayCallback, this);
293294
obs_display_set_background_color(m_display, 0x0);
295+
296+
SetSize(width, height);
297+
SetPosition(positionX, positionY);
294298
}
295299

296-
OBS::Display::Display(uint64_t windowHandle, std::string sourceName) : Display(windowHandle) {
300+
OBS::Display::Display(uint64_t windowHandle, uint32_t width, uint32_t height, uint32_t positionX, uint32_t positionY,
301+
std::string sourceName) : Display(windowHandle, width, height, positionX, positionY) {
297302
std::cout << "creating display" << std::endl;
298303
m_source = obs_get_source_by_name(sourceName.c_str());
299304
obs_source_inc_showing(m_source);

obs-studio-server/source/nodeobs_display.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ namespace OBS {
3333
Display();
3434

3535
public:
36-
Display(uint64_t windowHandle); // Create a Main Preview one
37-
Display(uint64_t windowHandle, std::string sourceName); // Create a Source-Specific one
36+
Display(uint64_t windowHandle, uint32_t width, uint32_t height,
37+
uint32_t positionX, uint32_t positionY); // Create a Main Preview one
38+
Display(uint64_t windowHandle, uint32_t width, uint32_t height,
39+
uint32_t positionX, uint32_t positionY, std::string sourceName); // Create a Source-Specific one
3840
~Display();
3941
#pragma endregion Constructors & Finalizer
4042

0 commit comments

Comments
 (0)