Пример #1
0
        private async void ProcessDraw()
        {
            try
            {
                var from = DateTime.Now.Subtract(_options.ExpiredMeetingTolerance);
                var to   = from.AddDays(2).Date;

                _appointments = _calendarServices.SelectMany(c => c.GetCalendar(from, to)).OrderBy(c => c.FromDateTime).ToArray();

                var rows    = _layoutContext.ButtonCount.Height;
                var columns = _layoutContext.ButtonCount.Width;
                LayoutDrawElement[] result = new LayoutDrawElement[columns * rows];

                for (byte i = 0; i < Math.Min(_layoutContext.ButtonCount.Height, _appointments.Length); i++)
                {
                    result[i * columns]     = new LayoutDrawElement(new Location(0, i), DrawText(FormatDateTime(_appointments[i].FromDateTime, _appointments[i].ToDateTime), _layoutContext));
                    result[i * columns + 1] = new LayoutDrawElement(new Location(2, i), DrawText(_appointments[i].Location, _layoutContext));
                    result[i * columns + 2] = new LayoutDrawElement(new Location(1, i), DrawText(_appointments[i].Organiser, _layoutContext));

                    byte firstNameIndex  = 3;
                    byte textButtonCount = (byte)(columns - firstNameIndex);
                    if (textButtonCount > 0)
                    {
                        using (var bitmap = new BitmapEx(_layoutContext.IconSize.Width * textButtonCount, _layoutContext.IconSize.Height))
                        {
                            bitmap.MakeTransparent();
                            DefaultDrawingAlgs.DrawText(bitmap, _layoutContext.Options.Theme.FontFamily, _appointments[i].Subject, _layoutContext.Options.Theme.ForegroundColor);
                            var elements = BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textButtonCount, 1), firstNameIndex, i, _layoutContext);
                            int j        = firstNameIndex;
                            foreach (var e in elements)
                            {
                                result[i * columns + j] = e;
                                j++;
                            }
                        }
                    }
                }

                DrawLayout?.Invoke(this, new DrawEventArgs(result));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception during weather station layout drawing: {ex}");
            }
        }
Пример #2
0
        void Draw()
        {
            var muted     = _mediaDeviceService.IsMuted;
            var volume    = _mediaDeviceService.Volume;
            var peakValue = _mediaDeviceService.GetPeakVolumeValue();

            var newValues = new Tuple <bool, double, float>(muted, volume, peakValue);

            if (!newValues.Equals(_lastValues))
            {
                _lastValues = newValues;

                using (var bitmap = DrawLevel(muted, volume, peakValue))
                {
                    DrawInvoke(BitmapHelpers.ExtractLayoutDrawElements(bitmap, ButtonCount, 0, 0, LayoutContext, new TransitionInfo(TransitionType.ElementUpdate, new TimeSpan(0, 0, 0, 0, 500))));
                }
            }
        }
Пример #3
0
        private async void ProcessDraw()
        {
            try
            {
                List <LayoutDrawElement> result = new List <LayoutDrawElement>(14);

                var weather = await _weatherStationService.GetHistorical();

                var values = weather.Union(new[] { await _weatherStationService.GetData() }).Select(m => _element.GetFunc(m)).ToArray();

                var currentValue = values.Last();
                var minValue     = values.Min();
                var maxValue     = values.Max();
                var avgValue     = values.Average();

                var color = _layoutContext.Options.Theme.ForegroundColor;

                result.Add(GetHeaderElement(0, 0, "Min", color));
                result.Add(GetHeaderElement(1, 0, "Avg", color));
                result.Add(GetHeaderElement(2, 0, "Max", color));
                result.Add(GetHeaderElement(3, 0, "Cur", color));

                result.Add(GetHeaderElement(0, 1, _element.TransformFunc(minValue), color));
                result.Add(GetHeaderElement(1, 1, _element.TransformFunc(avgValue), color));
                result.Add(GetHeaderElement(2, 1, _element.TransformFunc(maxValue), color));
                result.Add(GetHeaderElement(3, 1, _element.TransformFunc(currentValue), color));

                result.Add(GetHeaderElement(4, 1, _element.Suffix, color));

                var deviceWidth = _layoutContext.ButtonCount.Width;
                using (var bitmap = new BitmapEx(_layoutContext.IconSize.Width * deviceWidth, _layoutContext.IconSize.Height))
                {
                    bitmap.MakeTransparent();
                    DefaultDrawingAlgs.DrawPlot(bitmap, color, values, 0, bitmap.Height);
                    result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(deviceWidth, 1), 0, 2, _layoutContext));
                }

                DrawLayout?.Invoke(this, new DrawEventArgs(result.ToArray()));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception during weather station layout drawing: {ex}");
            }
        }
