window-basic-main.cpp 6.0 KB

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