/// <summary>
        /// This method paints the bounds and full bounds of nodes when the appropriate debug
        /// flags are set.
        /// </summary>
        /// <param name="paintContext">
        /// The paint context to use for painting debug information.
        /// </param>
        /// <remarks>
        /// Setting debugBounds and/or debugFullBounds flags is useful for visual debugging.
        /// </remarks>
        protected virtual void PaintDebugInfo(PPaintContext paintContext)
        {
            if (PDebug.DebugBounds || PDebug.DebugFullBounds)
            {
                Graphics2D g = paintContext.Graphics;

                PNodeList  nodes      = new PNodeList();
                RectangleF nodeBounds = RectangleF.Empty;

                for (int i = 0; i < LayerCount; i++)
                {
                    GetLayer(i).GetAllNodes(null, nodes);
                }

                GetAllNodes(null, nodes);

                foreach (PNode each in nodes)
                {
                    if (PDebug.DebugBounds)
                    {
                        nodeBounds = each.Bounds;

                        if (!nodeBounds.IsEmpty)
                        {
                            nodeBounds = each.LocalToGlobal(nodeBounds);
                            nodeBounds = GlobalToLocal(nodeBounds);
                            if (each == this || each.IsDescendentOf(this))
                            {
                                nodeBounds = LocalToView(nodeBounds);
                            }
                            g.DrawRectangle(boundsPen, nodeBounds.X, nodeBounds.Y, nodeBounds.Width, nodeBounds.Height);
                        }
                    }

                    if (PDebug.DebugFullBounds)
                    {
                        nodeBounds = each.FullBounds;

                        if (!nodeBounds.IsEmpty)
                        {
                            if (each.Parent != null)
                            {
                                nodeBounds = each.Parent.LocalToGlobal(nodeBounds);
                            }
                            nodeBounds = GlobalToLocal(nodeBounds);
                            if (each == this || each.IsDescendentOf(this))
                            {
                                nodeBounds = LocalToView(nodeBounds);
                            }
                            //g.FillRectangle(fullBoundsBrush, nodeBounds);
                            g.DrawRectangle(fullBoundsPen, nodeBounds);
                        }
                    }
                }
            }
        }
Example #2
0
        public override void Draw()
        {
            // draw bg
            if (backColor != SVGA.color)
            {
                Graphics2D.FillRectangle(bounds, backColor);
            }

            // draw border
            int  bs   = this.style.SIZE_BORDER;
            uint bord = this.style.C_BORDER;

            if (bs > 0)
            {
                Graphics2D.DrawRectangle(bounds, bs, bord);
            }

            // draw text
            int  shadSize = this.style.SIZE_TEXT_SHADOW;
            uint shadCol  = this.style.C_TEXT_SHADOW;

            if (text.Length > 0)
            {
                if (shadSize > 0 && shadCol != SVGA.color)
                {
                    Graphics2D.DrawStringShadow(x, y, text, textColor, shadCol, shadSize, Fonts.FONT_MONO);
                }
                else
                {
                    Graphics2D.DrawString(x, y, text, textColor, Fonts.FONT_MONO);
                }
            }
        }
Example #3
0
        public override void Draw()
        {
            // get style colors
            uint bg        = style.C_BG;
            uint fg        = style.C_TEXT;
            uint bord      = style.C_BORDER;
            uint bordOuter = style.C_BORDER_OUTER;
            uint bordInner = style.C_BORDER_INNER;
            uint fgShadow  = style.C_TEXT_SHADOW;
            uint fgHover   = style.C_TEXT_HOVER;
            uint fgDown    = style.C_TEXT_DOWN;
            uint dis       = style.C_DISABLED;
            uint shadow    = style.C_SHADOW;
            uint hov       = style.C_HOVER;
            uint dwn       = style.C_DOWN;

            // get style sizes
            int bordSize     = style.SIZE_BORDER;
            int shadowSize   = style.SIZE_SHADOW;
            int fgShadowSize = style.SIZE_TEXT_SHADOW;
            int borderStyle  = style.BORDER_STYLE;

            // draw background
            Graphics2D.FillRectangle(bounds, bg);

            // draw border
            Graphics2D.DrawRectangle(bounds, 1, bord);

            // draw buttons
            for (int i = 0; i < items.Count; i++)
            {
                items[i].Draw();
            }
        }
