コード例 #1
0
        public void Drag2()
        {
            DragPanel dp = new DragPanel
            {
                Width  = 10,
                Height = 10
            };
            RectangleView r = new RectangleView
            {
                PreferredHeight = 3,
                PreferredWidth  = 3,
                Position        = new Point(3, 3)
            };

            dp.Children.Add(r);

            MouseEventData mev = new MouseEventData(MouseEvent.MOUSE_PRESSED, new Point(3, 3), 1);

            UIElement.HandleMouseEvent(dp, mev);

            mev = new MouseEventData(MouseEvent.MOUSE_DRAGGED, new Point(1, 1), 1);
            UIElement.HandleMouseEvent(dp, mev);
            Assert.AreEqual(new Point(1, 1), r.Position);

            mev = new MouseEventData(MouseEvent.MOUSE_RELEASED, new Point(1, 1), 1);
            UIElement.HandleMouseEvent(dp, mev);
            Assert.AreEqual(new Point(1, 1), r.Position);
        }
コード例 #2
0
        public void AbsolutePositionParentChanged()
        {
            var scheduler = new TestScheduler();

            var root    = new UIElement();
            var element = new RectangleView();
            var child   = new Button();

            // Add element to root as a child.
            root.Children.Add(element);
            element.Children.Add(child);

            // Change the position of the element.
            scheduler.Schedule(TimeSpan.FromTicks(10), () => element.Position = new Point(86, 4));

            var expected = new[]
            {
                ReactiveTest.OnNext(1, new Point(0, 0)),
                ReactiveTest.OnNext(10, new Point(86, 4))
            };

            var actual = scheduler.Start(() => child.AbsolutePositionChanged, 0, 0, 1000).Messages;

            ReactiveAssert.AreElementsEqual(expected, actual);
        }
コード例 #3
0
        public void TestAddWindow2()
        {
            RectangleView r  = new RectangleView();
            WindowsView   wv = new WindowsView();

            WindowsView.Window wvNew = wv.AddWindow(r);
            Assert.AreEqual(500, wvNew.Width);
        }
コード例 #4
0
        public static void SetWidth(this RectangleView view, double width)
        {
            if (view == null)
            {
                return;
            }

            view.Width = width;
        }
コード例 #5
0
        public void TestAddWindow3()
        {
            RectangleView r1 = new RectangleView();
            RectangleView r2 = new RectangleView();
            WindowsView   wv = new WindowsView();

            WindowsView.Window wv1 = wv.AddWindow(r1); // To get an offset on wv2
            WindowsView.Window wv2 = wv.AddWindow(r2);
            Assert.AreEqual(new Point(10, 10), wv2.Position);
        }
コード例 #6
0
ファイル: MainActivity.cs プロジェクト: asafs/imagegame
        private void AddSectionButtonOnClick(object sender, EventArgs eventArgs)
        {
            if (_inAddSectionMode)
            {
                _currentRectangleView = null;
            }

            ((Button)sender).Text = _inAddSectionMode ? "Add Section" : "Done Edit";
            _inAddSectionMode     = !_inAddSectionMode;
        }
コード例 #7
0
        public void TestRemoveWindow()
        {
            RectangleView r1 = new RectangleView();
            RectangleView r2 = new RectangleView();
            WindowsView   wv = new WindowsView();

            WindowsView.Window wv1 = wv.AddWindow(r1); // To get an offset on wv2
            WindowsView.Window wv2 = wv.AddWindow(r2);
            wv.RemoveWindowWith(r2);
            Assert.AreEqual(false, wv.Children.Contains(wv2));
        }
