Esempio n. 1
0
        private bool _Upgrade(GraphTheme graphTheme)
        {
            if (Options.LATESTOPTIONSVERSION > this.OptionsVersion)
            {
                switch (this.OptionsVersion)
                {
                case 0:
                //this.OptionsVersion = LATESTOPTIONSVERSION;
                //return true;
                case 1:
                    if (GraphTheme.IsCustom(graphTheme))
                    {
                        this.ThemeType = ThemeList.CUSTOM;
                    }
                    else
                    {
                        this.ThemeType = ThemeList.AUTOMATIC;
                    }
                    this.OptionsVersion = LATESTOPTIONSVERSION;
                    return(true);

                default:
                    break;
                }
            }
            return(false);
        }
        private GraphTheme GetTheme(Options opt)
        {
            GraphTheme theme = GraphTheme.DefaultDarkTheme();

            if (opt.ThemeType == Options.ThemeList.LIGHT)
            {
                theme = GraphTheme.DefaultLightTheme();
            }
            else if (opt.ThemeType == Options.ThemeList.CUSTOM)
            {
                theme = GraphTheme.ReadFromDisk();
            }
            else if (opt.ThemeType == Options.ThemeList.AUTOMATIC)
            {
                Color taskBarColour = BLL.Win32Api.GetColourAt(BLL.Win32Api.GetTaskbarPosition().Location);
                if (taskBarColour.R + taskBarColour.G + taskBarColour.B > 382)
                {
                    theme = GraphTheme.DefaultLightTheme();
                }
                else
                {
                    theme = GraphTheme.DefaultDarkTheme();
                }
            }
            return(theme);
        }
        public SystemWatcherControl()
        {
            Options    opt   = TaskbarMonitor.Options.ReadFromDisk();
            GraphTheme theme = GraphTheme.ReadFromDisk();

            Initialize(opt, theme);
        }
Esempio n. 4
0
 public bool Upgrade(GraphTheme graphTheme)
 {
     if (_Upgrade(graphTheme)) // do a inplace upgrade
     {
         return(SaveToDisk());
     }
     return(false);
 }
Esempio n. 5
0
        public OptionForm(Options opt, GraphTheme theme, Version version, SystemWatcherControl originalControl)
        {
            this.Version = version;

            this.Theme         = new GraphTheme();
            this.OriginalTheme = theme;
            theme.CopyTo(this.Theme);

            this.Options         = new Options();
            this.OriginalOptions = opt;
            opt.CopyTo(this.Options);

            this.originalControl = originalControl;

            AvailableGraphTypes = new Dictionary <string, IList <Counters.ICounter.CounterType> >
            {
                { "CPU", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE,
                      TaskbarMonitor.Counters.ICounter.CounterType.STACKED
                  } },
                { "MEM", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE
                  } },
                { "DISK", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE,
                      TaskbarMonitor.Counters.ICounter.CounterType.STACKED,
                      TaskbarMonitor.Counters.ICounter.CounterType.MIRRORED
                  } },
                { "NET", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE,
                      TaskbarMonitor.Counters.ICounter.CounterType.STACKED,
                      TaskbarMonitor.Counters.ICounter.CounterType.MIRRORED
                  } }
            };
            InitializeComponent();

            /*
             * float dpiX, dpiY;
             * using (Graphics graphics = this.CreateGraphics())
             * {
             *  dpiX = graphics.DpiX;
             *  dpiY = graphics.DpiY;
             * }
             *
             * if (dpiX >= 96)
             * {
             *  var fontSize = 7.25f;
             *  this.Font = new Font("Calibri", fontSize, FontStyle.Regular);
             * }
             */
            Initialize();
        }
