1
0

window-basic-preview.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. OBSSceneItem stretchItem;
  28. ItemHandle stretchHandle = ItemHandle::None;
  29. vec2 stretchItemSize;
  30. matrix4 screenToItem;
  31. matrix4 itemToScreen;
  32. vec2 startPos;
  33. vec2 lastMoveOffset;
  34. bool mouseDown = false;
  35. bool mouseMoved = false;
  36. bool mouseOverItems = false;
  37. static vec2 GetMouseEventPos(QMouseEvent *event);
  38. static bool DrawSelectedItem(obs_scene_t *scene, obs_sceneitem_t *item,
  39. void *param);
  40. static OBSSceneItem GetItemAtPos(const vec2 &pos, bool selectBelow);
  41. static bool SelectedAtPos(const vec2 &pos);
  42. static void DoSelect(const vec2 &pos);
  43. static void DoCtrlSelect(const vec2 &pos);
  44. static vec3 GetScreenSnapOffset(const vec3 &tl, const vec3 &br);
  45. void GetStretchHandleData(const vec2 &pos);
  46. void SnapStretchingToScreen(vec3 &tl, vec3 &br);
  47. void ClampAspect(vec3 &tl, vec3 &br, vec2 &size, const vec2 &baseSize);
  48. vec3 CalculateStretchPos(const vec3 &tl, const vec3 &br);
  49. void StretchItem(const vec2 &pos);
  50. static void SnapItemMovement(vec2 &offset);
  51. void MoveItems(const vec2 &pos);
  52. void ProcessClick(const vec2 &pos);
  53. public:
  54. OBSBasicPreview(QWidget *parent, Qt::WindowFlags flags = 0);
  55. virtual void mousePressEvent(QMouseEvent *event) override;
  56. virtual void mouseReleaseEvent(QMouseEvent *event) override;
  57. virtual void mouseMoveEvent(QMouseEvent *event) override;
  58. void DrawSceneEditing();
  59. /* use libobs allocator for alignment because the matrices itemToScreen
  60. * and screenToItem may contain SSE data, which will cause SSE
  61. * instructions to crash if the data is not aligned to at least a 16
  62. * byte boundry. */
  63. static inline void* operator new(size_t size) {return bmalloc(size);}
  64. static inline void operator delete(void* ptr) {bfree(ptr);}
  65. };