Laxkit  0.0.7.1
displayer-xlib.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_XLIB_H
24 #define _LAX_DISPLAYER_XLIB_H
25 
26 #include <lax/anxapp.h>
27 #include <lax/vectors.h>
28 #include <lax/pancontroller.h>
29 #include <lax/panuser.h>
30 #include <lax/laxutils.h>
31 #include <lax/doublebbox.h>
32 #include <lax/laximages.h>
33 #include <lax/screencolor.h>
34 
35 #define DISPLAYER_NO_SHEAR (1<<0)
36 
37 namespace Laxkit {
38 
39 class DisplayerXlib : public Displayer
40 {
41  private:
42  void base_init();
43 
44  protected:
45  //not base displayer:
46  Display *dpy;
47  Window w;
48  Visual *vis;
49  GC gc;
50  int isinternal;
51 
52  XftFont *xfont;
53  XftFont *tempfont;
54  LaxFont *laxfont;
55  //XftColor textxftcolor;
56  XftDraw *textxftdraw;
57 
58  Region clipregion;
59  Pixmap clipmask;
60  NumStack<Region> clipstack;
61  virtual int Clip(Region newregion, int append);
62 
63  NumStack<flatpoint> curpoints;
64  NumStack<int> multiplepaths;
65  NumStack<int> multipleclosedpaths;
66  XPoint *xpoints; //of current path(s)
67  int needtobuildxpoints;
68  int maxxpoints_allocated;
69  int numxpoints;
70  int num_bez_div;
71  virtual void buildXPoints();
72 
73  double *ctm,ictm[6];
75  unsigned long fgcolor,bgcolor;
76  ScreenColor fg,bg;
77  LaxCompositeOp drawmode;
78 
79  public:
81  DisplayerXlib(anXWindow *w=NULL,PanController *pan=NULL);
82  virtual ~DisplayerXlib();
83  virtual Displayer *duplicate();
84 
87  virtual Display *GetDpy() { return dpy; }
88  virtual aDrawable *GetXw() { return xw; }
89  virtual Drawable GetXDrawable() { return w; }
90  virtual GC GetGC() { return gc; }
91  XftDraw *textdraw(Window xlib_window);
93 
96  virtual void SwapBuffers();
97  virtual void BackBuffer(int on);
98  virtual int StartDrawing(aDrawable *buffer);
99  virtual int MakeCurrent(aDrawable *buffer);
100  virtual int ClearDrawable(aDrawable *drawable);
101  virtual int CreateSurface(int width,int height, int type=-1);
102  virtual LaxImage *GetSurface();
103  virtual int ResizeSurface(int width, int height);
104  virtual int EndDrawing();
106 
109  virtual unsigned long NewFG(double r,double g,double b,double a=1.0);
110  virtual unsigned long NewFG(unsigned long ncol);
111  virtual unsigned long NewFG(ScreenColor *col);
112  virtual unsigned long NewFG(int r,int g,int b,int a=255);
113  virtual unsigned long NewBG(double r,double g,double b);
114  virtual unsigned long NewBG(int r,int g,int b);
115  virtual unsigned long NewBG(unsigned long nc);
116  virtual unsigned long FG() { return fgcolor; }
117  virtual unsigned long BG() { return bgcolor; }
118  virtual void LineAttributes(double width,int dash,int cap,int join);
119  virtual void FillAttributes(int fillstyle, int fillrule);
122 
123 
126  virtual void ClearWindow();
127  virtual flatpoint realtoscreen(flatpoint p);
128  virtual flatpoint realtoscreen(double x,double y);
129  virtual flatpoint screentoreal(int x,int y);
130  virtual flatpoint screentoreal(flatpoint p);
131 
132  virtual int Clip(flatpoint *p, int n, int append);//install a clip mask from a polyline (line is automatically closed)
133  virtual void PushClip(int startfresh); //push the current clip mask onto a stack, make a new one maybe
134  virtual void PopClip(); //restore a previous mask
135  virtual void ClearClip(); //remove any mask
136  virtual int activeMask(); //return whether there is an active mask
137 
138  //path drawing and filling
139  virtual int DrawReal(); //any subsequent calls are using real coordinates
140  virtual int DrawScreen(); //any subsequent calls are using screen coordinates
141  virtual void DrawOnMask();
142  virtual void DrawOnSrc();
143 
144  virtual void show(); //collapse source through mask onto surface
145  virtual void fill(int preserve);
146  virtual void stroke(int preserve);
147  virtual void moveto(flatpoint p);
148  virtual void lineto(flatpoint p);
149  virtual void curveto(flatpoint c1,flatpoint c2,flatpoint v);
150  virtual void closed();
151  virtual void closeopen();
152  virtual void drawpixel(flatpoint p);
153  virtual void drawpoint(double x,double y,double radius,int fill); //draw filled circle radius r
154  virtual void drawlines(flatpoint *points,int npoints,char closed,char fill);
155  virtual void drawline(flatpoint p1,flatpoint p2);
156  virtual void drawline(double ax,double ay,double bx,double by);
157 
158  //draw text
159  virtual int textheight();
160  virtual int font(LaxFont *nfont, double size=-1);
161  virtual int font(const char *fontconfigpattern);
162  virtual int font(const char *family,const char *style,double pixelsize);
163  virtual int fontsize(double size);
164  virtual double textextent(LaxFont *thisfont, const char *str,int len, double *width,double *height,double *ascent,double *descent,char real);
165  virtual double textout_line(double x,double y,const char *str,int len=0,unsigned long align=LAX_CENTER);
166  virtual double textout(double x,double y,const char *str,int len=0,unsigned long align=LAX_CENTER);
167  virtual double textout(double *matrix,double x,double y,const char *str,int len=0,unsigned long align=LAX_CENTER);
168  virtual double textout(double angle, double x,double y,const char *str,int len=0,unsigned long align=LAX_CENTER);
169 
170  //draw images
171  virtual int imageout(LaxImage *image, double x,double y, double w,double h);
172  virtual void imageout(LaxImage *img,double x,double y);
173  virtual void imageout(LaxImage *img,double *matrix);
174  virtual void imageout(LaxImage *img,double angle, double x,double y);
175  virtual void imageout_rotated(LaxImage *img,double x,double y,double ulx,double uly);
176  virtual void imageout_skewed(LaxImage *img,double ulx,double uly,double urx,double ury,double llx,double lly);
177 
178 
181  virtual double *m() { return ctm; }
182  virtual const double *Getctm() { return ctm; }
183  virtual const double *Getictm() { return ictm; }
184  virtual void findictm();
185 
186  virtual void ShiftScreen(int dx,int dy);
187  virtual void ShiftReal(double dx,double dy);
188  virtual void NewTransform(const double *d);
189  virtual void NewTransform(double a,double b,double c,double d,double x0,double y0);
190  virtual void PushAndNewTransform(const double *m);
191  virtual void PushAndNewAxes(flatpoint p,flatpoint x,flatpoint y);
192  virtual void PushAxes();
193  virtual void PopAxes();
194  virtual void Newangle(double angle,int dir=0,int dec=1);
195  virtual void Rotate(double angle,int x,int y,int dec=1);
196  virtual void Newmag(double xs,double ys=-1);
197  virtual void Zoomr(double m,flatpoint p);
198  virtual void Zoom(double m,int x,int y);
199  virtual void Zoom(double m);
200  virtual double Getmag(int c=0);
201  virtual double GetVMag(int x,int y);
203 };
204 
205 } // namespace Laxkit
206 
207 #endif

Mon Feb 17 2014 11:52:56, Laxkit