home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / fgl_v12.zip / FGL_DEMO.PRG < prev    next >
Text File  |  1994-08-28  |  16KB  |  318 lines

  1. /*** 
  2. Demo program to demonstrate the use of the Ferns' Graphics Library V 1.2.
  3. Programmer : F.D. Paanakker, 1994.
  4.  
  5. This DEMO program gives some examples of what you can do with the
  6. Ferns' Graphics Library.
  7. Although this demo is not particularly gripping, it works in 3 different
  8. graphic modes : 16 color, 256 color and 32768 Hicolor ! 
  9. The library has 16 color VGA support, but that is just so you can run
  10. it on almost every computer. The 16 color mode functions for saving and
  11. restoring backgrounds are not fast...maybe they will be fast in the
  12. next version of the library. For now they are just to support the few
  13. computer-owners who still have to cope with a standard VGA. 
  14. The 256 color and 32768 Hicolor functions are highly optimized.
  15. They are particularly fast !
  16. There are about 16 different SuperVGA cards that are supported. There's
  17. also VESA support ! 
  18. Hope you enjoy this demo and that it may give you many ideas...
  19.  
  20. Compile with :
  21.         CLIPPER FGL_DEMO /N
  22. ***/
  23.  
  24. PROCEDURE FGL_DEMO()         // main module.
  25.  SET SCOREBOARD OFF
  26.  
  27.   if (FGL_VGA_640x480() = .F.)              // Initialize video mode 640x480
  28.    QOUT("Hicolor Video not found...aborting")
  29.    QUIT
  30.   end if
  31.  
  32.   FGL_load_font("normal.fnt")               // load normal font 
  33.   ini_colors()                  // This functions initializes colors like
  34.                                 // WHITE,RED,BLACK etc...
  35.  
  36.   FGL_fill_rectangle(0,0,639,479,BLUE)      // blue background
  37.   IntroWindow(0,140)                        // window about features FGL
  38.   SpecialWindow(400,60)                     // Different kinds of windows
  39.   GraphWindow(50,100)                       // Show graphic primitives
  40.   FontWindow(0,0)                           // Show different fonts
  41.   SayGetWindow(135,230)                     // Window to demonstrate SAY and GET support
  42.   FGL_fill_rectangle(0,0,639,479,BLUE)      // clear background for last window
  43.   LastWindow(150,90)                        // Window about FGL
  44.  FGL_free_font()                             // release font-memory
  45.  FGL_TEXTMODE()                              // back to textmode.
  46.  QUIT                                        // THE END
  47. RETURN
  48.  
  49. PROCEDURE IntroWindow(X,Y)
  50. /* Introduction window */
  51. local text := {"With the Ferns' Graphics Library you can easily incorporate neat",;
  52.                 "graphics into your Clipper application.",;
  53.                 "There are functions for lines, text, circles, ellipses, rectangles, points,",; 
  54.                 "different fonts, etc. etc.",;
  55.                 "Then there are also functions to get en put backgrounds, display check-",;
  56.                 "boxes, radiobuttons, windows and normal buttons."}
  57.  
  58.   // N.B. : We don't save the background !
  59.                                                 // make window
  60.   FGL_OS2window(X,Y,639,200,"Ferns' Graphics Library Demo") 
  61.                                                 // print text
  62.   for i := 1 TO 6 ; FGL_text(X+10,Y+40+i*16,BLACK,WHITE,text[i]) ; next   
  63.  
  64.                                                 // make button
  65.   FGL_textbutton(X+220,Y+160,X+440,Y+180,"Continue")
  66.   selected(X+220,Y+160,X+440,Y+180,BLACK)       // special function to select button
  67.   INKEY(0)                                      // wait for key pressed
  68.   selected(X+220,Y+160,X+440,Y+180,WHITE)       // unselect button
  69. RETURN // IntroWindow
  70.  
  71. PROCEDURE SpecialWindow(X,Y)
  72. /* Shows different types of windows */
  73. local i
  74. local back                                         // variable for background
  75. local text1 := {"You can make your","program look like",;
  76.                 "an OS/2 program with","this window..."}
  77. local text2 := {"or like an Windows pro-","gram with this window."}
  78.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'Please wait while saving background ...')
  79.   back := FGL_get_background(X,Y,X+200,Y+200)      // save background
  80.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'                                       ')
  81.   FGL_OS2window(X,Y,200,200,"OS/2-like window")    // draw OS/2-like window
  82.   FOR i := 1 TO 4 
  83.    FGL_text(X+10,Y+20+(i*20),BLACK,WHITE,text1[i]) // text in window 
  84.   NEXT i 
  85.   FGL_textbutton(X+50,Y+160,X+150,Y+180,"Next")    // button
  86.   selected(X+50,Y+160,X+150,Y+180,BLACK)           // make button selected
  87.   inkey(0)                                         // wait for key pressed
  88.   FGL_WINwindow(X,Y,200,200,"Windows-like window") // new window
  89.   FOR i := 1 TO 2 
  90.    FGL_text(X+10,Y+40+(i*20),BLACK,BRIGHT_WHITE,text2[i])    // text in window 
  91.   NEXT i 
  92.    FGL_textbutton(X+50,Y+160,X+150,Y+180,"Continue")// button
  93.   selected(X+50,Y+160,X+150,Y+180,BLACK)            // make button selected
  94.   inkey(0)                                          // wait for key pressed
  95.   FGL_put_background(X,Y,X+200,Y+200,back)          // restore background
  96. RETURN // SpecialWindows
  97.  
  98. PROCEDURE GraphWindow(X,Y)
  99. /* Shows graphic primitives */
  100. local back                                        // variable for background
  101.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'Please wait while saving background ...')
  102.   back := FGL_get_background(X,Y,X+500,Y+300)     // save background
  103.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'                                       ')
  104.   FGL_OS2window(X,Y,500,300,"Window to demonstrate different graphic primitives")
  105.   FGL_text(X+10,Y+25,RED,WHITE,"The diffent graphic primitives are :")
  106.   FGL_rectangle(X+9,Y+49,X+491,Y+241,GRAY)        // make neat window
  107.   FGL_line(X+9,Y+49,X+9,Y+241,BRIGHT_WHITE)
  108.   FGL_line(X+9,Y+49,X+491,Y+49,BRIGHT_WHITE)
  109.   RandomPrimitives(X,Y)                           // Show different primitives
  110.   ButtonWindow(10,10)                             // call function (so you can
  111.                                                   // see that multiple windows
  112.                                                   // are saved correctly).
  113.   FGL_put_background(X,Y,X+500,Y+300,back)        // restore background
  114. RETURN // GraphWindow
  115.  
  116. PROCEDURE RandomPrimitives(X,Y)
  117. /* procedure will draw rectangles of random size at random locations */
  118. local key,xpos,ypos,width,hight,color
  119. local prim                                        // PRIMitive counter
  120. local text := {"lines            ",;              // names of primitives
  121.                "open rectangles  ",;
  122.                "filled rectangles",;
  123.                "open ellipses    ",;
  124.                "filled ellipses  ",;
  125.                "open circles     ",; 
  126.                "filled circles   "}
  127.   
  128.   FGL_textbutton(X+200,Y+260,X+300,Y+280,"Next")  // button
  129.  
  130.   FOR prim := 1 TO 7
  131.     FGL_set_viewport(0,0,0,0)                     // viewport now total screen
  132.     FGL_text(X+310,Y+25,BLUE,WHITE,text[prim])
  133.     selected(X+200,Y+260,X+300,Y+280,BLACK)       // make button selected
  134.     FGL_set_viewport(X+10,Y+50,X+490,Y+240)       // viewport : all output outside
  135.                                                   // this window won't be drawn.
  136.     FGL_fill_rectangle(X+10,Y+50,X+490,Y+240,prim)// background
  137.     key := INKEY()                           // get last key and make current
  138.     srandom(prim)                            // SeedRandom : starting point   
  139.                                              // random generator. This function   
  140.                                              // is supplied in Random.obj
  141.      DO WHILE (key = INKEY())                // loop while no key is pressed   
  142.        xpos := random() % 500                // select random values.
  143.        ypos := random() % 250                // the function random is also
  144.        width := (random() % 50)+40           // supplied in Random.obj
  145.        hight := (random() % 50)+40           // minimum value 40
  146.        color := random() % FGL_getnumcolors()// select one out of all the
  147.                                              // colors available.
  148.        DO CASE                               // which primitives is to be drawn ?
  149.          CASE prim = 1 ; FGL_line(X+xpos,Y+ypos,X+(random()%500),Y+(random()%250),color)
  150.          CASE prim = 2 ; FGL_rectangle(X+xpos,Y+ypos,X+xpos+width,Y+ypos+hight,color)
  151.          CASE prim = 3 ; FGL_fill_rectangle(X+xpos,Y+ypos,X+xpos+width,Y+ypos+hight,color)
  152.          CASE prim = 4 ; FGL_ellipse(X+xpos,Y+ypos,X+xpos+width,Y+ypos+hight,color)
  153.          CASE prim = 5 ; FGL_fill_ellipse(X+xpos,Y+ypos,X+xpos+width,Y+ypos+hight,color)
  154.          CASE prim = 6 ; FGL_circle(X+xpos,Y+ypos,width,color)
  155.          CASE prim = 7 ; FGL_fill_circle(X+xpos,Y+ypos,width,color)
  156.        ENDCASE
  157.      ENDDO
  158.     selected(X+200,Y+260,X+300,Y+280,WHITE)  // make button unselected
  159.   NEXT
  160.   
  161.   FGL_fill_rectangle(X+10,Y+50,X+490,Y+240,WHITE)    // background
  162.   FGL_set_viewport(0,0,0,0)                          // viewport now total screen
  163.   FGL_textbutton(X+200,Y+260,X+300,Y+280,"Continue") // button
  164.   selected(X+200,Y+260,X+300,Y+280,BLACK)            // make button selected
  165.   FGL_fill_rectangle(X+10,Y+25,X+490,Y+45,WHITE)     // remove text
  166.   FGL_text(X+50,Y+130,BLUE,WHITE,"As you have just seen, all the functions work with") 
  167.   FGL_text(X+50,Y+150,BLUE,WHITE,"    viewports. And at considerable speed too !")
  168.   inkey(0)                                           // wait for key pressed
  169.   selected(X+200,Y+260,X+300,Y+280,WHITE)            // unselect button.
  170. RETURN // Randomprimitives
  171.  
  172.  
  173. PROCEDURE ButtonWindow(X,Y)
  174. /* Shows neat window with radiobuttons and checkboxes */
  175. local back                                        // variable for background
  176.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'Please wait while saving background ...')
  177.   back := FGL_get_background(X,Y,X+400,Y+270)     // save background
  178.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'                                       ')
  179.   // now make nice box...
  180.   FGL_fill_rectangle(X,Y,X+400,Y+270,WHITE)
  181.   FGL_rectangle(X,Y,X+400,Y+270,BLACK)
  182.   little_shade(X+5,Y+5,X+400-5,Y+270-5)           // function for kind of 
  183.                                                   // a shadowbox.
  184.   little_shade(X+10,Y+15,X+400-10,Y+105)
  185.   little_shade(X+10,Y+115,X+400-10,Y+225)
  186.   little_shade(X+10,Y+235,X+400-10,Y+255)
  187.   
  188.   FGL_text(X+40,Y+20,BLUE,WHITE,"Want do you want ?")
  189.   FGL_text(X+40,Y+40,BLACK,WHITE,"Windows, with all it's overhead.")
  190.   FGL_text(X+40,Y+60,BLACK,WHITE,"Expensive DOS graphics lib.")
  191.   FGL_text(X+40,Y+80,BLACK,WHITE,"The Ferns' Graphics Library !")
  192.   FGL_RADIOBUTTON(X+20,Y+40,.F.)                  // display radiobutton
  193.   FGL_RADIOBUTTON(X+20,Y+60,.F.)
  194.   FGL_RADIOBUTTON(X+20,Y+80,.T.)
  195.   
  196.   FGL_text(X+40,Y+120,RED,WHITE,"The FG Library has :")
  197.   FGL_text(X+40,Y+140,BLACK,WHITE,"VGA, SuperVGA and Hicolor support !")
  198.   FGL_text(X+40,Y+160,BLACK,WHITE,"support of many graphic modes !")
  199.   FGL_text(X+40,Y+180,BLACK,WHITE,"Very fast and neat graphics !")
  200.   FGL_text(X+40,Y+200,BLACK,WHITE,"All kinds of useful functions !")
  201.   FGL_CHECKBOX(X+20,Y+140,.T.)                    // display checkbox
  202.   FGL_CHECKBOX(X+20,Y+160,.T.)
  203.   FGL_CHECKBOX(X+20,Y+180,.T.)
  204.   FGL_CHECKBOX(X+20,Y+200,.T.)
  205.  
  206.   FGL_text(X+12,Y+238,BLACK,WHITE,"The FG Library makes graphics programming easy!")
  207.   inkey(0)                                        // wait for keypress
  208.   FGL_put_background(X,Y,X+400,Y+270,back)        // restore background
  209. RETURN // ButtonWindow
  210.  
  211. PROCEDURE FontWindow(X,Y)
  212. local back                                        // variable for background
  213.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'Please wait while saving background ...')
  214.   back := FGL_get_background(X,Y,X+450,Y+150)     // save background
  215.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'                                       ')
  216.   FGL_fill_rectangle(X,Y,X+450,Y+150,WHITE)       // make neat box
  217.   FGL_rectangle(X,Y,X+450,Y+150,BLACK)
  218.   little_shade(X+5,Y+5,X+450-5,Y+150-5)
  219.   
  220.   FGL_text(X+10,Y+10,BLACK,WHITE,"You can put text on the screen using the normal font.")
  221.   FGL_load_font("helvetic.fnt")                   // load helvetic font 
  222.   FGL_text(X+10,Y+50,RED,WHITE,"or surprise everyone with the HELVETIC font !")
  223.   FGL_load_font("script.fnt")                     // load script font 
  224.   FGL_text(X+10,Y+70,RED,WHITE,"or surprise everyone with the SCRIPT font !")
  225.   FGL_load_font("broadway.fnt")                   // load broadway font 
  226.   FGL_text(X+10,Y+90,RED,WHITE,"or surprise everyone with the BROADWAY font !")
  227.   FGL_load_font("normal.fnt")                     // now load normal font 
  228.   FGL_textbutton(X+175,Y+150-30,X+275,Y+150-10,'Continue')
  229.   selected(X+175,Y+150-30,X+275,Y+150-10,BLACK)   // make button selected
  230.   inkey(0)                                        // wait for keypress
  231.   selected(X+175,Y+150-30,X+275,Y+150-10,WHITE)   // unselect button
  232.   FGL_put_background(X,Y,X+450,Y+150,back)        // restore background
  233. RETURN // FontWindow
  234.  
  235. PROCEDURE SayGetWindow(X,Y)
  236. local text := "Test input"
  237.   // N.B. : We don't save the background !
  238.   FGL_OS2window(X,Y,500,200,"The FG Library also has SAY and GET support")
  239.   FGL_text(X+8,Y+30,BLACK,WHITE,"Using the old coordinate system, you can still use the normal")
  240.   FGL_text(X+8,Y+50,BLACK,WHITE,"@ SAY and @ GET (with graphical cursor) !!!!")
  241.   FGL_textbutton(X+200,Y+200-30,X+300,Y+200-10,'Continue')
  242.   FGL_rectangle(23*8-1,20*16-1,33*8,21*16,BLACK) // black rect around input
  243.   FGL_textcolor(BLACK,BRIGHT_WHITE)              // set color for SAY and GET's
  244.   @ 20,23 GET text                               // display get
  245.   READ                                           // get input
  246.   selected(X+200,Y+200-30,X+300,Y+200-10,BLACK)   // make button selected
  247.   inkey(0)                                        // wait for keypress
  248.   selected(X+200,Y+200-30,X+300,Y+200-10,WHITE)   // unselect button
  249. RETURN  // SayGetWindow
  250.  
  251. PROCEDURE LastWindow(X,Y)
  252. local back,i,text := {"As you have just seen, the Ferns'",; 
  253.                     "Graphics Library contains many powerful",;
  254.                     "graphic functions. As development conti-",;
  255.                     "nues, there soon will be mouse, 24 bits",; 
  256.                     "Truecolor and wallpaper support. If you",; 
  257.                     "register now, you will receive the la-",;
  258.                     "test version and notification of major",; 
  259.                     "new versions.",; 
  260.                     "With the Ferns' Graphics Library, you",; 
  261.                     "will be ready for whatever comes next !"}
  262.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'Please wait while saving background ...')
  263.   back := FGL_get_background(X,Y,X+340,Y+300)     // save background
  264.   FGL_text(10,463,BRIGHT_WHITE,BLUE,'                                       ')
  265.   FGL_fill_rectangle(X,Y,X+340,Y+300,WHITE)       // make another neat box
  266.   FGL_rectangle(X,Y,X+340,Y+300,BLACK)
  267.   little_shade(X+5,Y+5,X+340-5,Y+300-5)
  268.   FOR i := 1 TO 10
  269.    FGL_text(X+10,Y+30+((i-1)*20),BLACK,WHITE,text[i])  // text in window
  270.   NEXT i
  271.   FGL_textbutton(X+120,Y+300-50,X+220,Y+300-30,'End Demo')
  272.   selected(X+120,Y+300-50,X+220,Y+300-30,BLACK)   // make button selected
  273.   inkey(0)                                        // wait for keypress
  274.   selected(X+120,Y+300-50,X+220,Y+300-30,WHITE)   // make button unselected
  275.   FGL_put_background(X,Y,X+340,Y+300,back)        // restore background
  276. RETURN // LastWindow
  277.  
  278. PROCEDURE little_shade(X1,Y1,X2,Y2)
  279. /* procedure to make open rectangle with shade .. */
  280.   FGL_rectangle(X1,Y1,X2-1,Y2-1,GRAY)
  281.   FGL_rectangle(X1+1,Y1+1,X2,Y2,BRIGHT_WHITE)
  282. RETURN // little_shade
  283.  
  284. PROCEDURE selected(X1,Y1,X2,Y2,color)
  285. /* Functions draws outline around button in 'color' */
  286.  FGL_line(X1-1,Y1+3,X1-1,Y2-3,color)
  287.  FGL_line(X2+1,Y1+3,X2+1,Y2-3,color)
  288.  FGL_line(X1+3,Y1-1,X2-3,Y1-1,color)
  289.  FGL_line(X1+3,Y2+1,X2-3,Y2+1,color)
  290. RETURN // selected
  291.  
  292. PROCEDURE ini_colors()
  293. /***
  294. Procedure initializes colors. Best method if you want to program in
  295. 3 different graphic modes...
  296. ***/
  297. public BLACK,BLUE,RED,WHITE,GRAY,BRIGHT_WHITE //Variable visible in whole program
  298.  
  299. IF (FGL_getnumcolors() = 16 .OR. FGL_getnumcolors() = 256)  // which mode ?
  300.  BLACK := 0                             // 16 and 256 color mode
  301.  BLUE  := 1
  302.  RED   := 4
  303.  WHITE := 7
  304.  GRAY  := 8
  305.  BRIGHT_WHITE := 15
  306. ELSE
  307.  BLACK := 0                             // 32768 Hicolor mode.
  308.  BLUE  := 21
  309.  RED   := 21504
  310.  WHITE := 22197
  311.  GRAY  := 10570
  312.  BRIGHT_WHITE := 32767
  313. ENDIF                                   // done..
  314.  
  315. RETURN // ini_colors()
  316.  
  317. /*** END DEMO PROGRAM ***/
  318.