コード例 #1
0
        public async Task LogPrint(ScreenMessage lcdt)
        {
            if (lcdt.Action != null && lcdt.Action.ToUpperInvariant().Equals("CLEAR"))
            {
                mainPage.text.Text = "";
            }

            await
                mainPage.dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () => { mainPage.text.Text += lcdt.Message + "\r\n"; });
        }
コード例 #2
0
        internal async Task SendEvent(
            object sender, 
            RoutedEventArgs e, 
            string action, 
            MessageBase message = null, 
            string messageText = null)
        {
            if (sender is Grid && this.sensors.ContainsKey("LCDG:TOUCH"))
            {
                if (e is PointerRoutedEventArgs)
                {
                    var pe = (PointerRoutedEventArgs)e;
                    var pt = pe.GetCurrentPoint(sender as FrameworkElement);
                    await
                        this.SendResult(
                            new ScreenResultMessage(message)
                                {
                                    Area = "TOUCH", 
                                    Action = action, 
                                    X = pt.Position.X, 
                                    Y = pt.Position.Y
                                });
                }
            }
            else if (!(sender is Grid))
            {
                var source = (e.OriginalSource ?? sender) as FrameworkElement;

                var id = (int)source.GetValue(Screen.RemoteIdProperty);

                if (message == null)
                {
                    message = new ScreenMessage { Type = 'S', Service = "LCDG", Id = id };
                }

                var newid = (message.Id == 0) ? id : message.Id;

                await
                    this.SendResult(
                        new ScreenResultMessage(message)
                            {
                                Area = source.GetType().Name.ToUpperInvariant(), 
                                Action = action, 
                                Tag = source.Tag?.ToString(), 
                                Type = message.Type ?? 'S', 
                                Id = newid, 
                                Result = messageText
                            }, 
                        newid + action);
            }
        }
