예제 #1
0
        private ScrollViewer getIndexTextBlock(Message msg)
        {
            ScrollViewer sv = null;

            sv = MainGrid.FindName("scrollViewerIndex" + msg.Id) as ScrollViewer;
            if (sv != null)
            {
                return(sv);
            }

            sv        = new ScrollViewer();
            sv.Height = msg.Size(0);
            sv.Width  = msg.Size(0);
            sv.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            sv.Margin = new Thickness(10);

            TextBlock tb = new TextBlock();

            tb.TextWrapping = TextWrapping.Wrap;
            tb.Inlines.Add(new Bold(new Run(msg.SenderName + ": ")));
            tb.Inlines.Add(new Run(msg.Content));
            tb.Background = new SolidColorBrush(msg.Color);
            tb.FontSize   = msg.FontSize();
            tb.MouseUp   += tb_MouseUp;

            tb.MouseEnter += tb_MouseEnter;
            tb.MouseLeave += tb_MouseLeave;

            tb.Tag = msg;

            sv.Content = tb;

            return(sv);
        }
예제 #2
0
        private void drawReferenceCircles()
        {
            int    i = 0;
            string controlNameBase = "ReferenceCircle";
            string name            = controlNameBase + i;

            // do it once, only after the control has been loaded:
            if (MainGrid.IsLoaded && (MainGrid.FindName(name) as Ellipse) == null)
            {
                foreach (double radius in circleDistances)
                {
                    // keep in mind that ScannedArea is a bit raised over what we consider the robot center.

                    // radius = MapperSettings.referenceCircleRadiusMeters;
                    double diamW = radius * ScannedArea.ActualWidth / rangeMaxValueM;
                    double diamH = radius * ScannedArea.ActualHeight * 2.0d / rangeMaxValueM;

                    // draw reference circle (usually 2 meters):
                    Ellipse circle = new Ellipse()
                    {
                        Name            = controlNameBase + i,
                        Width           = diamW,
                        Height          = diamH,
                        Margin          = new Thickness((MainGrid.ActualWidth - diamW) / 2.0d, (MainGrid.ActualHeight * 2.0d - diamH) / 2.0d, 0, 0),
                        Stroke          = Brushes.Cyan,
                        StrokeThickness = 1
                    };
                    MainGrid.Children.Add(circle);
                    MainGrid.RegisterName(circle.Name, circle);
                    i++;
                }
            }
        }
예제 #3
0
 private void LoadInnerGrid()
 {
     if (SingleStopControl == null)
     {
         SingleStopControl = (Grid)MainGrid.FindName("SingleStopControl");
     }
 }
예제 #4
0
        public void InitNode()
        {
            int    i;
            object tmp;

            node = new List <NodeInfo>(48);
            for (i = 0; i < 48; ++i)
            {
                node.Add(null);
            }

            for (i = 0; i < 48; ++i)
            {
                node[i] = new NodeInfo(i / 8, i % 8);
                string name = "lable" + i / 8 + i % 8;
                tmp           = MainGrid.FindName(name);
                node[i].lable = (Label)tmp;
                if (tmp is Label)
                {
                    Console.WriteLine("Node " + i + " is Label with row: " + i / 8 + ", col: " + i % 8);
                }
                else
                {
                    Console.WriteLine("Node " + i + " is NOT Label with row: " + i / 8 + ", col: " + i % 8);
                }
            }

            initNamePic();
            if (!dispatcherTimer.IsEnabled)
            {
                dispatcherTimer.Start();
            }
        }
예제 #5
0
 private void LoadInnerScrollViewer()
 {
     if (scrollViewer == null)
     {
         scrollViewer = (ScrollViewer)MainGrid.FindName("scrollViewer");
         //ItemsPanel = (StackPanel)scrollViewer.FindName("ItemsPanel");
     }
 }
