protected override void OnMouseMove(MouseEventArgs e) { var cp = e.GetPosition(this); if (IsMouseCaptured && Keyboard.IsKeyDown(Key.LeftCtrl)) { var pnt = (IInputElement)this.Parent; Point p = e.GetPosition(pnt); double toX = startOffset.X + p.X - ScreenStartPoint.X; double toY = startOffset.Y + p.Y - ScreenStartPoint.Y; _translateTransform.X = toX; _translateTransform.Y = toY; } else if (e.LeftButton == MouseButtonState.Pressed && (move || (Math.Abs(cp.X - ScreenStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(cp.Y - ScreenStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance))) { move = true; if (selected != null) { loElement el; loBinding w; loPin pin; if ((el = selected as loElement) != null) { el.SetLocation(new Vector(el.OriginalLocation.X + (cp.X - ScreenStartPoint.X), el.OriginalLocation.Y + (cp.Y - ScreenStartPoint.Y)), false); } else if ((pin = selected as loPin) != null && (pin.IsFreeInput || !pin.IsInput)) { w = new loBinding(selected as loPin, this); w.Update(ScreenStartPoint); selected = w; } else if ((w = selected as loBinding) != null && (w.Input == null || w.Output == null)) { w.Update(cp); } } else if (_mSelected != null) { foreach (var el in _mSelected) { el.SetLocation(new Vector(el.OriginalLocation.X + (cp.X - ScreenStartPoint.X), el.OriginalLocation.Y + (cp.Y - ScreenStartPoint.Y)), false); } } else { if (!_multipleSelection) { _multipleSelection = true; base.AddVisualChild(_mSelectVisual); } using (DrawingContext dc = _mSelectVisual.RenderOpen()) { dc.DrawRectangle(null, SelectionPen, new Rect(ScreenStartPoint, cp)); } } } else { base.OnMouseMove(e); } }
private void SourceLoaded(Task <DTopic> tt) { if (tt.IsFaulted || !tt.IsCompleted || tt.Result == null) { _mode = 1; return; } _source = tt.Result; DTopic lo = model.parent; if (_owner is loBlock && lo != null) { lo = lo.parent; } if (tt.Result.parent == lo || (tt.Result.parent != null && tt.Result.parent.parent == lo)) { _mode = 2; var src = lv._visuals.OfType <loPin>().FirstOrDefault(z => z.model == _source && !z.IsInput); if (src != null) { if (_srcBinding != null) { _srcBinding.Dispose(); } _srcBinding = new loBinding(src, this, lv); src.AddBinding(_srcBinding); this.Render(3); } } else { _mode = 3; this.Render(3); } }
private void DeleteLI(loItem el) { loBinding b = el as loBinding; DTopic t; if (b != null && (t = b.Output.GetModel()) != null) { t.SetField("cctor.LoBind", null); } else if ((t = el.GetModel()) != null && (t.Manifest == null || (JsLib.OfInt(t.Manifest, "attr", 0) & 1) != 1)) { t.Delete(); } }
public void AddBinding(loBinding w) { if (w == null) { return; } if (_mode == 0) { _connections.Add(w); } else { if (_srcBinding != null) { _srcBinding.Dispose(); } _srcBinding = w; _mode = 2; } Render(3); }
public override void Render(int chLevel) { if (model == null || model.State == null || model.Manifest == null) { return; } if (_mode != 0 && chLevel == 3) { var src_s = JsLib.OfString(JsLib.GetField(model.Manifest, "cctor.LoBind"), null); if (src_s == null) { _mode = 1; } else if (_source == null || _source.path != src_s || (_mode == 2 && _srcBinding == null && lv._dataIsLoaded)) { model.GetAsync(src_s).ContinueWith(SourceLoaded, TaskScheduler.FromCurrentSynchronizationContext()); return; } if (_mode != 2 && _srcBinding != null) { _source = null; _srcBinding.Dispose(); _srcBinding = null; } } this.Offset = _owner.Offset + _ownerOffset; if (chLevel == 3) { lv.MapRemove(this); lv.MapSet(_mode == 0 ? 3 : 0, (int)(Offset.X / CELL_SIZE + 0.5), (int)(Offset.Y / CELL_SIZE + 0.5), this); } var tc = model.State.ValueType; Brush br; switch (tc) { case JSC.JSValueType.Object: if (model.State is ByteArray || model.State.Value is ByteArray) { br = brByteArray; } else { br = Brushes.MediumOrchid; } break; case JSC.JSValueType.String: br = Brushes.Gold; break; case JSC.JSValueType.Double: case JSC.JSValueType.Integer: { double val = (double)model.State; br = val > 0 ? (val == 1 ? Brushes.LawnGreen : Brushes.LightSeaGreen) : (val == 0 ? brValueFalse : Brushes.DodgerBlue); //-V3024 } break; case JSC.JSValueType.Boolean: br = (bool)model.State.Value ? Brushes.LawnGreen : brValueFalse; //-V3095 break; default: br = Brushes.Black; break; } bool ic = (!(_owner is loVariable) || _mode == 0) && JsLib.ofBool(JsLib.GetField(model.Manifest, "Logram.trace"), false); if (!ic && chLevel == 1 && this.brush == br) { return; } this.brush = br; string val_s = string.Empty; if (ic) { var v = model.State; if (v != null) { switch (v.ValueType) { case JSC.JSValueType.Boolean: case JSC.JSValueType.Integer: case JSC.JSValueType.String: val_s = v.Value.ToString(); break; case JSC.JSValueType.Double: { double d = (double)v; int p = (int)Math.Log10(Math.Abs(d)); switch (p) { case -2: val_s = d.ToString("0.000##"); break; case -1: val_s = d.ToString("0.00##"); break; case 0: val_s = d.ToString("0.0##"); break; case 1: val_s = d.ToString("0.##"); break; case 2: val_s = d.ToString("0.#"); break; case 3: val_s = d.ToString("0.#"); break; case 4: val_s = d.ToString("0"); break; default: val_s = d.ToString("G4"); break; } } break; case JSC.JSValueType.Date: { var dt = (v.Value as JSL.Date).ToDateTime(); val_s = dt.ToString("yyMMdd HH:mm:ss"); break; } } } } using (DrawingContext dc = this.RenderOpen()) { if (_mode == 3) { dc.DrawRectangle(_selected ? brItemSelected : this.brush, null, new Rect(-2, -5, 4, 10)); } else { dc.DrawEllipse(_selected ? brItemSelected : this.brush, null, new Point(0, 0), 3, 3); } if (ic) { var ft = new FormattedText(val_s, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.Black); Point p; if (_mode == 0) { p = new Point(2, 2 - CELL_SIZE); } else { p = new Point(-2 - ft.WidthIncludingTrailingWhitespace, 2 - CELL_SIZE); } dc.DrawText(ft, p); } } if (_mode != 0 && _srcBinding != null && chLevel > 1) { _srcBinding.Render(chLevel); } if (_mode == 0 && chLevel > 0) { foreach (loBinding w in _connections.ToArray()) { w.Render(chLevel); } } }
public void RemoveBinding(loBinding w) { _connections.Remove(w); }