Logo Search packages:      
Sourcecode: patchage version File versions  Download package

void PatchBay::Module::resize (  ) 

Resize the module to fit its contents best.

Definition at line 218 of file Module.cpp.

References PatchBay::Port::height(), PatchBay::Port::is_input(), PatchBay::Port::is_output(), and PatchBay::Port::width().

{
      double widest_in = 0.0;
      double widest_out = 0.0;
      
      Port* p = NULL;
      
      // Find widest in/out ports
      for (PortList::iterator i = m_ports.begin(); i != m_ports.end(); ++i) {
            p = (*i);
            if (p->is_input() && p->width() > widest_in)
                  widest_in = p->width();
            else if (p->is_output() && p->width() > widest_out)
                  widest_out = p->width();
      }
      
      // Make sure module is wide enough for ports
      if (widest_in > widest_out)
            width(widest_in + 5.0);
      else
            width(widest_out + 5.0);
      
      // Make sure module is wide enough for title
      if (m_canvas_title.property_text_width() + 6.0 > m_width)
            width(m_canvas_title.property_text_width() + 6.0);

      // Set height to contain ports and title
      double height_base = m_canvas_title.property_text_height() + 2;
      double h = height_base;
      if (m_ports.size() > 0)
            h += m_ports.size() * ((*m_ports.begin())->height()+2.0);
      height(h);
      
      // Move ports to appropriate locations
      
      double y;
      int i = 0;
      for (PortList::iterator pi = m_ports.begin(); pi != m_ports.end(); ++pi, ++i) {
            Port* p = (*pi);

            y = height_base + (i * (p->height() + 2.0));
            if (p->is_input()) {
                  p->width(widest_in);
                  p->property_x() = 0.0;
                  p->property_y() = y;
            } else {
                  p->width(widest_out);
                  p->property_x() = m_width - p->width();
                  p->property_y() = y;
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index