Laxkit  0.0.7.1
units.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) 2011 by Tom Lechner
22 //
23 #ifndef _LAX_UNITS_H
24 #define _LAX_UNITS_H
25 
26 #include <lax/lists.h>
27 
28 namespace Laxkit {
29 
30 enum UnitTypes {
31  UNITS_None=0,
32  UNITS_Inches,
33  UNITS_Feet,
34  UNITS_Yards,
35  UNITS_CM,
36  UNITS_MM,
37  UNITS_Meters,
38  UNITS_Points,
39  UNITS_Pixels,
40  UNITS_MAX
41 };
42 
43 //------------------------------------- SimpleUnit ----------------------------------------
45 {
46  protected:
47  virtual SimpleUnit *find(const char *name,int len=-1);
48  virtual SimpleUnit *find(int units);
49  public:
50  int id;
51  double scaling;
52  PtrStack<char> names; //0,1,2 are short name, singular, plural
53  SimpleUnit *next;
54 
55  int defaultunits;
56 
57  SimpleUnit();
58  virtual ~SimpleUnit();
59 
60  virtual int UnitId(const char *name,int len=-1);
61  virtual int UnitInfo(const char *name, int *iid, double *scale, char **shortname, char **singular,char **plural);
62  virtual int UnitInfoIndex(int index, int *iid, double *scale, char **shortname, char **singular,char **plural);
63  virtual int UnitInfoId(int id, double *scale, char **shortname, char **singular,char **plural);
64  virtual double GetFactor(int fromunits, int tounits);
65  virtual int DefaultUnits();
66  virtual int DefaultUnits(const char *units);
67  virtual int DefaultUnits(int units);
68  virtual int PixelSize(double pixelsize, int intheseunits);
69  virtual int NumberOfUnits();
70  virtual int AddUnits(int nid, double scale, const char *shortname, const char *singular,const char *plural);
71  virtual double Convert(double value, const char *from, const char *to, int *error_ret);
72  virtual double Convert(double value, int from_id, int to_id, int *error_ret);
73 };
74 
75 typedef SimpleUnit UnitManager;
76 
77 //------------------------------------- CreateDefaultUnits() ----------------------------------------
80 
81 
82 } // namespace Laxkit
83 
84 #endif

Mon Feb 17 2014 11:52:57, Laxkit