Laxkit  0.0.7.1
patchinterface.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) 2004-2007,2010-2011 by Tom Lechner
22 //
23 #ifndef _LAX_PATCHINTERFACE_H
24 #define _LAX_PATCHINTERFACE_H
25 
26 #include <lax/interfaces/aninterface.h>
27 #include <lax/interfaces/somedata.h>
28 #include <lax/interfaces/linestyle.h>
29 #include <lax/screencolor.h>
30 
31 
32 
33 
34 namespace LaxInterfaces {
35 
36 typedef enum _PatchControls {
37  Patch_Full_Bezier=0,
38  Patch_Coons,
39  Patch_Border_Only,
40  Patch_Linear,
41  Patch_MAX
42 } PatchControls;
43 
44 
45  // matrix utilities
46 void getPolyT(double *N, double n, double t0);
47 void m_transpose(double *M);
48 void printG(const char *ch,double *G);
49 void getScaledI(double *I,double a,double b,double c,double d);
50 void getI(double *I);
51 void m_times_m(double *a,double *b,double *m);
52 void m_times_v(double *m,double *b,double *v);
53 double dot(double *a,double *b);
54 void getT(double *v,double t) ;
55 
56 
57 //------------------------------------- PatchRenderContext ------------------------
59 {
60  public:
61  double Cx[16],Cy[16];
62  double V[4]; //temp space
63  double s0,ds,t0,dt;
64 
65  unsigned char *buffer;
66  int bufferwidth,bufferheight;
67  int numchannels; //usually 4 (argb) and 8bits
68  int bitsperchannel; //8 or 16
69  int stride; //usually bufferwidth * numchannels * bitsperchannel/8
70 
71  flatpoint getPoint(double *S,double *T);
72 };
73 
74 //------------------------------ PatchData ---------------------
75 
76 #define PATCH_SMOOTH (1<<0)
77 
78 
79 class PatchData : virtual public SomeData
80 {
81  protected:
82 
83  public:
85  int griddivisions;
86  flatpoint *points;
87  int xsize,ysize; // sizes%3 must == 1, numpoints=xsize*ysize
88  unsigned int style;
89  PatchControls controls;
90  LineStyle linestyle;
91 
92  PatchData();
93  PatchData(double xx,double yy,double ww,double hh,int nr,int nc,unsigned int stle);
94  virtual ~PatchData();
95  virtual const char *whattype() { return "PatchData"; }
96  virtual SomeData *duplicate(SomeData *dup);
97  virtual void FindBBox();
98  virtual int pointin(flatpoint pp,int pin=1);
99 
102  virtual int hasColorData();
103  virtual flatpoint getControlPoint(int r,int c);
104  virtual flatpoint getPoint(double t,double s);
105  virtual flatpoint *bezAtEdge(flatpoint *p,int i,int row);
106  virtual flatpoint *bezCrossSection(flatpoint *p,int i,double t,int row);
107  virtual int bezOfPatch(flatpoint *p,int r,int rl,int c,int cl);
108  virtual void resolveToSubpatch(double s,double t,int &c,double &ss,int &r,double &tt);
109  virtual void resolveFromSubpatch(int c,double ss,int r,double tt,double &s,double &t);
110  virtual void getGt(double *G,int roffset,int coffset,int isfory);
111  virtual int inSubPatch(flatpoint p,int *r_ret,int *c_ret,double *t_ret,double *s_ret,double d);
112  virtual int coordsInSubPatch(flatpoint p,int r,int c,double maxd, double *s_ret,double *t_ret);
113  virtual int WhatColor(double s,double t,Laxkit::ScreenColor *color_ret);
115 
118  virtual void Set(double xx,double yy,double ww,double hh,int nr,int nc,unsigned int stle);
119  virtual void zap(flatpoint p,flatpoint x,flatpoint y);
120  virtual void zap(); // zap to bbox
121  virtual int subdivide(int r,double rt,int c,double ct);
122  virtual int subdivide(int xn=2,int yn=2);
123  virtual void grow(int where, double *tr);
124  virtual void collapse(int rr,int cc);
125  virtual void InterpolateControls(int whichcontrols);
126  virtual int warpPatch(flatpoint center, double r1,double r2, double s,double e);
128 
131  //rendering functions
132  virtual int renderToBuffer(unsigned char *buffer, int bufw, int bufh, int bufstride, int bufdepth, int bufchannels);
133  virtual void rpatchpoint(PatchRenderContext *context,
135  double s1,double t1, double s2,double t2,int which);
136  virtual void patchpoint(PatchRenderContext *context, double s0,double ds,double t0,double dt,int n);
137 
138  virtual void dump_out(FILE *f,int indent,int what,Laxkit::anObject *context);
139  virtual void dump_in_atts(LaxFiles::Attribute *att,int flag,Laxkit::anObject *context);
141 };
142 
143 
144 
145 //------------------------------ PatchInterface ---------------------
146 
147 enum PatchInterfaceActions {
148  PATCHA_RenderMode,
149  PATCHA_RecurseInc,
150  PATCHA_RecurseDec,
151  PATCHA_SmoothEdit,
152  PATCHA_MeshType,
153  PATCHA_MeshTypeR,
154  PATCHA_Select,
155  PATCHA_ConstrainY,
156  PATCHA_ConstrainX,
157  PATCHA_RowDivInc,
158  PATCHA_RowDivDec,
159  PATCHA_ColDivInc,
160  PATCHA_ColDivDec,
161  PATCHA_Subdivide,
162  PATCHA_SubdivideRows,
163  PATCHA_SubdivideCols,
164  PATCHA_Rectify,
165  PATCHA_Decorations,
166  PATCHA_CircleWarp,
167  PATCHA_SelectCorners,
168  PATCHA_SelectMids,
169  PATCHA_SelectEdgeMids,
170  PATCHA_SelectVerticalEdgeMids,
171  PATCHA_SelectHorizontalEdgeMids,
172  PATCHA_SelectAllVertically,
173  PATCHA_SelectMoreVertically,
174  PATCHA_SelectAllHorizontally,
175  PATCHA_SelectMoreHorizontally,
176  PATCHA_SelectAround,
177  PATCHA_MAX
178 };
179 
181 {
182  protected:
183  double movetransform[6];
184  flatpoint *movepts;
185  flatpoint lbdown;
186  flatpoint *cuth,*cutv;
187  double cutatct, cutatrt;
188  int overv,overh,overcv,overch,overstate;
189  int dragmode;
190  int hoverpoint;
191 
192  int bx,by,mx,my,constrain;
193  Laxkit::NumStack<int> curpoints;
194  void getG(double *G,int roffset,int coffset,int isfory);
195  virtual int selectablePoint(int i);
196  int mousedragged;
197  virtual int findNearHorizontal(flatpoint fp,double d,double *t_ret,int *i_ret);
198  virtual int findNearVertical(flatpoint fp,double d,double *t_ret,int *i_ret);
199  virtual void drawControlPoints();
200  virtual void drawControlPoint(int i);
201 
203  virtual int PerformAction(int action);
204  public:
205  //draw exterior and interior grid lines
206  enum PatchDecorations {
207  SHOW_Grid =(1<<0),
208  //draw indicators for the points
209  SHOW_Points =(1<<1),
210  //draw the exterior edges
211  SHOW_Edges =(1<<2),
212  SHOW_Max =(1<<3)
213  };
214 
215  // these are the state:
216  LineStyle linestyle;
217  unsigned long rimcolor,handlecolor,gridcolor;
218  int xs,ys, rdiv,cdiv;
219  unsigned long controlcolor;
220  int showdecs, oldshowdecs;
221  char whichcontrols;
222  int recurse;
224 
225  PatchData *data;
226  ObjectContext *poc;
227 
228  PatchInterface(int nid,Laxkit::Displayer *ndp);
229  virtual ~PatchInterface();
230  virtual Laxkit::ShortcutHandler *GetShortcuts();
231  virtual const char *IconId() { return "Patch"; }
232  virtual const char *Name();
233  virtual const char *whattype() { return "PatchInterface"; }
234  virtual const char *whatdatatype() { return "PatchData"; }
235  virtual anInterface *duplicate(anInterface *dup);
236  virtual int UseThisObject(ObjectContext *oc);
237  virtual int UseThis(Laxkit::anObject *newdata,unsigned int mask=0);
238  virtual int UseThis(int id,int ndata);
239  virtual void Clear(SomeData *d=NULL);
240  virtual int InterfaceOn();
241  virtual int InterfaceOff();
242  virtual ObjectContext *Context() { return poc; }
243  virtual int LBDown(int x,int y,unsigned int state,int count,const Laxkit::LaxMouse *d);
244  virtual int LBUp(int x,int y,unsigned int state,const Laxkit::LaxMouse *d);
245  virtual int MouseMove(int x,int y,unsigned int state,const Laxkit::LaxMouse *d);
246  virtual int CharInput(unsigned int ch, const char *buffer,int len,unsigned int state,const Laxkit::LaxKeyboard *d);
247  virtual int KeyUp(unsigned int ch,unsigned int state,const Laxkit::LaxKeyboard *d);
248 
249  virtual void drawpatch(int roff,int coff);
250  virtual void drawpatches();
251  virtual int Refresh();
252  virtual int DrawData(Laxkit::anObject *ndata,Laxkit::anObject *a1=NULL,Laxkit::anObject *a2=NULL,int info=0);
253 
254  virtual PatchData *newPatchData(double xx,double yy,double ww,double hh,int nr,int nc,unsigned int stle);
255  virtual void deletedata();
256  virtual int scan(int x,int y);
257  virtual int SelectPoint(int c,unsigned int state);
258 };
259 
260 } // namespace LaxInterfaces;
261 
262 #endif
263 

Mon Feb 17 2014 11:52:57, Laxkit