]> git.lyx.org Git - lyx.git/blob - src/mathed/math_xdata.h
some more changes
[lyx.git] / src / mathed / math_xdata.h
1 // -*- C++ -*-
2
3 #ifndef MATHEDXARRAY_H
4 #define MATHEDXARRAY_H
5
6 #include <iosfwd>
7
8 #include "math_data.h"
9 #include "math_metricsinfo.h"
10 #include "dimension.h"
11
12 #ifdef __GNUG__
13 #pragma interface
14 #endif
15
16 class MathPainterInfo;
17 class TextPainter;
18
19
20 /** This class extends a MathArray by drawing routines and caches for
21  * metric information.
22  */
23 class MathXArray
24 {
25 public:
26         /// type for positions and sizes
27         typedef MathArray::size_type       size_type;
28         /// const iterator into the underlying MathArray
29         typedef MathArray::const_iterator  const_iterator;
30
31         // helper structure for external metrics computations as done
32         // in parboxes
33         struct Row {
34                 /// constructor
35                 Row() {}
36                 /// last position of this row plus one
37                 size_type end; 
38                 /// y offset relative to yo
39                 int yo;
40                 /// dimensions of this row
41                 Dimension dim;
42                 /// glue between words
43                 int glue;
44         };
45
46         /// constructor
47         MathXArray();
48         /// rebuild cached metrics information
49         Dimension const & metrics(MathMetricsInfo & mi) const;
50         /// rebuild cached metrics information
51         void metricsExternal(MathMetricsInfo & mi,
52                 std::vector<MathXArray::Row> &) const;
53         /// redraw cell using cache metrics information
54         void draw(MathPainterInfo & pi, int x, int y) const;
55         /// redraw cell using external metrics information
56         void drawExternal(MathPainterInfo & pi, int x, int y,
57                 std::vector<MathXArray::Row> const &) const;
58         /// rebuild cached metrics information
59         Dimension const & metricsT(TextMetricsInfo const & mi) const;
60         /// redraw cell using cache metrics information
61         void drawT(TextPainter & pi, int x, int y) const;
62         /// mark cell for re-drawing
63         void touch() const;
64
65         /// access to cached x coordinate of last drawing
66         int xo() const { return xo_; }
67         /// access to cached y coordinate of last drawing
68         int yo() const { return yo_; }
69         /// access to cached x coordinate of mid point of last drawing
70         int xm() const { return xo_ + dim_.w / 2; }
71         /// access to cached y coordinate of mid point of last drawing
72         int ym() const { return yo_ + (dim_.d - dim_.a) / 2; }
73         /// returns x coordinate of given position in the array
74         int pos2x(size_type pos) const;
75         /// returns position of given x coordinate
76         size_type x2pos(int pos) const;
77         /// returns distance of this cell to the point given by x and y
78         // assumes valid position and size cache
79         int dist(int x, int y) const;
80
81         /// ascent of this cell above the baseline
82         int ascent() const { return dim_.a; }
83         /// descent of this cell below the baseline
84         int descent() const { return dim_.d; }
85         /// height of the cell
86         int height() const { return dim_.a + dim_.d; }
87         /// width of this cell
88         int width() const { return dim_.w; }
89         /// dimensions of cell
90         Dimension const & dim() const   { return dim_; }
91         /// bounding box of this cell
92         void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
93         /// find best position to do things
94         //void findPos(PosFinder &) const;
95         /// gives center coordinates
96         void center(int & x, int & y) const;
97         /// adjust (x,y) to point on boundary on a straight line from the center
98         void towards(int & x, int & y) const;
99
100         /// begin iterator of the underlying MathArray
101         const_iterator begin() const { return data_.begin(); }
102         /// end iterator of the underlying MathArray
103         const_iterator end() const { return data_.end(); }
104         /// access to data
105         MathArray const & data() const { return data_; }
106         /// access to data
107         MathArray & data() { return data_; }
108
109 private:
110         /// the underlying MathArray
111         MathArray data_;
112         /// cached dimensions of cell
113         mutable Dimension dim_;
114         /// cached x coordinate of last drawing
115         mutable int xo_;
116         /// cached y coordinate of last drawing
117         mutable int yo_;
118         /// cache size information of last drawing
119         mutable MathMetricsInfo size_;
120         /// cached cleaness of cell
121         mutable bool clean_;
122         /// cached draw status of cell
123         mutable bool drawn_;
124 };
125
126 /// output cell on a stream
127 std::ostream & operator<<(std::ostream & os, MathXArray const & ar);
128
129 #endif