home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CMAGIC.ZIP / DEMO.C next >
C/C++ Source or Header  |  1992-09-06  |  8KB  |  182 lines

  1. /* Demo program for C Magic, copyright 1992, Jeff Napier & Another Company */
  2.  
  3. /* Include MAGIC.LIB and GRAPHICS.LIB in project file.  Compile in large   */
  4. /* memory model only.  See TUTOR.DOC and MAGIC.TXT for more information    */
  5.  
  6. #include <magic.h>
  7. #include <graphics.h>
  8. #include <dos.h>     /* for delay() */
  9. #include <string.h>  /* for programmer's toolkit */
  10. #include <stdlib.h>  /* '' */
  11. #include <stdio.h>   /* '' */
  12. #include <conio.h>   /*  comment this out if using older version of TC */
  13. #include <ctype.h>   /* '' */
  14.  
  15. void extkey(void);   /* prototypes for Programmer's Toolkit functions */
  16. void asciichart(void);
  17.  
  18. void main() {
  19.     magic_setup();   /* must include this with every program */
  20.  
  21. /*  musicon = 0; */  /* Uncomment this line if you want to turn */
  22.                      /* off all the sound effects */
  23.  
  24.     bestvideo();     /* establishes best graphics mode for your computer */
  25.     triplex();       /* builds TRIP.CHR into your .EXE file */
  26.     settextjustify(CENTER_TEXT,TOP_TEXT);
  27.     outtextxy(320,70,"Welcome to C MAGIC");
  28.     bitmap();        /* switches to default, BITMAP font */
  29.     outtextxy(320,120,
  30.         "Copyright 1992, Another Company");
  31.     setcolor(LIGHTMAGENTA);
  32.     setlinestyle(0,0,3);
  33.     ellipse(320,100,0,360,280,60);
  34.     twinkle();       /* a C Magic sound effect */
  35.     waitforuser();   /* like getch() but allows use of mouse buttons, too */
  36.     pile("Now let's look at the code so far:");
  37.     pile(" ");       /* pile() is a super-easy string handler from C Magic */
  38.     pile("#include <magic.h>");
  39.     pile("#include <graphics.h>");
  40.     pile("void main() {");
  41.     pile("   magic_setup();");
  42.     pile("   bestvideo();");
  43.     pile("   triplex();");
  44.     pile("   settextjustify(CENTER_TEXT,TOP_TEXT);");
  45.     pile("   outtextxy(320,70,\"Welcome to C MAGIC\");");
  46.     pile("   bitmap();");
  47.     pile("   outtextxy(320,120,");
  48.     pile("      \"Copyright 1992, Another Company\");");
  49.     pile("   setcolor(LIGHTMAGENTA);");
  50.     pile("   setlinestyle(0,0,3);");
  51.     pile("   ellipse(320,100,0,360,280,60);");
  52.     pile("   twinkle();");
  53.     pile("   waitforuser();");
  54.     pile("              (Press any key to continue...)");
  55.     getanykey(-1,-1);    /* displays strings, waits for user action  */
  56.     pile("It's just that simple!");
  57.     pop(-1,-1);          /* displays strings in a pop up box */
  58.     delay(1500);         /* from DOS.H */
  59.     restore();           /* replaces screen under pop() */
  60.     pile("This demonstrates a cursor, available whether or not");
  61.     pile("you have a mouse.  You can move the cursor with the");
  62.     pile("arrow keys, [Home], [End], [Page Up], [Page Down]");
  63.     pile("or the number keys.  Try it.  Press [Enter] or click");
  64.     pile("the left mouse button when done.");
  65.     pop(0,getmaxy() - 100);
  66.     bugle();                 /* a C Magic sound effect */
  67.  
  68.     waste();                 /* clears keyboard buffer and mouse input */
  69.     pointeron();             /* turn on graphics mode arrow cursor     */
  70.     while (!left) poll();    /* read mouse button status and location  */
  71.        /* poll() updates global ints px & py for location, and global  */
  72.        /* chars left, center, and right for button status.             */
  73.        /* Whether or not mouse is present, poll() also takes key input */
  74.     pointeroff();            /* turns off graphics arrow               */
  75.     restore();               /* removes all traces of pop-up box       */
  76.     pile("Here's all the mouse code we just used:");
  77.     pile(" ");
  78.     pile("   waste();");
  79.     pile("   pointeron();");
  80.     pile("   while (!left) poll();");
  81.     pile("   pointeroff();");
  82.     pile(" ");
  83.     pile("          (Press any key to contnue...)");
  84.     getanykey(-1,-1);         /* pops up and waits for keypress        */
  85.  
  86.  
  87.                       /* Programmer's Toolkit starts here */
  88.  
  89.     textvideo();             /* switches back to text video */
  90.     mainback = GREEN;
  91.     xclear();                /* clears background to green */
  92.     centerjustify = 1;       /* center strings in pop-up boxes */
  93.     mc = 1;                  /* mc = "Menu Choice" - the highlighted item */
  94.     do {
  95.        boxback = RED;        /* pop-up box background is set to red */
  96.        pile("Programmer's Toolkit");
  97.        pile("Copyright 1992, Freeware by Another Company");
  98.        pop(18,2);            /* pop up a box at coordinates 18,2 */
  99.        boxback = BLUE;
  100.        boxtext = WHITE;
  101.        border = WHITE;
  102.        strcpy(sent[1],"ASCII Chart");
  103.        strcpy(sent[2],"Extended Keys");
  104.        strcpy(sent[3],"Quit");
  105.        menu(-1,-1);          /* pop up a menu, centered on screen */
  106.        if (u == 13) switch (mc) {
  107.           case 1 : asciichart(); break;
  108.           case 2 : extkey();
  109.        }            /* branch to a function, depending on user's    */
  110.             /* selection from menu.  These functions are    */
  111.             /* about 15 lines below this line in this file. */
  112.        restore();   /* get rid of title pop-up */
  113.    }
  114.    while (!((u == 13) && (mc == 3)));
  115.    xclear();
  116.    centerjustify = 0;
  117.    pile("The complete code for this program is in the file DEMO.C.");
  118.    pile("You can cut out the preliminary stuff to compile the");
  119.    pile("Programmer's Toolkit by itself, or you can cut, paste");
  120.    pile("and experiment from this demo to design your own programs.");
  121.    pile("There's far more to C MAGIC.  See TUTOR.DOC and MAGIC.TXT");
  122.    pile("for more functions and more information.");
  123.    pile(" ");
  124.    pile("        Thanks for looking at the C Magic library.");
  125.    getanykey(-1,-1);   /* pop up centered on screen, waits for user */
  126.    cleanup();
  127. }
  128.  
  129.     /* This function displays ASCII information */
  130.     /* corresponding to any key pressed. */
  131.  
  132. void extkey(void){
  133.    char tempstr[3];
  134.    xclear();
  135.    pile("Press any key to see it's extended code");
  136.    pile("Press [Esc] when done.");
  137.    pop(18,3);           /* pop up box at coordinates 18,3 */
  138.    strcpy(sent[1]," ");  /* makes an empty box */
  139.    strcpy(sent[2],"");
  140.    do {                   /* this loop executes until uses presses [Esc] */
  141.       getanykey(-1,-1);   /* display our result in a pop-up box */
  142.       if (keydetect == 2) strcpy(sent[1],"#0 + ");  /* an extended key */
  143.       sprintf(tempstr,"%c",u);                      /* build a string */
  144.       if ((u == 13) || (u == 8) || (u == 10) || (u == 7))
  145.          strcat(sent[1]," ");
  146.          else strcat(sent[1],tempstr);       /* if character is printable */
  147.                                              /* then we add it to string  */
  148.       itoa(u,tempstr,10);                    /* and convert it's ASCII #  */
  149.       strcat(sent[1],"(#");                  /* to a string and add that, */
  150.       strcat(sent[1],tempstr);               /* too.                      */
  151.       strcat(sent[1],")");
  152.    }
  153.    while (u != 27);                       /* ASCII 27 is the [Escape] key */
  154.    xclear();
  155.    } /* end of function extkey() */
  156.  
  157. void asciichart(void){
  158.    char x = 1,y = 1;
  159.    int temp;
  160.    char tempstr[3];
  161.    textcolor(YELLOW); textbackground(BLUE);
  162.    clrscr();
  163.    for (temp = 0; temp < 256; temp++) {     /* a loop that repeats 256 times */
  164.       gotoxy(x,y);                          /* and prints ASCII# / character */
  165.       cprintf(" ");
  166.       if (temp < 10) cprintf(" ");
  167.       if (temp < 100) cprintf (" ");
  168.       if ((temp != 7) && (temp != 8) && (temp != 10)
  169.       &&(temp != 13) && (temp != 27))
  170.       cprintf("%d=%c ",temp,temp);
  171.       else cprintf("%d=",temp);
  172.       y++;
  173.       if (y > 25){                         /* in readable columns on screen */
  174.          y = 1;
  175.          x += 7;
  176.       } /* end of if y > 25 */
  177.    } /* end of for loop */
  178.    waitforuser();                          /* wait for user to press a key */
  179.    xclear();
  180. } /* end of function asciichart() */
  181.  
  182.