Пример #1
0
        private void drawText()
        {
            if (DisplayInfoText && !String.IsNullOrEmpty(InfoText))
            {
                //SharpDX.Rectangle size = infoFont.MeasureText(null, InfoText, FontDrawFlags.Left);
                //Rectangle.

                //AABBGGRR
                infoFont.DrawText(null, InfoText, 5, 0, SharpDX.ColorBGRA.FromRgba(0xFFFFFFFF));
            }

            if (DisplaySubtitles && SubtitleItem != null && SubtitleItem.Lines.Count > 0)
            {
                String lines = SubtitleItem.Lines[0];
                for (int i = 1; i < SubtitleItem.Lines.Count; i++)
                {
                    lines += "\n" + SubtitleItem.Lines[i];
                }

                SharpDX.Rectangle fontRect = subtitleFont.MeasureText(null, lines, FontDrawFlags.Center);

                fontRect.X = backBuffer.Description.Width / 2 + fontRect.X;
                fontRect.Y = videoDestRect.BottomLeft.Y - fontRect.Height - subtitleBottomMargin;

                SharpDX.Rectangle shadowRect = new SharpDX.Rectangle(fontRect.X + subtitleShadowOffset, fontRect.Y + subtitleShadowOffset, fontRect.Width, fontRect.Height);

                subtitleFont.DrawText(null, lines, shadowRect, FontDrawFlags.Center, SharpDX.ColorBGRA.FromRgba(0xCC000000));
                subtitleFont.DrawText(null, lines, fontRect, FontDrawFlags.Center, SharpDX.ColorBGRA.FromRgba(0xFFF9FBFB));
            }
        }
Пример #2
0
        /// <summary>
        ///     Draws the tooltip button.
        /// </summary>
        /// <param name="position">
        ///     The position.
        /// </param>
        /// <param name="item">
        ///     The item.
        /// </param>
        internal static void DrawToolTipButton(Vector2 position, MenuItem item)
        {
            if (item.ValueType == MenuValueType.StringList)
            {
                return;
            }

            const string S = "[?]";
            var          x = (int)item.Position.X + item.Width - item.Height - Font.MeasureText(S).Width - 7;

            Font.DrawText(
                null,
                S,
                new Rectangle(x, (int)item.Position.Y, item.Width, item.Height),
                FontDrawFlags.VerticalCenter,
                new ColorBGRA(255, 255, 255, 255));
        }
Пример #3
0
		public static void DrawText(Font font, string text, int posX, int posY, Color color)
		{
			Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
			font.DrawText(null, text, posX + 1 + rec.X, posY + 1, Color.Black);
			font.DrawText(null, text, posX + rec.X, posY + 1, Color.Black);
			font.DrawText(null, text, posX - 1 + rec.X, posY - 1, Color.Black);
			font.DrawText(null, text, posX + rec.X, posY - 1, Color.Black);
			font.DrawText(null, text, posX + rec.X, posY, color);
		}
Пример #4
0
        public static void DrawText1(SharpDX.Direct3D9.Font font, String text, int posX, int posY, SharpDX.Color color)
        {
            Rectangle rec = font.MeasureText(null, text, SharpDX.Direct3D9.FontDrawFlags.Center);

            font.DrawText(null, text, posX + 1 + rec.X, posY + 1, SharpDX.Color.Black);
            font.DrawText(null, text, posX + rec.X, posY + 1, SharpDX.Color.Black);
            font.DrawText(null, text, posX - 1 + rec.X, posY - 1, SharpDX.Color.Black);
            font.DrawText(null, text, posX + rec.X, posY - 1, SharpDX.Color.Black);
            font.DrawText(null, text, posX + rec.X, posY, color);
        }
Пример #5
0
		private static Rectangle GetMeasured(Font font, string text) {
			Rectangle rec;
			var key = font.Description.FaceName + font.Description.Width + font.Description.Height +
					  font.Description.Weight + text;
			if (!Measured.TryGetValue(key, out rec))
			{
				rec = font.MeasureText(null, text, FontDrawFlags.Center);
				Measured.Add(key, rec);
			}
			return rec;
		}
