00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "stdafx.h"
00020
00021 #include <cfl/ControlHistogramCtrl.h>
00022
00023 #ifdef _DEBUG
00024 #define new DEBUG_NEW
00025 #undef THIS_FILE
00026 static char THIS_FILE[] = __FILE__;
00027 #endif
00028
00029 IMPLEMENT_DYNAMIC( CHistogramCtrl, CStatic )
00030
00031 const COLORREF DefaultBgColor = GetSysColor( COLOR_BTNFACE );
00032 const COLORREF DefaultBinColor = RGB( 100, 100, 100 );
00033 const COLORREF DefaultCursorColor = RGB( 255, 150, 150 );
00034
00035
00036
00037
00038 CHistogramCtrl::~CHistogramCtrl()
00039 {
00040 ;
00041 }
00042
00043
00044
00045
00046 CHistogramCtrl::CHistogramCtrl()
00047 : m_autoscale ( true )
00048 , m_horCursorOn( false )
00049 , m_verCursorOn( false )
00050 , m_horCursor ( -1 )
00051 , m_verCursor1 ( -1 )
00052 , m_verCursor2 ( -1 )
00053 , m_cursorColor( DefaultCursorColor )
00054 , m_binColor ( DefaultBinColor )
00055 , m_bgColor ( DefaultBgColor )
00056 {
00057 ;
00058 }
00059
00060
00061
00062
00063 int CHistogramCtrl::GetNumberOfBins() const
00064 {
00065 return m_histogram.GetSize();
00066 }
00067
00068
00069
00070
00071 int CHistogramCtrl::GetMaximumCount() const
00072 {
00073 return m_histogram.GetMaximum().count;
00074 }
00075
00076
00077
00078
00079 void CHistogramCtrl::SetHistogram( const HistogramType& histogram )
00080 {
00081 m_histogram = histogram;
00082 RedrawWindow();
00083 }
00084
00085
00086
00087
00088 void CHistogramCtrl::SetAutoscale( bool autoscale )
00089 {
00090 m_autoscale = autoscale;
00091 }
00092
00093
00094
00095
00096 void CHistogramCtrl::SetFullscale( bool fullscale )
00097 {
00098 m_fullscale = fullscale;
00099 }
00100
00101
00102
00103
00104 void CHistogramCtrl::EnableHorizontalCursor( bool enable )
00105 {
00106 m_horCursorOn = enable;
00107 }
00108
00109
00110
00111
00112 void CHistogramCtrl::SetHorizontalCursor( int percentage )
00113 {
00114 m_horCursor = percentage;
00115 }
00116
00117
00118
00119
00120 void CHistogramCtrl::EnableVerticalCursor( bool enable )
00121 {
00122 m_verCursorOn = enable;
00123 }
00124
00125
00126
00127
00128 void CHistogramCtrl::SetVerticalCursor1( int percentage )
00129 {
00130 m_verCursor1 = percentage;
00131 }
00132
00133
00134
00135
00136 void CHistogramCtrl::SetVerticalCursor2( int percentage )
00137 {
00138 m_verCursor2 = percentage;
00139 }
00140
00141
00142
00143
00144 void CHistogramCtrl::SetBinColor( COLORREF bincolor )
00145 {
00146 m_binColor = bincolor;
00147 }
00148
00149
00150
00151
00152 void CHistogramCtrl::SetCursorColor( COLORREF cursorcolor )
00153 {
00154 m_cursorColor = cursorcolor;
00155 }
00156
00157
00158
00159
00160 void CHistogramCtrl::SetBgColor( COLORREF bgcolor )
00161 {
00162 m_bgColor = bgcolor;
00163 }
00164
00165
00166
00167
00168 BEGIN_MESSAGE_MAP(CHistogramCtrl, CStatic)
00169
00170 ON_WM_ERASEBKGND()
00171 ON_WM_DRAWITEM()
00172 ON_WM_PAINT()
00173
00174 ON_WM_CREATE()
00175 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
00176
00177 END_MESSAGE_MAP()
00178
00179
00180
00181
00182 BOOL CHistogramCtrl::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult )
00183 {
00184 return CStatic::OnNotify( wParam, lParam, pResult );
00185 }
00186
00187
00188
00189
00190 BOOL CHistogramCtrl::Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext )
00191 {
00192 return CWnd::Create( lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext );
00193 }
00194
00195
00196
00197
00198 LRESULT CHistogramCtrl::WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
00199 {
00200 return CStatic::WindowProc( message, wParam, lParam );
00201 }
00202
00203
00204
00205
00206 BOOL CHistogramCtrl::OnEraseBkgnd( CDC* pDC )
00207 {
00208 CRect rc;
00209 GetClientRect( rc );
00210
00211 const int vspace = 2;
00212 const int winwidth = rc.Width();
00213 const int winheight = rc.Height();
00214
00215 const int hgmheight = winheight - 2 * vspace;
00216
00217 const double scale_factor = GetMaximumCount()
00218 ? static_cast<double>( hgmheight ) / GetMaximumCount() : 1;
00219
00220 const int barwidth = winwidth / GetNumberOfBins();
00221 const int hgmwidth = barwidth * GetNumberOfBins();
00222
00223 const int xoffset = ( winwidth - hgmwidth ) / 2;
00224 const int yoffset = vspace;
00225
00226
00227
00228
00229 pDC->FillSolidRect( 0, 0, winwidth, winheight, m_bgColor );
00230
00231
00232
00233
00234 {for( int i = 0; i < GetNumberOfBins(); ++i )
00235 {
00236 const int value = static_cast<int>( 0.5 + scale_factor * m_histogram.GetBinCount( i ) );
00237
00238 const int x = i * barwidth + xoffset;
00239 const int w = barwidth;
00240 const int y = winheight - value - yoffset;
00241 COLORREF white = RGB(255,255,255);
00242
00243
00244 pDC->Draw3dRect ( x, y, w, value, white, m_binColor );
00245 }}
00246
00247 if ( m_horCursorOn && 0 <= m_horCursor && m_horCursor <= 100 )
00248 {
00249 const int y = yoffset + static_cast<int>( 0.5 + 0.01 * m_horCursor * hgmheight );
00250
00251 pDC->FillSolidRect( xoffset, y, hgmwidth, 1, m_cursorColor );
00252 }
00253
00254 if ( m_verCursorOn && 0 <= m_verCursor1 && m_verCursor1 <= 100 )
00255 {
00256 const int x = xoffset + static_cast<int>( 0.5 + 0.01 * m_verCursor1 * hgmwidth );
00257
00258 pDC->FillSolidRect( x, yoffset, 1, hgmheight, m_cursorColor );
00259 }
00260
00261 if ( m_verCursorOn && 0 <= m_verCursor2 && m_verCursor2 <= 100 )
00262 {
00263 const int x = xoffset + static_cast<int>( 0.5 + 0.01 * m_verCursor2 * hgmwidth );
00264
00265 pDC->FillSolidRect( x, yoffset, 1, hgmheight, m_cursorColor );
00266 }
00267
00268 return CStatic::OnEraseBkgnd( pDC );
00269 }
00270
00271
00272
00273
00274 void CHistogramCtrl::OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct )
00275 {
00276 CStatic::OnDrawItem( nIDCtl, lpDrawItemStruct );
00277 }
00278
00279
00280
00281
00282 void CHistogramCtrl::OnPaint()
00283 {
00284 CPaintDC dc(this);
00285
00286
00287 }
00288
00289
00290
00291
00292 int CHistogramCtrl::OnCreate( LPCREATESTRUCT lpCreateStruct )
00293 {
00294 if ( -1 == CStatic::OnCreate(lpCreateStruct) )
00295 {
00296 return -1;
00297 }
00298
00299
00300
00301 return 0;
00302 }
00303
00304
00305
00306
00307 void CHistogramCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
00308 {
00309 LPNMCUSTOMDRAW lpcd = ( LPNMCUSTOMDRAW ) pNMHDR;
00310
00311
00312 switch( lpcd->dwDrawStage )
00313 {
00314 case CDDS_PREPAINT:
00315 *pResult = CDRF_NOTIFYITEMDRAW;
00316 break;
00317
00318 case CDDS_ITEMPREPAINT:
00319 if ( lpcd->dwItemSpec == TBCD_THUMB )
00320 {
00321 *pResult = CDRF_DODEFAULT;
00322 break;
00323 }
00324 break;
00325 }
00326 }
00327
00328
00329
00330
00331 BOOL CHistogramCtrl::PreCreateWindow( CREATESTRUCT& cs )
00332 {
00333 return CStatic::PreCreateWindow( cs );
00334 }
00335
00336
00337
00338