frontend: Improve preview source snapping - #12298
Conversation
PatTheMav
left a comment
There was a problem hiding this comment.
Functionally this PR is fine, but it seems very brute force and not particularly efficient to me and falls victim to "featuritis", just piling on little features one by one, each doing its own thing in isolation with no regard to other (similar) features and the architecture behind it.
Preview control drawing should be a single process, by a single responsible entity in code that knows about all of its "features" and thus set up a single render pass to draw all the pieces it knows should be visible for any given frame.
a7a004e to
f53cd97
Compare
152442d to
02623d0
Compare
|
I've added another commit that updates the default snap distance from |
| @@ -31,6 +31,17 @@ enum class ItemHandle : uint32_t { | |||
| Rot = ITEM_ROT | |||
| }; | |||
|
|
|||
| struct SnapGuide { | |||
There was a problem hiding this comment.
Is this a global type or would it make more sense to make it a nested type of OBSBasicPreview, given its limited usage?
| #define HELPER_ROT_BREAKPOINT 45.0f | ||
|
|
||
| namespace { | ||
| bool checkEdgeSnap(float moveAxis, float checkAxis, float clampDistance, float &offset) |
There was a problem hiding this comment.
A function named checkSomething should not have side-effects. What is the purpose of updating the offset as part of the check?
If the update is required, there's two cleaner ways to do it:
- Either return an optional value, which is only set when the check succeeds.
- Or return a
structwhich contains the check result as well as updated values.
| @@ -893,15 +926,32 @@ static bool AddItemBounds(obs_scene_t * /* scene */, obs_sceneitem_t *item, void | |||
| struct OffsetData { | |||
There was a problem hiding this comment.
Per our style guidelines, struct should only be used for "dumb" data structures. As soon as you add any methods to it, it needs to become a class.
I am on the fence about this - coming from Swift it feels natural to have structured data with "helper" methods embedded within the type, and as soon as you need actual heap-allocated objects which you share via references you use classes.
Probably worth amending our style guideline to make this deviation from Google's guidelines explicit, because I do not see much value in turning OffsetData into a class , just because you add helper functions to it.
| vec2 start; | ||
| vec2 end; | ||
|
|
||
| SnapGuide(float x1, float y1, float x2, float y2) |
There was a problem hiding this comment.
The constructor violates best practices from our style guide, because it forces the deconstruction of semantically linked values (x,y-coordinate pairs in this case) into distinct values, which opens up new ways to pass wrong data.
Indeed the code above should probably look more like this:
if (checkEdgeSnap(movingEdge.x(), itemEdge.x(), data->clampDist, data->offset.x)) {
vec2 startPoint {itemEdge.x(), 0.0f};
vec2 endPoint {itemEdge.x(), screen.y};
main->addSnapGuide({startPoint, endPoint});The compiler will automatically pick up the desired type SnapGuide from the signature of addSnapGuide and thus take those two vec2's to create one explicitly.
The lines are shorter and easier to read, the relationship between the values is clear. Points or origins should be represented by the type system and consistently used by it. Qt itself uses QPoint for that reason (which could and maybe should(?) be used instead of vec2?).
| extern "C" __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; | ||
| #endif | ||
|
|
||
| static constexpr double kDefaultSnapDistance = 5.0; |
There was a problem hiding this comment.
| static constexpr double kDefaultSnapDistance = 5.0; | |
| constexpr double kDefaultSnapDistance = 5.0; |
static is superfluous.
5dc9453 to
d1742b9
Compare
d1742b9 to
46e61b4
Compare
Description
This PR makes a number of changes to source snapping in the preview:
Additionally
obs64_wuvM7eemGG.mp4
Motivation and Context
I want to improve source snapping behaviour and visual feedback
How Has This Been Tested?
Moved a bunch of sources around. Toggled relevant snapping settings on and off to ensure behaviour matched settings.
Types of changes
Checklist: