public string GetMyLastObjectID() { string objectID = null; if (drawingCommands.Count > 0) { lock (drawingCommandLock) { for (int i = drawingCommands.Count - 1; i >= 0; i--) { if (drawingCommands[i] is LineObject) { LineObject drawingObject = (LineObject)drawingCommands[i]; string user_id; if ((drawingObject.ObjectID != null) && (drawingObject.ObjectID.LastIndexOf('_') >= 0)) { user_id = drawingObject.ObjectID.Substring(0, drawingObject.ObjectID.LastIndexOf('_')); if (string.Compare(user_id, DDD_Global.Instance.PlayerID) == 0) { objectID = drawingObject.ObjectID; break; } } } } } } return(objectID); }
public void DeleteSelectionObjects() { lock (drawingCommandLock) { foreach (Object command in drawingCommands) { if (command is LineObject) { LineObject lineObject = (LineObject)command; if (lineObject.ObjectSelected) { lineObject.ObjectSelected = false; // Determine if the user owns this object if (!IsAllowedSelection(lineObject)) { continue; } _Controller.WhiteboardUndoRequest(((LineObject)command).ObjectID, DDD_Global.Instance.PlayerID, Name); } } } numObjectsSelected = 0; } }
public bool Clear(string user_id) { lock (drawingCommandLock) { // Only clear this users drawing objects for (int i = drawingCommands.Count - 1; i >= 0; i--) { if (drawingCommands[i] is LineObject) { LineObject drawingObject = (LineObject)drawingCommands[i]; string objectUserID; if ((drawingObject.ObjectID != null) && (drawingObject.ObjectID.LastIndexOf('_') >= 0)) { objectUserID = drawingObject.ObjectID.Substring(0, drawingObject.ObjectID.LastIndexOf('_')); if (string.Compare(objectUserID, user_id) == 0) { // Clear this drawing object drawingCommands.RemoveAt(i); } } } } } return(true); }
private bool IsAllowedSelection(LineObject lineObject) { string user_id; string objectID = lineObject.ObjectID; if (IsRoomOwner) { return(true); } if (objectID.LastIndexOf('_') >= 0) { user_id = objectID.Substring(0, objectID.LastIndexOf('_')); } else { return(false); } return(string.Compare(user_id, DDD_Global.Instance.PlayerID) == 0); }
public void AddSelection(RectangleF selectionRect, bool areaSelection) { Polygon selectionPolygon = null; LineObject lineObject; PolygonCollisionResult result; LineObject prevSelectedObject = null; // Create Selection Polygon selectionPolygon = new Polygon(); selectionPolygon.Points.Add(new Vector(selectionRect.Left, selectionRect.Top)); selectionPolygon.Points.Add(new Vector(selectionRect.Right, selectionRect.Top)); selectionPolygon.Points.Add(new Vector(selectionRect.Right, selectionRect.Bottom)); selectionPolygon.Points.Add(new Vector(selectionRect.Left, selectionRect.Bottom)); selectionPolygon.Offset(0, 0); selectionPolygon.BuildEdges(); if (areaSelection) { // Select an area of objects lock (drawingCommandLock) { foreach (Object command in drawingCommands) { if (command is LineObject) { lineObject = command as LineObject; if ((lineObject.BoundingPolygon != null) && (lineObject.Mode != DrawModes.Circle)) { result = PolygonCollision(lineObject.BoundingPolygon, selectionPolygon, new Vector(0, 0)); if ((result.Intersect) && (IsAllowedSelection(lineObject))) { lineObject.ObjectSelected = true; numObjectsSelected++; } } else if (lineObject.Mode == DrawModes.Circle) { if ((CircleSelectedByRect(lineObject, selectionRect)) && (IsAllowedSelection(lineObject))) { lineObject.ObjectSelected = true; numObjectsSelected++; } } } } } } else { // Select a single object if (numObjectsSelected > 1) { ClearSelectionList(); } else if (numObjectsSelected == 1) { // Locate the previously selected object lock (drawingCommandLock) { foreach (Object command in drawingCommands) { if ((command is LineObject) && ((LineObject)command).ObjectSelected) { prevSelectedObject = command as LineObject; break; } } } } LineObject selectedObject = null; LineObject firstSelectedObject = null; bool prevSelectionFound = false; lock (drawingCommandLock) { foreach (Object command in drawingCommands) { if (command is LineObject) { bool objectSelected = false; lineObject = command as LineObject; if ((lineObject.BoundingPolygon != null) && (lineObject.Mode != DrawModes.Circle)) { result = PolygonCollision(lineObject.BoundingPolygon, selectionPolygon, new Vector(0, 0)); if ((result.Intersect) && (IsAllowedSelection(lineObject))) { objectSelected = true; } } else if (lineObject.Mode == DrawModes.Circle) { if ((CircleSelectedByRect(lineObject, selectionRect)) && (IsAllowedSelection(lineObject))) { objectSelected = true; } } if (objectSelected) { if (firstSelectedObject == null) { firstSelectedObject = lineObject; } if ((prevSelectionFound) && (lineObject != prevSelectedObject)) { selectedObject = lineObject; break; } if (lineObject == prevSelectedObject) { selectedObject = lineObject; prevSelectionFound = true; } } } } } if ((selectedObject == prevSelectedObject) || (selectedObject == null)) { selectedObject = firstSelectedObject; } ClearSelectionList(); if ((selectedObject != null) && (IsAllowedSelection(selectedObject))) { selectedObject.ObjectSelected = true; numObjectsSelected++; } } }
public bool AddLine(string objectID, DrawModes mode, LocationValue start, LocationValue end, double width, double oringinalScale, int color, string text) { LineObject line = new LineObject(); line.Mode = mode; line.Start = start; line.End = end; line.Width = width; line.OriginalScale = oringinalScale; line.Color = color; line.Text = text; line.ObjectID = objectID; line.BoundingPolygon = null; line.ObjectSelected = false; line.InnerRadius = 0.0f; line.OutterRadius = 0.0f; string user_id; if (objectID.LastIndexOf('_') >= 0) { user_id = objectID.Substring(0, objectID.LastIndexOf('_')); } else { return(false); } // If this is not a circle, create a bounding polygon for this object Polygon newBoundingPoly = null; if ((line.Mode == DrawModes.Line) || (line.Mode == DrawModes.Arrow)) { GetLineBoundingPoly((float)line.Start.X, (float)line.Start.Y, (float)line.End.X, (float)line.End.Y, (float)line.Width, (float)line.OriginalScale, out newBoundingPoly); line.BoundingPolygon = newBoundingPoly; } else if (line.Mode == DrawModes.Circle) { float innerRadius; float outterRadius; GetCircleBoundingPoly((float)line.Start.X, (float)line.Start.Y, (float)line.End.X, (float)line.End.Y, (float)line.Width, (float)line.OriginalScale, out newBoundingPoly, out outterRadius, out innerRadius); line.BoundingPolygon = newBoundingPoly; line.InnerRadius = innerRadius; line.OutterRadius = outterRadius; } if (string.Compare(user_id, DDD_Global.Instance.PlayerID) == 0) { lock (drawingCommandLock) { drawingCommands.Add(line); } } else { drawingCommands.Add(line); } return(true); }
public bool CircleSelectedByRect(LineObject lineObject, RectangleF selectionRect) { PointF circleDistance = new PointF(); float cornerDistance; float testRadius; bool intersectsOutterCir = false; bool testResult; if ((lineObject == null) || (lineObject.Mode != DrawModes.Circle)) { return(false); } if ((lineObject.InnerRadius < 0) || (lineObject.OutterRadius <= 0) || (lineObject.InnerRadius > lineObject.OutterRadius)) { return(false); } // Test for outter circle intersection (needs to be true to return true) testRadius = lineObject.OutterRadius; testResult = false; circleDistance.X = Math.Abs((float)lineObject.Start.X - selectionRect.X - selectionRect.Width / 2); circleDistance.Y = Math.Abs((float)lineObject.Start.Y - selectionRect.Y - selectionRect.Height / 2); if (circleDistance.X > (selectionRect.Width / 2 + testRadius)) { testResult = false; } else if (circleDistance.Y > (selectionRect.Height / 2 + testRadius)) { testResult = false; } else if (circleDistance.X <= (selectionRect.Width / 2)) { testResult = true; } else if (circleDistance.Y <= (selectionRect.Height / 2)) { testResult = true; } else { cornerDistance = (float)Math.Sqrt(Math.Pow((circleDistance.X - selectionRect.Width / 2), 2) + Math.Pow((circleDistance.Y - selectionRect.Height / 2), 2)); testResult = (cornerDistance <= testRadius); } if (testResult) { // Test for inner circle intersection (needs to be false or part of the rect // must be outside the inner circle to return true) testRadius = lineObject.InnerRadius; testResult = false; circleDistance.X = Math.Abs((float)lineObject.Start.X - selectionRect.X - selectionRect.Width / 2); circleDistance.Y = Math.Abs((float)lineObject.Start.Y - selectionRect.Y - selectionRect.Height / 2); if (circleDistance.X > (selectionRect.Width / 2 + testRadius)) { testResult = true; } else if (circleDistance.Y > (selectionRect.Height / 2 + testRadius)) { testResult = true; } else if (circleDistance.X <= (selectionRect.Width / 2)) { testResult = true; } else if (circleDistance.Y <= (selectionRect.Height / 2)) { testResult = true; } else { cornerDistance = (float)Math.Sqrt(Math.Pow((circleDistance.X - selectionRect.Width / 2), 2) + Math.Pow((circleDistance.Y - selectionRect.Height / 2), 2)); testResult = (cornerDistance > testRadius); } } return(testResult); }
private bool IsAllowedSelection(LineObject lineObject) { string user_id; string objectID = lineObject.ObjectID; if (IsRoomOwner) { return true; } if (objectID.LastIndexOf('_') >= 0) { user_id = objectID.Substring(0, objectID.LastIndexOf('_')); } else { return false; } return (string.Compare(user_id, DDD_Global.Instance.PlayerID) == 0); }
public bool AddLine(string objectID, DrawModes mode, LocationValue start, LocationValue end, double width, double oringinalScale, int color, string text) { LineObject line = new LineObject(); line.Mode = mode; line.Start = start; line.End = end; line.Width = width; line.OriginalScale = oringinalScale; line.Color = color; line.Text = text; line.ObjectID = objectID; line.BoundingPolygon = null; line.ObjectSelected = false; line.InnerRadius = 0.0f; line.OutterRadius = 0.0f; string user_id; if (objectID.LastIndexOf('_') >= 0) { user_id = objectID.Substring(0, objectID.LastIndexOf('_')); } else { return false; } // If this is not a circle, create a bounding polygon for this object Polygon newBoundingPoly = null; if ((line.Mode == DrawModes.Line) || (line.Mode == DrawModes.Arrow)) { GetLineBoundingPoly((float) line.Start.X, (float) line.Start.Y, (float) line.End.X, (float) line.End.Y, (float) line.Width, (float) line.OriginalScale, out newBoundingPoly); line.BoundingPolygon = newBoundingPoly; } else if (line.Mode == DrawModes.Circle) { float innerRadius; float outterRadius; GetCircleBoundingPoly((float)line.Start.X, (float)line.Start.Y, (float)line.End.X, (float)line.End.Y, (float)line.Width, (float)line.OriginalScale, out newBoundingPoly, out outterRadius, out innerRadius); line.BoundingPolygon = newBoundingPoly; line.InnerRadius = innerRadius; line.OutterRadius = outterRadius; } if (string.Compare(user_id, DDD_Global.Instance.PlayerID) == 0) { lock (drawingCommandLock) { drawingCommands.Add(line); } } else { drawingCommands.Add(line); } return true; }
public bool CircleSelectedByRect(LineObject lineObject, RectangleF selectionRect) { PointF circleDistance = new PointF(); float cornerDistance; float testRadius; bool intersectsOutterCir = false; bool testResult; if ((lineObject == null) || (lineObject.Mode != DrawModes.Circle)) { return false; } if ((lineObject.InnerRadius < 0) || (lineObject.OutterRadius <= 0) || (lineObject.InnerRadius > lineObject.OutterRadius)) { return false; } // Test for outter circle intersection (needs to be true to return true) testRadius = lineObject.OutterRadius; testResult = false; circleDistance.X = Math.Abs((float) lineObject.Start.X - selectionRect.X - selectionRect.Width / 2); circleDistance.Y = Math.Abs((float) lineObject.Start.Y - selectionRect.Y - selectionRect.Height / 2); if (circleDistance.X > (selectionRect.Width / 2 + testRadius)) { testResult = false; } else if (circleDistance.Y > (selectionRect.Height / 2 + testRadius)) { testResult = false; } else if (circleDistance.X <= (selectionRect.Width / 2)) { testResult = true; } else if (circleDistance.Y <= (selectionRect.Height / 2)) { testResult = true; } else { cornerDistance = (float)Math.Sqrt(Math.Pow((circleDistance.X - selectionRect.Width / 2), 2) + Math.Pow((circleDistance.Y - selectionRect.Height / 2), 2)); testResult = (cornerDistance <= testRadius); } if (testResult) { // Test for inner circle intersection (needs to be false or part of the rect // must be outside the inner circle to return true) testRadius = lineObject.InnerRadius; testResult = false; circleDistance.X = Math.Abs((float)lineObject.Start.X - selectionRect.X - selectionRect.Width / 2); circleDistance.Y = Math.Abs((float)lineObject.Start.Y - selectionRect.Y - selectionRect.Height / 2); if (circleDistance.X > (selectionRect.Width / 2 + testRadius)) { testResult = true; } else if (circleDistance.Y > (selectionRect.Height / 2 + testRadius)) { testResult = true; } else if (circleDistance.X <= (selectionRect.Width / 2)) { testResult = true; } else if (circleDistance.Y <= (selectionRect.Height / 2)) { testResult = true; } else { cornerDistance = (float)Math.Sqrt(Math.Pow((circleDistance.X - selectionRect.Width / 2), 2) + Math.Pow((circleDistance.Y - selectionRect.Height / 2), 2)); testResult = (cornerDistance > testRadius); } } return testResult; }