コード例 #8
0
        private void SetupImageOvewlay(CarModel carModel)
        {
            var height = (int)(400 * Resources.DisplayMetrics.Density);
            var width  = Resources.DisplayMetrics.WidthPixels;

            var bmp = BitmapFactory.DecodeByteArray(carModel.Bytes, 0, carModel.Bytes.Length);

            imageViewCar.SetImageBitmap(Bitmap.CreateScaledBitmap(bmp, Resources.DisplayMetrics.WidthPixels, height, false));

            var tlX = width * carModel.Rectangle.TlX;
            var tlY = height * carModel.Rectangle.TlY;
            var brX = width * carModel.Rectangle.BrX;
            var brY = height * carModel.Rectangle.BrY;

            var rectangle = new RectangleView(this, tlX, tlY, brX, brY);

            relativeLayoutImageRoot.AddView(rectangle);
        }
コード例 #9
0
        public void ObserveParentWidth()
        {
            var scheduler = new TestScheduler();

            var parent     = new UIElement();
            var child      = new RectangleView();
            var observable = child.ParentChanged.Where(t => t != null && child.IsVisible).Select(p => p.WidthChanged).Switch();

            // Setup parent child relationship
            parent.Children.Add(child);

            // Change the width of the parent.
            scheduler.Schedule(TimeSpan.FromTicks(10), () => parent.Width = 500);

            var expected = new[]
            {
                ReactiveTest.OnNext(1, 0),
                ReactiveTest.OnNext(10, 500)
            };

            var actual = scheduler.Start(() => observable, 0, 0, 1000).Messages;

            ReactiveAssert.AreElementsEqual(expected, actual);
        }