Пример #6
0
        /// <summary>
        ///     Fired when the scene is completely rendered.
        /// </summary>
        /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void Drawing_OnEndScene(EventArgs args)
        {
            if (!getCheckBoxItem(this.Menu, "DrawHealth_"))
            {
                return;
            }

            float i = 0;

            foreach (var hero in HeroManager.Enemies.Where(x => !x.IsDead))
            {
                var champion = hero.ChampionName;
                if (champion.Length > 12)
                {
                    champion = champion.Remove(7) + "...";
                }


                var championInfo = getCheckBoxItem(this.Menu, "DrawHealth_percent")
                    ? champion + " (" + (int)hero.HealthPercent + "%)"
                    : champion;

                // Draws the championnames
                Font.DrawText(
                    null,
                    championInfo,
                    (int)
                    ((Drawing.Width - this.HudOffsetRight - this.HudOffsetText - Font.MeasureText(null, championInfo, FontDrawFlags.Left).Width)),
                    (int)(this.HudOffsetTop + i + 4 - Font.MeasureText(null, championInfo, FontDrawFlags.Left).Height / 2f),
                    hero.HealthPercent > 0 ? new ColorBGRA(255, 255, 255, 255) : new ColorBGRA(244, 8, 8, 255));

                // Draws the rectangle
                this.DrawRect(
                    Drawing.Width - this.HudOffsetRight,
                    this.HudOffsetTop + i,
                    100,
                    this.BarHeight,
                    1,
                    Color.FromArgb(255, 51, 55, 51));

                // Fils the rectangle
                this.DrawRect(
                    Drawing.Width - this.HudOffsetRight,
                    this.HudOffsetTop + i,
                    hero.HealthPercent <= 0 ? 100 : (int)(hero.HealthPercent),
                    this.BarHeight,
                    1,
                    hero.HealthPercent < 30 && hero.HealthPercent > 0 ? Color.FromArgb(255, 230, 169, 14) : hero.HealthPercent <= 0 ? Color.FromArgb(255, 206, 20, 30) : Color.FromArgb(255, 29, 201, 38));

                i += 20f + this.HudSpacing;
            }
        }
Пример #7
0
        private static Rectangle GetMeasured(Font font, string text)
        {
            Rectangle rec;
            var       key = font.Description.FaceName + font.Description.Width + font.Description.Height +
                            font.Description.Weight + text;

            if (!Measured.TryGetValue(key, out rec))
            {
                rec = font.MeasureText(null, text, FontDrawFlags.Center);
                Measured.Add(key, rec);
            }
            return(rec);
        }
Пример #8
0
        //TODO: Too many drawtext for shadowtext, need another method fps issues
        public static void DrawText(Font font, String text, int posX, int posY, SharpDX.Color color)
        {
            if (font == null || font.IsDisposed)
            {
                throw new SharpDXException("");
            }
            Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);

            //font.DrawText(null, text, posX + 1 + rec.X, posY, Color.Black);
            font.DrawText(null, text, posX + 1 + rec.X, posY + 1, SharpDX.Color.Black);
            font.DrawText(null, text, posX + rec.X, posY + 1, SharpDX.Color.Black);
            //font.DrawText(null, text, posX - 1 + rec.X, posY, Color.Black);
            font.DrawText(null, text, posX - 1 + rec.X, posY - 1, SharpDX.Color.Black);
            font.DrawText(null, text, posX + rec.X, posY - 1, SharpDX.Color.Black);
            font.DrawText(null, text, posX + rec.X, posY, color);
        }
