]> git.lyx.org Git - lyx.git/blob - src/mathed/math_xdata.h
move things around
[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                 /// first position of this row
37                 size_type begin; 
38                 /// last position of this row plus one
39                 size_type end; 
40                 /// y offset relative to yo
41                 int yo;
42                 /// dimensions of this row
43                 Dimension dim;
44                 /// glue between words
45                 int glue;
46         };
47
48         /// constructor
49         MathXArray();
50         /// rebuild cached metrics information
51         Dimension const & metrics(MathMetricsInfo & mi) const;
52         /// rebuild cached metrics information
53         void metricsExternal(MathMetricsInfo & mi, std::vector<Dimension> &) const;
54         /// redraw cell using cache metrics information
55         void draw(MathPainterInfo & pi, int x, int y) const;
56         /// redraw cell using external metrics information
57         void drawExternal(MathPainterInfo & pi, int x, int y,
58                 std::vector<MathXArray::Row> const &) const;
59         /// rebuild cached metrics information
60         Dimension const & metricsT(TextMetricsInfo const & mi) const;
61         /// redraw cell using cache metrics information
62         void drawT(TextPainter & pi, int x, int y) const;
63         /// mark cell for re-drawing
64         void touch() const;
65
66         /// access to cached x coordinate of last drawing
67         int xo() const { return xo_; }
68         /// access to cached y coordinate of last drawing
69         int yo() const { return yo_; }
70         /// access to cached x coordinate of mid point of last drawing
71         int xm() const { return xo_ + dim_.w / 2; }
72         /// access to cached y coordinate of mid point of last drawing
73         int ym() const { return yo_ + (dim_.d - dim_.a) / 2; }
74         /// returns x coordinate of given position in the array
75         int pos2x(size_type pos) const;
76         /// returns position of given x coordinate
77         int pos2x(size_type pos1, size_type pos2, int glue) const;
78         /// returns position of given x coordinate
79         size_type x2pos(int pos) const;
80         /// returns position of given x coordinate fstarting from a certain pos
81         size_type x2pos(size_type startpos, int targetx, int glue) const;
82         /// returns distance of this cell to the point given by x and y
83         // assumes valid position and size cache
84         int dist(int x, int y) const;
85
86         /// ascent of this cell above the baseline
87         int ascent() const { return dim_.a; }
88         /// descent of this cell below the baseline
89         int descent() const { return dim_.d; }
90         /// height of the cell
91         int height() const { return dim_.a + dim_.d; }
92         /// width of this cell
93         int width() const { return dim_.w; }
94         /// dimensions of cell
95         Dimension const & dim() const   { return dim_; }
96         /// dimensions of cell
97         void setDim(Dimension const & d) const { dim_ = d; }
98         /// bounding box of this cell
99         void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
100         /// find best position to do things
101         //void findPos(PosFinder &) const;
102         /// gives center coordinates
103         void center(int & x, int & y) const;
104         /// adjust (x,y) to point on boundary on a straight line from the center
105         void towards(int & x, int & y) const;
106
107         /// begin iterator of the underlying MathArray
108         const_iterator begin() const { return data_.begin(); }
109         /// end iterator of the underlying MathArray
110         const_iterator end() const { return data_.end(); }
111         /// access to data
112         MathArray const & data() const { return data_; }
113         /// access to data
114         MathArray & data() { return data_; }
115
116 private:
117         /// the underlying MathArray
118         MathArray data_;
119         /// cached dimensions of cell
120         mutable Dimension dim_;
121         /// cached x coordinate of last drawing
122         mutable int xo_;
123         /// cached y coordinate of last drawing
124         mutable int yo_;
125         /// cache size information of last drawing
126         mutable MathMetricsInfo size_;
127         /// cached cleaness of cell
128         mutable bool clean_;
129         /// cached draw status of cell
130         mutable bool drawn_;
131 };
132
133 /// output cell on a stream
134 std::ostream & operator<<(std::ostream & os, MathXArray const & ar);
135
136 #endif