Laxkit  0.0.7.1
displayer-cairo.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2012 by Tom Lechner
22 //
23 #ifndef _LAX_DISPLAYER_CAIRO_H
24 #define _LAX_DISPLAYER_CAIRO_H
25 
26 #include <cairo/cairo-xlib.h>
27 #include <cairo/cairo-ft.h>
28 
29 #include <lax/displayer.h>
30 
31 
32 namespace Laxkit {
33 
34 class DisplayerCairo : public Displayer
35 {
36  protected:
37  char *buffer;
38  int bufferlen;
39  virtual int reallocBuffer(int len);
40 
41  Display *dpy; //if any
42  Visual *vis;
43  Window w;
44 
45  LaxCompositeOp blendmode;
46  int isinternal;
47  cairo_t *cr;
48  cairo_surface_t *target;
49  cairo_surface_t *surface;
50  cairo_surface_t *mask;
51  cairo_surface_t *source;
52  //PtrStack<cairo_surface_t> groups;
53 
54  double ctm[6],ictm[6];
55  PtrStack<double> axesstack;
56 
57  double fgRed, fgGreen, fgBlue, fgAlpha;
58  double bgRed, bgGreen, bgBlue, bgAlpha;
59 
60  cairo_font_face_t *curfont;
61  cairo_scaled_font_t *curscaledfont;
62  double _textheight;
63 
64  void base_init();
65  public:
66  DisplayerCairo(anXWindow *nxw=NULL,PanController *pan=NULL);
67  virtual ~DisplayerCairo();
68  virtual Displayer *duplicate();
69 
72  virtual Display *GetDpy();
74 
75  virtual cairo_t *GetCairo();
76 
79  virtual void SwapBuffers();
80  virtual void BackBuffer(int on);
81 
82  virtual void WrapWindow(anXWindow *nw);
83  virtual int StartDrawing(aDrawable *buffer);
84  virtual int MakeCurrent(aDrawable *buffer);
85  virtual int ClearDrawable(aDrawable *drawable);
86  virtual int CreateSurface(int w,int h, int type=-1);
87  virtual int ResizeSurface(int width, int height);
88  virtual LaxImage *GetSurface();
89  virtual int EndDrawing();
91 
94  virtual unsigned long NewFG(double r,double g,double b,double a=1.0);
95  virtual unsigned long NewFG(unsigned long ncol);
96  virtual unsigned long NewFG(ScreenColor *col);
97  virtual unsigned long NewFG(int r,int g,int b,int a=255);
98  virtual unsigned long NewBG(double r,double g,double b);
99  virtual unsigned long NewBG(int r,int g,int b);
100  virtual unsigned long NewBG(unsigned long nc);
101  virtual unsigned long FG();
102  virtual unsigned long BG();
103  virtual void LineAttributes(double width,int dash,int cap,int join);
104  virtual void FillAttributes(int fillstyle, int fillrule);
105  virtual LaxCompositeOp BlendMode(LaxCompositeOp mode);
106  virtual void setCairoBlendMode(cairo_operator_t mode);
108 
109 
112  virtual void ClearWindow();
113  virtual flatpoint realtoscreen(flatpoint p);
114  virtual flatpoint realtoscreen(double x,double y);
115  virtual flatpoint screentoreal(int x,int y);
116  virtual flatpoint screentoreal(flatpoint p);
117 
118  virtual int Clip(flatpoint *p, int n, int append);//install a clip mask from a polyline (line is automatically closed)
119  virtual void PushClip(int startfresh); //push the current clip mask onto a stack, make a new one maybe
120  virtual void PopClip(); //restore a previous mask
121  virtual void ClearClip(); //remove any mask
122  virtual int activeMask(); //return whether there is an active mask
123 
124  //path drawing and filling
125  virtual void DrawOnMask();
126  virtual void DrawOnSrc();
127 
128  virtual void show(); //collapse source through mask onto surface
129  virtual void fill(int preserve);
130  virtual void stroke(int preserve);
131  virtual void moveto(flatpoint p);
132  virtual void lineto(flatpoint p);
133  virtual void curveto(flatpoint c1,flatpoint c2,flatpoint v);
134  virtual void closed();
135  virtual void closeopen();
136 
137  virtual void drawpixel(flatpoint p);
138  virtual void drawpoint(double x,double y,double radius,int tofill); //draw filled circle radius r
139  virtual void drawlines(flatpoint *points,int npoints,char isclosed,char tofill);
140  virtual void drawline(flatpoint p1,flatpoint p2);
141  virtual void drawline(double ax,double ay,double bx,double by);
142 
143  //draw text
144  virtual void initFont(); //not from Displayer
145  virtual int textheight();
146  virtual int font(LaxFont *nfont, double size=-1);
147  virtual int font(const char *fontconfigpattern);
148  virtual int font(const char *family,const char *style,double pixelsize);
149  virtual int fontsize(double size);
150  virtual double textextent(LaxFont *thisfont, const char *str,int len, double *width,double *height,double *ascent,double *descent,char real);
151  virtual double textout(double x,double y,const char *str,int len=0,unsigned long align=LAX_CENTER);
152  virtual double textout(double *matrix,double x,double y,const char *str,int len=0,unsigned long align=LAX_CENTER);
153  virtual double textout(double angle, double x,double y,const char *str,int len=0,unsigned long align=LAX_CENTER);
154 
155  //draw images
156  virtual void imageout(LaxImage *img,double x,double y);
157  virtual int imageout(LaxImage *img, double x,double y, double w,double h);
158  virtual void imageout(LaxImage *img,double *matrix);
159  virtual void imageout(LaxImage *img,double angle, double x,double y);
160  virtual void imageout_rotated(LaxImage *img,double x,double y,double ulx,double uly);
161  virtual void imageout_skewed(LaxImage *img,double x,double y,double ulx,double uly,double urx,double ury);
162 
163 
166  virtual const double *Getctm();
167  virtual const double *Getictm();
168 
169  virtual void ShiftScreen(int dx,int dy);
170  virtual void NewTransform(const double *d);
171  virtual void NewTransform(double a,double b,double c,double d,double x0,double y0);
172  virtual void PushAxes();
173  virtual void PopAxes();
174  virtual int DrawReal(); //any subsequent calls are using real coordinates
175  virtual int DrawScreen(); //any subsequent calls are using screen coordinates
177 };
178 
179 } // namespace Laxkit
180 
181 #endif

Mon Feb 17 2014 11:52:56, Laxkit