Back to index

texmacs  1.0.7.15
renderer.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : renderer.hpp
00004 * DESCRIPTION: Abstract graphical rendering primitives
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef RENDERER_H
00013 #define RENDERER_H
00014 #include "bitmap_font.hpp"
00015 #include "url.hpp"
00016 
00017 typedef int SI;
00018 typedef unsigned int color;
00019 
00020 #define PIXEL          256
00021 #define PLUS_INFINITY  ((SI) 0x3fffffff)
00022 #define MINUS_INFINITY ((SI) 0xc0000000)
00023 
00024 /******************************************************************************
00025 * The abstract renderer class
00026 ******************************************************************************/
00027 
00028 class renderer_rep;
00029 typedef renderer_rep* renderer;
00030 class x_drawable_rep;
00031 class rectangle;
00032 typedef list<rectangle> rectangles;
00033 
00034 class renderer_rep {
00035 public:
00036   SI  ox, oy;               // origin
00037   SI  cx1, cy1, cx2, cy2;   // visible region (clipping)
00038   int sfactor;              // shrinking factor
00039   int pixel;                // PIXEL*sfactor
00040   int thicken;              // extra thinkening = (sfactor>>1)*PIXEL
00041   renderer master;          // master renderer in case of shadow renderers
00042   tree pattern;             // current background pattern
00043   int pattern_alpha;        // current background pattern transparency
00044   rectangles clip_stack;    // stack with clipping regions
00045 
00046 public:
00047   renderer_rep ();
00048   virtual ~renderer_rep ();
00049 
00050   /* routines for specific renderers */
00051   virtual bool is_printer ();
00052   virtual bool is_x_drawable ();
00053   virtual x_drawable_rep* as_x_drawable ();
00054   virtual void get_extents (int& w, int& h);
00055   virtual void next_page ();
00056   virtual bool repainted ();
00057   virtual bool interrupted (bool check= false);
00058 
00059   /* basic routines */
00060   void set_origin (SI x, SI y);
00061   void move_origin (SI dx, SI dy);
00062   void set_shrinking_factor (int sfactor);
00063   void round (SI& x, SI& y);
00064   void inner_round (SI& x1, SI& y1, SI& x2, SI& y2);
00065   void outer_round (SI& x1, SI& y1, SI& x2, SI& y2);
00066   friend void abs_round (SI& l);
00067   friend void abs_round (SI& x, SI& y);
00068   friend void abs_inner_round (SI& x1, SI& y1, SI& x2, SI& y2);
00069   friend void abs_outer_round (SI& x1, SI& y1, SI& x2, SI& y2);
00070   bool is_visible (SI x1, SI y1, SI x2, SI y2);
00071 
00072   /* color */
00073   virtual color get_color () = 0;
00074   virtual color get_background () = 0;
00075   virtual tree  get_background_pattern (int& alpha);
00076 
00077   /* main graphical routines */
00078   virtual void set_color (color c) = 0;
00079   virtual void set_background (color c) = 0;
00080   virtual void set_background_pattern (tree t, int alpha= 255);
00081   virtual void draw (int char_code, font_glyphs fn, SI x, SI y) = 0;
00082   virtual void set_line_style (SI w, int type=0, bool round=true) = 0;
00083   virtual void line (SI x1, SI y1, SI x2, SI y2) = 0;
00084   virtual void lines (array<SI> x, array<SI> y) = 0;
00085   virtual void clear (SI x1, SI y1, SI x2, SI y2) = 0;
00086   virtual void clear_pattern (SI x1, SI y1, SI x2, SI y2);
00087   virtual void fill (SI x1, SI y1, SI x2, SI y2) = 0;
00088   virtual void arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta) = 0;
00089   virtual void fill_arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta) = 0;
00090   virtual void polygon (array<SI> x, array<SI> y, bool convex=true) = 0;
00091   virtual void triangle (SI x1, SI y1, SI x2, SI y2, SI x3, SI y3);
00092   virtual void xpm (url file_name, SI x, SI y) = 0;
00093   virtual void image (url u, SI w, SI h, SI x, SI y,
00094                     double cx1, double cy1, double cx2, double cy2,
00095                       int alpha= 255) = 0;
00096   virtual void get_clipping (SI &x1, SI &y1, SI &x2, SI &y2);
00097   virtual void set_clipping (SI x1, SI y1, SI x2, SI y2, bool restore= false);
00098   void extra_clipping (SI x1, SI y1, SI x2, SI y2);
00099   void clip (SI x1, SI y1, SI x2, SI y2);
00100   void unclip ();
00101 
00102   /* shadowing and copying rectangular regions across renderers */
00103   virtual void fetch (SI x1, SI y1, SI x2, SI y2, renderer ren, SI x, SI y)=0;
00104   virtual void new_shadow (renderer& ren) = 0;
00105   virtual void delete_shadow (renderer& ren) = 0;
00106   virtual void get_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) = 0;
00107   virtual void put_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) = 0;
00108   virtual void apply_shadow (SI x1, SI y1, SI x2, SI y2) = 0;
00109 
00110   /* href and stuff */
00111   virtual void anchor(string label, SI x, SI y);
00112   virtual void href(string label, SI x1, SI y1, SI x2, SI y2);
00113 
00114   /* miscellaneous */
00115   virtual void draw_rectangles (rectangles rs);
00116   virtual void draw_selection (rectangles rs);
00117 };
00118 
00119 void abs_round (SI& l);
00120 void abs_round (SI& x, SI& y);
00121 void abs_inner_round (SI& x1, SI& y1, SI& x2, SI& y2);
00122 void abs_outer_round (SI& x1, SI& y1, SI& x2, SI& y2);
00123     
00124 #endif // defined RENDERER_H