Example #1
0
        public override bool Equals(object obj)
        {
            if (obj is CellColor)
            {
                CellColor otherColor = (CellColor)obj;

                return(A == otherColor.A && R == otherColor.R && G == otherColor.G && B == otherColor.B);
            }
            return(false);
        }
Example #2
0
        public void DrawCellText(PathCell cell, Rectangle location, string text, CellColor color)
        {
            float rgb = color.B + color.R + color.G;

            Color textColor = Color.Black;
            Vector2 cellCenter = new Vector2(location.Center.X, location.Center.Y);

            if (rgb < 0.25f)
            {
                textColor = Color.White;
            }

            spriteBatch.DrawString(parent.Font, text, cellCenter - (parent.Font.MeasureString(text) / 2), textColor);
        }
Example #3
0
        /// <summary>
        /// Prepare the grid from image data
        /// </summary>
        public void SetupGrid(CellColor[][] pixels)
        {
            Logger.I("Setup the grid using image pixels data...");

            // Fill cells
            for (int x = 0; x < pixels.Length; x++)
            {
                for (int y = 0; y < pixels[x].Length; y++)
                {
                    // Get the pixel color
                    CellColor c = pixels [x] [y];

                    // Transparent becomes white
                    if (c.A < 0.2f)
                    {
                        c = new CellColor()
                        {
                            A = 1f,
                            R = 1f,
                            G = 1f,
                            B = 1f                             // White
                        };
                    }

                    Cells [x] [y].Color = c;
                }
            }

            // Look at each cell and create series
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    var cell = Cells [x] [y];

                    if (cell.IsMarked == false)
                    {
                        // The cell become the first of a serie
                        Cell firstCell = cell;

                        // Find its unmarked neighbors
                        InitializePath(firstCell);
                    }
                }
            }

            this.View.InitializeViewForDrawing();
        }
Example #4
0
 public static Color ToXnaColor(this CellColor color)
 {
     return(new Color(color.R, color.G, color.B, color.A));
 }
