1
0

OBSBasic_Canvases.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /******************************************************************************
  2. Copyright (C) 2025 by Dennis Sädtler <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "OBSBasic.hpp"
  15. void OBSBasic::CanvasRemoved(void *data, calldata_t *params)
  16. {
  17. obs_canvas_t *canvas = static_cast<obs_canvas_t *>(calldata_ptr(params, "canvas"));
  18. QMetaObject::invokeMethod(static_cast<OBSBasic *>(data), "RemoveCanvas", Q_ARG(OBSCanvas, OBSCanvas(canvas)));
  19. }
  20. const OBS::Canvas &OBSBasic::AddCanvas(const std::string &name, obs_video_info *ovi, int flags)
  21. {
  22. OBSCanvas canvas = obs_canvas_create(name.c_str(), ovi, flags);
  23. auto &it = canvases.emplace_back(canvas);
  24. OnEvent(OBS_FRONTEND_EVENT_CANVAS_ADDED);
  25. return it;
  26. }
  27. bool OBSBasic::RemoveCanvas(OBSCanvas canvas)
  28. {
  29. if (!canvas)
  30. return false;
  31. auto canvas_it = std::find(std::begin(canvases), std::end(canvases), canvas);
  32. if (canvas_it != std::end(canvases)) {
  33. canvases.erase(canvas_it);
  34. OnEvent(OBS_FRONTEND_EVENT_CANVAS_REMOVED);
  35. return true;
  36. }
  37. return false;
  38. }