Exemple #1
0
 private void customImageChanged()
 {
     this.backgroundImages[1, 0]  = this.customImage.BackgroundNormalImage;
     this.backgroundImages[1, 1]  = this.customImage.BackgroundPressedImage;
     this.backgroundImages[1, 2]  = this.customImage.BackgroundDisabledImage;
     this.backgroundNinePatchs[1] = this.customImage.BackgroundNinePatchMargin;
     this.updateFlags            |= Button.UpdateFlags.Background;
 }
Exemple #2
0
        private void UpdateIconSprite()
        {
            if ((this.updateFlags & Button.UpdateFlags.Icon) == Button.UpdateFlags.Icon)
            {
                this.updateFlags &= ~Button.UpdateFlags.Icon;
                if (this.IconImage == null)
                {
                    this.iconSprt.Visible = false;
                    return;
                }
                if (this.IconImage.Ready)
                {
                    UISpriteUnit unit = this.iconSprt.GetUnit(0);
                    unit.Width  = (float)this.IconImage.Width;
                    unit.Height = (float)this.IconImage.Height;
                    switch (this.HorizontalAlignment)
                    {
                    case HorizontalAlignment.Left:
                        unit.X = 0f;
                        break;

                    case HorizontalAlignment.Center:
                        unit.X = (this.Width - unit.Width) / 2f;
                        break;

                    case HorizontalAlignment.Right:
                        unit.X = this.Width - unit.Width;
                        break;
                    }
                    switch (this.VerticalAlignment)
                    {
                    case VerticalAlignment.Top:
                        unit.Y = 0f;
                        break;

                    case VerticalAlignment.Middle:
                        unit.Y = (this.Height - unit.Height) / 2f;
                        break;

                    case VerticalAlignment.Bottom:
                        unit.Y = this.Height - unit.Height;
                        break;
                    }
                    this.iconSprt.ShaderType = ShaderType.Texture;
                    this.iconSprt.Image      = this.IconImage;
                    this.iconSprt.Visible    = true;
                    this.textSprt.Visible    = false;
                    return;
                }
                this.iconSprt.Visible = false;
                this.textSprt.Visible = false;
                this.updateFlags     |= Button.UpdateFlags.Icon;
            }
        }
Exemple #3
0
 private void UpdateTextSprite()
 {
     if (string.IsNullOrEmpty(this.Text))
     {
         this.textSprt.Visible = false;
         this.updateFlags     &= ~Button.UpdateFlags.Text;
     }
     if ((this.updateFlags & Button.UpdateFlags.Text) == Button.UpdateFlags.Text)
     {
         TextRenderHelper textRenderHelper = new TextRenderHelper();
         textRenderHelper.LineBreak           = LineBreak.AtCode;
         textRenderHelper.HorizontalAlignment = this.HorizontalAlignment;
         textRenderHelper.VerticalAlignment   = this.VerticalAlignment;
         textRenderHelper.Font         = this.TextFont;
         textRenderHelper.TextTrimming = this.TextTrimming;
         UISpriteUnit unit = this.textSprt.GetUnit(0);
         unit.Width  = this.Width;
         unit.Height = this.Height;
         unit.Color  = this.TextColor;
         if (this.textSprt.Image != null)
         {
             this.textSprt.Image.Dispose();
         }
         this.textSprt.Image      = textRenderHelper.DrawText(ref this.text, (int)unit.Width, (int)unit.Height);
         this.textSprt.Alpha      = ((this.State == Button.ButtonState.Disabled) ? 0.3f : 1f);
         this.textSprt.ShaderType = ShaderType.TextTexture;
         this.textSprt.Visible    = true;
         this.iconSprt.Visible    = false;
         if (this.TextShadow != null)
         {
             this.textSprt.InternalShaderType = InternalShaderType.TextureAlphaShadow;
             this.textSprt.ShaderUniforms["u_ShadowColor"] = new float[]
             {
                 this.TextShadow.Color.R,
                 this.TextShadow.Color.G,
                 this.TextShadow.Color.B,
                 this.TextShadow.Color.A
             };
             this.textSprt.ShaderUniforms["u_ShadowOffset"] = new float[]
             {
                 this.TextShadow.HorizontalOffset / (float)this.textSprt.Image.Width,
                 this.TextShadow.VerticalOffset / (float)this.textSprt.Image.Height
             };
         }
         this.updateFlags &= ~Button.UpdateFlags.Text;
     }
 }