コード例 #10
0
        private void Initialize()
        {
            if (!DesignTime.IsDesignMode)
            {
                TargetWidth = CalculateScreenDimension(200);
            }

            // Vertically-oriented layout for containing all scalebar components
            _rootLayout = new LinearLayout(Context)
            {
                Orientation      = Orientation.Vertical,
                LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent),
            };
            _rootLayout.SetGravity(GravityFlags.Top);

            // Initialize scalebar components with placeholder sizes and values
            var scalelineHeight = CalculateScreenDimension(2);

            _combinedScaleLine = new RectangleView(Context, TargetWidth, scalelineHeight)
            {
                BackgroundColor = ForegroundColor
            };
            _metricScaleLine = new RectangleView(Context, TargetWidth, 1);
            _metricValue     = new TextView(Context)
            {
                Text = "100"
            };
            _metricUnit = new TextView(Context)
            {
                Text = "m"
            };
            _usScaleLine = new RectangleView(Context, _metricScaleLine.Width * .9144, 1);
            _usValue     = new TextView(Context)
            {
                Text = "300"
            };
            _usUnit = new TextView(Context)
            {
                Text = "ft"
            };

            var fontSize = 12;

            _metricValue.SetTextSize(ComplexUnitType.Dip, fontSize);
            _metricValue.SetTextColor(ForegroundColor);
            _metricUnit.SetTextSize(ComplexUnitType.Dip, fontSize);
            _metricUnit.SetTextColor(ForegroundColor);
            _usValue.SetTextSize(ComplexUnitType.Dip, fontSize);
            _usValue.SetTextColor(ForegroundColor);
            _usUnit.SetTextSize(ComplexUnitType.Dip, fontSize);
            _usUnit.SetTextColor(ForegroundColor);

            // Listen for width updates on metric and imperial scale lines to update the combined scale line
            _metricScaleLine.PropertyChanged += ScaleLine_PropertyChanged;
            _usScaleLine.PropertyChanged     += ScaleLine_PropertyChanged;

            // ===============================================================
            // First row - placeholder, numeric text, and units text
            // ===============================================================
            var firstRowLayout = new LinearLayout(Context)
            {
                Orientation      = Orientation.Horizontal,
                LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent),
            };

            firstRowLayout.AddView(_metricScaleLine);
            firstRowLayout.AddView(_metricValue);
            firstRowLayout.AddView(_metricUnit);

            // ================================================================================
            // Second row - first metric tick line, placeholder, and second metric tick line
            // ================================================================================
            var secondRowLayout = new LinearLayout(Context)
            {
                Orientation      = Orientation.Horizontal,
                LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent),
            };

            var tickWidth  = CalculateScreenDimension(2);
            var tickHeight = CalculateScreenDimension(5);

            _firstMetricTickLine = new RectangleView(Context, tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };

            _metricWidthPlaceholder = new RectangleView(Context, _metricScaleLine.Width, 1);
            _secondMetricTickLine   = new RectangleView(Context, tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };

            secondRowLayout.AddView(_firstMetricTickLine);
            secondRowLayout.AddView(_metricWidthPlaceholder);
            secondRowLayout.AddView(_secondMetricTickLine);

            // ==============================================================================================
            // Third row - filler segment at start of scale line, combined metric/imperial scale line
            // ==============================================================================================
            var thirdRowLayout = new LinearLayout(Context)
            {
                Orientation      = Orientation.Horizontal,
                LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent),
            };

            _scaleLineStartSegment = new RectangleView(Context, Math.Round(tickWidth) * 2, scalelineHeight)
            {
                BackgroundColor = ForegroundColor
            };

            thirdRowLayout.AddView(_scaleLineStartSegment);
            thirdRowLayout.AddView(_combinedScaleLine);

            // ==============================================================================================
            // Fourth row - first imperial tick line, placeholder, second imperial tick line
            // ==============================================================================================
            var fourthRowLayout = new LinearLayout(Context)
            {
                Orientation      = Orientation.Horizontal,
                LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent),
            };

            _firstUsTickLine = new RectangleView(Context, tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };
            _secondUsTickLine = new RectangleView(Context, tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };

            fourthRowLayout.AddView(_firstUsTickLine);
            fourthRowLayout.AddView(_usScaleLine);
            fourthRowLayout.AddView(_secondUsTickLine);

            // ==========================================================================
            // Fifth row - placeholder, imperial numeric text, imperial unit text
            // ==========================================================================
            var fifthRowLayout = new LinearLayout(Context)
            {
                Orientation      = Orientation.Horizontal,
                LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent),
            };

            _usWidthPlaceholder = new RectangleView(Context, _usScaleLine.Width, 1);

            fifthRowLayout.AddView(_usWidthPlaceholder);
            fifthRowLayout.AddView(_usValue);
            fifthRowLayout.AddView(_usUnit);

            // Add all scalebar rows to the root layout
            _rootLayout.AddView(firstRowLayout);
            _rootLayout.AddView(secondRowLayout);
            _rootLayout.AddView(thirdRowLayout);
            _rootLayout.AddView(fourthRowLayout);
            _rootLayout.AddView(fifthRowLayout);

            // Add root layout to view
            AddView(_rootLayout);
            _rootLayout.RequestLayout();
        }
コード例 #11
0
 public static void SetBorderWidth(this RectangleView view, double width) => view.BorderWidth = width;
コード例 #12
0
 public static void SetBorderColor(this RectangleView view, UIColor color) => view.BorderColor = color;
