コード例 #1
0
        private void CalcBounds(DisplayObject obj,
                                Stage stage,
                                float scale,
                                bool intersectWithStage,
                                out Rectangle bounds,
                                out Rectangle boundsPOT)
        {
            float marginX;
            float marginY;

            // optimize for full-screen effects
            if (obj == stage || obj == SparrowSharpApp.Root)
            {
                marginX = marginY = 0;
                bounds  = new Rectangle(0, 0, stage.Width, stage.Height);
            }
            else
            {
                marginX = MarginX;
                marginY = MarginY;
                bounds  = obj.BoundsInSpace(stage);
            }

            if (intersectWithStage)
            {
                bounds = bounds.Intersection(stage.Bounds);
            }
            boundsPOT = null;
            Rectangle result = bounds;

            if (!result.IsEmpty())
            {
                // the bounds are a rectangle around the object, in stage coordinates,
                // and with an optional margin.
                bounds.Inflate(marginX, marginY);

                // To fit into a POT-texture, we extend it towards the right and bottom.
                int   minSize   = (int)(MIN_TEXTURE_SIZE / scale);
                float minWidth  = result.Width > minSize ? result.Width : minSize;
                float minHeight = result.Height > minSize ? result.Height : minSize;

                boundsPOT = new Rectangle(result.X,
                                          result.Top,
                                          NumberUtil.NextPowerOfTwo(minWidth * scale) / scale,
                                          NumberUtil.NextPowerOfTwo(minHeight * scale) / scale);
            }
        }
コード例 #2
0
        private Texture CreateTexture(int width, int height, float scale)
        {
            int legalWidth  = NumberUtil.NextPowerOfTwo(width * scale);
            int legalHeight = NumberUtil.NextPowerOfTwo(height * scale);

            TextureProperties texProps = new TextureProperties
            {
                TextureFormat      = TextureFormat.Rgba8888,
                Scale              = scale,
                Width              = legalWidth,
                Height             = legalHeight,
                NumMipmaps         = 0,
                PremultipliedAlpha = true
            };

            return(new GLTexture(IntPtr.Zero, texProps));
        }
コード例 #3
0
ファイル: CutTree.cs プロジェクト: sayon/csharp-algorithms
        public static CutTree <U> Build <U>(IList <U> source, int from, int to, Func <CutTree <U>, CutTree <U>, U> calc)
        {
            if (to < from)
            {
                return(null);
            }
            int length = to - from + 1;

            if (length == 1)
            {
                return(new CutTree <U>(from, to, source[from]));
            }
            int leftSize = NumberUtil.IsPowerOfTwo(length) ?
                           length / 2 :
                           NumberUtil.NextPowerOfTwo(length) / 2;

            var leftTree  = Build(source, from, from + leftSize - 1, calc);
            var rightTree = Build(source, from + leftSize, to, calc);

            return(new CutTree <U>(from, to, calc(leftTree, rightTree), leftTree, rightTree));
        }
コード例 #4
0
        /// <summary>
        /// Initializes a render texture with a certain ARGB color (0xAARRGGBB) and a scale factor.
        /// </summary>
        public RenderTexture(float width, float height, uint argbFillColor = 0x0, float scale = 1.0f)
        {
            int legalWidth  = NumberUtil.NextPowerOfTwo(width * scale);
            int legalHeight = NumberUtil.NextPowerOfTwo(height * scale);

            TextureProperties properties = new TextureProperties
            {
                TextureFormat      = Sparrow.Textures.TextureFormat.Rgba8888,
                Scale              = scale,
                Width              = legalWidth,
                Height             = legalHeight,
                NumMipmaps         = 0,
                PremultipliedAlpha = true
            };

            Rectangle region    = new Rectangle(0, 0, width, height);
            GLTexture glTexture = new GLTexture(IntPtr.Zero, properties);

            Init(glTexture, region);
            _renderSupport = new RenderSupport();
            Clear(argbFillColor, ColorUtil.GetA(argbFillColor) / 255.0f);
        }