示例#1
0
文件: paint.cs 项目: redhead/CGenPlus
        private void paint_MouseMove(object sender, MouseEventArgs e)
        {
            if (!clicked) return;
            if (insertion != null)
            {
                images.Add(new cImage(insertion, e.X - (int)(insertion.Width/2), e.Y - (int)(insertion.Height/2)));
                insertion = null;
                selectedImg = null;
                Refresh();
                return;
            }
            int x = (int)(e.X / w) * w;
            int y = (int)(e.Y / w) * w;

            int i = (int)(e.X / w);
            int j = (int)(e.Y / w);

            if(i < cells.Length && i >= 0 && j < cells[0].Length && j >= 0)
            {
                Image img;
                if (selectedImg == null)
                {
                    img = null;
                }
                else
                {
                    if (e.Button == MouseButtons.Right)
                    {
                        Bitmap btm = ((Bitmap)selectedImg);
                        if (cells[i][j].image != null)
                        {
                            btm = Bitmap.FromHbitmap(((Bitmap)cells[i][j].image).GetHbitmap());
                            for (int xx = 0; xx < w; xx++)
                            {
                                for (int yy = 0; yy < w; yy++)
                                {
                                    Color px = ((Bitmap)selectedImg).GetPixel(xx, yy);
                                    if (px != keyColor)
                                    {
                                        btm.SetPixel(xx, yy, px);
                                    }
                                }
                            }
                        }
                        else
                        {
                            btm = new Bitmap(w, w);
                            AlphaToWhite(btm);
                        }
                        img = Image.FromHbitmap(btm.GetHbitmap());
                    }
                    else
                    {
                        Bitmap btm = new Bitmap(w, w);
                        AlphaToWhite(btm);
                        img = Image.FromHbitmap(btm.GetHbitmap());
                    }
                }
                cells[i][j] = new Cell(img, cType.FILL);
            }
            Refresh();
        }
示例#2
0
文件: paint.cs 项目: redhead/CGenPlus
        public paint()
        {
            InitializeComponent();

            //BackColor = Color.FromArgb(65, 65, 65);

            cells = new Cell[20][];
            for (int i = 0; i < cells.Length; i++)
            {
                cells[i] = new Cell[w];
            }
            for (int i = 0; i < cells.Length; i++)
            {
                for (int j = 0; j < cells.Length; j++)
                {
                    cells[i][j] = new Cell();
                }
            }

            this.MouseWheel += new MouseEventHandler(paint_MouseWheel);

            tools.ShowItemToolTips = true;
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\fill.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\side.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\way.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\corner2.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\corner.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\paralel.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\corner_paralel.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\door.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\stairs.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\chest.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\enemy.gif"));
            tools.Items.Add(Image.FromFile(@"C:\Users\Radek\Documents\Visual Studio 2008\Projects\DrD+ Manager\DrD Správce\MapElements\column.gif"));

            for (int i = toolStart; i < tools.Items.Count; i++)
            {
                //tools.Items[i].BackColor = Color.White;
                //tools.Items[i].ImageTransparentColor = keyColor;
            }
        }
示例#3
0
        private void Form1_MouseDown(object snder, MouseEventArgs e)
        {
            float r = ((e.Y - menuStrip1.Height) / ((ClientSize.Height - menuStrip1.Height) / (float)row)); // Finds index of row
            float c = (e.X) / (ClientSize.Width / (float)col); // Finds index of col

            // Cells properties for drawing
            float cellWidth = ClientSize.Width / (float)col;
            float cellHeight = (ClientSize.Height - menuStrip1.Height) / (float)row;
            float cellX = (int)c * cellWidth;
            float cellY = (int)r * cellHeight + menuStrip1.Height;

            // Saves value of current row and col so when cell is created through
            // normal click from mouse, the cell is not set to unintended state if mouse
            // is moved on same cell
            tempR = (int)r;
            tempC = (int)c;

            // Verifies if valid row and col before creating cell
            if ((int)r < row && (int)r >= 0 && (int)c < col && (int)c >= 0)
            {
                // Change state of cell depending if cell was already created
                if (cellArray[(int)r, (int)c] != null && cellArray[(int)r, (int)c].IsAlive)
                {
                    // If the cell is already alive, change it to dead
                    cellArray[(int)r, (int)c].IsAlive = false;
                }
                else
                {
                    // If cell is empty or is dead, change state to alive
                    cellArray[(int)r, (int)c] = new Cell(true, cellWidth, cellHeight, cellX, cellY);
                }
            }
            Invalidate(); // Force repaint
        }