コード例 #13
0
        private void Initialize()
        {
            BackgroundColor = UIColor.Clear;

            // At run-time, don't display the sub-views until their dimensions have been calculated
            if (!DesignTime.IsDesignMode)
            {
                Hidden = true;
            }

            // Vertically-oriented stack view for containing all scalebar components
            _rootStackView = new UIStackView()
            {
                Axis         = UILayoutConstraintAxis.Vertical,
                Alignment    = UIStackViewAlignment.Leading,
                Distribution = UIStackViewDistribution.Fill,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 0
            };

            // Initialize scalebar components with placeholder sizes and values
            var font = UIFont.SystemFontOfSize(11);

            _combinedScaleLine = new RectangleView(200, 2)
            {
                BackgroundColor = ForegroundColor
            };
            _metricScaleLine = new RectangleView(200, 2);
            _metricValue     = new UILabel()
            {
                Text = "100", Font = font
            };
            _metricUnit = new UILabel()
            {
                Text = "m", Font = font
            };
            _usScaleLine = new RectangleView(_metricScaleLine.Width * .9144, 2);
            _usValue     = new UILabel()
            {
                Text = "300", Font = font
            };
            _usUnit = new UILabel()
            {
                Text = "ft", Font = font
            };

            // Listen for width updates on metric and imperial scale lines to update the combined scale line
            _metricScaleLine.PropertyChanged += ScaleLine_PropertyChanged;
            _usScaleLine.PropertyChanged     += ScaleLine_PropertyChanged;

            // ===============================================================
            // First row - placeholder, numeric text, and units text
            // ===============================================================
            var firstRowStackView = new UIStackView()
            {
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Leading,
                Distribution = UIStackViewDistribution.Fill,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 0
            };

            firstRowStackView.AddArrangedSubview(_metricScaleLine);
            firstRowStackView.AddArrangedSubview(_metricValue);
            firstRowStackView.AddArrangedSubview(_metricUnit);

            // ================================================================================
            // Second row - first metric tick line, placeholder, and second metric tick line
            // ================================================================================
            var secondRowStackView = new UIStackView()
            {
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Leading,
                Distribution = UIStackViewDistribution.Fill,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 0
            };

            var tickWidth  = 2;
            var tickHeight = 5;

            _firstMetricTickLine = new RectangleView(tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };

            var metricWidthPlaceholder = new UIView();

            _secondMetricTickLine = new RectangleView(tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };

            secondRowStackView.AddArrangedSubview(_firstMetricTickLine);
            secondRowStackView.AddArrangedSubview(metricWidthPlaceholder);
            secondRowStackView.AddArrangedSubview(_secondMetricTickLine);

            // ==============================================================================================
            // Third row - filler segment at start of scale line, metric scale line, imperial scale line
            // ==============================================================================================
            var thirdRowStackView = new UIStackView()
            {
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Leading,
                Distribution = UIStackViewDistribution.Fill,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 0
            };

            _scaleLineStartSegment = new RectangleView(4, 2)
            {
                BackgroundColor = ForegroundColor
            };

            thirdRowStackView.AddArrangedSubview(_scaleLineStartSegment);
            thirdRowStackView.AddArrangedSubview(_combinedScaleLine);

            // ==============================================================================================
            // Fourth row - first imperial tick line, placeholder, second imperial tick line
            // ==============================================================================================
            var fourthRowStackView = new UIStackView()
            {
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Leading,
                Distribution = UIStackViewDistribution.Fill,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 0
            };

            _firstUsTickLine = new RectangleView(tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };
            _secondUsTickLine = new RectangleView(tickWidth, tickHeight)
            {
                BackgroundColor = ForegroundColor
            };

            fourthRowStackView.AddArrangedSubview(_firstUsTickLine);
            fourthRowStackView.AddArrangedSubview(_usScaleLine);
            fourthRowStackView.AddArrangedSubview(_secondUsTickLine);

            // ==========================================================================
            // Fifth row - placeholder, imperial numeric text, imperial unit text
            // ==========================================================================
            var fifthRowStackView = new UIStackView()
            {
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Leading,
                Distribution = UIStackViewDistribution.Fill,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Spacing = 0
            };

            var usWidthPlaceholder = new UIView();

            fifthRowStackView.AddArrangedSubview(usWidthPlaceholder);
            fifthRowStackView.AddArrangedSubview(_usValue);
            fifthRowStackView.AddArrangedSubview(_usUnit);

            // Add all scalebar rows to the root stack view
            _rootStackView.AddArrangedSubview(firstRowStackView);
            _rootStackView.AddArrangedSubview(secondRowStackView);
            _rootStackView.AddArrangedSubview(thirdRowStackView);
            _rootStackView.AddArrangedSubview(fourthRowStackView);
            _rootStackView.AddArrangedSubview(fifthRowStackView);

            AddSubview(_rootStackView);

            // Anchor the root stack view to the bottom left of the view
            _rootStackView.LeadingAnchor.ConstraintEqualTo(LeadingAnchor).Active = true;
            _rootStackView.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active   = true;

            // Set up constraints to resize scalebar components when scale line resizes
            metricWidthPlaceholder.WidthAnchor.ConstraintEqualTo(_metricScaleLine.WidthAnchor).Active       = true;
            metricWidthPlaceholder.HeightAnchor.ConstraintEqualTo(_firstMetricTickLine.HeightAnchor).Active = true;
            usWidthPlaceholder.WidthAnchor.ConstraintEqualTo(_usScaleLine.WidthAnchor).Active = true;
            usWidthPlaceholder.HeightAnchor.ConstraintEqualTo(_usValue.HeightAnchor).Active   = true;

            InvalidateIntrinsicContentSize();
        }
