Example #1
0
        static void Main(String[] args)
        {
            MskTemperature.INIT();

            var arg = args.Length > 0 ? args[0].ToLower().Trim().Substring(0, 2) : String.Empty;

            switch (arg)
            {
            case "/s": //show
                       //run the screen saver
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                ShowScreensaver();
                Application.Run();
                break;

            case "/p": //preview
                       //show the screen saver preview
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FormMain(new IntPtr(Int64.Parse(args[1])))); //args[1] is the handle to the preview window
                break;

            case "/c": //configure
                FormConfig dlg1 = new FormConfig();
                dlg1.ShowDialog();
                break;

            default:
                //an argument was passed, but it wasn't /s, /p, or /c, so we don't care wtf it was
                //show the screen saver anyway
                //no arguments were passed
                //run the screen saver
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                ShowScreensaver();
                Application.Run();
                break;
            }
        }
Example #2
0
        private void draw()
        {
            var now = DateTime.Now;

            if (this.minutePre == now.Minute && 0 <= this.cntDraws && this.cntDraws < IDX_DRAW_POS_CHANGE)
            {
                this.cntDraws++;
                return;
            }

            this.minutePre = now.Minute;

            var szTime    = (int)(this.Size.Height * (SZ_TIME / 1440.0));
            var szDate    = (int)(this.Size.Height * (SZ_DATE / 1440.0));
            var lineSpace = (int)(this.Size.Height * (LINE_SPACE / 1440.0));
            var fntTime   = new Font("Arial Black", szTime);
            var fntDate   = new Font("Arial Black", szDate);

            var formGraphics = this.CreateGraphics();

            formGraphics.SmoothingMode = SmoothingMode.HighQuality;
            var strTime = now.ToString("HH:mm");
            var strDate = now.ToString("d MMMM yyyy\ndddd");
            var temp    = MskTemperature.GET_TEMPERATURE_CURR();

            if (!String.IsNullOrEmpty(temp))
            {
                strDate = String.Concat(strDate, "\n", temp);
            }
            var szStrTime = formGraphics.MeasureString(strTime, fntTime);
            var szStrDate = formGraphics.MeasureString(strDate, fntDate);
            var szStr     = new Size((int)Math.Max(szStrTime.Width, szStrDate.Width),
                                     (int)(szStrTime.Height + lineSpace + szStrDate.Height));

            if (0 > this.cntDraws || this.cntDraws >= IDX_DRAW_POS_CHANGE)
            {
                this.x        = (this.rnd.NextDouble() * (this.Size.Width - szStr.Width)) + (szStr.Width / 2);
                this.y        = (this.rnd.NextDouble() * (this.Size.Height - szStr.Height)) + (szStr.Height / 2);
                this.cntDraws = 0;
            }

            var drawFormat = new StringFormat {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
            };

            var path = new GraphicsPath();

            path.AddString(strTime, this.fontFamily, (int)FontStyle.Regular, szTime,
                           new Point((int)this.x, (int)this.y),
                           drawFormat);
            path.AddString(strDate, this.fontFamily, (int)FontStyle.Regular, szDate,
                           new Point((int)this.x, (int)(this.y + (szStrTime.Height / 2) + lineSpace)),
                           drawFormat);

            if (Math.Abs(this.boundClr.Width) > 0.1)
            {
                formGraphics.FillRectangle(Brushes.Black,
                                           this.boundClr.X - 20, this.boundClr.Y - 20,
                                           this.boundClr.Width + 40, this.boundClr.Height + 40);
            }
            formGraphics.FillPath(this.drawBrush, path);
            this.boundClr = path.GetBounds();

            formGraphics.Dispose();
        }