//=================================================================== // ヒットテスト //=================================================================== /// ヒットテスト public static bool TryHitTest(Profile profile, RelativePoint mousePoint, out LayoutElement hitElement, out HitModes hitMode) { // 計算途中の結果をまとめるスタック var moveStack = new Stack <LayoutElement>(); var sizeStack = new Stack <LayoutElement>(); // レイアウト要素を線形探索 foreach (var layoutElement in profile.LayoutElements) { // ヒットテスト対象外判定 var maximumBoundRect = HitTest.GetMaximumBoundRect(layoutElement); if (!maximumBoundRect.Contains(mousePoint)) { continue; } var moveRect = HitTest.GetMoveRect(layoutElement); if (moveRect.Contains(mousePoint)) { // 移動用領域 moveStack.Push(layoutElement); } else { // 移動用領域でない=サイズ変更用領域 sizeStack.Push(layoutElement); } } // sizeStack優先 foreach (var layoutElement in sizeStack) { // 見つかり次第終了 hitMode = HitTest.GetHitMode(layoutElement, mousePoint); hitElement = layoutElement; return(true); } // moveStack foreach (var layoutElement in moveStack) { // 見つかり次第終了 hitMode = HitModes.Move; hitElement = layoutElement; return(true); } hitElement = null; hitMode = HitModes.Neutral; return(false); }
//=================================================================== // 動作 //=================================================================== /// 開始 public void Start(LayoutElement target, HitModes hitMode, RelativePoint mousePoint, SnapGuide snapGuide) { this.target = target; this.hitMode = hitMode; this.mouseOffset = new RelativeMouseOffset(target, mousePoint); this.originalLTRB = new RelativeLTRB(target.BoundRelativeLeft, target.BoundRelativeTop, target.BoundRelativeRight, target.BoundRelativeBottom); this.snapGuide = snapGuide; this.lastUpdateControl = Environment.TickCount; this.MousePoint = mousePoint; this.ShouldUpdateControl = false; }
//=================================================================== // ヒットテスト //=================================================================== /// ヒットテスト public static bool TryHitTest(Profile profile, RelativePoint mousePoint, out LayoutElement hitElement, out HitModes hitMode) { // 計算途中の結果をまとめるスタック var moveStack = new Stack<LayoutElement>(); var sizeStack = new Stack<LayoutElement>(); // レイアウト要素を線形探索 foreach (var layoutElement in profile.LayoutElements) { // ヒットテスト対象外判定 var maximumBoundRect = HitTest.GetMaximumBoundRect(layoutElement); if (!maximumBoundRect.Contains(mousePoint)) continue; var moveRect = HitTest.GetMoveRect(layoutElement); if (moveRect.Contains(mousePoint)) { // 移動用領域 moveStack.Push(layoutElement); } else { // 移動用領域でない=サイズ変更用領域 sizeStack.Push(layoutElement); } } // sizeStack優先 foreach (var layoutElement in sizeStack) { // 見つかり次第終了 hitMode = HitTest.GetHitMode(layoutElement, mousePoint); hitElement = layoutElement; return true; } // moveStack foreach (var layoutElement in moveStack) { // 見つかり次第終了 hitMode = HitModes.Move; hitElement = layoutElement; return true; } hitElement = null; hitMode = HitModes.Neutral; return false; }
/// フィールドを初期化 private void Clear() { this.target = null; this.hitMode = HitModes.Neutral; this.mouseOffset = null; this.originalLTRB = null; this.snapGuide = null; this.lastUpdateControl = 0; this.MousePoint = null; this.ShouldUpdateControl = false; }