]> git.lyx.org Git - lyx.git/blob - src/Dimension.h
prepare Qt 5.6 builds
[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 namespace lyx {
16
17 /// Simple wrapper around three ints
18 class Dimension {
19 public:
20         /// constructor
21         Dimension() : wid(0), asc(0), des(0) {}
22         /// initialize data
23         Dimension(int w, int a, int d) : wid(w), asc(a), des(d) {}
24
25         Dimension & operator=(Dimension const & dim) {
26                 wid = dim.wid;
27                 asc = dim.asc;
28                 des = dim.des;
29                 return *this;
30         }
31         /// glue horizontally
32         void operator+=(Dimension const & dim);
33         /// set to empty box
34         void clear() { wid = asc = des = 0; }
35         /// get height
36         int height() const { return asc + des; }
37         /// get ascent
38         int ascent() const { return asc; }
39         /// get descent
40         int descent() const { return des; }
41         /// get width
42         int width() const { return wid; }
43
44         /// add space for a frame
45         //void addFrame(int frame) const;
46         /// add space for bottom part of a frame
47         //void addFrameBottom(int frame) const;
48
49 public:
50         /// these are intentionally public as things like
51         ///
52         ///   dim.asc += 20;
53         ///
54         /// are used all over the place and "hiding" those behind
55         ///
56         ///   dim.ascent(dim.ascent() + 20);
57         ///
58         /// makes the code neither faster nor clearer
59         /// width
60         int wid;
61         /// ascent
62         int asc;
63         /// descent
64         int des;
65 };
66
67 inline
68 bool operator==(Dimension const & a, Dimension const & b)
69 {
70         return a.wid == b.wid && a.asc == b.asc && a.des == b.des ;
71 }
72
73
74 inline
75 bool operator!=(Dimension const & a, Dimension const & b)
76 {
77         return a.wid != b.wid || a.asc != b.asc || a.des != b.des ;
78 }
79
80 class Point {
81 public:
82         Point()
83                 : x_(0), y_(0)
84         {}
85
86         Point(int x, int y);
87
88         int x_, y_;
89 };
90
91 } // namespace lyx
92
93 #endif