private async void ProcessDraw() { try { var weather = await _weatherStationService.GetHistorical(); LayoutDrawElement[] result = (new LayoutDrawElement[_elements.Count]); for (int i = 0; i < _elements.Count; i++) { var element = _elements[i]; var values = weather.Union(new[] { await _weatherStationService.GetData() }).Select(m => element.GetFunc(m)).ToArray(); var currentValue = values.Last(); var currentString = element.TransformFunc(currentValue); result[i] = new LayoutDrawElement(element.Location, DrawTexts(currentString, element.Suffix, values, _layoutContext)); } DrawLayout?.Invoke(this, new DrawEventArgs(result)); } catch (Exception ex) { Debug.WriteLine($"Exception during weather station layout drawing: {ex}"); } }
public void DoDraw(Location location) { DrawLayout?.Invoke(this, new DrawEventArgs(new[] { new LayoutDrawElement(location, _testBitmap.Clone(), new TransitionInfo(TransitionType.Instant, TimeSpan.Zero)), })); }
private void ElementOnDrawElement(object sender, DrawEventArgs e) { var placedElement = _elements.Values.FirstOrDefault(el => el.Element == sender); if (placedElement.Element != null) { if (e.Elements.Any(el => el.Location.X >= placedElement.Element.ButtonCount.Width || el.Location.Y >= placedElement.Element.ButtonCount.Height)) { throw new ArgumentException($"Element {placedElement.Element.Id.Value} of type {placedElement.Element.GetType().FullName} attempted to draw out of the borders."); } var drawEventArgs = new DrawEventArgs(e.Elements.Select(el => new LayoutDrawElement(placedElement.Location + el.Location, el.BitmapRepresentation, el.TransitionInfo)).ToArray()); DrawLayout?.Invoke(this, drawEventArgs); } }
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}"); } }
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}"); } }
private void DisconnectFromElement(ElementPlacement placement) { placement.Element.LeaveLayout(); placement.Element.DrawElement -= ElementOnDrawElement; LayoutDrawElement[] layoutDrawElements = new LayoutDrawElement[placement.Element.ButtonCount.Height * placement.Element.ButtonCount.Width]; int index = 0; for (byte x = 0; x < placement.Element.ButtonCount.Width; x++) { for (byte y = 0; y < placement.Element.ButtonCount.Height; y++) { layoutDrawElements[index] = new LayoutDrawElement(new Location((byte)(placement.Location.X + x), (byte)(placement.Location.Y + y)), LayoutContext.CreateBitmap()); index++; } } DrawLayout?.Invoke(this, new DrawEventArgs(layoutDrawElements)); }
private async void ProcessDraw() { var weather = await GetData(); var rows = _layoutContext.ButtonCount.Height; LayoutDrawElement[] result = new LayoutDrawElement[_layoutContext.ButtonCount.Width * rows]; for (byte i = 0; i < Math.Min(_layoutContext.ButtonCount.Width, weather.Length); i++) { result[i * rows] = new LayoutDrawElement(new Location(i, 0), DrawIcon(weather[i], GetDescription(weather[i]), _layoutContext)); result[i * rows + 1] = new LayoutDrawElement(new Location(i, 1), DrawTexts(WeatherHelpers.TempToStr(weather[i].TemperatureMaxCelsius ?? 0), WeatherHelpers.TempToStr(weather[i].TemperatureMinCelsius ?? 0), _layoutContext)); if (_layoutContext.ButtonCount.Height > 2) { result[i * rows + 2] = new LayoutDrawElement(new Location(i, 2), DrawTexts(((int)(weather[i].PressureMPa ?? 0)).ToString(), weather[i].Humidity.ToString() + "%", _layoutContext)); } if (_layoutContext.ButtonCount.Height > 3) { result[i * rows + 3] = new LayoutDrawElement(new Location(i, 3), DrawTexts(((int)(weather[i].Rain ?? 0)).ToString(), weather[i].Wind, _layoutContext)); } } DrawLayout?.Invoke(this, new DrawEventArgs(result)); }
protected void DrawInvoke(IEnumerable <LayoutDrawElement> drawElements) { DrawLayout?.Invoke(this, new DrawEventArgs(drawElements.ToArray())); }