SapView.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #ifndef _SAPVIEW_H_
  2. #define _SAPVIEW_H_
  3. // SapView.h : header file
  4. //
  5. #include "SapClassBasicDef.h"
  6. // Forward declarations
  7. class SAPCLASSBASIC_CLASS SapView;
  8. //
  9. // SapViewScaleParams class declaration
  10. //
  11. class SAPCLASSBASIC_CLASS SapViewScaleParams
  12. {
  13. public:
  14. SapViewScaleParams()
  15. { Construct(0, 0, SapDefWidth, SapDefHeight, 1.0, 1.0); }
  16. SapViewScaleParams(int left, int top, int width, int height)
  17. { Construct(left, top, width, height, 1.0, 1.0); }
  18. ~SapViewScaleParams() {}
  19. int Left() const { return m_Left;}
  20. int Top() const { return m_Top;}
  21. int Width() const { return m_Width;}
  22. int Height() const { return m_Height;}
  23. float ZoomHorz() const { return m_ZoomHorz;}
  24. float ZoomVert() const { return m_ZoomVert;}
  25. void SetLeft(int left) { m_Left = left ;}
  26. void SetTop(int top) { m_Top = top; }
  27. void SetWidth(int width) { m_Width = width; }
  28. void SetHeight(int height) { m_Height = height; }
  29. void SetZoomHorz(float zoomHorz) { m_ZoomHorz = zoomHorz; }
  30. void SetZoomVert(float zoomVert) { m_ZoomVert = zoomVert; }
  31. protected:
  32. // Utility methods
  33. void Construct(int left, int top, int width, int height, float zoomHorz, float zoomVert)
  34. {
  35. m_Left = left;
  36. m_Top = top;
  37. m_Width = width;
  38. m_Height = height;
  39. m_ZoomHorz = zoomHorz;
  40. m_ZoomVert = zoomVert;
  41. }
  42. protected:
  43. // ROI parameters
  44. int m_Left;
  45. int m_Top;
  46. int m_Width;
  47. int m_Height;
  48. // Zooming parameters
  49. float m_ZoomHorz;
  50. float m_ZoomVert;
  51. };
  52. //
  53. // SapViewCallbackInfo class declaration
  54. //
  55. class SAPCLASSBASIC_CLASS SapViewCallbackInfo
  56. {
  57. public:
  58. SapViewCallbackInfo(SapView *pView, void *context)
  59. { m_pView = pView; m_Context = context; }
  60. ~SapViewCallbackInfo() {}
  61. // Obsolete constructor
  62. SapViewCallbackInfo(void *context)
  63. { m_pView = NULL; m_Context = context; }
  64. SapView *GetView() const { return m_pView; }
  65. void *GetContext() const { return m_Context; }
  66. protected:
  67. SapView *m_pView;
  68. void *m_Context;
  69. };
  70. typedef void (*SapViewCallback)(SapViewCallbackInfo *);
  71. //
  72. // SapView class declaration
  73. //
  74. // Common view window handles
  75. const HWND SapHwndDesktop = (HWND) NULL;
  76. const HWND SapHwndAutomatic = (HWND) -1;
  77. class SAPCLASSBASIC_CLASS SapView : public SapManager
  78. {
  79. public:
  80. // Overlay modes
  81. typedef int OverlayMode;
  82. enum _OverlayMode
  83. {
  84. OverlayNone = 0,
  85. OverlayAlwaysOnTop = CORVIEW_VAL_OVERLAY_MODE_ALWAYS_ON_TOP,
  86. OverlayAutoKeying = CORVIEW_VAL_OVERLAY_MODE_AUTO_COLOR_KEYING,
  87. OverlayManualKeying = CORVIEW_VAL_OVERLAY_MODE_MANUAL_COLOR_KEYING
  88. };
  89. // Scaling modes
  90. enum ScalingMode
  91. {
  92. ScalingNone,
  93. ScalingFitToWindow,
  94. ScalingZoom,
  95. ScalingUserDefined
  96. };
  97. public:
  98. // Constructor/Destructor
  99. #if defined(__BORLANDC__) && !defined(__clang__)
  100. SapView(SapBuffer *pBuffer = NULL, void* hWnd = NULL, SapViewCallback pCallback = NULL, void *pContext = NULL);
  101. #else
  102. SapView(SapBuffer *pBuffer = NULL, HWND hWnd = SapHwndDesktop, SapViewCallback pCallback = NULL, void *pContext = NULL);
  103. #endif
  104. SapView(SapDisplay *pDisplay, SapBuffer *pBuffer, HWND hWnd = SapHwndDesktop, SapViewCallback pCallback = NULL, void *pContext = NULL);
  105. SapView(const SapView &view);
  106. virtual ~SapView();
  107. SapView &operator=(const SapView &view);
  108. // Module create/destroy
  109. virtual BOOL Create();
  110. virtual BOOL Destroy();
  111. // Access to implementation
  112. virtual CORHANDLE GetHandle() const { return m_hView; }
  113. SapBuffer *GetBuffer() const { return m_pBuffers; }
  114. SapDisplay *GetDisplay() const { return m_pDisplay; }
  115. HWND GetWindow() const { return m_hWindow; }
  116. SapViewCallback GetCallback() const { return m_pCallback; }
  117. void *GetContext() const { return m_pContext; }
  118. POINT GetScrollPos() const { return m_ScrollPos; }
  119. SIZE GetScrollRange() const { return m_ScrollRange; }
  120. OverlayMode GetOverlayMode() const { return m_OverlayMode; }
  121. SapDataRGB GetKeyColor() const { return m_KeyColor; }
  122. ScalingMode GetScalingMode() const { return m_ScalingMode; }
  123. BOOL GetImmediateMode() const { return m_bImmediateMode; }
  124. virtual BOOL IsAutoEmpty() const { return m_bAutoEmpty; }
  125. int GetThreadPriority() const { return m_ThreadPriority; }
  126. virtual BOOL SetDisplay( SapDisplay *pDisplay);
  127. virtual BOOL SetBuffer(SapBuffer *pBuffer);
  128. virtual BOOL SetWindow( HWND hWindow);
  129. virtual BOOL SetCallbackInfo( SapViewCallback pCallback, void *pContext= NULL);
  130. virtual int GetWidth();
  131. virtual int GetHeight();
  132. virtual BOOL GetViewArea( int *width, int *height);
  133. int GetIndex() const { return m_Index; }
  134. const SapViewScaleParams& GetScaleParamsDst() { return m_ScaleParamsDst;}
  135. const SapViewScaleParams& GetScaleParamsSrc() { return m_ScaleParamsSrc;}
  136. virtual BOOL IsCapabilityValid(int cap);
  137. virtual BOOL GetCapability(int cap, void *pValue);
  138. virtual BOOL IsParameterValid(int param);
  139. virtual BOOL GetParameter(int param, void *pValue);
  140. virtual BOOL SetParameter(int param, int value);
  141. virtual BOOL SetParameter(int param, void *pValue);
  142. virtual BOOL SetWindowTitle(const char *title);
  143. virtual BOOL GetWindowTitle(char *title);
  144. virtual BOOL SetOverlayMode(OverlayMode overlayMode);
  145. virtual BOOL SetKeyColor(SapDataRGB keyColor);
  146. // Access to display context
  147. virtual BOOL GetDC(HDC *pDC);
  148. virtual BOOL ReleaseDC();
  149. // Display control
  150. virtual void Init();
  151. virtual void Show();
  152. virtual void Show(int index);
  153. virtual void ShowNext();
  154. virtual void Hide();
  155. virtual BOOL HasRange();
  156. virtual int GetRange();
  157. virtual void GetRangeMinMax(int *pRangeMin, int *pRangeMax);
  158. virtual BOOL SetRange(int range);
  159. virtual BOOL SetScalingMode(ScalingMode scalingMode, BOOL bKeepAspectRatio= FALSE, BOOL refreshNow = TRUE);
  160. virtual BOOL SetScalingMode(float zoomHorz, float zoomVert, BOOL refreshNow = TRUE);
  161. virtual BOOL SetScalingMode(const SapViewScaleParams& srcParams, const SapViewScaleParams& dstParams, BOOL refreshNow = TRUE);
  162. virtual void SetAutoEmpty(BOOL isAutoEmpty) { m_bAutoEmpty = isAutoEmpty; }
  163. virtual void SetImmediateMode(BOOL immediateMode) { m_bImmediateMode = immediateMode; }
  164. virtual void SetThreadPriority( int priority) { m_ThreadPriority= priority; if( m_hThread != NULL) ::SetThreadPriority( m_hThread, priority);}
  165. // Look-up table management
  166. SapLut *GetLut() { return m_ViewLut; }
  167. virtual BOOL ApplyLut();
  168. // Message handlers
  169. virtual void OnPaint();
  170. virtual void OnMove();
  171. virtual void OnSize(BOOL refreshNow = TRUE);
  172. virtual void OnHScroll(int hPosition);
  173. virtual void OnVScroll(int vPosition);
  174. // Obsolete methods, kept for backward compatibility
  175. virtual CORHANDLE *GetHandles() const { return (CORHANDLE * const) &m_hView; }
  176. virtual CORHANDLE GetHandle(int index) const { return m_hView; }
  177. virtual CORHANDLE operator[] (int index) const { return m_hView; }
  178. SapBuffer *GetBuffers() const { return GetBuffer(); }
  179. virtual BOOL SetBuffers(SapBuffer *pBuffers) { return SetBuffer(pBuffers) ;}
  180. protected:
  181. // Utility methods
  182. void Construct(SapDisplay *pDisplay, SapBuffer *pBuffer, HWND hWindow, SapViewCallback pCallback, void *pContext, BOOL bAutoEmpty, int threadPriority);
  183. virtual BOOL SetKeyColor();
  184. virtual void DoShow();
  185. virtual void Next();
  186. virtual void SetScrollPosAndRange();
  187. virtual BOOL LoadLut();
  188. static UINT WINAPI ViewThreadProc(LPVOID lpParam);
  189. protected:
  190. // Parameters
  191. SapBuffer *m_pBuffers; // Reference to a buffer object
  192. SapDisplay *m_pDisplay; // Reference to a display object
  193. HWND m_hWindow; // Handle to a Window
  194. SapViewCallback m_pCallback; // Application callback function
  195. void *m_pContext; // Application context
  196. HDC m_hDC; // Windows GDI display context for system display
  197. OverlayMode m_OverlayMode; // Current overlay mode
  198. SapDataRGB m_KeyColor; // Current keying color
  199. BOOL m_bAutomaticWnd; //TRUE if using SapHwndAutomatic
  200. // Look-up table management
  201. int m_LutEntries;
  202. SapFormat m_LutFormat;
  203. SapLut *m_ViewLut;
  204. // Other variables
  205. ScalingMode m_ScalingMode; // Controls how images fit in the view window
  206. BOOL m_bKeepAspectRatio;
  207. SapViewScaleParams m_ScaleParamsSrc; // Source parameters for user-defined scaling mode
  208. SapViewScaleParams m_ScaleParamsDst; // Destination parameters for user-defined scaling mode
  209. POINT m_ScrollPos; // Current scrolling position
  210. SIZE m_ScrollRange; // Current scrolling range
  211. int m_Width; // Displayable width
  212. int m_Height; // Displayable height
  213. int m_ViewAreaWidth; // Viewing area width
  214. int m_ViewAreaHeight; // Viewing area height
  215. BOOL m_bAutoEmpty; // TRUE to automatically empty buffers
  216. BOOL m_bDisplayFree; // TRUE if display object is owned by the view object
  217. BOOL m_bImmediateMode; // TRUE if image display does not go through a separate thread
  218. BOOL m_IsDispBanditII; // TRUE if displaying on a Bandit II
  219. // View thread management
  220. int m_Index; // Index of the last displayed buffer
  221. int m_NextIndex; // Index of the next buffer to display
  222. HANDLE m_hThread; // Thread handle
  223. int m_ThreadPriority; // Thread priority
  224. HANDLE m_hStartEvent; // Signaled by the thread after it is started
  225. HANDLE m_hExitEvent; // When signaled, causes the thread to exit
  226. HANDLE m_hViewEvent; // Signaled when a buffer is ready to be displayed
  227. HANDLE m_hIdleEvent; // Signaled by the thread when it has no work to do
  228. LONG m_BuffersLeft; // Number of buffers left to display by the thread
  229. // Sapera view handle
  230. CORVIEW m_hView;
  231. };
  232. #endif // _SAPVIEW_H_