window-basic-main.cpp 5.3 KB

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