public static void DrawSpawn(MapSpawnValues spawn, ISpriteBatch spriteBatch, IDrawableMap map, Font font) { var spawnArea = spawn.SpawnArea; // Only draw if it does not cover the whole map if (!spawnArea.X.HasValue && !spawnArea.Y.HasValue && !spawnArea.Width.HasValue && !spawnArea.Height.HasValue) { return; } // Draw spawn area Vector2 cameraOffset = map.Camera.Min; Rectangle rect = spawnArea.ToRectangle(map); rect.X -= (int)cameraOffset.X; rect.Y -= (int)cameraOffset.Y; RenderRectangle.Draw(spriteBatch, rect, new Color(0, 255, 0, 75), new Color(0, 0, 0, 125), 2); // Draw name CharacterTemplate charTemp = CharacterTemplateManager.Instance[spawn.CharacterTemplateID]; if (charTemp != null) { string text = string.Format("{0}x {1} [{2}]", spawn.SpawnAmount, charTemp.TemplateTable.Name, spawn.CharacterTemplateID); Vector2 textPos = new Vector2(rect.X, rect.Y); textPos -= new Vector2(0, font.MeasureString(text).Y); textPos = textPos.Round(); spriteBatch.DrawStringShaded(font, text, textPos, Color.White, Color.Black); } }
/// <summary> /// Handles drawing of the screen. The ScreenManager already provides a GraphicsDevice.Clear() so /// there is often no need to clear the screen. This will only be called while the screen is the /// active screen. /// </summary> /// <param name="gameTime">The current game time.</param> public override void Draw(TickCount gameTime) { var spriteBatch = DrawingManager.BeginDrawGUI(false); if (spriteBatch == null) { return; } // Draw an overlay on top of the old screen RenderRectangle.Draw(spriteBatch, _cScreen.GetScreenArea(), _overlayColor); // Draw the GUI GUIManager.Draw(spriteBatch); // Draw some extras const int yOff = 150; spriteBatch.DrawStringShaded(_txtOutput.Font, "FPS: " + ScreenManager.FPS, new Vector2(_cScreen.ClientSize.X - 100, yOff), Color.White, Color.Black); spriteBatch.DrawStringShaded(_txtOutput.Font, string.Format("Game Time: {0}:{1:00}", GameDateTime.Now.Hour, GameDateTime.Now.Minute), new Vector2(_cScreen.ClientSize.X - 150, _txtOutput.Font.GetLineSpacing() + yOff), Color.White, Color.Black); DrawingManager.EndDrawGUI(); }
public static void Draw(ISpriteBatch sb, ICamera2D camera, WallEntityBase wall, Vector2 offset) { // Find the positon to draw to var p = wall.Position + offset; var dest = new Rectangle((int)p.X, (int)p.Y, (int)wall.Size.X, (int)wall.Size.Y); // Draw the collision area RenderRectangle.Draw(sb, dest, _wallColor); }
/// <summary> /// Draws a <see cref="Rectangle"/>. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="color">Color to draw the CollisionBox.</param> static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color, bool border = true) { if (border) { RenderRectangle.Draw(sb, position, size, color, _borderColor); } else { RenderRectangle.Draw(sb, position, size, color); } }
/// <summary> /// Draws the <see cref="ITooltip"/>. /// </summary> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw the <see cref="ITooltip"/> with.</param> /// <exception cref="ArgumentNullException"><paramref name="sb" /> is <c>null</c>.</exception> public virtual void Draw(ISpriteBatch sb) { if (sb == null) { throw new ArgumentNullException("sb"); } // Do nothing if not being displayed if (!IsDisplayed) { return; } var pos = GUIManager.CursorPosition + DrawOffset + BorderPadding; var size = _borderSize + (BorderPadding * 2); var ss = GUIManager.ScreenSize; // Ensure the tooltip is in the screen if (pos.X < 0) { pos.X = 0; } else if (pos.X + size.X > ss.X) { pos.X = ss.X - size.X; } if (pos.Y < 0) { pos.Y = 0; } else if (pos.Y + size.Y > ss.Y) { pos.Y = ss.Y - size.Y; } // Draw the border var borderRect = new Rectangle((int)(pos.X - BorderPadding.X), (int)(pos.Y - BorderPadding.Y), (int)(_borderSize.X + (BorderPadding.X * 2)), (int)(_borderSize.Y + (BorderPadding.Y * 2))); var b = _args.Border; if (b != null) { b.Draw(sb, borderRect); } else { RenderRectangle.Draw(sb, borderRect, _args.BackgroundColor); } // Draw the text _drawer.Draw(sb, _args.FontColor, pos); }
/// <summary> /// When overridden in the derived class, handles performing drawing before the GUI for a <see cref="IDrawableMap"/> has been draw. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to use to draw.</param> /// <param name="imap">The <see cref="IDrawableMap"/> being drawn.</param> protected override void HandleBeforeDrawMapGUI(ISpriteBatch spriteBatch, IDrawableMap imap) { base.HandleBeforeDrawMapGUI(spriteBatch, imap); if (!IsEnabled) { return; } var map = imap as EditorMap; if (map == null) { return; } var camera = map.Camera; if (camera == null) { return; } // Only draw for the map under the cursor if (map != _mouseOverMap) { return; } if (IsSelecting) { // Draw the selection area var a = camera.ToScreen(_selectionStart); var b = camera.ToScreen(_selectionEnd); if (a.QuickDistance(b) > _minSelectionAreaDrawSize) { var rect = Rectangle.FromPoints(a, b); RenderRectangle.Draw(spriteBatch, rect, _selectionAreaColorInner, _selectionAreaColorOuter); } } else { // Draw the tooltip var font = ToolTipFont; if (_toolTipObject != null && _toolTip != null && font != null) { spriteBatch.DrawStringShaded(font, _toolTip, _toolTipPos, Color.White, Color.Black); } } }
/// <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); if (_isCoolingDown) { RenderRectangle.Draw(spriteBatch, GetScreenArea(), new Color(0, 0, 0, 150)); } if (!IsEnabled) { RenderRectangle.Draw(spriteBatch, GetScreenArea(), new Color(255, 0, 0, 150)); } }
/// <summary> /// Draws a bar for the Character's SP. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="percent">The percent of the SP being drawn.</param> /// <param name="index">The 0-based index of the bar being drawn.</param> /// <param name="color">The color to draw the bar.</param> protected virtual void DrawSPBar(ISpriteBatch sb, byte percent, byte index, Color color) { const float spBarWidth = 55; const float spBarHeight = 6; var pos = DrawPosition + new Vector2((Size.X / 2f) - (spBarWidth / 2f), Size.Y + (spBarHeight * index)).Round(); var border = new Rectangle((int)pos.X, (int)pos.Y, (int)spBarWidth, (int)spBarHeight); var bar = border; bar.Width = (int)((spBarWidth * (percent / 100.0f))).Clamp(0.0f, spBarWidth); RenderRectangle.Draw(sb, border, new Color(0, 0, 0, 0), Color.Black); RenderRectangle.Draw(sb, bar, color); }
/// <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, handles drawing to the map after the given <see cref="MapRenderLayer"/> is drawn. /// </summary> /// <param name="map">The map the drawing is taking place on.</param> /// <param name="e">The <see cref="NetGore.Graphics.DrawableMapDrawLayerEventArgs"/> instance containing the event data.</param> protected override void HandleDrawAfterLayer(IDrawableMap map, DrawableMapDrawLayerEventArgs e) { if (e.Layer != MapRenderLayer.SpriteForeground) { return; } if (MapSpawns == null) { return; } foreach (var item in MapSpawns) { var rect = item.SpawnArea.ToRectangle(map); if (e.Camera.InView(rect)) { RenderRectangle.Draw(e.SpriteBatch, rect, _drawColor); } } }
/// <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); // Draw the progress bar float elapsedTime = TickCount.Now - _castStartTime; var percent = elapsedTime / _currentCastTime; var startDrawPos = ScreenPosition + new Vector2(Border.LeftWidth, Border.TopHeight); var drawWidth = ClientSize.X * Math.Min(percent, 1); var r = new Rectangle(startDrawPos.X, startDrawPos.Y, drawWidth, ClientSize.Y); RenderRectangle.Draw(spriteBatch, r, new Color(255, 0, 0, 200)); // Draw the name spriteBatch.DrawStringShaded(Font, Text, Position + _textOffset, ForeColor, Color.Black); // Stop drawing if we hit 100% if (percent >= 1.00f) { StopCasting(); } }
/// <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> /// Draws the selection region a selected item. /// </summary> /// <param name="sb">The <see cref="ISpriteBatch"/>.</param> /// <param name="area">The area to draw the selection.</param> protected virtual void DrawSelectionRegion(ISpriteBatch sb, Rectangle area) { RenderRectangle.Draw(sb, area, new Color(100, 100, 255, 150)); }
/// <summary> /// Draws a <see cref="Rectangle"/>. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="rect">The <see cref="Rectangle"/> to draw.</param> /// <param name="color">Color to draw the CollisionBox.</param> static void Draw(ISpriteBatch sb, Rectangle rect, Color color) { RenderRectangle.Draw(sb, rect, color, _borderColor); }