Example #5
0
        private void loadContent(string image)
        {
            // Create an empty texture
            BlankTexture = new Texture2D(SharedGraphicsDeviceManager.Current.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            Color[] color = new Color[1] { Color.White };
            BlankTexture.SetData(color);

            // Load font
            Font = contentManager.Load<SpriteFont>("font");

            // Read image
            Texture2D puzzleImage = contentManager.Load<Texture2D>(image);

            // Width and height
            int imageWidth = puzzleImage.Width;
            int imageHeight = puzzleImage.Height;

            // Colors pixel by pixel
            Color[] colors1D = new Color[puzzleImage.Width * puzzleImage.Height];
            puzzleImage.GetData(colors1D);
            Color[,] colors2D = new Color[puzzleImage.Width, puzzleImage.Height];
            for (int x = 0; x < puzzleImage.Width; x++)
            {
                for (int y = 0; y < puzzleImage.Height; y++)
                {
                    colors2D[x, y] = colors1D[x + y * puzzleImage.Width];
                }
            }

            grid = new PathGridXna(this, imageWidth, imageHeight);
            grid.GridCompleted += grid_GridCompleted;
            grid.CreateGrid(0, 0, grid);
            grid.LoadContent(contentManager);

            CellColor[][] colors = new CellColor[imageWidth][];

            for (int x = 0; x < imageWidth; x++)
            {
                colors[x] = new CellColor[imageHeight];

                for (int y = 0; y < imageHeight; y++)
                {
                    CellColor c;
                    c = new CellColor()
                    {
                        A = colors2D[x, y].A / 255f,
                        R = colors2D[x, y].R / 255f,
                        G = colors2D[x, y].G / 255f,
                        B = colors2D[x, y].B / 255f
                    };

                    colors[x][y] = c;
                }
            }

            grid.SetupGrid(colors);
        }
Example #6
0
        public void DrawPath(Cell cell, Rectangle pathRect, Point direction, CellColor color)
        {
            mContext.DrawImage (pathRect, UIImageEx.GetImageWithOverlayColor(mPathImage, color.UIColor).CGImage);

            // The old drawing code for perfect paths
            //			context.SetFillColor (color.UIColor.CGColor);

            // Draw in 2 parts:
            // First a rect
            //			context.FillRect (pathRect);
            //
            //			// Then an arc to the end
            //			if (direction.X < 0) {
            //				context.MoveTo (pathRect.Right, pathRect.Top);
            //				context.AddCurveToPoint (
            //					pathRect.Right + pathRect.Width / 3,
            //					pathRect.Top + pathRect.Height / 3,
            //					pathRect.Right + pathRect.Width / 3,
            //					pathRect.Top + 2 * pathRect.Height / 3,
            //					pathRect.Right,
            //					pathRect.Bottom
            //					);
            //			} else if (direction.X > 0) {
            //				context.MoveTo (pathRect.Left, pathRect.Top);
            //				context.AddCurveToPoint (
            //					pathRect.Left - pathRect.Width / 3,
            //					pathRect.Top + pathRect.Height / 3,
            //					pathRect.Left - pathRect.Width / 3,
            //					pathRect.Top + 2 * pathRect.Height / 3,
            //					pathRect.Left,
            //					pathRect.Bottom
            //					);
            //			}
            //			if (direction.Y < 0) {
            //				context.MoveTo (pathRect.Left, pathRect.Bottom);
            //				context.AddCurveToPoint (
            //					pathRect.Left + pathRect.Width / 3,
            //					pathRect.Bottom + pathRect.Height / 3,
            //					pathRect.Left + 2 * pathRect.Width / 3,
            //					pathRect.Bottom + pathRect.Height / 3,
            //					pathRect.Right,
            //					pathRect.Bottom
            //					);
            //			} else if (direction.Y > 0) {
            //				context.MoveTo (pathRect.Left, pathRect.Top);
            //				context.AddCurveToPoint (
            //					pathRect.Left + pathRect.Width / 3,
            //					pathRect.Top - pathRect.Height / 3,
            //					pathRect.Left + 2 * pathRect.Width / 3,
            //					pathRect.Top - pathRect.Height / 3,
            //					pathRect.Right,
            //					pathRect.Top
            //					);
            //			}
            //
            //			context.FillPath ();
        }
Example #7
0
        public void DrawLastCellIncompletePath(Cell cell, Rectangle rect, string pathValue, CellColor color)
        {
            UIColor colorUnderText = UIColor.LightGray;

            // Draw a gray circle!
            int circleReductionValue = mParent.CellSize / 8;
            mContext.SetFillColor (colorUnderText.CGColor);
            mContext.FillEllipseInRect (new RectangleF(rect.X + circleReductionValue, rect.Y + circleReductionValue, mParent.CellSize-2*circleReductionValue, mParent.CellSize-2*circleReductionValue));

            // Draw the text
            mContext.SetFillColor (UIColor.Black.CGColor);
            mContext.SelectFont ("Helvetica Neue", 12.0f, CGTextEncoding.MacRoman);
            mContext.ShowTextAtPoint (rect.X + mParent.CellSize/3, rect.Y + 2 * mParent.CellSize / 3, pathValue);
        }
Example #8
0
        public void DrawCellText(Cell cell, Rectangle location, string text, CellColor color)
        {
            mContext.SelectFont ("Helvetica Neue", 16.0f, CGTextEncoding.MacRoman);

            // Get the reverse color of the background
            float sumOfComponents = 0;
            float r, g, b, a;
            color.UIColor.GetRGBA (out r, out g, out b, out a);
            sumOfComponents = r + g + b;

            UIColor textColor = UIColor.Black;
            if (sumOfComponents < 0.25f)
            {
                textColor = UIColor.White;
            } else {
                textColor = UIColor.Black;
            }

            mContext.SetFillColor (textColor.CGColor);

            // Careful with the coordinates!!!
            // Remember it's a real mess because it's inverted
            mContext.ShowTextAtPoint (location.X + mParent.CellSize/3, location.Y + 2 * mParent.CellSize / 3, text);
        }
Example #9
0
 public void DrawPath(PathCell cell, Rectangle pathRect, Microsoft.Xna.Framework.Point direction, CellColor color)
 {
     spriteBatch.Draw(parent.BlankTexture, pathRect, color.ToXnaColor());
 }
Example #10
0
        public void DrawLastCellIncompletePath(PathCell cell, Rectangle rect, string pathValue, CellColor color)
        {
            Vector2 cellCenter = new Vector2(rect.Center.X, rect.Center.Y);

            int size = CellSize / 4;
            Rectangle smallRect = new Rectangle((int)cellCenter.X - size, (int)cellCenter.Y - size, 2 * size, 2 * size);
            spriteBatch.Draw(parent.BlankTexture, smallRect, Color.LightSalmon);

            spriteBatch.DrawString(parent.Font, pathValue, cellCenter - (parent.Font.MeasureString(pathValue) / 2), Color.Black);
        }
Example #11
0
        /// <summary>
        /// Create a UIView containing the game
        /// </summary>
        /// <returns>The grid.</returns>
        /// <param name="puzzle">Puzzle.</param>
        /// <param name="image">Image.</param>
        /// <param name="bitmap">Bitmap.</param>
        private UIView InitializeGrid(PuzzleData puzzle, UIImage image, Bitmap bitmap)
        {
            UIView view = null;

            // Here we create the real game view
            mPathGrid = new PathGridView (puzzle, (int)image.Size.Width, (int)image.Size.Height);
            mPathGrid.GridCompleted += GridCompleted;

            // Store it to prevent garbage collection
            view = mPathGrid.GridViewInternal;

            // Look at each pixel of the image
            CellColor[][] pixels = new CellColor[(int)image.Size.Width][];

            for (int x=0; x<image.Size.Width; x++) {

                pixels [x] = new CellColor[(int)image.Size.Height];

                for (int y=0; y<image.Size.Height; y++) {

                    // Get the pixel color
                    Color c = bitmap.GetPixel (x, y);

                    // Transform to generic color
                    pixels [x] [y] = new CellColor () {
                        A = c.A/255f,
                        R = c.R/255f,
                        G = c.G/255f,
                        B = c.B/255f
                    };

                }
            }

            // Transfer pixel data to the internal grid
            this.mPathGrid.SetupGrid (pixels);

            return view;
        }
Example #12
0
		/// <summary>
		/// Prepare the grid from image data
		/// </summary>
		public void SetupGrid (CellColor[][] pixels)
		{
			Logger.I ("Setup the grid using image pixels data...");

			// Fill cells
			for (int x=0; x<pixels.Length; x++) {
				for (int y=0; y<pixels[x].Length; y++) {

					// Get the pixel color
					CellColor c = pixels [x] [y];

					// Transparent becomes white
					if (c.A < 0.2f) {
						c = new CellColor () {
							A = 1f,
							R = 1f, 
							G = 1f, 
							B = 1f // White
						};
					}

					Cells [x] [y].Color = c;
				}	
			}

			// Look at each cell and create series
			for (int x=0; x<Width; x++) {
				for (int y=0; y<Height; y++) {

					var cell = Cells [x] [y];

					if (cell.IsMarked == false) {

						// The cell become the first of a serie
						Cell firstCell = cell;

						// Find its unmarked neighbors 
						InitializePath (firstCell);
					}
				}
			}

			this.View.InitializeViewForDrawing ();
		}