Ejemplo n.º 1
0
        //TODO: hook setup & destroy graphics properly
        private void DrawGraphics(object sender, GameOverlay.Windows.DrawGraphicsEventArgs e)
        {
            lock (m_lock)
            {
                e.Graphics.ClearScene();

                if (!string.IsNullOrEmpty(m_text))
                {
                    GameOverlay.Drawing.Font  font     = e.Graphics.CreateFont("Calibri", 50, true);
                    GameOverlay.Drawing.Point textSize = e.Graphics.MeasureString(font, m_text);

                    int middleX = m_overlay.Width / 2;
                    int middleY = m_overlay.Height / 2;

                    double millisElapsed = DateTime.Now.Subtract(m_shownTime).TotalMilliseconds;
                    if (millisElapsed > c_fadeStartDelay + c_fadeMillis)
                    {
                        return;
                    }

                    //'flash' by not displaying immediately on keyboard input, makes it easier to see when different keys are pressed
                    if (millisElapsed < 30)
                    {
                        return;
                    }

                    float alpha = 1.0f;
                    if (millisElapsed > c_fadeStartDelay)
                    {
                        alpha = 1.0f - (float)((millisElapsed - c_fadeStartDelay) / c_fadeMillis);
                    }

                    var backColour = e.Graphics.CreateSolidBrush(0.6f, 0.6f, 0.6f, 0.85f * alpha);
                    var fontColour = e.Graphics.CreateSolidBrush(0f, 0f, 0f, alpha);

                    var rect = GameOverlay.Drawing.Rectangle.Create((int)(middleX - textSize.X / 2), (int)(middleY - textSize.Y / 2), (int)textSize.X, (int)textSize.Y);
                    Inflate(ref rect, c_paddingX, c_paddingY);

                    e.Graphics.FillRectangle(backColour, rect);
                    if (c_border > 0)
                    {
                        Inflate(ref rect, c_border / 2, c_border / 2);
                        e.Graphics.DrawRectangle(fontColour, rect, c_border);
                    }

                    e.Graphics.DrawText(font, fontColour, middleX - textSize.X / 2, middleY - textSize.Y / 2, m_text);
                }
            }
        }
Ejemplo n.º 2
0
        public MainUI()
        {
            InitializeComponent();

            // Set titlebar.
            this.Text += string.Format(" {0}", Program.srtVersion);

            this.ContextMenu = Program.contextMenu;
            this.playerHealthStatus.ContextMenu = Program.contextMenu;
            this.statisticsPanel.ContextMenu    = Program.contextMenu;
            this.inventoryPanel.ContextMenu     = Program.contextMenu;

            //GDI+
            this.playerHealthStatus.Paint += this.playerHealthStatus_Paint;
            this.statisticsPanel.Paint    += this.statisticsPanel_Paint;
            this.inventoryPanel.Paint     += this.inventoryPanel_Paint;

            // DirectX
            if (Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.DirectXOverlay))
            {
                overlay = new DXOverlay(Program.gameWindowHandle);
                overlay.Initialize((GameOverlay.Windows.OverlayWindow w, GameOverlay.Drawing.Graphics g) =>
                {
                    font       = g.CreateFont("Consolas", 8, true);
                    redBrush   = g.CreateSolidBrush(255, 0, 0);
                    whiteBrush = g.CreateSolidBrush(255, 255, 255);
                    greyBrush  = g.CreateSolidBrush(150, 150, 150);
                    blackBrush = g.CreateSolidBrush(0, 0, 0);

                    backBrushDirectX = g.CreateSolidBrush(60, 60, 60);
                    foreBrushDirectX = g.CreateSolidBrush(100, 0, 0);
                });
                overlay.Run(statisticsPanelDirectX_Paint, CancellationToken.None);
            }

            if (Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.NoTitleBar))
            {
                this.FormBorderStyle = FormBorderStyle.None;
            }

            if (Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.Transparent))
            {
                this.TransparencyKey = Color.Black;
            }

            // Only run the following code if we're rendering inventory.
            if (!Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.NoInventory))
            {
                GameMemory.GenerateImages();

                // Create a black slot image for when side-pack is not equipped.
                inventoryError = new Bitmap(Program.INV_SLOT_WIDTH, Program.INV_SLOT_HEIGHT, PixelFormat.Format32bppPArgb);
                using (Graphics grp = Graphics.FromImage(inventoryError))
                {
                    grp.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 0, 0)), 0, 0, inventoryError.Width, inventoryError.Height);
                    grp.DrawLine(new Pen(Color.FromArgb(150, 255, 0, 0), 3), 0, 0, inventoryError.Width, inventoryError.Height);
                    grp.DrawLine(new Pen(Color.FromArgb(150, 255, 0, 0), 3), inventoryError.Width, 0, 0, inventoryError.Height);
                }

                // Set the width and height of the inventory display so it matches the maximum items and the scaling size of those items.
                this.inventoryPanel.Width  = Program.INV_SLOT_WIDTH * 4;
                this.inventoryPanel.Height = Program.INV_SLOT_HEIGHT * 5;

                // Adjust main form width as well.
                this.Width = this.statisticsPanel.Width + 24 + this.inventoryPanel.Width;

                // Only adjust form height if its greater than 461. We don't want it to go below this size.
                if (41 + this.inventoryPanel.Height > 461)
                {
                    this.Height = 41 + this.inventoryPanel.Height;
                }
            }
            else
            {
                // Disable rendering of the inventory panel.
                this.inventoryPanel.Visible = false;

                // Adjust main form width as well.
                this.Width = this.statisticsPanel.Width + 2;
            }

            lastPtrUpdate  = DateTime.UtcNow.Ticks;
            lastFullUIDraw = DateTime.UtcNow.Ticks;
        }