private bool AttachToLine(LayoutFreeLine currentLine) { int index = mFreeLines.IndexOf(currentLine); if (index < 0) { return(false); } for (int i = index + 1; i < mFreeLines.Count; i++) { var curLine = mFreeLines[i]; var attachType = currentLine.GetAttachType(curLine); if (attachType != FreeLineAttachType.Error) { var newMergeLine = currentLine.NewAttachLine(curLine, attachType); mFreeLines.Remove(currentLine); mFreeLines.Remove(curLine); mFreeLines.Add(newMergeLine); return(true); } } return(false); }
public void Generate(MySortedList <ImageFile> images) { foreach (var imageFile in images) { if (imageFile.ResultSize.Width > mLimitMaxImageSize.Width || imageFile.ResultSize.Height > mLimitMaxImageSize.Height) { UsedImages.Add(imageFile); return; } } MySortedList <ImageFile> imagesCopy = new MySortedList <ImageFile>(); do { imagesCopy.Clear(); imagesCopy.AddRange(images); mResultImageSize.Width = 0; mResultImageSize.Height = 0; UsedImages.Clear(); //init fist free line var firstLine = new LayoutFreeLine(0, 0, mCurrentMaxImageSize.Width); mFreeLines.Add(firstLine); Run(imagesCopy); Logger.LogInfoLine("Try Layout: All:{0}?Used:{1} ({2},{3})", images.Count, UsedImages.Count, mCurrentMaxImageSize.Width, mCurrentMaxImageSize.Height); if (imagesCopy.Count == 0 && UsedImages.Count == images.Count) { break; } else { int nextSize = ccNextPOT(mCurrentMaxImageSize.Width + 1); if (nextSize > mLimitMaxImageSize.Width) { break; } mCurrentMaxImageSize = new Size(nextSize, nextSize); } mFreeLines.Clear(); } while (true); // CalculateResultImageSize(); //end images.Clear(); images.AddRange(imagesCopy); }
private void MergeLines(LayoutFreeLine newImageLine) { int index = mFreeLines.IndexOf(newImageLine); if (index < 0) { return; } for (int i = index + 1; i < mFreeLines.Count; i++) { var curLine = mFreeLines[i]; var mergeType = newImageLine.GetMergeType(curLine); if (mergeType != FreeLineMergeType.Error) { var newMergeLine = newImageLine.NewMergeLine(curLine, mergeType); mFreeLines.Remove(newImageLine); mFreeLines.Remove(curLine); mFreeLines.Add(newMergeLine); } } }