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