Exemple #1
0
        static void Scale(AnimDoc doc, double nScale, Palette palFixed, bool fScaleIcon)
        {
            if (nScale >= 1.5)
            {
                doc.Hires = true;
            }

            // If not scaling icon, make a clone of it so it doesn't get scaled,
            // then after scaling set this clone back in.

            Strip stpIcon      = doc.StripSet["icon"];
            Strip stpIconClone = null;

            if (!fScaleIcon && stpIcon != null)
            {
                stpIconClone = (Strip)stpIcon.Clone();
            }

            // Scale all the bitmaps

            foreach (XBitmap xbm in doc.XBitmapSet)
            {
                // Scale

                xbm.Bitmap = TBitmapTools.ScaleBitmap(xbm.Bitmap, nScale, palFixed);

                // Scale the points in the frames that use this bitmap

                foreach (Strip stp in doc.StripSet)
                {
                    foreach (Frame fr in stp)
                    {
                        foreach (BitmapPlacer plc in fr.BitmapPlacers)
                        {
                            if (plc.XBitmap == xbm)
                            {
                                plc.X = (int)Math.Round(plc.X * nScale);
                                plc.Y = (int)Math.Round(plc.Y * nScale);
                            }
                        }
                    }
                }
            }

            // Scale all special points too

            foreach (Strip stp in doc.StripSet)
            {
                foreach (Frame fr in stp)
                {
                    Point pt = new Point();
                    pt.X            = (int)Math.Round(fr.SpecialPoint.X * nScale);
                    pt.Y            = (int)Math.Round(fr.SpecialPoint.Y * nScale);
                    fr.SpecialPoint = pt;
                }
            }

            // Put the strip icon back in if it shouldn't be scaled

            if (!fScaleIcon && stpIconClone != null)
            {
                // Patch in the clone and add the images to the XBitmapSet
                // (they are not added auto-magically).

                doc.StripSet[doc.StripSet.IndexOf(stpIcon)] = stpIconClone;
                foreach (Frame fr in stpIconClone)
                {
                    foreach (BitmapPlacer plc in fr.BitmapPlacers)
                    {
                        doc.XBitmapSet.Add(plc.XBitmap);
                    }
                }
            }
        }
Exemple #2
0
        static Strip MakeHighlightStrip(AnimDoc doc, int cxTile,
                                        Palette palFixed)
        {
            Strip stpHelp = doc.StripSet["help"];

            if (stpHelp == null)
            {
                return(null);
            }

            // This does a deep copy
            Strip stpHighlight = (Strip)stpHelp.Clone();

            stpHighlight.Name = "highlight";

            // Figure out the scaling. It would be better to pass this in as
            // a parameter.

            Frame     frT     = stpHighlight[0];
            Rectangle rcUnion = new Rectangle();

            foreach (BitmapPlacer plc in frT.BitmapPlacers)
            {
                Rectangle rc = new Rectangle();
                rc.X      = -plc.X;
                rc.Y      = -plc.Y;
                rc.Width  = plc.XBitmap.Width;
                rc.Height = plc.XBitmap.Height;
                if (rcUnion.IsEmpty)
                {
                    rcUnion = rc;
                }
                else
                {
                    rcUnion = Rectangle.Union(rcUnion, rc);
                }
            }

            // Needs to be 4 tiles high. Keep aspect ratio

            int cy = rcUnion.Height;

            if (cy < cxTile * 4)
            {
                cy = cxTile * 4;
            }
            double nScale = 1.0;

            if (cy > rcUnion.Height)
            {
                nScale = (double)cy / (double)rcUnion.Height;
            }

            // Scale

            if (nScale != 1.0)
            {
                foreach (Frame fr in stpHighlight)
                {
                    foreach (BitmapPlacer plc in fr.BitmapPlacers)
                    {
                        plc.XBitmap.Bitmap = TBitmapTools.ScaleBitmap(
                            plc.XBitmap.Bitmap, nScale, palFixed);
                        plc.X = (int)Math.Round(plc.X * nScale);
                        plc.Y = (int)Math.Round(plc.Y * nScale);
                    }

                    Point pt = new Point();
                    pt.X            = (int)Math.Round(fr.SpecialPoint.X * nScale);
                    pt.Y            = (int)Math.Round(fr.SpecialPoint.Y * nScale);
                    fr.SpecialPoint = pt;
                }
            }

            return(stpHighlight);
        }