Esempio n. 6
0
        public static bool IsCustom(GraphTheme theme)
        {
            var light = DefaultLightTheme();
            var dark  = DefaultDarkTheme();

            if (theme.BarColor.ToArgb() != light.BarColor.ToArgb() && theme.BarColor.ToArgb() != dark.BarColor.ToArgb())
            {
                return(true);
            }
            if (theme.TextColor.ToArgb() != light.TextColor.ToArgb() && theme.TextColor.ToArgb() != dark.TextColor.ToArgb())
            {
                return(true);
            }
            if (theme.TextShadowColor.ToArgb() != light.TextShadowColor.ToArgb() && theme.TextShadowColor.ToArgb() != dark.TextShadowColor.ToArgb())
            {
                return(true);
            }
            if (theme.TitleColor.ToArgb() != light.TitleColor.ToArgb() && theme.TitleColor.ToArgb() != dark.TitleColor.ToArgb())
            {
                return(true);
            }
            if (theme.TitleShadowColor.ToArgb() != light.TitleShadowColor.ToArgb() && theme.TitleShadowColor.ToArgb() != dark.TitleShadowColor.ToArgb())
            {
                return(true);
            }
            if (!theme.TitleFont.Equals(light) && !theme.TitleFont.Equals(dark))
            {
                return(true);
            }
            if (!theme.TitleSize.Equals(light) && !theme.TitleSize.Equals(dark))
            {
                return(true);
            }

            int i = 0;

            foreach (var item in theme.StackedColors)
            {
                if (light.StackedColors.Count <= i)
                {
                    return(true);
                }
                if (dark.StackedColors.Count <= i)
                {
                    return(true);
                }
                if (item.ToArgb() != light.StackedColors[i].ToArgb() && item.ToArgb() != dark.StackedColors[i].ToArgb())
                {
                    return(true);
                }
                i++;
            }

            return(false);
        }
        private void PollingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            UpdateGraphs();

            if (this.Options.ThemeType == Options.ThemeList.AUTOMATIC)
            {
                this.defaultTheme = GetTheme(this.Options);
            }

            this.Invalidate();
        }
Esempio n. 8
0
        private void Initialize()
        {
            _contextMenu = new ContextMenu();
            _contextMenu.MenuItems.Add(new MenuItem("Settings...", MenuItem_Settings_onClick));
            _contextMenu.MenuItems.Add(new MenuItem("Open Resource Monitor...", (e, a) => {
                System.Diagnostics.Process.Start("resmon.exe");
            }));
            _contextMenu.MenuItems.Add(new MenuItem(String.Format("About taskbar-monitor (v{0})...", Version.ToString(3)), MenuItem_About_onClick));
            this.ContextMenu = _contextMenu;

            defaultTheme = new GraphTheme
            {
                BarColor         = Color.FromArgb(255, 176, 222, 255),
                TextColor        = Color.FromArgb(200, 185, 255, 70),
                TextShadowColor  = Color.FromArgb(255, 0, 0, 0),
                TitleColor       = Color.FromArgb(255, 255, 255, 255),
                TitleShadowColor = Color.FromArgb(255, 0, 0, 0),
                StackedColors    = new List <Color>
                {
                    Color.FromArgb(255, 37, 84, 142),
                    Color.FromArgb(255, 65, 144, 242)
                }
            };


            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);

            InitializeComponent();
            AdjustControlSize();



            float dpiX, dpiY;

            using (Graphics graphics = this.CreateGraphics())
            {
                dpiX = graphics.DpiX;
                dpiY = graphics.DpiY;
            }
            float fontSize = 7f;

            if (dpiX > 96)
            {
                fontSize = 6f;
            }

            fontCounter    = new Font("Helvetica", fontSize, FontStyle.Bold);
            fontCounterMin = new Font("Helvetica", fontSize - 1, FontStyle.Bold);
            fontTitle      = new Font("Arial", fontSize, FontStyle.Bold);
        }
Esempio n. 9
0
        public Deskband()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Options    opt   = TaskbarMonitor.Options.ReadFromDisk();
            GraphTheme theme = GraphTheme.ReadFromDisk();

            var ctl = new SystemWatcherControl(opt, theme);

            Options.MinHorizontalSize = new Size((ctl.Options.HistorySize + 10) * ctl.CountersCount, 30);
            ctl.OnChangeSize         += Ctl_OnChangeSize;
            _control = ctl;
        }
Esempio n. 10
0
        public static GraphTheme ReadFromDisk()
        {
            GraphTheme theme = DefaultTheme();

            var folder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "taskbar-monitor");
            var origin = System.IO.Path.Combine(folder, "theme.json");

            if (System.IO.File.Exists(origin))
            {
                theme = JsonConvert.DeserializeObject <GraphTheme>(System.IO.File.ReadAllText(origin));
                if (theme.Upgrade()) // do a inplace upgrade
                {
                    theme.SaveToDisk();
                }
            }
            return(theme);
        }
