private void inkoverlay_SelectionMovedOrResized(object sender, Rectangle oldbbox) { dbg.WriteLine("----- inkoverlay_SelectionMovedOrResized -----"); // Ensure we're on the UI thread. dbg.Assert(!this.InvokeRequired); try // To prevent exceptions from propagating back to ink runtime. { // Formulate matrix to represent old->new transform. Strokes selection = inkoverlay.Selection; Rectangle newbbox = selection.GetBoundingBox(); using (Matrix m = Geometry.MatrixFromRects(oldbbox, newbbox)) { // Move the bodies and any attached mechanisms. ArrayList mechlist = new ArrayList(); RigidBodyBase[] bodies = doc.GetBodiesFor(selection); foreach (RigidBodyBase body in bodies) { body.Transform(m); MechanismBase[] mechs = doc.GetMechanismsForBody(body); foreach (MechanismBase mech in mechs) { if (!mechlist.Contains(mech)) { mechlist.Add(mech); } } // Move the bodytag to match. if (bodytag.Visible) { ShowBodyTag(body); } } foreach (MechanismBase mech in mechlist) { mech.Transform(m); } } // Repaint everything. Note: if excess flicker becomes apparent, it // might be reduced by invalidating the individual items' bounding boxes. Invalidate(); } catch (Exception ex) { // Log the error. Global.HandleThreadException(this, new System.Threading.ThreadExceptionEventArgs(ex)); } }
public Recognition(Strokes s, Result r, int baseline, int midpt) { _strokes = s; _bbox = s.GetBoundingBox(); updateIds(); allograph = ""; _curalt = 0; alts = new Result[] { r }; baselinealts = new int[] { baseline }; xheightalts = new int[] { midpt }; levelsetby = int.MaxValue; msftRecoged = false; }
private void OnObjectReceived(object o, ObjectReceivedEventArgs orea) { try { // Don't receive your own data if (orea.Participant != Conference.LocalParticipant) { if (orea.Data is SerializedInk) { Strokes strokes = ((SerializedInk)orea.Data).Strokes; // This call fails, claiming the strokes are in 2 ink objects // inkOverlay.Ink.Strokes.Add(strokes); // But this call works inkOverlay.Ink.AddStrokesAtRectangle(strokes, strokes.GetBoundingBox()); } else if (orea.Data is DeletedStrokes) { string[] identifiers = ((DeletedStrokes)orea.Data).Identifiers; Ink ink = inkOverlay.Ink; for (int i = 0; i < identifiers.Length; i++) { for (int j = ink.Strokes.Count - 1; j >= 0; j--) { Stroke stroke = ink.Strokes[j]; if ((string)stroke.ExtendedProperties[StrokeIdentifier].Data == identifiers[i]) { ink.DeleteStroke(stroke); break; } } } } else if (orea.Data is EraseAllInk) { inkOverlay.Ink.DeleteStrokes(); } // Update the screen when data arrives pbInk.Refresh(); } } catch (Exception e) { Log(string.Format(CultureInfo.CurrentCulture, "Exception: {0}", e.ToString())); } }
// actually, this next one is just used for setting word recognition from WPF-using stuff, replacing variant after public Recognition(Strokes s, string allog, string word, int baseline, int midpt) { _strokes = s; _bbox = s.GetBoundingBox(); updateIds(); allograph = allog; _curalt = 0; alts = new Result[] { word.Length == 1 ? new Result(word[0]) : new Result(word) }; baselinealts = new int[] { baseline }; xheightalts = new int[] { midpt }; levelsetby = int.MaxValue; msftRecoged = true; Console.WriteLine("Learner Hook: Here we will replace a result"); }
private void hover_EditCloneClicked(object sender, EventArgs e) { Strokes selected = inkoverlay.Selection; if (selected == null || selected.Count != 1) { return; } // Get objects for the targeted stroke(s). Ensure that only one is selected. RigidBodyBase[] bodies = doc.GetBodiesFor(selected); if (bodies.Length != 1) { return; } RigidBodyBase body = bodies[0]; // First, clone the ink stroke. Move it down and to the right a bit. Rectangle newrect = selected.GetBoundingBox(); newrect.Offset(1000, 1000); doc.Ink.AddStrokesAtRectangle(selected, newrect); // Next, clone the body, binding it to the new stroke id. // Note: we got the new Strokes' ids by listening to the InkAdded event // AddStrokesAtRectangle doesn't return the strokes' ids. RigidBodyBase newbody = body.Clone(neweststrokeids[0]); doc.Bodies.Add(newbody); // Repaint the area around the newbody. Rectangle dirtybbox = newbody.BoundingBox; InvalidateInkSpaceRectangle(dirtybbox); // Select it, to show the smart tag. inkoverlay.Selection = doc.Ink.CreateStrokes(neweststrokeids); }
public Recognition(Strokes s, string _allograph, int baseline, int midpt, bool msftRecog) { _strokes = s; _bbox = s.GetBoundingBox(); updateIds(); allograph = _allograph; _curalt = 0; Result[] tmpalts; if (_allographToAlternates.TryGetValue(allograph + (msftRecog?"MSFT":""), out tmpalts)) { alts = (Result[])tmpalts.Clone(); } else if (_allograph.Length == 1) { alts = new Result[] { new Result(_allograph[0]) }; } else { alts = new Result[] { new Result(_allograph) }; } for (int i = 0; i < alts.Length; i++) { alts[i] = new Result(alts[i]); } baselinealts = new int[alts.Length]; xheightalts = new int[alts.Length]; levelsetby = int.MaxValue; msftRecoged = msftRecog; for (int i = 0; i < alts.Length; i++) { SetMetrics(alts[i] == Result.Special.Imaginary ? "i" : alts[i], // bcz: Hack! need to do something similar for 'e' etc? baseline, midpt, ref baselinealts[i], ref xheightalts[i]); } }
/// <summary> /// Sets the selected strokes and selection rectangle. /// </summary> /// <param name="strokes">The strokes that should be selected. If null, the selection becomes empty</param> private void SetSelection(Strokes strokes) { // Tracks whether the rectangle that bounds the selected // strokes should be displayed bool isSelectionVisible = false; // Update the selected strokes collection selectedStrokes = strokes; // If no strokes are selected, set the selection rectangle // to empty if (!HasSelection()) { selectionRect = Rectangle.Empty; } // Otherwise, at least one stroke is selected and it is necessary // to display the selection rectangle. else { isSelectionVisible = true; // Retrieve the bounding box of the strokes selectionRect = selectedStrokes.GetBoundingBox(); using (Graphics g = CreateGraphics()) { InkSpaceToPixel(g, ref selectionRect); } // Pad the selection rectangle so that the selected ink // doesn't overlap with the selection rectangle's handles. selectionRect.Inflate(SelectionRectBuffer, SelectionRectBuffer); // compute the center of the rectangle that bounds the // selected strokes int xAvg = (selectionRect.Right+selectionRect.Left)/2; int yAvg = (selectionRect.Top+selectionRect.Bottom)/2; // Draw the resize handles // top left SetLocation(selectionHandles[0],selectionRect.Left, selectionRect.Top); // top SetLocation(selectionHandles[1],xAvg, selectionRect.Top); // top right SetLocation(selectionHandles[2],selectionRect.Right, selectionRect.Top); // left SetLocation(selectionHandles[3],selectionRect.Left, yAvg); // right SetLocation(selectionHandles[4],selectionRect.Right, yAvg); // bottom left SetLocation(selectionHandles[5],selectionRect.Left, selectionRect.Bottom); // bottom SetLocation(selectionHandles[6],xAvg, selectionRect.Bottom); // bottom right SetLocation(selectionHandles[7],selectionRect.Right, selectionRect.Bottom); } // Set the visibility of each selection handle in the // selection rectangle. If there is no selection, all // handles should be hidden. Otherwise, all handles should // be visible. foreach(PictureBox pb in selectionHandles) { pb.Visible = isSelectionVisible; } // Turn off autoredrawing if there is a selection - otherwise, // the selected ink will not be displayed as selected. myInkCollector.AutoRedraw = !isSelectionVisible; // Since the selection has changed, repaint the screen. Refresh(); }
public Recognition(Strokes s, string _allograph, int midpt, bool msftRecog) : this(s, _allograph, s.GetBoundingBox().Bottom, midpt, msftRecog) { }