Laxkit  0.0.7.1
gradientinterface.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-2011 by Tom Lechner
22 //
23 #ifndef _LAX_GRADIENTINTERFACE_H
24 #define _LAX_GRADIENTINTERFACE_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 namespace LaxInterfaces {
32 
33 
34 #define GRADIENT_RADIAL (1<<0)
35 #define GRADIENT_LINEAR (1<<1)
36 #define GRADIENT_FILL_PARENT (1<<2)
37 
38 //--------------------------------- GradientDataSpot ----------------------------
39 
41 {
42  public:
43  double t;
44  Laxkit::ScreenColor color;
45  GradientDataSpot(double tt,Laxkit::ScreenColor *col);
46  GradientDataSpot(double tt,int rr,int gg,int bb,int aa);
47  virtual ~GradientDataSpot() {}
48  virtual void dump_out(FILE *f,int indent,int what,Laxkit::anObject *context);
49  virtual void dump_in(FILE *f,int indent,Laxkit::anObject *context,LaxFiles::Attribute **Att=NULL);
50  virtual void dump_in_atts(LaxFiles::Attribute *att,int flag,Laxkit::anObject *context);
51 };
52 
53 //--------------------------------- GradientData ----------------------------
54 class GradientData : virtual public SomeData
55 {
56  protected:
57 
58  public:
59  unsigned int style;
60  double p1, p2, r1, r2, a;
62  GradientData();
63  GradientData(flatpoint pp1,flatpoint pp2,double rr1,double rr2,
64  Laxkit::ScreenColor *col1,Laxkit::ScreenColor *col2,unsigned int stle);
65  virtual ~GradientData() {}
66  virtual void Set(flatpoint pp1,flatpoint pp2,double rr1,double rr2,
67  Laxkit::ScreenColor *col1,Laxkit::ScreenColor *col2,unsigned int stle);
68  virtual const char *whattype() { return "GradientData"; }
69  virtual SomeData *duplicate(SomeData *dup);
70  virtual void FindBBox();
71  virtual int pointin(flatpoint pp,int pin=1);
72  virtual int ShiftPoint(int which,double dt);
73  virtual int AddColor(double t,int red,int green,int blue,int alpha);
74  virtual int AddColor(double t,Laxkit::ScreenColor *col);
75  virtual int WhatColor(double t,Laxkit::ScreenColor *col);
76  virtual int WhatColor(double t,double *col);
77  virtual int AddColor(GradientDataSpot *spot);
78  virtual void FlipColors();
79 
80  virtual int renderToBuffer(unsigned char *buffer, int bufw, int bufh, int bufstride, int bufdepth, int bufchannels);
81 
82  virtual void dump_out(FILE *f,int indent,int what,Laxkit::anObject *context);
83  virtual void dump_in_atts(LaxFiles::Attribute *att,int flag,Laxkit::anObject *context);
84 };
85 
86 
87 //--------------------------------- GradientInterface ----------------------------
88 
89 
91 {
92  protected:
93  int mx,my,draggingmode;
94  int curpoint; //-1=whole thing, >=0 is color point, -2 is none
96  virtual void newData(int x,int y);
98 
100  virtual int PerformAction(int action);
101  public:
102  // these are gradient state:
103  unsigned long controlcolor;
104  int creationstyle,showdecs,usepreview;
105  Laxkit::ScreenColor col1,col2;
106  flatpoint createv;
107  double creater1,creater2;
109 
110  GradientData *data;
111  ObjectContext *goc;
112 
113  GradientInterface(int nid,Laxkit::Displayer *ndp);
114  virtual ~GradientInterface();
115  virtual Laxkit::ShortcutHandler *GetShortcuts();
116  virtual anInterface *duplicate(anInterface *dup);
117  virtual const char *IconId();
118  virtual const char *Name();
119  virtual const char *whattype() { return "GradientInterface"; }
120  virtual const char *whatdatatype() { return "GradientData"; }
121  virtual int InterfaceOn();
122  virtual int InterfaceOff();
123  virtual int UseThis(Laxkit::anObject *newdata,unsigned int); // assumes not use local
124  virtual int UseThisObject(ObjectContext *oc);
125  virtual void Clear(SomeData *d) { if ((!d && data) || (d && d==data)) { data->dec_count(); data=NULL; } }
126 
127  virtual int LBDown(int x,int y,unsigned int state,int count,const Laxkit::LaxMouse *d);
128  virtual int LBUp(int x,int y,unsigned int state,const Laxkit::LaxMouse *d);
129  virtual int MouseMove(int x,int y,unsigned int state,const Laxkit::LaxMouse *d);
130  virtual int CharInput(unsigned int ch, const char *buffer,int len,unsigned int state,const Laxkit::LaxKeyboard *d);
131 
132  virtual int Refresh();
133  virtual void drawLinear();
134  virtual void drawRadial();
135  virtual void drawRadialLine(double t);
136  virtual int DrawData(Laxkit::anObject *ndata,Laxkit::anObject *a1=NULL,Laxkit::anObject *a2=NULL,int info=0);
137 
138  virtual int scan(int x,int y);
139  virtual int SelectPoint(int c);
140  virtual void deletedata();
141  virtual ObjectContext *Context() { return goc; }
142  virtual flatpoint getpoint(int c, int trans);
143  virtual int sendcolor(Laxkit::ScreenColor *col);
144 };
145 
146 } // namespace LaxInterfaces;
147 
148 #endif
149 

Mon Feb 17 2014 11:52:56, Laxkit