Example #4
0
        //-----------------------------------------------------------------------------
        // Overriden methods
        //-----------------------------------------------------------------------------

        protected override void Draw()
        {
            Graphics2D g = new Graphics2D(spriteBatch);

            //g.SetRenderTarget(GameData.RenderTargetGame);

            g.Begin(GameSettings.DRAW_MODE_DEFAULT);
            g.Clear(Color.White);
            g.Translate(new Vector2F(-this.HorizontalScroll.Value, -this.VerticalScroll.Value));
            g.DrawImage(Tileset.SpriteSheet.Image.GetVariant(Zone.ImageVariantID), Point2I.Zero);

            Point2I tilePoint = SelectedTile * (Tileset.SpriteSheet.CellSize + Tileset.SpriteSheet.Spacing);

            g.DrawRectangle(new Rectangle2I(tilePoint, Tileset.SpriteSheet.CellSize + 1), 1, Color.White);
            g.DrawRectangle(new Rectangle2I(tilePoint + 1, Tileset.SpriteSheet.CellSize - 1), 1, Color.Black);
            g.DrawRectangle(new Rectangle2I(tilePoint - 1, Tileset.SpriteSheet.CellSize + 3), 1, Color.Black);
            g.ResetTranslation();
            g.End();
        }
Example #5
0
        public override void Draw()
        {
            // get style colors
            uint bg = style.C_BG;
            uint fg = style.C_TEXT;
            uint bord = style.C_BORDER;
            uint bordOuter = style.C_BORDER_OUTER;
            uint bordInner = style.C_BORDER_INNER;
            uint fgShadow = style.C_TEXT_SHADOW;
            uint fgHover = style.C_TEXT_HOVER;
            uint fgDown = style.C_TEXT_DOWN;
            uint dis = style.C_DISABLED;
            uint shadow = style.C_SHADOW;
            uint hov = style.C_HOVER;
            uint dwn = style.C_DOWN;

            // get style sizes
            int bordSize = style.SIZE_BORDER;
            int shadowSize = style.SIZE_SHADOW;
            int fgShadowSize = style.SIZE_TEXT_SHADOW;
            int borderStyle = style.BORDER_STYLE;

            // draw bg
            Graphics2D.FillRectangle(bounds, bg);

            // draw border
            Graphics2D.DrawRectangle(bounds, bordSize, bord);

            // text
            if (text.Length > 0)
            {
                if (!passwordFilter) { Graphics2D.DrawString(x + 4, y + (height / 2) - 4, text, fg, Fonts.FONT_MONO); }
                else
                {
                    int sx = x + 4;
                    for (int i = 0; i < text.Length; i++)
                    {
                        Graphics2D.DrawChar(sx, y + (height / 2) - 4, '*', fg, Fonts.FONT_MONO);
                        sx += Fonts.FONT_MONO.characterWidth + Graphics2D.FONT_SPACING;
                    }
                }
            }

            if (cursor)
            {
                int xadd = textW;
                if (text.Length == 0) { xadd = 2; }
                Graphics2D.DrawChar(x + xadd + 2, y + (height / 2) - 4, '|', fg, Fonts.FONT_MONO);
            }
        }
Example #6
0
        private static void DrawTile(Graphics2D g, Tile tile)
        {
            if (TileDebugInfoMode == TileDrawInfo.CollisionBoxes)
            {
                if (tile.IsSolid && tile.CollisionModel != null)
                {
                    foreach (Rectangle2F box in tile.CollisionModel.Boxes)
                    {
                        Rectangle2F r = Rectangle2F.Translate(box, tile.Position);
                        g.FillRectangle(r, Color.Red);
                        //g.DrawRectangle(r, 1, Color.Maroon);
                    }
                }
            }
            else if (TileDebugInfoMode == TileDrawInfo.GridArea)
            {
                Rectangle2F tileBounds = (Rectangle2F)tile.TileGridArea;
                tileBounds.Point *= GameSettings.TILE_SIZE;
                tileBounds.Size  *= GameSettings.TILE_SIZE;
                Color c = Color.Yellow;
                if (tile.Layer == 1)
                {
                    c = Color.Blue;
                }
                else if (tile.Layer == 2)
                {
                    c = Color.Red;
                }
                g.FillRectangle(tileBounds, c);

                tileBounds = new Rectangle2F(tile.Position, tile.Size * GameSettings.TILE_SIZE);
                c          = Color.Olive;
                if (tile.Layer == 1)
                {
                    c = Color.Cyan;
                }
                else if (tile.Layer == 2)
                {
                    c = Color.Maroon;
                }

                g.DrawLine(new Line2F(tileBounds.TopLeft, tileBounds.BottomRight - new Point2I(1, 1)), 1, c);
                g.DrawLine(new Line2F(tileBounds.TopRight - new Point2I(1, 0), tileBounds.BottomLeft - new Point2I(0, 1)), 1, c);
                g.DrawRectangle(tileBounds, 1, Color.Black);
            }
        }
