sampapp.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // Sample/Test application for Video Library.
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #include "System.h"
  22. #include "Blue.h"
  23. #include "video.h"
  24. #include "hot.h"
  25. #include "wdisplay.h"
  26. #define VIDEO_FILE "\\\\METRO\\PROJECTS\\MUPPETS\\BEAKER\\TEMPASSETS\\LOSER1.AVI"
  27. #define CURSOR_FILE "\\\\METRO\\PROJECTS\\MUPPETS\\BEAKER\\TEMPASSETS\\HOTPTR.CUR"
  28. ///////////////////////////////////////////////////////////////////////////////
  29. //
  30. // Hooks Blue's Display's Window Proc. Return non-zero to have Blue return
  31. // your *plResult.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////////
  34. short WinProcHook(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam,
  35. LRESULT* plResult)
  36. {
  37. short sRes = 0; // Assume normal processing.
  38. switch (uiMsg)
  39. {
  40. case WM_SETCURSOR:
  41. // TRACE("WinProcHook(): WM_SETCURSOR.\n");
  42. // sRes = TRUE;
  43. // *plResult = TRUE;
  44. break;
  45. }
  46. return sRes;
  47. }
  48. ///////////////////////////////////////////////////////////////////////////////
  49. //
  50. // Waits for a mouse click (down, then up) on sButton { MOUSE_BUTTON_LEFT,
  51. // MOUSE_BUTTON_RIGHT }.
  52. //
  53. ///////////////////////////////////////////////////////////////////////////////
  54. static void WaitClick(short sButton)
  55. {
  56. while (Blu_GetMouseButton(sButton) == MOUSE_BUTTON_UP)
  57. {
  58. Blu_System();
  59. }
  60. while (Blu_GetMouseButton(sButton) == MOUSE_BUTTON_DOWN)
  61. {
  62. Blu_System();
  63. }
  64. }
  65. ///////////////////////////////////////////////////////////////////////////////
  66. //
  67. // Attempt to start or stop a video.
  68. // Returns 0 on success.
  69. //
  70. ///////////////////////////////////////////////////////////////////////////////
  71. #define MCI_TIME_OUT 500
  72. #define MCI_RETRIES 3
  73. static short ToggleVideo(CVideo* pvideo)
  74. {
  75. short sRes = 0; // Assume success.
  76. Blu_HookWinProc(WinProcHook);
  77. if (pvideo->IsPlaying() == TRUE)
  78. {
  79. pvideo->Stop();
  80. if (pvideo->IsPlaying() == TRUE)
  81. {
  82. TRACE("ToggleVideo(): Video did not stop yet.\n");
  83. sRes = -1;
  84. }
  85. else
  86. {
  87. pvideo->Close();
  88. }
  89. }
  90. else
  91. {
  92. if (pvideo->Open(VIDEO_FILE, 0, 0, 1, 1, 0) == VIDEO_SUCCESS)
  93. {
  94. short sRetries;
  95. long lEndTime = 0L;
  96. for ( sRetries = 0;
  97. sRetries < MCI_RETRIES && sRes == 0 && pvideo->IsPlaying() == FALSE;
  98. )
  99. {
  100. if (lEndTime < Blu_GetTime())
  101. {
  102. if (++sRetries == MCI_RETRIES)
  103. {
  104. TRACE("ToggleVideo(): Exceeded max retries.\n");
  105. }
  106. else
  107. {
  108. if (pvideo->Play() == VIDEO_SUCCESS)
  109. {
  110. // Set next time.
  111. lEndTime = Blu_GetTime() + MCI_TIME_OUT;
  112. }
  113. else
  114. {
  115. TRACE("ToggleVideo(): Play returned error.\n");
  116. sRes = -2;
  117. }
  118. }
  119. }
  120. Blu_System();
  121. }
  122. if (pvideo->IsPlaying() == TRUE)
  123. {
  124. TRACE("ToggleVideo(): Took %d tries to start.\n", sRetries);
  125. }
  126. }
  127. else
  128. {
  129. Blu_MsgBox(MB_ICN_STOP | MB_BUT_OK, "Sux!", "Unable to open <%s>.", VIDEO_FILE);
  130. }
  131. }
  132. return sRes;
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////
  135. //
  136. // Test video library functionality.
  137. //
  138. ///////////////////////////////////////////////////////////////////////////////
  139. short AppMain(void)
  140. {
  141. CVideo video;
  142. if (Blu_CreateDisplay(640, 400, (short)Blu_GetDisplayInfo(DI_MONITOR_COLORDEPTH))
  143. == 0)
  144. {
  145. short sButtonDn = FALSE;
  146. CHot hot;
  147. if (hot.Create(0, 0,
  148. Blu_GetDisplayInfo(DI_MONITOR_WIDTH), Blu_GetDisplayInfo(DI_MONITOR_HEIGHT),
  149. CURSOR_FILE) == 0)
  150. {
  151. hot.SetActive(TRUE);
  152. }
  153. else
  154. {
  155. TRACE("AppMain(): Unable to create hotbox.\n");
  156. }
  157. while (Blu_GetMouseButton(MOUSE_BUTTON_RIGHT) == MOUSE_BUTTON_UP)
  158. {
  159. if (Blu_GetMouseButton(MOUSE_BUTTON_LEFT) == MOUSE_BUTTON_DOWN)
  160. {
  161. sButtonDn = TRUE;
  162. }
  163. else
  164. {
  165. if (sButtonDn == TRUE)
  166. {
  167. ToggleVideo(&video);
  168. sButtonDn = FALSE;
  169. }
  170. }
  171. Blu_System();
  172. }
  173. while (Blu_GetMouseButton(MOUSE_BUTTON_RIGHT) == MOUSE_BUTTON_DOWN)
  174. {
  175. Blu_System();
  176. }
  177. }
  178. else
  179. {
  180. Blu_MsgBox(MB_ICN_INFO | MB_BUT_OK, "Sux!", "Unable to create display.");
  181. }
  182. return 0;
  183. }
  184. ///////////////////////////////////////////////////////////////////////////////
  185. // EOF.
  186. ///////////////////////////////////////////////////////////////////////////////