From c91463266309349c78ca9933129994f5ea49cee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Fri, 19 Apr 2019 17:44:11 +0200 Subject: [PATCH] GetSceneItemProperties: add width & height values --- src/Utils.cpp | 21 +++++++++++++++++++-- src/WSRequestHandler_SceneItems.cpp | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index ecd6039f..d79bdaee 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -115,8 +115,8 @@ obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t* item) { obs_data_set_double(data, "y", pos.y); obs_data_set_int(data, "source_cx", (int)item_width); obs_data_set_int(data, "source_cy", (int)item_height); - obs_data_set_double(data, "cx", item_width* scale.x); - obs_data_set_double(data, "cy", item_height* scale.y); + obs_data_set_double(data, "cx", item_width * scale.x); + obs_data_set_double(data, "cy", item_height * scale.y); obs_data_set_bool(data, "render", obs_sceneitem_visible(item)); return data; @@ -592,8 +592,20 @@ bool Utils::SetFilenameFormatting(const char* filenameFormatting) { * @property {int} `bounds.alignment` Alignment of the bounding box. * @property {double} `bounds.x` Width of the bounding box. * @property {double} `bounds.y` Height of the bounding box. + * @property {int} `sourceWidth` Base width (without scaling) of the source + * @property {int} `sourceHeight` Base source (without scaling) of the source + * @property {double} `width` Scene item width (base source width multiplied by the horizontal scaling factor) + * @property {double} `height` Scene item height (base source height multiplied by the vertical scaling factor) */ obs_data_t* Utils::GetSceneItemPropertiesData(obs_sceneitem_t* sceneItem) { + if (!sceneItem) { + return nullptr; + } + + OBSSource source = obs_sceneitem_get_source(sceneItem); + uint32_t baseSourceWidth = obs_source_get_width(source); + uint32_t baseSourceHeight = obs_source_get_height(source); + vec2 pos, scale, bounds; obs_sceneitem_crop crop; @@ -639,5 +651,10 @@ obs_data_t* Utils::GetSceneItemPropertiesData(obs_sceneitem_t* sceneItem) { obs_data_set_bool(data, "visible", isVisible); obs_data_set_obj(data, "bounds", boundsData); + obs_data_set_int(data, "sourceWidth", baseSourceWidth); + obs_data_set_int(data, "sourceHeight", baseSourceHeight); + obs_data_set_double(data, "width", baseSourceWidth * scale.x); + obs_data_set_double(data, "height", baseSourceHeight * scale.y); + return data; } diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 6b19ae97..76ecd971 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -25,7 +25,11 @@ * @return {int} `bounds.alignment` Alignment of the bounding box. * @return {double} `bounds.x` Width of the bounding box. * @return {double} `bounds.y` Height of the bounding box. -* +* @return {int} `sourceWidth` Base width (without scaling) of the source +* @return {int} `sourceHeight` Base source (without scaling) of the source +* @return {double} `width` Scene item width (base source width multiplied by the horizontal scaling factor) +* @return {double} `height` Scene item height (base source height multiplied by the vertical scaling factor) +* * @api requests * @name GetSceneItemProperties * @category scene items