コード例 #14
0
        private void InitializeImpl()
        {
            if (DesignTime.IsDesignMode)
            {
                // Add placeholder for design-time
                // Set background to light gray
                Layer.BackgroundColor = UIColor.FromRGBA(230, 230, 230, 255).CGColor;

                // Add "Time Slider" label
                var label = new UILabel()
                {
                    Text = "Time Slider",
                    Font = UIFont.SystemFontOfSize(11),
                    TranslatesAutoresizingMaskIntoConstraints = false,
                };
                AddSubview(label);

                // Center the "Time Slider" label
                label.CenterXAnchor.ConstraintEqualTo(CenterXAnchor).Active = true;
                label.CenterYAnchor.ConstraintEqualTo(CenterYAnchor).Active = true;
                return;
            }

            var fullExtentLabelFormat = string.IsNullOrEmpty(FullExtentLabelFormat) ? _defaultFullExtentLabelFormat : FullExtentLabelFormat;

            FullExtentStartTimeLabel = new UILabel()
            {
                Text      = FullExtent?.StartTime.ToString(fullExtentLabelFormat) ?? string.Empty,
                Font      = UIFont.SystemFontOfSize(11),
                TextColor = FullExtentLabelColor,
            };
            AddSubview(FullExtentStartTimeLabel);

            FullExtentEndTimeLabel = new UILabel()
            {
                Text      = FullExtent?.EndTime.ToString(fullExtentLabelFormat) ?? string.Empty,
                Font      = UIFont.SystemFontOfSize(11),
                TextColor = FullExtentLabelColor,
            };
            AddSubview(FullExtentEndTimeLabel);

            PreviousButton = new DrawActionButton()
            {
                BackgroundColor   = PlaybackButtonsFill,
                BorderColor       = PlaybackButtonsStroke,
                BorderWidth       = 0.5,
                DrawContentAction = (context, button) =>
                {
                    var spacing        = 3 + button.BorderWidth;
                    var barWidth       = 3;
                    var triangleWidth  = button.Bounds.Width - spacing - barWidth;
                    var triangleHeight = button.Bounds.Height - (button.BorderWidth * 2);
                    DrawTriangle(context, triangleWidth, triangleHeight, button.BackgroundColor.CGColor, button.BorderWidth,
                                 button.BorderColor.CGColor, pointOnRight: false, left: 0, top: button.BorderWidth);

                    var barLeft = triangleWidth + spacing - button.BorderWidth;
                    DrawRectangle(context, barWidth, button.Bounds.Height, button.BackgroundColor.CGColor,
                                  button.BorderWidth, button.BorderColor.CGColor, left: barLeft);
                },
            };
            PreviousButton.TouchUpInside += (o, e) => OnPreviousButtonClick();
            AddSubview(PreviousButton);

            NextButton = new DrawActionButton()
            {
                BackgroundColor   = PlaybackButtonsFill,
                BorderColor       = PlaybackButtonsStroke,
                BorderWidth       = 0.5,
                DrawContentAction = (context, button) =>
                {
                    var spacing        = 3 + button.BorderWidth;
                    var barWidth       = 3;
                    var triangleWidth  = button.Bounds.Width - spacing - barWidth;
                    var triangleHeight = button.Bounds.Height - (button.BorderWidth * 2);
                    DrawRectangle(context, barWidth, button.Bounds.Height, button.BackgroundColor.CGColor,
                                  button.BorderWidth, button.BorderColor.CGColor, left: button.BorderWidth);

                    DrawTriangle(context, triangleWidth, triangleHeight, button.BackgroundColor.CGColor, button.BorderWidth,
                                 button.BorderColor.CGColor, pointOnRight: true, left: barWidth + spacing, top: button.BorderWidth);
                },
            };
            NextButton.TouchUpInside += (o, e) => OnNextButtonClick();
            AddSubview(NextButton);

            PlayPauseButton = new DrawActionToggleButton()
            {
                BackgroundColor          = PlaybackButtonsFill,
                BorderColor              = PlaybackButtonsStroke,
                BorderWidth              = 0.5,
                DrawCheckedContentAction = (context, button) =>
                {
                    var spacing  = 4d;
                    var barWidth = 7d;
                    var left     = button.Bounds.GetMidX() - (spacing / 2) - barWidth - 2;
                    DrawRectangle(context, barWidth, button.Bounds.Height, button.BackgroundColor.CGColor, button.BorderWidth, button.BorderColor.CGColor, left);

                    left = button.Bounds.GetMidX() + (spacing / 2);
                    DrawRectangle(context, barWidth, button.Bounds.Height, button.BackgroundColor.CGColor, button.BorderWidth, button.BorderColor.CGColor, left);
                },
                DrawUncheckedContentAction = (context, button) =>
                {
                    var triangleWidth = button.Bounds.Width - button.BorderWidth;
                    DrawTriangle(context, triangleWidth, button.Bounds.Height, button.BackgroundColor.CGColor, button.BorderWidth,
                                 button.BorderColor.CGColor, pointOnRight: true, left: button.BorderWidth);
                },
            };
            PlayPauseButton.CheckedChanged += (o, e) => IsPlaying = PlayPauseButton.IsChecked;
            AddSubview(PlayPauseButton);

            var endTickWidth  = 1;
            var endTickHeight = 10;

            _startTimeTickmark = new RectangleView(endTickWidth, endTickHeight)
            {
                BackgroundColor = FullExtentStroke,
            };
            AddSubview(_startTimeTickmark);

            _endTimeTickmark = new RectangleView(endTickWidth, endTickHeight)
            {
                BackgroundColor = FullExtentStroke
            };
            AddSubview(_endTimeTickmark);

            var sliderTrackHeight = 2;

            SliderTrack = new RectangleView(100, sliderTrackHeight)
            {
                BackgroundColor = FullExtentFill,
                BorderColor     = FullExtentStroke,
                BorderWidth     = FullExtentBorderWidth,
            };
            AddSubview(SliderTrack);

            HorizontalTrackThumb = new RectangleView(100, sliderTrackHeight)
            {
                BackgroundColor = CurrentExtentFill,
                BorderColor     = FullExtentStroke,
                BorderWidth     = SliderTrack.BorderWidth,
            };
            HorizontalTrackThumb.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == nameof(RectangleView.Frame))
                {
                    HorizontalTrackThumb.Width = HorizontalTrackThumb.Frame.Width;
                }
            };

            SliderTrack.AddSubview(HorizontalTrackThumb);

            Tickmarks = new Primitives.Tickbar()
            {
                TickFill       = TimeStepIntervalTickFill,
                TickLabelColor = TimeStepIntervalLabelColor,
                ShowTickLabels = LabelMode == TimeSliderLabelMode.TimeStepInterval,
            };
            SliderTrack.AddSubview(Tickmarks);

            var thumbSize    = 36;
            var disabledSize = new CGSize(7, 16);

            MinimumThumb = new Thumb()
            {
                Width        = thumbSize,
                Height       = thumbSize,
                DisabledSize = disabledSize,
                CornerRadius = thumbSize / 2d,
                UseShadow    = true,
                Enabled      = !IsStartTimePinned,
            };
            SliderTrack.AddSubview(MinimumThumb);

            MaximumThumb = new Thumb()
            {
                Width        = thumbSize,
                Height       = thumbSize,
                DisabledSize = disabledSize,
                CornerRadius = thumbSize / 2d,
                UseShadow    = true,
                Enabled      = !IsEndTimePinned,
            };
            SliderTrack.AddSubview(MaximumThumb);

            var currentExtentLabelFormat = string.IsNullOrEmpty(CurrentExtentLabelFormat) ?
                                           _defaultCurrentExtentLabelFormat : CurrentExtentLabelFormat;

            MinimumThumbLabel = new UILabel()
            {
                Text          = CurrentExtent?.StartTime.ToString(currentExtentLabelFormat) ?? string.Empty,
                Font          = UIFont.SystemFontOfSize(11),
                TextColor     = CurrentExtentLabelColor,
                Hidden        = LabelMode != TimeSliderLabelMode.CurrentExtent,
                LineBreakMode = UILineBreakMode.Clip,
            };
            SliderTrack.AddSubview(MinimumThumbLabel);

            MaximumThumbLabel = new UILabel()
            {
                Text          = CurrentExtent?.StartTime.ToString(currentExtentLabelFormat) ?? string.Empty,
                Font          = UIFont.SystemFontOfSize(11),
                TextColor     = CurrentExtentLabelColor,
                Hidden        = LabelMode != TimeSliderLabelMode.CurrentExtent,
                LineBreakMode = UILineBreakMode.Clip,
            };
            SliderTrack.AddSubview(MaximumThumbLabel);

            // Add pan gesture recognizer to handle thumb manipulation
            var panRecognizer = new UIPanGestureRecognizer()
            {
                CancelsTouchesInView = false
            };

            panRecognizer.AddTarget(() =>
            {
                switch (panRecognizer.State)
                {
                case UIGestureRecognizerState.Began:
                    // Check whether gesture started on one of the thumbs.
                    // Use a minimum target size of 44 x 44 for hit testing.
                    var minTargetSize        = 44;
                    var minThumbHitTestFrame = ExpandFrame(MinimumThumb.Frame, minTargetSize);
                    var maxThumbHitTestFrame = ExpandFrame(MaximumThumb.Frame, minTargetSize);
                    var location             = panRecognizer.LocationInView(SliderTrack);

                    // Check if gesture is within min thumb
                    if (!IsStartTimePinned && minThumbHitTestFrame.Contains(location))
                    {
                        MinimumThumb.IsFocused = true;
                        _lastTouchLocation     = panRecognizer.LocationInView(MinimumThumb);
                    }

                    // Check if gesture is within max thumb
                    if (!IsEndTimePinned && maxThumbHitTestFrame.Contains(location))
                    {
                        MaximumThumb.IsFocused = true;
                        _lastTouchLocation     = panRecognizer.LocationInView(MaximumThumb);
                    }

                    // TODO: Allow dragging middle thumb?
                    // else if (HorizontalTrackThumb.Frame.Contains(location))
                    // {
                    //   _isHorizontalThumbFocused = true;
                    //   _lastTouchLocation = panRecognizer.LocationInView(HorizontalTrackThumb);
                    // }
                    break;

                case UIGestureRecognizerState.Changed:
                    if (!MinimumThumb.IsFocused && !MaximumThumb.IsFocused && !(MinimumThumb.IsFocused && IsStartTimePinned) && !(MaximumThumb.IsFocused && IsEndTimePinned))
                    {
                        return;
                    }

                    UIView trackedView = null;
                    if (MinimumThumb.IsFocused && MaximumThumb.IsFocused)
                    {
                        // Gesture was within both min and max thumb, so let the direction of the gesture determine which thumb should be dragged
                        var maxThumbTranslateX = panRecognizer.LocationInView(MaximumThumb).X - _lastTouchLocation.X;
                        if (maxThumbTranslateX < 0)
                        {
                            // Gesture is moving thumb toward the min, so put focus on min thumb
                            trackedView            = MinimumThumb;
                            MaximumThumb.IsFocused = false;
                        }
                        else
                        {
                            // Gesture is moving thumb toward the max, so put focus on min thumb
                            trackedView            = MaximumThumb;
                            MinimumThumb.IsFocused = false;
                        }
                    }
                    else if (MinimumThumb.IsFocused)
                    {
                        trackedView = MinimumThumb;
                    }
                    else if (MaximumThumb.IsFocused)
                    {
                        trackedView = MaximumThumb;
                    }

                    var currentLocation = panRecognizer.LocationInView(trackedView);
                    var translateX      = currentLocation.X - _lastTouchLocation.X;

                    if (MinimumThumb.IsFocused)
                    {
                        OnMinimumThumbDrag(translateX);
                    }

                    if (MaximumThumb.IsFocused)
                    {
                        OnMaximumThumbDrag(translateX);
                    }

                    // TODO: Allow dragging middle thumb?
                    // if (_isHorizontalThumbFocused)
                    // OnCurrentExtentThumbDrag(translateX);
                    break;

                case UIGestureRecognizerState.Ended:
                case UIGestureRecognizerState.Cancelled:
                case UIGestureRecognizerState.Failed:
                    MinimumThumb.IsFocused = false;
                    MaximumThumb.IsFocused = false;
                    OnDragCompleted();
                    break;
                }
            });
            AddGestureRecognizer(panRecognizer);

            PositionTickmarks();
            ApplyLabelMode(LabelMode);
        }
