当前位置: 首页>>代码示例>>C#>>正文


C# RenderingContext.MeasureString方法代码示例

本文整理汇总了C#中RenderingContext.MeasureString方法的典型用法代码示例。如果您正苦于以下问题:C# RenderingContext.MeasureString方法的具体用法?C# RenderingContext.MeasureString怎么用?C# RenderingContext.MeasureString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RenderingContext的用法示例。


在下文中一共展示了RenderingContext.MeasureString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Render

        public override void Render(RenderingContext rc, Dictionary<UiMountPoint, Vec2> mountPoints)
        {
            if (!Settings.ShowText || !alertsText.Any())
            {
                return;
            }

            Rect rect = model.Window.ClientRect();
            int xScreenCenter = rect.W / 2 + rect.X;
            int yPos = rect.H * Settings.YPosition / 100 + rect.Y;

            var playerPos = model.Player.GetComponent<Positioned>().GridPos;
            int fontSize = Settings.TextFontSize;
            bool first = true;
            Rect rectBackground = new Rect();
            foreach (var alert in alertsText)
            {
                int cntAlive = alert.Value.Count(c => c.IsAlive);
                if (cntAlive == 0)
                    continue;

                Vec2 textSize = rc.MeasureString(alert.Key, fontSize, DrawTextFormat.Center);

                int iconSize = 3 + textSize.Y;

                int xPos = xScreenCenter - textSize.X / 2 - 6;
                rc.AddTextWithHeight(new Vec2(xPos + 6, yPos), alert.Key, Color.Red, fontSize, DrawTextFormat.Left);

                int cntArrows = 1;
                rectBackground = new Rect(xPos - cntAlive * iconSize, yPos, textSize.X + 12 + cntAlive * iconSize, textSize.Y);
                if (first) // vertical padding above
                {
                    if( !Settings.StackUp)
                        rectBackground.Y -= 5;
                    rectBackground.H += 5;
                    first = false;
                }
                rc.AddBox(rectBackground, Color.FromArgb(Settings.TextBgAlpha, 1, 1, 1));

                foreach (EntityWrapper mob in alert.Value)
                {
                    if (!mob.IsAlive)
                        continue;
                    Vec2 delta = mob.GetComponent<Positioned>().GridPos - playerPos;
                    double phi;
                    double distance = delta.GetPolarCoordinates(out phi);
                    RectUV uv = GetDirectionsUv(phi, distance);

                    Rect rectDirection = new Rect(xPos - cntArrows * iconSize, yPos, rectBackground.H, rectBackground.H);
                    cntArrows++;
                    rc.AddSprite("directions.png", rectDirection, uv, Color.Red);
                }

                yPos += Settings.StackUp ? -textSize.Y : textSize.Y;
            }

            if (!first)  // vertical padding below
            {
                rectBackground.Y = rectBackground.Y + (Settings.StackUp ? - rectBackground.H - 5: rectBackground.H);
                rectBackground.H = 5;
                rc.AddBox(rectBackground, Color.FromArgb(Settings.TextBgAlpha, 1, 1, 1));
            }
        }
开发者ID:benjy3gg,项目名称:PoeHud,代码行数:63,代码来源:MonsterTracker.cs

示例2: Render

        public override void Render(RenderingContext rc, Dictionary<UiMountPoint, Vec2> mountPoints)
        {
            if (this.model.Player != null && this.model.Player.GetComponent<Player>().Level >= 100)
            {
                return;
            }
            if (!this.hasStarted)
            {
                this.startXp = this.model.Player.GetComponent<Player>().XP;
                this.startTime = DateTime.Now;
                this.lastCalcTime = DateTime.Now;
                this.hasStarted = true;
                return;
            }
            DateTime dtNow = DateTime.Now;
            TimeSpan delta = dtNow - this.lastCalcTime;

            if (delta.TotalSeconds > 1)
            {
                calculateRemainingExp(dtNow);
                this.lastCalcTime = dtNow;
            }

            int fontSize = Settings.FontSize;
            int bgAlpha = Settings.BgAlpha;

            Vec2 mapWithOffset = mountPoints[UiMountPoint.LeftOfMinimap];

            int yCursor = 0;
            Vec2 rateTextSize = rc.AddTextWithHeight(new Vec2(mapWithOffset.X, mapWithOffset.Y), this.curDisplayString, Color.White, fontSize, DrawTextFormat.Right);
            yCursor += rateTextSize.Y;
            Vec2 remainingTextSize = rc.AddTextWithHeight(new Vec2(mapWithOffset.X, mapWithOffset.Y + yCursor), this.curTimeLeftString, Color.White, fontSize, DrawTextFormat.Right);
            yCursor += remainingTextSize.Y;

            int thirdLine = mapWithOffset.Y + yCursor;

            int textWidth = Math.Max(rateTextSize.X, remainingTextSize.X) + 10;
            string strTimer = null;

            if (Settings.ShowZoneAndTimeSpent)
            {
                Vec2 areaLevelNote = rc.AddTextWithHeight(new Vec2(mapWithOffset.X, thirdLine), this.model.Area.CurrentArea.DisplayName, Color.White, fontSize, DrawTextFormat.Right);

                strTimer = AreaInstance.GetTimeString(dtNow - this.model.Area.CurrentArea.TimeEntered);
                Vec2 timerSize = rc.MeasureString(strTimer, fontSize, DrawTextFormat.Left);
                yCursor += areaLevelNote.Y;
                textWidth = Math.Max(textWidth, areaLevelNote.X + timerSize.X + 20 + 10);
            }

            Rect clientRect = model.Internal.IngameState.IngameUi.Minimap.SmallMinimap.GetClientRect();

            int width = Math.Max(textWidth, Math.Max(clientRect.W, 0/*this.overlay.PreloadAlert.Bounds.W*/));
            Rect rect = new Rect(mapWithOffset.X - width + 5, mapWithOffset.Y - 5, width, yCursor + 10);

            if( Settings.ShowClock)
                rc.AddTextWithHeight(new Vec2(rect.X + 5, mapWithOffset.Y), dtNow.ToShortTimeString(), Color.White, fontSize, DrawTextFormat.Left);

            if( Settings.ShowZoneAndTimeSpent)
                rc.AddTextWithHeight(new Vec2(rect.X + 5, thirdLine), strTimer, Color.White, fontSize, DrawTextFormat.Left);

            rc.AddBox(rect, Color.FromArgb(bgAlpha, 1, 1, 1));

            mountPoints[UiMountPoint.LeftOfMinimap] = new Vec2(mapWithOffset.X, mapWithOffset.Y + 5 + rect.H);
        }