예제 #6
0
        public MainWindow()
        {
            InitializeComponent();
            levelInfo                = LevelHelper.getLevelInfo(0);
            random                   = new Random();
            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            isGameContinue           = true;
            failNotiyer              = new FAIL(LevelHelper.gameLevel);

            dispatcherTimer.Start();
            // start init game info
            InitNode();
            setNodeStartLevel();
            refreshNodeState();
            // end of start game info

            object item = MainGrid.FindName("lableInfo");

            if (item is Label)
            {
                labelInfo = (Label)item;
            }
#if false
            object item = MainGrid.FindName("lable00");

            if (item is Label)
            {
                MessageBox.Show("find success!!");
                Label lbl = (Label)item;
                lbl.Background = new ImageBrush(new BitmapImage(new Uri(MASTER_PATH + pic15)));
                lbl.Background = null;
                lbl.Opacity    = 0.3;
            }

            ImageBrush imgBrush = new ImageBrush();

            imgBrush.ImageSource =
                new BitmapImage(new Uri(@"Dock.jpg", UriKind.Relative));
#endif


            string testDir = Directory.GetCurrentDirectory();
            //string[] test2 = Directory.GetDirectories("C:\\Users\\Toan\\source\\repos\\Duong\\Duong\\image\\");
        }
예제 #7
0
        private void Pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            // need to invoke UI updates on the UI thread because this event
            // handler gets invoked on a separate thread.
            var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                var PinName     = GetPinName(sender.PinNumber);
                var PinTextName = GetPinTextName(sender.PinNumber);
                var PinIcon     = MainGrid.FindName(PinName) as Ellipse;
                var PinText     = MainGrid.FindName(PinTextName) as TextBlock;

                var test = Gpio04Status;

                if (e.Edge == GpioPinEdge.FallingEdge)
                {
                    PinIcon.Fill = redBrush;
                    PinText.Text = "Çekiliyor";
                }
                else
                {
                    PinIcon.Fill = grayBrush;
                    PinText.Text = "Boşta";
                }
            });
        }
예제 #8
0
        public void CreateNGrid(int x, int y)
        {
            A = x;

            //repaint
            int intTotalChildren = MainGrid.Children.Count - 1;

            for (int intCounter = intTotalChildren; intCounter > 0; intCounter--)
            {
                if (MainGrid.Children[intCounter].GetType() == typeof(Grid))
                {
                    Grid ucCurrentChild = (Grid)MainGrid.Children[intCounter];
                    MainGrid.Children.Remove(ucCurrentChild);
                }
            }
            //Clear the List
            RuleCells.Clear();
            Grid NGrid = new Grid();

            NGrid.Width  = Double.NaN;
            NGrid.Height = Double.NaN;
            NGrid.HorizontalAlignment = HorizontalAlignment.Left;
            NGrid.VerticalAlignment   = VerticalAlignment.Top;
            NGrid.SetValue(Grid.RowProperty, 1);
            NGrid.SetValue(Grid.ColumnProperty, 1);
            NGrid.SetValue(Grid.RowSpanProperty, 2);

            for (int i = 0; i < y; i++)
            {
                ColumnDefinition gridCol = new ColumnDefinition();
                gridCol.Width = GridLength.Auto;
                NGrid.ColumnDefinitions.Add(gridCol);
            }

            for (int i = 0; i < x; i++)
            {
                RowDefinition rowdef = new RowDefinition();
                rowdef.Height = GridLength.Auto;
                NGrid.RowDefinitions.Add(rowdef);
            }

            for (int i = 0; i < x; i++)
            {
                List <Cell> sublist = new List <Cell>();
                for (int j = 0; j < y; j++)
                {
                    Label Box = new Label();

                    if (Z == 1)
                    {
                        if (i == 0 && j == 0 || i == 0 && j == 2 || i == 2 && j == 0 || i == 2 && j == 2)
                        {
                            Box.Visibility = Visibility.Hidden;
                            Box.IsEnabled  = false;
                        }
                    }


                    //Middle one is off the charts.
                    if ((i == (x * 2) / 5 && j == (y * 2) / 5))
                    {
                        Box.IsEnabled = false;
                    }


                    Box.Width  = 120 / x;
                    Box.Height = 120 / y;
                    Box.Name   = "Y" + i.ToString() + "Y" + j.ToString();

                    object o = MainGrid.FindName(Box.Name);
                    if (o != null)
                    {
                        MainGrid.UnregisterName(Box.Name);
                    }
                    MainGrid.RegisterName(Box.Name, Box);


                    //  if (neighbourhood != 4)
                    {
                        Cell cell = new Cell(i, j);
                        cell.State = 3;
                        sublist.Add(cell);
                    }


                    Box.MouseDown        += new MouseButtonEventHandler(Cell_Click);
                    Box.BorderBrush       = new SolidColorBrush(Colors.Gray);
                    Box.BorderThickness   = new Thickness(1);
                    Box.FontSize          = 14;
                    Box.FontWeight        = FontWeights.Bold;
                    Box.Foreground        = new SolidColorBrush(Colors.Black);
                    Box.VerticalAlignment = VerticalAlignment.Top;
                    Grid.SetRow(Box, i);
                    Grid.SetColumn(Box, j);
                    NGrid.Children.Add(Box);
                }
                RuleCells.Add(sublist);
            }


            RuleGrid = NGrid;
            MainGrid.Children.Add(NGrid);
        }
