home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / v / vpoint.zip / AJGFUNS.C < prev    next >
C/C++ Source or Header  |  1993-02-01  |  11KB  |  497 lines

  1.  
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <graph.h>
  7. #include <time.h>
  8. #include "\qc25\toolbox\getkey.h"
  9.  
  10. #include "\qc25\toolbox\sound.h"
  11. #include "\qc25\bin\ajgfun.h"
  12. #include "mousefun.h"
  13.  
  14. boolean regfonts2(void);
  15. color_t c_array2[16] = {
  16.             _BLACK, _BLUE, _GREEN, _CYAN, _RED, _MAGENTA, _BROWN,
  17.             _WHITE, _GRAY, _LIGHTBLUE, _LIGHTGREEN, _LIGHTCYAN,
  18.             _LIGHTRED, _LIGHTMAGENTA, _YELLOW, _BRIGHTWHITE};
  19.  
  20.  
  21. extern int r = 10, g = 20, b = 30;
  22.  
  23.  
  24. boolean regfonts2(void)
  25. /* Read header info from .FON files in current or given directory. */
  26. {
  27.     char   fondir[_MAX_PATH];
  28.     char   temp[50];
  29.     short  fontnum;
  30.  
  31.  
  32.     if( _registerfonts( "*.FON" ) <= 0 )
  33.     {
  34.     _settextcolor(12);
  35.     _outtext( "\n Please Enter the full path where *.FON files are located:\n ");
  36.     _settextcolor(1);
  37.     _outtext( ">> " );
  38.     gets( fondir );
  39.     strcat( fondir, "\\*.FON" );
  40.     fontnum = _registerfonts( fondir );
  41.  
  42.     if ( fontnum <= 0 )
  43.         {
  44.         _outtext( "Error: Sorry, unable to register fonts" );
  45.         return( NOGO );
  46.         }
  47.     sprintf( temp, "\n%d Graphics character fonts read.\n", fontnum );
  48.     _settextcolor(9);
  49.     _outtext( temp );
  50.     getch();
  51.     _settextcolor(15);
  52.     return( GO );
  53.     }
  54. }
  55.  
  56.  
  57. unsigned long get_color(int *type1, int *r, int *g, int *b)
  58. /* Returns an integer value corresponding to the next VGA color in a series */
  59. {
  60.     int red = * r;
  61.     int green = * g;
  62.     int blue = * b;
  63.     int type = *type1;
  64.  
  65.     if (type > 10)
  66.       type = 1;
  67.  
  68.     /*if ((red == 62) OR (blue == 62) OR (green == 62))
  69.       {
  70.       red = green = blue = 10;
  71.       if (type == 5)
  72.     type = 1;
  73.       else ++type;
  74.       }
  75.  
  76.     else
  77.       if ((red <= 0) || (blue <= 0) || (green <= 0))
  78.     red = blue = green = 62;
  79.     */
  80.  
  81.     if ( red EQ 62 )
  82.       red = 5;
  83.     if ( green EQ 62 )
  84.       green = 5;
  85.     if ( blue EQ 62 )
  86.       blue = 5;
  87.     if ( red EQ 0 )
  88.       red = 62;
  89.     if ( green EQ 0 )
  90.       green = 62;
  91.     if ( blue EQ 0 )
  92.       blue = 62;
  93.     type = rand() % 8;
  94.  
  95.     switch(type)
  96.       {
  97.     case 1  :
  98.           if (red < 63)
  99.             red++;
  100.           else if (green < 63)
  101.             green++;
  102.           else if (blue < 63)
  103.             blue++;
  104.           break;
  105.     case 2  :
  106.           if (green < 63)
  107.             green++;
  108.  
  109.           else if (blue < 63)
  110.             blue++;
  111.           else if (red < 63)
  112.             red++;
  113.           break;
  114.     case 3  :
  115.           if (blue < 63)
  116.             blue++;
  117.           else if (red < 63)
  118.             red++;
  119.           else if (green < 63)
  120.             green++;
  121.     case 4  :
  122.           if (blue < 63)
  123.             blue++;
  124.           else if (green < 63)
  125.             green++;
  126.           else if (red < 63)
  127.             red++;
  128.           break;
  129.  
  130.  
  131.     case 5 : red = (rand() % 63 );
  132.           green = rand() % 63;
  133.           blue = rand() % 63;
  134.           break;
  135.  
  136.  
  137.     case 6  :
  138.           if (red > 10)
  139.             red--;
  140.           else if (green > 10)
  141.             green--;
  142.           else if (blue > 10)
  143.             blue--;
  144.           break;
  145.     case 7  :
  146.           if (green > 10)
  147.             green--;
  148.           else if (blue > 10)
  149.             blue--;
  150.           else if (red > 10)
  151.             red--;
  152.           break;
  153.     case 8  :
  154.           if (blue > 10)
  155.             blue--;
  156.           else if (red > 10)
  157.             red--;
  158.           else if (green > 10)
  159.             green--;
  160.     case 9:
  161.           red = (rand() % 63 );
  162.           green = rand() % 63;
  163.           blue = rand() % 63;
  164.           break;
  165.     case 10:
  166.           red = (rand() % 63 );
  167.           green = rand() % 63;
  168.           blue = rand() % 63;
  169.           break;
  170.  
  171.     }
  172.     * r = red;
  173.     * g = green;
  174.     * b = blue;
  175.     * type1 = type;
  176.     return (rgb(red, green, blue));
  177.  
  178. }
  179.  
  180. /* Simple bubble sort for short arrays of integers */
  181. void sort(short * p, int n)
  182.  
  183. {
  184.     int i, j, temp;
  185.  
  186.     for (i = n; i > 1; --i)
  187.       for (j = 1; j < i; ++j)
  188.         if (p[j] > p[j+1])
  189.           {
  190.           temp = p[j];
  191.           p[j] = p[j + 1];
  192.           p[j + 1] = temp;
  193.           }
  194. }
  195.  
  196.  
  197.  
  198. /* Takes an area of the screen defined by the received logical
  199.    coordinates and resets the color values of any non-background
  200.    pixels to a random palette color */
  201.  
  202. void remap(short x1, short y1, short x2, short y2)
  203. {
  204.     short    color = 1;
  205.     pixtype  x, y;
  206.  
  207.     if (vc.numcolors >= 12)
  208.       for (x = x1; x <= x2; x++)
  209.         for (y = y1; y <= y2; y++)
  210.           if (_getpixel(x, y) != 0) /// Remap all non-background pixels
  211.         {
  212.         /* _setcolor(rand() % vc.numcolors + 1); */
  213.         if ( color < vc.numcolors )
  214.           ++color;
  215.         else
  216.           color = 1;
  217.         _setcolor( color );
  218.          _setpixel(x, y);
  219.         }
  220. }
  221.  
  222. void remap2(short x1, short y1, short x2, short y2, short maptype)
  223. {
  224.     short    color = 1;
  225.     pixtype  x, y;
  226.  
  227.  
  228.     switch (maptype)
  229.     {
  230.     case 1 : /* horzontal bars */
  231.     for (x = x1; x <= x2; x++)
  232.         for (y = y1; y <= y2; y++)
  233.           if (_getpixel(x, y) != 0) /// Remap all non-background pixels
  234.         {
  235.         if (kbhit())
  236.           return;
  237.         /* _setcolor(rand() % vc.numcolors + 1); */
  238.         if ( color < vc.numcolors )
  239.           ++color;
  240.         else
  241.           color = 1;
  242.         _setcolor( color );
  243.          _setpixel(x, y);
  244.         }
  245.     break;
  246.  
  247.     case 2 : /* random pixels */
  248.     for (x = x1; x <= x2; x++)
  249.         for (y = y1; y <= y2; y++)
  250.           if (_getpixel(x, y) != 0) /// Remap all non-background pixels
  251.         {if (kbhit())
  252.           return;
  253.          _setcolor(rand() % vc.numcolors + 1);
  254.          _setpixel(x, y);
  255.         }
  256.     break;
  257.  
  258.     case 3 : /* moire remapping */
  259.     for (x = x1; x <= x2; x++)
  260.         for (y = y1; y <= y2; y++)
  261.           {if (kbhit())
  262.         return;
  263.           if (_getpixel(x, y) != 0) /// Remap all non-background pixels
  264.         color =  ( ( x * x + y * y ) / 10 ) % vc.numcolors ;
  265.           if ( color <= 1 )
  266.         color = rand() % vc.numcolors + 1;
  267.           _setcolor ( color );
  268.           _setpixel(x, y);
  269.           }
  270.  
  271.     break;
  272.  
  273.     case 4 : /* vertical bars */
  274.     for (y = y1; y <= y2; y++)
  275.       for (x = x1; x <= x2; x++)
  276.           if (_getpixel(x, y) != 0) /// Remap all non-background pixels
  277.         {if (kbhit())
  278.           return;
  279.         if ( color < vc.numcolors )
  280.           ++color;
  281.         else
  282.           color = 1;
  283.         _setcolor( color );
  284.          _setpixel(x, y);
  285.         }
  286.     break;
  287.  
  288.  
  289.     default:
  290.     break;
  291.     }
  292.  
  293. }
  294.  
  295.  
  296. /* Receives a string and returns the logical x coordinate to center the
  297.    string on the CRT display depending on hardware & video configuration*/
  298. pixtype centerx(char * text)
  299. {
  300.      return((short)(vc.numxpixels / 2) - (_getgtextextent(text) / 2) - 1);
  301. }
  302.  
  303.  
  304. /* Returns a neatly formatted string containing the day/month/date/year
  305.    "days" number of days from the present date */
  306. void getdate(char * temp, time_t days)
  307.  
  308. {
  309.     time_t  bintime;
  310.     char    * datestr;
  311.     short   i;
  312.  
  313.     days *= 86400;  /// Number of seconds in a day
  314.     time(&bintime);
  315.     bintime += days;
  316.     datestr = ctime(&bintime);
  317.  
  318.     /* The following reformats the string returned by "ctime" to eliminate
  319.        unneccessary chars */
  320.     datestr[12] = datestr[21];
  321.     datestr[13] = datestr[22];
  322.     datestr[14] = datestr[23];
  323.     datestr[15] = datestr[24];
  324.     datestr[16] = '\0';
  325.     for (i = 17; i <= 26; i++)
  326.       datestr[i] = ' ';
  327.  
  328.     strcpy( temp, "The Megubucks Number for ");
  329.     strcat( temp, datestr);
  330. }
  331.  
  332. /* Sets the origin for logical screen coordinates to the center, depending
  333.    on the video mode */
  334. void set_center_origin(void)
  335. {
  336.        int  xcent, ycent;
  337.        struct videoconfig vc;
  338.  
  339.     _getvideoconfig(&vc);
  340.     xcent = vc.numxpixels / 2 - 1;
  341.     ycent = vc.numypixels / 2 - 1;
  342.     _setlogorg(xcent, ycent);
  343. }
  344.  
  345.  
  346.  
  347. /* Sets a type font for graphics mode display
  348.  Returns FALSE if the video driver is unable to set the desired combination*/
  349. boolean set_font(short font, /// Fonts 1 thru 6 defined in "numfun.h"
  350.          short size) /// Size of type displayed, range 1..10
  351. {
  352.  
  353.     char list[20], * temp;
  354.  
  355.     switch (font)
  356.       {
  357.       case COUR :
  358.          strcat( strcat( strcpy( list, "t'" ), "courier" ), "'");
  359.          break;
  360.       case HELV :
  361.          strcat( strcat( strcpy( list, "t'" ), "helv" ), "'");
  362.          break;
  363.       case MOD :
  364.          strcat( strcat( strcpy( list, "t'" ), "modern" ), "'");
  365.          break;
  366.       case ROM :
  367.          strcat( strcat( strcpy( list, "t'" ), "roman" ), "'");
  368.          break;
  369.       case TRMN :
  370.          strcat( strcat( strcpy( list, "t'" ), "tms rmn" ), "'");
  371.          break;
  372.       case SCRP :
  373.          strcat( strcat( strcpy( list, "t'" ), "script" ), "'");
  374.          break;
  375.       case HELVE :
  376.          strcat( strcat( strcpy( list, "t'" ), "helve" ), "'");
  377.          break;
  378.       case HELVF :
  379.          strcat( strcat( strcpy( list, "t'" ), "helvf" ), "'");
  380.          break;
  381.       case TRMNE :
  382.          strcat( strcat( strcpy( list, "t'" ), "trmne" ), "'");
  383.          break;
  384.       case TRMNF :
  385.          strcat( strcat( strcpy( list, "t'" ), "trmnf" ), "'");
  386.          break;
  387.       case VGAFIX :
  388.          strcat( strcat( strcpy( list, "t'" ), "vgafix" ), "'");
  389.          break;
  390.       case VGAOEM :
  391.          strcat( strcat( strcpy( list, "t'" ), "vgaoem" ), "'");
  392.          break;
  393.       case VGASYS :
  394.          strcat( strcat( strcpy( list, "t'" ), "vgasys" ), "'");
  395.          break;
  396.  
  397.       default  :
  398.          _outtext("Cant set that font identifier\n Press A key...");
  399.          getch();
  400.          break;
  401.       }
  402.  
  403.     switch (size)
  404.       {
  405.       case 1 :
  406.         strcat( list, "h4w3b" );
  407.         break;
  408.       case 2 :
  409.         strcat( list, "h10w8b" );
  410.         break;
  411.       case 3 :
  412.         strcat( list, "h12w9b" );
  413.         break;
  414.       case 4 :
  415.         strcat( list, "h15w12b" );
  416.         break;
  417.       case 5 :
  418.         strcat( list, "h18w22b" );
  419.         break;
  420.       case 6 :
  421.         strcat( list, "h20w16b" );
  422.         break;
  423.       case 7 :
  424.         strcat( list, "h25w20b" );
  425.         break;
  426.       case 8 :
  427.         strcat( list, "h30w24b" );
  428.         break;
  429.       case 9 :
  430.         strcat( list, "h38w32b" );
  431.         break;
  432.       case 10:
  433.         strcat( list, "h42w35b" );
  434.         break;
  435.       default:
  436.         _outtext(" Font size must be in the range 1..10\n Press A Key...");
  437.         getch();
  438.         break;
  439.       }
  440.  
  441.       if ( _setfont( list ) == FALSE )
  442.         {
  443.         sprintf( temp, "Can't set font %s\n Press A Key...\0", list );
  444.         _outtext( temp );
  445.         getch();
  446.         return( FALSE );
  447.         }
  448.  
  449.       _getfontinfo( &fi );
  450.       return( TRUE );
  451. }
  452.  
  453. void mixall(void)
  454. {
  455.     int x = 1;
  456.     int type = 1;
  457.     int color = 1;
  458.     unsigned cnum;
  459.  
  460.     while ( !kbhit())
  461.     for (color = 1; color <= vc.numcolors; color++)
  462.       {
  463.       if (++x % 300 == 0)
  464.         ++type;
  465.       if (type == 6)
  466.         type = 1;
  467.       cnum = get_color(&type, &r, &g, &b);
  468.       _remappalette(color, cnum);
  469.       /*if (color == vc.numcolors)
  470.         color = 1;  */
  471.       }
  472.       getch();
  473.      /// _remapallpalette(color_array);
  474. }
  475.  
  476. boolean reset_mouse(void)
  477. /* This function initializes the mouse for programs that require one.
  478.    It is a redefinition of the QuickC Toolbox mouse_reset() function,
  479.    since the programs I write which require a mouse need two buttons.
  480.    The function returns FALSE if a two-button mouse is not installed. */
  481.  
  482. {
  483.     mouse_t  status;  /// Mouse status, ie. installed or not.
  484.     mouse_t  buttons; /// Number of buttons available on mouse.
  485.  
  486.     mouse_reset( &status, &buttons );
  487.  
  488.     if ( ( status NE -1 ) OR ( buttons NE 2 ) )
  489.       return( FALSE );
  490.     ///else
  491.      /// mouse_setgcurs( &gcursor_hand );
  492.     return( TRUE );
  493. }
  494.  
  495.  
  496.  
  497.