mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Requested changes to move the common code to a utils function.
This commit is contained in:
parent
8946e8997f
commit
1993596232
@ -553,3 +553,77 @@ bool Utils::SetFilenameFormatting(const char* filenameFormatting) {
|
||||
config_save(profile);
|
||||
return true;
|
||||
}
|
||||
|
||||
obs_data_t* Utils::GetSceneItemPropertiesData(obs_sceneitem_t* sceneItem) {
|
||||
OBSDataAutoRelease data = obs_data_create();
|
||||
|
||||
OBSDataAutoRelease posData = obs_data_create();
|
||||
vec2 pos;
|
||||
obs_sceneitem_get_pos(sceneItem, &pos);
|
||||
obs_data_set_double(posData, "x", pos.x);
|
||||
obs_data_set_double(posData, "y", pos.y);
|
||||
obs_data_set_int(posData, "alignment", obs_sceneitem_get_alignment(sceneItem));
|
||||
obs_data_set_obj(data, "position", posData);
|
||||
|
||||
obs_data_set_double(data, "rotation", obs_sceneitem_get_rot(sceneItem));
|
||||
|
||||
OBSDataAutoRelease scaleData = obs_data_create();
|
||||
vec2 scale;
|
||||
obs_sceneitem_get_scale(sceneItem, &scale);
|
||||
obs_data_set_double(scaleData, "x", scale.x);
|
||||
obs_data_set_double(scaleData, "y", scale.y);
|
||||
obs_data_set_obj(data, "scale", scaleData);
|
||||
|
||||
OBSDataAutoRelease cropData = obs_data_create();
|
||||
obs_sceneitem_crop crop;
|
||||
obs_sceneitem_get_crop(sceneItem, &crop);
|
||||
obs_data_set_int(cropData, "left", crop.left);
|
||||
obs_data_set_int(cropData, "top", crop.top);
|
||||
obs_data_set_int(cropData, "right", crop.right);
|
||||
obs_data_set_int(cropData, "bottom", crop.bottom);
|
||||
obs_data_set_obj(data, "crop", cropData);
|
||||
|
||||
obs_data_set_bool(data, "visible", obs_sceneitem_visible(sceneItem));
|
||||
|
||||
OBSDataAutoRelease boundsData = obs_data_create();
|
||||
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(sceneItem);
|
||||
if (boundsType == OBS_BOUNDS_NONE) {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_NONE");
|
||||
}
|
||||
else {
|
||||
switch (boundsType) {
|
||||
case OBS_BOUNDS_STRETCH: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_STRETCH");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_INNER: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_INNER");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_OUTER: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_OUTER");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_TO_WIDTH: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_WIDTH");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_TO_HEIGHT: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_HEIGHT");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_MAX_ONLY: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_MAX_ONLY");
|
||||
break;
|
||||
}
|
||||
}
|
||||
obs_data_set_int(boundsData, "alignment", obs_sceneitem_get_bounds_alignment(sceneItem));
|
||||
vec2 bounds;
|
||||
obs_sceneitem_get_bounds(sceneItem, &bounds);
|
||||
obs_data_set_double(boundsData, "x", bounds.x);
|
||||
obs_data_set_double(boundsData, "y", bounds.y);
|
||||
}
|
||||
obs_data_set_obj(data, "bounds", boundsData);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ class Utils {
|
||||
static obs_sceneitem_t* GetSceneItemFromItem(obs_source_t* source, obs_data_t* item);
|
||||
static obs_source_t* GetTransitionFromName(QString transitionName);
|
||||
static obs_source_t* GetSceneFromNameOrCurrent(QString sceneName);
|
||||
static obs_data_t* GetSceneItemPropertiesData(obs_sceneitem_t* item);
|
||||
|
||||
static bool IsValidAlignment(const uint32_t alignment);
|
||||
|
||||
|
@ -940,78 +940,10 @@ void WSEvents::OnSceneItemTransform(void* param, calldata_t* data) {
|
||||
const char* sceneItemName =
|
||||
obs_source_get_name(obs_sceneitem_get_source(sceneItem));
|
||||
|
||||
OBSDataAutoRelease fields = obs_data_create();
|
||||
OBSDataAutoRelease fields = Utils::GetSceneItemPropertiesData(sceneItem);
|
||||
obs_data_set_string(fields, "scene-name", sceneName);
|
||||
obs_data_set_string(fields, "item-name", sceneItemName);
|
||||
|
||||
OBSDataAutoRelease posData = obs_data_create();
|
||||
vec2 pos;
|
||||
obs_sceneitem_get_pos(sceneItem, &pos);
|
||||
obs_data_set_double(posData, "x", pos.x);
|
||||
obs_data_set_double(posData, "y", pos.y);
|
||||
obs_data_set_int(posData, "alignment", obs_sceneitem_get_alignment(sceneItem));
|
||||
obs_data_set_obj(fields, "position", posData);
|
||||
|
||||
obs_data_set_double(fields, "rotation", obs_sceneitem_get_rot(sceneItem));
|
||||
|
||||
OBSDataAutoRelease scaleData = obs_data_create();
|
||||
vec2 scale;
|
||||
obs_sceneitem_get_scale(sceneItem, &scale);
|
||||
obs_data_set_double(scaleData, "x", scale.x);
|
||||
obs_data_set_double(scaleData, "y", scale.y);
|
||||
obs_data_set_obj(fields, "scale", scaleData);
|
||||
|
||||
OBSDataAutoRelease cropData = obs_data_create();
|
||||
obs_sceneitem_crop crop;
|
||||
obs_sceneitem_get_crop(sceneItem, &crop);
|
||||
obs_data_set_int(cropData, "left", crop.left);
|
||||
obs_data_set_int(cropData, "top", crop.top);
|
||||
obs_data_set_int(cropData, "right", crop.right);
|
||||
obs_data_set_int(cropData, "bottom", crop.bottom);
|
||||
obs_data_set_obj(fields, "crop", cropData);
|
||||
|
||||
obs_data_set_bool(fields, "visible", obs_sceneitem_visible(sceneItem));
|
||||
|
||||
OBSDataAutoRelease boundsData = obs_data_create();
|
||||
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(sceneItem);
|
||||
if (boundsType == OBS_BOUNDS_NONE) {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_NONE");
|
||||
}
|
||||
else {
|
||||
switch (boundsType) {
|
||||
case OBS_BOUNDS_STRETCH: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_STRETCH");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_INNER: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_INNER");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_OUTER: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_OUTER");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_TO_WIDTH: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_WIDTH");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_TO_HEIGHT: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_HEIGHT");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_MAX_ONLY: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_MAX_ONLY");
|
||||
break;
|
||||
}
|
||||
}
|
||||
obs_data_set_int(boundsData, "alignment", obs_sceneitem_get_bounds_alignment(sceneItem));
|
||||
vec2 bounds;
|
||||
obs_sceneitem_get_bounds(sceneItem, &bounds);
|
||||
obs_data_set_double(boundsData, "x", bounds.x);
|
||||
obs_data_set_double(boundsData, "y", bounds.y);
|
||||
}
|
||||
obs_data_set_obj(fields, "bounds", boundsData);
|
||||
|
||||
instance->broadcastUpdate("SceneItemTransformChanged", fields);
|
||||
}
|
||||
|
||||
|
@ -53,77 +53,9 @@ HandlerResponse WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler*
|
||||
return req->SendErrorResponse("specified scene item doesn't exist");
|
||||
}
|
||||
|
||||
OBSDataAutoRelease data = obs_data_create();
|
||||
OBSDataAutoRelease data = Utils::GetSceneItemPropertiesData(sceneItem);
|
||||
obs_data_set_string(data, "name", itemName.toUtf8());
|
||||
|
||||
OBSDataAutoRelease posData = obs_data_create();
|
||||
vec2 pos;
|
||||
obs_sceneitem_get_pos(sceneItem, &pos);
|
||||
obs_data_set_double(posData, "x", pos.x);
|
||||
obs_data_set_double(posData, "y", pos.y);
|
||||
obs_data_set_int(posData, "alignment", obs_sceneitem_get_alignment(sceneItem));
|
||||
obs_data_set_obj(data, "position", posData);
|
||||
|
||||
obs_data_set_double(data, "rotation", obs_sceneitem_get_rot(sceneItem));
|
||||
|
||||
OBSDataAutoRelease scaleData = obs_data_create();
|
||||
vec2 scale;
|
||||
obs_sceneitem_get_scale(sceneItem, &scale);
|
||||
obs_data_set_double(scaleData, "x", scale.x);
|
||||
obs_data_set_double(scaleData, "y", scale.y);
|
||||
obs_data_set_obj(data, "scale", scaleData);
|
||||
|
||||
OBSDataAutoRelease cropData = obs_data_create();
|
||||
obs_sceneitem_crop crop;
|
||||
obs_sceneitem_get_crop(sceneItem, &crop);
|
||||
obs_data_set_int(cropData, "left", crop.left);
|
||||
obs_data_set_int(cropData, "top", crop.top);
|
||||
obs_data_set_int(cropData, "right", crop.right);
|
||||
obs_data_set_int(cropData, "bottom", crop.bottom);
|
||||
obs_data_set_obj(data, "crop", cropData);
|
||||
|
||||
obs_data_set_bool(data, "visible", obs_sceneitem_visible(sceneItem));
|
||||
|
||||
OBSDataAutoRelease boundsData = obs_data_create();
|
||||
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(sceneItem);
|
||||
if (boundsType == OBS_BOUNDS_NONE) {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_NONE");
|
||||
}
|
||||
else {
|
||||
switch (boundsType) {
|
||||
case OBS_BOUNDS_STRETCH: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_STRETCH");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_INNER: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_INNER");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_OUTER: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_OUTER");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_TO_WIDTH: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_WIDTH");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_SCALE_TO_HEIGHT: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_HEIGHT");
|
||||
break;
|
||||
}
|
||||
case OBS_BOUNDS_MAX_ONLY: {
|
||||
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_MAX_ONLY");
|
||||
break;
|
||||
}
|
||||
}
|
||||
obs_data_set_int(boundsData, "alignment", obs_sceneitem_get_bounds_alignment(sceneItem));
|
||||
vec2 bounds;
|
||||
obs_sceneitem_get_bounds(sceneItem, &bounds);
|
||||
obs_data_set_double(boundsData, "x", bounds.x);
|
||||
obs_data_set_double(boundsData, "y", bounds.y);
|
||||
}
|
||||
obs_data_set_obj(data, "bounds", boundsData);
|
||||
|
||||
return req->SendOKResponse(data);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user