예제 #9
0
        private ScrollViewer getTextBlock(Message msg, int level = 0)
        {
            ScrollViewer sv = null;
            TextBlock    tb = null;

            //查找目标UI是否已存在于容器
            sv = MainGrid.FindName("scrollViewer" + msg.Id) as ScrollViewer;
            if (sv == null)
            {
                //没有找到,新建UI
                sv = new ScrollViewer();
                tb = new TextBlock();

                sv.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                tb.TextWrapping = TextWrapping.Wrap;
                tb.Inlines.Add(new Bold(new Run(msg.SenderName + ": ")));
                tb.Inlines.Add(new Run(msg.Content));
                tb.Background = new SolidColorBrush(msg.Color);
                tb.MouseUp   += tb_MouseUp;

                tb.MouseEnter += tb_MouseEnter;
                tb.MouseLeave += tb_MouseLeave;

                tb.Tag = msg;

                sv.Content = tb;
                sv.Tag     = currentCenterId;
            }
            else
            {
                ////已经正常显示则不修改
                if (sv.IsVisible && (int)sv.Tag == currentCenterId)
                {
                    return(sv);
                }
                //否则进行微调
                tb = sv.Content as TextBlock;
            }

            sv.Height   = msg.Size(level);
            sv.Width    = msg.Size(level);
            sv.Tag      = currentCenterId;
            tb.FontSize = msg.FontSize(level);

            if (level == 0 || level == 1)
            {
                //正常显示
                tb.Background = new SolidColorBrush(msg.Color);
                tb.Foreground = Brushes.Black;
            }
            else
            {
                //弱显示
                tb.Background = new SolidColorBrush(msg.LightColor);
                tb.Foreground = new SolidColorBrush(Message.LightFontColor);
            }

            if (!sv.IsVisible)
            {
                if (level == 0)
                {
                    //正中间
                    sv.Margin = new Thickness(0);
                }
                else if (level >= -1)
                {
                    //儿子位置正关联
                    ScrollViewer sv0 = MainGrid.FindName("scrollViewer" + msg.Father) as ScrollViewer;
                    if (sv0 != null)
                    {
                        double distance = sv0.Width + sv.Width;// -randomMove / 2 + random.Next(randomMove);
                        sv.Margin = Message.Position(msg.Place, distance, sv0.Margin);
                    }
                }
                else if (level == -2)
                {
                    //父亲位置负关联
                    ScrollViewer sv0 = MainGrid.FindName("scrollViewer" + currentCenterId) as ScrollViewer;
                    Message      m0  = MessagesKeeper.Get(currentCenterId);
                    if (sv0 != null && m0 != null)
                    {
                        double distance = sv0.Width + sv.Width;// -randomMove / 2 + random.Next(randomMove);
                        sv.Margin = Message.Position(m0.Place, distance, sv0.Margin, -1);
                    }
                }
            }

            sv.Visibility = Visibility.Visible;

            return(sv);
        }