]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/molecule.hh
fd4833d71fe3b7c65d172f91bdd72ecde9007cfb
[lilypond.git] / lily / include / molecule.hh
1 /*
2   molecule.hh -- declare Molecule
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #ifndef MOLECULE_HH
9 #define MOLECULE_HH
10
11 #include <stdlib.h>             // size_t
12 #include "lily-proto.hh"
13 #include "box.hh"
14 #include "axes.hh"
15 #include "direction.hh"
16 #include "lily-guile.hh"
17 #include "smobs.hh"
18
19 /** a group of individually translated symbols. You can add molecules
20     to the top, to the right, etc.
21
22     It is implemented as a "tree" of scheme expressions, as in
23
24      Expr = combine Expr Expr
25               | translate Offset Expr
26               | SCHEME
27               ;
28
29     SCHEME is a Scheme expression that --when eval'd-- produces the
30     desired output.  
31
32
33     Because of the way that Molecule is implemented, it is the most
34     efficient to add "fresh" molecules to what you're going to build.
35     
36     Dimension behavior:
37
38     Empty molecules have empty dimensions.  If add_at_edge is used to
39     init the molecule, we assume that
40     DIMENSIONS = (Interval (0,0),Interval (0,0)
41 */
42 class Molecule
43 {
44   friend SCM ly_set_molecule_extent_x (SCM, SCM, SCM);
45   
46   Box dim_;
47   SCM expr_;
48   
49   DECLARE_SIMPLE_SMOBS (Molecule,);  
50 public:
51   Molecule (Box, SCM s);
52   Molecule ();
53
54
55   SCM smobbed_copy () const;
56   SCM get_expr () const;
57
58   /**
59      Set dimensions to empty, or to (Interval (0,0),Interval (0,0) */
60   void set_empty (bool);
61   void add_at_edge (Axis a, Direction d, const Molecule &m, Real padding);
62   void add_molecule (Molecule const &m);
63   void translate (Offset);
64   
65   /**
66      align D direction in axis A.
67
68      If D == CENTER, then move the dimension (A).center () to (0,0)
69
70      Else, move so dimension (A)[D] == 0.0
71      
72    */
73   void align_to (Axis a, Direction d);
74   void translate_axis (Real,Axis);
75   
76   Interval extent (Axis) const;
77   Box extent_box () const;
78   /**
79      codify THIS into a Scheme expression.
80    */
81   SCM create_scheme () const;
82   bool empty_b () const;
83
84
85   static SCM ly_get_molecule_extent (SCM mol, SCM axis);
86   static SCM ly_set_molecule_extent_x (SCM,SCM,SCM);
87   static SCM ly_molecule_combined_at_edge (SCM,SCM,SCM,SCM,SCM);
88 };
89
90
91 DECLARE_UNSMOB(Molecule,molecule);
92 SCM fontify_atom (Font_metric*, SCM atom);
93
94 Molecule create_molecule (SCM brew_molecule);
95
96
97
98 #endif