private void OnTouchBegan(object sender, TouchEventArgs args) { if (TouchBegan != null) { TouchBegan(sender, args); } }
private void OnTouchCancelled(object sender, TouchEventArgs args) { if (TouchCancelled != null) { TouchCancelled(sender, args); } }
protected override void OnTouchDown(TouchEventArgs args) { base.OnTouchDown(args); }
void TouchTarget_TouchTapGesture(object sender, TouchEventArgs e) { //tapped = true; }
protected override void OnTouchLeave(TouchEventArgs e) { if (e.RelatedActor == null || !e.RelatedActor.IsDescendentOf(this)) OverNode = null; base.OnTouchLeave(e); }
private void TouchLeaveHandler(Actor sender, TouchEventArgs e) { if (e.Pointer == -1 && !_cancelled) _over = false; }
private void TouchDraggedHandler(Actor sender, TouchEventArgs e) { if (e.Pointer != PressedPointer || _cancelled) return; Vector2 position = e.GetPosition(sender); _pressed = IsOverActor(sender, position.X, position.Y); if (_pressed && e.Pointer == 0 && Button != -1 && !Mouse.GetState().IsButtonPressed(Button)) _pressed = false; if (!_pressed) InvalidateTapSquare(); }
public void TouchUp(object sender, TouchEventArgs e) { _inputProcessor.TouchUp(sender, e); }
public void TouchTapGesture(object sender, TouchEventArgs e) { TouchPoint t = e.TouchPoint; if (t.IsFingerRecognized) { Tuple<TouchPoint, long> currentTap = new Tuple<TouchPoint, long>(t, DateTime.Now.Ticks); bool doubleTap = wasDoubleTap(this.previousTap, currentTap); if (doubleTap) { //Faketap detects if double tap was triggered by tangible bool fakeTap = wasFakeTap(t); if (!fakeTap) { Tuple<SolidThing, Quaternion, float, Vector3> brick = getTouchedBlock(t.X, t.Y); //If we touched a block if (brick != null) { //If we are currently holding a block if (selectedBrick != null) { //if we touched the same block we want to deselct it if (selectedBrick.Item1.Equals(brick.Item1)) { selectedBrick.Item1.IsWeightless = false; selectedBrick.Item1.IsActive = true; selectedBrick.Item1._isSelected = false; selectedBrick = null; } //If we touched a new block with an block currently selected. else { selectedBrick.Item1.IsWeightless = false; selectedBrick.Item1._isSelected = false; selectedBrick.Item1.IsActive = true; selectedBrick = brick; selectedBrick.Item1.IsWeightless = true; selectedBrick.Item1._isSelected = true; } } //If no block selected then select this one else { selectedBrick = brick; selectedBrick.Item1.IsWeightless = true; selectedBrick.Item1._isSelected = true; } } this.previousTap = null; } } else { this.previousTap = currentTap; } } else { if (!t.IsFingerRecognized && !t.IsTagRecognized) { if (t.MajorAxis > 30) { Tuple<TouchPoint, long> currentTap = new Tuple<TouchPoint, long>(t, DateTime.Now.Ticks); bool doubleTap = wasDoubleTap(this.previousTap, currentTap); if (doubleTap) { //If we are currently holding a block if (selectedBrick != null) { selectedBrick.Item1.IsWeightless = false; selectedBrick.Item1.IsActive = true; selectedBrick.Item1._isSelected = false; selectedBrick = null; } } } } } }
public void TouchMove(object sender, TouchEventArgs e) { TouchPoint t = e.TouchPoint; long currentTime = Timestamp; if (t.IsFingerRecognized) { //MOVING BLOCKS if (t.Id == this.holdingTouchPointID && !rotateOrZoom) { try { rotateOrZoom = false; Segment s; s.P1 = _game.GraphicsDevice.Viewport.Unproject(new Vector3(t.X, t.Y, 0f), _viewManager.Projection, _viewManager.DefaultView, Matrix.Identity); s.P2 = _game.GraphicsDevice.Viewport.Unproject(new Vector3(t.X, t.Y, 1f), _viewManager.Projection, _viewManager.DefaultView, Matrix.Identity); Vector3 diff, point; Vector3.Subtract(ref s.P2, ref s.P1, out diff); Vector3.Multiply(ref diff, this.selectedBrick.Item3, out diff); //TODO FIX NULL REFERENCE(selectedblock) Vector3.Add(ref s.P1, ref diff, out point); Vector3 position = Vector3.Add(point, this.selectedBrick.Item4); selectedBrick.Item1.SetVelocity(Vector3.Zero, Vector3.Zero); selectedBrick.Item1.SetWorld(position, selectedBrick.Item2); selectedBrick.Item1.IsActive = true; } catch (NullReferenceException) { //IDK why it was throwing null here. } } } }
public void TouchDown(object sender, TouchEventArgs e) { TouchPoint t = e.TouchPoint; //bool fakeTap = wasFakeTap(t); //if (t.IsFingerRecognized && !fakeTap)ake if (t.IsFingerRecognized) { this.activeTouchPoints.Add(t.Id, t); Tuple<SolidThing, Quaternion, float, Vector3> touchedBlock = getTouchedBlock(t.X, t.Y); //Conditions for camera movement if (selectedBrick == null || touchedBlock == null || !selectedBrick.Item1.Equals(touchedBlock.Item1)) { this.manipulationProcessor.CompleteManipulation(Timestamp); if (selectedBrick != null) { this.selectedBrick.Item1.LinearVelocity = Vector3.Zero; } } //Else we are moving a block (or possibly selecting it) else { if (this.selectedBrick != null && touchedBlock.Item1.Equals(this.selectedBrick.Item1)) { this.selectedBrick = touchedBlock; this.holdingTouchPointIds.Add(t.Id); this.holdingTouchPointID = t.Id; } } } else if (!t.IsTagRecognized) { Tuple<SolidThing, Quaternion, float, Vector3> brick = getTouchedBlock(t.X, t.Y); if (selectedBrick == null && brick != null) { selectedBrick = brick; selectedBrick.Item1.IsWeightless = true; selectedBrick.Item1._isSelected = true; begin = Timestamp; } } }
/// <summary> /// Handling aller Eingaben, Mausbewegungen und Updaten aller Screens und Controls. /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { if (Game.IsActive) { #region Mouse Interaction if (MouseEnabled) { MouseState mouse = Mouse.GetState(); // Mausposition anhand des Mouse Modes ermitteln Point mousePosition = mouse.Position; if (MouseMode == MouseMode.Captured) mousePosition = new Point( mousePosition.X - (GraphicsDevice.Viewport.Width / 2), mousePosition.Y - (GraphicsDevice.Viewport.Height / 2)); // Mouse Move if (mousePosition != lastMousePosition) { MouseEventArgs moveArgs = new MouseEventArgs() { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition, }; root.InternalMouseMove(moveArgs); if (!moveArgs.Handled && MouseMove != null) MouseMove(moveArgs); // Start Drag Handling if (mouse.LeftButton == ButtonState.Pressed && DraggingArgs == null) { DraggingArgs = new DragEventArgs() { GlobalPosition = mousePosition, LocalPosition = mousePosition, }; draggingId = null; root.InternalStartDrag(DraggingArgs); if (!DraggingArgs.Handled && StartDrag != null) StartDrag(DraggingArgs); } // Drop move if (mouse.LeftButton == ButtonState.Pressed && DraggingArgs != null && draggingId == null && DraggingArgs.Handled) { DragEventArgs args = new DragEventArgs() { GlobalPosition = mousePosition, LocalPosition = mousePosition, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalDropMove(args); if (!args.Handled && DropMove != null) DropMove(args); } } // Linke Maustaste if (mouse.LeftButton == ButtonState.Pressed) { if (!lastLeftMouseButtonPressed) { MouseEventArgs leftDownArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; // Linke Maustaste wurde neu gedrückt root.InternalLeftMouseDown(leftDownArgs); if (!leftDownArgs.Handled && LeftMouseDown != null) LeftMouseDown(leftDownArgs); } lastLeftMouseButtonPressed = true; } else { if (lastLeftMouseButtonPressed) { // Handle Drop if (DraggingArgs != null && DraggingArgs.Handled) { DragEventArgs args = new DragEventArgs() { GlobalPosition = mousePosition, LocalPosition = mousePosition, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalEndDrop(args); if (!args.Handled && EndDrop != null) EndDrop(args); } // Discard Dragging Infos DraggingArgs = null; draggingId = null; // Linke Maustaste wurde losgelassen MouseEventArgs leftClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalLeftMouseClick(leftClickArgs); if (!leftClickArgs.Handled && LeftMouseClick != null) LeftMouseClick(leftClickArgs); if (lastLeftClick.HasValue && gameTime.TotalGameTime - lastLeftClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Left Click MouseEventArgs leftDoubleClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalLeftMouseDoubleClick(leftDoubleClickArgs); if (!leftDoubleClickArgs.Handled && LeftMouseDoubleClick != null) LeftMouseDoubleClick(leftDoubleClickArgs); lastLeftClick = null; } else { lastLeftClick = gameTime.TotalGameTime; } // Mouse Up MouseEventArgs leftUpArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalLeftMouseUp(leftUpArgs); if (!leftUpArgs.Handled && LeftMouseUp != null) LeftMouseUp(leftUpArgs); } lastLeftMouseButtonPressed = false; } // Rechte Maustaste if (mouse.RightButton == ButtonState.Pressed) { if (!lastRightMouseButtonPressed) { // Rechte Maustaste neu gedrückt MouseEventArgs rightDownArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseDown(rightDownArgs); if (!rightDownArgs.Handled && RightMouseDown != null) RightMouseDown(rightDownArgs); } lastRightMouseButtonPressed = true; } else { if (lastRightMouseButtonPressed) { // Rechte Maustaste losgelassen MouseEventArgs rightClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseClick(rightClickArgs); if (!rightClickArgs.Handled && RightMouseClick != null) RightMouseClick(rightClickArgs); if (lastRightClick.HasValue && gameTime.TotalGameTime - lastRightClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Left Click MouseEventArgs rightDoubleClickArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseDoubleClick(rightDoubleClickArgs); if (!rightDoubleClickArgs.Handled && RightMouseDoubleClick != null) RightMouseDoubleClick(rightDoubleClickArgs); lastRightClick = null; } else { lastRightClick = gameTime.TotalGameTime; } MouseEventArgs rightUpArgs = new MouseEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition }; root.InternalRightMouseUp(rightUpArgs); if (!rightUpArgs.Handled && RightMouseUp != null) RightMouseUp(rightUpArgs); } lastRightMouseButtonPressed = false; } // Mousewheel if (lastMouseWheelValue != mouse.ScrollWheelValue) { int diff = (mouse.ScrollWheelValue - lastMouseWheelValue); MouseScrollEventArgs scrollArgs = new MouseScrollEventArgs { MouseMode = MouseMode, GlobalPosition = mousePosition, LocalPosition = mousePosition, Steps = diff }; root.InternalMouseScroll(scrollArgs); if (!scrollArgs.Handled && MouseScroll != null) MouseScroll(scrollArgs); lastMouseWheelValue = mouse.ScrollWheelValue; } // Potentieller Positionsreset if (MouseMode == MouseMode.Free) { lastMousePosition = mouse.Position; } else if (mousePosition.X != 0 || mousePosition.Y != 0) { Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); } } #endregion #region Keyboard Interaction if (KeyboardEnabled) { KeyboardState keyboard = Keyboard.GetState(); bool shift = keyboard.IsKeyDown(Keys.LeftShift) | keyboard.IsKeyDown(Keys.RightShift); bool ctrl = keyboard.IsKeyDown(Keys.LeftControl) | keyboard.IsKeyDown(Keys.RightControl); bool alt = keyboard.IsKeyDown(Keys.LeftAlt) | keyboard.IsKeyDown(Keys.RightAlt); KeyEventArgs args; foreach (Keys key in Enum.GetValues(typeof(Keys))) { if (keyboard.IsKeyDown(key)) { if (!pressedKeys.ContainsKey(key)) { // Taste ist neu args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyDown(args); if (!args.Handled) { if (KeyDown != null) KeyDown(args); } args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyPress(args); pressedKeys.Add(key, gameTime.TotalGameTime.TotalMilliseconds + 500); // Spezialfall Tab-Taste (falls nicht verarbeitet wurde) if (key == Keys.Tab && !args.Handled) { if (shift) root.InternalTabbedBackward(); else root.InternalTabbedForward(); } } else { // Taste ist immernoch gedrückt if (pressedKeys[key] <= gameTime.TotalGameTime.TotalMilliseconds) { args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyPress(args); if (!args.Handled) { if (KeyPress != null) KeyPress(args); } pressedKeys[key] = gameTime.TotalGameTime.TotalMilliseconds + 50; } } } else { if (pressedKeys.ContainsKey(key)) { // Taste losgelassen args = new KeyEventArgs() { Key = key, Shift = shift, Ctrl = ctrl, Alt = alt }; root.InternalKeyUp(args); pressedKeys.Remove(key); if (!args.Handled) { if (KeyUp != null) KeyUp(args); } } } } } #endregion #region Touchpanel Interaction if (TouchEnabled) { TouchCollection touchPoints = TouchPanel.GetState(); foreach (var touchPoint in touchPoints) { Point point = touchPoint.Position.ToPoint(); TouchEventArgs args = new TouchEventArgs() { TouchId = touchPoint.Id, GlobalPosition = point, LocalPosition = point }; switch (touchPoint.State) { case TouchLocationState.Pressed: root.InternalTouchDown(args); if (!args.Handled && TouchDown != null) TouchDown(args); break; case TouchLocationState.Moved: // Touch Move root.InternalTouchMove(args); if (!args.Handled && TouchMove != null) TouchMove(args); // Start Dragging if (DraggingArgs == null) { DraggingArgs = new DragEventArgs() { GlobalPosition = point, LocalPosition = point, }; draggingId = touchPoint.Id; root.InternalStartDrag(DraggingArgs); if (!DraggingArgs.Handled && StartDrag != null) StartDrag(DraggingArgs); } // Drop move if (DraggingArgs != null && draggingId == touchPoint.Id && DraggingArgs.Handled) { DragEventArgs moveArgs = new DragEventArgs() { GlobalPosition = point, LocalPosition = point, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalDropMove(moveArgs); if (!args.Handled && DropMove != null) DropMove(moveArgs); } break; case TouchLocationState.Released: // Handle Drop if (DraggingArgs != null && draggingId == touchPoint.Id && DraggingArgs.Handled) { DragEventArgs dropArgs = new DragEventArgs() { GlobalPosition = point, LocalPosition = point, Content = DraggingArgs.Content, Icon = DraggingArgs.Icon, Sender = DraggingArgs.Sender }; root.InternalEndDrop(dropArgs); if (!args.Handled && EndDrop != null) EndDrop(dropArgs); } // Discard Dragging Infos DraggingArgs = null; draggingId = null; // Linke Maustaste wurde losgelassen TouchEventArgs tapArgs = new TouchEventArgs { TouchId = touchPoint.Id, GlobalPosition = point, LocalPosition = point }; root.InternalTouchTap(tapArgs); if (!tapArgs.Handled && TouchTap != null) TouchTap(tapArgs); if (lastTouchTap.HasValue && gameTime.TotalGameTime - lastLeftClick.Value < TimeSpan.FromMilliseconds(DoubleClickDelay)) { // Double Tap TouchEventArgs doubleTapArgs = new TouchEventArgs { TouchId = touchPoint.Id, GlobalPosition = point, LocalPosition = point }; root.InternalTouchDoubleTap(doubleTapArgs); if (!doubleTapArgs.Handled && TouchDoubleTap != null) TouchDoubleTap(doubleTapArgs); lastTouchTap = null; } else { lastTouchTap = gameTime.TotalGameTime; } root.InternalTouchUp(args); if (!args.Handled && TouchUp != null) TouchUp(args); break; } } } #endregion } #region Recalculate Sizes if (root.HasInvalidDimensions()) { Point available = new Point(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); Point required = root.GetExpectedSize(available); root.SetActualSize(available); } root.Update(gameTime); #endregion #region Form anpassen string screentitle = ActiveScreen != null ? ActiveScreen.Title : string.Empty; string windowtitle = TitlePrefix + (string.IsNullOrEmpty(screentitle) ? "" : " - " + screentitle); if (Game.Window != null && Game.Window.Title != windowtitle) Game.Window.Title = windowtitle; #endregion }
void touchTarget_TouchUp(object sender, TouchEventArgs e) { System.Diagnostics.Debug.WriteLine("Touch Up: " + e.TouchPoint.Id); }
void touchTarget_TouchTapGesture(object sender, TouchEventArgs e) { System.Diagnostics.Debug.WriteLine("Tap: " + e.TouchPoint.Id); Resources.Instance.TapDetected = true; Resources.Instance.PointerX = (int)e.TouchPoint.X; Resources.Instance.PointerY = (int)e.TouchPoint.Y; }
void touchTarget_TouchMove(object sender, TouchEventArgs e) { System.Diagnostics.Debug.WriteLine("Toutch Move"); if (currentInputMode == INPUT_MODE.SLIDE && e.TouchPoint.IsFingerRecognized) { if (touchPointForSlide != null && touchPointForSlide.Id == e.TouchPoint.Id) { float deltaX = Math.Abs(e.TouchPoint.CenterX - touchPointForSlide.CenterX); if (e.TouchPoint.CenterX - touchPointForSlide.CenterX > 0) Resources.Instance.Camera.RotateLookAt(0.0015f * deltaX, Camera.AXIS.Y); else { Resources.Instance.Camera.RotateLookAt(-0.0015f * deltaX, Camera.AXIS.Y); } } touchPointForSlide = e.TouchPoint; } }
protected override void OnTouchTap(TouchEventArgs args) { base.OnTouchTap(args); EventArgs e = new EventArgs(); OnExecuted(e); if (Executed != null) Executed(this, e); args.Handled = true; }
public void TouchTapGesture(object sender, TouchEventArgs e) { _inputProcessor.TouchTapGesture(sender, e); }
public void TouchUp(object sender, TouchEventArgs e) { TouchPoint t = e.TouchPoint; if (t.IsFingerRecognized) { holdingTouchPointIds.Remove(t.Id); //Remove touchpoint from active point lists lock (activeTouchPoints) { activeTouchPoints.Remove(t.Id); } this.manipulationProcessor.CompleteManipulation(Timestamp); if (selectedBrick != null) { this.selectedBrick.Item1.LinearVelocity = Vector3.Zero; } if (t.Id == this.holdingTouchPointID) { this.holdingTouchPointID = -1; if (this.selectedBrick != null) { this.selectedBrick.Item1.LinearVelocity = Vector3.Zero; } } } }
public void TouchTapGesture(object sender, TouchEventArgs e) { }
public void TouchUp(object sender, TouchEventArgs e) { }
private void TouchDownHandler(Actor sender, TouchEventArgs e) { if (IsPressed) return; if (e.Pointer == 0 && Button != -1 && Button != e.Button) return; _pressed = true; if (_actor.Stage != null) _actor.CaptureTouch(e.Pointer); PressedPointer = e.Pointer; PressedButton = e.Button; TouchDownX = e.StagePosition.X; TouchDownY = e.StagePosition.Y; e.Handled = true; }
void SinglePlayerContract_TouchEventHandler(object sender, TouchEventArgs e) { Vector2 ActualLocation = ScreenToWorld(e.Location); Vector2 DragStart = ScreenToWorld(e.Location + e.Direction); if (MessageBox != null) if (MessageBox.Visible) { if (MessageBox.Intersects(e.Location)) { MessageBox.Close(); } } //if (InternalPause) //{ // if (e.State == TouchStates.OnTap) // { // if (MessageBox.Intersects(ActualLocation)) // { // if (MessageBox.Visible) // { // MessageBox.Close(); // InternalPause = false; // GameScript.Pause = false; // } // } // } // return; //} if (e.State != TouchStates.OnDrag) CanDrag = true; if (e.State == TouchStates.OnDrag || e.State == TouchStates.OnTap) { foreach (Planet planet in GameManager.State.PlayerPlanets) { float Range = planet.PlanetSize * 64 + 32 * camera.Zoom; if (e.State == TouchStates.OnDrag && CanDrag) { if (Vector2.Distance(planet.Position, DragStart) <= Range) { CanDrag = false; } } if (Vector2.Distance(planet.Position, ActualLocation) <= Range) { if (!GameSelectedPlanets.Contains(planet)) { GameActions++; if (PlanetSelectedInstance.State != SoundState.Playing) { PlanetSelectedInstance.Play(); } GameSelectedPlanets.Add(planet); } } } if (CanDrag) { camera.Position -= e.Direction / camera.Zoom; Vector2 cameraWorldMin = Vector2.Transform(Vector2.Zero, Matrix.Invert(camera.Transforms)); Vector2 cameraSize = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height) / camera.Zoom; Vector2 limitWorldMin = new Vector2(0, 0); Vector2 limitWorldMax = new Vector2(Width, Height); Vector2 positionOffset = camera.Position - cameraWorldMin; camera.Position = Vector2.Clamp(cameraWorldMin, limitWorldMin, limitWorldMax - cameraSize) + positionOffset; //camera.Position = Vector2.Clamp(camera.Position, new Vector2(400, 240), new Vector2(Width-400, Height-240)); } } else if (e.State == TouchStates.OnDoubleTap) { foreach (Planet planet in GameManager.State.Planets) { GameActions++; float Range = planet.PlanetSize * 64 + 32; if (Vector2.Distance(planet.Position, ActualLocation) <= Range) { foreach (Planet selected in GameSelectedPlanets) GameManager.SendFleet(selected.Forces / 2, selected, planet); } } FleetSend.Play(); GameSelectedPlanets.Clear(); } else if (e.State == TouchStates.OnPinch) { if (Width > 800 && Height > 480) { Vector2 Old1 = e.Location - e.Direction; Vector2 Old2 = e.Location2 - e.Direction2; float newDistance = Vector2.Distance(e.Location, e.Location2); float oldDistance = Vector2.Distance(Old1, Old2); float Factor = newDistance / oldDistance; camera.Zoom *= Factor; float minZoomX = (float)GraphicsDevice.Viewport.Width / Width; float minZoomY = (float)GraphicsDevice.Viewport.Height / Height; camera.Zoom = MathHelper.Clamp(camera.Zoom, MathHelper.Max(minZoomX, minZoomY), 1f); Vector2 cameraWorldMin = Vector2.Transform(Vector2.Zero, Matrix.Invert(camera.Transforms)); Vector2 cameraSize = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height) / camera.Zoom; Vector2 limitWorldMin = new Vector2(0, 0); Vector2 limitWorldMax = new Vector2(Width, Height); Vector2 positionOffset = camera.Position - cameraWorldMin; camera.Position = Vector2.Clamp(cameraWorldMin, limitWorldMin, limitWorldMax - cameraSize) + positionOffset; } } else if (e.State == TouchStates.OnFlick && CanDrag) { cameraVelocity = -e.Direction / 100; } }
private void TouchEnterHandler(Actor sender, TouchEventArgs e) { if (e.Pointer == -1 && !_cancelled) _over = true; }
void contract_TouchEventHandler(object sender, TouchEventArgs e) { if (Manager.SelectedMenu == "Exit") { if (e.State == TouchStates.OnDoubleTap) Exit(); return; } if (e.State == TouchStates.OnFlick) { offsetVelocity = e.Direction / 100; return; } #region Process Menu Input if (Manager.SelectedMenu == "Base" && textManager.Height > 320 && e.State == TouchStates.OnDrag) { textSettings.Offset = Vector2.Clamp(textSettings.Offset + new Vector2(0, e.Direction.Y), new Vector2(67, 54 - (textManager.Height - 320)), new Vector2(67, 54)); } else if (Manager.SelectedMenu == "Epilogue" && e.State == TouchStates.OnDrag) { (Manager.Menues["Epilogue"] as EpilogueMenu).MoveText(e); } else if (Manager.SelectedMenu == "Strategic") { Rectangle intRect = new Rectangle((int)e.Location.X, (int)e.Location.Y, 5, 5); Rectangle intLoc = new Rectangle((int)SciencePosition.X, (int)SciencePosition.Y, ScienceRectangle.Width, ScienceRectangle.Height); Draging = false; if (intRect.Intersects(intLoc)) { if (e.State == TouchStates.OnDrag && ScienceAnimator.State == AnimatorState.Stoped && ScienceAnimatorReversed.State == AnimatorState.Stoped) { Draging = true; SciencePosition += e.Direction; if (SciencePosition.X < 27) SciencePosition.X = 27; else if (SciencePosition.X > 462) SciencePosition.X = 462; if (SciencePosition.Y < 8) SciencePosition.Y = 8; else if (SciencePosition.Y > 319) SciencePosition.Y = 319; ScienceRectangle.Width = 512 - (int)SciencePosition.X; ScienceRectangle.Height = (int)SciencePosition.Y - 8 + 103; ScienceRectangle.Y = 305 - ((int)SciencePosition.Y - 8); } } else if (!ScienceLock) { GalaxyImage.Offset = Vector2.Clamp(GalaxyImage.Offset + e.Direction * 0.5f, new Vector2(-224 - 310, -480), new Vector2(0, 0)); foreach (Control control in Manager.Menues["Strategic"].Controls) { HexControl ab = control as HexControl; if (ab != null) { ab.Offset = GalaxyImage.Offset; } } } } else if (Manager.SelectedMenu == "Mission") { if (Manager.Menues["Mission"].Blocking) return; MissionOffset = Vector2.Clamp(MissionOffset + new Vector2(e.Direction.X, 0), new Vector2(-(Manager.Menues["Mission"].Controls.Count - 3) * 240 + 400, 0), new Vector2(0, 0)); foreach (Control control in Manager.Menues["Mission"].Controls) { TexturedButton ab = control as TexturedButton; if (ab != null) { ab.Offset = MissionOffset; } } } #endregion }
private void TouchUpHandler(Actor sender, TouchEventArgs e) { if (e.Pointer == PressedPointer) { if (!_cancelled) { Vector2 position = e.GetPosition(sender); bool touchUpOver = IsOverActor(sender, position.X, position.Y); if (touchUpOver && e.Pointer == 0 && Button != -1 && e.Button != Button) touchUpOver = false; if (touchUpOver) { long time = DateTime.Now.Ticks * 100; if (time - _lastTapTime > _tapCountInterval) TapCount = 0; TapCount = TapCount + 1; _lastTapTime = time; if (ClickHandler != null) ClickHandler(e); } if (_actor.Stage != null) _actor.ReleaseTouchCapture(e.Pointer); else if (e.Stage != null) e.Stage.ReleaseTouchCapture(e.Pointer); } _pressed = false; PressedPointer = -1; PressedButton = -1; _cancelled = false; } }
protected override void OnTouchDown(TouchEventArgs e) { Vector2 position = e.GetPosition(this); TreeNode node = NodeAt(position.Y); if (node == null) return; if (node != NodeAt(position.Y)) return; KeyboardState keystate = Keyboard.GetState(); bool shiftPressed = keystate.IsKeyDown(Keys.LeftShift) || keystate.IsKeyDown(Keys.RightShift); bool ctrlPressed = keystate.IsKeyDown(Keys.LeftControl) || keystate.IsKeyDown(Keys.RightControl); if (MultiSelect && _selectedNodes.Count > 0 && shiftPressed) { float low = _selectedNodes.First().Actor.Y; float high = node.Actor.Y; _selectionChanger.Begin(_selectedNodes); if (!ctrlPressed) _selectionChanger.UnselectAll(); if (low > high) SelectNodes(_rootNodes, high, low); else SelectNodes(_rootNodes, low, high); _selectionChanger.End(); return; } if (!MultiSelect || !ctrlPressed) { if (Children.Count > 0) { float rowX = node.Actor.X; if (node.Icon != null) rowX -= IconSpacing + node.Icon.MinWidth; float indent = 0; if (node.Children == null || node.Children.Count == 0) indent = rowX; else { TreeNode parent = node.Parent; while (parent != null) { indent += _indentSpacing; parent = parent.Parent; } } if (position.X > indent && position.X < rowX) { node.IsExpanded = !node.IsExpanded; return; } } if (!node.IsSelectable) return; bool unselect = ToggleSelect && _selectedNodes.Count == 1 && _selectedNodes.Contains(node); _selectionChanger.Begin(_selectedNodes); _selectionChanger.UnselectAll(); if (!unselect) _selectionChanger.Select(node); _selectionChanger.End(); return; } else if (!node.IsSelectable) return; _selectionChanger.Begin(_selectedNodes); _selectionChanger.Select(node); _selectionChanger.End(); base.OnTouchDown(e); }