Пример #9
0
        /// <summary>
        ///     Fired when the scene is completely rendered.
        /// </summary>
        /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void Drawing_OnEndScene(EventArgs args)
        {
            if (!getCheckBoxItem("DrawHealth_"))
            {
                return;
            }

            float i = 0;

            foreach (var hero in HeroManager.Enemies)
            {
                var champion = hero.ChampionName;
                if (champion.Length > 12)
                {
                    champion = champion.Remove(7) + "...";
                }

                Font.DrawText(
                    null,
                    champion,
                    (int)
                    ((float)(Drawing.Width - HudOffsetRight) - 60f
                     - Font.MeasureText(null, champion, FontDrawFlags.Right).Width / 2f),
                    (int)
                    (HudOffsetTop + i + 4
                     - Font.MeasureText(null, champion, FontDrawFlags.Right).Height / 2f),
                    hero.HealthPercent > 0 ? new ColorBGRA(255, 255, 255, 255) : new ColorBGRA(244, 8, 8, 255));

                this.DrawRect(
                    Drawing.Width - HudOffsetRight,
                    HudOffsetTop + i,
                    100,
                    this.BarHeight,
                    1,
                    Color.FromArgb(255, 51, 55, 51));

                this.DrawRect(
                    Drawing.Width - HudOffsetRight,
                    HudOffsetTop + i,
                    hero.HealthPercent <= 0 ? 100 : (int)(hero.HealthPercent),
                    this.BarHeight,
                    1,
                    hero.HealthPercent < 30 && hero.HealthPercent > 0 ? Color.FromArgb(255, 230, 169, 14) : hero.HealthPercent <= 0 ? Color.FromArgb(255, 206, 20, 30) : Color.FromArgb(255, 29, 201, 38));

                i += 20f + this.HudSpacing;
            }
        }
Пример #10
0
        /// <summary>
        ///     Fired when the game is loaded.
        /// </summary>
        /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
        private static void Game_OnGameLoad(EventArgs args)
        {
            CreateMenu();

            var heroes      = ObjectManager.Get <Obj_AI_Hero>();
            var objAiHeroes = heroes as Obj_AI_Hero[] ?? heroes.ToArray();

            Allies  = objAiHeroes.Where(x => x.IsAlly);
            Enemies = objAiHeroes.Where(x => x.IsEnemy);

            Status = CalcStatus.NoEnemies;

            BoxLine  = new Line(Drawing.Direct3DDevice);
            TextFont = new Font(
                Drawing.Direct3DDevice,
                new FontDescription
            {
                FaceName        = "Tahoma",
                Height          = 14,
                OutputPrecision = FontPrecision.Default,
                Quality         = FontQuality.Antialiased
            });
            Sprite = new Sprite(Drawing.Direct3DDevice);

            IndicatorSprite = new Render.Sprite(Resources.Green_Check, IndicatorPosition);
            IndicatorSprite.PositionUpdate  += () => IndicatorPosition;
            IndicatorSprite.VisibleCondition =
                sender => Status != CalcStatus.NoEnemies && DrawCalculation;
            IndicatorSprite.Scale = new Vector2(0.4f);
            IndicatorSprite.Add();

            TextHeightSpacing = TextFont.MeasureText(Sprite, "A").Height + 10;

            GreenBitmap = Resources.Green_Check;
            RedBitmap   = Resources.Red_X;

            Game.PrintChat(
                "<font color=\"#7CFC00\"><b>Team Fight Calculator:</b></font> by ChewyMoon loaded. The UI only shows when there is enemies! (for now)");

            Drawing.OnDraw      += Drawing_OnDraw;
            Drawing.OnPreReset  += Drawing_OnPreReset;
            Drawing.OnPostReset += DrawingOnOnPostReset;
            Game.OnWndProc      += Game_OnWndProc;
            Game.OnUpdate       += GameOnOnUpdate;
        }