Esempio n. 11
0
        public void CopyTo(GraphTheme theme)
        {
            theme.BarColor         = this.BarColor;
            theme.TextColor        = this.TextColor;
            theme.TextShadowColor  = this.TextShadowColor;
            theme.TitleColor       = this.TitleColor;
            theme.TitleShadowColor = this.TitleShadowColor;
            theme.TitleFont        = this.TitleFont;
            theme.TitleSize        = this.TitleSize;
            theme.CurrentValueFont = this.CurrentValueFont;
            theme.CurrentValueSize = this.CurrentValueSize;

            theme.StackedColors = new List <Color>();

            foreach (var item in this.StackedColors)
            {
                theme.StackedColors.Add(item);
            }
        }
        private void Initialize(Options opt, GraphTheme theme)
        {
            Counters = new List <Counters.ICounter>();
            if (opt.CounterOptions.ContainsKey("CPU"))
            {
                var ct = new Counters.CounterCPU(opt);
                ct.Initialize();
                Counters.Add(ct);
            }
            if (opt.CounterOptions.ContainsKey("MEM"))
            {
                var ct = new Counters.CounterMemory(opt);
                ct.Initialize();
                Counters.Add(ct);
            }
            if (opt.CounterOptions.ContainsKey("DISK"))
            {
                var ct = new Counters.CounterDisk(opt);
                ct.Initialize();
                Counters.Add(ct);
            }
            if (opt.CounterOptions.ContainsKey("NET"))
            {
                var ct = new Counters.CounterNetwork(opt);
                ct.Initialize();
                Counters.Add(ct);
            }

            ApplyOptions(opt, theme);
            //Initialize();
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);

            InitializeComponent();
            AdjustControlSize();

            pollingTimer          = new System.Timers.Timer(opt.PollTime * 1000);
            pollingTimer.Enabled  = true;
            pollingTimer.Elapsed += PollingTimer_Elapsed;
            pollingTimer.Start();
        }
Esempio n. 13
0
        private void UpdatePreview()
        {
            var previewOptions = new Options();

            this.Options.CopyTo(previewOptions);

            /*
             * for (int i = 0; i < previewOptions.CounterOptions.Keys.Count; i++)
             * {
             *  string key = previewOptions.CounterOptions.Keys.ElementAt(i);
             *  if (key != this.listCounters.Text)
             *  {
             *      previewOptions.CounterOptions.Remove(key);
             *      i--;
             *  }
             * }*/
            GraphTheme previewTheme = GraphTheme.DefaultDarkTheme();

            if (previewOptions.ThemeType == Options.ThemeList.LIGHT)
            {
                previewTheme = GraphTheme.DefaultLightTheme();
            }
            else if (previewOptions.ThemeType == Options.ThemeList.CUSTOM)
            {
                previewTheme = new GraphTheme();
                this.Theme.CopyTo(previewTheme);
            }
            else if (previewOptions.ThemeType == Options.ThemeList.AUTOMATIC)
            {
                Color taskBarColour = BLL.Win32Api.GetColourAt(BLL.Win32Api.GetTaskbarPosition().Location);
                if (taskBarColour.R + taskBarColour.G + taskBarColour.B > 382)
                {
                    previewTheme = GraphTheme.DefaultLightTheme();
                }
                else
                {
                    previewTheme = GraphTheme.DefaultDarkTheme();
                }
            }

            swcPreview.ApplyOptions(previewOptions, previewTheme);
        }
        public void ApplyOptions(Options Options, GraphTheme theme)
        {
            this.Options      = Options;
            this.defaultTheme = theme;

            fontTitle   = new Font(defaultTheme.TitleFont, defaultTheme.TitleSize, defaultTheme.TitleFontStyle);
            fontCounter = new Font(defaultTheme.CurrentValueFont, defaultTheme.CurrentValueSize, defaultTheme.CurrentValueFontStyle);

            _contextMenu = new ContextMenu();
            _contextMenu.MenuItems.Add(new MenuItem("Settings...", MenuItem_Settings_onClick));
            _contextMenu.MenuItems.Add(new MenuItem("Open Resource Monitor...", (e, a) =>
            {
                System.Diagnostics.Process.Start("resmon.exe");
            }));
            _contextMenu.MenuItems.Add(new MenuItem(String.Format("About taskbar-monitor (v{0})...", Version.ToString(3)), MenuItem_About_onClick));
            this.ContextMenu = _contextMenu;


            if (PreviewMode)
            {
                Color taskBarColour = BLL.Win32Api.GetColourAt(BLL.Win32Api.GetTaskbarPosition().Location);
                this.BackColor = taskBarColour;
            }

            /*
             *  float dpiX, dpiY;
             *  using (Graphics graphics = this.CreateGraphics())
             *  {
             *      dpiX = graphics.DpiX;
             *      dpiY = graphics.DpiY;
             *  }
             *  float fontSize = 7f;
             *  if (dpiX > 96)
             *      fontSize = 6f;
             */

            AdjustControlSize();
            UpdateGraphs();
            this.Invalidate();
        }
