home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / dev / src / wavetools_dev.lha / wavetools / DadMon / Interface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-12  |  3.8 KB  |  158 lines

  1. /*
  2. ** All the interface stuff
  3. ** put here
  4. **
  5. **
  6. */
  7.  
  8. #include <intuition/intuitionbase.h>
  9. #include <exec/nodes.h>
  10. #include <exec/tasks.h>
  11. #include <libraries/dos.h>
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16.  
  17. #define HASH_PEN    0            /* Pen used for hash lines.*/
  18.  
  19. #define MaxValue 65536    /* if unsigned 16 bit samples but they could be signed */
  20.  
  21. /*****************************************************
  22. **  Static variabler som funktionerna kan arbeta på.**
  23. **  Interfacets "state"                             **
  24. *****************************************************/
  25.  
  26.     static LONG height,width,left,right,top,bottom;
  27.     static ULONG int_steps_per_pixel;
  28.     static int whitepen,blackpen;
  29.     static short pen,minpen,maxpen;
  30.     static unsigned short RGB;
  31.     static int class;
  32.         static struct Window *CustWindow;
  33.  
  34. #define rp CustWindow->RPort
  35. #define bl CustWindow->BorderLeft
  36. #define bt CustWindow->BorderTop
  37. #define br CustWindow->BorderRight
  38. #define bb CustWindow->BorderBottom
  39. #define ww CustWindow->Width
  40. #define wh CustWindow->Height
  41.  
  42.  
  43. struct MsgPort *OpenFace(WIN_LEFT, WIN_TOP, WIN_WIDTH,WIN_HEIGHT){
  44.     struct Screen *PubScreen;
  45.     LONG n;
  46.         WORD zoom_words[4] = {WIN_LEFT, WIN_TOP, WIN_WIDTH, PubScreen->WBorTop + PubScreen->Font->ta_YSize + 1};
  47.  
  48.     PubScreen = (struct Screen *)LockPubScreen(NULL);
  49.     CustWindow = (struct Window *)OpenWindowTags(NULL,
  50.                     WA_Left,    WIN_LEFT,
  51.                     WA_Top,        WIN_TOP,
  52.                     WA_Width,    WIN_WIDTH,
  53.                     WA_Height,    WIN_HEIGHT,
  54.                     WA_MinWidth,50,
  55.                     WA_MinHeight,25,
  56.                     WA_IDCMP,    CLOSEWINDOW | NEWSIZE | CHANGEWINDOW,
  57.                     WA_Flags,    ACTIVATE | SMART_REFRESH | WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH,
  58.                     WA_Title,    "DadMon",
  59.                     WA_PubScreen,PubScreen,
  60.                     WA_Zoom,    zoom_words,
  61.                     NULL);
  62.     UnlockPubScreen(NULL,PubScreen);
  63.     CustWindow->MinHeight = bt;
  64.     whitepen = 1;
  65.     blackpen = 0;
  66.     maxpen = 0x000;
  67.     minpen = 0xfff;
  68.     for (n = 0; n < (1 << PubScreen->BitMap.Depth); n++) {
  69.         RGB = GetRGB4(PubScreen->ViewPort.ColorMap,n);
  70.         pen = (RGB & 0x00f) + ((RGB & 0x0f0) >> 4) + ((RGB & 0xf00) >> 8);
  71.         if (pen < minpen) {
  72.             minpen = pen;
  73.             blackpen = n;
  74.         }
  75.         if (pen > maxpen) {
  76.             maxpen = pen;
  77.             whitepen = n;
  78.         }
  79.     }
  80.  
  81.     height = wh - bt - bb;
  82.     width  = ww - br - bl;
  83.     left   = bl;
  84.     right  = left + width - 1;
  85.     top    = bt;
  86.     bottom = bt + height - 1;
  87.  
  88.      /*FreshFace(void);*/    /* fresh up face */
  89.     return(CustWindow->UserPort);
  90. }
  91.  
  92.  
  93. void MoveFace(WORD left_sample,WORD right_sample){
  94.     WORD low_base,high_base;
  95.     int left,right;
  96.  
  97.         if (wh > bt) {
  98.         height = wh - bt - bb;
  99.         width  = ww - br - bl;
  100.         left   = bl;
  101.         right  = left + width - 1;
  102.         top    = bt;
  103.         bottom = bt + height - 1;
  104.             int_steps_per_pixel = MaxValue/height; /* Max=65535 */
  105.             low_base = bottom ;
  106.                 high_base= top + height/2;
  107.         ScrollRaster(rp,1,0,left,top,right,bottom);
  108.  
  109.  
  110.         left_sample = abs(left_sample);
  111.         Move(rp,right,high_base);
  112.         SetAPen(rp,blackpen);
  113.         Draw(rp, right, high_base - (left_sample/int_steps_per_pixel));
  114.         SetAPen(rp,whitepen);
  115.         Draw(rp,right,top);
  116.  
  117.         SetAPen(rp,blackpen);
  118.         right_sample = abs(right_sample);
  119.                Move(rp,right,low_base);
  120.         Draw(rp, right, low_base - (right_sample/int_steps_per_pixel));
  121.         SetAPen(rp,whitepen);
  122.         Draw(rp,right,high_base);
  123.  
  124.  
  125.         SetAPen(rp, HASH_PEN);
  126.         Move(rp, left,high_base);
  127.         Draw(rp, right, high_base);
  128.         Move(rp, left, top + height/2);
  129.         Draw(rp, right, top + height/2);
  130.         Move(rp, left, low_base);
  131.         Draw(rp, right, low_base);
  132.  
  133.  
  134.     }
  135. }
  136.  
  137.  
  138. void FreshFace(void){
  139.  
  140.       if (wh > bt) {
  141.         SetAPen(rp,whitepen);
  142.         RectFill(rp,left,top,right,bottom);
  143.         SetAPen(rp, HASH_PEN);
  144.         Move(rp, left, top + height/4);
  145.         Draw(rp, right, top + height/4);
  146.         Move(rp, left, top + height/2);
  147.         Draw(rp, right, top + height/2);
  148.         Move(rp, left, top + 3*height/4);
  149.         Draw(rp, right, top + 3*height/4);
  150.     }
  151.  
  152. }
  153.  
  154. void CloseFace(void){
  155.     if (CustWindow)
  156.         CloseWindow(CustWindow);
  157. }
  158.