private static TerminalID[] CreateTIDs(Gates.IOGates.AbstractNumeric gate) { // note that only ONE of these can be true // but we do an add so that it works for whichever // one is selected TerminalID[] tids = new TerminalID[gate.NumberOfInputs + gate.Output.Length]; int tidx = 0; // for the top line we invert the ordering // this matches standard IC numbering // AND provides for matching up of LSB for (int i = 0; i < gate.NumberOfInputs; i++) { tids[tidx++] = new TerminalID(true, gate.NumberOfInputs - i - 1, Position.TOP); } // for the bottom, we will purposefully // violate standard IC numbering // BECAUSE we want the visual appearance of // a binary # to line up with the illuminated ports for (int i = 0; i < gate.Output.Length; i++) { tids[tidx++] = new TerminalID(false, gate.Output.Length - i - 1, Position.BOTTOM); } return(tids); }
public Numeric(Gates.IOGates.AbstractNumeric gate) : base(gate, CreateTIDs(gate) ) { _nu = gate; Rectangle r = new Rectangle(); r.Margin = new System.Windows.Thickness(15); r.Width = this.Width - 30; r.Height = this.Height - 30; r.Stroke = Brushes.Black; r.StrokeThickness = 2; r.Fill = Brushes.White; myCanvas.Children.Add(r); nval = new TextBox(); nval.Margin = new System.Windows.Thickness(20); nval.FontFamily = new FontFamily("Courier New"); nval.FontSize = 12; nval.TextAlignment = TextAlignment.Center; nval.Width = this.Width - 40; nval.Height = 18; nval.Background = Brushes.AntiqueWhite; Binding bind = new Binding("Value"); bind.Source = _nu; bind.Mode = BindingMode.TwoWay; bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; bind.ValidatesOnExceptions = true; nval.SetBinding(TextBox.TextProperty, bind); Binding bindve = new Binding("(Validation.Errors)[0].Exception.InnerException.Message"); bindve.Source = nval; bindve.Mode = BindingMode.OneWay; nval.SetBinding(TextBox.ToolTipProperty, bindve); myCanvas.Children.Add(nval); TextBlock tb = new TextBlock(); tb.Margin = new Thickness(20, 36, 20, 20); tb.FontSize = 8; tb.Text = "!!!"; tb.Width = this.Width - 40; tb.TextAlignment = TextAlignment.Center; tb.ToolTip = "Click to Change Representation"; Binding bindrep = new Binding("SelectedRepresentation"); bindrep.Converter = new RepConverter(); bindrep.Source = _nu; bindrep.Mode = BindingMode.OneWay; tb.SetBinding(TextBlock.TextProperty, bindrep); tb.MouseDown += new System.Windows.Input.MouseButtonEventHandler(tb_MouseDown); tb.MouseEnter += new System.Windows.Input.MouseEventHandler(tb_MouseEnter); tb.MouseLeave += new System.Windows.Input.MouseEventHandler(tb_MouseLeave); myCanvas.Children.Add(tb); }
public Numeric(Gates.IOGates.AbstractNumeric gate) : base(gate, CreateTIDs(gate)) { _nu = gate; Rectangle r = new Rectangle(); r.Margin = new System.Windows.Thickness(15); r.Width = this.Width - 30; r.Height = this.Height - 30; r.Stroke = Brushes.Black; r.StrokeThickness = 2; r.Fill = Brushes.White; myCanvas.Children.Add(r); nval = new TextBox(); // green team : // set event handler to call GotFocus() nval.GotFocus += new RoutedEventHandler(nval_GotFocus); nval.Margin = new System.Windows.Thickness(20); nval.FontFamily = new FontFamily("Courier New"); nval.FontSize = 12; nval.TextAlignment = TextAlignment.Center; nval.Width = this.Width - 40; nval.Height = 18; nval.Background = Brushes.AntiqueWhite; Binding bind = new Binding("Value"); bind.Source = _nu; bind.Mode = BindingMode.TwoWay; bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; bind.ValidatesOnExceptions = true; nval.SetBinding(TextBox.TextProperty, bind); Binding bindve = new Binding("(Validation.Errors)[0].Exception.InnerException.Message"); bindve.Source = nval; bindve.Mode = BindingMode.OneWay; nval.SetBinding(TextBox.ToolTipProperty, bindve); myCanvas.Children.Add(nval); TextBlock tb = new TextBlock(); tb.Margin = new Thickness(20, 36, 20, 20); tb.FontSize = 8; tb.Text = "!!!"; tb.Width = this.Width - 40; tb.TextAlignment = TextAlignment.Center; tb.ToolTip = "Click to Change Representation"; Binding bindrep = new Binding("SelectedRepresentation"); bindrep.Converter = new RepConverter(); bindrep.Source = _nu; bindrep.Mode = BindingMode.OneWay; tb.SetBinding(TextBlock.TextProperty, bindrep); tb.MouseDown += new System.Windows.Input.MouseButtonEventHandler(tb_MouseDown); tb.MouseEnter += new System.Windows.Input.MouseEventHandler(tb_MouseEnter); tb.MouseLeave += new System.Windows.Input.MouseEventHandler(tb_MouseLeave); myCanvas.Children.Add(tb); }