Пример #11
0
 public static void DrawText(Font font, String text, int posX, int posY, Color color)
 {
     if (font == null || font.IsDisposed)
     {
         throw new SharpDXException("");
         return;
     }
     Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
     font.DrawText(null, text, posX + 1 + rec.X, posY, Color.Black);
     font.DrawText(null, text, posX + 1 + rec.X, posY + 1, Color.Black);
     font.DrawText(null, text, posX + rec.X, posY + 1, Color.Black);
     font.DrawText(null, text, posX - 1 + rec.X, posY, Color.Black);
     font.DrawText(null, text, posX - 1 + rec.X, posY - 1, Color.Black);
     font.DrawText(null, text, posX + rec.X, posY - 1, Color.Black);
     font.DrawText(null, text, posX + rec.X, posY, color);
 }
Пример #12
0
 public Rectangle GetTextRectangle()
 {
     return(Font?.MeasureText(null, Message, FontDrawFlags.Right) ?? Rectangle.Empty);
 }
Пример #13
0
 public UpvoteItem(string name)
 {
     _text = string.Format("Please consider to upvote {0} in the Assembly Database.", name);
     _font = new Font(
         Drawing.Direct3DDevice,
         new FontDescription
         {
             FaceName = "Calibri",
             Height = 20,
             OutputPrecision = FontPrecision.Default,
             Quality = FontQuality.Default
         });
     _measured = _font.MeasureText(null, _text, FontDrawFlags.Center);
     _line = new Line(Drawing.Direct3DDevice) { Width = _measured.Height + (Padding * 2) };
 }
Пример #14
0
        /// <summary>
        ///     Formats the given text into lines.
        /// </summary>
        /// <param name="value">
        ///     The value.
        /// </param>
        /// <param name="htmlSupport">
        ///     Indicates whether to support HTML tags.
        /// </param>
        /// <returns>
        ///     The formatted list.
        /// </returns>
        public List <string> FormatText(string value, bool htmlSupport)
        {
            var lines     = (BodyFont.MeasureText(Sprite, value, 0).Width / MaximumBodyLineLength) + 1;
            var lastIndex = 0;
            var format    = false;
            var linesList = new List <string>();

            if (value.Contains("</br>") && htmlSupport)
            {
                lines = 0;
                var formatLines = new List <string>();
                var valueCopy   = value;
                while (valueCopy.Contains("</br>"))
                {
                    var breakLine = valueCopy.Substring(0, valueCopy.IndexOf("</br>", StringComparison.Ordinal));
                    ++lines;
                    formatLines.Add(!string.IsNullOrEmpty(breakLine) ? breakLine : string.Empty);

                    valueCopy = valueCopy.Substring(
                        valueCopy.IndexOf("</br>", StringComparison.Ordinal) + 5,
                        valueCopy.Length - valueCopy.IndexOf("</br>", StringComparison.Ordinal) - 5);
                }

                formatLines.Add(string.IsNullOrEmpty(valueCopy) ? " " : valueCopy);
                this.BodyHeight += BodyFont.Description.Height;

                foreach (var line in formatLines)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        linesList.Add(" ");
                        this.BodyHeight += BodyFont.Description.Height;
                        continue;
                    }

                    for (var j = line.Length; j > -1; --j)
                    {
                        if (j - 1 > -1 && line.Length - lastIndex - j >= 0 &&
                            BodyFont.MeasureText(Sprite, line.Substring(lastIndex, line.Length - lastIndex - j), 0)
                            .Width < MaximumBodyLineLength)
                        {
                            continue;
                        }

                        var original = line.Substring(lastIndex, line.Length - lastIndex - j);

                        if (!string.IsNullOrEmpty(original))
                        {
                            linesList.Add(original);
                        }

                        lastIndex = line.Length - j;
                    }

                    lastIndex = 0;
                }

                format = true;
            }

            if (!format)
            {
                for (var j = value.Length; j > -1; --j)
                {
                    if (j - 1 > -1 && value.Length - lastIndex - j >= 0 &&
                        BodyFont.MeasureText(Sprite, value.Substring(lastIndex, value.Length - lastIndex - j), 0)
                        .Width < MaximumBodyLineLength)
                    {
                        continue;
                    }

                    var original = value.Substring(lastIndex, value.Length - lastIndex - j);

                    if (!string.IsNullOrEmpty(original))
                    {
                        linesList.Add(original);
                    }

                    lastIndex = value.Length - j;
                }
            }

            if (lines > 4)
            {
                this.BodyHeight += BodyFont.Description.Height * (lines - 4);
            }

            return(linesList);
        }
