public void fm_MouseDown(Object sender, MouseEventArgs e) { //図形オブジェクトを作成する Shape sh = null; if (currentShape == Shape.RECT) { sh = new Rect(); } else if (currentShape == Shape.OVAL) { sh = new Oval(); } else if (currentShape == Shape.LINE) { sh = new Line(); } //図形オブジェクトの色を設定する sh.SetColor(currentColor); //図形オブジェクトの座標を設定する sh.SetStartPoint(e.X, e.Y); sh.SetEndPoint(e.X, e.Y); //図形オブジェクトをリスト末尾に追加する shapeList.Add(sh); //フォームを再描画する this.Invalidate(); }
protected void HandleOval(Oval item, PdfPageWriter writer, Context context) { var physicalBox = ToPhysicalBox(item, context); var go = (PdfGraphicsOptions)GetReferenceObject(item.GraphicsOptionsRef ?? context.GraphicsOptionsRef) ?? new PdfGraphicsOptions(); writer.DrawOval2(physicalBox[0], physicalBox[1], physicalBox[2], physicalBox[3], go); }
public static Shape createShape(ScreenshotEditor editor, bool cropBoxActive, XPathNavigator element) { string type = element.GetAttribute("type", ""); Shape s = null; switch (type) { case "Arrow": s = new Arrow(editor, element); break; case "CropBox": s = new CropBox(editor, element, cropBoxActive); break; case "Censor": s = new Censor(editor, element); break; case "Line": s = new Line(editor, element); break; case "Oval": s = new Oval(editor, element); break; case "MagnifyingGlass": s = new MagnifyingGlass(editor, element); break; case "Pencil": s = new Pencil(editor, element); break; case "Picture": s = new Picture(editor, element); break; case "PonyVille": s = new PonyVille(editor, element); break; case "RectangleShape": s = new RectangleShape(editor, element); break; case "TextShape": s = new TextShape(editor, element); break; default: break; } return(s); }
public void ToolMouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { oval = new Oval(e.X, e.Y); oval.width = 0; oval.height = 0; canvas.AddPuzzleObject(oval); } }
public void ShouldParseSquareCommand() { // Arrange string inputStrig = "Draw an oval with an x-axis radius of 50 and a y-axis radius of 170"; // Act var parser = new OvalParser(); Oval res = parser.Parse(inputStrig); // Assert Assert.IsNotNull(res); Assert.AreEqual(50, res.XRadius); Assert.AreEqual(170, res.YRadius); }
private void CoinGenerator_Tick_1(object sender, EventArgs e) { Oval coin = new Oval(); coins.Add(coin); Random randomCoinLocation = new Random(); Random randomCoinInterval = new Random(); coins[indexCoin].BackColor = Color.FromArgb(128, 255, 255); coins[indexCoin].Image = Resources.CoinSM3DL; coins[indexCoin].Height = 30; coins[indexCoin].Width = 30; coins[indexCoin].Top = 0; coins[indexCoin].Left = randomCoinLocation.Next(0, 410); gamePanel.Controls.Add(coins[indexCoin]); coinGeneratorTimer.Interval = randomCoinInterval.Next(coinFrequencyMinimumNumber, coinFrequencyMaximumNumber); ; coinMovementTimer.Start(); indexCoin++; }
public override Point GetLineAnchorLocation(DiagramItemBase toItem, Point toPoint, int toItemDiagramLinesCount, int toItemDiagramLinesNumber, bool isSelfStart) { Point p = new Point(); Point p2 = new Point(); Point pTo = new Point(); Line2D firstLineSelf; if (toItem != null) { pTo.X = Canvas.GetLeft(toItem) + toItem.ActualWidth / 2; pTo.Y = Canvas.GetTop(toItem) + toItem.ActualHeight / 2; } else { pTo = toPoint; } double tX = Canvas.GetLeft(this) + this.ActualWidth / 2; double tY = Canvas.GetTop(this) + this.ActualHeight / 2; double testX = pTo.X - tX; double testY = pTo.Y - tY; if (testX == 0) { testX = 0.001; } if (testY == 0) { testY = 0.001; } double ovalX = Canvas.GetLeft(this) + this.Width / 2; double ovalY = Canvas.GetTop(this) + this.Height / 2; double ovalR2 = this.Width / 2; double ovalR1 = this.Height / 2; Oval o = new Oval(ovalX, ovalY, ovalR1, ovalR2); if (toItemDiagramLinesCount > 1) { if (toItem == this) { if (isSelfStart) { p.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY - this.ActualHeight / 2; p2.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p2.Y = tY - this.ActualHeight; firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); return(Geometry2D.GetOvalLineCross(firstLineSelf, o)[0]); } else { p.X = tX + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); p2.X = tX + this.ActualWidth; p2.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); return(Geometry2D.GetOvalLineCross(firstLineSelf, o)[1]); } } Point pFrom = new Point(); pFrom.X = tX; if (testY <= 0) { pFrom.Y = Canvas.GetTop(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } else { pFrom.Y = tY + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); // we have two: // - line from pTo to pFrom (firstLine) // - oval if (testY <= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } if (testY <= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } } else { if (toItem == this) { if (isSelfStart) { p.X = tX; p.Y = tY - this.ActualHeight / 2; return(p); } else { p.X = tX + this.ActualWidth / 2; p.Y = tY; return(p); } } Point pFrom = new Point(); pFrom.X = tX; pFrom.Y = tY; Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); if (testY <= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } if (testY <= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } } return(p); }
private void Oval_pressed(object sender, TappedRoutedEventArgs e) { Oval.Play(); }
public void copy(Shape s) { Shape temp; if (s!=null) { temp = new Rect(0,0,1,1,Color.Black); //is s a rectangle...? if (temp.GetType() == s.GetType()) temp = new Rect((Rect)s); else { //is it an oval...? temp = new Oval(0,0,1,1,Color.Black); if (temp.GetType() == s.GetType()) temp = new Oval((Oval)s); else { //is it a line...? temp = new Segment(0,0,1,1,Color.Black,1); if (temp.GetType() == s.GetType()) temp = new Segment((Segment)s); else { //is it a triangle...? Point p1 = new Point(); Point p2 = new Point(); Point p3 = new Point(); temp = new Triangle(p1,p2,p3,Color.Black); if (temp.GetType() == s.GetType()) temp = new Triangle((Triangle)s); } } } //put the brand new copy into myShapes right after(above in the picture) the original myShapes.Insert(myShapes.IndexOf(s)+1,temp); } //if s is null, do nothing return; }
public static void Menu() { int x = 0; do { /* * Interfaces Implement Polymorphism. Each class that Inherits an Interfaces will implement * the method defined in the interface in a different way, making it Polymorphic. * Interfaces make it easier to make code easier to maintain,extend, and test. * When a class implements an Interface, it fufills a contract set by the Interface. * * See Generic Examples also * * Interfaces should be programmed at the right level. Interfaces should be granular * IList<T> - ICollection -> IENumberable * * IEnumerable Implementations (IEnumerable<T> limited to collectsions that are strongly typed: * List<T> * Array * ArrayList * SortedList<TKey, TValue> * HashTable * Queue / Queue<T> * Stack / Stack<T> * Dictionary<TKey, TValue> * ObservableCollection<T> * * ICollection<T> Implementations * List<T> * SortedList<TKey, TValue> * Dictionary<TKey, TValue> * * IList<T> Implementations * List<T> * * Program at the Right Level * IEnumerable <T> - If we need to Iterate over a Collection / Sequence or Data Bind * to a List Control * ICollection<T> - If we need to Add/Remove Items in a Collection, * Count Items in a Collection, * Clear a Collection. * IList<T> - If we need to Control the Order Items in a Collection, * Get an Item by the Index. * * Differences between IEnumerable, ICollection, and IList Interfaces * https://www.c-sharpcorner.com/UploadFile/78607b/difference-between-ienumerable-icollection-and-ilist-interf/ * * Abstract Classes versus Interfaces * ------------------------- | --------------------- * May Contain implementation | May not contain implementation code - Biggest weakness * Code or may simulate an | By default all objects are public and absract. Since it is * interface and just have | abstract by default then all methods must be implemented. * abstract signature. | * A class may inherit from a | A class may implement any number of interfaces - Biggest * single base class | strength. * Members have access | Members are automatically public * modifiers * May contain fields, | May only contain properties, methods, events, and indexers . | No implementation usually just contain signatures. | properties, constructors, | | destructors, methods, | Interfaces may not contain fields | events, and indexers | | | Note: You can use interface when you know signature but you don't know the implmentation. | You can use abstract class when you know some implementation but not all. A class may only | inherit from one abstract class, but a class may inherit from multiple interfaces. See | info on Abstract Methods in BaseExamples.cs | | Note_2: Interfaces can't have static methods. A class that implements an interface needs | to implement them all as instance methods. | | As a guideline: | Use classes and subclasses for types that naturally share an implementation | Use interfaces for types that have independent implementations. | | Natural - Can Compare with other Instances of the same type | | EQUALITY COMPARISONS | Natural IEquatable<T> IComparable<T> | IComparable | Plugged_in IEqualityComparer IComparer | IEqualityComparer<T> IComparer<T> | Structural IStructuralEquatable IStructuralEquatable | | | | */ Console.Clear(); Console.WriteLine(" Types of Interfaces \n "); Console.WriteLine(" 0. IComparable \n "); Console.WriteLine(" 1. IDisposable \n "); Console.WriteLine(" 2. IEnumerable \n "); Console.WriteLine(" 3. IList \n"); Console.WriteLine(" 4. IDictionary \n"); Console.WriteLine(" 5. Self Created \n"); Console.WriteLine(" 6. IQueryable \n"); Console.WriteLine(" 8. Web Page \n"); Console.WriteLine(" 9. Quit \n\n "); Console.Write(" Enter Number to execute Routine "); int selection; selection = Common.readInt("Enter Number to Execute Routine : ", 0, 9); switch (selection) { case 0: /* * IComparable will allow you to compare one class( one instance) to another * class (or instance). You have to implement 'compare' in class that is * inheriting IComparable. * * IComparable will tell you if * x < y * x > y * x == y * returning an integer * - 1 means less than * 1 means greater * 0 means equal to * */ SortingExamples.Sort_A_Class(); Console.ReadKey(); SortingExamples.Sort_Numbers(); Console.ReadKey(); break; // ==, != operators - Work out of the box only for primitive types and reference types // Operators do not work in generic code // Object.Equals - ok in generic code // // >, <, >=, <= operators - Work out of the box only for primitive types // case 2: /* * When something is define as IEnumerable it lets you know that you can use * LINQ to Query. * * IEnumerable - A List, Array, Query, String implements IEnumerable. * An IEnumerable Interface specifies that the underlying type implements IEnumerable * * public Interface IEnumerator * { *** *** MoveNext will throw an exception if collection has changed. *** Cannot modify a collection while enumerating. *** *** *** bool MoveNext(); *** object Current {get;} *** void Reset(); ***} *** ***public interface IEnumerable ***{ ***IEnumerator GetEnumerator(); ***} *** ** ** You can implement a class that uses the IEnumerable<string> interface. If you do this ** you will have to use the 'yield return' ** 'yield return' statements are NOT Return statements. ** ** What happens when a yield return occurs inside a method that returns an IEnumerator interface ** The C# compiler determines this is a case where you want the compiler to write an enumerator for ** you. The yield return statements simply tell the compiler what the sequence of enumeration values ** to return is. * ** Use 'yield return' when you want to return elements from a collection one at a time. Once * execution goes back it will pick up execution at the statement immediately following * the 'yield' return. * * * See also IterationStatements.cs for examples of Yield Return. * See also LINQExamples.cs on how deferred execution works. * * * */ MenuCreateAndUseTypes.EnumerableMethods.Menu(); MenuCreateAndUseTypes.IEnumeratorInterface.Menu(); break; case 3: // See BaseExamples.cs on more info on Array versus Lists // // IList<T> // Arrays are a fixed size. System.Array does not contain a definition for 'Add' // new string[] is a fixed size. // This problem with arrays is what List<T> was designed to overcome. // new List<string> allows you to add to an array. // Arrays can be multi-dimensional. List are restricted to being one dimensional. // // List<T> acts as an array in every aspect and in addition you can add and // remove elements. // // List<T> uses a capacity and a count method // Capacity - Gets increased if you keep adding elements. Once you add elements // and go past the capacity it gets increased by 8. // // count - Total number of elements you have added // if the count is 4 and the capacity is 8 you cannot display elements that exceed the count. // GenericExamples.GA_Main(); break; //case 4: //Dictionary uses a hash table. It is a large collection //that will divide a collection into smaller collections. //Each smaller collection is defined as a bucket. //If you know what bucket the item your searching for is in, //you only need to search that bucket. // //The modulo % method along with the .gethashcode method is used to determine the bucket when //storing or retrieving a value. // //If two values x and y evaluate to equal then they must evaluate to the same hash code. // // StringComparer implements IEqualityComparer // If two objects are equal they must return the same hash code that is why the IEqualityComparer // defines its own get hash code method so you can make sure that rule is followed. // // public int GetHashCode (string obj) // { // return obj.ToUpper().GetHashCode(); // Best to reuse what Microsoft has already done // } // // SortedList<TKey, TValue> - Dictionary that keeps its values sorted. It's a Dictionary and NOT a List. // Sorted List does NOT contain a Hash Table. So when you implement an IComparer interface you won't have a // hash method. // // SortedDictionary<TKey, TValue> - Functionally is the same as SortedList<TKey, TValue> // Added and Removing Elments is a lot faster using a Sorted Dictionary verus a Sorted List. // So only use a SortedDictionary if you need to make frequent changes to the collection. // case 5: Shape shape = new Oval(); shape.WhatAmI(); var car = new Car(); car.Start(); car.Stop(); var mower = new LawnMower(); mower.Start(); mower.Stop(); Console.Write("\nPress Enter to Continue "); Console.ReadKey(); Collections. Using_Collections(); Console.ReadKey(); break; case 6: /* IQueryable is used in Entity Frameworks and serves as a replacement for IEnumerable. It is how * a database is accessed via SQL. Like IEnumerable it represents a datasource something you can query. * IQueryable does not execute code in memory. IQueryable translates code into SQL. IQueryable works * with the Expression clause. The Expression Clause will translate Lambda statements and passes them * so that they can be translated into SQL. The Entity Framework will inspect the Expression to tranlate * into SQL. * * Watch this video again at some point to write program that will use Entity Frameworks and display * SQL to Console. * https://app.pluralsight.com/course-player?clipId=64018007-2730-4598-9fca-6aee3d4e0fcd */ Console.WriteLine(" Not yet built"); Console.ReadKey(); break; case 8: Process.Start("http://msdn.microsoft.com/en-us/library/87d83y5b.aspx"); break; case 9: x = 9; break; default: Console.WriteLine(" Invalid Number"); break; } } while (x < 9); // end do } // end Menu()
/// <summary> /// Отпускание кнопки мышки /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ContainerMouseUp(object sender, MouseEventArgs e) { // если мышь была захвачена if (!_container.Capture) { return; } // освобождаем захват мышки _container.Capture = false; // если нажата левая кнопка if (e.Button == MouseButtons.Left) { var rect = _ribbonRect; Figure figure; switch (EditorMode) { case EditorMode.Selection: // нормализация параметров для прямоугольника выбора // добавляем все фигуры, которые оказались охваченными прямоугольником выбора // в список выбранных фигур foreach (var fig in _figures.Where(fig => rect.Contains(Rectangle.Ceiling(fig.Bounds)))) { _selected.Add(fig); } if (_selected.Count > 0) { Focus(_selected[0]); } break; // перетаскивание выбранных фигур "мышкой" case EditorMode.Dragging: if (CurrentMarker == null) { FileChanged = true; // перебираем все выделенные фигуры и смещаем foreach (var fig in _selected) { fig.UpdateLocation(_mouseOffset); } _container.Invalidate(); OnEditorFarConnerUpdated(); } else if (CurrentMarker is ISizeMarker) // тянут за размерный маркер { FileChanged = true; // перебираем все выделенные фигуры и меняем размер foreach (var fig in _selected) { fig.UpdateSize(_mouseOffset, CurrentMarker); } _container.Invalidate(); OnEditorFarConnerUpdated(); } else if ((CurrentMarker is VertexLocationMarker) && _selected.Count == 1) // тянут за маркер узла { FileChanged = true; var fig = _selected[0]; fig.UpdateSize(_mouseOffset, CurrentMarker); _container.Invalidate(); OnEditorFarConnerUpdated(); } break; //TODO Сделать что-то с этой "лестницей" case EditorMode.AddLine: figure = new Polyline(MouseDownLocation, _mouseOffset) { Stroke = (Stroke)DefaultStroke.Clone() }; AddFigure(figure); OnEditorFarConnerUpdated(); break; case EditorMode.AddPolygon: figure = new Polygon(rect.Location, new Point(rect.Width, rect.Height)) { Stroke = (Stroke)DefaultStroke.Clone(), Fill = (Fill)DefaultFill.Clone() }; AddFigure(figure); OnEditorFarConnerUpdated(); break; case EditorMode.AddRectangle: figure = new Rect(rect.Location, new Point(rect.Width, rect.Height)) { Stroke = (Stroke)DefaultStroke.Clone(), Fill = (Fill)DefaultFill.Clone() }; AddFigure(figure); OnEditorFarConnerUpdated(); break; case EditorMode.AddSquare: figure = new Square(rect.Location, new Point(Math.Min(rect.Width, rect.Height), Math.Min(rect.Width, rect.Height))) { Stroke = (Stroke)DefaultStroke.Clone(), Fill = (Fill)DefaultFill.Clone() }; AddFigure(figure); OnEditorFarConnerUpdated(); break; case EditorMode.AddEllipse: figure = new Oval(rect.Location, new Point(rect.Width, rect.Height)) { Stroke = (Stroke)DefaultStroke.Clone(), Fill = (Fill)DefaultFill.Clone() }; AddFigure(figure); OnEditorFarConnerUpdated(); break; case EditorMode.AddCircle: figure = new Circle(rect.Location, new Point(Math.Min(rect.Width, rect.Height), Math.Min(rect.Width, rect.Height))) { Stroke = (Stroke)DefaultStroke.Clone(), Fill = (Fill)DefaultFill.Clone() }; AddFigure(figure); OnEditorFarConnerUpdated(); break; } } // возвращаем режим EditorMode = EditorMode.Selection; // обнуление прямоугольника выбора _ribbonRect = Rectangle.Empty; _pt1 = _pt2 = Point.Empty; _container.Invalidate(); }
public void TouchEnd(Point p) { Geometry.End = p; Geometry = new Oval(Geometry); }