]> git.lyx.org Git - lyx.git/blob - src/mathed/math_xdata.h
oh well
[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
11 #ifdef __GNUG__
12 #pragma interface
13 #endif
14
15 class Painter;
16 class TextPainter;
17
18
19 /** This class extends a MathArray by drawing routines and caches for
20  * metric information.
21  */
22 class MathXArray
23 {
24 public:
25         /// type for positions and sizes
26         typedef MathArray::size_type       size_type;
27         /// const iterator into the underlying MathArray
28         typedef MathArray::const_iterator  const_iterator;
29
30         /// constructor
31         MathXArray();
32         /// rebuild cached metrics information
33         void metrics(MathMetricsInfo const & st) const;
34         /// redraw cell using cache metrics information
35         void draw(Painter & pain, int x, int y) const;
36         /// rebuild cached metrics information
37         void metricsT(TextMetricsInfo const & st) const;
38         /// redraw cell using cache metrics information
39         void drawT(TextPainter & pain, int x, int y) const;
40         /// mark cell for re-drawing
41         void touch() const;
42
43         /// access to cached x coordinate of last drawing
44         int xo() const { return xo_; }
45         /// access to cached y coordinate of last drawing
46         int yo() const { return yo_; }
47         /// access to cached x coordinate of mid point of last drawing
48         int xm() const { return xo_ + width_ / 2; }
49         /// access to cached y coordinate of mid point of last drawing
50         int ym() const { return yo_ + (descent_ - ascent_) / 2; }
51         /// returns x coordinate of given position in the array
52         int pos2x(size_type pos) const;
53         /// returns position of given x coordinate
54         size_type x2pos(int pos) const;
55         /// returns distance of this cell to the point given by x and y
56         // assumes valid position and size cache
57         int dist(int x, int y) const;
58
59         /// ascent of this cell above the baseline
60         int ascent() const { return ascent_; }
61         /// descent of this cell below the baseline
62         int descent() const { return descent_; }
63         /// height of the cell
64         int height() const { return ascent_ + descent_; }
65         /// width of this cell
66         int width() const { return width_; }
67         /// bounding box of this cell
68         void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
69         /// find best position to do things
70         //void findPos(PosFinder &) const;
71         /// gives center coordinates
72         void center(int & x, int & y) const;
73         /// adjust (x,y) to point on boundary on a straight line from the center
74         void towards(int & x, int & y) const;
75
76         /// begin iterator of the underlying MathArray
77         const_iterator begin() const { return data_.begin(); }
78         /// end iterator of the underlying MathArray
79         const_iterator end() const { return data_.end(); }
80
81 public:
82         /// the underlying MathArray
83         MathArray data_;
84         /// cached width of cell
85         mutable int width_;
86         /// cached ascent of cell
87         mutable int ascent_;
88         /// cached descent of cell
89         mutable int descent_;
90         /// cached x coordinate of last drawing
91         mutable int xo_;
92         /// cached y coordinate of last drawing
93         mutable int yo_;
94         /// cache size information of last drawing
95         mutable MathMetricsInfo size_;
96         /// cached cleaness of cell
97         mutable bool clean_;
98         /// cached draw status of cell
99         mutable bool drawn_;
100 };
101
102 /// output cell on a stream
103 std::ostream & operator<<(std::ostream & os, MathXArray const & ar);
104
105 #endif