Пример #15
0
        /// <summary>
        /// Fired when everything has been drawn.
        /// </summary>
        /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="Exception">[PermaShow] - MenuItem not supported</exception>
        private static void Drawing_OnEndScene(EventArgs args)
        {
            if (Drawing.Direct3DDevice == null || Drawing.Direct3DDevice.IsDisposed)
            {
                return;
            }

            if (!placetosave.Item("enablepermashow").GetValue <bool>())
            {
                Unsub();
                return;
            }

            PermaArea();

            var halfwidth = 0.96f * (PermaShowWidth / 2);

            var baseposition = new Vector2(BoxPosition.X - halfwidth, BoxPosition.Y);

            var boxx = BoxPosition.X + (PermaShowWidth / 2) - (SmallBoxWidth / 2);

            foreach (var permaitem in PermaShowItems)
            {
                var index  = PermaShowItems.IndexOf(permaitem);
                var boxpos = new Vector2(boxx,
                                         baseposition.Y + (Text.Description.Height * 1.2f * index));
                var endpos  = new Vector2(BoxPosition.X + (PermaShowWidth / 2), baseposition.Y + (Text.Description.Height * 1.2f * index));
                var itempos = new Vector2(baseposition.X, baseposition.Y + (Text.Description.Height * 1.2f * index));

                int textpos = (int)(endpos.X - (SmallBoxWidth / 1.2f));

                switch (permaitem.Item.ValueType)
                {
                case MenuValueType.Boolean:
                    DrawBox(boxpos, permaitem.Item.GetValue <bool>());
                    Text.DrawText(null, permaitem.DisplayName + ":",
                                  (int)itempos.X, (int)itempos.Y, permaitem.Color);
                    Text.DrawText(null, permaitem.Item.GetValue <bool>().ToString(),
                                  textpos, (int)itempos.Y, permaitem.Color);
                    break;

                case MenuValueType.Slider:
                    Text.DrawText(null, permaitem.DisplayName + ":",
                                  (int)itempos.X, (int)itempos.Y, permaitem.Color);
                    Text.DrawText(null, permaitem.Item.GetValue <Slider>().Value.ToString(),
                                  textpos, (int)itempos.Y, permaitem.Color);
                    break;

                case MenuValueType.KeyBind:
                    DrawBox(boxpos, permaitem.Item.GetValue <KeyBind>().Active);
                    Text.DrawText(null,
                                  permaitem.DisplayName + " [" + Utils.KeyToText(permaitem.Item.GetValue <KeyBind>().Key) + "] :", (int)itempos.X, (int)itempos.Y,
                                  permaitem.Color);

                    Text.DrawText(null,
                                  permaitem.Item.GetValue <KeyBind>().Active.ToString(), textpos, (int)(boxpos.Y),
                                  permaitem.Color);
                    break;

                case MenuValueType.StringList:
                    Text.DrawText(null,
                                  permaitem.DisplayName + ":",
                                  (int)itempos.X, (int)itempos.Y, permaitem.Color);
                    var dimen = Text.MeasureText(sprite, permaitem.Item.GetValue <StringList>().SelectedValue);
                    Text.DrawText(null, permaitem.Item.GetValue <StringList>().SelectedValue,
                                  (int)(textpos + dimen.Width < endpos.X ? textpos : endpos.X - dimen.Width), (int)itempos.Y, permaitem.Color);
                    break;

                case MenuValueType.Integer:
                    Text.DrawText(null, permaitem.DisplayName + ":",
                                  (int)itempos.X, (int)itempos.Y, permaitem.Color);
                    Text.DrawText(null, permaitem.Item.GetValue <int>().ToString(),
                                  textpos, (int)itempos.Y, permaitem.Color);
                    break;

                case MenuValueType.None:
                    break;

                default:
                    throw new Exception("[PermaShow] - MenuItem not supported");
                }
            }
        }
