public override void OnRender(RenderTarget Target) { if (!sizeSet) { if (Image != null && Image.IsLoaded) { sizeSet = true; Size = new Vector2(Image.Width, Image.Height); } else if (HoverImage != null && HoverImage.IsLoaded) { sizeSet = true; Size = new Vector2(HoverImage.Width, HoverImage.Height); } else if (DownImage != null && DownImage.IsLoaded) { sizeSet = true; Size = new Vector2(DownImage.Width, DownImage.Height); } } // preload hover and down images if (HoverImage != null) { HoverImage.Touch(); } if (DownImage != null) { DownImage.Touch(); } if (isHover && HoverImage != null) { Target.DrawSprite(HoverImage); } else if (isDown) { Target.DrawSprite(DownImage); } else { Target.DrawSprite(Image); } if (Text != null && Font != null) { Vector2 textpos; if (TextHorizontalAlign == TextAlignment.Left) { textpos.x = 0; } else if (TextHorizontalAlign == TextAlignment.Center) { textpos.x = Size.x / 2; } else { textpos.x = Size.x; } if (TextVerticalAlign == VerticalTextAlignment.Top) { textpos.y = 0; } else if (TextVerticalAlign == VerticalTextAlignment.Center) { textpos.y = Size.y / 2; } else { textpos.y = Size.y; } if (isHover && HoverFont != null) { HoverFont.DrawText(Target, textpos, Text, TextHorizontalAlign, TextVerticalAlign); } else { Font.DrawText(Target, textpos, Text, TextHorizontalAlign, TextVerticalAlign); } } }
private void CheckMouseUpdate() { inputController.Begin(); //Begin get inputController this.Clicked = false; //LEFT CLICK if (inputController.IsLeftClick()) { if (isHovered) { Debug.WriteLine(String.Format("{0},{1}", inputController.MousePosition.X, inputController.MousePosition.Y)); if (this.CanSelect) { this.isSelected = true; } this.Clicked = true; this.DoButtonEvent(); this.DoButtonEventWithSender(this); } else { if (this.CanSelect) { this.isSelected = false; } } } //RIGHT CLICK if (inputController.IsRightLick()) { if (isHovered) { this.isRightClick = true; this.OnRightClick(); } else { this.isRightClick = false; } } if (this.Sprite.Bound.Contains(inputController.MousePosition) && !isHovered) { if (hoverImage != null) { HoverImage.CopyAnimation(Sprite); this.Sprite = HoverImage; } isHovered = true; } if (!this.Sprite.Bound.Contains(inputController.MousePosition) && isHovered) { isHovered = false; if (normalImage != null) { NormalImage.CopyAnimation(Sprite); this.Sprite = NormalImage; } } if (isSelected && this.CanSelect) { if (selectedImage != null) { SelectedImage.CopyAnimation(Sprite); this.Sprite = SelectedImage; } else if (normalImage != null) { NormalImage.CopyAnimation(Sprite); this.Sprite = NormalImage; } } inputController.End(); //End get inputController }