more WIP on setter

This commit is contained in:
Teddy Stoddard 2017-10-14 13:10:40 -04:00
parent d418b4e624
commit b0170ef671
3 changed files with 40 additions and 9 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);