home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / GR_SHAPE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  2.7 KB  |  166 lines

  1. /*********************
  2.  *
  3.  *  gr_shape.c - Graphics shape functions.
  4.  *
  5.  *  Purpose: This file contains functions to manage graphics shapes.
  6.  *
  7.  *  Blackstar C Function Library
  8.  *  (c) Copyright 1985,1989 Sterling Castle Software
  9.  *
  10.  *******/
  11.  
  12. #include <dos.h>
  13. #include "blackstr.h"
  14. #include "gr_head.h"
  15. #include "sc_head.h"
  16. #include "sy_head.h"
  17. #include "primitiv.h"
  18. #include <memory.h>
  19.  
  20.  
  21. /********
  22.  *
  23.  *   gr_draw(shape) - draw a shape from shape table
  24.  *
  25.  **/
  26.  
  27. void gr_draw(short int *shape)
  28. {
  29.     int x,y,x1,y1;
  30.  
  31.     x = grx_, y=gry_;       /* current point is relative */
  32.     while (*shape!=EOS) {
  33.     x1 = (*shape++) + x;
  34.     y1 = (*shape++) + y;
  35.     gr_setpt(x1,y1);
  36.     }
  37. }
  38.  
  39.  
  40. /********
  41.  *
  42.  *   gr_scale(shape,factor) - scale a shape by factor
  43.  *
  44.  **/
  45.  
  46. void gr_scale(short int *shape, float factor)
  47. {
  48.     while(*shape != EOS)
  49.     *shape++ = (*shape * factor);
  50. }
  51.  
  52.  
  53. /********
  54.  *
  55.  *   gr_scan(shape) - scan a shape from screen
  56.  *
  57.  **/
  58.  
  59. short int *gr_scan(short int *shape)
  60. {
  61.     short int *ptr;
  62.     int i,j;
  63.  
  64.     ptr = shape;
  65.     for(j=gr_miny_; j<=gr_maxy_; ++j)
  66.     for(i=gr_minx_; i<=gr_maxx_; ++i)
  67.         if(gr_getpt(i,j) == grfcol_) {
  68.         *shape++ = i-gr_minx_;
  69.         *shape++ = j-gr_miny_;
  70.         }
  71.     *shape++ = EOS;
  72.     *shape = EOS;
  73.     return(ptr);
  74. }
  75.  
  76.  
  77. /********
  78.  *
  79.  *   gr_getp(pic) - get graphics picture to buffer
  80.  *
  81.  **/
  82.  
  83. char *gr_getp(char *pic)
  84. {
  85.     #if LDATA
  86.     #else
  87.     struct SREGS    segs;
  88.     int ptr,dseg;
  89.     #endif
  90.  
  91.     #if LDATA
  92.     memcpy(pic,gr_buf_,sc_mem_*1024);
  93.  
  94.     #else
  95.     segread(&segs);
  96.     dseg = segs.ds;
  97.     ptr = (int)pic;
  98.     movedata(gr_seg_,gr_off_,dseg,ptr,sc_mem_*1024);
  99.     #endif
  100.  
  101.     return(pic);
  102. }
  103.  
  104.  
  105. /********
  106.  *
  107.  *   gr_putp(pic) - put graphics picture to screen (small model)
  108.  *
  109.  **/
  110.  
  111. void gr_putp(char *pic)
  112. {
  113.     #if LDATA
  114.     #else
  115.     struct SREGS segs;
  116.     int ptr,dseg;
  117.     #endif
  118.  
  119.     #if LDATA
  120.     memcpy(gr_buf_,pic,sc_mem_*1024);
  121.  
  122.     #else
  123.     segread(&segs);
  124.     dseg = segs.ds;
  125.     ptr = (int)pic;
  126.     movedata(dseg,ptr,gr_seg_,gr_off_,sc_mem_*1024);
  127.     #endif
  128. }
  129.  
  130.  
  131. /********
  132.  *
  133.  *   gr_box(x1,y1,x2,y2) - draw a box (absolute) from diagonal points
  134.  *
  135.  **/
  136.  
  137. void gr_box(int x1, int y1, int x2, int y2)
  138. {
  139.     gr_pos(x1,y1);          /* start at upper left corner */
  140.     gr_lineto(x2,y1);
  141.     gr_lineto(x2,y2);
  142.     gr_lineto(x1,y2);
  143.     gr_lineto(x1,y1);
  144. }
  145.  
  146.  
  147. /********
  148.  *
  149.  *   gr_poly(shape) - draw a shape with line segments
  150.  *
  151.  **/
  152.  
  153. void gr_poly(short int *shape)
  154. {
  155.     int x,y,dx,dy;
  156.  
  157.     dx = grx_, dy = gry_;
  158.     while(*shape != EOS) {
  159.     x = dx+(*shape++);
  160.     y = dy+(*shape++);
  161.     gr_lineto(x,y);
  162.     }
  163.     printf("exiting gr_shape...\n");
  164. }
  165.  
  166.