Пример #16
0
 /// <summary>
 ///     Calculates the center position for the given text on within a rectangle boundaries.
 /// </summary>
 /// <param name="rectangle">Rectangle boundaries</param>
 /// <param name="sprite">Sprite which is being drawn on</param>
 /// <param name="font">Text Font</param>
 /// <param name="text">The Text</param>
 /// <param name="flags">Centered Flags</param>
 /// <returns>Returns the center position of the text on the rectangle.</returns>
 public static Vector2 GetCenteredText(
     this Rectangle rectangle, 
     Sprite sprite, 
     Font font, 
     string text, 
     CenteredFlags flags)
 {
     return font == null
                ? rectangle.GetCenteredText(sprite, text, flags)
                : rectangle.GetCenter(sprite, font.MeasureText(sprite, text, 0), flags);
 }
Пример #17
0
        /*
         * public void Draw()
         * {
         *  if (Font == null || Font.IsDisposed || Device == null || Device.IsDisposed || Height < 1 || string.IsNullOrEmpty(Message))
         *      return;
         *
         *  using (this)
         *  {
         *      Font.DrawText(null, Message, X, Y, Color);
         *  }
         * }*/

        public SharpDX.Rectangle GetTextRectangle()
        {
            return(Font.MeasureText(null, Message, FontDrawFlags.Right));
        }
Пример #18
0
 public static void DrawText(Font font, String text, int posX, int posY, Color color)
 {
     Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
     font.DrawText(null, text, posX + 1 + rec.X, posY + 1, SharpColor.White);
 }
Пример #19
0
        static void Main()
        {
            var form = new RenderForm("SharpDX - Direct3D9 Font Sample");
            int width = form.ClientSize.Width;
            int height = form.ClientSize.Height;
            var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });

            // Initialize the Font
            FontDescription fontDescription = new FontDescription()
            {
                Height = 72,
                Italic = false,
                CharacterSet = FontCharacterSet.Ansi,
                FaceName = "Arial",
                MipLevels = 0,
                OutputPrecision = FontPrecision.TrueType,
                PitchAndFamily = FontPitchAndFamily.Default,
                Quality = FontQuality.ClearType,
                Weight = FontWeight.Bold
            };



            var font = new Font(device, fontDescription);

            var displayText = "Direct3D9 Text!";

            // Measure the text to display
            var fontDimension = font.MeasureText(null, displayText, new Rectangle(0, 0, width, height), FontDrawFlags.Center | FontDrawFlags.VerticalCenter);

            int xDir = 1;
            int yDir = 1;

            RenderLoop.Run(form, () =>
            {
                device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
                device.BeginScene();

                // Make the text boucing on the screen limits
                if ((fontDimension.Right + xDir) > width)
                    xDir = -1;
                else if ((fontDimension.Left + xDir) <= 0)
                    xDir = 1;

                if ((fontDimension.Bottom + yDir) > height)
                    yDir = -1;
                else if ((fontDimension.Top + yDir) <= 0)
                    yDir = 1;

                fontDimension.Left += (int)xDir;
                fontDimension.Top += (int)yDir;
                fontDimension.Bottom += (int)yDir;
                fontDimension.Right += (int)xDir;

                // Draw the text
                font.DrawText(null, displayText, fontDimension, FontDrawFlags.Center | FontDrawFlags.VerticalCenter, Color.White);

                device.EndScene();
                device.Present();
            });
        }
Пример #20
0
        public static void DrawText(Font font, String text, int posX, int posY, Color color)
        {
            Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);

            font.DrawText(null, text, posX + 1 + rec.X, posY + 1, SharpColor.White);
        }