Laxkit  0.0.7.1
curvewindow.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) 2013 by Tom Lechner
22 //
23 #ifndef _LAX_CURVEWINDOW_H
24 #define _LAX_CURVEWINDOW_H
25 
26 #include <lax/anxapp.h>
27 #include <lax/rectangles.h>
28 #include <lax/buttondowninfo.h>
29 
30 namespace Laxkit {
31 
32 
33 
35 {
36  private:
37  void base_init();
38 
39  public:
40  enum CurveTypes {
41  Linear,
42  Autosmooth,
43  Bezier
44  };
45 
46  double xmin, xmax;
47  double ymin, ymax;
48  char *xlabel, *ylabel;
49  char *title;
50  CurveTypes curvetype;
51 
52  int numsamples, lookup_min, lookup_max;
53  int *lookup;
54 
55  NumStack<flatpoint> points;
56  NumStack<flatpoint> fauxpoints;
57 
58  CurveInfo();
59  CurveInfo(const char *ntitle,
60  const char *xl, double nxmin, double nxmax,
61  const char *yl, double nymin, double nymax);
62  virtual ~CurveInfo();
63  virtual const char *whattype() { return "CurveInfo"; }
64  virtual void SetXBounds(double nxmin, double nxmax);
65  virtual void SetYBounds(double nymin, double nymax);
66  virtual void SetTitle(const char *ntitle);
67  virtual double f(double x);
68  virtual double f_linear(double x);
69  virtual double f_autosmooth(double x);
70  virtual double f_bezier(double x);
71  virtual flatpoint MapUnitPoint(flatpoint p);
72  virtual int AddPoint(double x,double y);
73  virtual int MovePoint(int index, double x,double y);
74  virtual void SetSinusoidal(int samples);
75  virtual void Reset();
76 
77  virtual void MakeFakeCurve();
78  virtual int MakeLookupTable(int *table,int numentries, int minvalue, int maxvalue);
79  virtual void RefreshLookup();
80  virtual void RefreshLookup(int nsamples, int nmin, int nmax);
81  virtual void LookupDump(const char *label,FILE *f);
82 
83  //serializing aids
84  virtual void dump_out(FILE *f,int indent,int what,anObject *context);
85  virtual LaxFiles::Attribute *dump_out_atts(LaxFiles::Attribute *att,int what,anObject *context);
86  virtual void dump_in_atts(LaxFiles::Attribute *att,int flag,anObject *context);
87 };
88 
89 
90 enum CurveWindowStyles {
91  CURVE_Show_Ranges=(1<<15),
92 };
93 
94 class CurveWindow : public anXWindow
95 {
96  protected:
97  LaxFont *smallnumbers;
98  IntRectangle rect;
99  unsigned int curve_win_style;
100  int firsttime;
101  CurveInfo *curveinfo;
102  ButtonDownInfo buttondown;
103 
104  int show_label_ranges;
105  int show_labels;
106  int always_refresh_lookup;
107  int highlighteditable;
108 
109  flatpoint lastpoint;
110  int draglimbo;
111  flatpoint ClampPoint(flatpoint p, int pp);
112 
113  int *histogram; //in range [0..1000]
114  int hist_n;
115 
116  public:
117  enum CurveWindowEditable {
118  YMax =(1<<0),
119  YMin =(1<<1),
120  XMax =(1<<2),
121  XMin =(1<<3),
122  YUnits=(1<<4),
123  XUnits=(1<<5)
124  };
125 
126  int padouter, padinner;
127  unsigned int curve_color;
128  unsigned int graph_color;
129  unsigned int editable; //mask of enum curvewindoweditable
130 
131  CurveWindow(anXWindow *parnt,const char *nname,const char *ntitle,unsigned long nstyle,
132  int xx,int yy,int ww,int hh,int brder,
133  anXWindow *prev, unsigned long nowner, const char *nsend,
134  const char *nctitle=NULL,
135  const char *xl=NULL, double nxmin=0, double nxmax=1,
136  const char *yl=NULL, double nymin=0, double nymax=1);
137  virtual ~CurveWindow();
138  virtual const char *whattype() { return "CurveWindow"; }
139  //virtual int init();
140  virtual void Refresh();
141  virtual int LBDown(int x,int y,unsigned int state,int count,const LaxMouse *d);
142  virtual int LBUp(int x,int y,unsigned int state,const LaxMouse *d);
143  //virtual int MBDown(int x,int y,unsigned int state,int count,const LaxMouse *d);
144  //virtual int MBUp(int x,int y,unsigned int state,const LaxMouse *d);
145  //virtual int RBDown(int x,int y,unsigned int state,int count,const LaxMouse *d);
146  //virtual int RBUp(int x,int y,unsigned int state,const LaxMouse *d);
147  virtual int WheelUp(int x,int y,unsigned int state,int count,const LaxMouse *d);
148  virtual int WheelDown(int x,int y,unsigned int state,int count,const LaxMouse *d);
149  virtual int MouseMove(int x,int y,unsigned int state,const LaxMouse *d);
150  virtual int MoveResize(int nx,int ny,int nw,int nh);
151  virtual int Resize(int nw,int nh);
152  virtual int Event(const EventData *e,const char *mes);
153  virtual void ChangeEditable(unsigned int which, int on);
154 
155  //serializing aids
156  virtual LaxFiles::Attribute *dump_out_atts(LaxFiles::Attribute *att,int what,anObject *context);
157  virtual void dump_in_atts(LaxFiles::Attribute *att,int flag,anObject *context);
158 
159 
160  //curve specific functions:
161  virtual void SetupRect();
162  virtual int scaneditable(int x,int y);
163  virtual int scan(int x,int y);
164  virtual int scannear(int x,int y, flatpoint *p_ret, int *index);
165  virtual int MakeLookupTable(int *table,int numentries, int minvalue, int maxvalue);
166  virtual void send(int which=0);
167  virtual double f(double x);
168  virtual CurveInfo *GetInfo() { return curveinfo; }
169  virtual int SetInfo(CurveInfo *info);
170  virtual int AddPoint(double x,double y);
171  virtual int MovePoint(int index, double x,double y);
172  virtual void Reset();
173 };
174 
175 
176 } // namespace Laxkit
177 
178 #endif
179 
180 
181 

Mon Feb 17 2014 11:52:56, Laxkit