]> git.lyx.org Git - lyx.git/blob - src/dimension.h
bf42106de0bb986e8fc5449b4a7b1fb7f5777d9b
[lyx.git] / src / dimension.h
1 // -*- C++ -*-
2 /**
3  * \file dimension.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef DIMENSION_H
13 #define DIMENSION_H
14
15
16 namespace lyx {
17
18 class LyXFont;
19
20 /// Simple wrapper around three ints
21 class Dimension {
22 public:
23         /// constructor
24         Dimension() : wid(0), asc(0), des(0) {}
25         /// initialize data
26         Dimension(int w, int a, int d) : wid(w), asc(a), des(d) {}
27
28         Dimension & operator=(Dimension const & dim) {
29                 wid = dim.wid;
30                 asc = dim.asc;
31                 des = dim.des;
32                 return *this;
33         }
34         /// glue horizontally
35         void operator+=(Dimension const & dim);
36         /// set to empty box
37         void clear() { wid = asc = des = 0; }
38         /// set to empty box suitble for given font
39         void clear(LyXFont const & font);
40         /// get height
41         int height() const { return asc + des; }
42         /// get ascent
43         int ascent() const { return asc; }
44         /// get descent
45         int descent() const { return des; }
46         /// get width
47         int width() const { return wid; }
48
49         /// add space for a frame
50         //void addFrame(int frame) const;
51         /// add space for bottom part of a frame
52         //void addFrameBottom(int frame) const;
53
54 public:
55         /// these are intentionally public as things like
56         ///
57         ///   dim.asc += 20;
58         ///
59         /// are used all over the place and "hiding" those behind
60         ///
61         ///   dim.ascent(dim.ascent() + 20);
62         ///
63         /// makes the code neither faster nor clearer
64         /// width
65         int wid;
66         /// ascent
67         int asc;
68         /// descent
69         int des;
70 };
71
72 inline
73 bool operator==(Dimension const & a, Dimension const & b)
74 {
75         return a.wid == b.wid && a.asc == b.asc && a.des == b.des ;
76 }
77
78
79 inline
80 bool operator!=(Dimension const & a, Dimension const & b)
81 {
82         return a.wid != b.wid || a.asc != b.asc || a.des != b.des ;
83 }
84
85
86 } // namespace lyx
87
88 #endif