开发者ID:benjy3gg,项目名称:PoeHud,代码行数:64,代码来源:XPHRenderer.cs

示例3: Render

        public override void Render(RenderingContext rc)
        {
            if (!Settings.GetBool("XphDisplay") || (this.poe.Player != null && this.poe.Player.GetComponent<Player>().Level >= 100))
            {
                return;
            }
            if (!this.hasStarted)
            {
                this.startXp = this.poe.Player.GetComponent<Player>().XP;
                this.startTime = DateTime.Now;
                this.lastCalcTime = DateTime.Now;
                this.hasStarted = true;
                return;
            }
            DateTime dtNow = DateTime.Now;
            TimeSpan delta = dtNow - this.lastCalcTime;

            if (delta.TotalSeconds > 1.0)
            {
                this.poe.Area.CurrentArea.AddTimeSpent(delta);
                calculateRemainingExp(dtNow);
                this.lastCalcTime = dtNow;
            }

            int fontSize = Settings.GetInt("XphDisplay.FontSize");
            int bgAlpha = Settings.GetInt("XphDisplay.BgAlpha");

            Rect clientRect = this.poe.Internal.IngameState.IngameUi.Minimap.SmallMinimap.GetClientRect();
            Vec2 mapWithOffset = new Vec2(clientRect.X - 10, clientRect.Y + 5);
            int yCursor = 0;
            Vec2 rateTextSize = rc.AddTextWithHeight(new Vec2(mapWithOffset.X, mapWithOffset.Y), this.curDisplayString, Color.White, fontSize, DrawTextFormat.Right);
            yCursor += rateTextSize.Y;
            Vec2 remainingTextSize = rc.AddTextWithHeight(new Vec2(mapWithOffset.X, mapWithOffset.Y + yCursor), this.curTimeLeftString, Color.White, fontSize, DrawTextFormat.Right);
            yCursor += remainingTextSize.Y;
            int thirdLine = mapWithOffset.Y + yCursor;
            Vec2 areaLevelNote = rc.AddTextWithHeight(new Vec2(mapWithOffset.X, thirdLine), this.poe.Area.CurrentArea.DisplayName, Color.White, fontSize, DrawTextFormat.Right);
            string strTimer = this.poe.Area.CurrentArea.TimeString;
            Vec2 timerSize = rc.MeasureString(strTimer, fontSize, DrawTextFormat.Left);
            yCursor += areaLevelNote.Y;

            int textWidth = Math.Max( Math.Max(rateTextSize.X, remainingTextSize.X), areaLevelNote.X + timerSize.X + 20 ) + 10;
            int width = Math.Max(textWidth, Math.Max(clientRect.W, this.overlay.PreloadAlert.Bounds.W));
            Rect rect = new Rect(mapWithOffset.X - width + 5, mapWithOffset.Y - 5, width, yCursor + 10);
            this.Bounds = rect;

            rc.AddTextWithHeight(new Vec2(rect.X + 5, mapWithOffset.Y), dtNow.ToShortTimeString(), Color.White, fontSize, DrawTextFormat.Left);
            rc.AddTextWithHeight(new Vec2(rect.X + 5, thirdLine), strTimer, Color.White, fontSize, DrawTextFormat.Left);

            rc.AddBox(rect, Color.FromArgb(bgAlpha, 1, 1, 1));
        }
开发者ID:sbradno,项目名称:PoeHud,代码行数:50,代码来源:XPHRenderer.cs


注:本文中的RenderingContext.MeasureString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。