/// <summary> /// Draws the ItemEntity. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="pos">Position to draw at.</param> /// <param name="color">The color to draw the item.</param> /// <exception cref="ArgumentNullException"><paramref name="sb" /> is <c>null</c>.</exception> public void Draw(ISpriteBatch sb, Vector2 pos, Color color) { if (sb == null) { throw new ArgumentNullException("sb"); } if (BeforeDraw != null) { BeforeDraw.Raise(this, EventArgsHelper.Create(sb)); } if (IsVisible) { if (_grh != null) { _grh.Draw(sb, pos, color); } } if (AfterDraw != null) { AfterDraw.Raise(this, EventArgsHelper.Create(sb)); } }
/// <summary> /// Draws the item in this slot. This method is always called, even when the slot is empty. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="itemSprite">The <see cref="Grh"/> to draw. Will never be null, but can contain /// an invalid or empty sprite.</param> protected virtual void DrawItem(ISpriteBatch spriteBatch, Grh itemSprite) { if (itemSprite.GrhData == null) { return; } // Grab the screen position and client size var sp = ScreenPosition; var cs = ClientSize; // Get the size to use for drawing (never exceeding the size of the control) var drawSize = Vector2.Min(cs, itemSprite.Size); // Get the draw position (centering on the control) var drawPos = sp + ((cs - drawSize) / 2f); // Draw var spriteDestRect = new Rectangle(drawPos.X, drawPos.Y, drawSize.X, drawSize.Y); _sprite.Draw(spriteBatch, spriteDestRect); // Draw the amount var itemInfo = GetSlotItemInfo(); if (itemInfo == null) { return; } var amount = ItemsCollection.PeerTradeForm.GetItemAmount(itemInfo); DrawItemAmount(spriteBatch, amount); }
/// <summary> /// Draws the emoticon. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="position">The world position to draw the emoticon.</param> public void Draw(ISpriteBatch spriteBatch, Vector2 position) { // Check for a valid state if (!IsValidStateToUse) { return; } _grh.Draw(spriteBatch, position); }
/// <summary> /// Draws the <see cref="Control"/>. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> protected override void DrawControl(ISpriteBatch spriteBatch) { base.DrawControl(spriteBatch); var itemInfo = ItemInfo; if (itemInfo == null) { _grh = null; return; } if (_grh == null || _grh.GrhData.GrhIndex != itemInfo.Graphic) { try { _grh = new Grh(itemInfo.Graphic, AnimType.Loop, 0); } catch (Exception ex) { _grh = null; if (log.IsErrorEnabled) { log.ErrorFormat("Failed to load shop Grh with index `{0}`: `{1}`", itemInfo.Graphic, ex); } } } if (_grh == null) { return; } // Draw the item in the center of the slot var offset = (_itemSize - _grh.Size) / 2f; _grh.Draw(spriteBatch, ScreenPosition + offset); }
/// <summary> /// Performs the default menu background drawing. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> protected virtual void DrawBackground(ISpriteBatch spriteBatch) { // Draw the background if (_background != null) { var bgDest = new Rectangle(0, 0, ScreenManager.ScreenSize.X, ScreenManager.ScreenSize.Y); _background.Draw(spriteBatch, bgDest); } // Draw the title if (!string.IsNullOrEmpty(_title)) { spriteBatch.DrawStringShaded(GameScreenHelper.DefaultMenuTitleFont, Title, _titlePosition, _titleColor, _titleBorderColor); } }
/// <summary> /// Draws the quick bar item. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="position">The position to draw the item at. If null, the item will be /// drawn in the center of the quick bar slot.</param> /// <param name="color">The color.</param> void DrawQuickBarItem(ISpriteBatch spriteBatch, Vector2?position, Color color) { var isOnBar = (position == null); // Draw the item in the quick bar switch (QuickBarItemType) { case QuickBarItemType.Inventory: var item = QuickBarForm._gps.UserInfo.Inventory[(InventorySlot)QuickBarItemValue]; if (item == null) { break; } if (position == null) { position = CenterOnSlot(item.Grh); } item.Draw(spriteBatch, position.Value, color); break; case QuickBarItemType.Skill: if (_skillInfo == null) { break; } if (position == null) { position = CenterOnSlot(_grh); } _grh.Draw(spriteBatch, position.Value); if (isOnBar && CooldownManager.IsCoolingDown(_skillInfo.CooldownGroup, TickCount.Now)) { RenderRectangle.Draw(spriteBatch, GetScreenArea(), new Color(0, 0, 0, 150)); } break; } }
/// <summary> /// When overridden in the derived class, draws the graphics to the control. /// </summary> /// <param name="currentTime">The current time.</param> protected override void HandleDraw(TickCount currentTime) { base.HandleDraw(currentTime); if (DesignMode) { return; } if (_drawingManager.RenderWindow == null) { return; } if (Grh == null) { return; } Grh.Update(currentTime); m.Update(currentTime); _drawingManager.Update(currentTime); var sb = _drawingManager.BeginDrawWorld(_camera); if (sb == null) { return; } // Change the view var oldView = RenderWindow.GetView(); _drawView.Reset(new FloatRect(Camera.Min.X, Camera.Min.Y, Camera.Size.X, Camera.Size.Y)); RenderWindow.SetView(_drawView); try { try { Grh.Draw(sb, Vector2.Zero, Color.White); } catch (LoadingFailedException) { // A LoadingFailedException is generally fine here since it probably means the graphic file was invalid // or does not exist } // Draw the walls if (Walls != null) { foreach (var wall in Walls) { var rect = wall.ToRectangle(); RenderRectangle.Draw(sb, rect, _autoWallColor); } } m.Draw(sb, Camera); } finally { _drawingManager.EndDrawWorld(); // Restore the view RenderWindow.SetView(oldView); } }
/// <summary> /// When overridden in the derived class, draws the graphics to the control. /// </summary> /// <param name="currentTime">The current time.</param> protected override void HandleDraw(TickCount currentTime) { if (DesignMode) { base.HandleDraw(currentTime); return; } TransBoxManager.Update(currentTime); RenderWindow.Clear(Color.Black); // Update the cursor display for the transformation box. Only change the cursor if we are currently // under a transbox, or we have just stopped being under one. If we update it every frame, it screws with the // UI display for everything else (like when the cursor is over a textbox). var transBoxCursor = TransBoxManager.CurrentCursor; if (transBoxCursor == null) { if (_wasUnderTransBox) { Cursor = Cursors.Default; _wasUnderTransBox = false; } } else { Cursor = transBoxCursor; _wasUnderTransBox = true; } // TODO: Implement drawing logic // Do some actual work here _spriteBatch.Begin(BlendMode.Alpha, _camera); if (TilesetConfiguration != null) { int x = 0; int y = 0; for (int i = 0; i < TilesetConfiguration.GrhDatas.Count; i++) { var grh = TilesetConfiguration.GrhDatas[i]; Grh nGrh = new Grh(grh); nGrh.Draw(_spriteBatch, new Vector2(y * EditorSettings.Default.GridSize.X, x * EditorSettings.Default.GridSize.Y)); y++; if (y % TilesetConfiguration.Width == 0) { x++; y = 0; } } // Draw little selection box RenderRectangle.Draw(_spriteBatch, new Rectangle(grhX, grhY, EditorSettings.Default.GridSize.X, EditorSettings.Default.GridSize.Y), Color.TransparentWhite, Color.White, -3f); } _spriteBatch.End(); int deltaTime; if (_lastUpdateTime == TickCount.MinValue) { deltaTime = 30; } else { deltaTime = Math.Max(5, (int)(currentTime - _lastUpdateTime)); } _lastUpdateTime = currentTime; _camera.Min += _cameraVelocity * (deltaTime / 1000f); }
/// <summary> /// The default quest indicator drawer. /// </summary> /// <param name="grh">The <see cref="Grh"/> to draw.</param> /// <param name="c">The character the indicator is for.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param> protected virtual void DefaultIndicatorDrawer(Grh grh, TCharacter c, ISpriteBatch sb) { var pos = new Vector2(c.Center.X, c.Position.Y) - new Vector2(grh.Size.X / 2f, grh.Size.Y + 12); grh.Draw(sb, pos); }
public void Draw(ISpriteBatch sb, Vector2 position, TickCount currentTime) { _grh.Update(currentTime); _grh.Draw(sb, position); }