home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / microcrn / issue_51.arc / DISPLAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-06  |  3.3 KB  |  95 lines

  1. /* DISPLAY.C : Functions to support displaying a voice pattern on the 
  2.    screen using the Borland BGI graphics functions.  
  3.    Bruce Eckel, Revolution2 Real-Time Consulting.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdarg.h>  /* va_start(), etc. */
  8. #include <string.h>
  9. #include <math.h>
  10. #include "capture.h"
  11. #include "display.h"
  12.  
  13. /* This is a "printf"-like function for printing messages while
  14. using the BGI in graphics mode.  It is limited because it always
  15. starts at the left and doesn't wrap at the bottom of the screen,
  16. but it is useful for debugging. */
  17. void gprintf(char * format, ...) {  /* graphics printf for BGI */
  18.   static int textline = 0;
  19.   char textbuf[80];
  20.   va_list argptr;
  21.   va_start(argptr, format);
  22.   vsprintf(textbuf, format, argptr);
  23.   va_end(argptr);
  24.   outtextxy(0,textline, textbuf);
  25.   textline += textheight("x");  /* move to the next line */
  26. }
  27.  
  28. void display_series(unsigned * series, int series_size,
  29.     int offset,
  30.     scale_factor vertical_scale_factor,
  31.     scale_factor horizontal_scale_factor,
  32.     int color) {
  33.   int i, j, step;
  34.   /* create a local copy of the array: */
  35.   int * lseries = (int *) calloc(series_size, sizeof(int));
  36.   memcpy(lseries, series, series_size * sizeof(int));
  37.   /* First, perform vertical scaling of the local array: */
  38.   switch(vertical_scale_factor) {
  39.     case quarter: for(i = 0; i < series_size; i++)
  40.             lseries[i] >>= 2;  /* divide by 4 */
  41.           break;
  42.     case half:    for(i = 0; i < series_size; i++)
  43.             lseries[i] >>= 1;  /* divide by 2 */
  44.           break;
  45.     case full:    break;  /* no change */
  46.     case twice:  for(i = 0; i < series_size; i++)
  47.             lseries[i] <<= 1;  /* multiply by 2 */
  48.           break;
  49.     case quad:    for(i = 0; i < series_size; i++)
  50.             lseries[i] <<= 2;  /* multiply by 4 */
  51.           break;
  52.   }
  53.   if(offset)
  54.     for(i = 0; i < series_size; i++)
  55.       lseries[i] += offset;
  56.   /* Now display the array according to the horizontal scale factor: */
  57.   switch(horizontal_scale_factor) {
  58.     /* display a part of the series in the whole space: */
  59.     case quarter: for(i = 0; i < (series_size/4); i++)
  60.             putpixel(i<<2,lseries[i], color);
  61.           break;
  62.     case half:    for(i = 0; i < (series_size/2); i++)
  63.             putpixel(i<<1,lseries[i], color);
  64.           break;
  65.     /* display the whole series in the whole space: */
  66.     case full:    for(i = 0; i < series_size; i++)
  67.             putpixel(i,lseries[i], color);
  68.           break;
  69.     /* display the whole series in a smaller space: */
  70.     case twice:  for(i = 0; i < (series_size/2); i++)
  71.             putpixel(i, lseries[i<<1], color);
  72.           break;
  73.     case quad:    for(i = 0; i < (series_size/4); i++)
  74.             putpixel(i,lseries[i<<2], color);
  75.           break;
  76.   }
  77.   free(lseries);  /* release local copy of the array */
  78. }
  79.  
  80. void display_viewsettings(struct viewporttype view) {
  81.   /* The following macro was used during debugging to display all the
  82.    viewport settings.  Notice the use of the new ANSI C preprocessor
  83.    directives: the "stringize" directive (#) which takes the argument
  84.    and makes it into a string, and the "paste" directive (##) which
  85.    takes two names and creates a variable name from them.  Notice also
  86.    that in:
  87.    #arg " = %d"
  88.    the preprocessor concatenates the two strings together.
  89.   */
  90.   
  91.   #define P(arg) gprintf(#arg " = %d", view.##arg)
  92.   P(left); P(right); P(top); P(bottom); P(clip);
  93.   getch();
  94. }
  95.