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