Пример #4
0
        public void TestExtractLayoutDrawElements()
        {
            Color green = Color.FromArgb(0, 200, 0);
            Color red   = Color.FromArgb(200, 0, 0);
            Color blue  = Color.FromArgb(0, 0, 200);

            Color black = Color.FromArgb(0, 0, 0);
            Color gray  = Color.FromArgb(100, 100, 100);
            Color white = Color.FromArgb(200, 200, 200);

            using (var bitmap = new Bitmap(30, 20))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                    using (var rBrush = new SolidBrush(red))
                        using (var gBrush = new SolidBrush(green))
                            using (var bBrush = new SolidBrush(blue))
                                using (var bkBrush = new SolidBrush(black))
                                    using (var grBrush = new SolidBrush(gray))
                                        using (var wtBrush = new SolidBrush(white))
                                        {
                                            graphics.FillRectangle(rBrush, 0, 0, 10, 10);
                                            graphics.FillRectangle(gBrush, 10, 0, 10, 10);
                                            graphics.FillRectangle(bBrush, 20, 0, 10, 10);
                                            graphics.FillRectangle(bkBrush, 0, 10, 10, 10);
                                            graphics.FillRectangle(grBrush, 10, 10, 10, 10);
                                            graphics.FillRectangle(wtBrush, 20, 10, 10, 10);
                                        }

                var initializer = new Initializer();

                using (var sourceRepresentation = new BitmapRepresentation(bitmap))
                    using (var sourceBitmapEx = sourceRepresentation.CreateBitmap())
                    {
                        var ldes = BitmapHelpers.ExtractLayoutDrawElements(sourceBitmapEx, new DeviceSize(3, 2), 5, 3, initializer.LayoutContext).ToArray();

                        Assert.AreEqual(true, CheckColorOfElement(ldes, 5, 3, red));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 6, 3, green));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 7, 3, blue));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 5, 4, black));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 6, 4, gray));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 7, 4, white));
                    }
            }
        }
Пример #5
0
        private void PerformDraw(PlayingInfo playingInfo)
        {
            byte imageSize = 2;
            byte textSize  = 3;
            var  result    = new List <LayoutDrawElement>();

            if (playingInfo.IsPlaying != _isPlaying)
            {
                _isPlaying = playingInfo.IsPlaying;
                _playPauseButton.ReplaceText(_isPlaying.Value?FontAwesomeRes.fa_pause:FontAwesomeRes.fa_play);
            }

            if (_previousRepresentation != playingInfo?.BitmapRepresentation)
            {
                _previousRepresentation = playingInfo?.BitmapRepresentation;

                using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * imageSize, LayoutContext.IconSize.Height * imageSize))
                {
                    bitmap.MakeTransparent();
                    if (playingInfo?.BitmapRepresentation != null)
                    {
                        using (BitmapEx coverBitmap = playingInfo.BitmapRepresentation.CreateBitmap())
                        {
                            BitmapHelpers.ResizeBitmap(coverBitmap, bitmap);
                        }
                    }

                    result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(imageSize, imageSize), 0, 0, LayoutContext));
                }
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                var lineWidth = 0.05;

                bitmap.MakeTransparent();
                var title = playingInfo?.Title;
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, title, LayoutContext.Options.Theme.ForegroundColor);

                if (playingInfo != null)
                {
                    using (var graphics = bitmap.CreateGraphics())
                        using (var brush = new SolidBrush(GlobalContext.Options.Theme.ForegroundColor))
                        {
                            var rect = new Rectangle(0, (int)(bitmap.Height * (1 - lineWidth)), (int)(bitmap.Width * playingInfo.CurrentPosition.TotalMilliseconds / playingInfo.DurationSpan.TotalMilliseconds), (int)(bitmap.Height * lineWidth));
                            graphics.FillRectangle(brush, rect);
                        }
                }

                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 0, LayoutContext));
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                bitmap.MakeTransparent();
                var artist = playingInfo?.Artist ?? string.Empty;
                var album  = playingInfo?.Album ?? string.Empty;
                var text   = $"{artist}\n{album}";
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, text, GlobalContext.Options.Theme.ForegroundColor);
                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 1, LayoutContext));
            }

            DrawInvoke(result);
        }