]> git.lyx.org Git - lyx.git/blob - src/Dimension.h
Fix text direction issue for InsetInfo in RTL context
[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         /// check if box is empty
36         bool empty() const { return wid == 0 && asc == 0 && wid == 0; }
37         /// get height
38         int height() const { return asc + des; }
39         /// get ascent
40         int ascent() const { return asc; }
41         /// get descent
42         int descent() const { return des; }
43         /// get width
44         int width() const { return wid; }
45
46         /// add space for a frame
47         //void addFrame(int frame) const;
48         /// add space for bottom part of a frame
49         //void addFrameBottom(int frame) const;
50
51 public:
52         /// these are intentionally public as things like
53         ///
54         ///   dim.asc += 20;
55         ///
56         /// are used all over the place and "hiding" those behind
57         ///
58         ///   dim.ascent(dim.ascent() + 20);
59         ///
60         /// makes the code neither faster nor clearer
61         /// width
62         int wid;
63         /// ascent
64         int asc;
65         /// descent
66         int des;
67 };
68
69 inline
70 bool operator==(Dimension const & a, Dimension const & b)
71 {
72         return a.wid == b.wid && a.asc == b.asc && a.des == b.des ;
73 }
74
75
76 inline
77 bool operator!=(Dimension const & a, Dimension const & b)
78 {
79         return a.wid != b.wid || a.asc != b.asc || a.des != b.des ;
80 }
81
82 class Point {
83 public:
84         Point()
85                 : x_(0), y_(0)
86         {}
87
88         Point(int x, int y);
89
90         int x_, y_;
91 };
92
93 } // namespace lyx
94
95 #endif