yolobs-studio/UI/window-basic-preview.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
4.5 KiB
C++
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
#pragma once
#include <obs.hpp>
#include <graphics/vec2.h>
#include <graphics/matrix4.h>
2019-09-22 21:19:10 +00:00
#include <util/threading.h>
#include <mutex>
#include <vector>
2016-02-23 23:16:51 +00:00
#include "qt-display.hpp"
#include "obs-app.hpp"
class OBSBasic;
class QMouseEvent;
2019-09-22 21:19:10 +00:00
#define ITEM_LEFT (1 << 0)
#define ITEM_RIGHT (1 << 1)
#define ITEM_TOP (1 << 2)
#define ITEM_BOTTOM (1 << 3)
2016-02-23 23:16:51 +00:00
2018-02-19 19:54:37 +00:00
#define ZOOM_SENSITIVITY 1.125f
2016-02-23 23:16:51 +00:00
enum class ItemHandle : uint32_t {
2019-09-22 21:19:10 +00:00
None = 0,
TopLeft = ITEM_TOP | ITEM_LEFT,
TopCenter = ITEM_TOP,
TopRight = ITEM_TOP | ITEM_RIGHT,
CenterLeft = ITEM_LEFT,
CenterRight = ITEM_RIGHT,
BottomLeft = ITEM_BOTTOM | ITEM_LEFT,
2016-02-23 23:16:51 +00:00
BottomCenter = ITEM_BOTTOM,
2019-09-22 21:19:10 +00:00
BottomRight = ITEM_BOTTOM | ITEM_RIGHT,
2016-02-23 23:16:51 +00:00
};
class OBSBasicPreview : public OBSQTDisplay {
Q_OBJECT
2019-07-27 12:47:10 +00:00
friend class SourceTree;
2019-09-22 21:19:10 +00:00
friend class SourceTreeItem;
2019-07-27 12:47:10 +00:00
2016-02-23 23:16:51 +00:00
private:
2016-05-24 19:53:01 +00:00
obs_sceneitem_crop startCrop;
2019-09-22 21:19:10 +00:00
vec2 startItemPos;
vec2 cropSize;
2018-12-16 16:14:58 +00:00
OBSSceneItem stretchGroup;
2016-02-23 23:16:51 +00:00
OBSSceneItem stretchItem;
2019-09-22 21:19:10 +00:00
ItemHandle stretchHandle = ItemHandle::None;
vec2 stretchItemSize;
matrix4 screenToItem;
matrix4 itemToScreen;
matrix4 invGroupTransform;
2016-02-23 23:16:51 +00:00
2019-07-27 12:47:10 +00:00
gs_texture_t *overflow = nullptr;
2019-09-22 21:19:10 +00:00
gs_vertbuffer_t *rectFill = nullptr;
vec2 startPos;
vec2 mousePos;
vec2 lastMoveOffset;
vec2 scrollingFrom;
vec2 scrollingOffset;
bool mouseDown = false;
bool mouseMoved = false;
bool mouseOverItems = false;
bool cropping = false;
bool locked = false;
bool scrollMode = false;
bool fixedScaling = false;
bool selectionBox = false;
int32_t scalingLevel = 0;
float scalingAmount = 1.0f;
std::vector<obs_sceneitem_t *> hoveredPreviewItems;
std::vector<obs_sceneitem_t *> selectedItems;
std::mutex selectMutex;
2019-07-27 12:47:10 +00:00
2016-02-23 23:16:51 +00:00
static vec2 GetMouseEventPos(QMouseEvent *event);
2019-09-22 21:19:10 +00:00
static bool FindSelected(obs_scene_t *scene, obs_sceneitem_t *item,
void *param);
2019-07-27 12:47:10 +00:00
static bool DrawSelectedOverflow(obs_scene_t *scene,
2019-09-22 21:19:10 +00:00
obs_sceneitem_t *item, void *param);
2016-02-23 23:16:51 +00:00
static bool DrawSelectedItem(obs_scene_t *scene, obs_sceneitem_t *item,
2019-09-22 21:19:10 +00:00
void *param);
static bool DrawSelectionBox(float x1, float y1, float x2, float y2,
gs_vertbuffer_t *box);
2016-02-23 23:16:51 +00:00
static OBSSceneItem GetItemAtPos(const vec2 &pos, bool selectBelow);
static bool SelectedAtPos(const vec2 &pos);
static void DoSelect(const vec2 &pos);
static void DoCtrlSelect(const vec2 &pos);
2016-05-24 19:53:01 +00:00
static vec3 GetSnapOffset(const vec3 &tl, const vec3 &br);
2016-02-23 23:16:51 +00:00
void GetStretchHandleData(const vec2 &pos);
2020-10-01 20:15:25 +00:00
void UpdateCursor(uint32_t &flags);
2016-02-23 23:16:51 +00:00
void SnapStretchingToScreen(vec3 &tl, vec3 &br);
void ClampAspect(vec3 &tl, vec3 &br, vec2 &size, const vec2 &baseSize);
vec3 CalculateStretchPos(const vec3 &tl, const vec3 &br);
2016-05-24 19:53:01 +00:00
void CropItem(const vec2 &pos);
2016-02-23 23:16:51 +00:00
void StretchItem(const vec2 &pos);
static void SnapItemMovement(vec2 &offset);
void MoveItems(const vec2 &pos);
2019-09-22 21:19:10 +00:00
void BoxItems(const vec2 &startPos, const vec2 &pos);
2016-02-23 23:16:51 +00:00
void ProcessClick(const vec2 &pos);
public:
2020-10-01 20:15:25 +00:00
OBSBasicPreview(QWidget *parent,
Qt::WindowFlags flags = Qt::WindowFlags());
2019-07-27 12:47:10 +00:00
~OBSBasicPreview();
static OBSBasicPreview *Get();
2016-02-23 23:16:51 +00:00
2017-04-19 19:54:15 +00:00
virtual void keyPressEvent(QKeyEvent *event) override;
virtual void keyReleaseEvent(QKeyEvent *event) override;
2018-02-19 19:54:37 +00:00
virtual void wheelEvent(QWheelEvent *event) override;
2016-02-23 23:16:51 +00:00
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
2019-07-27 12:47:10 +00:00
virtual void leaveEvent(QEvent *event) override;
2016-02-23 23:16:51 +00:00
2019-07-27 12:47:10 +00:00
void DrawOverflow();
2016-02-23 23:16:51 +00:00
void DrawSceneEditing();
2019-09-22 21:19:10 +00:00
inline void SetLocked(bool newLockedVal) { locked = newLockedVal; }
inline void ToggleLocked() { locked = !locked; }
inline bool Locked() const { return locked; }
2016-08-28 12:07:43 +00:00
2019-09-22 21:19:10 +00:00
inline void SetFixedScaling(bool newFixedScalingVal)
{
fixedScaling = newFixedScalingVal;
}
2018-02-19 19:54:37 +00:00
inline bool IsFixedScaling() const { return fixedScaling; }
void SetScalingLevel(int32_t newScalingLevelVal);
void SetScalingAmount(float newScalingAmountVal);
inline int32_t GetScalingLevel() const { return scalingLevel; }
inline float GetScalingAmount() const { return scalingAmount; }
2017-04-19 19:54:15 +00:00
2018-02-19 19:54:37 +00:00
void ResetScrollingOffset();
2019-09-22 21:19:10 +00:00
inline void SetScrollingOffset(float x, float y)
{
vec2_set(&scrollingOffset, x, y);
}
inline float GetScrollX() const { return scrollingOffset.x; }
inline float GetScrollY() const { return scrollingOffset.y; }
2017-04-19 19:54:15 +00:00
2016-02-23 23:16:51 +00:00
/* use libobs allocator for alignment because the matrices itemToScreen
* and screenToItem may contain SSE data, which will cause SSE
* instructions to crash if the data is not aligned to at least a 16
2017-06-29 19:01:10 +00:00
* byte boundary. */
2019-09-22 21:19:10 +00:00
static inline void *operator new(size_t size) { return bmalloc(size); }
static inline void operator delete(void *ptr) { bfree(ptr); }
2016-02-23 23:16:51 +00:00
};