/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { if (_isInitialized) { MouseState currentState = Mouse.GetState(); Rectangle mouseBoundingBox = new Rectangle(currentState.X, currentState.Y, 1, 1); _colorStream.Update(gameTime); foreach (GuiDrawable guiDrawable in _guiDrawable) { guiDrawable.Update(currentState, _oldMouseState, mouseBoundingBox, gameTime); } if (null != Chooser.Sensor && Chooser.Sensor.IsRunning) { if (mouseBoundingBox.Intersects(_scrollable.GraceArea)) { _scrollable.Update(currentState, _oldMouseState, mouseBoundingBox, gameTime); if (currentState.LeftButton == ButtonState.Released && _oldMouseState.LeftButton == ButtonState.Pressed) { _timeStamp = gameTime.TotalGameTime.TotalMilliseconds; _elevationAngle = GetAngle(); } } if (_timeStamp != double.MinValue && gameTime.TotalGameTime.TotalMilliseconds - _timeStamp > 1500) { _timeStamp = double.MinValue; /** Sometimes, the USB port can just cause an error because of its drivers */ try { Chooser.Sensor.ElevationAngle = _elevationAngle; } catch (Exception e) { } } } _oldMouseState = currentState; } base.Update(gameTime); }
public override void Update(MouseState mouseState, MouseState oldMouseState, Rectangle mouseBoundingBox, GameTime gameTime) { if (mouseBoundingBox.Intersects(_scrollable.GraceArea)) { _scrollable.Update(mouseState, oldMouseState, mouseBoundingBox, gameTime); float scrollPercent = _scrollable.GetScrollTop(); float paginationSegment = 100.0f / (_pages); /** 100% scrolled would always give you a page 1 if this wasn't implemented */ if (scrollPercent != 100.0f) { _currentPage = (int)(scrollPercent / paginationSegment); } else { /** Zero based paging system */ _currentPage = _pages - 1; } _pageBeginning = _viewableItems * _currentPage; _pageEnding = _pageBeginning + _viewableItems; if (_pageEnding >= _collection.Count) { _pageEnding = _collection.Count; } } else { if (_pageEnding >= _collection.Count) { _pageEnding = _collection.Count; } } for (int i = _pageBeginning; i < _pageEnding; ++i) { _collection[i].Update(mouseState, oldMouseState, mouseBoundingBox, gameTime); } }