]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-closure.cc
* lily/self-aligment-interface.cc (set_align_self): new function
[lilypond.git] / lily / grob-closure.cc
1 #include "grob.hh"
2 #include "simple-closure.hh"
3
4 /*
5   UGH : todo -> to different file.
6  */
7
8 SCM
9 axis_offset_symbol (Axis a)
10 {
11   return a == X_AXIS
12     ? ly_symbol2scm ("X-offset")
13     : ly_symbol2scm ("Y-offset");
14 }
15
16 SCM
17 axis_parent_positioning (Axis a)
18 {
19   return (a == X_AXIS)
20     ? Grob::x_parent_positioning_proc
21     : Grob::y_parent_positioning_proc;
22 }
23
24
25
26 /*
27   Replace
28
29   (orig-proc GROB)
30
31   by
32
33   (+ (PROC GROB) (orig-proc GROB))
34   
35 */
36 void
37 add_offset_callback (Grob *g, SCM proc, Axis a)
38 {
39   SCM data = g->get_property_data (axis_offset_symbol (a));
40   if (ly_is_procedure (data))
41     data = ly_make_simple_closure (scm_list_1  (data));
42   else if (is_simple_closure (data))
43     data = simple_closure_expression (data);
44   else if (!scm_is_number (data))
45     g->internal_set_property (axis_offset_symbol (a),
46                               proc);
47   else
48     {
49       SCM plus = ly_lily_module_constant ("+");
50       SCM expr = scm_list_3 (plus,
51                              ly_make_simple_closure (scm_list_1 (proc)),
52                              data);
53       g->internal_set_property (axis_offset_symbol (a),
54                                 ly_make_simple_closure (expr));
55     }
56 }
57
58
59 /*
60   replace
61
62   (orig-proc GROB)
63
64   by
65
66   (PROC GROB (orig-proc GROB)) 
67
68 */
69 void
70 chain_offset_callback (Grob *g, SCM proc, Axis a)
71 {
72   SCM data = g->get_property_data (axis_offset_symbol (a));
73
74   if (ly_is_procedure (data))
75     data = ly_make_simple_closure (scm_list_1  (data));
76   else if (is_simple_closure (data))
77     data = simple_closure_expression (data);
78   else if (!scm_is_number (data))
79     data = scm_from_int (0);
80   
81   SCM expr = scm_list_2 (proc, data);
82   g->internal_set_property (axis_offset_symbol (a),
83                             
84                             // twice: one as a wrapper for grob property routines,
85                             // once for the actual delayed binding. 
86                             ly_make_simple_closure (ly_make_simple_closure (expr)));
87 }