public async Task <SnapsCoordinate> GetTappedCoordinateAsync() { enableTouch(); SnapsCoordinate tappedPositionResult = new SnapsCoordinate(); AutoResetEvent GetTappedPositionCompleteEvent = new AutoResetEvent(false); var tcs = new TaskCompletionSource <object>(); TappedEventHandler lambda = (s, e) => { // Get the position relative to the graphics canvas as this // is the one we will be drawing Point p = e.GetPosition(manager.DisplayGrid);// (Grid) s); tappedPositionResult.XValue = (int)Math.Round(p.X); tappedPositionResult.YValue = (int)Math.Round(p.Y); tcs.TrySetResult(null); }; try { this.Tapped += lambda; await tcs.Task; } finally { this.Tapped -= lambda; disableTouch(); } return(tappedPositionResult); }
public void StartProgram() { while (true) { SnapsCoordinate drawPos = SnapsEngine.GetDraggedCoordinate(); SnapsEngine.DrawDot(pos: drawPos, width: 10); } }
public void StartProgram() { while (true) { SnapsCoordinate tappedPos = SnapsEngine.GetTappedCoordinate(); SnapsEngine.DrawDot(tappedPos, 20); } }
public void StartProgram() { SnapsCoordinate origin = new SnapsCoordinate(x: 0, y: 0); SnapsEngine.SetDrawingColor(red: 255, green: 0, blue: 0); while (true) { SnapsCoordinate lineEnd = SnapsEngine.GetTappedCoordinate(); SnapsEngine.DrawLine(p1: origin, p2: lineEnd); } }
void DrawDotsUntilDrawInLeftCorner() { while (true) { SnapsCoordinate drawPos = SnapsEngine.GetDraggedCoordinate(); if (drawPos.XValue < 50 && drawPos.YValue < 50) { break; } SnapsEngine.DrawDot(pos: drawPos, width: 20); } }
public SnapsCoordinate GetTappedCoordinate() { SnapsCoordinate tappedPositionResult = new SnapsCoordinate(); AutoResetEvent GetTappedCompleteEvent = new AutoResetEvent(false); manager.InvokeOnUIThread( async() => { tappedPositionResult = await GetTappedCoordinateAsync(); GetTappedCompleteEvent.Set(); }); GetTappedCompleteEvent.WaitOne(); return(tappedPositionResult); }
public void StartProgram() { while (true) { SnapsCoordinate drawPos = SnapsEngine.GetDraggedCoordinate(); if (drawPos.XValue < 10 && drawPos.YValue < 10) { SnapsEngine.ClearGraphics(); } else { SnapsEngine.DrawDot(pos: drawPos, width: 20); } } }
public void StartProgram() { SnapsCoordinate screenSize = SnapsEngine.GetScreenSize(); SnapsCoordinate center; center.XValue = screenSize.XValue / 2; center.YValue = screenSize.YValue / 2; SnapsEngine.SetDrawingColor(red: 255, green: 0, blue: 0); while (true) { SnapsCoordinate lineEnd = SnapsEngine.GetTappedCoordinate(); SnapsEngine.DrawLine(center, lineEnd); } }
public void StartProgram() { SnapsEngine.SetBackgroundColor(red: 100, green: 100, blue: 100); SnapsCoordinate pos = new SnapsCoordinate(100, 200); SnapsEngine.SetDrawingColor(red: 255, green: 255, blue: 255); SnapsEngine.DrawDot(pos: pos, width: 100); SnapsEngine.SetDrawingColor(red: 0, green: 0, blue: 0); SnapsEngine.DrawDot(pos: pos, width: 80); SnapsEngine.SetDrawingColor(red: 0, green: 0, blue: 255); SnapsEngine.DrawDot(pos: pos, width: 60); SnapsEngine.SetDrawingColor(red: 255, green: 0, blue: 0); SnapsEngine.DrawDot(pos: pos, width: 40); SnapsEngine.SetDrawingColor(red: 255, green: 255, blue: 0); SnapsEngine.DrawDot(pos: pos, width: 20); }
public SnapsCoordinate GetScreenSize() { AutoResetEvent getSizeCompletedEvent = new AutoResetEvent(false); SnapsCoordinate position = new SnapsCoordinate(); manager.InvokeOnUIThread( () => { position.XValue = (int)this.ActualWidth; position.YValue = (int)this.ActualHeight; getSizeCompletedEvent.Set(); } ); getSizeCompletedEvent.WaitOne(); return(position); }
public void StartProgram() { // Set the screen color to gray SnapsEngine.SetBackgroundColor(red: 100, green: 100, blue: 100); // Stop the control menu being displayed when the program finishes SnapsEngine.DisplayControMenuAtProgramEnd = false; SnapsCoordinate pos = new SnapsCoordinate(100, 200); SnapsEngine.SetDrawingColor(red: 255, green: 255, blue: 255); SnapsEngine.DrawDot(pos: pos, width: 100); SnapsEngine.SetDrawingColor(red: 0, green: 0, blue: 0); SnapsEngine.DrawDot(pos: pos, width: 80); SnapsEngine.SetDrawingColor(red: 0, green: 0, blue: 255); SnapsEngine.DrawDot(pos: pos, width: 60); SnapsEngine.SetDrawingColor(red: 255, green: 0, blue: 0); SnapsEngine.DrawDot(pos: pos, width: 40); SnapsEngine.SetDrawingColor(red: 255, green: 255, blue: 0); SnapsEngine.DrawDot(pos: pos, width: 20); }
public void StartProgram() { PenModes penType; penType = PenModes.SquarePen; // Draw a pallette block for selecting a square pen SnapsEngine.SetDrawingColor(SnapsColor.Red); // draw the block background SnapsEngine.DrawBlock(x: 0, y: 0, width: 50, height: 50); SnapsEngine.SetDrawingColor(SnapsColor.White); // draw a white block to indicate the square pen SnapsEngine.DrawBlock(x: 15, y: 15, width: 20, height: 20); // Draw a pallette block for selecting a round pen SnapsEngine.SetDrawingColor(SnapsColor.Red); // draw the block background SnapsEngine.DrawBlock(x: 52, y: 0, width: 50, height: 50); SnapsEngine.SetDrawingColor(SnapsColor.White); // draw a white dot to indicate the round pen SnapsEngine.DrawDot(x: 77, y: 25, width: 20); // Draw a pallette block for selecting the "erase" pen SnapsEngine.SetDrawingColor(SnapsColor.Red); // draw the block background SnapsEngine.DrawBlock(x: 104, y: 0, width: 50, height: 50); SnapsEngine.SetDrawingColor(SnapsColor.White); // draw an X that indicates "erase" SnapsEngine.DrawLine(x1: 104, y1: 0, x2: 154, y2: 50); SnapsEngine.DrawLine(x1: 104, y1: 50, x2: 154, y2: 0); SnapsColor backgroundColor = SnapsColor.White; SnapsColor drawColor = SnapsColor.Black; while (true) { SnapsCoordinate drawPos = SnapsEngine.GetDraggedCoordinate(); // See if the draw position is inside the square pen pallette item if (drawPos.XValue > 0 && drawPos.XValue < 50 && drawPos.YValue > 0 && drawPos.YValue < 50) { // in the square pen area penType = PenModes.SquarePen; continue; // go round the loop again } // See if the draw position is inside the round pen pallette item if (drawPos.XValue > 52 && drawPos.XValue < 102 && drawPos.YValue > 0 && drawPos.YValue < 50) { // in the round pen area penType = PenModes.RoundPen; continue; // go round the loop again } // See if the draw position is inside the erase pen pallette item if (drawPos.XValue > 104 && drawPos.XValue < 154 && drawPos.YValue > 0 && drawPos.YValue < 50) { // in the erase pen area penType = PenModes.ErasePen; continue; // go round the loop again } switch (penType) { case PenModes.RoundPen: SnapsEngine.SetDrawingColor(drawColor); SnapsEngine.DrawDot(drawPos, 20); break; case PenModes.SquarePen: SnapsEngine.SetDrawingColor(drawColor); SnapsEngine.DrawBlock(drawPos.XValue, drawPos.YValue, 20, 20); break; case PenModes.ErasePen: SnapsEngine.SetDrawingColor(backgroundColor); SnapsEngine.DrawBlock(drawPos.XValue, drawPos.YValue, 20, 20); break; } } }
public async Task <SnapsCoordinate> GetDraggedCoordinateAsync() { enableTouch(); SnapsCoordinate draggedPositionResult = new SnapsCoordinate(); AutoResetEvent GetDraggedPositionCompleteEvent = new AutoResetEvent(false); var tcs = new TaskCompletionSource <object>(); TappedEventHandler pointerTappedHandler = (s, e) => { // Get the position relative to the graphics canvas as this // is the one we will be drawing Point p = e.GetPosition(manager.DisplayGrid);// (Grid) s); draggedPositionResult.XValue = (int)Math.Round(p.X); draggedPositionResult.YValue = (int)Math.Round(p.Y); tcs.TrySetResult(null); }; PointerEventHandler pointerMovedHandler = (s, e) => { bool doDraw = false; // Get the position relative to the graphics canvas as this // is the one we will be drawing PointerPoint p = e.GetCurrentPoint(this);// (Grid) s); switch (p.PointerDevice.PointerDeviceType) { case Windows.Devices.Input.PointerDeviceType.Mouse: if (p.Properties.IsLeftButtonPressed) { doDraw = true; } break; case Windows.Devices.Input.PointerDeviceType.Pen: if (p.Properties.Pressure > 0) { doDraw = true; } break; case Windows.Devices.Input.PointerDeviceType.Touch: doDraw = true; break; } if (doDraw) { draggedPositionResult.XValue = (int)Math.Round(p.RawPosition.X); draggedPositionResult.YValue = (int)Math.Round(p.RawPosition.Y); tcs.TrySetResult(null); } }; try { this.Tapped += pointerTappedHandler; this.PointerMoved += pointerMovedHandler; await tcs.Task; } finally { this.Tapped -= pointerTappedHandler; this.PointerMoved -= pointerMovedHandler; disableTouch(); } return(draggedPositionResult); }
public void DrawLine(SnapsCoordinate p1, SnapsCoordinate p2) { graphicsCanvas.DrawLine(p1.XValue, p1.YValue, p2.XValue, p2.YValue); }
public void DrawDot(SnapsCoordinate pos, int width) { graphicsCanvas.DrawDot(pos.XValue, pos.YValue, width); }