示例#1
0
 public void DrawImage(IUITexture image, Rectangle position, Color tint)
 {
     if (image.Texture != null)
     {
         SpriteBatch.Draw(image.Texture, position, image.Bounds, tint);
     }
 }
        public IUITexture Insert(IUITexture tile)
        {
            IUITexture result;

            foreach (var b in builders)
            {
                if (b.Insert(tile, out result))
                {
                    return(result);
                }
            }

            var rt = new RenderTarget2D(device, size, size, false, device.PresentationParameters.BackBufferFormat, DepthFormat.None, 1, RenderTargetUsage.PreserveContents);

            device.SetRenderTarget(rt);
            device.Clear(Color.Transparent);
            device.SetRenderTarget(null);

            var b2 = new TextureAtlasBuilder(rt, rt.Bounds);

            if (b2.Insert(tile, out result))
            {
                builders.Add(b2);
            }
            return(result);
        }
示例#3
0
 public Button(IUIStyle style, string text = "", IUITexture iconTex = null) : base(style)
 {
     Content = new IconLabel(style)
     {
         Texture = iconTex, Text = text, Enabled = false, Anchor = AnchoredRect.CreateHorizontallyStretched()
     };
 }
 public static void DrawImageFromAtlas(this IBatchedDrawingService ds,
                                       IUITexture image,
                                       Rectangle destinationRectangle,
                                       Rectangle?sourceRectangle,
                                       Color color)
 {
     ds.Draw(image, destinationRectangle, sourceRectangle, color, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f);
 }
示例#5
0
            public IUITexture ProcessTexture(IUITexture texture)
            {
                IUITexture result;

                if (processedTextures.TryGetValue(texture, out result))
                {
                    return(result);
                }
                result = this.atlasBuilder.Insert(texture);
                processedTextures[texture] = result;
                return(result);
            }
示例#6
0
 public void Draw(IUITexture texture,
                  Rectangle destinationRectangle,
                  Rectangle?sourceRectangle,
                  Color color,
                  float rotation,
                  Vector2 origin,
                  SpriteEffects effects,
                  float layerDepth)
 {
     if (texture.Texture != null)
     {
         SpriteBatch.Draw(texture.Texture, destinationRectangle, sourceRectangle, color, rotation, origin, effects,
                          layerDepth);
     }
 }
            public TreeNode Insert(IUITexture tex, int padding)
            {
                if (!Leaf)
                {
                    var maybeLeft = Left.Insert(tex, padding);
                    if (maybeLeft != null)
                    {
                        return(maybeLeft);
                    }
                    return(Right.Insert(tex, padding));
                }

                if (Texture != null)
                {
                    // There is already something here
                    return(null);
                }
                var texBounds = tex.Bounds;

                if (texBounds.Width > CellBounds.Width ||
                    texBounds.Height > CellBounds.Height)
                {
                    // does not fit into the available space
                    return(null);
                }
                if (texBounds.Width == CellBounds.Width &&
                    texBounds.Height == CellBounds.Height)
                {
                    Texture = tex;
                    return(this);
                }
                if ((CellBounds.Width - texBounds.Width) > (CellBounds.Height - texBounds.Height))
                {
                    // vertical split
                    Left  = new TreeNode(new Rectangle(CellBounds.X, CellBounds.Y, texBounds.Width, CellBounds.Height));
                    Right = new TreeNode(new Rectangle(CellBounds.X + padding + texBounds.Width, CellBounds.Y,
                                                       CellBounds.Width - texBounds.Width - padding, CellBounds.Height));
                }
                else
                {
                    Left  = new TreeNode(new Rectangle(CellBounds.X, CellBounds.Y, CellBounds.Width, texBounds.Height));
                    Right = new TreeNode(new Rectangle(CellBounds.X, CellBounds.Y + padding + texBounds.Height, CellBounds.Width,
                                                       CellBounds.Height - texBounds.Height - padding));
                }
                return(Left.Insert(tex, padding));
            }
示例#8
0
 /// <summary>
 /// 异步获取CMTexture回调
 /// </summary>
 /// <param name="tex"></param>
 /// <param name="param1"></param>
 /// <param name="param2"></param>
 /// <param name="param3"></param>
 private static void OnGetCMTextureDlg(IUITexture tex, object param1, object param2, object param3)
 {
     if (null != param1 && param1 is UITexture)
     {
         UITexture uitexture = (UITexture)param1;
         Texture   texture   = (null != tex) ? tex.GetTexture() : null;
         uitexture.mainTexture = texture;
         if (null != param2 && param2 is bool)
         {
             bool makePerfect = (bool)param2;
             if (makePerfect && null != uitexture)
             {
                 uitexture.MakePixelPerfect();
             }
         }
     }
 }
        public bool Insert(IUITexture tile, out IUITexture result)
        {
            if (!IsValid(tile))
            {
                result = tile;
                return(true);
            }

            var res = root.Insert(tile, 2);

            if (res != null)
            {
                result = res.Harvest(texture);
                return(result != null);
            }

            result = tile;
            return(false);
        }
        public static void Draw([NotNull] this IBatchedDrawingService ds,
                                [CanBeNull] IUITexture texture,
                                Vector2 position,
                                Rectangle?sourceRectangle,
                                Color color,
                                float rotation,
                                Vector2 origin,
                                float scale,
                                SpriteEffects effects,
                                float layerDepth)
        {
            if (texture == null)
            {
                return;
            }

            var rect = new Rectangle((int)position.X, (int)position.Y, (int)(texture.Width * scale),
                                     (int)(texture.Height * scale));

            ds.Draw(texture, rect, sourceRectangle, color, rotation, origin, effects, layerDepth);
        }
示例#11
0
 public StyleDefinition(string name, List <IStyleRule> rules, IUITexture whitePixel)
 {
     this.WhitePixel = whitePixel;
     Name            = name;
     Rules           = rules;
 }
示例#12
0
 void Draw(IUITexture texture, Rectangle destinationRectangle, Color color)
 {
     SpriteBatch.Draw(texture.Texture, destinationRectangle, color);
 }
 static bool IsValid(IUITexture tex)
 {
     return(tex?.Texture != null);
 }
示例#14
0
 public IUITexture ProcessTexture(IUITexture texture)
 {
     return(texture);
 }
 public RadioButtonSetContent(IUIStyle style, string text = "", IUITexture iconTex = null) : base(style, text, iconTex)
 {
     AddStyleClass(StyleClass);
 }
 public static void DrawImage(this IBatchedDrawingService ds, IUITexture image, Vector2 position, Color tint)
 {
     ds.DrawImage(image, new Rectangle((int)position.X, (int)position.Y, image.Width, image.Height), tint);
 }