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.
2014-06-15 09:54:48 +02:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
#include <cmath>
|
2019-01-15 02:58:20 +01:00
|
|
|
#include <string>
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
#include <graphics/vec4.h>
|
|
|
|
#include <graphics/matrix4.h>
|
|
|
|
#include "window-basic-preview.hpp"
|
|
|
|
#include "window-basic-main.hpp"
|
|
|
|
#include "obs-app.hpp"
|
2019-01-15 02:58:20 +01:00
|
|
|
#include "platform.hpp"
|
2023-03-08 19:20:10 +01:00
|
|
|
#include "display-helpers.hpp"
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
#define HANDLE_RADIUS 4.0f
|
|
|
|
#define HANDLE_SEL_RADIUS (HANDLE_RADIUS * 1.5f)
|
2023-07-07 04:47:17 +02:00
|
|
|
#define HELPER_ROT_BREAKPOINT 45.0f
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
/* TODO: make C++ math classes and clean up code here later */
|
|
|
|
|
|
|
|
OBSBasicPreview::OBSBasicPreview(QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: OBSQTDisplay(parent, flags)
|
|
|
|
{
|
2016-11-05 17:48:46 +01:00
|
|
|
ResetScrollingOffset();
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2019-01-15 02:58:20 +01:00
|
|
|
OBSBasicPreview::~OBSBasicPreview()
|
|
|
|
{
|
2019-07-24 03:08:08 +02:00
|
|
|
obs_enter_graphics();
|
|
|
|
|
|
|
|
if (overflow)
|
2019-01-15 02:58:20 +01:00
|
|
|
gs_texture_destroy(overflow);
|
2019-07-24 03:08:08 +02:00
|
|
|
if (rectFill)
|
|
|
|
gs_vertexbuffer_destroy(rectFill);
|
2020-02-18 09:14:42 +01:00
|
|
|
if (circleFill)
|
|
|
|
gs_vertexbuffer_destroy(circleFill);
|
2019-07-24 03:08:08 +02:00
|
|
|
|
|
|
|
obs_leave_graphics();
|
2019-01-15 02:58:20 +01:00
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec2 OBSBasicPreview::GetMouseEventPos(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2022-07-29 20:31:13 +02:00
|
|
|
float pixelRatio = main->GetDevicePixelRatio();
|
2014-07-16 02:01:59 +02:00
|
|
|
float scale = pixelRatio / main->previewScale;
|
2022-07-19 16:12:17 +02:00
|
|
|
QPoint qtPos = event->pos();
|
2014-06-17 02:55:48 +02:00
|
|
|
vec2 pos;
|
2022-07-19 16:12:17 +02:00
|
|
|
vec2_set(&pos, (qtPos.x() - main->previewX / pixelRatio) * scale,
|
|
|
|
(qtPos.y() - main->previewY / pixelRatio) * scale);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2020-12-24 04:57:55 +01:00
|
|
|
static void RotatePos(vec2 *pos, float rot)
|
|
|
|
{
|
|
|
|
float cosR = cos(rot);
|
|
|
|
float sinR = sin(rot);
|
|
|
|
|
|
|
|
vec2 newPos;
|
|
|
|
|
|
|
|
newPos.x = cosR * pos->x - sinR * pos->y;
|
|
|
|
newPos.y = sinR * pos->x + cosR * pos->y;
|
|
|
|
|
|
|
|
vec2_copy(pos, &newPos);
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
struct SceneFindData {
|
|
|
|
const vec2 &pos;
|
|
|
|
OBSSceneItem item;
|
|
|
|
bool selectBelow;
|
|
|
|
|
2018-06-02 18:45:01 +02:00
|
|
|
obs_sceneitem_t *group = nullptr;
|
|
|
|
|
2014-06-25 10:50:44 +02:00
|
|
|
SceneFindData(const SceneFindData &) = delete;
|
2014-06-25 11:12:30 +02:00
|
|
|
SceneFindData(SceneFindData &&) = delete;
|
2014-06-25 10:50:44 +02:00
|
|
|
SceneFindData &operator=(const SceneFindData &) = delete;
|
|
|
|
SceneFindData &operator=(SceneFindData &&) = delete;
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
inline SceneFindData(const vec2 &pos_, bool selectBelow_)
|
|
|
|
: pos(pos_),
|
|
|
|
selectBelow(selectBelow_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
struct SceneFindBoxData {
|
|
|
|
const vec2 &startPos;
|
|
|
|
const vec2 &pos;
|
|
|
|
std::vector<obs_sceneitem_t *> sceneItems;
|
|
|
|
|
|
|
|
SceneFindBoxData(const SceneFindData &) = delete;
|
|
|
|
SceneFindBoxData(SceneFindData &&) = delete;
|
|
|
|
SceneFindBoxData &operator=(const SceneFindData &) = delete;
|
|
|
|
SceneFindBoxData &operator=(SceneFindData &&) = delete;
|
|
|
|
|
|
|
|
inline SceneFindBoxData(const vec2 &startPos_, const vec2 &pos_)
|
|
|
|
: startPos(startPos_),
|
|
|
|
pos(pos_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
static bool SceneItemHasVideo(obs_sceneitem_t *item)
|
2014-07-04 19:58:03 +02:00
|
|
|
{
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_source_t *source = obs_sceneitem_get_source(item);
|
2014-07-04 19:58:03 +02:00
|
|
|
uint32_t flags = obs_source_get_output_flags(source);
|
|
|
|
return (flags & OBS_SOURCE_VIDEO) != 0;
|
|
|
|
}
|
|
|
|
|
2014-10-14 01:52:26 +02:00
|
|
|
static bool CloseFloat(float a, float b, float epsilon = 0.01)
|
|
|
|
{
|
2015-04-07 22:15:33 +02:00
|
|
|
using std::abs;
|
2014-10-14 01:52:26 +02:00
|
|
|
return abs(a - b) <= epsilon;
|
|
|
|
}
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool FindItemAtPos(obs_scene_t * /* scene */, obs_sceneitem_t *item,
|
2014-09-26 02:44:05 +02:00
|
|
|
void *param)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
|
|
|
SceneFindData *data = reinterpret_cast<SceneFindData *>(param);
|
|
|
|
matrix4 transform;
|
2014-10-14 01:52:26 +02:00
|
|
|
matrix4 invTransform;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec3 transformedPos;
|
2014-06-17 02:55:48 +02:00
|
|
|
vec3 pos3;
|
2014-10-14 01:52:26 +02:00
|
|
|
vec3 pos3_;
|
2014-06-17 02:55:48 +02:00
|
|
|
|
2014-07-04 19:58:03 +02:00
|
|
|
if (!SceneItemHasVideo(item))
|
|
|
|
return true;
|
2017-06-18 02:10:42 +02:00
|
|
|
if (obs_sceneitem_locked(item))
|
|
|
|
return true;
|
2014-07-04 19:58:03 +02:00
|
|
|
|
2014-06-17 02:55:48 +02:00
|
|
|
vec3_set(&pos3, data->pos.x, data->pos.y, 0.0f);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
obs_sceneitem_get_box_transform(item, &transform);
|
|
|
|
|
2014-10-14 01:52:26 +02:00
|
|
|
matrix4_inv(&invTransform, &transform);
|
|
|
|
vec3_transform(&transformedPos, &pos3, &invTransform);
|
|
|
|
vec3_transform(&pos3_, &transformedPos, &transform);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2014-10-14 01:52:26 +02:00
|
|
|
if (CloseFloat(pos3.x, pos3_.x) && CloseFloat(pos3.y, pos3_.y) &&
|
|
|
|
transformedPos.x >= 0.0f && transformedPos.x <= 1.0f &&
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
transformedPos.y >= 0.0f && transformedPos.y <= 1.0f) {
|
|
|
|
if (data->selectBelow && obs_sceneitem_selected(item)) {
|
|
|
|
if (data->item)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
data->selectBelow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->item = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static vec3 GetTransformedPos(float x, float y, const matrix4 &mat)
|
|
|
|
{
|
|
|
|
vec3 result;
|
|
|
|
vec3_set(&result, x, y, 0.0f);
|
|
|
|
vec3_transform(&result, &result, &mat);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline vec2 GetOBSScreenSize()
|
|
|
|
{
|
|
|
|
obs_video_info ovi;
|
2014-06-17 02:55:48 +02:00
|
|
|
vec2 size;
|
|
|
|
vec2_zero(&size);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
if (obs_get_video_info(&ovi)) {
|
|
|
|
size.x = float(ovi.base_width);
|
|
|
|
size.y = float(ovi.base_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2016-04-07 03:03:29 +02:00
|
|
|
vec3 OBSBasicPreview::GetSnapOffset(const vec3 &tl, const vec3 &br)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
vec2 screenSize = GetOBSScreenSize();
|
|
|
|
vec3 clampOffset;
|
|
|
|
|
|
|
|
vec3_zero(&clampOffset);
|
|
|
|
|
2016-04-07 03:03:29 +02:00
|
|
|
const bool snap = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"SnappingEnabled");
|
|
|
|
if (snap == false)
|
|
|
|
return clampOffset;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2016-04-07 03:03:29 +02:00
|
|
|
const bool screenSnap = config_get_bool(
|
|
|
|
GetGlobalConfig(), "BasicWindow", "ScreenSnapping");
|
2016-04-07 03:10:39 +02:00
|
|
|
const bool centerSnap = config_get_bool(
|
|
|
|
GetGlobalConfig(), "BasicWindow", "CenterSnapping");
|
2016-04-07 03:03:29 +02:00
|
|
|
|
|
|
|
const float clampDist = config_get_double(GetGlobalConfig(),
|
|
|
|
"BasicWindow",
|
|
|
|
"SnapDistance") /
|
|
|
|
main->previewScale;
|
2016-04-07 03:10:39 +02:00
|
|
|
const float centerX = br.x - (br.x - tl.x) / 2.0f;
|
|
|
|
const float centerY = br.y - (br.y - tl.y) / 2.0f;
|
2016-04-07 03:03:29 +02:00
|
|
|
|
|
|
|
// Left screen edge.
|
|
|
|
if (screenSnap && fabsf(tl.x) < clampDist)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
clampOffset.x = -tl.x;
|
2016-04-07 03:03:29 +02:00
|
|
|
// Right screen edge.
|
|
|
|
if (screenSnap && fabsf(clampOffset.x) < EPSILON &&
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
fabsf(screenSize.x - br.x) < clampDist)
|
|
|
|
clampOffset.x = screenSize.x - br.x;
|
2016-04-07 03:10:39 +02:00
|
|
|
// Horizontal center.
|
|
|
|
if (centerSnap && fabsf(screenSize.x - (br.x - tl.x)) > clampDist &&
|
|
|
|
fabsf(screenSize.x / 2.0f - centerX) < clampDist)
|
|
|
|
clampOffset.x = screenSize.x / 2.0f - centerX;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2016-04-07 03:03:29 +02:00
|
|
|
// Top screen edge.
|
|
|
|
if (screenSnap && fabsf(tl.y) < clampDist)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
clampOffset.y = -tl.y;
|
2016-04-07 03:03:29 +02:00
|
|
|
// Bottom screen edge.
|
|
|
|
if (screenSnap && fabsf(clampOffset.y) < EPSILON &&
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
fabsf(screenSize.y - br.y) < clampDist)
|
|
|
|
clampOffset.y = screenSize.y - br.y;
|
2016-04-07 03:10:39 +02:00
|
|
|
// Vertical center.
|
|
|
|
if (centerSnap && fabsf(screenSize.y - (br.y - tl.y)) > clampDist &&
|
|
|
|
fabsf(screenSize.y / 2.0f - centerY) < clampDist)
|
|
|
|
clampOffset.y = screenSize.y / 2.0f - centerY;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
return clampOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBSSceneItem OBSBasicPreview::GetItemAtPos(const vec2 &pos, bool selectBelow)
|
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
if (!scene)
|
|
|
|
return OBSSceneItem();
|
|
|
|
|
|
|
|
SceneFindData data(pos, selectBelow);
|
|
|
|
obs_scene_enum_items(scene, FindItemAtPos, &data);
|
|
|
|
return data.item;
|
|
|
|
}
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool CheckItemSelected(obs_scene_t * /* scene */, obs_sceneitem_t *item,
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
SceneFindData *data = reinterpret_cast<SceneFindData *>(param);
|
|
|
|
matrix4 transform;
|
|
|
|
vec3 transformedPos;
|
2014-06-17 02:55:48 +02:00
|
|
|
vec3 pos3;
|
|
|
|
|
2014-07-04 19:58:03 +02:00
|
|
|
if (!SceneItemHasVideo(item))
|
|
|
|
return true;
|
2018-06-02 18:45:01 +02:00
|
|
|
if (obs_sceneitem_is_group(item)) {
|
|
|
|
data->group = item;
|
|
|
|
obs_sceneitem_group_enum_items(item, CheckItemSelected, param);
|
|
|
|
data->group = nullptr;
|
|
|
|
|
|
|
|
if (data->item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 19:58:03 +02:00
|
|
|
|
2014-06-17 02:55:48 +02:00
|
|
|
vec3_set(&pos3, data->pos.x, data->pos.y, 0.0f);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
obs_sceneitem_get_box_transform(item, &transform);
|
|
|
|
|
2018-06-02 18:45:01 +02:00
|
|
|
if (data->group) {
|
|
|
|
matrix4 parent_transform;
|
|
|
|
obs_sceneitem_get_draw_transform(data->group,
|
|
|
|
&parent_transform);
|
|
|
|
matrix4_mul(&transform, &transform, &parent_transform);
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
matrix4_inv(&transform, &transform);
|
|
|
|
vec3_transform(&transformedPos, &pos3, &transform);
|
|
|
|
|
|
|
|
if (transformedPos.x >= 0.0f && transformedPos.x <= 1.0f &&
|
|
|
|
transformedPos.y >= 0.0f && transformedPos.y <= 1.0f) {
|
|
|
|
if (obs_sceneitem_selected(item)) {
|
|
|
|
data->item = item;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OBSBasicPreview::SelectedAtPos(const vec2 &pos)
|
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
if (!scene)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SceneFindData data(pos, false);
|
|
|
|
obs_scene_enum_items(scene, CheckItemSelected, &data);
|
|
|
|
return !!data.item;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct HandleFindData {
|
2018-08-16 13:44:40 +02:00
|
|
|
const vec2 &pos;
|
|
|
|
const float radius;
|
|
|
|
matrix4 parent_xform;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
OBSSceneItem item;
|
|
|
|
ItemHandle handle = ItemHandle::None;
|
2020-02-18 09:14:42 +01:00
|
|
|
float angle = 0.0f;
|
|
|
|
vec2 rotatePoint;
|
|
|
|
vec2 offsetPoint;
|
|
|
|
|
|
|
|
float angleOffset = 0.0f;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2014-06-25 10:50:44 +02:00
|
|
|
HandleFindData(const HandleFindData &) = delete;
|
2014-06-25 11:12:30 +02:00
|
|
|
HandleFindData(HandleFindData &&) = delete;
|
2014-06-25 10:50:44 +02:00
|
|
|
HandleFindData &operator=(const HandleFindData &) = delete;
|
|
|
|
HandleFindData &operator=(HandleFindData &&) = delete;
|
|
|
|
|
2018-08-16 13:44:40 +02:00
|
|
|
inline HandleFindData(const vec2 &pos_, float scale)
|
|
|
|
: pos(pos_),
|
|
|
|
radius(HANDLE_SEL_RADIUS / scale)
|
|
|
|
{
|
|
|
|
matrix4_identity(&parent_xform);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline HandleFindData(const HandleFindData &hfd,
|
|
|
|
obs_sceneitem_t *parent)
|
|
|
|
: pos(hfd.pos),
|
|
|
|
radius(hfd.radius),
|
|
|
|
item(hfd.item),
|
2020-02-18 09:14:42 +01:00
|
|
|
handle(hfd.handle),
|
|
|
|
angle(hfd.angle),
|
|
|
|
rotatePoint(hfd.rotatePoint),
|
|
|
|
offsetPoint(hfd.offsetPoint)
|
2018-08-16 13:44:40 +02:00
|
|
|
{
|
|
|
|
obs_sceneitem_get_draw_transform(parent, &parent_xform);
|
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
};
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool FindHandleAtPos(obs_scene_t * /* scene */, obs_sceneitem_t *item,
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void *param)
|
|
|
|
{
|
2018-08-16 13:44:40 +02:00
|
|
|
HandleFindData &data = *reinterpret_cast<HandleFindData *>(param);
|
2018-06-02 18:45:01 +02:00
|
|
|
|
|
|
|
if (!obs_sceneitem_selected(item)) {
|
|
|
|
if (obs_sceneitem_is_group(item)) {
|
2018-08-16 13:44:40 +02:00
|
|
|
HandleFindData newData(data, item);
|
2020-02-18 09:14:42 +01:00
|
|
|
newData.angleOffset = obs_sceneitem_get_rot(item);
|
|
|
|
|
2018-06-02 18:45:01 +02:00
|
|
|
obs_sceneitem_group_enum_items(item, FindHandleAtPos,
|
2018-08-16 13:44:40 +02:00
|
|
|
&newData);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
2018-08-16 13:44:40 +02:00
|
|
|
data.item = newData.item;
|
|
|
|
data.handle = newData.handle;
|
2020-02-18 09:14:42 +01:00
|
|
|
data.angle = newData.angle;
|
|
|
|
data.rotatePoint = newData.rotatePoint;
|
|
|
|
data.offsetPoint = newData.offsetPoint;
|
2018-06-02 18:45:01 +02:00
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
return true;
|
2018-06-02 18:45:01 +02:00
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
matrix4 transform;
|
2014-06-17 02:55:48 +02:00
|
|
|
vec3 pos3;
|
2018-08-16 13:44:40 +02:00
|
|
|
float closestHandle = data.radius;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2018-08-16 13:44:40 +02:00
|
|
|
vec3_set(&pos3, data.pos.x, data.pos.y, 0.0f);
|
2014-06-17 02:55:48 +02:00
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
obs_sceneitem_get_box_transform(item, &transform);
|
|
|
|
|
|
|
|
auto TestHandle = [&](float x, float y, ItemHandle handle) {
|
2018-08-16 13:44:40 +02:00
|
|
|
vec3 handlePos = GetTransformedPos(x, y, transform);
|
|
|
|
vec3_transform(&handlePos, &handlePos, &data.parent_xform);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
float dist = vec3_dist(&handlePos, &pos3);
|
2018-08-16 13:44:40 +02:00
|
|
|
if (dist < data.radius) {
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
if (dist < closestHandle) {
|
|
|
|
closestHandle = dist;
|
2018-08-16 13:44:40 +02:00
|
|
|
data.handle = handle;
|
|
|
|
data.item = item;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TestHandle(0.0f, 0.0f, ItemHandle::TopLeft);
|
|
|
|
TestHandle(0.5f, 0.0f, ItemHandle::TopCenter);
|
|
|
|
TestHandle(1.0f, 0.0f, ItemHandle::TopRight);
|
|
|
|
TestHandle(0.0f, 0.5f, ItemHandle::CenterLeft);
|
|
|
|
TestHandle(1.0f, 0.5f, ItemHandle::CenterRight);
|
|
|
|
TestHandle(0.0f, 1.0f, ItemHandle::BottomLeft);
|
|
|
|
TestHandle(0.5f, 1.0f, ItemHandle::BottomCenter);
|
|
|
|
TestHandle(1.0f, 1.0f, ItemHandle::BottomRight);
|
|
|
|
|
2023-07-07 03:22:09 +02:00
|
|
|
vec2 scale;
|
|
|
|
obs_sceneitem_get_scale(item, &scale);
|
2023-07-07 04:25:23 +02:00
|
|
|
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(item);
|
2020-02-18 09:14:42 +01:00
|
|
|
vec2 rotHandleOffset;
|
2020-12-24 04:57:55 +01:00
|
|
|
vec2_set(&rotHandleOffset, 0.0f,
|
|
|
|
HANDLE_RADIUS * data.radius * 1.5 - data.radius);
|
2023-07-07 04:25:23 +02:00
|
|
|
bool invertx = scale.x < 0.0f && boundsType == OBS_BOUNDS_NONE;
|
|
|
|
float angle = atan2(invertx ? transform.x.y * -1.0f : transform.x.y,
|
|
|
|
invertx ? transform.x.x * -1.0f : transform.x.x);
|
2023-07-07 03:22:09 +02:00
|
|
|
RotatePos(&rotHandleOffset, angle);
|
2020-02-18 09:14:42 +01:00
|
|
|
RotatePos(&rotHandleOffset, RAD(data.angleOffset));
|
|
|
|
|
2023-07-07 04:25:23 +02:00
|
|
|
bool inverty = scale.y < 0.0f && boundsType == OBS_BOUNDS_NONE;
|
2023-03-28 15:34:30 +02:00
|
|
|
vec3 handlePos =
|
2023-07-07 04:25:23 +02:00
|
|
|
GetTransformedPos(0.5f, inverty ? 1.0f : 0.0f, transform);
|
2020-02-18 09:14:42 +01:00
|
|
|
vec3_transform(&handlePos, &handlePos, &data.parent_xform);
|
|
|
|
handlePos.x -= rotHandleOffset.x;
|
2023-07-07 03:22:09 +02:00
|
|
|
handlePos.y -= rotHandleOffset.y;
|
2020-02-18 09:14:42 +01:00
|
|
|
|
|
|
|
float dist = vec3_dist(&handlePos, &pos3);
|
|
|
|
if (dist < data.radius) {
|
|
|
|
if (dist < closestHandle) {
|
|
|
|
closestHandle = dist;
|
|
|
|
data.item = item;
|
|
|
|
data.angle = obs_sceneitem_get_rot(item);
|
|
|
|
data.handle = ItemHandle::Rot;
|
|
|
|
|
|
|
|
vec2_set(&data.rotatePoint,
|
|
|
|
transform.t.x + transform.x.x / 2 +
|
|
|
|
transform.y.x / 2,
|
|
|
|
transform.t.y + transform.x.y / 2 +
|
|
|
|
transform.y.y / 2);
|
|
|
|
|
|
|
|
obs_sceneitem_get_pos(item, &data.offsetPoint);
|
|
|
|
data.offsetPoint.x -= data.rotatePoint.x;
|
|
|
|
data.offsetPoint.y -= data.rotatePoint.y;
|
|
|
|
|
|
|
|
RotatePos(&data.offsetPoint,
|
|
|
|
-RAD(obs_sceneitem_get_rot(item)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
static vec2 GetItemSize(obs_sceneitem_t *item)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
|
|
|
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(item);
|
|
|
|
vec2 size;
|
|
|
|
|
|
|
|
if (boundsType != OBS_BOUNDS_NONE) {
|
|
|
|
obs_sceneitem_get_bounds(item, &size);
|
|
|
|
} else {
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_source_t *source = obs_sceneitem_get_source(item);
|
2016-03-31 03:46:02 +02:00
|
|
|
obs_sceneitem_crop crop;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec2 scale;
|
|
|
|
|
2014-08-03 23:39:19 +02:00
|
|
|
obs_sceneitem_get_scale(item, &scale);
|
2016-03-31 03:46:02 +02:00
|
|
|
obs_sceneitem_get_crop(item, &crop);
|
|
|
|
size.x = float(obs_source_get_width(source) - crop.left -
|
|
|
|
crop.right) *
|
|
|
|
scale.x;
|
|
|
|
size.y = float(obs_source_get_height(source) - crop.top -
|
|
|
|
crop.bottom) *
|
|
|
|
scale.y;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2021-03-09 11:15:17 +01:00
|
|
|
void OBSBasicPreview::GetStretchHandleData(const vec2 &pos, bool ignoreGroup)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
if (!scene)
|
|
|
|
return;
|
|
|
|
|
2022-07-29 20:31:13 +02:00
|
|
|
float scale = main->previewScale / main->GetDevicePixelRatio();
|
2018-08-16 13:44:40 +02:00
|
|
|
vec2 scaled_pos = pos;
|
|
|
|
vec2_divf(&scaled_pos, &scaled_pos, scale);
|
|
|
|
HandleFindData data(scaled_pos, scale);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
obs_scene_enum_items(scene, FindHandleAtPos, &data);
|
|
|
|
|
|
|
|
stretchItem = std::move(data.item);
|
|
|
|
stretchHandle = data.handle;
|
|
|
|
|
2020-02-18 09:14:42 +01:00
|
|
|
rotateAngle = data.angle;
|
|
|
|
rotatePoint = data.rotatePoint;
|
|
|
|
offsetPoint = data.offsetPoint;
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
if (stretchHandle != ItemHandle::None) {
|
|
|
|
matrix4 boxTransform;
|
|
|
|
vec3 itemUL;
|
|
|
|
float itemRot;
|
|
|
|
|
|
|
|
stretchItemSize = GetItemSize(stretchItem);
|
|
|
|
|
|
|
|
obs_sceneitem_get_box_transform(stretchItem, &boxTransform);
|
2014-08-03 23:39:19 +02:00
|
|
|
itemRot = obs_sceneitem_get_rot(stretchItem);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec3_from_vec4(&itemUL, &boxTransform.t);
|
|
|
|
|
|
|
|
/* build the item space conversion matrices */
|
|
|
|
matrix4_identity(&itemToScreen);
|
|
|
|
matrix4_rotate_aa4f(&itemToScreen, &itemToScreen, 0.0f, 0.0f,
|
|
|
|
1.0f, RAD(itemRot));
|
|
|
|
matrix4_translate3f(&itemToScreen, &itemToScreen, itemUL.x,
|
|
|
|
itemUL.y, 0.0f);
|
|
|
|
|
|
|
|
matrix4_identity(&screenToItem);
|
|
|
|
matrix4_translate3f(&screenToItem, &screenToItem, -itemUL.x,
|
|
|
|
-itemUL.y, 0.0f);
|
|
|
|
matrix4_rotate_aa4f(&screenToItem, &screenToItem, 0.0f, 0.0f,
|
|
|
|
1.0f, RAD(-itemRot));
|
2016-03-31 03:46:02 +02:00
|
|
|
|
|
|
|
obs_sceneitem_get_crop(stretchItem, &startCrop);
|
|
|
|
obs_sceneitem_get_pos(stretchItem, &startItemPos);
|
|
|
|
|
|
|
|
obs_source_t *source = obs_sceneitem_get_source(stretchItem);
|
|
|
|
cropSize.x = float(obs_source_get_width(source) -
|
|
|
|
startCrop.left - startCrop.right);
|
|
|
|
cropSize.y = float(obs_source_get_height(source) -
|
|
|
|
startCrop.top - startCrop.bottom);
|
2018-06-02 18:45:01 +02:00
|
|
|
|
2018-07-16 03:18:25 +02:00
|
|
|
stretchGroup = obs_sceneitem_get_group(scene, stretchItem);
|
2021-03-09 11:15:17 +01:00
|
|
|
if (stretchGroup && !ignoreGroup) {
|
2018-06-02 18:45:01 +02:00
|
|
|
obs_sceneitem_get_draw_transform(stretchGroup,
|
|
|
|
&invGroupTransform);
|
|
|
|
matrix4_inv(&invGroupTransform, &invGroupTransform);
|
|
|
|
obs_sceneitem_defer_group_resize_begin(stretchGroup);
|
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:48:46 +01:00
|
|
|
void OBSBasicPreview::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
2017-05-13 19:13:55 +02:00
|
|
|
if (!IsFixedScaling() || event->isAutoRepeat()) {
|
2016-11-05 17:48:46 +01:00
|
|
|
OBSQTDisplay::keyPressEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event->key()) {
|
|
|
|
case Qt::Key_Space:
|
|
|
|
setCursor(Qt::OpenHandCursor);
|
|
|
|
scrollMode = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBSQTDisplay::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (event->isAutoRepeat()) {
|
|
|
|
OBSQTDisplay::keyReleaseEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event->key()) {
|
|
|
|
case Qt::Key_Space:
|
|
|
|
scrollMode = false;
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBSQTDisplay::keyReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-05-13 19:13:55 +02:00
|
|
|
void OBSBasicPreview::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
2020-06-08 00:31:13 +02:00
|
|
|
if (scrollMode && IsFixedScaling()) {
|
|
|
|
const int delta = event->angleDelta().y();
|
|
|
|
if (delta != 0) {
|
|
|
|
if (delta > 0)
|
|
|
|
SetScalingLevel(scalingLevel + 1);
|
|
|
|
else
|
|
|
|
SetScalingLevel(scalingLevel - 1);
|
|
|
|
emit DisplayResized();
|
|
|
|
}
|
2017-05-13 19:13:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OBSQTDisplay::wheelEvent(event);
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void OBSBasicPreview::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
2022-07-19 16:12:17 +02:00
|
|
|
QPointF pos = event->position();
|
|
|
|
|
2017-05-13 19:13:55 +02:00
|
|
|
if (scrollMode && IsFixedScaling() &&
|
2016-11-10 15:32:44 +01:00
|
|
|
event->button() == Qt::LeftButton) {
|
|
|
|
setCursor(Qt::ClosedHandCursor);
|
2022-07-19 16:12:17 +02:00
|
|
|
scrollingFrom.x = pos.x();
|
2022-07-31 06:19:27 +02:00
|
|
|
scrollingFrom.y = pos.y();
|
2016-11-10 15:32:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->button() == Qt::RightButton) {
|
|
|
|
scrollMode = false;
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
}
|
|
|
|
|
2016-07-26 10:32:43 +02:00
|
|
|
if (locked) {
|
|
|
|
OBSQTDisplay::mousePressEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2022-07-29 20:31:13 +02:00
|
|
|
float pixelRatio = main->GetDevicePixelRatio();
|
2022-07-19 16:12:17 +02:00
|
|
|
float x = pos.x() - main->previewX / pixelRatio;
|
|
|
|
float y = pos.y() - main->previewY / pixelRatio;
|
2016-03-31 03:46:02 +02:00
|
|
|
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
|
|
|
bool altDown = (modifiers & Qt::AltModifier);
|
2019-07-24 03:08:08 +02:00
|
|
|
bool shiftDown = (modifiers & Qt::ShiftModifier);
|
|
|
|
bool ctrlDown = (modifiers & Qt::ControlModifier);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2015-04-03 03:05:55 +02:00
|
|
|
OBSQTDisplay::mousePressEvent(event);
|
|
|
|
|
|
|
|
if (event->button() != Qt::LeftButton &&
|
|
|
|
event->button() != Qt::RightButton)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
return;
|
|
|
|
|
2015-04-03 03:05:55 +02:00
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
mouseDown = true;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(selectMutex);
|
|
|
|
selectedItems.clear();
|
|
|
|
}
|
|
|
|
|
2016-03-31 03:46:02 +02:00
|
|
|
if (altDown)
|
|
|
|
cropping = true;
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
if (altDown || shiftDown || ctrlDown) {
|
|
|
|
vec2 s;
|
|
|
|
SceneFindBoxData data(s, s);
|
|
|
|
|
|
|
|
obs_scene_enum_items(main->GetCurrentScene(), FindSelected,
|
|
|
|
&data);
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(selectMutex);
|
|
|
|
selectedItems = data.sceneItems;
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec2_set(&startPos, x, y);
|
2021-03-09 11:15:17 +01:00
|
|
|
GetStretchHandleData(startPos, false);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2014-07-16 02:01:59 +02:00
|
|
|
vec2_divf(&startPos, &startPos, main->previewScale / pixelRatio);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
startPos.x = std::round(startPos.x);
|
|
|
|
startPos.y = std::round(startPos.y);
|
|
|
|
|
|
|
|
mouseOverItems = SelectedAtPos(startPos);
|
|
|
|
vec2_zero(&lastMoveOffset);
|
2019-07-24 03:08:08 +02:00
|
|
|
|
|
|
|
mousePos = startPos;
|
2021-03-22 06:14:37 +01:00
|
|
|
wrapper =
|
|
|
|
obs_scene_save_transform_states(main->GetCurrentScene(), true);
|
|
|
|
changed = false;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
2020-02-15 09:44:07 +01:00
|
|
|
void OBSBasicPreview::UpdateCursor(uint32_t &flags)
|
|
|
|
{
|
2022-01-06 03:42:30 +01:00
|
|
|
if (obs_sceneitem_locked(stretchItem)) {
|
|
|
|
unsetCursor();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-18 09:14:42 +01:00
|
|
|
if (!flags && (cursor().shape() != Qt::OpenHandCursor || !scrollMode))
|
2020-02-15 09:44:07 +01:00
|
|
|
unsetCursor();
|
|
|
|
if (cursor().shape() != Qt::ArrowCursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((flags & ITEM_LEFT && flags & ITEM_TOP) ||
|
|
|
|
(flags & ITEM_RIGHT && flags & ITEM_BOTTOM))
|
|
|
|
setCursor(Qt::SizeFDiagCursor);
|
|
|
|
else if ((flags & ITEM_LEFT && flags & ITEM_BOTTOM) ||
|
|
|
|
(flags & ITEM_RIGHT && flags & ITEM_TOP))
|
|
|
|
setCursor(Qt::SizeBDiagCursor);
|
|
|
|
else if (flags & ITEM_LEFT || flags & ITEM_RIGHT)
|
|
|
|
setCursor(Qt::SizeHorCursor);
|
|
|
|
else if (flags & ITEM_TOP || flags & ITEM_BOTTOM)
|
|
|
|
setCursor(Qt::SizeVerCursor);
|
2020-02-18 09:14:42 +01:00
|
|
|
else if (flags & ITEM_ROT)
|
|
|
|
setCursor(Qt::OpenHandCursor);
|
2020-02-15 09:44:07 +01:00
|
|
|
}
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool select_one(obs_scene_t * /* scene */, obs_sceneitem_t *item,
|
|
|
|
void *param)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_sceneitem_t *selectedItem =
|
|
|
|
reinterpret_cast<obs_sceneitem_t *>(param);
|
2018-06-02 18:45:01 +02:00
|
|
|
if (obs_sceneitem_is_group(item))
|
|
|
|
obs_sceneitem_group_enum_items(item, select_one, param);
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
obs_sceneitem_select(item, (selectedItem == item));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::DoSelect(const vec2 &pos)
|
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
OBSSceneItem item = GetItemAtPos(pos, true);
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_scene_enum_items(scene, select_one, (obs_sceneitem_t *)item);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::DoCtrlSelect(const vec2 &pos)
|
|
|
|
{
|
|
|
|
OBSSceneItem item = GetItemAtPos(pos, false);
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool selected = obs_sceneitem_selected(item);
|
|
|
|
obs_sceneitem_select(item, !selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::ProcessClick(const vec2 &pos)
|
|
|
|
{
|
|
|
|
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
|
|
|
|
|
|
|
if (modifiers & Qt::ControlModifier)
|
|
|
|
DoCtrlSelect(pos);
|
|
|
|
else
|
|
|
|
DoSelect(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
2016-11-10 15:32:44 +01:00
|
|
|
if (scrollMode)
|
|
|
|
setCursor(Qt::OpenHandCursor);
|
|
|
|
|
2016-07-26 10:32:43 +02:00
|
|
|
if (locked) {
|
|
|
|
OBSQTDisplay::mouseReleaseEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
if (mouseDown) {
|
|
|
|
vec2 pos = GetMouseEventPos(event);
|
|
|
|
|
|
|
|
if (!mouseMoved)
|
|
|
|
ProcessClick(pos);
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
if (selectionBox) {
|
|
|
|
Qt::KeyboardModifiers modifiers =
|
|
|
|
QGuiApplication::keyboardModifiers();
|
|
|
|
|
|
|
|
bool altDown = modifiers & Qt::AltModifier;
|
|
|
|
bool shiftDown = modifiers & Qt::ShiftModifier;
|
|
|
|
bool ctrlDown = modifiers & Qt::ControlModifier;
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(selectMutex);
|
|
|
|
if (altDown || ctrlDown || shiftDown) {
|
2019-10-10 07:24:55 +02:00
|
|
|
for (size_t i = 0; i < selectedItems.size();
|
|
|
|
i++) {
|
2019-07-24 03:08:08 +02:00
|
|
|
obs_sceneitem_select(selectedItems[i],
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 07:24:55 +02:00
|
|
|
for (size_t i = 0; i < hoveredPreviewItems.size();
|
|
|
|
i++) {
|
2019-07-24 03:08:08 +02:00
|
|
|
bool select = true;
|
|
|
|
obs_sceneitem_t *item = hoveredPreviewItems[i];
|
|
|
|
|
|
|
|
if (altDown) {
|
|
|
|
select = false;
|
|
|
|
} else if (ctrlDown) {
|
|
|
|
select = !obs_sceneitem_selected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_sceneitem_select(hoveredPreviewItems[i],
|
|
|
|
select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-02 18:45:01 +02:00
|
|
|
if (stretchGroup) {
|
|
|
|
obs_sceneitem_defer_group_resize_end(stretchGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
stretchItem = nullptr;
|
|
|
|
stretchGroup = nullptr;
|
|
|
|
mouseDown = false;
|
|
|
|
mouseMoved = false;
|
|
|
|
cropping = false;
|
2019-07-24 03:08:08 +02:00
|
|
|
selectionBox = false;
|
2020-02-15 09:44:07 +01:00
|
|
|
unsetCursor();
|
2019-02-08 08:58:40 +01:00
|
|
|
|
|
|
|
OBSSceneItem item = GetItemAtPos(pos, true);
|
2019-07-24 03:08:08 +02:00
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(selectMutex);
|
|
|
|
hoveredPreviewItems.clear();
|
|
|
|
hoveredPreviewItems.push_back(item);
|
|
|
|
selectedItems.clear();
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
2021-03-22 06:14:37 +01:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2021-11-26 10:25:39 +01:00
|
|
|
OBSDataAutoRelease rwrapper =
|
2021-04-13 00:52:55 +02:00
|
|
|
obs_scene_save_transform_states(main->GetCurrentScene(), true);
|
2021-03-22 06:14:37 +01:00
|
|
|
|
|
|
|
auto undo_redo = [](const std::string &data) {
|
2021-11-26 10:25:39 +01:00
|
|
|
OBSDataAutoRelease dat =
|
|
|
|
obs_data_create_from_json(data.c_str());
|
2023-03-28 16:24:17 +02:00
|
|
|
OBSSourceAutoRelease source = obs_get_source_by_uuid(
|
|
|
|
obs_data_get_string(dat, "scene_uuid"));
|
2021-03-22 06:14:37 +01:00
|
|
|
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())
|
2021-11-26 10:25:39 +01:00
|
|
|
->SetCurrentScene(source.Get(), true);
|
2021-03-22 06:14:37 +01:00
|
|
|
|
|
|
|
obs_scene_load_transform_states(data.c_str());
|
|
|
|
};
|
|
|
|
|
|
|
|
if (wrapper && rwrapper) {
|
|
|
|
std::string undo_data(obs_data_get_json(wrapper));
|
|
|
|
std::string redo_data(obs_data_get_json(rwrapper));
|
|
|
|
if (changed && undo_data.compare(redo_data) != 0)
|
|
|
|
main->undo_s.add_action(
|
|
|
|
QTStr("Undo.Transform")
|
|
|
|
.arg(obs_source_get_name(
|
|
|
|
main->GetCurrentSceneSource())),
|
2021-04-28 04:00:29 +02:00
|
|
|
undo_redo, undo_redo, undo_data, redo_data);
|
2021-03-22 06:14:37 +01:00
|
|
|
}
|
|
|
|
|
2021-11-26 10:25:39 +01:00
|
|
|
wrapper = nullptr;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct SelectedItemBounds {
|
|
|
|
bool first = true;
|
|
|
|
vec3 tl, br;
|
|
|
|
};
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool AddItemBounds(obs_scene_t * /* scene */, obs_sceneitem_t *item,
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
SelectedItemBounds *data =
|
|
|
|
reinterpret_cast<SelectedItemBounds *>(param);
|
2018-08-18 13:28:28 +02:00
|
|
|
vec3 t[4];
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2018-08-18 13:28:28 +02:00
|
|
|
auto add_bounds = [data, &t]() {
|
|
|
|
for (const vec3 &v : t) {
|
|
|
|
if (data->first) {
|
|
|
|
vec3_copy(&data->tl, &v);
|
|
|
|
vec3_copy(&data->br, &v);
|
|
|
|
data->first = false;
|
|
|
|
} else {
|
|
|
|
vec3_min(&data->tl, &data->tl, &v);
|
|
|
|
vec3_max(&data->br, &data->br, &v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (obs_sceneitem_is_group(item)) {
|
|
|
|
SelectedItemBounds sib;
|
|
|
|
obs_sceneitem_group_enum_items(item, AddItemBounds, &sib);
|
|
|
|
|
|
|
|
if (!sib.first) {
|
|
|
|
matrix4 xform;
|
|
|
|
obs_sceneitem_get_draw_transform(item, &xform);
|
|
|
|
|
|
|
|
vec3_set(&t[0], sib.tl.x, sib.tl.y, 0.0f);
|
|
|
|
vec3_set(&t[1], sib.tl.x, sib.br.y, 0.0f);
|
|
|
|
vec3_set(&t[2], sib.br.x, sib.tl.y, 0.0f);
|
|
|
|
vec3_set(&t[3], sib.br.x, sib.br.y, 0.0f);
|
|
|
|
vec3_transform(&t[0], &t[0], &xform);
|
|
|
|
vec3_transform(&t[1], &t[1], &xform);
|
|
|
|
vec3_transform(&t[2], &t[2], &xform);
|
|
|
|
vec3_transform(&t[3], &t[3], &xform);
|
|
|
|
add_bounds();
|
|
|
|
}
|
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
if (!obs_sceneitem_selected(item))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
matrix4 boxTransform;
|
|
|
|
obs_sceneitem_get_box_transform(item, &boxTransform);
|
|
|
|
|
2018-08-18 13:28:28 +02:00
|
|
|
t[0] = GetTransformedPos(0.0f, 0.0f, boxTransform);
|
|
|
|
t[1] = GetTransformedPos(1.0f, 0.0f, boxTransform);
|
|
|
|
t[2] = GetTransformedPos(0.0f, 1.0f, boxTransform);
|
|
|
|
t[3] = GetTransformedPos(1.0f, 1.0f, boxTransform);
|
|
|
|
add_bounds();
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-07 03:13:56 +02:00
|
|
|
struct OffsetData {
|
|
|
|
float clampDist;
|
|
|
|
vec3 tl, br, offset;
|
|
|
|
};
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool GetSourceSnapOffset(obs_scene_t * /* scene */,
|
|
|
|
obs_sceneitem_t *item, void *param)
|
2016-04-07 03:13:56 +02:00
|
|
|
{
|
|
|
|
OffsetData *data = reinterpret_cast<OffsetData *>(param);
|
|
|
|
|
|
|
|
if (obs_sceneitem_selected(item))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
matrix4 boxTransform;
|
|
|
|
obs_sceneitem_get_box_transform(item, &boxTransform);
|
|
|
|
|
|
|
|
vec3 t[4] = {GetTransformedPos(0.0f, 0.0f, boxTransform),
|
|
|
|
GetTransformedPos(1.0f, 0.0f, boxTransform),
|
|
|
|
GetTransformedPos(0.0f, 1.0f, boxTransform),
|
|
|
|
GetTransformedPos(1.0f, 1.0f, boxTransform)};
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
vec3 tl, br;
|
|
|
|
vec3_zero(&tl);
|
|
|
|
vec3_zero(&br);
|
|
|
|
for (const vec3 &v : t) {
|
|
|
|
if (first) {
|
|
|
|
vec3_copy(&tl, &v);
|
|
|
|
vec3_copy(&br, &v);
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
vec3_min(&tl, &tl, &v);
|
|
|
|
vec3_max(&br, &br, &v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Snap to other source edges
|
|
|
|
#define EDGE_SNAP(l, r, x, y) \
|
|
|
|
do { \
|
|
|
|
double dist = fabsf(l.x - data->r.x); \
|
|
|
|
if (dist < data->clampDist && \
|
|
|
|
fabsf(data->offset.x) < EPSILON && data->tl.y < br.y && \
|
|
|
|
data->br.y > tl.y && \
|
|
|
|
(fabsf(data->offset.x) > dist || \
|
|
|
|
data->offset.x < EPSILON)) \
|
|
|
|
data->offset.x = l.x - data->r.x; \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
EDGE_SNAP(tl, br, x, y);
|
|
|
|
EDGE_SNAP(tl, br, y, x);
|
|
|
|
EDGE_SNAP(br, tl, x, y);
|
|
|
|
EDGE_SNAP(br, tl, y, x);
|
|
|
|
#undef EDGE_SNAP
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void OBSBasicPreview::SnapItemMovement(vec2 &offset)
|
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
|
|
|
|
SelectedItemBounds data;
|
|
|
|
obs_scene_enum_items(scene, AddItemBounds, &data);
|
|
|
|
|
|
|
|
data.tl.x += offset.x;
|
|
|
|
data.tl.y += offset.y;
|
|
|
|
data.br.x += offset.x;
|
|
|
|
data.br.y += offset.y;
|
|
|
|
|
2016-04-07 03:03:29 +02:00
|
|
|
vec3 snapOffset = GetSnapOffset(data.tl, data.br);
|
|
|
|
|
|
|
|
const bool snap = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"SnappingEnabled");
|
2016-04-07 03:13:56 +02:00
|
|
|
const bool sourcesSnap = config_get_bool(
|
|
|
|
GetGlobalConfig(), "BasicWindow", "SourceSnapping");
|
2016-04-07 03:03:29 +02:00
|
|
|
if (snap == false)
|
|
|
|
return;
|
2016-04-07 03:13:56 +02:00
|
|
|
if (sourcesSnap == false) {
|
|
|
|
offset.x += snapOffset.x;
|
|
|
|
offset.y += snapOffset.y;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float clampDist = config_get_double(GetGlobalConfig(),
|
|
|
|
"BasicWindow",
|
|
|
|
"SnapDistance") /
|
|
|
|
main->previewScale;
|
2016-04-07 03:03:29 +02:00
|
|
|
|
2016-04-07 03:13:56 +02:00
|
|
|
OffsetData offsetData;
|
|
|
|
offsetData.clampDist = clampDist;
|
|
|
|
offsetData.tl = data.tl;
|
|
|
|
offsetData.br = data.br;
|
|
|
|
vec3_copy(&offsetData.offset, &snapOffset);
|
|
|
|
|
|
|
|
obs_scene_enum_items(scene, GetSourceSnapOffset, &offsetData);
|
|
|
|
|
|
|
|
if (fabsf(offsetData.offset.x) > EPSILON ||
|
|
|
|
fabsf(offsetData.offset.y) > EPSILON) {
|
|
|
|
offset.x += offsetData.offset.x;
|
|
|
|
offset.y += offsetData.offset.y;
|
|
|
|
} else {
|
|
|
|
offset.x += snapOffset.x;
|
|
|
|
offset.y += snapOffset.y;
|
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool move_items(obs_scene_t * /* scene */, obs_sceneitem_t *item,
|
|
|
|
void *param)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
2017-06-18 02:10:42 +02:00
|
|
|
if (obs_sceneitem_locked(item))
|
|
|
|
return true;
|
|
|
|
|
2018-06-02 18:45:01 +02:00
|
|
|
bool selected = obs_sceneitem_selected(item);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec2 *offset = reinterpret_cast<vec2 *>(param);
|
|
|
|
|
2018-06-02 18:45:01 +02:00
|
|
|
if (obs_sceneitem_is_group(item) && !selected) {
|
|
|
|
matrix4 transform;
|
|
|
|
vec3 new_offset;
|
|
|
|
vec3_set(&new_offset, offset->x, offset->y, 0.0f);
|
|
|
|
|
|
|
|
obs_sceneitem_get_draw_transform(item, &transform);
|
|
|
|
vec4_set(&transform.t, 0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
matrix4_inv(&transform, &transform);
|
|
|
|
vec3_transform(&new_offset, &new_offset, &transform);
|
|
|
|
obs_sceneitem_group_enum_items(item, move_items, &new_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected) {
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec2 pos;
|
2014-08-03 23:39:19 +02:00
|
|
|
obs_sceneitem_get_pos(item, &pos);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec2_add(&pos, &pos, offset);
|
2014-08-03 23:39:19 +02:00
|
|
|
obs_sceneitem_set_pos(item, &pos);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::MoveItems(const vec2 &pos)
|
|
|
|
{
|
|
|
|
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
|
|
|
|
vec2 offset, moveOffset;
|
|
|
|
vec2_sub(&offset, &pos, &startPos);
|
|
|
|
vec2_sub(&moveOffset, &offset, &lastMoveOffset);
|
|
|
|
|
|
|
|
if (!(modifiers & Qt::ControlModifier))
|
|
|
|
SnapItemMovement(moveOffset);
|
|
|
|
|
|
|
|
vec2_add(&lastMoveOffset, &lastMoveOffset, &moveOffset);
|
|
|
|
|
|
|
|
obs_scene_enum_items(scene, move_items, &moveOffset);
|
|
|
|
}
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
static bool CounterClockwise(float x1, float x2, float x3, float y1, float y2,
|
|
|
|
float y3)
|
|
|
|
{
|
|
|
|
return (y3 - y1) * (x2 - x1) > (y2 - y1) * (x3 - x1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IntersectLine(float x1, float x2, float x3, float x4, float y1,
|
|
|
|
float y2, float y3, float y4)
|
|
|
|
{
|
|
|
|
bool a = CounterClockwise(x1, x2, x3, y1, y2, y3);
|
|
|
|
bool b = CounterClockwise(x1, x2, x4, y1, y2, y4);
|
|
|
|
bool c = CounterClockwise(x3, x4, x1, y3, y4, y1);
|
|
|
|
bool d = CounterClockwise(x3, x4, x2, y3, y4, y2);
|
|
|
|
|
|
|
|
return (a != b) && (c != d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IntersectBox(matrix4 transform, float x1, float x2, float y1,
|
|
|
|
float y2)
|
|
|
|
{
|
|
|
|
float x3, x4, y3, y4;
|
|
|
|
|
|
|
|
x3 = transform.t.x;
|
|
|
|
y3 = transform.t.y;
|
|
|
|
x4 = x3 + transform.x.x;
|
|
|
|
y4 = y3 + transform.x.y;
|
|
|
|
|
|
|
|
if (IntersectLine(x1, x1, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y1, y1, y3, y4) ||
|
|
|
|
IntersectLine(x2, x2, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y2, y2, y3, y4))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
x4 = x3 + transform.y.x;
|
|
|
|
y4 = y3 + transform.y.y;
|
|
|
|
|
|
|
|
if (IntersectLine(x1, x1, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y1, y1, y3, y4) ||
|
|
|
|
IntersectLine(x2, x2, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y2, y2, y3, y4))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
x3 = transform.t.x + transform.x.x;
|
|
|
|
y3 = transform.t.y + transform.x.y;
|
|
|
|
x4 = x3 + transform.y.x;
|
|
|
|
y4 = y3 + transform.y.y;
|
|
|
|
|
|
|
|
if (IntersectLine(x1, x1, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y1, y1, y3, y4) ||
|
|
|
|
IntersectLine(x2, x2, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y2, y2, y3, y4))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
x3 = transform.t.x + transform.y.x;
|
|
|
|
y3 = transform.t.y + transform.y.y;
|
|
|
|
x4 = x3 + transform.x.x;
|
|
|
|
y4 = y3 + transform.x.y;
|
|
|
|
|
|
|
|
if (IntersectLine(x1, x1, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y1, y1, y3, y4) ||
|
|
|
|
IntersectLine(x2, x2, x3, x4, y1, y2, y3, y4) ||
|
|
|
|
IntersectLine(x1, x2, x3, x4, y2, y2, y3, y4))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#undef PI
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
bool OBSBasicPreview::FindSelected(obs_scene_t *, obs_sceneitem_t *item,
|
2019-07-24 03:08:08 +02:00
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
SceneFindBoxData *data = reinterpret_cast<SceneFindBoxData *>(param);
|
|
|
|
|
|
|
|
if (obs_sceneitem_selected(item))
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
static bool FindItemsInBox(obs_scene_t * /* scene */, obs_sceneitem_t *item,
|
2019-07-24 03:08:08 +02:00
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
SceneFindBoxData *data = reinterpret_cast<SceneFindBoxData *>(param);
|
|
|
|
matrix4 transform;
|
|
|
|
matrix4 invTransform;
|
|
|
|
vec3 transformedPos;
|
|
|
|
vec3 pos3;
|
|
|
|
vec3 pos3_;
|
|
|
|
|
2021-09-18 07:09:37 +02:00
|
|
|
vec2 pos_min, pos_max;
|
|
|
|
vec2_min(&pos_min, &data->startPos, &data->pos);
|
|
|
|
vec2_max(&pos_max, &data->startPos, &data->pos);
|
|
|
|
|
|
|
|
const float x1 = pos_min.x;
|
|
|
|
const float x2 = pos_max.x;
|
|
|
|
const float y1 = pos_min.y;
|
|
|
|
const float y2 = pos_max.y;
|
2019-07-24 03:08:08 +02:00
|
|
|
|
|
|
|
if (!SceneItemHasVideo(item))
|
|
|
|
return true;
|
|
|
|
if (obs_sceneitem_locked(item))
|
|
|
|
return true;
|
|
|
|
if (!obs_sceneitem_visible(item))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
vec3_set(&pos3, data->pos.x, data->pos.y, 0.0f);
|
|
|
|
|
|
|
|
obs_sceneitem_get_box_transform(item, &transform);
|
|
|
|
|
|
|
|
matrix4_inv(&invTransform, &transform);
|
|
|
|
vec3_transform(&transformedPos, &pos3, &invTransform);
|
|
|
|
vec3_transform(&pos3_, &transformedPos, &transform);
|
|
|
|
|
|
|
|
if (CloseFloat(pos3.x, pos3_.x) && CloseFloat(pos3.y, pos3_.y) &&
|
|
|
|
transformedPos.x >= 0.0f && transformedPos.x <= 1.0f &&
|
|
|
|
transformedPos.y >= 0.0f && transformedPos.y <= 1.0f) {
|
|
|
|
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.t.x > x1 && transform.t.x < x2 && transform.t.y > y1 &&
|
|
|
|
transform.t.y < y2) {
|
|
|
|
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.t.x + transform.x.x > x1 &&
|
|
|
|
transform.t.x + transform.x.x < x2 &&
|
|
|
|
transform.t.y + transform.x.y > y1 &&
|
|
|
|
transform.t.y + transform.x.y < y2) {
|
|
|
|
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.t.x + transform.y.x > x1 &&
|
|
|
|
transform.t.x + transform.y.x < x2 &&
|
|
|
|
transform.t.y + transform.y.y > y1 &&
|
|
|
|
transform.t.y + transform.y.y < y2) {
|
|
|
|
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.t.x + transform.x.x + transform.y.x > x1 &&
|
|
|
|
transform.t.x + transform.x.x + transform.y.x < x2 &&
|
|
|
|
transform.t.y + transform.x.y + transform.y.y > y1 &&
|
|
|
|
transform.t.y + transform.x.y + transform.y.y < y2) {
|
|
|
|
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.t.x + 0.5 * (transform.x.x + transform.y.x) > x1 &&
|
|
|
|
transform.t.x + 0.5 * (transform.x.x + transform.y.x) < x2 &&
|
|
|
|
transform.t.y + 0.5 * (transform.x.y + transform.y.y) > y1 &&
|
|
|
|
transform.t.y + 0.5 * (transform.x.y + transform.y.y) < y2) {
|
|
|
|
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IntersectBox(transform, x1, x2, y1, y2)) {
|
|
|
|
data->sceneItems.push_back(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::BoxItems(const vec2 &startPos, const vec2 &pos)
|
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
if (!scene)
|
|
|
|
return;
|
|
|
|
|
2020-02-15 09:44:07 +01:00
|
|
|
if (cursor().shape() != Qt::CrossCursor)
|
|
|
|
setCursor(Qt::CrossCursor);
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
SceneFindBoxData data(startPos, pos);
|
|
|
|
obs_scene_enum_items(scene, FindItemsInBox, &data);
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(selectMutex);
|
|
|
|
hoveredPreviewItems = data.sceneItems;
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec3 OBSBasicPreview::CalculateStretchPos(const vec3 &tl, const vec3 &br)
|
|
|
|
{
|
2014-08-03 23:39:19 +02:00
|
|
|
uint32_t alignment = obs_sceneitem_get_alignment(stretchItem);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec3 pos;
|
|
|
|
|
|
|
|
vec3_zero(&pos);
|
|
|
|
|
|
|
|
if (alignment & OBS_ALIGN_LEFT)
|
|
|
|
pos.x = tl.x;
|
|
|
|
else if (alignment & OBS_ALIGN_RIGHT)
|
|
|
|
pos.x = br.x;
|
|
|
|
else
|
|
|
|
pos.x = (br.x - tl.x) * 0.5f + tl.x;
|
|
|
|
|
|
|
|
if (alignment & OBS_ALIGN_TOP)
|
|
|
|
pos.y = tl.y;
|
|
|
|
else if (alignment & OBS_ALIGN_BOTTOM)
|
|
|
|
pos.y = br.y;
|
|
|
|
else
|
|
|
|
pos.y = (br.y - tl.y) * 0.5f + tl.y;
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::ClampAspect(vec3 &tl, vec3 &br, vec2 &size,
|
|
|
|
const vec2 &baseSize)
|
|
|
|
{
|
|
|
|
float baseAspect = baseSize.x / baseSize.y;
|
|
|
|
float aspect = size.x / size.y;
|
|
|
|
uint32_t stretchFlags = (uint32_t)stretchHandle;
|
|
|
|
|
|
|
|
if (stretchHandle == ItemHandle::TopLeft ||
|
|
|
|
stretchHandle == ItemHandle::TopRight ||
|
|
|
|
stretchHandle == ItemHandle::BottomLeft ||
|
|
|
|
stretchHandle == ItemHandle::BottomRight) {
|
2017-01-06 17:07:24 +01:00
|
|
|
if (aspect < baseAspect) {
|
|
|
|
if ((size.y >= 0.0f && size.x >= 0.0f) ||
|
|
|
|
(size.y <= 0.0f && size.x <= 0.0f))
|
|
|
|
size.x = size.y * baseAspect;
|
|
|
|
else
|
|
|
|
size.x = size.y * baseAspect * -1.0f;
|
|
|
|
} else {
|
|
|
|
if ((size.y >= 0.0f && size.x >= 0.0f) ||
|
|
|
|
(size.y <= 0.0f && size.x <= 0.0f))
|
|
|
|
size.y = size.x / baseAspect;
|
|
|
|
else
|
|
|
|
size.y = size.x / baseAspect * -1.0f;
|
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
} else if (stretchHandle == ItemHandle::TopCenter ||
|
|
|
|
stretchHandle == ItemHandle::BottomCenter) {
|
2017-01-06 17:07:24 +01:00
|
|
|
if ((size.y >= 0.0f && size.x >= 0.0f) ||
|
|
|
|
(size.y <= 0.0f && size.x <= 0.0f))
|
|
|
|
size.x = size.y * baseAspect;
|
|
|
|
else
|
|
|
|
size.x = size.y * baseAspect * -1.0f;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
} else if (stretchHandle == ItemHandle::CenterLeft ||
|
|
|
|
stretchHandle == ItemHandle::CenterRight) {
|
2017-01-06 17:07:24 +01:00
|
|
|
if ((size.y >= 0.0f && size.x >= 0.0f) ||
|
|
|
|
(size.y <= 0.0f && size.x <= 0.0f))
|
|
|
|
size.y = size.x / baseAspect;
|
|
|
|
else
|
|
|
|
size.y = size.x / baseAspect * -1.0f;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size.x = std::round(size.x);
|
|
|
|
size.y = std::round(size.y);
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_LEFT)
|
|
|
|
tl.x = br.x - size.x;
|
|
|
|
else if (stretchFlags & ITEM_RIGHT)
|
|
|
|
br.x = tl.x + size.x;
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_TOP)
|
|
|
|
tl.y = br.y - size.y;
|
|
|
|
else if (stretchFlags & ITEM_BOTTOM)
|
|
|
|
br.y = tl.y + size.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::SnapStretchingToScreen(vec3 &tl, vec3 &br)
|
|
|
|
{
|
|
|
|
uint32_t stretchFlags = (uint32_t)stretchHandle;
|
|
|
|
vec3 newTL = GetTransformedPos(tl.x, tl.y, itemToScreen);
|
|
|
|
vec3 newTR = GetTransformedPos(br.x, tl.y, itemToScreen);
|
|
|
|
vec3 newBL = GetTransformedPos(tl.x, br.y, itemToScreen);
|
|
|
|
vec3 newBR = GetTransformedPos(br.x, br.y, itemToScreen);
|
|
|
|
vec3 boundingTL;
|
|
|
|
vec3 boundingBR;
|
|
|
|
|
|
|
|
vec3_copy(&boundingTL, &newTL);
|
|
|
|
vec3_min(&boundingTL, &boundingTL, &newTR);
|
|
|
|
vec3_min(&boundingTL, &boundingTL, &newBL);
|
|
|
|
vec3_min(&boundingTL, &boundingTL, &newBR);
|
|
|
|
|
|
|
|
vec3_copy(&boundingBR, &newTL);
|
|
|
|
vec3_max(&boundingBR, &boundingBR, &newTR);
|
|
|
|
vec3_max(&boundingBR, &boundingBR, &newBL);
|
|
|
|
vec3_max(&boundingBR, &boundingBR, &newBR);
|
|
|
|
|
2016-04-07 03:03:29 +02:00
|
|
|
vec3 offset = GetSnapOffset(boundingTL, boundingBR);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec3_add(&offset, &offset, &newTL);
|
|
|
|
vec3_transform(&offset, &offset, &screenToItem);
|
|
|
|
vec3_sub(&offset, &offset, &tl);
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_LEFT)
|
|
|
|
tl.x += offset.x;
|
|
|
|
else if (stretchFlags & ITEM_RIGHT)
|
|
|
|
br.x += offset.x;
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_TOP)
|
|
|
|
tl.y += offset.y;
|
|
|
|
else if (stretchFlags & ITEM_BOTTOM)
|
|
|
|
br.y += offset.y;
|
|
|
|
}
|
|
|
|
|
2016-05-03 02:07:13 +02:00
|
|
|
static float maxfunc(float x, float y)
|
|
|
|
{
|
|
|
|
return x > y ? x : y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float minfunc(float x, float y)
|
|
|
|
{
|
|
|
|
return x < y ? x : y;
|
|
|
|
}
|
|
|
|
|
2016-03-31 03:46:02 +02:00
|
|
|
void OBSBasicPreview::CropItem(const vec2 &pos)
|
|
|
|
{
|
|
|
|
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(stretchItem);
|
|
|
|
uint32_t stretchFlags = (uint32_t)stretchHandle;
|
|
|
|
uint32_t align = obs_sceneitem_get_alignment(stretchItem);
|
|
|
|
vec3 tl, br, pos3;
|
|
|
|
|
|
|
|
vec3_zero(&tl);
|
|
|
|
vec3_set(&br, stretchItemSize.x, stretchItemSize.y, 0.0f);
|
|
|
|
|
|
|
|
vec3_set(&pos3, pos.x, pos.y, 0.0f);
|
|
|
|
vec3_transform(&pos3, &pos3, &screenToItem);
|
|
|
|
|
|
|
|
obs_sceneitem_crop crop = startCrop;
|
2023-07-07 06:08:16 +02:00
|
|
|
vec2 scale, rawscale;
|
2016-03-31 03:46:02 +02:00
|
|
|
|
2023-07-07 06:08:16 +02:00
|
|
|
obs_sceneitem_get_scale(stretchItem, &rawscale);
|
|
|
|
vec2_set(&scale,
|
|
|
|
boundsType == OBS_BOUNDS_NONE ? rawscale.x : fabsf(rawscale.x),
|
|
|
|
boundsType == OBS_BOUNDS_NONE ? rawscale.y
|
|
|
|
: fabsf(rawscale.y));
|
2016-03-31 03:46:02 +02:00
|
|
|
|
|
|
|
vec2 max_tl;
|
|
|
|
vec2 max_br;
|
|
|
|
|
|
|
|
vec2_set(&max_tl, float(-crop.left) * scale.x,
|
|
|
|
float(-crop.top) * scale.y);
|
|
|
|
vec2_set(&max_br, stretchItemSize.x + crop.right * scale.x,
|
|
|
|
stretchItemSize.y + crop.bottom * scale.y);
|
|
|
|
|
2016-05-03 02:07:13 +02:00
|
|
|
typedef std::function<float(float, float)> minmax_func_t;
|
2016-03-31 03:46:02 +02:00
|
|
|
|
2023-07-07 06:08:16 +02:00
|
|
|
minmax_func_t min_x = scale.x < 0.0f && boundsType == OBS_BOUNDS_NONE
|
|
|
|
? maxfunc
|
|
|
|
: minfunc;
|
|
|
|
minmax_func_t min_y = scale.y < 0.0f && boundsType == OBS_BOUNDS_NONE
|
|
|
|
? maxfunc
|
|
|
|
: minfunc;
|
|
|
|
minmax_func_t max_x = scale.x < 0.0f && boundsType == OBS_BOUNDS_NONE
|
|
|
|
? minfunc
|
|
|
|
: maxfunc;
|
|
|
|
minmax_func_t max_y = scale.y < 0.0f && boundsType == OBS_BOUNDS_NONE
|
|
|
|
? minfunc
|
|
|
|
: maxfunc;
|
2016-03-31 03:46:02 +02:00
|
|
|
|
2016-05-03 02:07:13 +02:00
|
|
|
pos3.x = min_x(pos3.x, max_br.x);
|
|
|
|
pos3.x = max_x(pos3.x, max_tl.x);
|
|
|
|
pos3.y = min_y(pos3.y, max_br.y);
|
|
|
|
pos3.y = max_y(pos3.y, max_tl.y);
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_LEFT) {
|
2016-03-31 03:46:02 +02:00
|
|
|
float maxX = stretchItemSize.x - (2.0 * scale.x);
|
2016-05-03 02:07:13 +02:00
|
|
|
pos3.x = tl.x = min_x(pos3.x, maxX);
|
2016-03-31 03:46:02 +02:00
|
|
|
|
2016-05-03 02:07:13 +02:00
|
|
|
} else if (stretchFlags & ITEM_RIGHT) {
|
2016-03-31 03:46:02 +02:00
|
|
|
float minX = (2.0 * scale.x);
|
2016-05-03 02:07:13 +02:00
|
|
|
pos3.x = br.x = max_x(pos3.x, minX);
|
2016-03-31 03:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_TOP) {
|
|
|
|
float maxY = stretchItemSize.y - (2.0 * scale.y);
|
2016-05-03 02:07:13 +02:00
|
|
|
pos3.y = tl.y = min_y(pos3.y, maxY);
|
2016-03-31 03:46:02 +02:00
|
|
|
|
2016-05-03 02:07:13 +02:00
|
|
|
} else if (stretchFlags & ITEM_BOTTOM) {
|
2016-03-31 03:46:02 +02:00
|
|
|
float minY = (2.0 * scale.y);
|
2016-05-03 02:07:13 +02:00
|
|
|
pos3.y = br.y = max_y(pos3.y, minY);
|
2016-03-31 03:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ALIGN_X (ITEM_LEFT | ITEM_RIGHT)
|
|
|
|
#define ALIGN_Y (ITEM_TOP | ITEM_BOTTOM)
|
|
|
|
vec3 newPos;
|
|
|
|
vec3_zero(&newPos);
|
|
|
|
|
|
|
|
uint32_t align_x = (align & ALIGN_X);
|
|
|
|
uint32_t align_y = (align & ALIGN_Y);
|
|
|
|
if (align_x == (stretchFlags & ALIGN_X) && align_x != 0)
|
|
|
|
newPos.x = pos3.x;
|
|
|
|
else if (align & ITEM_RIGHT)
|
|
|
|
newPos.x = stretchItemSize.x;
|
|
|
|
else if (!(align & ITEM_LEFT))
|
|
|
|
newPos.x = stretchItemSize.x * 0.5f;
|
|
|
|
|
|
|
|
if (align_y == (stretchFlags & ALIGN_Y) && align_y != 0)
|
|
|
|
newPos.y = pos3.y;
|
|
|
|
else if (align & ITEM_BOTTOM)
|
|
|
|
newPos.y = stretchItemSize.y;
|
|
|
|
else if (!(align & ITEM_TOP))
|
|
|
|
newPos.y = stretchItemSize.y * 0.5f;
|
|
|
|
#undef ALIGN_X
|
|
|
|
#undef ALIGN_Y
|
|
|
|
|
|
|
|
crop = startCrop;
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_LEFT)
|
|
|
|
crop.left += int(std::round(tl.x / scale.x));
|
|
|
|
else if (stretchFlags & ITEM_RIGHT)
|
|
|
|
crop.right +=
|
|
|
|
int(std::round((stretchItemSize.x - br.x) / scale.x));
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_TOP)
|
|
|
|
crop.top += int(std::round(tl.y / scale.y));
|
|
|
|
else if (stretchFlags & ITEM_BOTTOM)
|
|
|
|
crop.bottom +=
|
|
|
|
int(std::round((stretchItemSize.y - br.y) / scale.y));
|
|
|
|
|
|
|
|
vec3_transform(&newPos, &newPos, &itemToScreen);
|
|
|
|
newPos.x = std::round(newPos.x);
|
|
|
|
newPos.y = std::round(newPos.y);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
vec3 curPos;
|
|
|
|
vec3_zero(&curPos);
|
|
|
|
obs_sceneitem_get_pos(stretchItem, (vec2*)&curPos);
|
|
|
|
blog(LOG_DEBUG, "curPos {%d, %d} - newPos {%d, %d}",
|
|
|
|
int(curPos.x), int(curPos.y),
|
|
|
|
int(newPos.x), int(newPos.y));
|
|
|
|
blog(LOG_DEBUG, "crop {%d, %d, %d, %d}",
|
|
|
|
crop.left, crop.top,
|
|
|
|
crop.right, crop.bottom);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
obs_sceneitem_defer_update_begin(stretchItem);
|
|
|
|
obs_sceneitem_set_crop(stretchItem, &crop);
|
2018-07-19 07:04:32 +02:00
|
|
|
if (boundsType == OBS_BOUNDS_NONE)
|
|
|
|
obs_sceneitem_set_pos(stretchItem, (vec2 *)&newPos);
|
2016-03-31 03:46:02 +02:00
|
|
|
obs_sceneitem_defer_update_end(stretchItem);
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void OBSBasicPreview::StretchItem(const vec2 &pos)
|
|
|
|
{
|
|
|
|
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
|
|
|
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(stretchItem);
|
|
|
|
uint32_t stretchFlags = (uint32_t)stretchHandle;
|
|
|
|
bool shiftDown = (modifiers & Qt::ShiftModifier);
|
|
|
|
vec3 tl, br, pos3;
|
|
|
|
|
|
|
|
vec3_zero(&tl);
|
|
|
|
vec3_set(&br, stretchItemSize.x, stretchItemSize.y, 0.0f);
|
|
|
|
|
|
|
|
vec3_set(&pos3, pos.x, pos.y, 0.0f);
|
|
|
|
vec3_transform(&pos3, &pos3, &screenToItem);
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_LEFT)
|
|
|
|
tl.x = pos3.x;
|
|
|
|
else if (stretchFlags & ITEM_RIGHT)
|
|
|
|
br.x = pos3.x;
|
|
|
|
|
|
|
|
if (stretchFlags & ITEM_TOP)
|
|
|
|
tl.y = pos3.y;
|
|
|
|
else if (stretchFlags & ITEM_BOTTOM)
|
|
|
|
br.y = pos3.y;
|
|
|
|
|
|
|
|
if (!(modifiers & Qt::ControlModifier))
|
|
|
|
SnapStretchingToScreen(tl, br);
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_source_t *source = obs_sceneitem_get_source(stretchItem);
|
2014-06-17 02:55:48 +02:00
|
|
|
|
2023-05-20 00:46:45 +02:00
|
|
|
uint32_t source_cx = obs_source_get_width(source);
|
|
|
|
uint32_t source_cy = obs_source_get_height(source);
|
|
|
|
|
|
|
|
/* if the source's internal size has been set to 0 for whatever reason
|
|
|
|
* while resizing, do not update transform, otherwise source will be
|
|
|
|
* stuck invisible until a complete transform reset */
|
|
|
|
if (!source_cx || !source_cy)
|
|
|
|
return;
|
|
|
|
|
2014-06-17 02:55:48 +02:00
|
|
|
vec2 baseSize;
|
2023-05-20 00:46:45 +02:00
|
|
|
vec2_set(&baseSize, float(source_cx), float(source_cy));
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2014-06-17 02:55:48 +02:00
|
|
|
vec2 size;
|
|
|
|
vec2_set(&size, br.x - tl.x, br.y - tl.y);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
if (boundsType != OBS_BOUNDS_NONE) {
|
Do not clamp aspect by default when using bounds
If the scene item has a bounding box set up for it, do not make it use
aspect ratio clamping by default.
Instead, make it so that shift will turn on aspect ratio, and make it
also apply to all types of bounding box modes.
The only time where aspect ratio clamping should apply by default is
when bounds are not in use (i.e. when a source is just created). Some
will disagree with me just because that's how photoshop does it, but
we're not photoshop, and I feel that the majority of users will have
more trouble with it disabled by default than enabled by default.
So to sum it up:
If bounds inactive, clamp aspect ratio by default, because scene items
start out with it inactive, and it directly affects the scale.
If bounds active, do not clamp aspect ratio by default, because clamping
to aspect ratio doesn't particularly have an effect for mode bounds
modes except for "stretch to bounds".
2014-06-23 08:53:39 +02:00
|
|
|
if (shiftDown)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
ClampAspect(tl, br, size, baseSize);
|
|
|
|
|
|
|
|
if (tl.x > br.x)
|
|
|
|
std::swap(tl.x, br.x);
|
|
|
|
if (tl.y > br.y)
|
|
|
|
std::swap(tl.y, br.y);
|
|
|
|
|
|
|
|
vec2_abs(&size, &size);
|
|
|
|
|
|
|
|
obs_sceneitem_set_bounds(stretchItem, &size);
|
|
|
|
} else {
|
2016-03-31 03:46:02 +02:00
|
|
|
obs_sceneitem_crop crop;
|
|
|
|
obs_sceneitem_get_crop(stretchItem, &crop);
|
|
|
|
|
|
|
|
baseSize.x -= float(crop.left + crop.right);
|
|
|
|
baseSize.y -= float(crop.top + crop.bottom);
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
if (!shiftDown)
|
|
|
|
ClampAspect(tl, br, size, baseSize);
|
|
|
|
|
|
|
|
vec2_div(&size, &size, &baseSize);
|
2014-08-03 23:39:19 +02:00
|
|
|
obs_sceneitem_set_scale(stretchItem, &size);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pos3 = CalculateStretchPos(tl, br);
|
|
|
|
vec3_transform(&pos3, &pos3, &itemToScreen);
|
|
|
|
|
2014-06-17 02:55:48 +02:00
|
|
|
vec2 newPos;
|
|
|
|
vec2_set(&newPos, std::round(pos3.x), std::round(pos3.y));
|
2014-08-03 23:39:19 +02:00
|
|
|
obs_sceneitem_set_pos(stretchItem, &newPos);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 09:14:42 +01:00
|
|
|
void OBSBasicPreview::RotateItem(const vec2 &pos)
|
|
|
|
{
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
|
|
|
bool shiftDown = (modifiers & Qt::ShiftModifier);
|
|
|
|
bool ctrlDown = (modifiers & Qt::ControlModifier);
|
|
|
|
|
|
|
|
vec2 pos2;
|
2020-12-24 04:57:55 +01:00
|
|
|
vec2_copy(&pos2, &pos);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
|
|
|
float angle =
|
|
|
|
atan2(pos2.y - rotatePoint.y, pos2.x - rotatePoint.x) + RAD(90);
|
|
|
|
|
|
|
|
#define ROT_SNAP(rot, thresh) \
|
|
|
|
if (abs(angle - RAD(rot)) < RAD(thresh)) { \
|
|
|
|
angle = RAD(rot); \
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shiftDown) {
|
|
|
|
for (int i = 0; i <= 360 / 15; i++) {
|
|
|
|
ROT_SNAP(i * 15 - 90, 7.5);
|
|
|
|
}
|
|
|
|
} else if (!ctrlDown) {
|
|
|
|
ROT_SNAP(rotateAngle, 5)
|
|
|
|
|
|
|
|
ROT_SNAP(-90, 5)
|
|
|
|
ROT_SNAP(-45, 5)
|
|
|
|
ROT_SNAP(0, 5)
|
|
|
|
ROT_SNAP(45, 5)
|
|
|
|
ROT_SNAP(90, 5)
|
|
|
|
ROT_SNAP(135, 5)
|
|
|
|
ROT_SNAP(180, 5)
|
|
|
|
ROT_SNAP(225, 5)
|
|
|
|
ROT_SNAP(270, 5)
|
|
|
|
ROT_SNAP(315, 5)
|
|
|
|
}
|
|
|
|
#undef ROT_SNAP
|
|
|
|
|
|
|
|
vec2 pos3;
|
|
|
|
vec2_copy(&pos3, &offsetPoint);
|
|
|
|
RotatePos(&pos3, angle);
|
|
|
|
pos3.x += rotatePoint.x;
|
|
|
|
pos3.y += rotatePoint.y;
|
|
|
|
|
|
|
|
obs_sceneitem_set_rot(stretchItem, DEG(angle));
|
|
|
|
obs_sceneitem_set_pos(stretchItem, &pos3);
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void OBSBasicPreview::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
2020-12-24 04:57:55 +01:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2021-03-22 06:14:37 +01:00
|
|
|
changed = true;
|
|
|
|
|
2022-07-19 16:12:17 +02:00
|
|
|
QPointF qtPos = event->position();
|
|
|
|
|
2022-07-29 20:31:13 +02:00
|
|
|
float pixelRatio = main->GetDevicePixelRatio();
|
2020-12-24 04:57:55 +01:00
|
|
|
|
2016-11-05 17:48:46 +01:00
|
|
|
if (scrollMode && event->buttons() == Qt::LeftButton) {
|
2020-12-24 04:57:55 +01:00
|
|
|
scrollingOffset.x += pixelRatio * (qtPos.x() - scrollingFrom.x);
|
|
|
|
scrollingOffset.y += pixelRatio * (qtPos.y() - scrollingFrom.y);
|
2022-07-19 16:12:17 +02:00
|
|
|
scrollingFrom.x = qtPos.x();
|
|
|
|
scrollingFrom.y = qtPos.y();
|
2016-11-05 17:48:46 +01:00
|
|
|
emit DisplayResized();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-10 15:32:44 +01:00
|
|
|
if (locked)
|
|
|
|
return;
|
|
|
|
|
2020-02-15 09:44:07 +01:00
|
|
|
bool updateCursor = false;
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
if (mouseDown) {
|
|
|
|
vec2 pos = GetMouseEventPos(event);
|
|
|
|
|
|
|
|
if (!mouseMoved && !mouseOverItems &&
|
|
|
|
stretchHandle == ItemHandle::None) {
|
|
|
|
ProcessClick(startPos);
|
|
|
|
mouseOverItems = SelectedAtPos(startPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.x = std::round(pos.x);
|
|
|
|
pos.y = std::round(pos.y);
|
|
|
|
|
2016-03-31 03:46:02 +02:00
|
|
|
if (stretchHandle != ItemHandle::None) {
|
2022-01-06 03:42:30 +01:00
|
|
|
if (obs_sceneitem_locked(stretchItem))
|
|
|
|
return;
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
selectionBox = false;
|
|
|
|
|
2018-07-16 03:18:25 +02:00
|
|
|
OBSScene scene = main->GetCurrentScene();
|
2018-06-02 18:45:01 +02:00
|
|
|
obs_sceneitem_t *group =
|
|
|
|
obs_sceneitem_get_group(scene, stretchItem);
|
|
|
|
if (group) {
|
|
|
|
vec3 group_pos;
|
|
|
|
vec3_set(&group_pos, pos.x, pos.y, 0.0f);
|
|
|
|
vec3_transform(&group_pos, &group_pos,
|
|
|
|
&invGroupTransform);
|
|
|
|
pos.x = group_pos.x;
|
|
|
|
pos.y = group_pos.y;
|
|
|
|
}
|
|
|
|
|
2020-02-18 09:14:42 +01:00
|
|
|
if (stretchHandle == ItemHandle::Rot) {
|
|
|
|
RotateItem(pos);
|
|
|
|
setCursor(Qt::ClosedHandCursor);
|
|
|
|
} else if (cropping)
|
2016-03-31 03:46:02 +02:00
|
|
|
CropItem(pos);
|
|
|
|
else
|
|
|
|
StretchItem(pos);
|
|
|
|
|
|
|
|
} else if (mouseOverItems) {
|
2020-02-15 09:44:07 +01:00
|
|
|
if (cursor().shape() != Qt::SizeAllCursor)
|
|
|
|
setCursor(Qt::SizeAllCursor);
|
2019-07-24 03:08:08 +02:00
|
|
|
selectionBox = false;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
MoveItems(pos);
|
2019-07-24 03:08:08 +02:00
|
|
|
} else {
|
|
|
|
selectionBox = true;
|
|
|
|
if (!mouseMoved)
|
|
|
|
DoSelect(startPos);
|
|
|
|
BoxItems(startPos, pos);
|
2016-03-31 03:46:02 +02:00
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
mouseMoved = true;
|
2019-07-24 03:08:08 +02:00
|
|
|
mousePos = pos;
|
2019-02-08 08:58:40 +01:00
|
|
|
} else {
|
|
|
|
vec2 pos = GetMouseEventPos(event);
|
|
|
|
OBSSceneItem item = GetItemAtPos(pos, true);
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
std::lock_guard<std::mutex> lock(selectMutex);
|
|
|
|
hoveredPreviewItems.clear();
|
|
|
|
hoveredPreviewItems.push_back(item);
|
2020-02-15 09:44:07 +01:00
|
|
|
|
|
|
|
if (!mouseMoved && hoveredPreviewItems.size() > 0) {
|
|
|
|
mousePos = pos;
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(
|
|
|
|
App()->GetMainWindow());
|
2022-07-29 20:31:13 +02:00
|
|
|
float scale = main->GetDevicePixelRatio();
|
2022-07-19 16:12:17 +02:00
|
|
|
float x = qtPos.x() - main->previewX / scale;
|
|
|
|
float y = qtPos.y() - main->previewY / scale;
|
2020-02-15 09:44:07 +01:00
|
|
|
vec2_set(&startPos, x, y);
|
|
|
|
updateCursor = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateCursor) {
|
2021-03-09 11:15:17 +01:00
|
|
|
GetStretchHandleData(startPos, true);
|
2020-02-15 09:44:07 +01:00
|
|
|
uint32_t stretchFlags = (uint32_t)stretchHandle;
|
|
|
|
UpdateCursor(stretchFlags);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
void OBSBasicPreview::leaveEvent(QEvent *)
|
2019-02-08 08:58:40 +01:00
|
|
|
{
|
2019-07-24 03:08:08 +02:00
|
|
|
std::lock_guard<std::mutex> lock(selectMutex);
|
|
|
|
if (!selectionBox)
|
|
|
|
hoveredPreviewItems.clear();
|
2019-02-08 08:58:40 +01:00
|
|
|
}
|
|
|
|
|
2020-02-18 09:14:42 +01:00
|
|
|
static void DrawLine(float x1, float y1, float x2, float y2, float thickness,
|
|
|
|
vec2 scale)
|
|
|
|
{
|
|
|
|
float ySide = (y1 == y2) ? (y1 < 0.5f ? 1.0f : -1.0f) : 0.0f;
|
|
|
|
float xSide = (x1 == x2) ? (x1 < 0.5f ? 1.0f : -1.0f) : 0.0f;
|
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
|
|
|
|
gs_vertex2f(x1, y1);
|
|
|
|
gs_vertex2f(x1 + (xSide * (thickness / scale.x)),
|
|
|
|
y1 + (ySide * (thickness / scale.y)));
|
|
|
|
gs_vertex2f(x2 + (xSide * (thickness / scale.x)),
|
|
|
|
y2 + (ySide * (thickness / scale.y)));
|
|
|
|
gs_vertex2f(x2, y2);
|
|
|
|
gs_vertex2f(x1, y1);
|
|
|
|
|
|
|
|
gs_vertbuffer_t *line = gs_render_save();
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(line);
|
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
|
|
|
gs_vertexbuffer_destroy(line);
|
|
|
|
}
|
|
|
|
|
2022-07-29 20:31:13 +02:00
|
|
|
static void DrawSquareAtPos(float x, float y, float pixelRatio)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
|
|
|
struct vec3 pos;
|
|
|
|
vec3_set(&pos, x, y, 0.0f);
|
2018-06-02 18:20:00 +02:00
|
|
|
|
|
|
|
struct matrix4 matrix;
|
|
|
|
gs_matrix_get(&matrix);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
vec3_transform(&pos, &pos, &matrix);
|
|
|
|
|
|
|
|
gs_matrix_push();
|
2018-06-02 18:20:00 +02:00
|
|
|
gs_matrix_identity();
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
gs_matrix_translate(&pos);
|
2019-02-08 08:58:40 +01:00
|
|
|
|
2020-12-24 04:57:55 +01:00
|
|
|
gs_matrix_translate3f(-HANDLE_RADIUS * pixelRatio,
|
|
|
|
-HANDLE_RADIUS * pixelRatio, 0.0f);
|
|
|
|
gs_matrix_scale3f(HANDLE_RADIUS * pixelRatio * 2,
|
|
|
|
HANDLE_RADIUS * pixelRatio * 2, 1.0f);
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
|
|
|
|
2022-07-29 20:31:13 +02:00
|
|
|
static void DrawRotationHandle(gs_vertbuffer_t *circle, float rot,
|
2023-03-28 15:34:30 +02:00
|
|
|
float pixelRatio, bool invert)
|
2019-02-08 08:58:40 +01:00
|
|
|
{
|
2020-02-18 09:14:42 +01:00
|
|
|
struct vec3 pos;
|
2023-03-28 15:34:30 +02:00
|
|
|
vec3_set(&pos, 0.5f, invert ? 1.0f : 0.0f, 0.0f);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
|
|
|
struct matrix4 matrix;
|
|
|
|
gs_matrix_get(&matrix);
|
|
|
|
vec3_transform(&pos, &pos, &matrix);
|
2019-02-08 08:58:40 +01:00
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
|
2020-02-18 09:14:42 +01:00
|
|
|
gs_vertex2f(0.5f - 0.34f / HANDLE_RADIUS, 0.5f);
|
|
|
|
gs_vertex2f(0.5f - 0.34f / HANDLE_RADIUS, -2.0f);
|
|
|
|
gs_vertex2f(0.5f + 0.34f / HANDLE_RADIUS, -2.0f);
|
|
|
|
gs_vertex2f(0.5f + 0.34f / HANDLE_RADIUS, 0.5f);
|
|
|
|
gs_vertex2f(0.5f - 0.34f / HANDLE_RADIUS, 0.5f);
|
2019-02-08 08:58:40 +01:00
|
|
|
|
|
|
|
gs_vertbuffer_t *line = gs_render_save();
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(line);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_identity();
|
|
|
|
gs_matrix_translate(&pos);
|
|
|
|
|
|
|
|
gs_matrix_rotaa4f(0.0f, 0.0f, 1.0f, RAD(rot));
|
2020-12-24 04:57:55 +01:00
|
|
|
gs_matrix_translate3f(-HANDLE_RADIUS * 1.5 * pixelRatio,
|
|
|
|
-HANDLE_RADIUS * 1.5 * pixelRatio, 0.0f);
|
|
|
|
gs_matrix_scale3f(HANDLE_RADIUS * 3 * pixelRatio,
|
|
|
|
HANDLE_RADIUS * 3 * pixelRatio, 1.0f);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
|
|
|
gs_matrix_translate3f(0.0f, -HANDLE_RADIUS * 2 / 3, 0.0f);
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(circle);
|
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
|
|
|
|
|
|
|
gs_matrix_pop();
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_vertexbuffer_destroy(line);
|
|
|
|
}
|
|
|
|
|
2021-05-20 08:52:36 +02:00
|
|
|
static void DrawStripedLine(float x1, float y1, float x2, float y2,
|
|
|
|
float thickness, vec2 scale)
|
|
|
|
{
|
|
|
|
float ySide = (y1 == y2) ? (y1 < 0.5f ? 1.0f : -1.0f) : 0.0f;
|
|
|
|
float xSide = (x1 == x2) ? (x1 < 0.5f ? 1.0f : -1.0f) : 0.0f;
|
|
|
|
|
|
|
|
float dist =
|
|
|
|
sqrt(pow((x1 - x2) * scale.x, 2) + pow((y1 - y2) * scale.y, 2));
|
|
|
|
float offX = (x2 - x1) / dist;
|
|
|
|
float offY = (y2 - y1) / dist;
|
|
|
|
|
|
|
|
for (int i = 0, l = ceil(dist / 15); i < l; i++) {
|
|
|
|
gs_render_start(true);
|
|
|
|
|
|
|
|
float xx1 = x1 + i * 15 * offX;
|
|
|
|
float yy1 = y1 + i * 15 * offY;
|
|
|
|
|
|
|
|
float dx;
|
|
|
|
float dy;
|
|
|
|
|
|
|
|
if (x1 < x2) {
|
|
|
|
dx = std::min(xx1 + 7.5f * offX, x2);
|
|
|
|
} else {
|
|
|
|
dx = std::max(xx1 + 7.5f * offX, x2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y1 < y2) {
|
|
|
|
dy = std::min(yy1 + 7.5f * offY, y2);
|
|
|
|
} else {
|
|
|
|
dy = std::max(yy1 + 7.5f * offY, y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_vertex2f(xx1, yy1);
|
|
|
|
gs_vertex2f(xx1 + (xSide * (thickness / scale.x)),
|
|
|
|
yy1 + (ySide * (thickness / scale.y)));
|
|
|
|
gs_vertex2f(dx, dy);
|
|
|
|
gs_vertex2f(dx + (xSide * (thickness / scale.x)),
|
|
|
|
dy + (ySide * (thickness / scale.y)));
|
|
|
|
|
|
|
|
gs_vertbuffer_t *line = gs_render_save();
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(line);
|
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
|
|
|
gs_vertexbuffer_destroy(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 15:35:42 +02:00
|
|
|
static void DrawRect(float thickness, vec2 scale)
|
2019-02-08 08:58:40 +01:00
|
|
|
{
|
|
|
|
gs_render_start(true);
|
|
|
|
|
|
|
|
gs_vertex2f(0.0f, 0.0f);
|
2019-04-19 15:35:42 +02:00
|
|
|
gs_vertex2f(0.0f + (thickness / scale.x), 0.0f);
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_vertex2f(0.0f, 1.0f);
|
2020-03-19 11:25:24 +01:00
|
|
|
gs_vertex2f(0.0f + (thickness / scale.x), 1.0f);
|
2019-04-19 15:35:42 +02:00
|
|
|
gs_vertex2f(0.0f, 1.0f - (thickness / scale.y));
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_vertex2f(1.0f, 1.0f);
|
2020-03-19 11:25:24 +01:00
|
|
|
gs_vertex2f(1.0f, 1.0f - (thickness / scale.y));
|
2019-04-19 15:35:42 +02:00
|
|
|
gs_vertex2f(1.0f - (thickness / scale.x), 1.0f);
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_vertex2f(1.0f, 0.0f);
|
2020-03-19 11:25:24 +01:00
|
|
|
gs_vertex2f(1.0f - (thickness / scale.x), 0.0f);
|
2019-04-19 15:35:42 +02:00
|
|
|
gs_vertex2f(1.0f, 0.0f + (thickness / scale.y));
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_vertex2f(0.0f, 0.0f);
|
2020-03-19 11:25:24 +01:00
|
|
|
gs_vertex2f(0.0f, 0.0f + (thickness / scale.y));
|
2019-02-08 08:58:40 +01:00
|
|
|
|
|
|
|
gs_vertbuffer_t *rect = gs_render_save();
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(rect);
|
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
|
|
|
gs_vertexbuffer_destroy(rect);
|
|
|
|
}
|
|
|
|
|
2016-03-31 03:46:02 +02:00
|
|
|
static inline bool crop_enabled(const obs_sceneitem_crop *crop)
|
|
|
|
{
|
|
|
|
return crop->left > 0 || crop->top > 0 || crop->right > 0 ||
|
|
|
|
crop->bottom > 0;
|
|
|
|
}
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
bool OBSBasicPreview::DrawSelectedOverflow(obs_scene_t *, obs_sceneitem_t *item,
|
|
|
|
void *param)
|
2019-01-15 02:58:20 +01:00
|
|
|
{
|
|
|
|
if (obs_sceneitem_locked(item))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!SceneItemHasVideo(item))
|
|
|
|
return true;
|
|
|
|
|
2023-02-10 13:27:08 +01:00
|
|
|
OBSBasicPreview *prev = reinterpret_cast<OBSBasicPreview *>(param);
|
2019-01-15 02:58:20 +01:00
|
|
|
|
2023-02-10 13:27:08 +01:00
|
|
|
if (!prev->GetOverflowSelectionHidden() && !obs_sceneitem_visible(item))
|
2019-01-15 02:58:20 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (obs_sceneitem_is_group(item)) {
|
|
|
|
matrix4 mat;
|
|
|
|
obs_sceneitem_get_draw_transform(item, &mat);
|
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_mul(&mat);
|
|
|
|
obs_sceneitem_group_enum_items(item, DrawSelectedOverflow,
|
|
|
|
param);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
|
|
|
|
2023-02-10 13:27:08 +01:00
|
|
|
if (!prev->GetOverflowAlwaysVisible() && !obs_sceneitem_selected(item))
|
2019-01-15 02:58:20 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
matrix4 boxTransform;
|
|
|
|
matrix4 invBoxTransform;
|
|
|
|
obs_sceneitem_get_box_transform(item, &boxTransform);
|
|
|
|
matrix4_inv(&invBoxTransform, &boxTransform);
|
|
|
|
|
|
|
|
vec3 bounds[] = {
|
|
|
|
{{{0.f, 0.f, 0.f}}},
|
|
|
|
{{{1.f, 0.f, 0.f}}},
|
|
|
|
{{{0.f, 1.f, 0.f}}},
|
|
|
|
{{{1.f, 1.f, 0.f}}},
|
|
|
|
};
|
|
|
|
|
|
|
|
bool visible = std::all_of(
|
|
|
|
std::begin(bounds), std::end(bounds), [&](const vec3 &b) {
|
|
|
|
vec3 pos;
|
|
|
|
vec3_transform(&pos, &b, &boxTransform);
|
|
|
|
vec3_transform(&pos, &pos, &invBoxTransform);
|
|
|
|
return CloseFloat(pos.x, b.x) && CloseFloat(pos.y, b.y);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!visible)
|
|
|
|
return true;
|
|
|
|
|
2019-04-03 08:23:37 +02:00
|
|
|
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_DEFAULT, "DrawSelectedOverflow");
|
|
|
|
|
2019-01-15 02:58:20 +01:00
|
|
|
obs_transform_info info;
|
|
|
|
obs_sceneitem_get_info(item, &info);
|
|
|
|
|
|
|
|
gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_REPEAT);
|
|
|
|
gs_eparam_t *image = gs_effect_get_param_by_name(solid, "image");
|
|
|
|
gs_eparam_t *scale = gs_effect_get_param_by_name(solid, "scale");
|
|
|
|
|
|
|
|
vec2 s;
|
|
|
|
vec2_set(&s, boxTransform.x.x / 96, boxTransform.y.y / 96);
|
|
|
|
|
|
|
|
gs_effect_set_vec2(scale, &s);
|
|
|
|
gs_effect_set_texture(image, prev->overflow);
|
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_mul(&boxTransform);
|
|
|
|
|
|
|
|
obs_sceneitem_crop crop;
|
|
|
|
obs_sceneitem_get_crop(item, &crop);
|
|
|
|
|
|
|
|
while (gs_effect_loop(solid, "Draw")) {
|
|
|
|
gs_draw_sprite(prev->overflow, 0, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_matrix_pop();
|
|
|
|
|
2019-04-03 08:23:37 +02:00
|
|
|
GS_DEBUG_MARKER_END();
|
|
|
|
|
2019-01-15 02:58:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-29 03:42:41 +01:00
|
|
|
bool OBSBasicPreview::DrawSelectedItem(obs_scene_t *, obs_sceneitem_t *item,
|
|
|
|
void *param)
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
{
|
2017-06-18 02:10:42 +02:00
|
|
|
if (obs_sceneitem_locked(item))
|
|
|
|
return true;
|
|
|
|
|
2018-01-18 05:25:57 +01:00
|
|
|
if (!SceneItemHasVideo(item))
|
|
|
|
return true;
|
|
|
|
|
2020-02-18 09:14:42 +01:00
|
|
|
OBSBasicPreview *prev = reinterpret_cast<OBSBasicPreview *>(param);
|
|
|
|
|
2018-06-02 18:45:01 +02:00
|
|
|
if (obs_sceneitem_is_group(item)) {
|
|
|
|
matrix4 mat;
|
2020-02-18 09:14:42 +01:00
|
|
|
obs_transform_info groupInfo;
|
2018-06-02 18:45:01 +02:00
|
|
|
obs_sceneitem_get_draw_transform(item, &mat);
|
2020-02-18 09:14:42 +01:00
|
|
|
obs_sceneitem_get_info(item, &groupInfo);
|
|
|
|
|
|
|
|
prev->groupRot = groupInfo.rot;
|
2018-06-02 18:45:01 +02:00
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_mul(&mat);
|
2020-02-18 09:14:42 +01:00
|
|
|
obs_sceneitem_group_enum_items(item, DrawSelectedItem, prev);
|
2018-06-02 18:45:01 +02:00
|
|
|
gs_matrix_pop();
|
2020-02-18 09:14:42 +01:00
|
|
|
|
|
|
|
prev->groupRot = 0.0f;
|
2018-06-02 18:45:01 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 00:27:38 +01:00
|
|
|
OBSBasic *main = OBSBasic::Get();
|
2019-02-08 08:58:40 +01:00
|
|
|
|
2022-07-29 20:31:13 +02:00
|
|
|
float pixelRatio = main->GetDevicePixelRatio();
|
2020-12-24 04:57:55 +01:00
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
bool hovered = false;
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(prev->selectMutex);
|
2019-10-10 07:24:55 +02:00
|
|
|
for (size_t i = 0; i < prev->hoveredPreviewItems.size(); i++) {
|
2019-07-24 03:08:08 +02:00
|
|
|
if (prev->hoveredPreviewItems[i] == item) {
|
|
|
|
hovered = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 08:58:40 +01:00
|
|
|
bool selected = obs_sceneitem_selected(item);
|
|
|
|
|
2019-02-12 00:27:38 +01:00
|
|
|
if (!selected && !hovered)
|
2019-02-08 08:58:40 +01:00
|
|
|
return true;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
matrix4 boxTransform;
|
2014-10-14 02:42:30 +02:00
|
|
|
matrix4 invBoxTransform;
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
obs_sceneitem_get_box_transform(item, &boxTransform);
|
2014-10-14 02:42:30 +02:00
|
|
|
matrix4_inv(&invBoxTransform, &boxTransform);
|
|
|
|
|
|
|
|
vec3 bounds[] = {
|
|
|
|
{{{0.f, 0.f, 0.f}}},
|
|
|
|
{{{1.f, 0.f, 0.f}}},
|
|
|
|
{{{0.f, 1.f, 0.f}}},
|
|
|
|
{{{1.f, 1.f, 0.f}}},
|
|
|
|
};
|
|
|
|
|
2021-07-03 07:55:47 +02:00
|
|
|
main->GetCameraIcon();
|
|
|
|
|
|
|
|
QColor selColor = main->GetSelectionColor();
|
|
|
|
QColor cropColor = main->GetCropColor();
|
|
|
|
QColor hoverColor = main->GetHoverColor();
|
|
|
|
|
2019-02-08 08:58:40 +01:00
|
|
|
vec4 red;
|
|
|
|
vec4 green;
|
|
|
|
vec4 blue;
|
|
|
|
|
2021-07-03 07:55:47 +02:00
|
|
|
vec4_set(&red, selColor.redF(), selColor.greenF(), selColor.blueF(),
|
|
|
|
1.0f);
|
|
|
|
vec4_set(&green, cropColor.redF(), cropColor.greenF(),
|
|
|
|
cropColor.blueF(), 1.0f);
|
|
|
|
vec4_set(&blue, hoverColor.redF(), hoverColor.greenF(),
|
|
|
|
hoverColor.blueF(), 1.0f);
|
2019-02-08 08:58:40 +01:00
|
|
|
|
2014-10-14 02:42:30 +02:00
|
|
|
bool visible = std::all_of(
|
|
|
|
std::begin(bounds), std::end(bounds), [&](const vec3 &b) {
|
|
|
|
vec3 pos;
|
|
|
|
vec3_transform(&pos, &b, &boxTransform);
|
|
|
|
vec3_transform(&pos, &pos, &invBoxTransform);
|
|
|
|
return CloseFloat(pos.x, b.x) && CloseFloat(pos.y, b.y);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!visible)
|
|
|
|
return true;
|
|
|
|
|
2019-04-03 08:23:37 +02:00
|
|
|
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_DEFAULT, "DrawSelectedItem");
|
|
|
|
|
2019-04-19 15:35:42 +02:00
|
|
|
matrix4 curTransform;
|
|
|
|
vec2 boxScale;
|
|
|
|
gs_matrix_get(&curTransform);
|
|
|
|
obs_sceneitem_get_box_scale(item, &boxScale);
|
|
|
|
boxScale.x *= curTransform.x.x;
|
|
|
|
boxScale.y *= curTransform.y.y;
|
|
|
|
|
2016-03-31 03:46:02 +02:00
|
|
|
obs_transform_info info;
|
|
|
|
obs_sceneitem_get_info(item, &info);
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
gs_matrix_push();
|
2014-08-20 21:38:53 +02:00
|
|
|
gs_matrix_mul(&boxTransform);
|
2016-03-31 03:44:49 +02:00
|
|
|
|
|
|
|
obs_sceneitem_crop crop;
|
|
|
|
obs_sceneitem_get_crop(item, &crop);
|
|
|
|
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_effect_t *eff = gs_get_effect();
|
|
|
|
gs_eparam_t *colParam = gs_effect_get_param_by_name(eff, "color");
|
|
|
|
|
2021-07-03 07:55:47 +02:00
|
|
|
gs_effect_set_vec4(colParam, &red);
|
|
|
|
|
2016-03-31 03:44:49 +02:00
|
|
|
if (info.bounds_type == OBS_BOUNDS_NONE && crop_enabled(&crop)) {
|
2020-12-24 04:57:55 +01:00
|
|
|
#define DRAW_SIDE(side, x1, y1, x2, y2) \
|
|
|
|
if (hovered && !selected) { \
|
|
|
|
gs_effect_set_vec4(colParam, &blue); \
|
|
|
|
DrawLine(x1, y1, x2, y2, HANDLE_RADIUS *pixelRatio / 2, \
|
|
|
|
boxScale); \
|
|
|
|
} else if (crop.side > 0) { \
|
|
|
|
gs_effect_set_vec4(colParam, &green); \
|
|
|
|
DrawStripedLine(x1, y1, x2, y2, HANDLE_RADIUS *pixelRatio / 2, \
|
|
|
|
boxScale); \
|
|
|
|
} else { \
|
|
|
|
DrawLine(x1, y1, x2, y2, HANDLE_RADIUS *pixelRatio / 2, \
|
|
|
|
boxScale); \
|
|
|
|
} \
|
2019-02-08 08:58:40 +01:00
|
|
|
gs_effect_set_vec4(colParam, &red);
|
2019-06-23 07:13:45 +02:00
|
|
|
|
2019-02-08 08:58:40 +01:00
|
|
|
DRAW_SIDE(left, 0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
DRAW_SIDE(top, 0.0f, 0.0f, 1.0f, 0.0f);
|
|
|
|
DRAW_SIDE(right, 1.0f, 0.0f, 1.0f, 1.0f);
|
|
|
|
DRAW_SIDE(bottom, 0.0f, 1.0f, 1.0f, 1.0f);
|
2016-03-31 03:44:49 +02:00
|
|
|
#undef DRAW_SIDE
|
|
|
|
} else {
|
2019-02-08 08:58:40 +01:00
|
|
|
if (!selected) {
|
|
|
|
gs_effect_set_vec4(colParam, &blue);
|
2020-12-24 04:57:55 +01:00
|
|
|
DrawRect(HANDLE_RADIUS * pixelRatio / 2, boxScale);
|
2019-02-08 08:58:40 +01:00
|
|
|
} else {
|
2020-12-24 04:57:55 +01:00
|
|
|
DrawRect(HANDLE_RADIUS * pixelRatio / 2, boxScale);
|
2019-02-08 08:58:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(main->box);
|
|
|
|
gs_effect_set_vec4(colParam, &red);
|
|
|
|
|
|
|
|
if (selected) {
|
2022-07-29 20:31:13 +02:00
|
|
|
DrawSquareAtPos(0.0f, 0.0f, pixelRatio);
|
|
|
|
DrawSquareAtPos(0.0f, 1.0f, pixelRatio);
|
|
|
|
DrawSquareAtPos(1.0f, 0.0f, pixelRatio);
|
|
|
|
DrawSquareAtPos(1.0f, 1.0f, pixelRatio);
|
|
|
|
DrawSquareAtPos(0.5f, 0.0f, pixelRatio);
|
|
|
|
DrawSquareAtPos(0.0f, 0.5f, pixelRatio);
|
|
|
|
DrawSquareAtPos(0.5f, 1.0f, pixelRatio);
|
|
|
|
DrawSquareAtPos(1.0f, 0.5f, pixelRatio);
|
2020-02-18 09:14:42 +01:00
|
|
|
|
|
|
|
if (!prev->circleFill) {
|
|
|
|
gs_render_start(true);
|
|
|
|
|
|
|
|
float angle = 180;
|
|
|
|
for (int i = 0, l = 40; i < l; i++) {
|
|
|
|
gs_vertex2f(sin(RAD(angle)) / 2 + 0.5f,
|
|
|
|
cos(RAD(angle)) / 2 + 0.5f);
|
|
|
|
angle += 360 / l;
|
|
|
|
gs_vertex2f(sin(RAD(angle)) / 2 + 0.5f,
|
|
|
|
cos(RAD(angle)) / 2 + 0.5f);
|
|
|
|
gs_vertex2f(0.5f, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
prev->circleFill = gs_render_save();
|
|
|
|
}
|
|
|
|
|
2023-07-07 04:25:23 +02:00
|
|
|
bool invert = info.scale.y < 0.0f &&
|
|
|
|
info.bounds_type == OBS_BOUNDS_NONE;
|
2022-07-29 20:31:13 +02:00
|
|
|
DrawRotationHandle(prev->circleFill, info.rot + prev->groupRot,
|
2023-03-28 15:34:30 +02:00
|
|
|
pixelRatio, invert);
|
2016-03-31 03:44:49 +02:00
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
gs_matrix_pop();
|
|
|
|
|
2019-04-03 08:23:37 +02:00
|
|
|
GS_DEBUG_MARKER_END();
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
bool OBSBasicPreview::DrawSelectionBox(float x1, float y1, float x2, float y2,
|
|
|
|
gs_vertbuffer_t *rectFill)
|
|
|
|
{
|
2020-12-24 04:57:55 +01:00
|
|
|
OBSBasic *main = OBSBasic::Get();
|
|
|
|
|
2022-07-29 20:31:13 +02:00
|
|
|
float pixelRatio = main->GetDevicePixelRatio();
|
2020-12-24 04:57:55 +01:00
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
x1 = std::round(x1);
|
|
|
|
x2 = std::round(x2);
|
|
|
|
y1 = std::round(y1);
|
|
|
|
y2 = std::round(y2);
|
|
|
|
|
|
|
|
gs_effect_t *eff = gs_get_effect();
|
|
|
|
gs_eparam_t *colParam = gs_effect_get_param_by_name(eff, "color");
|
|
|
|
|
|
|
|
vec4 fillColor;
|
|
|
|
vec4_set(&fillColor, 0.7f, 0.7f, 0.7f, 0.5f);
|
|
|
|
|
|
|
|
vec4 borderColor;
|
|
|
|
vec4_set(&borderColor, 1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
vec2 scale;
|
|
|
|
vec2_set(&scale, std::abs(x2 - x1), std::abs(y2 - y1));
|
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_identity();
|
|
|
|
|
|
|
|
gs_matrix_translate3f(x1, y1, 0.0f);
|
|
|
|
gs_matrix_scale3f(x2 - x1, y2 - y1, 1.0f);
|
|
|
|
|
|
|
|
gs_effect_set_vec4(colParam, &fillColor);
|
|
|
|
gs_load_vertexbuffer(rectFill);
|
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
|
|
|
|
|
|
|
gs_effect_set_vec4(colParam, &borderColor);
|
2020-12-24 04:57:55 +01:00
|
|
|
DrawRect(HANDLE_RADIUS * pixelRatio / 2, scale);
|
2019-07-24 03:08:08 +02:00
|
|
|
|
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-15 02:58:20 +01:00
|
|
|
void OBSBasicPreview::DrawOverflow()
|
|
|
|
{
|
|
|
|
if (locked)
|
|
|
|
return;
|
|
|
|
|
2023-02-10 13:27:08 +01:00
|
|
|
if (overflowHidden)
|
2019-01-15 02:58:20 +01:00
|
|
|
return;
|
|
|
|
|
2019-04-03 08:23:37 +02:00
|
|
|
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_DEFAULT, "DrawOverflow");
|
|
|
|
|
2019-01-15 02:58:20 +01:00
|
|
|
if (!overflow) {
|
|
|
|
std::string path;
|
|
|
|
GetDataFilePath("images/overflow.png", path);
|
|
|
|
overflow = gs_texture_create_from_file(path.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
|
|
|
|
|
|
|
if (scene) {
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_scale3f(main->previewScale, main->previewScale, 1.0f);
|
|
|
|
obs_scene_enum_items(scene, DrawSelectedOverflow, this);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(nullptr);
|
2019-04-03 08:23:37 +02:00
|
|
|
|
|
|
|
GS_DEBUG_MARKER_END();
|
2019-01-15 02:58:20 +01:00
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
void OBSBasicPreview::DrawSceneEditing()
|
|
|
|
{
|
2016-07-26 10:32:43 +02:00
|
|
|
if (locked)
|
|
|
|
return;
|
|
|
|
|
2019-04-03 08:23:37 +02:00
|
|
|
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_DEFAULT, "DrawSceneEditing");
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
|
2015-10-16 16:31:52 +02:00
|
|
|
gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
|
2014-09-26 02:44:05 +02:00
|
|
|
gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2014-08-08 08:42:07 +02:00
|
|
|
gs_technique_begin(tech);
|
|
|
|
gs_technique_begin_pass(tech, 0);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
|
|
|
OBSScene scene = main->GetCurrentScene();
|
2017-06-18 02:10:42 +02:00
|
|
|
|
2018-06-02 18:20:00 +02:00
|
|
|
if (scene) {
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_scale3f(main->previewScale, main->previewScale, 1.0f);
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
obs_scene_enum_items(scene, DrawSelectedItem, this);
|
2018-06-02 18:20:00 +02:00
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
|
2019-07-24 03:08:08 +02:00
|
|
|
if (selectionBox) {
|
|
|
|
if (!rectFill) {
|
|
|
|
gs_render_start(true);
|
|
|
|
|
|
|
|
gs_vertex2f(0.0f, 0.0f);
|
|
|
|
gs_vertex2f(1.0f, 0.0f);
|
|
|
|
gs_vertex2f(0.0f, 1.0f);
|
2020-03-19 11:25:24 +01:00
|
|
|
gs_vertex2f(1.0f, 1.0f);
|
2019-07-24 03:08:08 +02:00
|
|
|
|
|
|
|
rectFill = gs_render_save();
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawSelectionBox(startPos.x * main->previewScale,
|
|
|
|
startPos.y * main->previewScale,
|
|
|
|
mousePos.x * main->previewScale,
|
|
|
|
mousePos.y * main->previewScale, rectFill);
|
|
|
|
}
|
|
|
|
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
gs_load_vertexbuffer(nullptr);
|
|
|
|
|
2014-08-08 08:42:07 +02:00
|
|
|
gs_technique_end_pass(tech);
|
|
|
|
gs_technique_end(tech);
|
2019-04-03 08:23:37 +02:00
|
|
|
|
|
|
|
GS_DEBUG_MARKER_END();
|
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.
2014-06-15 09:54:48 +02:00
|
|
|
}
|
2016-11-05 17:48:46 +01:00
|
|
|
|
|
|
|
void OBSBasicPreview::ResetScrollingOffset()
|
|
|
|
{
|
|
|
|
vec2_zero(&scrollingOffset);
|
|
|
|
}
|
2017-05-13 19:13:55 +02:00
|
|
|
|
|
|
|
void OBSBasicPreview::SetScalingLevel(int32_t newScalingLevelVal)
|
|
|
|
{
|
2023-02-13 23:14:57 +01:00
|
|
|
newScalingLevelVal = std::clamp(newScalingLevelVal, -MAX_SCALING_LEVEL,
|
|
|
|
MAX_SCALING_LEVEL);
|
2017-05-13 19:13:55 +02:00
|
|
|
float newScalingAmountVal =
|
|
|
|
pow(ZOOM_SENSITIVITY, float(newScalingLevelVal));
|
|
|
|
scalingLevel = newScalingLevelVal;
|
|
|
|
SetScalingAmount(newScalingAmountVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::SetScalingAmount(float newScalingAmountVal)
|
|
|
|
{
|
|
|
|
scrollingOffset.x *= newScalingAmountVal / scalingAmount;
|
|
|
|
scrollingOffset.y *= newScalingAmountVal / scalingAmount;
|
|
|
|
scalingAmount = newScalingAmountVal;
|
2018-06-02 18:26:18 +02:00
|
|
|
}
|
2019-02-12 00:25:42 +01:00
|
|
|
|
|
|
|
OBSBasicPreview *OBSBasicPreview::Get()
|
|
|
|
{
|
|
|
|
return OBSBasic::Get()->ui->preview;
|
|
|
|
}
|
2021-11-01 08:16:56 +01:00
|
|
|
|
2022-08-03 16:47:25 +02:00
|
|
|
static obs_source_t *CreateLabel(float pixelRatio)
|
2021-11-01 08:16:56 +01:00
|
|
|
{
|
|
|
|
OBSDataAutoRelease settings = obs_data_create();
|
|
|
|
OBSDataAutoRelease font = obs_data_create();
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
obs_data_set_string(font, "face", "Arial");
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
obs_data_set_string(font, "face", "Helvetica");
|
|
|
|
#else
|
|
|
|
obs_data_set_string(font, "face", "Monospace");
|
|
|
|
#endif
|
|
|
|
obs_data_set_int(font, "flags", 1); // Bold text
|
2022-08-03 16:47:25 +02:00
|
|
|
obs_data_set_int(font, "size", 16 * pixelRatio);
|
2021-11-01 08:16:56 +01:00
|
|
|
|
|
|
|
obs_data_set_obj(settings, "font", font);
|
|
|
|
obs_data_set_bool(settings, "outline", true);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
obs_data_set_int(settings, "outline_color", 0x000000);
|
|
|
|
obs_data_set_int(settings, "outline_size", 3);
|
|
|
|
const char *text_source_id = "text_gdiplus";
|
|
|
|
#else
|
|
|
|
const char *text_source_id = "text_ft2_source";
|
|
|
|
#endif
|
|
|
|
|
2023-03-18 04:56:50 +01:00
|
|
|
return obs_source_create_private(text_source_id, NULL, settings);
|
2021-11-01 08:16:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SetLabelText(int sourceIndex, int px)
|
|
|
|
{
|
|
|
|
OBSBasicPreview *prev = OBSBasicPreview::Get();
|
|
|
|
|
|
|
|
if (px == prev->spacerPx[sourceIndex])
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string text = std::to_string(px) + " px";
|
|
|
|
|
|
|
|
obs_source_t *source = prev->spacerLabel[sourceIndex];
|
|
|
|
|
|
|
|
OBSDataAutoRelease settings = obs_source_get_settings(source);
|
|
|
|
obs_data_set_string(settings, "text", text.c_str());
|
|
|
|
obs_source_update(source, settings);
|
|
|
|
|
|
|
|
prev->spacerPx[sourceIndex] = px;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawLabel(OBSSource source, vec3 &pos, vec3 &viewport)
|
|
|
|
{
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vec3_mul(&pos, &pos, &viewport);
|
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_identity();
|
|
|
|
gs_matrix_translate(&pos);
|
|
|
|
obs_source_video_render(source);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
|
|
|
|
2022-08-03 16:47:25 +02:00
|
|
|
static void DrawSpacingLine(vec3 &start, vec3 &end, vec3 &viewport,
|
|
|
|
float pixelRatio)
|
2021-11-01 08:16:56 +01:00
|
|
|
{
|
2022-08-04 04:28:02 +02:00
|
|
|
OBSBasic *main = OBSBasic::Get();
|
|
|
|
|
2021-11-01 08:16:56 +01:00
|
|
|
matrix4 transform;
|
|
|
|
matrix4_identity(&transform);
|
|
|
|
transform.x.x = viewport.x;
|
|
|
|
transform.y.y = viewport.y;
|
|
|
|
|
|
|
|
gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
|
|
|
|
gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
|
|
|
|
|
2022-08-04 04:28:02 +02:00
|
|
|
QColor selColor = main->GetSelectionColor();
|
2021-11-01 08:16:56 +01:00
|
|
|
vec4 color;
|
2022-08-04 04:28:02 +02:00
|
|
|
vec4_set(&color, selColor.redF(), selColor.greenF(), selColor.blueF(),
|
|
|
|
1.0f);
|
|
|
|
|
2021-11-01 08:16:56 +01:00
|
|
|
gs_effect_set_vec4(gs_effect_get_param_by_name(solid, "color"), &color);
|
|
|
|
|
|
|
|
gs_technique_begin(tech);
|
|
|
|
gs_technique_begin_pass(tech, 0);
|
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_mul(&transform);
|
|
|
|
|
|
|
|
vec2 scale;
|
|
|
|
vec2_set(&scale, viewport.x, viewport.y);
|
|
|
|
|
2022-08-03 16:47:25 +02:00
|
|
|
DrawLine(start.x, start.y, end.x, end.y,
|
|
|
|
pixelRatio * (HANDLE_RADIUS / 2), scale);
|
2021-11-01 08:16:56 +01:00
|
|
|
|
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(nullptr);
|
|
|
|
|
|
|
|
gs_technique_end_pass(tech);
|
|
|
|
gs_technique_end(tech);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RenderSpacingHelper(int sourceIndex, vec3 &start, vec3 &end,
|
2022-08-03 16:47:25 +02:00
|
|
|
vec3 &viewport, float pixelRatio)
|
2021-11-01 08:16:56 +01:00
|
|
|
{
|
|
|
|
bool horizontal = (sourceIndex == 2 || sourceIndex == 3);
|
|
|
|
|
|
|
|
// If outside of preview, don't render
|
|
|
|
if (!((horizontal && (end.x >= start.x)) ||
|
|
|
|
(!horizontal && (end.y >= start.y))))
|
|
|
|
return;
|
|
|
|
|
|
|
|
float length = vec3_dist(&start, &end);
|
|
|
|
|
|
|
|
obs_video_info ovi;
|
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
|
|
|
|
float px;
|
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
px = length * ovi.base_width;
|
|
|
|
} else {
|
|
|
|
px = length * ovi.base_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (px <= 0.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OBSBasicPreview *prev = OBSBasicPreview::Get();
|
|
|
|
obs_source_t *source = prev->spacerLabel[sourceIndex];
|
|
|
|
vec3 labelSize, labelPos;
|
|
|
|
vec3_set(&labelSize, obs_source_get_width(source),
|
|
|
|
obs_source_get_height(source), 1.0f);
|
|
|
|
|
|
|
|
vec3_div(&labelSize, &labelSize, &viewport);
|
|
|
|
|
|
|
|
vec3 labelMargin;
|
2022-08-03 16:47:25 +02:00
|
|
|
vec3_set(&labelMargin, SPACER_LABEL_MARGIN * pixelRatio,
|
|
|
|
SPACER_LABEL_MARGIN * pixelRatio, 1.0f);
|
2021-11-01 08:16:56 +01:00
|
|
|
vec3_div(&labelMargin, &labelMargin, &viewport);
|
|
|
|
|
|
|
|
vec3_set(&labelPos, end.x, end.y, end.z);
|
|
|
|
if (horizontal) {
|
|
|
|
labelPos.x -= (end.x - start.x) / 2;
|
|
|
|
labelPos.x -= labelSize.x / 2;
|
|
|
|
labelPos.y -= labelMargin.y + (labelSize.y / 2) +
|
|
|
|
(HANDLE_RADIUS / viewport.y);
|
|
|
|
} else {
|
|
|
|
labelPos.y -= (end.y - start.y) / 2;
|
|
|
|
labelPos.y -= labelSize.y / 2;
|
|
|
|
labelPos.x += labelMargin.x;
|
|
|
|
}
|
|
|
|
|
2022-08-03 16:47:25 +02:00
|
|
|
DrawSpacingLine(start, end, viewport, pixelRatio);
|
2021-11-01 08:16:56 +01:00
|
|
|
SetLabelText(sourceIndex, (int)px);
|
|
|
|
DrawLabel(source, labelPos, viewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicPreview::DrawSpacingHelpers()
|
|
|
|
{
|
|
|
|
if (locked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OBSBasic *main = OBSBasic::Get();
|
|
|
|
|
2022-10-11 17:31:24 +02:00
|
|
|
vec2 s;
|
|
|
|
SceneFindBoxData data(s, s);
|
|
|
|
|
|
|
|
obs_scene_enum_items(main->GetCurrentScene(), FindSelected, &data);
|
|
|
|
|
2023-08-14 18:09:05 +02:00
|
|
|
if (data.sceneItems.size() != 1)
|
2021-11-01 08:16:56 +01:00
|
|
|
return;
|
|
|
|
|
2023-08-14 18:09:05 +02:00
|
|
|
OBSSceneItem item = data.sceneItems[0];
|
2021-11-01 08:16:56 +01:00
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (obs_sceneitem_locked(item))
|
|
|
|
return;
|
|
|
|
|
|
|
|
vec2 itemSize = GetItemSize(item);
|
|
|
|
if (itemSize.x == 0.0f || itemSize.y == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2022-08-10 13:09:49 +02:00
|
|
|
obs_sceneitem_t *parentGroup =
|
|
|
|
obs_sceneitem_get_group(main->GetCurrentScene(), item);
|
|
|
|
|
|
|
|
if (parentGroup && obs_sceneitem_locked(parentGroup))
|
|
|
|
return;
|
|
|
|
|
2021-11-01 08:16:56 +01:00
|
|
|
matrix4 boxTransform;
|
|
|
|
obs_sceneitem_get_box_transform(item, &boxTransform);
|
|
|
|
|
|
|
|
obs_transform_info oti;
|
|
|
|
obs_sceneitem_get_info(item, &oti);
|
|
|
|
|
|
|
|
obs_video_info ovi;
|
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
|
|
|
|
vec3 size;
|
|
|
|
vec3_set(&size, ovi.base_width, ovi.base_height, 1.0f);
|
|
|
|
|
|
|
|
// Init box transform side locations
|
|
|
|
vec3 left, right, top, bottom;
|
|
|
|
|
|
|
|
vec3_set(&left, 0.0f, 0.5f, 1.0f);
|
|
|
|
vec3_set(&right, 1.0f, 0.5f, 1.0f);
|
|
|
|
vec3_set(&top, 0.5f, 0.0f, 1.0f);
|
|
|
|
vec3_set(&bottom, 0.5f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
// Decide which side to use with box transform, based on rotation
|
|
|
|
// Seems hacky, probably a better way to do it
|
|
|
|
float rot = oti.rot;
|
|
|
|
|
2022-08-10 17:06:25 +02:00
|
|
|
if (parentGroup) {
|
|
|
|
obs_transform_info groupOti;
|
|
|
|
obs_sceneitem_get_info(parentGroup, &groupOti);
|
|
|
|
|
|
|
|
//Correct the scene item rotation angle
|
|
|
|
rot = oti.rot + groupOti.rot;
|
|
|
|
|
|
|
|
// Correct the scene item box transform
|
|
|
|
// Based on scale, rotation angle, position of parent's group
|
|
|
|
matrix4_scale3f(&boxTransform, &boxTransform, groupOti.scale.x,
|
|
|
|
groupOti.scale.y, 1.0f);
|
|
|
|
matrix4_rotate_aa4f(&boxTransform, &boxTransform, 0.0f, 0.0f,
|
|
|
|
1.0f, RAD(groupOti.rot));
|
|
|
|
matrix4_translate3f(&boxTransform, &boxTransform,
|
|
|
|
groupOti.pos.x, groupOti.pos.y, 0.0f);
|
|
|
|
}
|
|
|
|
|
2023-03-04 07:57:58 +01:00
|
|
|
// Switch top/bottom or right/left if scale is negative
|
2023-07-07 04:47:17 +02:00
|
|
|
if (oti.scale.x < 0.0f && oti.bounds_type == OBS_BOUNDS_NONE) {
|
2023-03-04 07:57:58 +01:00
|
|
|
vec3 l = left;
|
|
|
|
vec3 r = right;
|
|
|
|
|
|
|
|
vec3_copy(&left, &r);
|
|
|
|
vec3_copy(&right, &l);
|
|
|
|
}
|
|
|
|
|
2023-07-07 04:47:17 +02:00
|
|
|
if (oti.scale.y < 0.0f && oti.bounds_type == OBS_BOUNDS_NONE) {
|
2023-03-04 07:57:58 +01:00
|
|
|
vec3 t = top;
|
|
|
|
vec3 b = bottom;
|
|
|
|
|
|
|
|
vec3_copy(&top, &b);
|
|
|
|
vec3_copy(&bottom, &t);
|
|
|
|
}
|
|
|
|
|
2023-07-07 04:47:17 +02:00
|
|
|
if (rot >= HELPER_ROT_BREAKPOINT) {
|
|
|
|
for (float i = HELPER_ROT_BREAKPOINT; i <= 360.0f; i += 90.0f) {
|
2021-11-01 08:16:56 +01:00
|
|
|
if (rot < i)
|
|
|
|
break;
|
|
|
|
|
|
|
|
vec3 l = left;
|
|
|
|
vec3 r = right;
|
|
|
|
vec3 t = top;
|
|
|
|
vec3 b = bottom;
|
|
|
|
|
|
|
|
vec3_copy(&top, &l);
|
|
|
|
vec3_copy(&right, &t);
|
|
|
|
vec3_copy(&bottom, &r);
|
|
|
|
vec3_copy(&left, &b);
|
|
|
|
}
|
2023-07-07 04:47:17 +02:00
|
|
|
} else if (rot <= -HELPER_ROT_BREAKPOINT) {
|
|
|
|
for (float i = -HELPER_ROT_BREAKPOINT; i >= -360.0f;
|
2021-11-01 08:16:56 +01:00
|
|
|
i -= 90.0f) {
|
|
|
|
if (rot > i)
|
|
|
|
break;
|
|
|
|
|
|
|
|
vec3 l = left;
|
|
|
|
vec3 r = right;
|
|
|
|
vec3 t = top;
|
|
|
|
vec3 b = bottom;
|
|
|
|
|
|
|
|
vec3_copy(&top, &r);
|
|
|
|
vec3_copy(&right, &b);
|
|
|
|
vec3_copy(&bottom, &l);
|
|
|
|
vec3_copy(&left, &t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get sides of box transform
|
|
|
|
left = GetTransformedPos(left.x, left.y, boxTransform);
|
|
|
|
right = GetTransformedPos(right.x, right.y, boxTransform);
|
|
|
|
top = GetTransformedPos(top.x, top.y, boxTransform);
|
|
|
|
bottom = GetTransformedPos(bottom.x, bottom.y, boxTransform);
|
|
|
|
|
|
|
|
bottom.y = size.y - bottom.y;
|
|
|
|
right.x = size.x - right.x;
|
|
|
|
|
|
|
|
// Init viewport
|
|
|
|
vec3 viewport;
|
|
|
|
vec3_set(&viewport, main->previewCX, main->previewCY, 1.0f);
|
|
|
|
|
|
|
|
vec3_div(&left, &left, &viewport);
|
|
|
|
vec3_div(&right, &right, &viewport);
|
|
|
|
vec3_div(&top, &top, &viewport);
|
|
|
|
vec3_div(&bottom, &bottom, &viewport);
|
|
|
|
|
|
|
|
vec3_mulf(&left, &left, main->previewScale);
|
|
|
|
vec3_mulf(&right, &right, main->previewScale);
|
|
|
|
vec3_mulf(&top, &top, main->previewScale);
|
|
|
|
vec3_mulf(&bottom, &bottom, main->previewScale);
|
|
|
|
|
|
|
|
// Draw spacer lines and labels
|
|
|
|
vec3 start, end;
|
|
|
|
|
2022-08-03 16:47:25 +02:00
|
|
|
float pixelRatio = main->GetDevicePixelRatio();
|
2021-11-01 08:16:56 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (!spacerLabel[i])
|
2022-08-03 16:47:25 +02:00
|
|
|
spacerLabel[i] = CreateLabel(pixelRatio);
|
2021-11-01 08:16:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
vec3_set(&start, top.x, 0.0f, 1.0f);
|
|
|
|
vec3_set(&end, top.x, top.y, 1.0f);
|
2022-08-03 16:47:25 +02:00
|
|
|
RenderSpacingHelper(0, start, end, viewport, pixelRatio);
|
2021-11-01 08:16:56 +01:00
|
|
|
|
|
|
|
vec3_set(&start, bottom.x, 1.0f - bottom.y, 1.0f);
|
|
|
|
vec3_set(&end, bottom.x, 1.0f, 1.0f);
|
2022-08-03 16:47:25 +02:00
|
|
|
RenderSpacingHelper(1, start, end, viewport, pixelRatio);
|
2021-11-01 08:16:56 +01:00
|
|
|
|
|
|
|
vec3_set(&start, 0.0f, left.y, 1.0f);
|
|
|
|
vec3_set(&end, left.x, left.y, 1.0f);
|
2022-08-03 16:47:25 +02:00
|
|
|
RenderSpacingHelper(2, start, end, viewport, pixelRatio);
|
2021-11-01 08:16:56 +01:00
|
|
|
|
|
|
|
vec3_set(&start, 1.0f - right.x, right.y, 1.0f);
|
|
|
|
vec3_set(&end, 1.0f, right.y, 1.0f);
|
2022-08-03 16:47:25 +02:00
|
|
|
RenderSpacingHelper(3, start, end, viewport, pixelRatio);
|
2021-11-01 08:16:56 +01:00
|
|
|
}
|
2023-03-08 19:20:10 +01:00
|
|
|
|
|
|
|
void OBSBasicPreview::ClampScrollingOffsets()
|
|
|
|
{
|
|
|
|
obs_video_info ovi;
|
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
|
|
|
|
QSize targetSize = GetPixelSize(this);
|
|
|
|
|
|
|
|
vec3 target, offset;
|
|
|
|
vec3_set(&target, (float)targetSize.width(), (float)targetSize.height(),
|
|
|
|
1.0f);
|
|
|
|
|
|
|
|
vec3_set(&offset, (float)ovi.base_width, (float)ovi.base_height, 1.0f);
|
|
|
|
vec3_mulf(&offset, &offset, scalingAmount);
|
|
|
|
|
|
|
|
vec3_sub(&offset, &offset, &target);
|
|
|
|
|
|
|
|
vec3_mulf(&offset, &offset, 0.5f);
|
|
|
|
vec3_maxf(&offset, &offset, 0.0f);
|
|
|
|
|
|
|
|
scrollingOffset.x = std::clamp(scrollingOffset.x, -offset.x, offset.x);
|
|
|
|
scrollingOffset.y = std::clamp(scrollingOffset.y, -offset.y, offset.y);
|
|
|
|
}
|