protected void ResizeSliders() { if (this._sliders.Count == 0) { return; } if (this.Horizontal) { //TODO: change each textbox size and move both labels and textboxes //get space left for textboxes: int totalLabelWidth = 0; //Graphics g = Graphics.FromImage for (int i = 0; i < this._sliders.Count; i++) { totalLabelWidth += this._labels[i].Width; } totalLabelWidth += this._spacing.X * (this._labels.Count - 1); int sliderWidth = (this.Width - totalLabelWidth) / this._sliders.Count; EPoint pnt = new EPoint(0, 0); for (int i = 0; i < this._sliders.Count; i++) { this._labels[i].Location = pnt.ToPoint(); pnt.X = this._labels[i].Right; this._sliders[i].Location = pnt.ToPoint(); this._sliders[i].Width = sliderWidth; pnt.X = this._sliders[i].Right; pnt += this._spacing; } } else { for (int i = 0; i < this._sliders.Count; i++) { this._sliders[i].Width = this.Width - this._sliders[i].Left; } } }
public static Bitmap PackBitmapsIntoOneLarge(ArrayList bmps, EPoint pntPreferredLayout, out Node infoRoot) { //If no specification of number of tiles on X and Y, make a guess: if (pntPreferredLayout == null) { int nNumOnX = (int)Math.Sqrt(bmps.Count); if (nNumOnX * nNumOnX < bmps.Count) { nNumOnX++; } int nNumOnY = bmps.Count / nNumOnX; if (nNumOnX * nNumOnY < bmps.Count) { nNumOnY++; } pntPreferredLayout = new EPoint(nNumOnX, nNumOnY); } bool bTrimWhiteSpace = true; //when packing the bitmap tightly, must store the offsets of bitmap frames so they don't wiggle on playback: bool bUseIndividualOffsets = true; infoRoot = new Node(); Node node = infoRoot.AppendChild("root"); node.AppendChild("NumFramesTotal").Value = bmps.Count; node.AppendChild("NumFramesOnX").Value = pntPreferredLayout.X; Node subNode; subNode = node.AppendChild("Animations"); //subNode.AppendChild("Default").Value = "0 0-4"; EPoint[] offsets = new EPoint[bmps.Count]; //this is the smallest rectangle that can encompass all frames: ERectangle rctBounds = ERectangle.FromLTRB(9999, 9999, -9999, -9999); //Trim white space from all bitmaps subNode = node.AppendChild("Frames"); for (int i = 0; i < bmps.Count; i++) { Bitmap bmp = (Bitmap)bmps[i]; if (bTrimWhiteSpace) { EPoint pntMid = new EPoint(bmp.Size.Width, bmp.Size.Height) / 2; EPoint pntTopLeftCorner; bmp = BitmapHelper.TrimWhitespace(bmp, out pntTopLeftCorner); bmps[i] = bmp; offsets[i] = pntTopLeftCorner; if (bUseIndividualOffsets) //make more compact (but offset values are needed): { rctBounds.Expand(new ERectangle(0, 0, bmp.Width, bmp.Height)); //make offset to middle of input bitmap offsets[i] = pntMid - pntTopLeftCorner; } else //Expand bounds so no offset values are needed: { rctBounds.Expand(new ERectangle(pntTopLeftCorner.X, pntTopLeftCorner.Y, bmp.Width, bmp.Height)); } } else { rctBounds.Expand(new ERectangle(0, 0, bmp.Width, bmp.Height)); } } //Create the merged bitmap: EPoint totalSize = rctBounds.Size * pntPreferredLayout; Bitmap largeBmp = new Bitmap(totalSize.X, totalSize.Y); Graphics g = Graphics.FromImage(largeBmp); for (int i = 0; i < bmps.Count; i++) { Bitmap bmp = (Bitmap)bmps[i]; EPoint pntDst = new EPoint((i % pntPreferredLayout.X) * rctBounds.Size.X, (i / pntPreferredLayout.X) * rctBounds.Size.Y); Node subsub = subNode.AppendChild("Frame"); subsub.Value = i.ToString(); if (bUseIndividualOffsets) { //subsub.AppendChild("Offset").Value = (offsets[i]+rctBounds.TopLeft).ToString(); subsub.AppendChild("Offset").Value = offsets[i].ToString(); } else { //pntDst is upper left corner of destination rectangle. //Since we don't use individual offset, we want to move it according to offset: pntDst = pntDst - rctBounds.TopLeft + offsets[i]; } g.DrawImage(bmp, new RectangleF(pntDst.ToPoint(), new Size(bmp.Width, bmp.Height))); } if (bUseIndividualOffsets) { node.AppendChild("RegPoint").Value = new EPoint().ToString(); } else { node.AppendChild("RegPoint").Value = rctBounds.TopLeft.ToString(); } return(largeBmp); }
protected void ResizeSliders() { if (this._sliders.Count == 0) return; if (this.Horizontal) { //TODO: change each textbox size and move both labels and textboxes //get space left for textboxes: int totalLabelWidth = 0; //Graphics g = Graphics.FromImage for (int i = 0; i < this._sliders.Count; i++) totalLabelWidth += this._labels[i].Width; totalLabelWidth += this._spacing.X * (this._labels.Count - 1); int sliderWidth = (this.Width - totalLabelWidth) / this._sliders.Count; EPoint pnt = new EPoint(0, 0); for (int i = 0; i < this._sliders.Count; i++) { this._labels[i].Location = pnt.ToPoint(); pnt.X = this._labels[i].Right; this._sliders[i].Location = pnt.ToPoint(); this._sliders[i].Width = sliderWidth; pnt.X = this._sliders[i].Right; pnt += this._spacing; } } else { for (int i = 0; i < this._sliders.Count; i++) this._sliders[i].Width = this.Width - this._sliders[i].Left; } }
public static Bitmap PackBitmapsIntoOneLarge(ArrayList bmps, EPoint pntPreferredLayout, out Node infoRoot) { //If no specification of number of tiles on X and Y, make a guess: if (pntPreferredLayout == null) { int nNumOnX = (int)Math.Sqrt(bmps.Count); if (nNumOnX*nNumOnX < bmps.Count) nNumOnX++; int nNumOnY = bmps.Count/nNumOnX; if (nNumOnX*nNumOnY < bmps.Count) nNumOnY++; pntPreferredLayout = new EPoint(nNumOnX, nNumOnY); } bool bTrimWhiteSpace = true; //when packing the bitmap tightly, must store the offsets of bitmap frames so they don't wiggle on playback: bool bUseIndividualOffsets = true; infoRoot = new Node(); Node node = infoRoot.AppendChild("root"); node.AppendChild("NumFramesTotal").Value = bmps.Count; node.AppendChild("NumFramesOnX").Value = pntPreferredLayout.X; Node subNode; subNode = node.AppendChild("Animations"); //subNode.AppendChild("Default").Value = "0 0-4"; EPoint[] offsets = new EPoint[bmps.Count]; //this is the smallest rectangle that can encompass all frames: ERectangle rctBounds = ERectangle.FromLTRB(9999,9999,-9999,-9999); //Trim white space from all bitmaps subNode = node.AppendChild("Frames"); for (int i = 0; i < bmps.Count; i++) { Bitmap bmp = (Bitmap)bmps[i]; if (bTrimWhiteSpace) { EPoint pntMid = new EPoint(bmp.Size.Width, bmp.Size.Height)/2; EPoint pntTopLeftCorner; bmp = BitmapHelper.TrimWhitespace(bmp, out pntTopLeftCorner); bmps[i] = bmp; offsets[i] = pntTopLeftCorner; if (bUseIndividualOffsets) //make more compact (but offset values are needed): { rctBounds.Expand(new ERectangle(0,0,bmp.Width, bmp.Height)); //make offset to middle of input bitmap offsets[i] = pntMid - pntTopLeftCorner; } else //Expand bounds so no offset values are needed: rctBounds.Expand(new ERectangle(pntTopLeftCorner.X, pntTopLeftCorner.Y, bmp.Width, bmp.Height)); } else { rctBounds.Expand(new ERectangle(0, 0, bmp.Width, bmp.Height)); } } //Create the merged bitmap: EPoint totalSize = rctBounds.Size*pntPreferredLayout; Bitmap largeBmp = new Bitmap(totalSize.X, totalSize.Y); Graphics g = Graphics.FromImage(largeBmp); for (int i = 0; i < bmps.Count; i++) { Bitmap bmp = (Bitmap)bmps[i]; EPoint pntDst = new EPoint((i%pntPreferredLayout.X)*rctBounds.Size.X, (i/pntPreferredLayout.X)*rctBounds.Size.Y); Node subsub = subNode.AppendChild("Frame"); subsub.Value = i.ToString(); if (bUseIndividualOffsets) { //subsub.AppendChild("Offset").Value = (offsets[i]+rctBounds.TopLeft).ToString(); subsub.AppendChild("Offset").Value = offsets[i].ToString(); } else { //pntDst is upper left corner of destination rectangle. //Since we don't use individual offset, we want to move it according to offset: pntDst = pntDst-rctBounds.TopLeft+offsets[i]; } g.DrawImage(bmp, new RectangleF(pntDst.ToPoint(), new Size(bmp.Width,bmp.Height))); } if (bUseIndividualOffsets) node.AppendChild("RegPoint").Value = new EPoint().ToString(); else node.AppendChild("RegPoint").Value = rctBounds.TopLeft.ToString(); return largeBmp; }