Example #7
0
        public void DrawWindow()
        {
            if (state == WindowState.maximized)
            {
            }

            if (state != WindowState.minimized)
            {
                // draw bg
                Graphics2D.FillRectangle(boundsUsable, backColor);
                Graphics2D.DrawRectangle(new Rectangle(boundsUsable.x, boundsUsable.y, boundsUsable.width, boundsUsable.height + 1), 1, Color.silver);

                // draw title bar
                Graphics2D.FillRectangle(tbBounds, Color.gray32);

                // draw title
                Graphics2D.DrawString(x + 8, y + 6, title, Color.white, Fonts.FONT_MONO);

                // draw buttons
                if (exitBox)
                {
                    btnClose.Draw();
                }
                if (maximizeBox)
                {
                    btnMax.Draw();
                }
                if (minimizeBox)
                {
                    btnMin.Draw();
                }

                // draw title bar border
                Graphics2D.DrawRectangle(tbBounds, 1, Color.silver);
            }
        }
Example #8
0
        public override void Draw()
        {
            // get style colors
            uint bg        = style.C_BG;
            uint fg        = style.C_TEXT;
            uint bord      = style.C_BORDER;
            uint bordOuter = style.C_BORDER_OUTER;
            uint bordInner = style.C_BORDER_INNER;
            uint fgShadow  = style.C_TEXT_SHADOW;
            uint fgHover   = style.C_TEXT_HOVER;
            uint fgDown    = style.C_TEXT_DOWN;
            uint dis       = style.C_DISABLED;
            uint shadow    = style.C_SHADOW;
            uint hov       = style.C_HOVER;
            uint dwn       = style.C_DOWN;

            // get style sizes
            int bordSize     = style.SIZE_BORDER;
            int shadowSize   = style.SIZE_SHADOW;
            int fgShadowSize = style.SIZE_TEXT_SHADOW;
            int borderStyle  = style.BORDER_STYLE;

            // current colors
            if (hover && !down)
            {
                bgCurrent = hov; fgCurrent = fgHover;
            }
            else if (hover && down)
            {
                bgCurrent = dwn; fgCurrent = fgDown;
            }
            else if (!hover && !down)
            {
                bgCurrent = bg; fgCurrent = fg;
            }
            if (!enabled)
            {
                bgCurrent = dis;
            }

            // draw bg
            Graphics2D.FillRectangle(bounds, bgCurrent);

            // draw border - fixed single
            if (borderStyle == 1 && bordSize > 0)
            {
                Graphics2D.DrawRectangle(bounds, bordSize, bord);
            }

            // draw text
            if (text.Length > 0)
            {
                Font f = Fonts.FONT_MONO;
                if (font == 3)
                {
                    f = Fonts.FONT_SYMBOLS;
                }

                int textW = f.StringWidth(text);
                int xx = x + 4, yy = y + (height / 2) - (f.characterHeight / 2);
                if (textAlign == TextAlign.middle)
                {
                    xx = x + (width / 2) - (textW / 2);
                }
                if (textAlign == TextAlign.left)
                {
                    xx = x + 4;
                }
                if (textAlign == TextAlign.right)
                {
                    xx = x + width - (textW + 4);
                }

                Graphics2D.DrawString(xx, yy, text, fgCurrent, f);
            }
        }
