window-basic-preview.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <obs.hpp>
  3. #include <graphics/vec2.h>
  4. #include <graphics/matrix4.h>
  5. #include "qt-display.hpp"
  6. #include "obs-app.hpp"
  7. class OBSBasic;
  8. class QMouseEvent;
  9. #define ITEM_LEFT (1<<0)
  10. #define ITEM_RIGHT (1<<1)
  11. #define ITEM_TOP (1<<2)
  12. #define ITEM_BOTTOM (1<<3)
  13. enum class ItemHandle : uint32_t {
  14. None = 0,
  15. TopLeft = ITEM_TOP | ITEM_LEFT,
  16. TopCenter = ITEM_TOP,
  17. TopRight = ITEM_TOP | ITEM_RIGHT,
  18. CenterLeft = ITEM_LEFT,
  19. CenterRight = ITEM_RIGHT,
  20. BottomLeft = ITEM_BOTTOM | ITEM_LEFT,
  21. BottomCenter = ITEM_BOTTOM,
  22. BottomRight = ITEM_BOTTOM | ITEM_RIGHT
  23. };
  24. class OBSBasicPreview : public OBSQTDisplay {
  25. Q_OBJECT
  26. private:
  27. obs_sceneitem_crop startCrop;
  28. vec2 startItemPos;
  29. vec2 cropSize;
  30. OBSSceneItem stretchItem;
  31. ItemHandle stretchHandle = ItemHandle::None;
  32. vec2 stretchItemSize;
  33. matrix4 screenToItem;
  34. matrix4 itemToScreen;
  35. vec2 startPos;
  36. vec2 lastMoveOffset;
  37. bool mouseDown = false;
  38. bool mouseMoved = false;
  39. bool mouseOverItems = false;
  40. bool cropping = false;
  41. static vec2 GetMouseEventPos(QMouseEvent *event);
  42. static bool DrawSelectedItem(obs_scene_t *scene, obs_sceneitem_t *item,
  43. void *param);
  44. static OBSSceneItem GetItemAtPos(const vec2 &pos, bool selectBelow);
  45. static bool SelectedAtPos(const vec2 &pos);
  46. static void DoSelect(const vec2 &pos);
  47. static void DoCtrlSelect(const vec2 &pos);
  48. static vec3 GetSnapOffset(const vec3 &tl, const vec3 &br);
  49. void GetStretchHandleData(const vec2 &pos);
  50. void SnapStretchingToScreen(vec3 &tl, vec3 &br);
  51. void ClampAspect(vec3 &tl, vec3 &br, vec2 &size, const vec2 &baseSize);
  52. vec3 CalculateStretchPos(const vec3 &tl, const vec3 &br);
  53. void CropItem(const vec2 &pos);
  54. void StretchItem(const vec2 &pos);
  55. static void SnapItemMovement(vec2 &offset);
  56. void MoveItems(const vec2 &pos);
  57. void ProcessClick(const vec2 &pos);
  58. public:
  59. OBSBasicPreview(QWidget *parent, Qt::WindowFlags flags = 0);
  60. virtual void mousePressEvent(QMouseEvent *event) override;
  61. virtual void mouseReleaseEvent(QMouseEvent *event) override;
  62. virtual void mouseMoveEvent(QMouseEvent *event) override;
  63. void DrawSceneEditing();
  64. /* use libobs allocator for alignment because the matrices itemToScreen
  65. * and screenToItem may contain SSE data, which will cause SSE
  66. * instructions to crash if the data is not aligned to at least a 16
  67. * byte boundry. */
  68. static inline void* operator new(size_t size) {return bmalloc(size);}
  69. static inline void operator delete(void* ptr) {bfree(ptr);}
  70. };