Esempio n. 15
0
        private void UpdatePreview()
        {
            var previewOptions = new Options();

            this.Options.CopyTo(previewOptions);

            /*
             * for (int i = 0; i < previewOptions.CounterOptions.Keys.Count; i++)
             * {
             *  string key = previewOptions.CounterOptions.Keys.ElementAt(i);
             *  if (key != this.listCounters.Text)
             *  {
             *      previewOptions.CounterOptions.Remove(key);
             *      i--;
             *  }
             * }*/
            var previewTheme = new GraphTheme();

            this.Theme.CopyTo(previewTheme);

            swcPreview.ApplyOptions(previewOptions, previewTheme);
        }
 public bool IsCustomTheme()
 {
     return(GraphTheme.IsCustom(this.defaultTheme));
 }
Esempio n. 17
0
        public OptionForm(Options opt, GraphTheme theme, Version version)
        {
            this.Version         = version;
            this.Theme           = theme;
            this.Options         = new Options();
            this.OriginalOptions = opt;
            opt.CopyTo(this.Options);
            AvailableGraphTypes = new Dictionary <string, IList <Counters.ICounter.CounterType> >
            {
                { "CPU", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE,
                      TaskbarMonitor.Counters.ICounter.CounterType.STACKED
                  } },
                { "MEM", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE
                  } },
                { "DISK", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE,
                      TaskbarMonitor.Counters.ICounter.CounterType.STACKED,
                      TaskbarMonitor.Counters.ICounter.CounterType.MIRRORED
                  } },
                { "NET", new List <TaskbarMonitor.Counters.ICounter.CounterType>
                  {
                      TaskbarMonitor.Counters.ICounter.CounterType.SINGLE,
                      TaskbarMonitor.Counters.ICounter.CounterType.STACKED,
                      TaskbarMonitor.Counters.ICounter.CounterType.MIRRORED
                  } }
            };
            InitializeComponent();

            float dpiX, dpiY;

            using (Graphics graphics = this.CreateGraphics())
            {
                dpiX = graphics.DpiX;
                dpiY = graphics.DpiY;
            }

            if (dpiX >= 96)
            {
                var fontSize = 7.25f;
                this.Font = new Font("Calibri", fontSize, FontStyle.Regular);
            }

            this.editHistorySize.Value           = this.Options.HistorySize;
            this.editPollTime.Value              = this.Options.PollTime;
            this.listCounters.DataSource         = this.Options.CounterOptions.Keys.AsEnumerable().ToList();
            this.listShowTitle.DataSource        = Enum.GetValues(typeof(CounterOptions.DisplayType));
            this.listShowCurrentValue.DataSource = Enum.GetValues(typeof(CounterOptions.DisplayType));
            this.listSummaryPosition.DataSource  = Enum.GetValues(typeof(CounterOptions.DisplayPosition));
            this.listTitlePosition.DataSource    = Enum.GetValues(typeof(CounterOptions.DisplayPosition));

            lblVersion.Text = "v" + version.ToString(3);

            ActiveCounter = this.Options.CounterOptions.First().Value;
            UpdateForm();
            UpdateReplicateSettingsMenu();
            btnColorBar.BackColor                = this.Theme.BarColor;
            btnColorCurrentValue.BackColor       = this.Theme.TextColor;
            btnColorCurrentValueShadow.BackColor = this.Theme.TextShadowColor;
            btnColorTitle.BackColor              = this.Theme.TitleColor;
            btnColorTitleShadow.BackColor        = this.Theme.TitleShadowColor;
            btnColor1.BackColor = this.Theme.StackedColors[0];
            btnColor2.BackColor = this.Theme.StackedColors[1];

            UpdatePreview();

            initializing = false;
        }
Esempio n. 18
0
 private void buttonResetDefaults_Click(object sender, EventArgs e)
 {
     Options.DefaultOptions().CopyTo(this.Options);
     GraphTheme.DefaultDarkTheme().CopyTo(this.Theme);
     Initialize();
 }