Example #9
0
        public override void Draw()
        {
            // get style colors
            uint bg        = style.C_BG;
            uint fg        = style.C_TEXT;
            uint bord      = style.C_BORDER;
            uint bordOuter = style.C_BORDER_OUTER;
            uint bordInner = style.C_BORDER_INNER;
            uint fgShadow  = style.C_TEXT_SHADOW;
            uint fgHover   = style.C_TEXT_HOVER;
            uint fgDown    = style.C_TEXT_DOWN;
            uint dis       = style.C_DISABLED;
            uint shadow    = style.C_SHADOW;
            uint hov       = style.C_HOVER;
            uint dwn       = style.C_DOWN;

            // get style sizes
            int bordSize     = style.SIZE_BORDER;
            int shadowSize   = style.SIZE_SHADOW;
            int fgShadowSize = style.SIZE_TEXT_SHADOW;
            int borderStyle  = style.BORDER_STYLE;

            // current colors
            if (hover && !down)
            {
                bgCurrent = hov; bordCurrent = fgHover;
            }
            else if (hover && down)
            {
                bgCurrent = dwn; bordCurrent = fgDown;
            }
            else if (!hover && !down)
            {
                if (!toggled)
                {
                    bgCurrent = bg;
                }
                else
                {
                    bgCurrent = bord;
                }
                bordCurrent = bord;
            }
            if (!enabled)
            {
                bgCurrent = dis;
            }

            // draw box
            Graphics2D.FillRectangle(box, bgCurrent);

            // draw border
            Graphics2D.DrawRectangle(box, 1, bordCurrent);

            // draw text
            if (text.Length > 0 && this.txtWidth > 0)
            {
                if (fgShadowSize > 0)
                {
                    if (font == FontIndex.mono7x9)
                    {
                        Graphics2D.DrawStringShadow(x + box.width + 8, y + 2, text, fg, fgShadow, fgShadowSize, Fonts.FONT_MONO);
                    }
                }
                else
                {
                    if (font == FontIndex.mono7x9)
                    {
                        Graphics2D.DrawString(x + box.width + 8, y + 2, text, fg, Fonts.FONT_MONO);
                    }
                }
            }
        }
