window-main-basic.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[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 <obs.hpp>
  15. #include "obs-app.hpp"
  16. #include "wx-wrappers.hpp"
  17. #include "window-settings-basic.hpp"
  18. #include "window-main-basic.hpp"
  19. void OBSBasic::SceneAdded(obs_source_t source)
  20. {
  21. const char *name = obs_source_getname(source);
  22. obs_scene_t scene = obs_scene_fromsource(source);
  23. scenes->Append(wxString(name, wxConvUTF8), scene);
  24. }
  25. void OBSBasic::SourceAdded(void *data, calldata_t params)
  26. {
  27. OBSBasic *window = (OBSBasic*)data;
  28. obs_source_t source;
  29. calldata_getptr(params, "source", (void**)&source);
  30. obs_source_type type;
  31. obs_source_gettype(source, &type, NULL);
  32. if (type == SOURCE_SCENE)
  33. window->SceneAdded(source);
  34. }
  35. void OBSBasic::SourceDestroyed(void *data, calldata_t params)
  36. {
  37. OBSBasic *window = (OBSBasic*)data;
  38. obs_source_t source;
  39. calldata_getptr(params, "source", (void**)&source);
  40. /* TODO */
  41. }
  42. bool OBSBasic::Init()
  43. {
  44. if (!obs_startup())
  45. return false;
  46. if (!InitGraphics())
  47. return false;
  48. signal_handler_connect(obs_signalhandler(), "source-add",
  49. OBSBasic::SourceAdded, this);
  50. signal_handler_connect(obs_signalhandler(), "source-destroy",
  51. OBSBasic::SourceDestroyed, this);
  52. //obs_scene_t scene = obs_scene_create("test scene");
  53. //obs_add_source(obs_scene_getsource(scene));
  54. //obs_load_module("test-input");
  55. return true;
  56. }
  57. OBSBasic::~OBSBasic()
  58. {
  59. obs_shutdown();
  60. }
  61. bool OBSBasic::InitGraphics()
  62. {
  63. wxSize size = previewPanel->GetClientSize();
  64. struct obs_video_info ovi;
  65. wxGetApp().GetConfigFPS(ovi.fps_num, ovi.fps_den);
  66. ovi.graphics_module = wxGetApp().GetRenderModule();
  67. ovi.window_width = size.x;
  68. ovi.window_height = size.y;
  69. ovi.base_width = (uint32_t)config_get_uint(GetGlobalConfig(),
  70. "Video", "BaseCX");
  71. ovi.base_height = (uint32_t)config_get_uint(GetGlobalConfig(),
  72. "Video", "BaseCY");
  73. ovi.output_width = (uint32_t)config_get_uint(GetGlobalConfig(),
  74. "Video", "OutputCX");
  75. ovi.output_height = (uint32_t)config_get_uint(GetGlobalConfig(),
  76. "Video", "OutputCY");
  77. ovi.output_format = VIDEO_FORMAT_RGBA;
  78. ovi.adapter = 0;
  79. ovi.window = WxToGSWindow(previewPanel);
  80. if (!obs_reset_video(&ovi))
  81. return false;
  82. //required to make opengl display stuff on osx(?)
  83. SendSizeEvent();
  84. return true;
  85. }
  86. void OBSBasic::OnClose(wxCloseEvent &event)
  87. {
  88. wxGetApp().ExitMainLoop();
  89. event.Skip();
  90. }
  91. void OBSBasic::OnMinimize(wxIconizeEvent &event)
  92. {
  93. event.Skip();
  94. }
  95. void OBSBasic::OnSize(wxSizeEvent &event)
  96. {
  97. struct obs_video_info ovi;
  98. event.Skip();
  99. if (!obs_get_video_info(&ovi))
  100. return;
  101. /* resize preview panel to fix to the top section of the window */
  102. wxSize targetSize = GetPreviewContainer()->GetSize();
  103. double targetAspect = double(targetSize.x) / double(targetSize.y);
  104. double baseAspect = double(ovi.base_width) / double(ovi.base_height);
  105. if (targetAspect > baseAspect)
  106. GetPreviewPanel()->SetMinSize(wxSize(targetSize.y * baseAspect,
  107. targetSize.y));
  108. else
  109. GetPreviewPanel()->SetMinSize(wxSize(targetSize.x,
  110. targetSize.x / baseAspect));
  111. }
  112. void OBSBasic::fileNewClicked(wxCommandEvent &event)
  113. {
  114. }
  115. void OBSBasic::fileOpenClicked(wxCommandEvent &event)
  116. {
  117. }
  118. void OBSBasic::fileSaveClicked(wxCommandEvent &event)
  119. {
  120. }
  121. void OBSBasic::fileExitClicked(wxCommandEvent &event)
  122. {
  123. wxGetApp().ExitMainLoop();
  124. }
  125. void OBSBasic::scenesRDown(wxMouseEvent &event)
  126. {
  127. }
  128. void OBSBasic::sceneAddClicked(wxCommandEvent &event)
  129. {
  130. }
  131. void OBSBasic::sceneRemoveClicked(wxCommandEvent &event)
  132. {
  133. }
  134. void OBSBasic::scenePropertiesClicked(wxCommandEvent &event)
  135. {
  136. }
  137. void OBSBasic::sceneUpClicked(wxCommandEvent &event)
  138. {
  139. }
  140. void OBSBasic::sceneDownClicked(wxCommandEvent &event)
  141. {
  142. }
  143. void OBSBasic::sourcesRDown(wxMouseEvent &event)
  144. {
  145. }
  146. void OBSBasic::sourceAddClicked(wxCommandEvent &event)
  147. {
  148. }
  149. void OBSBasic::sourceRemoveClicked(wxCommandEvent &event)
  150. {
  151. }
  152. void OBSBasic::sourcePropertiesClicked(wxCommandEvent &event)
  153. {
  154. }
  155. void OBSBasic::sourceUpClicked(wxCommandEvent &event)
  156. {
  157. }
  158. void OBSBasic::sourceDownClicked(wxCommandEvent &event)
  159. {
  160. }
  161. void OBSBasic::settingsClicked(wxCommandEvent &event)
  162. {
  163. OBSBasicSettings test(this);
  164. test.ShowModal();
  165. }
  166. void OBSBasic::exitClicked(wxCommandEvent &event)
  167. {
  168. wxGetApp().ExitMainLoop();
  169. }