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