コード例 #1
0
 private void blockTextChange(object sender, RoutedEventArgs e)
 {
     LabelTextBox ltb = new LabelTextBox();
     ltb.txt = (TextBox)sender;
     ltb.txb.Text = ltb.txt.Text;
 }
コード例 #2
0
 public static Size MeasureTextSize(string text, LabelTextBox ob)
 {
     FontFamily fontFamily = ob.txb.FontFamily;
     FontStyle fontStyle = ob.txb.FontStyle;
     FontWeight fontWeight = ob.txb.FontWeight;
     FontStretch fontStretch = ob.txb.FontStretch;
     double fontSize = ob.txb.FontSize;
     FormattedText ft = new FormattedText(text,
                                          CultureInfo.CurrentCulture,
                                          FlowDirection.LeftToRight,
                                          new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                                          fontSize,
                                          Brushes.Black);
     return new Size(ft.Width, ft.Height);
 }
コード例 #3
0
            private void createBlock(int row, int col, int blockWidth, int blockHeight)
            {
                if (currentBlockType == JsonToDML.DMLUIElementSyntax.InputBlock)
                {
                    InputBlockPropertiesViewModel ob = new InputBlockPropertiesViewModel();
                    ob.OnParameterChange += ParameterViewModel_OnParameterChange_Input;
                
                    int numberOfBlocksLabel;
                    int numberOfBlocksBox;
                    LabelTextBox ltb = new LabelTextBox();
                    ltb.DataContext = ob;

                    uid++;
                    ob.ID = uid.ToString();
                    ob.Row = row.ToString();
                    ob.Col = col.ToString();
                    ob.dmlKeyword = currentBlockType;
                    ltb.txb.Text = "Label";
             
                    Size s = MeasureTextSize(ltb.txb.Text, ltb);
                    numberOfBlocksLabel = (int)Math.Ceiling((double)(Math.Ceiling(s.Width) / WIDTH));
                    numberOfBlocksBox = blockWidth - numberOfBlocksLabel;

                    ltb.Width = blockWidth * WIDTH;
                    ltb.Height = blockHeight * HEIGHT;

                    ltb.txb.Width = WIDTH * numberOfBlocksLabel;
                    ltb.txb.Height = HEIGHT * blockHeight;

                    ltb.txt.Width = WIDTH * numberOfBlocksBox;
                    ltb.txt.Height = HEIGHT * blockHeight;

                    ltb.txt.BorderBrush = Brushes.Red;
                    ltb.txt.BorderThickness = new Thickness(2, 2, 2, 2);

                    ltb.txt.TextChanged += blockTextChange;
                    ltb.PreviewKeyDown += selectInputBlock;
                    ltb.PreviewMouseDown += mouseClickInputBlock;

                    Grid.SetRow(ltb, row);
                    Grid.SetColumn(ltb, col - numberOfBlocksLabel);
                    Grid.SetColumnSpan(ltb, ((int)(ltb.Width) / WIDTH));
                    Grid.SetRowSpan(ltb, ((int)(ltb.Height) / HEIGHT));
                    MyGrid.Children.Add(ltb);

                    var blockName = "BLOCK";
                    blockNameCount = blockNameCount + 1;
                    blockName = "BLOCK_" + blockNameCount;

                    daElement = new DrawAreaUiElement(ob.ID, currentBlockType, ob.Row.ToString(), ob.Col.ToString(), blockName, "TOKEN", "", "#TARGET", "#SOURCE", "", ltb.txt.Width.ToString(), "12", ltb.txt.Height.ToString());
                    daList.addUIElementToUIElementList(daElement);
                    DrawToJSON.DrawAreaToJSON(daList.UIL);

                    inputBlockPropertiesViewModel = ob;
                    viewModelList.Add(ob);
                    inputBlockPropertiesViewModel.inputBlockVisibility = Visibility.Visible;
                    outputBlockPropertiesViewModel.outputBlockVisibility = Visibility.Collapsed;
                }
                else if (currentBlockType == JsonToDML.DMLUIElementSyntax.OutputBlock)
                {
                    OutputBlockPropertiesViewModel ob = new OutputBlockPropertiesViewModel();
                    ob.OnParameterChange += ParameterViewModel_OnParameterChange_Output;

                    int numberOfBlocksLabel;
                    int numberOfBlocksBox;
                    LabelTextBox ltb = new LabelTextBox();
                    ltb.DataContext = ob;

                    uid++;
                    ob.ID = uid.ToString();
                    ob.Row = row.ToString();
                    ob.Col = col.ToString();
                    ob.dmlKeyword = currentBlockType;
                    ltb.txb.Text = "Label";

                    Size s = MeasureTextSize(ltb.txb.Text, ltb);
                    numberOfBlocksLabel = (int)Math.Ceiling((double)(Math.Ceiling(s.Width) / WIDTH));
                    numberOfBlocksBox = blockWidth - numberOfBlocksLabel;

                    ltb.Width = blockWidth * WIDTH;
                    ltb.Height = blockHeight * HEIGHT;

                    ltb.txb.Width = WIDTH * numberOfBlocksLabel;
                    ltb.txb.Height = HEIGHT * blockHeight;

                    ltb.txt.Width = WIDTH * numberOfBlocksBox;
                    ltb.txt.Height = HEIGHT * blockHeight;

                    ltb.txt.BorderBrush = Brushes.Red;
                    ltb.txt.BorderThickness = new Thickness(2, 2, 2, 2);

                    ltb.txt.TextChanged += blockTextChange;
                    ltb.PreviewKeyDown += selectOutputBlock;
                    ltb.PreviewMouseDown += mouseClickOutputBlock;

                    Grid.SetRow(ltb, row);
                    Grid.SetColumn(ltb, col - numberOfBlocksLabel);
                    Grid.SetColumnSpan(ltb, ((int)(ltb.Width) / WIDTH));
                    Grid.SetRowSpan(ltb, ((int)(ltb.Height) / HEIGHT));
                    MyGrid.Children.Add(ltb);

                    var blockName = "BLOCK";
                    blockNameCount = blockNameCount + 1;
                    blockName = "BLOCK_" + blockNameCount;

                    daElement = new DrawAreaUiElement(ob.ID, currentBlockType, ob.Row.ToString(), ob.Col.ToString(), blockName, "TOKEN", "", "#TARGET", "#SOURCE", "", ltb.txt.Width.ToString(), "12", ltb.txt.Height.ToString());
                    daList.addUIElementToUIElementList(daElement);
                    DrawToJSON.DrawAreaToJSON(daList.UIL);

                    outputBlockPropertiesViewModel = ob;
                    viewModelOutputList.Add(ob);
                    inputBlockPropertiesViewModel.inputBlockVisibility = Visibility.Collapsed;
                    outputBlockPropertiesViewModel.outputBlockVisibility = Visibility.Visible;
                }
            }