From b0170ef6719794d30709d0c1be47bf601b423a27 Mon Sep 17 00:00:00 2001 From: Teddy Stoddard Date: Sat, 14 Oct 2017 13:10:40 -0400 Subject: [PATCH] more WIP on setter --- Utils.cpp | 17 +++++++++++++++++ Utils.h | 2 ++ WSRequestHandler.cpp | 30 +++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Utils.cpp b/Utils.cpp index fcc45d23..91d04a76 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -142,6 +142,23 @@ obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, const char* n return search.result; } +bool Utils::IsValidAlignment(const bool alignment) { + switch (alignment) { + case OBS_ALIGN_CENTER: + case OBS_ALIGN_LEFT: + case OBS_ALIGN_RIGHT: + case OBS_ALIGN_TOP: + case OBS_ALIGN_BOTTOM: + case OBS_ALIGN_TOP & OBS_ALIGN_LEFT: + case OBS_ALIGN_TOP & OBS_ALIGN_RIGHT: + case OBS_ALIGN_BOTTOM & OBS_ALIGN_LEFT: + case OBS_ALIGN_BOTTOM & OBS_ALIGN_RIGHT: { + return true; + } + } + return false; +} + obs_source_t* Utils::GetTransitionFromName(const char* search_name) { obs_source_t* found_transition = NULL; diff --git a/Utils.h b/Utils.h index 6b75e9c4..ea53c0e1 100644 --- a/Utils.h +++ b/Utils.h @@ -39,6 +39,8 @@ class Utils { static obs_source_t* GetTransitionFromName(const char* search_name); static obs_source_t* GetSceneFromNameOrCurrent(const char* scene_name); + static bool IsValidAlignment(const bool alignment); + static obs_data_array_t* GetScenes(); static obs_data_t* GetSceneData(obs_source* source); diff --git a/WSRequestHandler.cpp b/WSRequestHandler.cpp index d31706e8..9280892a 100644 --- a/WSRequestHandler.cpp +++ b/WSRequestHandler.cpp @@ -1353,8 +1353,8 @@ void WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) { * @return {String} `name` The name of the source. * @return {int} `position.x` The x position of the source from the left. * @return {int} `position.y` The y position of the source from the top. + * @return {int} `position.alignment` The point on the source that the item is manipulated from. * @return {double} `rotation` The clockwise rotation of the item in degrees around the point of alignment. - * @return {int?string?} `alignment` The point on the source that the item is manipulated from. * @return {double} `scale.x` The x-scale factor of the source. * @return {double} `scale.y` The y-scale factor of the source. * @return {int} `crop.top` The number of pixels cropped off the top of the source before scaling. @@ -1364,7 +1364,7 @@ void WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) { * @return {bool} `visible` If the source is visible. * @return {bool/Object} `bounds` False if bounds are not turned on. Object if bounds are turned on. * @return {String} `bounds.type` Type of bounding box. - * @return {int?string?} `bounds.alignment` Alignment of the bounding box. + * @return {int} `bounds.alignment` Alignment of the bounding box. * @return {double} `bounds.width` Width of the bounding box. * @return {double} `bounds.height` Height of the bounding box. * @@ -1409,17 +1409,16 @@ void WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) { obs_sceneitem_get_pos(scene_item, &pos); obs_data_set_double(pos_data, "x", pos.x); obs_data_set_double(pos_data, "y", pos.y); - obs_data_set_obj(data, "position", pos_data); - - obs_data_set_double(data, "rotation", obs_sceneitem_get_rot(scene_item)); - - // investigate this and maybe convert so string in switch statement // #define OBS_ALIGN_CENTER (0) // #define OBS_ALIGN_LEFT (1<<0) // #define OBS_ALIGN_RIGHT (1<<1) // #define OBS_ALIGN_TOP (1<<2) // #define OBS_ALIGN_BOTTOM (1<<3) - obs_data_set_int(data, "alignment", obs_sceneitem_get_alignment(scene_item)); + obs_data_set_int(pos_data, "alignment", obs_sceneitem_get_alignment(scene_item)); + obs_data_set_obj(data, "position", pos_data); + + obs_data_set_double(data, "rotation", obs_sceneitem_get_rot(scene_item)); + obs_data_t* scale_data = obs_data_create(); vec2 scale; @@ -1472,7 +1471,6 @@ void WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) { } } - // same with alignment above, decide if it should convert to string // #define OBS_ALIGN_CENTER (0) // #define OBS_ALIGN_LEFT (1<<0) // #define OBS_ALIGN_RIGHT (1<<1) @@ -1502,6 +1500,8 @@ void WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) { * @param {String} `item` The name of the source. * @param {int} `position.x` * @param {int} `position.y` + * @param {int} `position.alignment` + * @param {double} `rotation` The new clockwise rotation of the item in degrees * @param {int} `crop.top` * @param {int} `crop.bottom` * @param {int} `crop.left` @@ -1549,9 +1549,21 @@ void WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req) { if (obs_data_has_user_value(req_position, "y")) { new_position.y = obs_data_get_int(req_position, "y"); } + if (obs_data_has_user_value(req_position, "alignment")) { + const uint32_t alignment = obs_data_get_int(req_position, "alignment"); + if (Utils::IsValidAlignment(alignment)) { + obs_sceneitem_set_alignment(alignment); + } + // Send an error in the else statement? + // Append an error message to the response? + } obs_sceneitem_set_pos(scene_item, &new_position); } + if (req->hasField("rotation")) { + obs_sceneitem_set_rot(scene_item, (float)obs_data_get_double(req->data, "rotation")); + } + if (req->hasField("crop")) { obs_sceneitem_crop old_crop; obs_sceneitem_get_crop(scene_item, &old_crop);