public TransformerTranslate(KPage page, InkControl control, params Transformer[] transformer) { innerRad = (int)(20 * Util.GetScaleFactor()); if (img == null || img.IsDisposed) { Bitmap bmp = ResManager.LoadIcon("gui/translator.svg", innerRad); img = new Renderer.Image(bmp); } this.control = control; this.page = page; this.pageVersion = page.Version; this.transformer = transformer; int c = 0; float _x = 0, _y = 0; selectedLines = new bool[page.LineCount]; for (int i = 0; i < page.LineCount; i++) { Line l = page.GetLine(i); if (l.Selected) { PointF center = new PointF(l.Bounds.X + l.Bounds.Width / 2, l.Bounds.Y + l.Bounds.Height / 2); _x += center.X; _y += center.Y; c++; } selectedLines[i] = l.Selected; } _x /= c; _y /= c; //control.GetTransform().Transform(ref _x, ref _y); //PointF pf = control.GetTransform().GetTranslation(); x = (int)(_x); y = (int)(_y); this.Others = new List <Transformer>(this.transformer); this.Others.Add(this); foreach (Transformer trans in this.transformer) { trans.SetPosition(x, y); trans.Others = this.Others; } }
public override bool Think(List <Touch> allTouches, ref Touch stylus, ref Touch mouse, int screenWidth, int screenHeight) { if (IsMouseDown()) { return(false); } if (page.LineCount != selectedLines.Length) { Close = true; } else { for (int i = 0; i < page.LineCount; i++) { if (selectedLines[i] != page.GetLine(i).Selected) { Close = true; } } } if (control.Page != page) { Close = true; } bool refresh = false; PointF?cursorPos = null; uint pointerId = 0; if (stylus != null) { cursorPos = new PointF(stylus.X, stylus.Y); pointerId = stylus.Id; } else if (mouse != null) { cursorPos = new PointF(mouse.X, mouse.Y); pointerId = mouse.Id; } else if (allTouches.Count > 0) { cursorPos = new PointF(allTouches[0].X, allTouches[0].Y); pointerId = allTouches[0].Id; } if (cursorPos.HasValue && Collides(cursorPos.Value.X, cursorPos.Value.Y, screenWidth, screenHeight)) { currentTouchId = pointerId; } if (currentTouchId != uint.MaxValue) { Touch t = null; t = stylus | mouse; if (t == null) { foreach (Touch touch in allTouches) { if (touch.Id == currentTouchId) { t = touch; break; } } } if (t != null) { int ox = this.x; int oy = this.y; this.x = t.X; this.y = t.Y; control.GetTransform().GetInverse().Transform(ref this.x, ref this.y); page.TransformCurrentObjects(Matrix3x3.Translation(x - ox, y - oy)); foreach (Transformer trans in this.transformer) { trans.SetPosition(x, y); } control.RefreshPage(); } else { currentTouchId = uint.MaxValue; HistoryManager.StoreState(page); } stylus = null; mouse = null; allTouches.Clear(); refresh = true; } if (Close) { foreach (Transformer trans in this.transformer) { trans.Close = true; } } if (firstcall) { firstcall = false; refresh = true; } MouseDown = currentTouchId != uint.MaxValue; return(refresh); }