Example #10
0
        // Draw an entire level.
        public void DrawLevel(Graphics2D g)
        {
            g.Clear(new Color(175, 175, 180));             // Gray background.

            // Draw the level if it is open.
            if (editorControl.IsLevelOpen)
            {
                // Draw the rooms.
                for (int x = 0; x < Level.Width; x++)
                {
                    for (int y = 0; y < Level.Height; y++)
                    {
                        g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                        g.Translate((Vector2F)(new Point2I(x, y) * ((Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing)));
                        DrawRoom(g, Level.GetRoomAt(x, y));
                        g.ResetTranslation();
                    }
                }

                // Draw the highlight box.
                if (editorControl.HighlightMouseTile && cursorTileLocation >= Point2I.Zero)
                {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                    Rectangle2I box = new Rectangle2I(GetLevelTileCoordDrawPosition(cursorTileLocation), new Point2I(16, 16));
                    g.DrawRectangle(box.Inflated(1, 1), 1, Color.White);
                    g.ResetTranslation();
                }

                // Draw selection grid.
                if (selectionGridLevel == Level && !selectionGridArea.IsEmpty)
                {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));

                    if (selectionGrid != null)
                    {
                        for (int i = 0; i < selectionGrid.LayerCount; i++)
                        {
                            for (int y = 0; y < selectionGrid.Height; y++)
                            {
                                for (int x = 0; x < selectionGrid.Width; x++)
                                {
                                    Point2I          position = GetLevelTileCoordDrawPosition(selectionGridArea.Point + new Point2I(x, y));
                                    TileDataInstance tile     = selectionGrid.GetTileIfAtLocation(x, y, i);

                                    // Draw tile.
                                    if (tile != null)
                                    {
                                        DrawTile(g, tile, position, Color.White);
                                    }
                                }
                            }
                        }
                        // Draw event tiles.
                        if (editorControl.ShowEvents || editorControl.ShouldDrawEvents)
                        {
                            for (int i = 0; i < selectionGrid.EventTiles.Count; i++)
                            {
                                Point2I position = GetLevelTileCoordDrawPosition(selectionGridArea.Point) + selectionGrid.EventTiles[i].Position;
                                DrawEventTile(g, selectionGrid.EventTiles[i], position, Color.White);
                            }
                        }
                    }

                    // Draw the selection box.
                    if (!selectionBox.IsEmpty)
                    {
                        Point2I     start = GetLevelPixelDrawPosition(selectionBox.TopLeft);
                        Point2I     end   = GetLevelPixelDrawPosition(selectionBox.BottomRight);
                        Rectangle2I box   = new Rectangle2I(start, end - start);

                        g.DrawRectangle(box, 1, Color.White);
                        g.DrawRectangle(box.Inflated(1, 1), 1, Color.Black);
                        g.DrawRectangle(box.Inflated(-1, -1), 1, Color.Black);
                    }

                    g.ResetTranslation();
                }

                // Draw selected tiles.
                foreach (BaseTileDataInstance tile in selectedTiles)
                {
                    g.Translate(new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                    Rectangle2I bounds = tile.GetBounds();
                    bounds.Point += GetRoomDrawPosition(tile.Room);
                    g.DrawRectangle(bounds, 1, Color.White);
                    g.DrawRectangle(bounds.Inflated(1, 1), 1, Color.Black);
                    g.DrawRectangle(bounds.Inflated(-1, -1), 1, Color.Black);
                    g.ResetTranslation();
                }

                // Draw player sprite for 'Test At Position'
                Point2I roomSize  = (Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing;
                Point2I tilePoint = highlightedRoom * roomSize + highlightedTile * GameSettings.TILE_SIZE;
                if (editorControl.PlayerPlaceMode && highlightedTile >= Point2I.Zero)
                {
                    g.DrawSprite(GameData.SPR_PLAYER_FORWARD, (Vector2F)tilePoint + new Vector2F(-HorizontalScroll.Value, -VerticalScroll.Value));
                }
            }
        }
Example #11
0
        // Draw an entire room.
        private void DrawRoom(Graphics2D g, Room room)
        {
            Color belowFade = new Color(255, 255, 255, 150);
            Color aboveFade = new Color(255, 255, 255, 100);
            Color hide      = Color.Transparent;
            Color normal    = Color.White;

            // Draw white background.
            g.FillRectangle(new Rectangle2I(Point2I.Zero, room.Size * GameSettings.TILE_SIZE), Color.White);

            // Draw tile layers.
            for (int i = 0; i < room.LayerCount; i++)
            {
                // Determine color/transparency for layer based on layer visibility.
                Color color = normal;
                if (!editorControl.ShouldDrawEvents)
                {
                    if (editorControl.CurrentLayer > i)
                    {
                        if (editorControl.BelowTileDrawMode == TileDrawModes.Hide)
                        {
                            color = hide;
                        }
                        else if (editorControl.BelowTileDrawMode == TileDrawModes.Fade)
                        {
                            color = belowFade;
                        }
                    }
                    else if (editorControl.CurrentLayer < i)
                    {
                        if (editorControl.AboveTileDrawMode == TileDrawModes.Hide)
                        {
                            color = hide;
                        }
                        else if (editorControl.AboveTileDrawMode == TileDrawModes.Fade)
                        {
                            color = aboveFade;
                        }
                    }
                }

                // Draw the tile grid for this layer.
                for (int x = 0; x < room.Width; x++)
                {
                    for (int y = 0; y < room.Height; y++)
                    {
                        Point2I          position = new Point2I(x, y) * GameSettings.TILE_SIZE;
                        TileDataInstance tile     = room.GetTile(x, y, i);

                        // Draw tile.
                        if (tile != null && tile.IsAtLocation(x, y))
                        {
                            DrawTile(g, tile, position, color);
                        }

                        // Draw grid square.
                        if (i == room.LayerCount - 1)
                        {
                            if (editorControl.ShowGrid)
                            {
                                g.DrawRectangle(new Rectangle2I(position, new Point2I(GameSettings.TILE_SIZE + 1)), 1, new Color(0, 0, 0, 150));
                            }
                        }
                    }
                }
            }

            // Draw event tiles.
            if (editorControl.ShowEvents || editorControl.ShouldDrawEvents)
            {
                for (int i = 0; i < room.EventData.Count; i++)
                {
                    DrawEventTile(g, room.EventData[i], room.EventData[i].Position, Color.White);
                }
            }

            // Draw the spacing lines between rooms.
            if (editorControl.RoomSpacing > 0)
            {
                g.FillRectangle(new Rectangle2I(0, room.Height * GameSettings.TILE_SIZE, room.Width * GameSettings.TILE_SIZE, editorControl.RoomSpacing), Color.Black);
                g.FillRectangle(new Rectangle2I(room.Width * GameSettings.TILE_SIZE, 0, editorControl.RoomSpacing, room.Height * GameSettings.TILE_SIZE + editorControl.RoomSpacing), Color.Black);
            }
        }
Example #12
0
        //-----------------------------------------------------------------------------
        // Overriden methods
        //-----------------------------------------------------------------------------

        protected override void Draw()
        {
            Graphics2D g = new Graphics2D(spriteBatch);

            //g.SetRenderTarget(GameData.RenderTargetGame);
            g.Begin(GameSettings.DRAW_MODE_DEFAULT);

            Point2I selectedTileLocation = GetSelectedTileLocation();

            // Draw the tileset.
            g.Clear(Color.White);
            g.Translate(-this.HorizontalScroll.Value, -this.VerticalScroll.Value);
            if (Tileset.SpriteSheet == null)
            {
                // Draw each tile's sprite seperately.
                for (int y = 0; y < Tileset.Height; y++)
                {
                    for (int x = 0; x < Tileset.Width; x++)
                    {
                        BaseTileData tileData = Tileset.GetTileData(x, y);
                        if (tileData != null)
                        {
                            int             spacing = 1;
                            Vector2F        drawPos = new Vector2F(x, y) * (Tileset.CellSize + spacing);
                            SpriteAnimation spr     = tileData.Sprite;

                            int imageVariantID = tileData.Properties.GetInteger("image_variant", Zone.ImageVariantID);
                            if (imageVariantID < 0)
                            {
                                imageVariantID = Zone.ImageVariantID;
                            }
                            if (spr.IsAnimation)
                            {
                                int substripIndex = tileData.Properties.GetInteger("substrip_index", 0);
                                spr.Animation = spr.Animation.GetSubstrip(substripIndex);
                            }

                            g.DrawAnimation(tileData.Sprite, imageVariantID, 0.0f, drawPos, Color.White);
                        }
                    }
                }
            }
            else
            {
                // Draw the spritesheet's image.
                g.Translate(-Tileset.SpriteSheet.Offset);
                g.DrawImage(Tileset.SpriteSheet.Image.GetVariant(Zone.ImageVariantID), Point2I.Zero);
                g.ResetTranslation();
            }


            // Draw the selection box.
            if (selectedTileLocation >= Point2I.Zero)
            {
                Point2I tilePoint = selectedTileLocation * (Tileset.CellSize + Tileset.Spacing);
                g.Translate(-this.HorizontalScroll.Value, -this.VerticalScroll.Value);
                g.DrawRectangle(new Rectangle2I(tilePoint, Tileset.CellSize + 1), 1, Color.White);
                g.DrawRectangle(new Rectangle2I(tilePoint + 1, Tileset.CellSize - 1), 1, Color.Black);
                g.DrawRectangle(new Rectangle2I(tilePoint - 1, Tileset.CellSize + 3), 1, Color.Black);
                g.ResetTranslation();
            }

            g.End();
        }
Example #13
0
        /// <inheritdoc />
        protected override void Draw2D(Graphics2D graphics)
        {
            base.Draw2D(graphics);

            if (!_enabled)
            {
                return;
            }

            RectangleF targetRectFull;

            switch (_currentType)
            {
            case PerformanceDrawingLayerType.FramesPerSecond:

                // Get display text
                var fpsText = "-";
                if (_lastRender != DateTime.MinValue)
                {
                    _lastTimeSpans.Add(DateTime.UtcNow - _lastRender);
                    while (_lastTimeSpans.Count > 30)
                    {
                        _lastTimeSpans.RemoveAt(0);
                    }

                    var averageTime = _lastTimeSpans
                                      .Select(actTimeSpan => actTimeSpan.TotalMilliseconds)
                                      .Average();
                    fpsText = Math.Round(1000f / averageTime, 0).ToString(CultureInfo.InvariantCulture);
                }
                _lastRender = DateTime.UtcNow;

                // Render display text
                targetRectFull = new RectangleF(
                    graphics.ScreenWidth - 120f, 10f + _verticalPadding, 100f, 22f);
                graphics.FillRectangle(targetRectFull, _backBrush);
                graphics.DrawRectangle(targetRectFull, _borderBrush);
                graphics.DrawText($"FPS: {fpsText}", _textFormatCentered, targetRectFull, _foreBrush, DrawTextOptions.Clip);
                break;

            case PerformanceDrawingLayerType.PressedKeys:

                // Build display text
                var stringBuilder = new StringBuilder(16);
                foreach (var actKeyDown in _keysDown)
                {
                    if (stringBuilder.Length > 0)
                    {
                        stringBuilder.Append(", ");
                    }
                    stringBuilder.Append(actKeyDown.ToString());
                }

                // Render background for display text
                targetRectFull = new RectangleF(
                    graphics.ScreenWidth - 220f, 10f + _verticalPadding, 200f, 66f);
                graphics.FillRectangle(targetRectFull, _backBrush);
                graphics.DrawRectangle(targetRectFull, _borderBrush);

                // Render header
                var targetRectHeader = targetRectFull;
                targetRectHeader.Height -= 44f;
                targetRectHeader.Inflate(-3f, -3f);
                graphics.DrawText("Keys down:", _textFormatLeftAligned, targetRectHeader, _foreBrush);

                // Render content area
                var targetRectContent = targetRectFull;
                targetRectContent.Height -= 22f;
                targetRectContent.Y      += 22f;
                targetRectContent.Inflate(-3f, -3f);
                graphics.DrawText(stringBuilder.ToString(), _textFormatLeftAligned, targetRectContent, _foreBrush);
                break;
            }
        }
Example #14
0
        public override void Draw()
        {
            // draw bg
            Graphics2D.FillRectangle(bounds, Color.gray32);

            // draw input indicator
            tick++;
            if (tick > 40)
            {
                if (!MSPS2.moving && KBPS2.currentKey == null)
                {
                    inCol = Color.white;
                }
                tick = 0;
            }

            if (MSPS2.moving && KBPS2.currentKey == null)
            {
                inCol = Color.orange;
            }
            if (!MSPS2.moving && KBPS2.currentKey != null)
            {
                inCol = Color.limeGreen;
            }
            if (MSPS2.moving && KBPS2.currentKey != null)
            {
                inCol = Color.teal;
            }

            Graphics2D.DrawChar(width - 84, 7, '!', inCol, Fonts.FONT_SYMBOLS);

            // draw running apps
            int xx = 26, yy = 2, ww = 76, hh = 18;

            for (int i = 0; i < ProcessManager.windows.Count; i++)
            {
                Window proc = ProcessManager.windows[i];

                int tw = Fonts.FONT_MONO.StringWidth(proc.name) + 16;
                if (ww < tw)
                {
                    ww = tw;
                }
                Rectangle btn = new Rectangle(xx, yy, ww, hh);
                uint      ic  = Color.silver;

                if (btn.Contains(MSPS2.position))
                {
                    ic = Color.darkOrange;
                    if (MSPS2.state == Cosmos.System.MouseState.Left && proc.minimizeBox)
                    {
                        if (!btnClick)
                        {
                            if (ProcessManager.selWindowID != proc.id)
                            {
                                ProcessManager.selWindowID = proc.id;
                            }
                            else
                            {
                                if (proc.state != WindowState.minimized)
                                {
                                    proc.SetState(WindowState.minimized);
                                }
                                else
                                {
                                    proc.SetState(proc.prevState);
                                }
                            }

                            btnClick = true;
                        }
                        ic = Color.brown;
                    }
                }
                if (MSPS2.state == Cosmos.System.MouseState.None)
                {
                    btnClick = false;
                }
                // draw btn
                Graphics2D.DrawRectangle(btn, 1, ic);

                string txt = ProcessManager.windows[i].title;
                if (txt.Length > 9)
                {
                    txt = txt.Substring(0, 7) + "..";
                }

                Graphics2D.DrawString(xx + 8, yy + 4, ProcessManager.windows[i].title, ic, Fonts.FONT_MONO);

                // inc pos
                xx += ww + 4;
            }
        }
Example #15
0
        /** <summary> Draws the debug menu. </summary> */
        private void DrawMenu(Graphics2D g, DebugMenuItem item, int pathIndex, Point2I position)
        {
            if (pathIndex >= currentPath.Count)
            {
                return;
            }

            int itemWidth         = 32;
            int itemHeight        = 28;
            int offset            = 32;
            int textOffset        = 0;
            int hotkeyOffset      = 0;
            int hotkeyColumnWidth = 0;
            int textColumnWidth   = 0;
            int rightPading       = 24;
            //int padding = 20;
            int hotkeyColumnPadding = 20;

            if (pathIndex == 0)
            {
                offset              = 6;
                rightPading         = 8;
                hotkeyColumnPadding = 0;
            }

            // Measure the width to draw the menu at.
            for (int i = 0; i < item.Items.Count; ++i)
            {
                DebugMenuItem subItem = item.Items[i];

                Rectangle2I r1 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.Text, Align.Left);
                Rectangle2I r2 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.HotKey.Name, Align.Left);
                hotkeyOffset      = GMath.Max(hotkeyOffset, r1.Width + offset + 10);
                itemWidth         = GMath.Max(itemWidth, r1.Width + r2.Width + offset + rightPading);
                textColumnWidth   = GMath.Max(textColumnWidth, r1.Width);
                hotkeyColumnWidth = GMath.Max(hotkeyColumnWidth, r2.Width);
            }
            hotkeyOffset = offset + textColumnWidth + hotkeyColumnPadding;
            textOffset   = offset;
            itemWidth    = offset + textColumnWidth + hotkeyColumnPadding + hotkeyColumnWidth + rightPading;


            // Draw outline.
            Rectangle2I menuRect = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight * item.Items.Count);

            if (pathIndex == 0)
            {
                menuRect.Width  = itemWidth * item.Items.Count;
                menuRect.Height = itemHeight;
            }
            g.DrawRectangle(menuRect, 1.0f, colorOutline);

            // Draw background.
            menuRect.Inflate(-1, -1);
            g.FillRectangle(menuRect, colorBackground);

            // Draw item list.
            for (int i = 0; i < item.Items.Count; ++i)
            {
                Rectangle2I r = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight);

                if (pathIndex == 0)
                {
                    r.Inflate(0, -1);
                    if (i == 0)
                    {
                        r.X     += 1;
                        r.Width -= 1;
                    }
                    if (i == item.Items.Count - 1)
                    {
                        r.Width -= 1;
                    }
                }
                else
                {
                    r.Inflate(-1, 0);
                    if (i == 0)
                    {
                        r.Y      += 1;
                        r.Height -= 1;
                    }
                    if (i == item.Items.Count - 1)
                    {
                        r.Height -= 1;
                    }
                }

                DebugMenuItem subItem = item.Items[i];

                // Draw highlight.
                if (currentPath[pathIndex] == i)
                {
                    Rectangle2F sr = (Rectangle2I)r;
                    sr.Inflate(-2, -2);
                    if (controlMode == MenuControlMode.Keyboard || controlMode == MenuControlMode.GamePad || pathIndex < currentPath.Count - 1)
                    {
                        g.FillRectangle(sr, colorBackgroundHighlight);
                    }
                }
                Point2I ms = (Point2I)Mouse.GetPosition();
                if (r.Contains(ms))
                {
                    mouseHover     = true;
                    mouseHoverItem = subItem;
                    Rectangle2F sr = (Rectangle2I)r;
                    sr.Inflate(-2, -2);
                    if (controlMode == MenuControlMode.Mouse)
                    {
                        g.FillRectangle(sr, colorBackgroundHighlight);
                    }
                }

                // Draw text label.
                string text   = subItem.Text;
                string hotkey = subItem.HotKey.Name;
                g.DrawRealString(debugMenuFont, text, new Point2I(r.Min.X + textOffset, (int)r.Center.Y), Align.Left | Align.Int, colorText);
                g.DrawRealString(debugMenuFont, hotkey, new Point2I(r.Min.X + hotkeyOffset, (int)r.Center.Y), Align.Left | Align.Int, colorHotkey);

                // Draw toggle check.
                if (subItem is ToggleMenuItem)
                {
                    bool     enabled = ((ToggleMenuItem)subItem).IsEnabled;
                    SpriteEx spr     = debugMenuSprites["checkbox_disabled"];
                    if (enabled)
                    {
                        spr = debugMenuSprites["checkbox_enabled"];
                    }
                    if (subItem is RadioButtonMenuItem)
                    {
                        spr = debugMenuSprites["radiobutton_disabled"];
                        if (enabled)
                        {
                            spr = debugMenuSprites["radiobutton_enabled"];
                        }
                    }
                    g.DrawSpriteEx(spr, new Vector2F(r.Min.X + 6, r.Min.Y + 6), colorText);
                }

                // Draw submenu arrow.
                if (item != menu && subItem.Items.Count > 0)
                {
                    g.DrawSpriteEx(debugMenuSprites["submenu_arrow"], new Vector2F(r.Max.X - 18, r.Min.Y + 6), colorArrow);
                }

                // Draw nested menu.
                if (currentPath[pathIndex] == i)
                {
                    Point2I p = position;
                    if (pathIndex == 0)
                    {
                        p.Y += itemHeight - 1;
                    }
                    else
                    {
                        p.X += itemWidth - 1;
                    }

                    DrawMenu(g, subItem, pathIndex + 1, p);
                }

                // Move current position.
                if (pathIndex == 0)
                {
                    position.X += itemWidth;
                }
                else
                {
                    position.Y += itemHeight;
                }
            }
        }