UI: Add scene editing
So, scene editing was interesting (and by interesting I mean excruciating). I almost implemented 'manipulator' visuals (ala 3dsmax for example), and used 3 modes for controlling position/rotation/size, but in a 2D editing, it felt clunky, so I defaulted back to simply click-and-drag for movement, and then took a similar though slightly different looking approach for handling scaling and reszing. I also added a number of menu item helpers related to positioning, scaling, rotating, flipping, and resetting the transform back to default. There is also a new 'transform' dialog (accessible via menu) which will allow you to manually edit every single transform variable of a scene item directly if desired. If a scene item does not have bounds active, pulling on the sides of a source will cause it to resize it via base scale rather than by the bounding box system (if the source resizes that scale will apply). If bounds are active, it will modify the bounding box only instead. How a source scales when a bounding box is active depends on the type of bounds being used. You can set it to scale to the inner bounds, the outer bounds, scale to bounds width only, scale to bounds height only, and a setting to stretch to bounds (which forces a source to always draw at the bounding box size rather than be affected by its internal size). You can also set it to be used as a 'maximum' size, so that the source doesn't necessarily get scaled unless it extends beyond the bounds. Like in OBS1, objects will snap to the edges unless the control key is pressed. However, this will now happen even if the object is rotated or oriented in any strange way. Snapping will also occur when stretching or changing the bounding box size.
This commit is contained in:
@@ -175,14 +175,19 @@ static void calculate_bounds_data(struct obs_scene_item *item,
|
||||
struct vec2 *origin, struct vec2 *scale,
|
||||
uint32_t *cx, uint32_t *cy)
|
||||
{
|
||||
float width = (float)(*cx) * fabsf(scale->x);
|
||||
float height = (float)(*cy) * fabsf(scale->y);
|
||||
float item_aspect = width / height;
|
||||
float bounds_aspect = item->bounds.x / item->bounds.y;
|
||||
float width_diff, height_diff;
|
||||
float width = (float)(*cx) * fabsf(scale->x);
|
||||
float height = (float)(*cy) * fabsf(scale->y);
|
||||
float item_aspect = width / height;
|
||||
float bounds_aspect = item->bounds.x / item->bounds.y;
|
||||
uint32_t bounds_type = item->bounds_type;
|
||||
float width_diff, height_diff;
|
||||
|
||||
if (item->bounds_type == OBS_BOUNDS_SCALE_INNER ||
|
||||
item->bounds_type == OBS_BOUNDS_SCALE_OUTER) {
|
||||
if (item->bounds_type == OBS_BOUNDS_MAX_ONLY)
|
||||
if (width > item->bounds.x || height > item->bounds.y)
|
||||
bounds_type = OBS_BOUNDS_SCALE_INNER;
|
||||
|
||||
if (bounds_type == OBS_BOUNDS_SCALE_INNER ||
|
||||
bounds_type == OBS_BOUNDS_SCALE_OUTER) {
|
||||
bool use_width = (bounds_aspect < item_aspect);
|
||||
float mul;
|
||||
|
||||
@@ -195,13 +200,13 @@ static void calculate_bounds_data(struct obs_scene_item *item,
|
||||
|
||||
vec2_mulf(scale, scale, mul);
|
||||
|
||||
} else if (item->bounds_type == OBS_BOUNDS_SCALE_TO_WIDTH) {
|
||||
} else if (bounds_type == OBS_BOUNDS_SCALE_TO_WIDTH) {
|
||||
vec2_mulf(scale, scale, item->bounds.x / width);
|
||||
|
||||
} else if (item->bounds_type == OBS_BOUNDS_SCALE_TO_HEIGHT) {
|
||||
} else if (bounds_type == OBS_BOUNDS_SCALE_TO_HEIGHT) {
|
||||
vec2_mulf(scale, scale, item->bounds.y / height);
|
||||
|
||||
} else if (item->bounds_type == OBS_BOUNDS_STRETCH) {
|
||||
} else if (bounds_type == OBS_BOUNDS_STRETCH) {
|
||||
scale->x = item->bounds.x / (float)(*cx);
|
||||
scale->y = item->bounds.y / (float)(*cy);
|
||||
}
|
||||
|
@@ -95,12 +95,12 @@ enum allow_direct_render {
|
||||
*/
|
||||
enum obs_bounds_type {
|
||||
OBS_BOUNDS_NONE, /**< no bounds */
|
||||
OBS_BOUNDS_ALIGN_ONLY, /**< no scaling to bounds, align only */
|
||||
OBS_BOUNDS_STRETCH, /**< stretch (ignores base scale) */
|
||||
OBS_BOUNDS_SCALE_INNER, /**< scales to inner rectangle */
|
||||
OBS_BOUNDS_SCALE_OUTER, /**< scales to outer rectangle */
|
||||
OBS_BOUNDS_SCALE_TO_WIDTH, /**< scales to the width */
|
||||
OBS_BOUNDS_SCALE_TO_HEIGHT, /**< scales to the height */
|
||||
OBS_BOUNDS_STRETCH /**< stretch (ignores base scale) */
|
||||
OBS_BOUNDS_MAX_ONLY, /**< no scaling, maximum size only */
|
||||
};
|
||||
|
||||
struct obs_sceneitem_info {
|
||||
|
Reference in New Issue
Block a user