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

  1. #include "stdafx.h"
  2. #include "tracker.h"
  3.  
  4. #include "mainfrm.h"
  5. #include "gtkformat.h"
  6. #include "trackerDoc.h"
  7. #include "trackerView.h"
  8.  
  9. #include <math.h>
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. static int kfx_floor(float x)
  18. {
  19.     int xi;
  20.     WORD old_fpcw,new_fpcw;
  21.     __asm
  22.     {
  23.         fld     x
  24.         fwait
  25.         fnstcw  old_fpcw
  26.         fwait
  27.         mov     ax,old_fpcw
  28.         or      ah,0x0c
  29.         mov     new_fpcw,ax
  30.         fldcw   new_fpcw
  31.         fistp   xi
  32.         fldcw   old_fpcw
  33.         mov     eax,xi
  34.         cmp     eax,0
  35.         jg      noadd
  36.         inc     eax
  37.     noadd:
  38.         mov     xi,eax
  39.     }
  40.     return xi;
  41. }
  42.  
  43.  
  44. static char note_table[12*6+1][4]=
  45. {
  46.   "---",
  47.   "C-1","C#1","D-1","D#1","E-1","F-1","F#1","G-1","G#1","A-1","A#1","B-1",
  48.   "C-2","C#2","D-2","D#2","E-2","F-2","F#2","G-2","G#2","A-2","A#2","B-2",
  49.   "C-3","C#3","D-3","D#3","E-3","F-3","F#3","G-3","G#3","A-3","A#3","B-3",
  50.   "C-4","C#4","D-4","D#4","E-4","F-4","F#4","G-4","G#4","A-4","A#4","B-4",
  51.   "C-5","C#5","D-5","D#5","E-5","F-5","F#5","G-5","G#5","A-5","A#5","B-5",
  52.   "C-6","C#6","D-6","D#6","E-6","F-6","F#6","G-6","G#6","A-6","A#6","B-6"
  53. };
  54.  
  55. static int x_size_array[4]=
  56. {
  57.     0,0,0,0,
  58. };
  59. void CPatternView::DrawPattern(CDC *pDC)
  60. {
  61.     CTrackerDoc* pDoc = GetDocument();
  62.     ASSERT_VALID(pDoc);
  63.  
  64.     if (!pDoc->synth || ! pDoc->pl)
  65.         return;
  66.  
  67.     CRect rect;
  68.     int xpostab[]={0,30,50,70};
  69.     int xpos,i,j,patStart;
  70.     CGdiObject *oldstock;
  71.  
  72.  
  73.     int x_offset;
  74.     int x_spacing;
  75.     int x_row_spacing;
  76.     int y_col_spaceing;
  77.     CSize char_size;
  78.  
  79.     // TODO: add draw code for native data here
  80.  
  81.     pDC->SetBkColor  (RGB(0,0,0));
  82.     pDC->SetBkMode (TRANSPARENT);
  83.     pDC->SetTextColor (pDoc->ctrl_text);
  84.  
  85.     // lets shrink window for tracker data    
  86.     pDC->SetViewportOrg (0,128);
  87.     GetClientRect (&rect);
  88.     rect.bottom-=(128);
  89.  
  90.  
  91.  
  92.     CFont font;
  93.     font.CreateFont(11,0,0,0,0,0,0,0,0,00,0,0,0,"Lucida Console");
  94. //    oldstock = pDC->SelectStockObject (SYSTEM_FIXED_FONT);
  95.     oldstock = pDC->SelectObject (&font);
  96.     // hackeli-hack..  try to figure out the spacing between chars..
  97.     // use "M" as reference char...
  98.     char_size = pDC->GetTextExtent("M");
  99.  
  100.     x_offset = char_size.cx * 2 + rect.left;
  101.     y_col_spaceing = char_size.cy;
  102.  
  103.     xpostab[0] = 0 + rect.left;
  104.     xpostab[1] = xpostab[0] + 3 * char_size.cx;    
  105.     xpostab[2] = xpostab[1] + 2 * char_size.cx;    
  106.     xpostab[3] = xpostab[2] + 2 * char_size.cx;    
  107.  
  108.     x_row_spacing = (2+2+2+3+1) * char_size.cx;
  109.  
  110.     ///-----------------------
  111.     patStart = patScroller.GetScrollPos ();
  112.  
  113.  
  114.  
  115.     // draw tracker bar
  116.     pDC->FillSolidRect (rect.left,rect.top, rect.Width (), y_col_spaceing,pDoc->ctrl_bg);
  117.     pDC->Draw3dRect (rect.left,rect.top, rect.Width (), y_col_spaceing,pDoc->ctrl_light,pDoc->ctrl_dark);
  118.  
  119.     j =  pDoc->gtk->channels[seqCursor.col].positions[seqCursor.pos].pattern;
  120.     for (i=patStart;i<16;i++)
  121.     {
  122.         char tmp[64];
  123.         if (!j) sprintf (tmp,"empty");
  124.         else sprintf (tmp,"%02x:%02d",j,i);
  125.  
  126. //        pDC->TextOut ((i-patStart)*x_row_spacing+rect.left+25,0,tmp);
  127.         pDC->TextOut ((i-patStart)*x_row_spacing+rect.left+x_offset,0,tmp);
  128.     }
  129. //------------------------------
  130.     
  131.     pDC->SetViewportOrg (0,128+y_col_spaceing);
  132.     GetClientRect (&rect);
  133.     rect.bottom-=(128+y_col_spaceing*2);
  134.  
  135.     // draw lousy stuff beetween each track...
  136. //    xpos = rect.left + 20;
  137.     xpos = x_offset;
  138.     for (i=0;i<16;i++)
  139.     {
  140. //        pDC->Draw3dRect (xpos+i*95,rect.top,2,rect.Height (),pDoc->ctrl_light,pDoc->ctrl_dark);        
  141. //        if (xpos+i*95 > rect.right) break;
  142.         pDC->Draw3dRect (xpos+i*x_row_spacing,rect.top,2,rect.Height (),pDoc->ctrl_light,pDoc->ctrl_dark);        
  143.         if (xpos+i*x_row_spacing > rect.right) break;
  144.     }
  145.  
  146.  
  147.     int middle;
  148.     middle = ((int)(rect.Height ()/2.0) - y_col_spaceing / 2.0f);
  149.  
  150. // draw middle "edit" bar
  151.     pDC->FillSolidRect (rect.left,middle, rect.Width (), y_col_spaceing,pDoc->ctrl_bg);
  152.     pDC->Draw3dRect (rect.left,middle, rect.Width (), y_col_spaceing,pDoc->ctrl_light,pDoc->ctrl_dark);
  153.  
  154.  
  155.     x_offset += char_size.cx;
  156.     // draw cursor
  157.     xpos = (patCursor.col-patStart)*x_row_spacing+x_offset;
  158.  
  159.     if (isPatternEdit && (!pDoc->playing))
  160.     {
  161.         if (!patCursor.rowcol)
  162.         {
  163.             pDC->FillSolidRect (xpos,middle,xpostab[1] - xpostab[0],y_col_spaceing,pDoc->ctrl_cursor);    
  164.         } else
  165.             {
  166.                 if ((patCursor.rowcol-1) & 1) xpos+=char_size.cx;
  167.  
  168.                 xpos = xpos + xpostab[((patCursor.rowcol-1)>>1)+1];
  169.                 pDC->FillSolidRect (xpos,middle,char_size.cx,y_col_spaceing,pDoc->ctrl_cursor);
  170.  
  171.             }
  172.     }
  173.   
  174. // Draw pattern data
  175.     pDC->SetTextColor (pDoc->ctrl_text);
  176.  
  177.  
  178.  
  179.     char buf[16];
  180.     int pos_start;
  181.     int edt_mode;
  182.     int ep1,ep2,ec1,ec2;
  183.     COLORREF curscol; 
  184.  
  185.     if (!pDoc->playing)
  186.         pos_start = patCursor.pos;
  187.     else 
  188.         pos_start = pDoc->play_patternrow;
  189.  
  190.     
  191.     pos_start =  -pos_start * y_col_spaceing + middle;
  192.     pDC->SetTextColor (pDoc->ctrl_text);
  193.  
  194.  
  195.     GTK_PATTERN *pattern;
  196.     GTK_PATTERNPOS *patpos;
  197.     int num;
  198.     if (!pDoc->playing)
  199.         num = pDoc->gtk->channels[seqCursor.col].positions[seqCursor.pos].pattern;
  200.     else
  201.         num = pDoc->play_pattern;
  202.  
  203.     pattern = &pDoc->gtk->patterns[num];
  204.  
  205.  
  206. //    lets draw the "numbers"
  207.     for (i=0;i<pattern->len;i++)
  208.     {
  209.  
  210.         if ((i*y_col_spaceing + pos_start)> rect.top)
  211.         {
  212.             sprintf (buf,"%02x",i);
  213.             pDC->TextOut (0,i*y_col_spaceing + pos_start,buf);
  214.         }
  215.         if ((i*y_col_spaceing + pos_start)> rect.bottom) break;
  216.     }
  217.  
  218.   // If we are in block copy mode, find out which row/col 
  219.   // that should be marked..
  220.     #define mswap(a,b) {int tmp; tmp=(a);(a)=(b);(b)=tmp;}
  221.     if (pDoc->editData.state == GTK_EDITSTATE_PATTERNSELECT)
  222.     {
  223.         ep1 = pDoc->editData.beginmark.pos;
  224.         ep2 = pDoc->editData.endmark.pos;
  225.         if (ep1 > ep2)
  226.               mswap(ep1,ep2);
  227.  
  228.         ec1 = pDoc->editData.beginmark.col;
  229.         ec2 = pDoc->editData.endmark.col;
  230.         if (ec1 > ec2)
  231.             mswap(ec1,ec2);
  232.     }
  233.     #undef mswap
  234.  
  235.     //    lets draw each channel
  236.     edt_mode=0;
  237.     ///for (j=0;j<64;j++)
  238.     for (j=0;j<pattern->len;j++)
  239.     {
  240.  
  241.         if ((y_col_spaceing*j + pos_start) < rect.top)
  242.             continue;
  243.         if ((y_col_spaceing*j + pos_start) > rect.bottom)
  244.             continue;
  245.  
  246.  
  247.         patpos = pattern->patterndata[j];
  248.         curscol=pDoc->ctrl_text;
  249.         if (pDoc->editData.state == GTK_EDITSTATE_PATTERNSELECT)
  250.         {
  251.             edt_mode=0;
  252.             if ((j >= ep1) && (j <= ep2))
  253.             {
  254.               edt_mode=1;
  255.               curscol = pDoc->ctrl_marktext;
  256.             }
  257.         }
  258.         
  259.         for (i=patStart;i<16;i++)
  260.         {
  261.             xpos = (i-patStart)*x_row_spacing+x_offset;
  262.             if (!edt_mode)
  263.             {
  264.                 if (i == patCursor.col)    pDC->SetTextColor (pDoc->ctrl_curtext);
  265.                 else    pDC->SetTextColor (pDoc->ctrl_text);
  266.       
  267.             } else
  268.                 {
  269.                   if ((i>=ec1) && (i<=ec2))
  270.                     pDC->SetTextColor (curscol);          
  271.                   else 
  272.                     pDC->SetTextColor (pDoc->ctrl_text);          
  273.       
  274.                 } // else
  275.  
  276.             if (patpos[i].note == GTK_NOTE_OFF)
  277.             {
  278.                 sprintf (buf,"off");
  279.             } else
  280.                 {
  281.                     if (patpos[i].note > 12*6)
  282.                         sprintf (buf,"???");
  283.                     else
  284.                         sprintf (buf,note_table[patpos[i].note]);
  285.                 }
  286.             pDC->TextOut (xpos+xpostab[0],j*y_col_spaceing + pos_start,buf);
  287.             
  288.             // DAN!! fixa en sσn dΣr instΣllningsbar grej f÷r varje sσn hΣr RGB!
  289.             sprintf (buf,"%02x",patpos[i].velocity);
  290.             pDC->SetTextColor(RGB(0xFF,0xFF,0x40));
  291.             pDC->TextOut (xpos+xpostab[1],j*y_col_spaceing + pos_start,buf);
  292.  
  293.             sprintf (buf,"%02x",patpos[i].fx);
  294.             pDC->SetTextColor(RGB(0xE0,0xFF,0xFF));
  295.             pDC->TextOut (xpos+xpostab[2],j*y_col_spaceing + pos_start,buf);
  296.  
  297.             sprintf (buf,"%02x",patpos[i].param);
  298.             pDC->SetTextColor(RGB(0x80,0xFF,0x60));
  299.             pDC->TextOut (xpos+xpostab[3],j*y_col_spaceing + pos_start,buf);            
  300.             if ((i-patStart)*x_row_spacing+rect.left > rect.right) break;
  301.         }
  302.         if ((j*y_col_spaceing + pos_start) > rect.bottom) break;
  303.  
  304.     }
  305.  
  306.   pDC->SelectObject(oldstock);
  307. } // drawTrk
  308.