Exemplo n.º 1
0
        public SelectRectangleViewModel()
        {
            MouseLeftDownPoint       = new ReactivePropertySlim <RoixBorderPoint>(mode: ReactivePropertyMode.None);
            MouseLeftUpPoint         = new ReactivePropertySlim <RoixBorderPoint>(mode: ReactivePropertyMode.None);
            MouseMovePoint           = new ReactivePropertySlim <RoixBorderPoint>();
            ViewBorderSize           = new ReactivePropertySlim <RoixSize>(mode: ReactivePropertyMode.DistinctUntilChanged);
            SelectedRectangleToModel = new ReactivePropertySlim <RoixIntRect>();

            var imageSourceSize = MyImage.ToRoixIntSize();

            // 画像座標系の選択枠(これを基準に管理する) マウス操作中に枠を更新 + 操作完了時に枠位置を通知する
            var selectedRectangleOnImage = MouseMovePoint
                                           .Select(latestPoint => (startPoint: MouseLeftDownPoint.Value, latestPoint))
                                           .Where(x => x.startPoint != x.latestPoint)
                                           .SkipUntil(MouseLeftDownPoint.ToUnit())
                                           .TakeUntil(MouseLeftUpPoint.ToUnit())
                                           .Finally(() =>
            {
                var(startPoint, latestPoint) = (MouseLeftDownPoint.Value, MouseLeftUpPoint.Value);
                if (startPoint == default || latestPoint == default || startPoint == latestPoint)
                {
                    return;
                }

                SelectedRectangleToModel.Value = RoixBorderIntRect.Create(startPoint, latestPoint, imageSourceSize).Roi;
            })
                                           .Repeat()
                                           .Select(x => RoixBorderIntRect.Create(x.startPoint, x.latestPoint, imageSourceSize))
                                           .ToReadOnlyReactivePropertySlim();

            // View座標系の選択枠
            SelectedRectangle = selectedRectangleOnImage
                                .CombineLatest(ViewBorderSize, (rect, border) => rect.ConvertToNewBorder(border).Roi)
                                .ToReadOnlyReactivePropertySlim();
        }
Exemplo n.º 2
0
        public SelectFixRectViewModel()
        {
            MouseLeftDownPoint = new ReactivePropertySlim <RoixBorderPoint>(mode: ReactivePropertyMode.None);
            MouseMovePoint     = new ReactivePropertySlim <RoixBorderPoint>();
            ViewBorderSize     = new ReactivePropertySlim <RoixSize>(mode: ReactivePropertyMode.DistinctUntilChanged);

            var imageSourceSize = MyImage.ToRoixIntSize();

            // 画像座標系の固定サイズ枠(これを基準に管理する) 右クリックで固定サイズの枠を描画する
            var clickedFixedRectangleOnImage = MouseLeftDownPoint
                                               .Where(border => border.Border.IsNotZero)
                                               .Select(borderPointOnView =>
            {
                var length         = 100;
                var rectBorderSize = new RoixIntSize(length).ToRoixBorder(imageSourceSize);
                var rectHalfSize   = rectBorderSize.Size / 2d;

                var newCenterPoint = borderPointOnView.ConvertToNewBorderInt(imageSourceSize);
                var newRect        = new RoixBorderIntRect(newCenterPoint - (RoixIntVector)rectHalfSize, rectBorderSize);
                return(newRect.GetClippedBorderIntRect(isPointPriority: false));
            })
                                               .ToReadOnlyReactivePropertySlim();

            // Model通知
            ClickedFixedRectangleToModel = clickedFixedRectangleOnImage
                                           .Where(border => border.Border.IsNotZero)
                                           .Select(borderRectOnView => borderRectOnView.Roi)
                                           .ToReadOnlyReactivePropertySlim();

            // View座標系の選択枠
            ClickedFixedRectangle = clickedFixedRectangleOnImage
                                    .CombineLatest(ViewBorderSize, (rect, border) => rect.ConvertToNewBorder(border).Roi)
                                    .ToReadOnlyReactivePropertySlim();
        }