Exemple #4
0
 private void UpdateBackgroundSprite()
 {
     if ((this.updateFlags & Button.UpdateFlags.Background) == Button.UpdateFlags.Background)
     {
         this.updateFlags &= ~Button.UpdateFlags.Background;
         ImageAsset imageAsset = this.backgroundImages[(int)this.Style, (int)this.State];
         if (imageAsset == null)
         {
             this.backgroundPrim.Image   = null;
             this.backgroundPrim.Visible = true;
             return;
         }
         if (imageAsset.Ready)
         {
             this.backgroundPrim.Image       = imageAsset;
             this.backgroundPrim.VertexCount = 9;
             this.backgroundPrim.Visible     = true;
             UIPrimitiveUtility.SetupNinePatch(this.backgroundPrim, this.Width, this.Height, 0f, 0f, this.backgroundNinePatchs[(int)this.Style]);
             return;
         }
         this.backgroundPrim.Visible = false;
         this.updateFlags           |= Button.UpdateFlags.Background;
     }
 }
Exemple #5
0
 public Button()
 {
     this.backgroundPrim = new UIPrimitive((DrawMode)4, 16, 28);
     base.RootUIElement.AddChildLast(this.backgroundPrim);
     this.backgroundPrim.ShaderType = ShaderType.Texture;
     this.iconSprt = new UISprite(1);
     base.RootUIElement.AddChildLast(this.iconSprt);
     this.iconSprt.ShaderType = ShaderType.SolidFill;
     this.iconSprt.Visible    = false;
     this.textSprt            = new UISprite(1);
     base.RootUIElement.AddChildLast(this.textSprt);
     this.textSprt.ShaderType = ShaderType.TextTexture;
     this.textSprt.Visible    = false;
     this.State                   = Button.ButtonState.Normal;
     this.updateFlags             = Button.UpdateFlags.Background;
     this.backgroundImages        = new ImageAsset[Enum.GetValues(typeof(ButtonStyle)).Length, Enum.GetValues(typeof(Button.ButtonState)).Length];
     this.backgroundImages[0, 0]  = new ImageAsset(SystemImageAsset.ButtonBackgroundNormal);
     this.backgroundImages[0, 1]  = new ImageAsset(SystemImageAsset.ButtonBackgroundPressed);
     this.backgroundImages[0, 2]  = new ImageAsset(SystemImageAsset.ButtonBackgroundDisabled);
     this.backgroundNinePatchs    = new NinePatchMargin[Enum.GetValues(typeof(ButtonStyle)).Length];
     this.backgroundNinePatchs[0] = AssetManager.GetNinePatchMargin(SystemImageAsset.ButtonBackgroundNormal);
     this.CustomImage             = null;
     this.IconImage               = null;
     this.Text                = "";
     this.TextFont            = UISystem.DefaultFont;
     this.TextTrimming        = TextTrimming.EllipsisCharacter;
     this.TextColor           = new UIColor(1f, 1f, 1f, 1f);
     this.TextShadow          = null;
     this.HorizontalAlignment = HorizontalAlignment.Center;
     this.VerticalAlignment   = VerticalAlignment.Middle;
     this.Style               = ButtonStyle.Default;
     this.Enabled             = true;
     this.Width               = 214f;
     this.Height              = 56f;
     this.PriorityHit         = true;
 }
Exemple #6
0
 private void textShadowChanged()
 {
     this.updateFlags |= Button.UpdateFlags.Text;
 }