X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fseparation-item.cc;h=b990ad61fbcf147aa81c9126b15ef98ee43ac2e8;hb=6e227b10eed0ebe522ca7512eb7d2cc1d9561e64;hp=8b59a919678891a412152655fb83b51ecc3b2bf4;hpb=10809c81d2cf7066eb9838e732900229a900824b;p=lilypond.git diff --git a/lily/separation-item.cc b/lily/separation-item.cc index 8b59a91967..b990ad61fb 100644 --- a/lily/separation-item.cc +++ b/lily/separation-item.cc @@ -1,28 +1,27 @@ -/* - separation-item.cc -- implement Separation_item - +/* + separation-item.cc -- implement Separation_item + source file of the GNU LilyPond music typesetter - - (c) 1998--2003 Han-Wen Nienhuys - - */ + + (c) 1998--2005 Han-Wen Nienhuys +*/ #include "separation-item.hh" + #include "paper-column.hh" #include "warn.hh" -#include "group-interface.hh" +#include "pointer-group-interface.hh" #include "accidental-placement.hh" void -Separation_item::add_item (Grob*s,Item* i) +Separation_item::add_item (Grob *s, Item *i) { assert (i); - Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"),i); - s->add_dependency (i); + Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"), i); } void -Separation_item::add_conditional_item (Grob* me , Grob *e) +Separation_item::add_conditional_item (Grob *me, Grob *e) { Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e); } @@ -30,31 +29,27 @@ Separation_item::add_conditional_item (Grob* me , Grob *e) /* Return the width of ME given that we are considering the object on the LEFT. - */ +*/ Interval -Separation_item::conditional_width (Grob * me, Grob * left) +Separation_item::conditional_width (Grob *me, Grob *left) { Interval w = width (me); - - Item *item = dynamic_cast (me); - Paper_column * pc = item->get_column (); - - - for (SCM s = me->get_grob_property ("conditional-elements"); gh_pair_p (s); s = ly_cdr (s)) + + Item *item = dynamic_cast (me); + Paper_column *pc = item->get_column (); + + extract_grob_set (me, "conditional-elements", elts); + for (int i = 0; i < elts.size (); i++) { - SCM elt = ly_car (s); - if (!unsmob_grob (elt)) - continue; - - Item *il = unsmob_item (elt); + Item *il = dynamic_cast (elts[i]); if (pc != il->get_column ()) { /* this shouldn't happen, but let's continue anyway. */ - programming_error (_ ("Separation_item: I've been drinking too much")); - continue; /*UGH UGH*/ + programming_error ("Separation_item: I've been drinking too much"); + continue; /*UGH UGH*/ } - if (to_boolean (il->get_grob_property ("no-spacing-rods"))) + if (to_boolean (il->get_property ("no-spacing-rods"))) { continue; } @@ -65,44 +60,37 @@ Separation_item::conditional_width (Grob * me, Grob * left) } } - SCM pad = me->get_grob_property ("padding"); + SCM pad = me->get_property ("padding"); - if (gh_number_p (pad)) - { - w[RIGHT] += gh_scm2double (pad)/2; - w[LEFT] -= gh_scm2double (pad)/2; - } + w.widen (robust_scm2double (pad, 0.0)); return w; } Interval Separation_item::width (Grob *me) { - SCM sw = me->get_grob_property ("X-extent"); + SCM sw = me->get_property ("X-extent"); if (is_number_pair (sw)) { return ly_scm2interval (sw); } - Item *item = dynamic_cast (me); - Paper_column * pc = item->get_column (); + Item *item = dynamic_cast (me); + Paper_column *pc = item->get_column (); Interval w; - - for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s); s = ly_cdr (s)) - { - SCM elt = ly_car (s); - if (!unsmob_grob (elt)) - continue; - Item *il = unsmob_item (elt); + extract_grob_set (me, "elements", elts); + for (int i = 0; i < elts.size (); i++) + { + Item *il = dynamic_cast (elts[i]); if (pc != il->get_column ()) { /* this shouldn't happen, but let's continue anyway. */ - programming_error (_ ("Separation_item: I've been drinking too much")); - continue; /*UGH UGH*/ + programming_error ("Separation_item: I've been drinking too much"); + continue; /*UGH UGH*/ } - if (to_boolean (il->get_grob_property ("no-spacing-rods"))) + if (to_boolean (il->get_property ("no-spacing-rods"))) { continue; } @@ -114,69 +102,60 @@ Separation_item::width (Grob *me) } } - SCM pad = me->get_grob_property ("padding"); + SCM pad = me->get_property ("padding"); - if (gh_number_p (pad)) - { - w[RIGHT] += gh_scm2double (pad)/2; - w[LEFT] -= gh_scm2double (pad)/2; - } + w.widen (robust_scm2double (pad, 0.0)); + + me->set_property ("X-extent", ly_interval2scm (w)); - me->set_grob_property ("X-extent", ly_interval2scm (w)); - return w; } Interval -Separation_item::relative_width (Grob * me, Grob * common) +Separation_item::relative_width (Grob *me, Grob *common) { Interval iv = width (me); - return dynamic_cast(me)->get_column ()->relative_coordinate (common, X_AXIS) + iv ; + return dynamic_cast (me)->get_column ()->relative_coordinate (common, X_AXIS) + iv; } - /* Try to find the break-aligned symbol in SEPARATION_ITEM that is sticking out at direction D. The x size is put in LAST_EXT */ -Grob* -Separation_item::extremal_break_aligned_grob (Grob *separation_item, Direction d, - Interval * last_ext) +Grob * +Separation_item::extremal_break_aligned_grob (Grob *me, + Direction d, + Interval *last_ext) { - Grob *col = dynamic_cast (separation_item)->get_column (); + Grob *col = dynamic_cast (me)->get_column (); last_ext->set_empty (); Grob *last_grob = 0; - for (SCM s = separation_item->get_grob_property ("elements"); - gh_pair_p (s); s = gh_cdr (s)) + + extract_grob_set (me, "elements", elts); + for (int i = elts.size (); i--; ) { - Grob * break_item = unsmob_grob (gh_car (s)); - - if (!gh_symbol_p (break_item->get_grob_property ("break-align-symbol"))) + Grob *break_item = elts[i]; + if (!scm_is_symbol (break_item->get_property ("break-align-symbol"))) continue; Interval ext = break_item->extent (col, X_AXIS); if (ext.is_empty ()) continue; + if (!last_grob - || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0) ) + || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0)) { *last_ext = ext; - last_grob = break_item; + last_grob = break_item; } } - return last_grob; + return last_grob; } - - - - -ADD_INTERFACE (Separation_item,"separation-item-interface", - "Item that computes widths to generate spacing rods.\n" -"\n" -"Calculate dimensions for the Separating_group_spanner; this has to be " -"an item to get dependencies correct. " -, "padding X-extent conditional-elements elements"); +ADD_INTERFACE (Separation_item, "separation-item-interface", + "Item that computes widths to generate spacing rods. " + "This is done in concert with @ref{separation-spanner-interface}.", + "padding X-extent conditional-elements elements");