Changeset 2009


Ignore:
Timestamp:
10/01/08 21:35:28 (11 years ago)
Author:
julien-quint
Message:

Wrapping is essentially done; debug colors are left in for the moment and there are some kinks left to iron out.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Obi/Obi/ProjectView/Strip.cs

    r2008 r2009  
    225225            else 
    226226            { 
    227                 if (mBlockLayout.Controls.Count == 0) AddCursorAtBlockLayoutIndex(0); 
     227                if (mBlockLayout.Controls.Count == 0) 
     228                { 
     229                    StripCursor cursor = AddCursorAtBlockLayoutIndex(0); 
     230                } 
    228231                Block block = node is PhraseNode ? new AudioBlock((PhraseNode)node, this) : new Block(node, this); 
    229232                mBlockLayout.Controls.Add(block); 
     
    458461 
    459462        // Add a cursor at the given index (in the context of the block layout.) 
    460         private void AddCursorAtBlockLayoutIndex(int index) 
     463        // Return the new cursor. 
     464        private StripCursor AddCursorAtBlockLayoutIndex(int index) 
    461465        { 
    462466            StripCursor cursor = new StripCursor(this.Node); 
     
    466470            mBlockLayout.Controls.Add(cursor); 
    467471            mBlockLayout.Controls.SetChildIndex(cursor, index); 
     472            return cursor; 
    468473        } 
    469474 
     
    480485        } 
    481486 
     487        // Get the minimum width necessary for the block layout to contain all blocks. 
     488        private int BlockLayoutMinimumWidth 
     489        { 
     490            get 
     491            { 
     492                int w_min = 0; 
     493                int count = mBlockLayout.Controls.Count; 
     494                if (count > 2) 
     495                { 
     496                    // there is at least one block; the first block must fit the first two cursors 
     497                    w_min = mBlockLayout.Controls[0].Width + mBlockLayout.Controls[0].Margin.Horizontal + 
     498                        mBlockLayout.Controls[1].Width + mBlockLayout.Controls[1].Margin.Horizontal + 
     499                        mBlockLayout.Controls[2].Width + mBlockLayout.Controls[2].Margin.Horizontal; 
     500                    // following blocks are counted with the following cursor 
     501                    for (int i = 3; i < mBlockLayout.Controls.Count - 1; i += 2) 
     502                    { 
     503                        int w = mBlockLayout.Controls[i].Width + mBlockLayout.Controls[i].Margin.Horizontal + 
     504                            mBlockLayout.Controls[i + 1].Width + mBlockLayout.Controls[i + 1].Margin.Horizontal; 
     505                        if (w > w_min) w_min = w; 
     506                    } 
     507                } 
     508                return w_min; 
     509            } 
     510        } 
     511 
     512        // Size of the borders 
    482513        private int BorderHeight { get { return Bounds.Height - ClientSize.Height; } } 
    483514        private int BorderWidth { get { return Bounds.Width - ClientSize.Width; } } 
     515 
     516        // Get the height of the strip for the current block layout size/position. 
     517        // Includes the border size. 
     518        private int HeightForContents 
     519        { 
     520            get 
     521            { 
     522                return mBlockLayout.Location.Y + mBlockLayout.Height + mBlockLayout.Margin.Bottom + BorderHeight; 
     523            } 
     524        } 
    484525 
    485526        // Blocks are added, removed, or their width has changed after the audio scale changed. 
     
    498539                int width_blocks = BlockLayoutFullWidth; 
    499540                mBlockLayout.Width = width_blocks; 
    500                 int width_label = mLabel.Width + mLabel.Margin.Horizontal; 
    501                 int width_layout = mBlockLayout.Width + mBlockLayout.Margin.Horizontal; 
    502                 Width = Math.Max(width_label, width_layout) + BorderWidth; 
     541                Width = WidthForContents; 
    503542            } 
    504543        } 
     
    508547        private void Resize_Label() 
    509548        { 
    510             int width_label = mLabel.Width + mLabel.Margin.Horizontal; 
    511             int width_layout = mBlockLayout.Width + mBlockLayout.Margin.Horizontal; 
    512549            // move the block layout up or down if the label height has changed 
    513550            // and resize the strip accordingly 
    514551            mBlockLayout.Location = new Point(mBlockLayout.Location.X, 
    515552                mLabel.Location.Y + mLabel.Height + mLabel.Margin.Bottom + mBlockLayout.Margin.Top); 
    516             Size = new Size(Math.Max(width_label, width_layout) + BorderWidth, 
     553            Size = new Size(WidthForContents, 
    517554                mBlockLayout.Location.Y + mBlockLayout.Height + mBlockLayout.Margin.Bottom + BorderHeight); 
    518555        } 
     
    533570                mBlockLayout.AutoSizeMode = AutoSizeMode.GrowAndShrink; 
    534571                mBlockLayout.WrapContents = true; 
    535                 int width_max = mContentView.ClientRectangle.Width - Margin.Horizontal - BorderWidth - 
     572                // The width of the block layout should fit the available space, unless it's narrower. 
     573                // This may be overridden however by the minimum width to fit the widest waveform. 
     574                int width_fit = mContentView.ClientRectangle.Width - Margin.Horizontal - BorderWidth - 
    536575                    mBlockLayout.Margin.Horizontal; 
    537                 mBlockLayout.MaximumSize = new Size(Math.Min(BlockLayoutFullWidth, width_max), 0); 
    538                 Size = new Size(width_max, mBlockLayout.Location.Y + mBlockLayout.Height + mBlockLayout.Margin.Bottom + 
    539                     BorderHeight); 
     576                mBlockLayout.MaximumSize = 
     577                    new Size(Math.Max(BlockLayoutMinimumWidth, Math.Min(BlockLayoutFullWidth, width_fit)), 0); 
     578                Size = new Size(WidthForContents, HeightForContents); 
    540579            } 
    541580            else 
     
    543582                mBlockLayout.AutoSize = false; 
    544583                mBlockLayout.WrapContents = false; 
    545  
     584                mBlockLayout.MaximumSize = new Size(0, 0); 
     585                mBlockLayout.Height = mBlockHeight; 
     586                Height = HeightForContents; 
    546587                Resize_Blocks(); 
    547588            } 
     
    610651        } 
    611652 
     653        // Width of the strip to contain the label and the block layout, including borders. 
     654        private int WidthForContents 
     655        { 
     656            get 
     657            { 
     658                int width_label = mLabel.Width + mLabel.Margin.Horizontal; 
     659                int width_layout = mBlockLayout.Width + mBlockLayout.Margin.Horizontal; 
     660                return Math.Max(width_label, width_layout) + BorderWidth; 
     661            } 
     662        } 
     663 
    612664 
    613665        // Resize when a block size has changed. 
Note: See TracChangeset for help on using the changeset viewer.