Video.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. /******************************************************************************/
  4. VideoEditor VideoEdit;
  5. /******************************************************************************/
  6. /******************************************************************************/
  7. GuiObj* VideoEditor::Custom::test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel){return null;}
  8. void VideoEditor::Custom::draw(C GuiPC &gpc)
  9. {
  10. if(visible() && gpc.visible)
  11. {
  12. D.clip(gpc.clip);
  13. Rect r=rect()+gpc.offset;
  14. VideoEditor &ve=*(VideoEditor*)user;
  15. ve.video.update (ve.video_time); ve.video_time+=Time.ad(); // Editor works in background so app time gets updated even when minimized, update time only when actually drawing
  16. ve.video.drawFit(r);
  17. r.draw(Gui.borderColor(), false);
  18. }
  19. }
  20. void VideoEditor::Locate(VideoEditor &editor) {Proj.elmLocate(editor.elm_id);}
  21. void VideoEditor::create()
  22. {
  23. width =&add();
  24. height=&add();
  25. //kbps =&add(); don't create because Theora and VP9 fail to detect it correctly
  26. fps =&add();
  27. codec =&add();
  28. autoData(this);
  29. Rect r=::PropWin::create("Video Player", Vec2(0.02f, -0.02f)); button[1].show(); button[2].func(HideProjAct, SCAST(GuiObj, T)).show(); flag|=WIN_RESIZABLE;
  30. T+=custom.create(this);
  31. rect(Rect_C(0, 0, Min(1.7f, D.w()*2), Min(1.07f, D.h()*2)));
  32. T+=locate.create(Rect_U(0.11f, r.min.y-0.02f, 0.15f, 0.055f), "Locate").func(Locate, T).focusable(false).desc("Locate this element in the Project");
  33. }
  34. void VideoEditor::setInfo()
  35. {
  36. if(width )width ->name.set(S+"Width: " +video.width ());
  37. if(height)height->name.set(S+"Height: "+video.height());
  38. if(kbps )kbps ->name.set(S+"Kbps: " +DivRound(video.bitRate(), 1000));
  39. if(fps )fps ->name.set(S+"FPS: " +TextReal(video.fps(), -1));
  40. if(codec )codec ->name.set(S+"Codec: " +video.codecName());
  41. }
  42. void VideoEditor::update(C GuiPC &gpc)
  43. {
  44. ::EE::ClosableWindow::update(gpc);
  45. if(gpc.visible && visible())setInfo();
  46. }
  47. VideoEditor& VideoEditor::hide( ) {set(null); ::PropWin::hide(); return T;}
  48. Rect VideoEditor::sizeLimit( )C {Rect r=::EE::Window::sizeLimit(); r.min.set(1.0f, 0.45f); return r;}
  49. VideoEditor& VideoEditor::rect(C Rect &rect)
  50. {
  51. ::EE::Window::rect(rect);
  52. flt x=0; if(props.elms())x=0.22f; //props[0].button.rect().max.x;
  53. Rect r(x, -clientHeight(), clientWidth(), 0); r.extend(-0.02f);
  54. custom.rect(r);
  55. return T;
  56. }
  57. void VideoEditor::flush()
  58. {
  59. if(elm && changed)
  60. {
  61. if(ElmVideo *data=elm->videoData())data->newVer(); // modify just before saving/sending in case we've received data from server after edit
  62. Preview.elmChanged(elm->id);
  63. }
  64. changed=false;
  65. }
  66. void VideoEditor::setChanged()
  67. {
  68. if(elm)
  69. {
  70. changed=true;
  71. if(ElmVideo *data=elm->videoData())data->newVer();
  72. }
  73. }
  74. void VideoEditor::set(Elm *elm)
  75. {
  76. if(elm && elm->type!=ELM_VIDEO)elm=null;
  77. if(T.elm!=elm)
  78. {
  79. flush();
  80. T.elm =elm;
  81. T.elm_id=(elm ? elm->id : UIDZero);
  82. if(elm){video.create(Proj.gamePath(*elm), true); video_time=0;}else video.del(); // start from the beginning to avoid freezes
  83. setInfo();
  84. Proj.refresh(false, false);
  85. visible(T.elm!=null).moveToTop();
  86. }
  87. }
  88. void VideoEditor::activate(Elm *elm) {set(elm); if(T.elm)::EE::GuiObj::activate();}
  89. void VideoEditor::toggle(Elm *elm) {if(elm==T.elm)elm=null; set(elm);}
  90. void VideoEditor::closeElm(C UID &elm_id) {if(elm && elm->id==elm_id)video.del();}
  91. void VideoEditor::erasing(C UID &elm_id) {if(elm && elm->id==elm_id)set(null);}
  92. void VideoEditor::elmChanged(C UID &elm_id)
  93. {
  94. if(elm && elm->id==elm_id)
  95. {
  96. video.create(Proj.gamePath(*elm), true); video_time=0; setInfo(); // start from the beginning to avoid freezes
  97. }
  98. }
  99. VideoEditor::VideoEditor() : elm_id(UIDZero), elm(null), changed(false), video_time(0), width(null), height(null), kbps(null), fps(null), codec(null) {}
  100. /******************************************************************************/