コード例 #15
0
ファイル: MainActivity.cs プロジェクト: asafs/imagegame
        private void ImageViewOnTouch(object sender, View.TouchEventArgs touchEventArgs)
        {
            MotionEvent motionEvent = touchEventArgs.Event;

            var imageView = (ImageView)sender;

            TouchLocation currentPoint = TouchLocation.FromMotion(imageView, motionEvent);

            switch (motionEvent.ActionMasked)
            {
            case MotionEventActions.Down:
                if (_currentRectangleView != null)
                {
                    _inMoveState = motionEvent.PointerCount == 1 &&
                                   _currentRectangleView.InRect(currentPoint.ScreenX, currentPoint.ScreenY);

                    var scaleListener = new MyOnScaleGestureListener(this.UpdateRectSize, _currentRectangleView.InternalRect);
                    _scaleGestureDetector = new ScaleGestureDetector(this, scaleListener);
                }

                break;

            case MotionEventActions.Move:
                if (_currentRectangleView != null)
                {
                    if (_inMoveState)
                    {
                        _currentRectangleView?.MoveCenter(touchEventArgs.Event.RawX, touchEventArgs.Event.RawY);
                        _label.Text = $"Moving center to {currentPoint}";
                    }
                    else
                    {
                        _scaleGestureDetector.OnTouchEvent(motionEvent);
                    }
                }

                break;

            case MotionEventActions.Up:
                if (_inAddSectionMode && _currentRectangleView == null)
                {
                    var drawingRect = new Rect();
                    imageView.GetDrawingRect(drawingRect);

                    double defaultWidth  = imageView.Width * 0.10;
                    double defaultHeight = imageView.Height * 0.10;
                    _currentRectangleView = new RectangleView(this,
                                                              RectangleView.CreateRect(
                                                                  currentPoint.ScreenX,
                                                                  currentPoint.ScreenY,
                                                                  defaultWidth,
                                                                  defaultHeight),
                                                              drawingRect);

                    _imageLayout.AddView(_currentRectangleView);
                }

                _inMoveState = false;
                break;
            }
        }
コード例 #16
0
 public RectangleModel()
 {
     Page = new RectangleView(this);
 }