Skip to content

File TimerBar.cs

File List > LemonUI > LemonUI > TimerBars > TimerBar.cs

Go to the documentation of this file


#if FIVEM
using CitizenFX.Core.UI;
#elif RAGEMP
using RAGE.Game;
#elif SHVDN3 || SHVDNC
using GTA.UI;
#endif
using System;
using LemonUI.Elements;
using System.Drawing;

namespace LemonUI.TimerBars
{
    public class TimerBar : IDrawable
    {
        #region Fields

        internal const float separation = 6.25f;
        internal const float backgroundWidth = 220;
        internal const float backgroundHeight = 37;

        protected internal readonly ScaledTexture background = new ScaledTexture("timerbars", "all_black_bg")
        {
            Color = Color.FromArgb(160, 255, 255, 255)
        };
        protected internal readonly ScaledText title = new ScaledText(PointF.Empty, string.Empty, 0.29f)
        {
            Alignment = Alignment.Right,
            WordWrap = 1000
        };
        protected internal readonly ScaledText info = new ScaledText(PointF.Empty, string.Empty, 0.5f)
        {
            Alignment = Alignment.Right,
            WordWrap = 1000
        };

        private string rawTitle = string.Empty;
        private string rawInfo = string.Empty;

        #endregion

        #region Properties

        public string Title
        {
            get => rawTitle;
            set
            {
                rawTitle = value ?? throw new ArgumentNullException(nameof(value));
                title.Text = value.ToUpperInvariant();
            }
        }
        public string Info
        {
            get => rawInfo;
            set
            {
                rawInfo = value ?? throw new ArgumentNullException(nameof(value));
                info.Text = value.ToUpperInvariant();
            }
        }
        public float InfoWidth => info.Width;
        public Color Color
        {
            get => info.Color;
            set => info.Color = value;
        }

        #endregion

        #region Constructors

        public TimerBar(string title, string info)
        {
            Title = title;
            Info = info;
        }

        #endregion

        #region Functions

        public virtual void Recalculate(PointF pos)
        {
            background.Position = pos;
            background.Size = new SizeF(backgroundWidth, backgroundHeight);
            title.Position = new PointF(pos.X + 91, pos.Y + 8);
            info.Position = new PointF(pos.X + 218, pos.Y - 3);
        }
        public virtual void Draw()
        {
            background.Draw();
            title.Draw();
            info.Draw();
        }

        #endregion
    }
}