home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1990 / USERNV90.MSA / TEXT_GEM.DOC < prev    next >
Text File  |  1990-05-24  |  4KB  |  80 lines

  1.                              GEM
  2.  
  3.          Roland Waddilove finishes off his examination of the
  4.            VDI with a quick look at some powerful functions
  5.  
  6.  
  7. You'll be pleased to hear that we've almost finished our exploration on the
  8. ST's virtual device interface, or VDI for short. This part of GEM contains
  9. dozens of graphic functions that are used in all GEM programs and before you
  10. can master GEM you must first unveil the VDI's mysteries. This month, in the
  11. final part of this series, I'll be showing some of the functions we haven't yet
  12. looked at. They're a mixed bunch, but they are important as we'll see.
  13.     One of the features of the ST that hits you right between the eyes the
  14. first time you see the machine is the GUI - the graphic user interface. Windows
  15. can be opened, resized, moved and closed simply by pointing and clicking with
  16. the mouse.
  17.     We have looked at a vast number of VDI functions and these are the
  18. functions used to draw text and graphics inside windows. The window's contents
  19. never spill outside the borders because the operating system won't let it,
  20. right? Wrong! Open a window, print some text then draw a few lines and you'l
  21. see a horrible mess on the screen. What has gone wrong?
  22.     It's up to you - the programmer - to ensure that text and graphics stay
  23. within the borders of the window and you can easily do this by setting a
  24. clipping rectangle. You give the VDI the coordinates of a ractangle on the
  25. screen and tell it that text and graphics must only appear within its borders -
  26. anything outside must be "clipped off". (In a GEM application you would
  27. calculate the borders of the window and pass the coordinates to the VDI as the
  28. clipping rectangle. Then all output will be restricted to the window.
  29.     The function you need is:
  30.  
  31. short handle, clipflag,xyarray[4];
  32. vs_clip(handle,clipflag,xyarray);
  33.  
  34.     The 'handle' parameter is the good old VDI handle and the 'clipflag' is
  35. either 1 to enable clipping or 0 to disable it. The 'xyarray' is an array
  36. containing the coordinates of the top-left-hand corner and bottom-right-hand
  37. corner of the clipping rectangle. So if you wanted to restrict all output to a
  38. box in the centre of the screen you could use:
  39.  
  40. xyarray[0] = 220;       /* top left x coordinate */
  41. xyarray[1] = 50;        /* top left y coordinate */
  42. xyarray[2] = 420;       /* bottom right x coordinate */
  43. xyarray[3] = 150;       /* bottom right y coordinate */
  44. vs_clip(handle,1,xyarray);
  45.  
  46.     A couple of graphic functions that we haven't yet looked at are circles and
  47. ellipses. Both a fairly straightforward and are quite similar. Before you start
  48. you'll need to set the writing mode, interior style, fill colour index, fill
  49. perimeter visibility and user defined fill pattern (if necessary). We have
  50. covered these functions before - they're the same ones that are used for
  51. rectangles so I'll just give you a brief reminder what their syntax is:
  52.  
  53. vswr_mode(handle,mode);           /* set writing mode */
  54. vsf_interior(handle,style);       /* set fill interior style */
  55. vsf_style(handle,style);          /* select pattern or hatch style */
  56. vsf_color(handle,color);          /* select fill colour */
  57. vsf_perimeter(handle,flag);       /* set perimeter visibility */
  58. vsf_udpat(handle,fillpat,planes); /* set user defined fill pattern */
  59.  
  60.     You don't have to set all these parameters before calling the circle and
  61. ellipse drawing functions because the VDI usually defaults to sensible values,
  62. but if you can't see anything onscreen, then try setting them.
  63.     The circle function is:
  64.  
  65. short handle, x, y, radius;
  66. v_circle(handle, x, y, radius);
  67.  
  68.     The ellipse function is equally simple:
  69.  
  70. short handle, x, y, xradius, yradius;
  71. v_ellipse(handle, x, y, xradius, yradius);
  72.  
  73.     The ellipse, of course, requires two radii (dig out your school maths
  74. books). And that just about rounds off our look at the VDI. I haven't covered
  75. all of the functions, just the most important ones. There are others, but
  76. you'll rarely need them. Now let's see you put all this theory into practice. I
  77. have given you a couple of dozen VDI functions so let's see who can supply
  78. Atari ST User with the best demo. The wining entries will appear on a future
  79. cover disk - fame and fortune awaits you do get cracking!
  80.