home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / beaversweeper_v101.zip / src / RawSampleView.cpp < prev    next >
C/C++ Source or Header  |  2003-01-06  |  3KB  |  126 lines

  1. // RawSampleView.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tracker.h"
  6. #include "RawSampleView.h"
  7. #include "isSamplePool.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CRawSampleView
  17.  
  18. CRawSampleView::CRawSampleView()
  19. {
  20.     m_sample = 0;
  21. }
  22.  
  23. CRawSampleView::~CRawSampleView()
  24. {
  25. }
  26.  
  27.  
  28. BEGIN_MESSAGE_MAP(CRawSampleView, CWnd)
  29.     //{{AFX_MSG_MAP(CRawSampleView)
  30.     ON_WM_PAINT()
  31.     //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33.  
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CRawSampleView message handlers
  37.  
  38. void CRawSampleView::OnPaint() 
  39. {    
  40.     CPaintDC dc(this); // device context for painting    
  41.     RECT dcr;
  42.     CWnd::GetClientRect( &dcr );
  43.     
  44.     // TODO: Add your message handler code here    
  45.     CDC dcc;
  46.     dcc.CreateCompatibleDC(0);
  47.     CBitmap bmp;
  48.     bmp.CreateCompatibleBitmap( &dc, dcr.right, dcr.bottom );
  49.     dcc.SelectObject( &bmp );
  50.     CDC* pDC = &dcc;
  51.     pDC->PatBlt( 0, 0, dcr.right, dcr.bottom, BLACKNESS );
  52.  
  53.  
  54.     if (m_sample && m_sample->buffer) {
  55.  
  56.  
  57.  
  58.         CGdiObject *old_pen;
  59.  
  60.  
  61.         DWORD col1 = RGB(0,255,0);
  62.         DWORD col2 = RGB(255,255,255);
  63.  
  64.         CPen pen1( PS_SOLID, 1, col1 );
  65.         CPen pen2( PS_SOLID, 1, col2 );
  66.  
  67.         old_pen = pDC->SelectObject( &pen1 );
  68.  
  69.         for (int x=dcr.left;x<dcr.right;x++) {
  70.  
  71.             int _xp = x - dcr.left;
  72.             int sample1 = _xp * m_sample->sampleLength / (dcr.right - dcr.left);
  73.             int sample2 = (_xp+1) * m_sample->sampleLength / (dcr.right - dcr.left);
  74.  
  75.             if (sample1<0) sample1=0;
  76.             if (sample1>=m_sample->sampleLength) sample1=m_sample->sampleLength-1;
  77.  
  78.             int yc = int( float(dcr.top - dcr.bottom) * m_sample->buffer[ sample1 ] );
  79.             if (yc<1)yc=1;
  80.  
  81.             pDC->MoveTo( x, (dcr.top + dcr.bottom - yc) / 2 );
  82.             pDC->LineTo( x, (dcr.top + dcr.bottom + yc) / 2 );
  83.  
  84.  
  85.             bool drawline = false;
  86.  
  87.              if (m_sample->loopStart >= sample1 && m_sample->loopStart < sample2)
  88.                 drawline = true;
  89.             if (m_sample->loopEnd >= sample1 && m_sample->loopEnd < sample2)
  90.                 drawline = true;
  91.  
  92.  
  93.             if (true == drawline) {
  94.                 pDC->SelectObject( &pen2 );
  95.                 pDC->MoveTo( x, dcr.top );
  96.                 pDC->LineTo( x, dcr.bottom );
  97.                 pDC->SelectObject( &pen1 );
  98.             }
  99.  
  100.         }
  101.  
  102.         pDC->SelectObject( old_pen );
  103.     
  104.     }
  105.  
  106.     
  107.  
  108.     dc.BitBlt( 0, 0, dcr.right, dcr.bottom, pDC, 0, 0, SRCCOPY );
  109.     bmp.DeleteObject();
  110.     dcc.DeleteDC();
  111.  
  112.     // Do not call CWnd::OnPaint() for painting messages
  113. }
  114.  
  115.  
  116. void CRawSampleView::setSample( isSamplePool::Sample *sample)
  117. {
  118.     m_sample = sample;
  119. }
  120.  
  121. void CRawSampleView::update(void)
  122. {
  123.     Invalidate(FALSE);
  124.     UpdateWindow();
  125. }
  126.