Example #1
0
        protected internal override void OnTouchEvent(TouchEventCollection touchEvents)
        {
            base.OnTouchEvent(touchEvents);
            if (!this.Enabled)
            {
                return;
            }
            TouchEvent primaryTouchEvent = touchEvents.PrimaryTouchEvent;

            switch (primaryTouchEvent.Type)
            {
            case TouchEventType.Up:
                if (this.state == Slider.SliderState.Pressed)
                {
                    this.state = Slider.SliderState.Normal;
                    this.UpdateView();
                    if (this.ValueChangeEventEnabled && this.ValueChanged != null)
                    {
                        this.ValueChanged.Invoke(this, new SliderValueChangeEventArgs(this.Value));
                    }
                }
                break;

            case TouchEventType.Down:
                this.handleClickPos.X = this.handleImage.X - primaryTouchEvent.LocalPosition.X;
                this.handleClickPos.Y = this.handleImage.Y - primaryTouchEvent.LocalPosition.Y;
                this.state            = Slider.SliderState.Pressed;
                this.UpdateView();
                return;

            case TouchEventType.Move:
                if (this.state == Slider.SliderState.Pressed)
                {
                    this.UpdateHandlePos(primaryTouchEvent.LocalPosition);
                    if (this.ValueChangeEventEnabled && this.ValueChanging != null)
                    {
                        this.ValueChanging.Invoke(this, new SliderValueChangeEventArgs(this.Value));
                        return;
                    }
                }
                break;

            default:
                return;
            }
        }
Example #2
0
 public Slider()
 {
     this.baseImageAssets              = new ImageAsset[Enum.GetValues(typeof(SliderOrientation)).Length];
     this.baseImageAssets[1]           = new ImageAsset(SystemImageAsset.SliderVerticalBaseNormal);
     this.baseImageAssets[0]           = new ImageAsset(SystemImageAsset.SliderHorizontalBaseNormal);
     this.baseImageNinePatchMargins    = new NinePatchMargin[Enum.GetValues(typeof(SliderOrientation)).Length];
     this.baseImageNinePatchMargins[1] = AssetManager.GetNinePatchMargin(SystemImageAsset.SliderVerticalBaseNormal);
     this.baseImageNinePatchMargins[0] = AssetManager.GetNinePatchMargin(SystemImageAsset.SliderHorizontalBaseNormal);
     this.barImageAssets              = new ImageAsset[Enum.GetValues(typeof(SliderOrientation)).Length];
     this.barImageAssets[1]           = new ImageAsset(SystemImageAsset.SliderVerticalBarNormal);
     this.barImageAssets[0]           = new ImageAsset(SystemImageAsset.SliderHorizontalBarNormal);
     this.barImageNinePatchMargins    = new NinePatchMargin[Enum.GetValues(typeof(SliderOrientation)).Length];
     this.barImageNinePatchMargins[1] = AssetManager.GetNinePatchMargin(SystemImageAsset.SliderVerticalBarNormal);
     this.barImageNinePatchMargins[0] = AssetManager.GetNinePatchMargin(SystemImageAsset.SliderHorizontalBarNormal);
     this.handleImageAssets           = new ImageAsset[Enum.GetValues(typeof(SliderOrientation)).Length, Enum.GetValues(typeof(Slider.SliderState)).Length];
     this.handleImageAssets[1, 0]     = new ImageAsset(SystemImageAsset.SliderVerticalHandleNormal);
     this.handleImageAssets[1, 1]     = new ImageAsset(SystemImageAsset.SliderVerticalHandlePressed);
     this.handleImageAssets[1, 2]     = new ImageAsset(SystemImageAsset.SliderVerticalHandleDisabled);
     this.handleImageAssets[0, 0]     = new ImageAsset(SystemImageAsset.SliderHorizontalHandleNormal);
     this.handleImageAssets[0, 1]     = new ImageAsset(SystemImageAsset.SliderHorizontalHandlePressed);
     this.handleImageAssets[0, 2]     = new ImageAsset(SystemImageAsset.SliderHorizontalHandleDisabled);
     this.baseImage = new ImageBox();
     this.baseImage.ImageScaleType = ImageScaleType.NinePatch;
     this.baseImage.TouchResponse  = false;
     base.AddChildLast(this.baseImage);
     this.barImage = new ImageBox();
     this.barImage.ImageScaleType = ImageScaleType.NinePatch;
     this.barImage.TouchResponse  = false;
     base.AddChildLast(this.barImage);
     this.handleImage = new ImageBox();
     this.handleImage.ImageScaleType = ImageScaleType.NinePatch;
     base.AddChildLast(this.handleImage);
     this.value    = 0f;
     this.minValue = 0f;
     this.maxValue = 1f;
     this.state    = Slider.SliderState.Normal;
     this.ValueChangeEventEnabled = true;
     this.ValueChanging           = null;
     this.ValueChanged            = null;
     this.handleClickPos          = Vector2.Zero;
     this.Orientation             = SliderOrientation.Horizontal;
     base.HookChildTouchEvent     = true;
     this.PriorityHit             = true;
     this.UpdateView();
 }