-/*
- staff-side.cc -- implement Staff_side
-
+/*
+ g-staff-side.cc -- implement Staff_side_element
+
source file of the GNU LilyPond music typesetter
+
+ (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
- (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-#include "interval.hh"
-#include "paper-def.hh"
-#include "dimension.hh"
#include "staff-side.hh"
-#include "staff-sym.hh"
+#include "staff-symbol.hh"
#include "debug.hh"
+#include "warn.hh"
+#include "dimensions.hh"
+#include "dimension-cache.hh"
-
-Staff_side::Staff_side()
+Staff_side_element::Staff_side_element ()
{
- coordinate_offset_f_=0;
- sym_int_ = Interval (0,0);
- padding_f_ = 0.0;
dir_ = CENTER;
+ to_position_l_ = 0;
+ set_elt_property (transparent_scm_sym, SCM_BOOL_T);
axis_ = Y_AXIS;
}
+void
+Staff_side_element::do_pre_processing ()
+{
+ if (!dir_)
+ dir_ = get_default_direction ();
-Interval
-Staff_side::support_extent() const
+ if (axis_ == X_AXIS)
+ position_self ();
+}
+
+Direction
+Staff_side_element::get_default_direction () const
{
- Interval y_int;
- for (int i=0; i < support_l_arr_.size(); i++)
- {
- Graphical_axis_group *common =
- common_group (support_l_arr_[i], axis_);
-
- Real y = support_l_arr_[i]->relative_coordinate (common, axis_)
- -relative_coordinate (common,axis_);
+ return DOWN;
+}
- y_int.unite (y + support_l_arr_[i]->extent(axis_));
- }
- if (y_int.empty_b())
- {
- y_int = Interval (0,0);
- }
- return Interval(y_int[LEFT] - padding_f_, y_int[RIGHT] + padding_f_);
+void
+Staff_side_element::set_victim (Score_element *e)
+{
+ add_dependency (e);
+ to_position_l_ = e;
+ to_position_l_->set_parent (this, axis_);
}
void
-Staff_side::add_support (Score_element*i)
+Staff_side_element::add_support (Score_element*e)
{
- support_l_arr_.push (i);
- add_dependency (i);
+ add_dependency (e);
+ support_l_arr_.push (e);
}
-Real
-Staff_side::get_position_f () const
+
+void
+Staff_side_element::do_substitute_element_pointer (Score_element*o, Score_element*n)
{
- if (!dir_)
+ Staff_symbol_referencer::do_substitute_element_pointer (o,n);
+ if (o == to_position_l_)
+ to_position_l_ = n;
+ else
+ support_l_arr_.unordered_substitute (o,n);
+}
+
+void
+Staff_side_element::position_self ()
+{
+ if (to_position_l_ &&
+ to_position_l_->get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
+ return;
+
+ Axis other = Axis ((axis_ + 1) % NO_AXES);
+ if (parent_l (axis_)->empty_b (axis_)
+ &&parent_l (axis_)->empty_b (other)) // guh
{
- warning (_ ("Staff_side::get_position_f(): "
- "somebody forgot to set my direction, returning -20"));
- return -20;
+ warning (_("No support; erasing script"));
+ to_position_l_->set_empty (X_AXIS,Y_AXIS);
+ to_position_l_->set_elt_property (transparent_scm_sym, SCM_BOOL_T);
+ set_empty (X_AXIS, Y_AXIS);
+ return ;
}
+
+ Interval dim;
+ Graphical_element *common = 0;
+ if (support_l_arr_.size ())
+ {
+ common = common_refpoint (typecast_array (support_l_arr_, (Graphical_element*)0),
+ axis_);
+ for (int i=0; i < support_l_arr_.size (); i++)
+ {
+ Score_element * e = support_l_arr_ [i];
+ Real coord = e->relative_coordinate (common, axis_);
- Real y = 0;
- Real inter_f = paper()-> internote_f ();
+ dim.unite (coord + e->extent (axis_));
+ }
+ }
+ else
+ common = parent_l (axis_);
- Interval v = support_extent();
+ if (dim.empty_b ())
+ {
+ dim = Interval(0,0);
+ }
+
+
+ Interval sym_dim
+ = to_position_l_
+ ? to_position_l_->extent (axis_)
+ : Interval(0,0);
- // ugh, dim[y] = PT over here
- y = v[dir_] + 1 * dir_ * inter_f;
+ Real off = relative_coordinate (common, axis_);
- int coordinate_offset_f_i = (int)rint (y / inter_f);
- // ugh: 5 -> staff_lines
- if (axis_ == Y_AXIS && abs (coordinate_offset_f_i) < 5)
+ SCM pad = remove_elt_property (padding_scm_sym);
+ if (pad != SCM_BOOL_F)
{
- if (!(abs (coordinate_offset_f_i) % 2))
- y += (Real)dir_ * inter_f;
+ off += gh_scm2double (SCM_CDR(pad)) * dir_;
}
-// else
-// y = v[dir_] + 1 * dir_ * inter_f;
-
- return y;
+ Real total_off = dim[dir_] + off;
+
+ /*
+ no_staff_support_scm_sym is ugh bugfix to get staccato dots right.
+ */
+ if (to_position_l_ && to_position_l_->get_elt_property (no_staff_support_scm_sym) == SCM_BOOL_F)
+ total_off += - sym_dim[-dir_];
+
+ dim_cache_[axis_]->set_offset (total_off);
+ if (fabs (total_off) > 100 CM)
+ programming_error ("Huh ? Improbable staff side dim.");
}
-Interval
-Staff_side::symbol_height() const
+void
+Staff_side_element::do_post_processing ()
{
- return Interval (0,0);
+ if (axis_ == Y_AXIS)
+ position_self ();
}
-Interval
-Staff_side::symbol_width () const
+
+void
+Staff_side_element::do_add_processing ()
{
- return Interval (0,0);
+ if (get_elt_property (no_staff_support_scm_sym) == SCM_BOOL_F
+ && axis_ == Y_AXIS && staff_symbol_l ())
+ {
+ add_support (staff_symbol_l ());
+ }
}
-void
-Staff_side::do_pre_processing ()
+Interval
+Staff_side_element::do_height () const
{
- if (axis_== X_AXIS)
- do_side_processing ();
+ Interval i;
+ if (to_position_l_)
+ return to_position_l_->extent (Y_AXIS);
+ return i;
}
void
-Staff_side::do_side_processing ()
+Staff_side_element::do_print () const
{
- sym_int_ = symbol_extent();
- coordinate_offset_f_ = get_position_f();
- if (dir_)
- coordinate_offset_f_ += - sym_int_[-dir_];
+#ifndef NPRINT
+ if (to_position_l_)
+ DOUT << "positioning " << to_position_l_->name();
+ DOUT << "axis == " << axis_name_str (axis_)
+ << ", dir == " << to_str ((int)dir_ );
+#endif
}
-/*
- ugh should use do_width (), do_height (), get_extent ()
- */
+
Interval
-Staff_side::symbol_extent () const
+Staff_side_item::do_width () const
{
- if (axis_ == Y_AXIS)
- return symbol_height ();
- else
- return symbol_width ();
+ Interval i;
+ if (to_position_l_)
+ return to_position_l_->extent (X_AXIS);
+ return i;
}
-
void
-Staff_side::do_post_processing()
+Staff_side_item::do_print () const
{
- if (axis_ == Y_AXIS)
- do_side_processing ();
+ Staff_side_element::do_print ();
}
void
-Staff_side::do_substitute_dependency (Score_element*o, Score_element*n)
+Staff_side_spanner::do_print () const
{
- support_l_arr_.unordered_substitute (o,n);
+ Staff_side_element::do_print ();
}
-
-
-IMPLEMENT_IS_TYPE_B1(Staff_side, Score_element);