home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Archived / Updates / Flash / flashplayer / flashlib / h / graphic < prev    next >
Encoding:
Text File  |  2000-03-24  |  4.8 KB  |  175 lines

  1. /////////////////////////////////////////////////////////////
  2. // Flash Plugin and Player
  3. // Copyright (C) 1998 Olivier Debon
  4. //
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. //
  19. ///////////////////////////////////////////////////////////////
  20. #ifndef _GRAPHIC_H_
  21. #define _GRAPHIC_H_
  22.  
  23. #define ALPHA_OPAQUE 255
  24.  
  25. enum FillType {
  26.     f_Solid          = 0x00,
  27.     f_LinearGradient = 0x10,
  28.     f_RadialGradient = 0x12,
  29.     f_TiledBitmap    = 0x40,
  30.     f_clippedBitmap  = 0x41,
  31.     f_None         = 0x80
  32. };
  33.  
  34. struct Gradient {
  35.     int         nbGradients;
  36.     unsigned char     ratio[8];
  37.     Color         color[8];
  38.     // For rendering
  39.     Color        *ramp;
  40.     Matrix         imat;
  41.     int has_alpha;
  42. };
  43.  
  44.  
  45. struct FillStyleDef {
  46.     FillType     type;    // See enum FillType
  47.  
  48.     // Solid
  49.     Color         color;
  50.  
  51.     // Gradient
  52.     Gradient     gradient;
  53.  
  54.     // Bitmap
  55.     Bitmap        *bitmap;
  56.     Matrix              bitmap_matrix;
  57. #ifdef RISCOS
  58.     long            bm_a, bm_b, bm_c, bm_d, bm_tx, bm_ty;
  59. #endif
  60.     Color               *cmap;
  61.     unsigned char *alpha_table;
  62.  
  63.     // Gradient or Bitmap
  64.     Matrix         matrix;
  65.  
  66.     FillStyleDef() {
  67.         style_size += sizeof(FillStyleDef);
  68.         style_nb++;
  69.     }
  70. };
  71.  
  72. struct Segment {
  73.     long x1,x2;
  74.     long         ymax;
  75.     FillStyleDef    *fs[2];    // 0 is left 1 is right
  76.     int         aa;
  77.     long         dX;
  78.     long         X;
  79.  
  80.     struct Segment *next;
  81.     struct Segment *nextValid;
  82. };
  83.  
  84. /* fractional bits (we don't use twips here... too expensive) */
  85. #define FRAC_BITS    5
  86. //#define FRAC         (1 << FRAC_BITS)
  87. #define FRAC         (1L << FRAC_BITS)
  88. #define NB_SEGMENT_MAX (2048*4)
  89. #define SEGFRAC         8
  90.  
  91. class GraphicDevice {
  92. protected:
  93.     Color             backgroundColor;
  94.     Color             foregroundColor;
  95.     int             targetWidth;
  96.     int              targetHeight;
  97.     Rect             viewPort;
  98.     int             movieWidth;
  99.     int             movieHeight;
  100.     int             zoom;
  101. #if !defined(RISCOS)
  102.     unsigned long         redMask;
  103.     unsigned long         greenMask;
  104.     unsigned long         blueMask;
  105. #endif
  106.     int             clipping;
  107.     FlashDisplay        *flashDisplay;
  108.     int             bgInitialized;
  109.  
  110. public:
  111.         /* polygon rasterizer */
  112.  
  113.         Segment **segs;
  114.         int ymin,ymax;
  115.         int height;
  116.         Segment *seg_pool;
  117.         Segment *seg_pool_cur;
  118.  
  119.         void *scan_line_func_id;
  120.         ScanLineFunc scan_line_func;
  121.  
  122.     long             showMore;    // Used for debugging
  123.     Rect             clip_rect;
  124.  
  125. protected:
  126.     long     clip(long &y, long &start, long &end);
  127.  
  128. public:
  129.     Matrix            *adjust;    // Matrix to fit window (shrink or expand)
  130.  
  131.     // For Direct Graphics
  132.     unsigned char         *canvasBuffer;    // A pointer to canvas'memory
  133.     long             bpl;    // Bytes per line
  134.     long             bpp;    // Bytes per pixel
  135.     long             pad;    // Scanline pad in byte
  136.  
  137.     GraphicDevice(FlashDisplay *fd);
  138.     ~GraphicDevice();
  139.  
  140.     int     setBackgroundColor(Color);
  141.     void     setForegroundColor(Color);
  142.     Color     getBackgroundColor();
  143.     Color     getForegroundColor();
  144.     void     setMovieDimension(long width, long height);
  145.     void     setMovieZoom(int zoom);
  146.     void     setMovieOffset(long x, long y);
  147.     virtual void     clearCanvas() {};
  148.     long     getWidth();
  149.     long     getHeight();
  150.     virtual long     allocColor(Color /*color*/) {return 0;};
  151.         virtual Color    getColor(unsigned long /*c*/) {Color col; return col;};
  152.         unsigned long mix_alpha(unsigned long c1, unsigned long c2, int alpha);
  153.     Color     *getColormap(Color *old, long n, Cxform *cxform);
  154.         virtual void     fillLineBitmap(FillStyleDef */*f*/, long /*y*/, long /*start*/, long /*end*/) {};
  155.     virtual void     fillLineLG(Gradient */*grad*/, long /*y*/, long /*start*/, long /*end*/) {};
  156.     virtual void     fillLineRG(Gradient */*grad*/, long /*y*/, long /*start*/, long /*end*/) {};
  157.         virtual void     fillLine(FillStyleDef */*f*/, long /*y*/, long /*start*/, long /*end*/) {};
  158.         virtual void     fillLineAA(FillStyleDef */*f*/, long /*y*/, long /*start*/, long /*end*/) {};
  159.  
  160.         virtual void     drawLine(long /*x1*/, long /*y1*/, long /*x2*/, long /*y2*/, long /*width*/) {};
  161.     void      drawBox(long x1, long y1, long x2, long y2);
  162.  
  163.         void     addSegment(long x1, long y1, long x2, long y2,
  164.                             FillStyleDef *f0,
  165.                             FillStyleDef *f1,
  166.                             int aa);
  167.  
  168.         void     drawPolygon(void);
  169.  
  170.     void     updateClippingRegion(Rect *);
  171.     void     setClipping(int);
  172. };
  173.  
  174. #endif /* _GRAPHIC_H_ */
  175.