Example #1
0
 /// <summary>
 /// Find the objects in the image.
 /// </summary>
 /// <param name="image">The image to search for objects</param>
 /// <param name="filter">The filter with color</param>
 /// <param name="g">The Graphics to draw the rectangles</param>
 /// <param name="analyser">The ImageAnalyser to analysis the image</param>
 private void FindObjectsOfImage(Image image, ColorFilter filter, List<Rectangle> blocksFace, Graphics g, ImageAnalyser analyser)
 {
     Pen p = new Pen(filter.BorderColor, 3.0F);
     foreach (Rectangle item in analyser.GetObjectsCoordinates(image, filter))
     {
         VisualCubeBlock newFacelet = new VisualCubeBlock();
         newFacelet.Color = ColorTranslate.getFaceColorByColor(p.Color);
         Rectangle coord = new Rectangle();
         if (HasParentBlock(blocksFace, item, out coord))
         {
             newFacelet.Rectangle = coord;
             this.CurrentFace.AddBlock(newFacelet.Clone(), true);
             g.DrawRectangle(p, coord);
         }
         newFacelet.Dispose();
     }
 }
 /// <summary>
 /// Adds or edit the block in the list.
 /// </summary>
 /// <param name="newBlock">The block to add/edit</param>
 /// <param name="beforeBlockSort">If true, compares the position in the image to know if the blocks already exists. Otherwise, compare the Square property</param>
 public void AddBlock(VisualCubeBlock newBlock, bool beforeBlockSort)
 {
     int foundIndex = -1;
     for (int i = 0; i < _blocks.Count; i++)
     {
         if (beforeBlockSort)
         {
             if (newBlock.Rectangle.Equals(_blocks[i].Rectangle))
             {
                 foundIndex = i;
                 break;
             }
         }
         else
         {
             if (newBlock.Square == _blocks[i].Square)
             {
                 foundIndex = i;
                 break;
             }
         }
     }
     if (foundIndex == -1)
         _blocks.Add(newBlock);
     else
     {
         _blocks[foundIndex].Color = newBlock.Color;
     }
     if (newBlock.IsCenter())
         this.FaceColor = newBlock.Color;
 }
Example #3
0
 private void btnBuildDefaultCube_Click(object sender, EventArgs e)
 {
     Array facesArray = Enum.GetValues(typeof(CubeFaceType));
     Array squaresArray = Enum.GetValues(typeof(CubeFaceletType));
     CubeFaceColor[] colors = new CubeFaceColor[] { CubeFaceColor.R, CubeFaceColor.O, CubeFaceColor.B, CubeFaceColor.G, CubeFaceColor.W, CubeFaceColor.Y };
     for (int i = 0; i < facesArray.Length; i++)
     {
         VisualCubeFace face = new VisualCubeFace();
         face.FaceType = (CubeFaceType)facesArray.GetValue(i);
         foreach (CubeFaceletType item in squaresArray)
         {
             VisualCubeBlock block = new VisualCubeBlock();
             block.Square = item;
             block.Color = colors[i];
             face.AddBlock(block.Clone(), false);
             block.Dispose();
         }
         this.CurrentCube.AddFace(face.Clone());
         face.Dispose();
     }
     picbCubeDiagram.Invalidate();
 }
 /// <summary>
 /// Sort method delegate to compare the Y coordinates of blocks
 /// </summary>
 /// <param name="b1">The first block to compare.</param>
 /// <param name="b2">The second block to compare.</param>
 /// <returns>Returns -1 if the first Y is lower thant the second. 1 if the second Y is lower than the first. 0 if they are equal</returns>
 private int SortBlockListByY(VisualCubeBlock b1, VisualCubeBlock b2)
 {
     int retorno = 0;
     if (b1.Rectangle.Y < b2.Rectangle.Y)
         retorno = -1;
     else if (b1.Rectangle.Y > b2.Rectangle.Y)
         retorno = 1;
     return retorno;
 }