コード例 #3
0
        public async void LcdPrint(ScreenMessage lcdt)
        {
            var isText = lcdt.Service.Equals("LCDT");
            FrameworkElement element = null;
            var expandToEdge = false;
            SolidColorBrush backgroundBrush = null;

            if (lcdt.Action != null)
            {
                if (!string.IsNullOrWhiteSpace(lcdt.ARGB))
                {
                    if (lcdt.ARGB[0] == '#')
                    {
                        var hex = lcdt.ARGB.ToByteArray();
                        if (hex.Length > 3)
                        {
                            backgroundBrush =
                                new SolidColorBrush(Color.FromArgb((hex[0] == 0 ? (byte) 255 : hex[0]), hex[1], hex[2],
                                    hex[3]));
                        }
                    }
                    else
                    {
                        UInt32 color;
                        if (UInt32.TryParse(lcdt.ARGB, out color))
                        {
                            var argb = new ArgbUnion {Value = color};
                            backgroundBrush = new SolidColorBrush(Color.FromArgb(argb.A == 0 ? (byte) 255 : argb.A, argb.R, argb.G, argb.B));
                        }
                    }   
                }

                var action = lcdt.Action.ToUpperInvariant();
                switch (action)
                {
                    case "ORIENTATION":
                        {
                            var current = DisplayInformation.AutoRotationPreferences;
                            if (lcdt.Value.HasValue)
                            {
                                DisplayInformation.AutoRotationPreferences = (DisplayOrientations)lcdt.Value.Value;
                            }

                            await mainPage.SendResult(new ScreenResultMessage(lcdt) { ResultId = (int)current });

                            break;
                        }
                    case "ENABLE":
                        {
                            mainPage.sensors[lcdt.Service + ":" + lcdt.Message] = 1;
                            return;
                        }
                    case "DISABLE":
                        {
                            if (mainPage.sensors.ContainsKey(lcdt.Service + ":" + lcdt.Message))
                            {
                                mainPage.sensors.Remove(lcdt.Service + ":" + lcdt.Message);
                            }

                            return;
                        }
                    case "CLEAR":
                        {
                            if (lcdt.Y.HasValue)
                            {
                                RemoveLine(lcdt.Y.Value);
                            }
                            else if (lcdt.Pid.HasValue)
                            {
                                RemoveId(lcdt.Pid.Value);
                            }
                            else
                            {
                                mainPage.canvas.Children.Clear();

                                if (backgroundBrush != null)
                                {
                                    mainPage.canvas.Background = backgroundBrush;
                                }

                                lastY = -1;
                                mainPage.player.Stop();
                                mainPage.player.Source = null;
                            }

                            break;
                        }

                    case "BUTTON":
                        {
                            element = new Button
                            {
                                Content = lcdt.Message,
                                FontSize = lcdt.Size ?? DefaultFontSize,
                                Tag = lcdt.Tag,
                                Foreground = textForgroundBrush,
                                Background =  new SolidColorBrush(Colors.Gray)

                            };

                            element.Tapped += async (s, a) => await mainPage.SendEvent(s, a, "tapped");
                            ((Button)element).Click += async (s, a) => await mainPage.SendEvent(s, a, "click");
                            element.PointerPressed += async (s, a) => await mainPage.SendEvent(s, a, "pressed");
                            element.PointerReleased += async (s, a) => await mainPage.SendEvent(s, a, "released");

                            break;
                        }

                    case "IMAGE":
                        {
                            var imageBitmap = new BitmapImage(new Uri(lcdt.Path, UriKind.Absolute));
                            //imageBitmap.CreateOptions = Windows.UI.Xaml.Media.Imaging.BitmapCreateOptions.IgnoreImageCache;

                            if (lcdt.Width.HasValue)
                            {
                                imageBitmap.DecodePixelWidth = lcdt.Width.Value;
                            }

                            if (lcdt.Height.HasValue)
                            {
                                imageBitmap.DecodePixelHeight = lcdt.Height.Value;
                            }

                            element = new Image
                            {
                                Tag = lcdt.Tag
                            };

                            ((Image)element).Source = imageBitmap;

                            element.Tapped += async (s, a) => await mainPage.SendEvent(s, a, "tapped");
                            break;
                        }
                    case "LINE":
                    {
                        var line = new Line
                        {
                            X1 = lcdt.X.Value,
                            Y1 = lcdt.Y.Value,
                            X2 = lcdt.X2.Value,
                            Y2 = lcdt.Y2.Value,
                            StrokeThickness = lcdt.Width ?? 1,
                            Stroke = foreground
                        };

                        element = line;

                        break;
                    }

                    case "INPUT":
                        {
                            element = new TextBox
                            {
                                Text = lcdt.Message,
                                FontSize = lcdt.Size ?? DefaultFontSize,
                                TextWrapping = TextWrapping.Wrap,
                                Foreground = textForgroundBrush,
                                AcceptsReturn = lcdt.Multi ?? false
                            };

                            expandToEdge = true;

                            element.SetValue(Canvas.LeftProperty, lcdt.X);
                            element.SetValue(Canvas.TopProperty, lcdt.Y);

                            element.LostFocus += async (s, a) => await mainPage.SendEvent(s, a, "lostfocus", lcdt, ((TextBox)s).Text);
                            ((TextBox)element).TextChanged += async (s, a) => await mainPage.SendEvent(s, a, "changed", lcdt, ((TextBox)s).Text);

                            break;
                        }
                    case "CHANGE":
                        {
                            var retrievedElement = GetId(lcdt.Pid.Value);
                            if (retrievedElement != null)
                            {
                                if (lcdt.ARGB != null)
                                {
                                    var i = 0;
                                }
                            }

                            break;
                        }
                    case "RECTANGLE":
                        {
                            var rect = new Rectangle
                            {
                                Tag = lcdt.Tag,
                                Fill = backgroundBrush ?? gray
                            };

                            if (lcdt.Width.HasValue)
                            {
                                rect.Width = lcdt.Width.Value;
                            }

                            if (lcdt.Height.HasValue)
                            {
                                rect.Height = lcdt.Height.Value;
                            }

                            element = rect;

                            element.Tapped += async (s, a) => await mainPage.SendEvent(s, a, "tapped", lcdt);
                            rect.PointerEntered += async (s, a) => await mainPage.SendEvent(s, a, "entered", lcdt);
                            rect.PointerExited += async (s, a) => await mainPage.SendEvent(s, a, "exited", lcdt);

                            break;
                        }
                    case "TEXT":
                        {
                            TextBlock textBlock = new TextBlock
                            {
                                Text = lcdt.Message,
                                FontSize = lcdt.Size ?? DefaultFontSize,
                                TextWrapping = TextWrapping.Wrap,
                                Tag = lcdt.Tag,
                                Foreground = textForgroundBrush
                            };

                            expandToEdge = true;

                            element = textBlock;
                            element.SetValue(Canvas.LeftProperty, lcdt.X);
                            element.SetValue(Canvas.TopProperty, lcdt.Y);
                            break;
                        }

                    default:
                        break;
                }
            }

            if (element == null && isText && lcdt.Message != null)
            {
                var x = lcdt.X ?? 0;
                var y = lcdt.Y ?? lastY + 1;

                expandToEdge = true;

                element = new TextBlock
                {
                    Text = lcdt.Message,
                    FontSize = lcdt.Size ?? DefaultFontSize,
                    TextWrapping = TextWrapping.Wrap,
                    Tag = y.ToString(),
                    Foreground = textForgroundBrush
                };

                var textblock = (TextBlock)element;

                textblock.FontFamily = fixedFont;

                if (lcdt.Foreground != null)
                {
                    textblock.Foreground = HexColorToBrush(lcdt.Foreground);
                }

                if (lcdt.HorizontalAlignment != null)
                {
                    if (lcdt.HorizontalAlignment.Equals("Center"))
                    {
                        textblock.TextAlignment = TextAlignment.Center;
                    }
                }

                element.SetValue(Canvas.LeftProperty, isText ? x * textblock.FontSize : x);
                element.SetValue(Canvas.TopProperty, isText ? y * textblock.FontSize : y);
            }
            else if (element != null && element.GetType() != typeof(Line))
            {
                element.SetValue(Canvas.LeftProperty, lcdt.X);
                element.SetValue(Canvas.TopProperty, lcdt.Y);
            }

            if (element != null)
            {
                var x = lcdt.X ?? 0;
                var y = lcdt.Y ?? lastY + 1;

                if (lcdt.HorizontalAlignment != null)
                {
                    if (lcdt.HorizontalAlignment.Equals("Center"))
                    {
                        element.HorizontalAlignment = HorizontalAlignment.Center;
                        element.Width = mainPage.canvas.Width;
                    }
                }

                if (lcdt.FlowDirection != null)
                {
                    if (lcdt.FlowDirection.Equals("RightToLeft"))
                    {
                        element.FlowDirection = FlowDirection.RightToLeft;
                    } else if (lcdt.FlowDirection.Equals("LeftToRight"))
                    {
                        element.FlowDirection = FlowDirection.LeftToRight;
                    }
                }

                if (lcdt.Width.HasValue)
                {
                    element.Width = lcdt.Width.Value;
                }
                else if (expandToEdge)
                {
                    element.Width = mainPage.canvas.ActualWidth;
                }

                if (lcdt.Height.HasValue)
                {
                    element.Height = lcdt.Height.Value;
                }

                //TODO: add optional/extra properties in a later version here.
                if (isText && x == 0)
                {
                    RemoveLine(y);
                }

                element.SetValue(RemoteIdProperty, lcdt.Id);

                mainPage.canvas.Children.Add(element);

                if (isText)
                {
                    lastY = y;
                }
            }
        }