Esempio n. 19
0
        private void drawGraph(System.Drawing.Graphics formGraphics, int x, int y, int maxH, bool invertido, TaskbarMonitor.Counters.CounterInfo info, GraphTheme theme, CounterOptions opt)
        {
            var pos = maxH - ((info.CurrentValue * maxH) / info.MaximumValue);

            if (pos > Int32.MaxValue)
            {
                pos = Int32.MaxValue;
            }
            int posInt = Convert.ToInt32(pos) + y;

            var height = (info.CurrentValue * maxH) / info.MaximumValue;

            if (height > Int32.MaxValue)
            {
                height = Int32.MaxValue;
            }
            int heightInt = Convert.ToInt32(height);

            using (SolidBrush BrushBar = new SolidBrush(theme.BarColor))
            {
                if (invertido)
                {
                    formGraphics.FillRectangle(BrushBar, new Rectangle(x + Options.HistorySize, maxH, 4, heightInt));
                }
                else
                {
                    formGraphics.FillRectangle(BrushBar, new Rectangle(x + Options.HistorySize, posInt, 4, heightInt));
                }
            }

            var initialGraphPosition = x + Options.HistorySize - info.History.Count;

            Point[] points   = new Point[info.History.Count + 2];
            int     i        = 0;
            int     inverter = invertido ? -1 : 1;

            foreach (var item in info.History)
            {
                var heightItem = (item * maxH) / info.MaximumValue;
                if (heightItem > Int32.MaxValue)
                {
                    height = Int32.MaxValue;
                }
                var convertido = Convert.ToInt32(heightItem);


                if (invertido)
                {
                    points[i] = new Point(initialGraphPosition + i, 0 + convertido + y);
                }
                else
                {
                    points[i] = new Point(initialGraphPosition + i, maxH - convertido + y);
                }
                i++;
            }
            if (invertido)
            {
                points[i]     = new Point(initialGraphPosition + i, 0 + y);
                points[i + 1] = new Point(initialGraphPosition, 0 + y);
            }
            else
            {
                points[i]     = new Point(initialGraphPosition + i, maxH + y);
                points[i + 1] = new Point(initialGraphPosition, maxH + y);
            }
            using (SolidBrush BrushGraph = new SolidBrush(theme.getNthColor(2, invertido ? 1 : 0)))
            {
                formGraphics.FillPolygon(BrushGraph, points);
            }
        }
Esempio n. 20
0
        private void drawStackedGraph(System.Drawing.Graphics formGraphics, int x, int y, int maxH, bool invertido, List <TaskbarMonitor.Counters.CounterInfo> infos, GraphTheme theme, CounterOptions opt)
        {
            float        absMax    = 0;
            List <float> lastValue = new List <float>();

            // accumulate values for stacked effect
            List <List <float> > values = new List <List <float> >();

            foreach (var info in infos.AsEnumerable().Reverse())
            {
                absMax += info.MaximumValue;
                var value = new List <float>();
                int z     = 0;
                foreach (var item in info.History)
                {
                    value.Add(item + (lastValue.Count > 0 ? lastValue.ElementAt(z) : 0));
                    z++;
                }
                values.Add(value);
                lastValue = value;
            }
            var historySize = values.Count > 0 ? values[0].Count : 0;
            // now we draw it

            var colors = theme.GetColorGradient(theme.StackedColors[0], theme.StackedColors[1], values.Count);
            int w      = 0;

            if (!invertido)
            {
                values.Reverse();
            }
            foreach (var info in values)
            {
                float currentValue = info.Count > 0 ? info.Last() : 0;
                var   pos          = maxH - ((currentValue * maxH) / absMax);
                if (pos > Int32.MaxValue)
                {
                    pos = Int32.MaxValue;
                }
                int posInt = Convert.ToInt32(pos) + y;

                var height = (currentValue * maxH) / absMax;
                if (height > Int32.MaxValue)
                {
                    height = Int32.MaxValue;
                }
                int heightInt = Convert.ToInt32(height);

                SolidBrush BrushBar = new SolidBrush(theme.BarColor);
                formGraphics.FillRectangle(BrushBar, new Rectangle(x + Options.HistorySize, posInt, 4, heightInt));
                BrushBar.Dispose();

                int     i = 0;
                var     initialGraphPosition = x + Options.HistorySize - historySize;
                Point[] points = new Point[historySize + 2];
                foreach (var item in info)
                {
                    var heightItem = (item * maxH) / absMax;
                    if (heightItem > Int32.MaxValue)
                    {
                        heightItem = Int32.MaxValue;
                    }
                    var convertido = Convert.ToInt32(heightItem);

                    points[i] = new Point(initialGraphPosition + i, maxH - convertido + y);
                    i++;
                }
                points[i]     = new Point(initialGraphPosition + i, maxH + y);
                points[i + 1] = new Point(initialGraphPosition, maxH + y);

                Brush brush = new SolidBrush(colors.ElementAt(w));
                w++;
                formGraphics.FillPolygon(brush, points);
                brush.Dispose();
            }
        }
 public SystemWatcherControl(Options opt, GraphTheme theme)//CSDeskBand.CSDeskBandWin w,
 {
     Initialize(opt, theme);
 }