public void Update(GameTime gameTime, Dictionary dictionary) { var mouseState = Mouse.GetState(); SwipeKeyboard.GetBoundingBox(_centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard); Rectangle interactRect = VirtualCoords.ComputePixelRect(cornerKeyboard - new Vector2(CONSTELLATION_WIDTH * 0.01f), sizeKeyboard + new Vector2(CONSTELLATION_WIDTH * 0.02f)); if (interactRect.Contains(mouseState.Position)) // TODO: or intersects word rect { _selectionInterpolation = _selectionInterpolation + (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectionInterpolation = Math.Min(1f, _selectionInterpolation); } else { _selectionInterpolation = _selectionInterpolation - (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectionInterpolation = Math.Max(0f, _selectionInterpolation); } _swipeLine.Update(gameTime, _centerPosition); _associatedWord.ActiveWord = dictionary.ClosestWordToSwipePattern(_swipeLine.HandlePositionsRelative); _associatedWord.UpdateConstallationWord(_selectionInterpolation); }
public void Update() { var mouseState = Mouse.GetState(); SwipeKeyboard.GetBoundingBox(_centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard); Rectangle interactRect = DrawArea(); IsPressed = mouseState.LeftButton == ButtonState.Pressed && _mouseStateLastFrame == ButtonState.Released && interactRect.Contains(mouseState.Position); _mouseStateLastFrame = mouseState.LeftButton; }
public void Draw(SpriteBatch spriteBatch, float selectionInterpolation, Vector2 centerPosition) { SwipeKeyboard.GetBoundingBox(centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard); Rectangle rectKeyboard = VirtualCoords.ComputePixelRect(cornerKeyboard, sizeKeyboard); float thicknessScaled = VirtualCoords.ComputePixelScale(BASE_LINE_THICKNESS); float dashLengthScaled = VirtualCoords.ComputePixelScale(BASE_LINE_DASH * selectionInterpolation); float dashTotalScaled = VirtualCoords.ComputePixelScale(BASE_LINE_DASH); float radiusScaled = VirtualCoords.ComputePixelScale(BASE_LINE_THICKNESS); for (int h = 0; h < Length; ++h) { if (h > 0) { Vector2 pos0 = OriginalHandlePositionsRelative[h - 1] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); Vector2 pos1 = OriginalHandlePositionsRelative[h] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); LineRendering.DrawLineDashed(spriteBatch, pos0, pos1, StyleSheet.BackgroundColor * selectionInterpolation, dashLengthScaled, dashTotalScaled * 2 - dashLengthScaled, thicknessScaled * 0.7f, radiusScaled * 2f, radiusScaled * 2f); } //DrawFromRelative(spriteBatch, rectKeyboard, StyleSheet.DotTexture, // StyleSheet.BackgroundColor * selectionInterpolation, OriginalHandlePositionsRelative[h], BASE_LINE_THICKNESS * 1.5f, 0); } for (int h = 0; h < Length; ++h) { Color color = Color.Lerp(StyleSheet.BackgroundColor, StyleSheet.HighlightColor, selectionInterpolation); float radius = MathHelper.Lerp(BASE_STAR_SIZE, SELECTED_STAR_SIZE, _selectIntepolationHandles[h]); if (h > 0) { Vector2 pos0 = HandlePositionsRelative[h - 1] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); Vector2 pos1 = HandlePositionsRelative[h] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); LineRendering.DrawLineDashed(spriteBatch, pos0, pos1, color * (0.5f + 0.5f * selectionInterpolation), dashTotalScaled + dashLengthScaled, dashTotalScaled - dashLengthScaled, thicknessScaled, radiusScaled * 2f, radiusScaled * 2f); } DrawFromRelative(spriteBatch, rectKeyboard, StyleSheet.StarTexture, color, HandlePositionsRelative[h], radius * 2, _selectIntepolationHandles[h] + selectionInterpolation + h); } }
public void Update(GameTime gameTime, Vector2 centerPosition) { var mouseState = Mouse.GetState(); SwipeKeyboard.GetBoundingBox(centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard); Rectangle rectKeyboard = VirtualCoords.ComputePixelRect(cornerKeyboard, sizeKeyboard); bool mouseInside = rectKeyboard.Contains(mouseState.Position); if (_selectedHandle != -1 && mouseInside) { HandlePositionsRelative[_selectedHandle] = (mouseState.Position - rectKeyboard.Location).ToVector2() / rectKeyboard.Width; } bool clicked = mouseState.LeftButton == ButtonState.Pressed && _lastMouseState.LeftButton == ButtonState.Released && mouseInside; bool released = mouseState.LeftButton == ButtonState.Released && _lastMouseState.LeftButton == ButtonState.Pressed; float radius = SELECTED_STAR_SIZE; float radiusScaled = VirtualCoords.ComputePixelScale(radius); int closestStar = -1; if (_selectedHandle == -1 && mouseInside) { float minDist = float.MaxValue; for (int h = 0; h < Length; ++h) { Point centerStar = new Point((int)(rectKeyboard.X + rectKeyboard.Width * HandlePositionsRelative[h].X + 0.5f), (int)(rectKeyboard.Y + rectKeyboard.Width * HandlePositionsRelative[h].Y + 0.5f)); float distStar = (centerStar - mouseState.Position).ToVector2().Length(); if (minDist > distStar && distStar < radiusScaled) { minDist = distStar; closestStar = h; if (clicked) { _selectedHandle = h; } } } } for (int h = 0; h < Length; ++h) { Point centerStar = new Point((int)(rectKeyboard.X + rectKeyboard.Width * HandlePositionsRelative[h].X + 0.5f), (int)(rectKeyboard.Y + rectKeyboard.Width * HandlePositionsRelative[h].Y + 0.5f)); if (closestStar == h || _selectedHandle == h) { _selectIntepolationHandles[h] += (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectIntepolationHandles[h] = Math.Min(1f, _selectIntepolationHandles[h]); } else if (h != closestStar) { _selectIntepolationHandles[h] -= (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectIntepolationHandles[h] = Math.Max(0f, _selectIntepolationHandles[h]); } if (_selectedHandle == h && released) { _selectedHandle = -1; } } if (mouseState.LeftButton != ButtonState.Pressed) { _selectedHandle = -1; } _lastMouseState = mouseState; }