FrmCamViewF.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FrmCamViewF.h"
  5. #include "FrmCctvMonitoringF.h"
  6. #include "AppGlobalF.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma link "AcesTechXPlayer2Lib_OCX"
  10. #pragma link "cxContainer"
  11. #pragma link "cxControls"
  12. #pragma link "cxEdit"
  13. #pragma link "cxGraphics"
  14. #pragma link "cxLabel"
  15. #pragma link "cxLookAndFeelPainters"
  16. #pragma link "cxLookAndFeels"
  17. #pragma resource "*.dfm"
  18. TFrmCamera *FrmCamera = NULL;
  19. //---------------------------------------------------------------------------
  20. __fastcall TFrmCamera::TFrmCamera(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. FPlay = false;
  24. FAutoPlay = true;
  25. FConHandle = 0;
  26. FInstalled = false;
  27. AcesTechXPlayer21->DoubleBuffered = true;
  28. InitCamera(NULL, FAutoPlay);
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TFrmCamera::MnuConnectClick(TObject *Sender)
  32. {
  33. FAutoPlay = true;
  34. Connect();
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TFrmCamera::MnuDisconnectClick(TObject *Sender)
  38. {
  39. FAutoPlay = false;
  40. Disconnect();
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TFrmCamera::MnuReleaseClick(TObject *Sender)
  44. {
  45. CameraRelease();
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall TFrmCamera::Connect()
  49. {
  50. Disconnect();
  51. if (FId.IsEmpty()) return;
  52. if (FViewAddress.IsEmpty()) return;
  53. PnlCamera->Caption = "¿¬°áÁß...";
  54. AcesTechXPlayer21->Visible = true;
  55. try
  56. {
  57. Log(FTitle + " " + FName + " Connect");
  58. AcesTechXPlayer21->URL = FViewAddress;
  59. FConHandle = AcesTechXPlayer21->ConnectAsync();
  60. Log(FTitle + " " + FName + " Handle: " + String(FConHandle));
  61. }
  62. catch(...)
  63. {
  64. }
  65. FPlay = true;
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TFrmCamera::Disconnect()
  69. {
  70. if (!FPlay) return;
  71. try
  72. {
  73. //if (FConHandle)
  74. {
  75. Log(FTitle + " " + FName + " Disconnect");
  76. AcesTechXPlayer21->Close();
  77. }
  78. FConHandle = 0;
  79. }
  80. catch(...)
  81. {
  82. }
  83. PnlCamera->Caption = "Disconnected";
  84. AcesTechXPlayer21->Visible = false;
  85. FConHandle = 0;
  86. FPlay = false;
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TFrmCamera::CameraRelease()
  90. {
  91. Disconnect();
  92. InitCamera(NULL, FAutoPlay);
  93. PnlCamera->Caption = "";
  94. AcesTechXPlayer21->Visible = false;
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TFrmCamera::PnlCameraDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept)
  98. {
  99. Accept = true;
  100. if (!g_Drag.Id.IsEmpty())
  101. {
  102. #if 0
  103. int x_gap = Top;
  104. int y_gap = Left;
  105. FrmMain->StDrag->Top = (Y-10-FrmMain->StDrag->Height) - y_gap;
  106. FrmMain->StDrag->Left = (X) - x_gap;
  107. if (!FrmMain->StDrag->Visible)
  108. {
  109. FrmMain->StDrag->Visible = true;
  110. }
  111. #endif
  112. }
  113. else
  114. {
  115. Accept = false;
  116. }
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TFrmCamera::PnlCameraDragDrop(TObject *Sender, TObject *Source, int X, int Y)
  120. {
  121. if (!g_Drag.Id.IsEmpty())
  122. {
  123. FId = g_Drag.Id;
  124. FGroup = g_Drag.Group;
  125. FName = g_Drag.Name;
  126. FStreamingType = g_Drag.StreamingType;
  127. FViewAddress = g_Drag.ViewAddress;
  128. FFullAddress = g_Drag.FullAddress;
  129. PnlCamera->Caption = "Disconnected";
  130. DisplayName(FName);
  131. FInstalled = true;
  132. if (FAutoPlay || FPlay)
  133. {
  134. Connect();
  135. }
  136. }
  137. g_Drag.Id = "";
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TFrmCamera::InitCamera(TXCctv *ACctv, bool AAutoPlay/*=true*/)
  141. {
  142. FAutoPlay = AAutoPlay;
  143. if (!ACctv)
  144. {
  145. FId = "";
  146. FGroup = "";
  147. FName = "";
  148. FStreamingType = "";
  149. FViewAddress = "";
  150. FFullAddress = "";
  151. DisplayName(" ");
  152. FInstalled = false;
  153. }
  154. else
  155. {
  156. FId = ACctv->Id;
  157. FGroup = ACctv->Group;
  158. FName = ACctv->Name;
  159. FStreamingType = ACctv->StreamingType;
  160. FViewAddress = ACctv->ViewAddress;
  161. FFullAddress = ACctv->FullAddress;
  162. PnlCamera->Caption = "Disconnected";
  163. DisplayName(FName);
  164. FInstalled = true;
  165. }
  166. }
  167. //---------------------------------------------------------------------------
  168. void __fastcall TFrmCamera::DisplayName(String AName)
  169. {
  170. LblName->Visible = false;
  171. LblName->Caption = FName;
  172. LblName->Transparent = false;
  173. LblName->Transparent = true;
  174. LblName->Visible = true;
  175. LblName->Refresh();
  176. LblName->BringToFront();
  177. //::SetWindowLong(LblName->Handle, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT);
  178. //::SetLayeredWindowAttributes(LblName->Handle, 0, 80, LWA_ALPHA);
  179. // long __fastcall DrawText(BSTR text, long x, long y, BSTR fontname, long fontsize,
  180. // long underline, long fontcolor, long bordercolor, long bkcolor);
  181. // AcesTechXPlayer21->DrawTextW(AName.c_str(), 10, 10, L"¸¼Àº °íµñ", 10, 0, 0, 0, 0);
  182. }
  183. //---------------------------------------------------------------------------
  184. void __fastcall TFrmCamera::UpdateCctvMasterInfo()
  185. {
  186. if (!FInstalled) return;
  187. TXCctv *pCctv = XCctvManager->FLists.Find(FId);
  188. if (pCctv)
  189. {
  190. if (pCctv->EditMode == DB_DELETE ||
  191. pCctv->DEL_YN == "Y")
  192. {
  193. CameraRelease();
  194. return;
  195. }
  196. bool bReconnect = false;
  197. if (FViewAddress != pCctv->ViewAddress ||
  198. FFullAddress != pCctv->FullAddress)
  199. {
  200. bReconnect = true;
  201. }
  202. InitCamera(pCctv, FAutoPlay);
  203. if (bReconnect)
  204. {
  205. if (FPlay)
  206. {
  207. Connect();
  208. }
  209. }
  210. }
  211. else
  212. {
  213. CameraRelease();
  214. }
  215. }
  216. //---------------------------------------------------------------------------
  217. void __fastcall TFrmCamera::TmrPlayTimer(TObject *Sender)
  218. {
  219. TmrStop->Enabled = false;
  220. TmrPlay->Enabled = false;
  221. Connect();
  222. }
  223. //---------------------------------------------------------------------------
  224. void __fastcall TFrmCamera::TmrStopTimer(TObject *Sender)
  225. {
  226. TmrPlay->Enabled = false;
  227. TmrStop->Enabled = false;
  228. Disconnect();
  229. }
  230. //---------------------------------------------------------------------------
  231. void __fastcall TFrmCamera::LblNameClick(TObject *Sender)
  232. {
  233. return;
  234. LblName->Parent = AcesTechXPlayer21;
  235. LblName->Transparent = false;
  236. LblName->Transparent = true;
  237. //AcesTechXPlayer21->Visible = !AcesTechXPlayer21->Visible;
  238. }
  239. //---------------------------------------------------------------------------