Пример #1
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Rectangle r      = new Rectangle(0, 0, this.ClientRectangle.Width - ((groupBox1.Visible) ? groupBox1.Width : 0), this.ClientRectangle.Height - ((statusStrip1.Visible) ? statusStrip1.Height : 0) - ((statusStrip1.Visible) ? statusStrip2.Height : 0) + menuStrip1.Height);
            int       min    = Math.Min(r.Height, r.Width);
            double    factor = 3 * ((double)min / (double)400);

            if (r.Width > r.Height)
            {
                r.X = (r.Width - r.Height) / 2;
            }
            else if (r.Height > r.Width)
            {
                r.Y = (r.Height - r.Width) / 2;
            }

            rubikRenderer.SetDrawingArea(r, factor);

            RenderInfo currentCommand = command;

            if (currentCommand.FacesProjected != null)
            {
                PositionSpec selectedPos = (contextMenuStrip1.Visible) ? currentSelection : rubikRenderer.RubikManager.RubikCube.Render(e.Graphics, currentCommand, PointToClient(Cursor.Position));
                if (selectedPos.Equals(currentSelection))
                {
                    rubikRenderer.RubikManager.RubikCube.Render(e.Graphics, currentCommand, PointToClient(Cursor.Position));
                }
                rubikRenderer.RubikManager.setFaceSelection(Face3D.SelectionMode.None);
                rubikRenderer.RubikManager.setFaceSelection(oldSelection.CubePosition, oldSelection.FacePosition, Face3D.SelectionMode.Second);
                rubikRenderer.RubikManager.setFaceSelection(selectedPos.CubePosition, selectedPos.FacePosition, Face3D.SelectionMode.First);
                currentSelection           = selectedPos;
                toolStripStatusLabel2.Text = "[" + selectedPos.CubePosition.ToString() + "] | " + selectedPos.FacePosition.ToString();
            }
        }
Пример #2
0
        public PositionSpec Render(Graphics g, Rectangle screen, double scale, Point mousePos)
        {
            PositionSpec result = RubikCube.Render(g, screen, scale, mousePos);

            if (Rotating)
            {
                RubikCube.LayerRotation[rotationLayer] += rotationStep;
                if ((rotationTarget > 0 && RubikCube.LayerRotation[rotationLayer] >= rotationTarget) || (rotationTarget < 0 && RubikCube.LayerRotation[rotationLayer] <= rotationTarget))
                {
                    resetFlags(true);
                }
            }
            return(result);
        }
Пример #3
0
 private void groupBox1_EnabledChanged(object sender, EventArgs e)
 {
     if (!groupBox1.Enabled)
     {
         rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
         oldSelection = new PositionSpec()
         {
             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
         };
         currentSelection = new PositionSpec()
         {
             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
         };
     }
 }
Пример #4
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Delete)
     {
         rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
         oldSelection = new PositionSpec()
         {
             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
         };
         currentSelection = new PositionSpec()
         {
             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
         };
     }
 }
Пример #5
0
        public PositionSpec Render(Graphics g, RenderInfo info, Point mousePos)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            PositionSpec mousePositionSpec = new PositionSpec()
            {
                CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
            };

            foreach (Face3D face in info.FacesProjected)
            {
                PointF[]     parr = face.Edges.Select(p => new PointF((float)p.X, (float)p.Y)).ToArray();
                GraphicsPath gp   = new GraphicsPath();
                gp.AddPolygon(parr);
                double fak = ((Math.Sin((double)Environment.TickCount / (double)200) + 1) / 4) + 0.75;
                if (gp.IsVisible(mousePos))
                {
                    mousePositionSpec = new PositionSpec()
                    {
                        CubePosition = face.MasterPosition, FacePosition = face.Position
                    }
                }
                ;
                if (face.Selection.HasFlag(Face3D.SelectionMode.Second))
                {
                    g.FillPolygon(new HatchBrush(HatchStyle.Percent75, Color.Black, face.Color), parr);
                }
                else if (face.Selection.HasFlag(Face3D.SelectionMode.NotPossible))
                {
                    g.FillPolygon(new SolidBrush(Color.FromArgb(face.Color.A, (int)(face.Color.R * 0.15), (int)(face.Color.G * 0.15), (int)(face.Color.B * 0.15))), parr);
                }
                else if (face.Selection.HasFlag(Face3D.SelectionMode.First))
                {
                    g.FillPolygon(new HatchBrush(HatchStyle.Percent30, Color.Black, face.Color), parr);
                }
                else if (face.Selection.HasFlag(Face3D.SelectionMode.Possible))
                {
                    g.FillPolygon(new SolidBrush(Color.FromArgb(face.Color.A, (int)(Math.Min(face.Color.R * fak, 255)), (int)(Math.Min(face.Color.G * fak, 255)), (int)(Math.Min(face.Color.B * fak, 255)))), parr);
                }
                else
                {
                    g.FillPolygon(new SolidBrush(face.Color), parr);
                }
                g.DrawPolygon(Pens.Black, parr);
            }
            return(mousePositionSpec);
        }
    }
Пример #6
0
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         if ((Control.ModifierKeys & Keys.Shift) != 0)
         {
             if (currentSelection.CubePosition != Cube3D.RubikPosition.None && currentSelection.FacePosition != Face3D.FacePosition.None)
             {
                 Color clr = rubikRenderer.RubikManager.getFaceColor(currentSelection.CubePosition, currentSelection.FacePosition);
                 int   ind = 0;
                 for (int i = 0; i < contextMenuStrip1.Items.Count; i++)
                 {
                     if (contextMenuStrip1.Items[i].Text == clr.Name)
                     {
                         ind = i;
                     }
                 }
                 ind++;
                 if (ind >= colors.Length)
                 {
                     ind = 0;
                 }
                 rubikRenderer.RubikManager.setFaceColor(currentSelection.CubePosition, currentSelection.FacePosition, colors[ind]);
             }
         }
         else
         {
             if (!contextMenuStrip1.Visible)
             {
                 if (oldSelection.CubePosition == Cube3D.RubikPosition.None || oldSelection.FacePosition == Face3D.FacePosition.None)
                 {
                     if (currentSelection.CubePosition == Cube3D.RubikPosition.None || currentSelection.FacePosition == Face3D.FacePosition.None)
                     {
                         rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                         oldSelection = new PositionSpec()
                         {
                             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                         };
                         currentSelection = new PositionSpec()
                         {
                             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                         };
                     }
                     else
                     {
                         if (!Cube3D.isCorner(currentSelection.CubePosition))
                         {
                             oldSelection = currentSelection;
                             rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f =>
                             {
                                 if (currentSelection.CubePosition != c.Position && !Cube3D.isCenter(c.Position) && currentSelection.FacePosition == f.Position)
                                 {
                                     Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(currentSelection.FacePosition);
                                     Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(currentSelection.CubePosition, c.Position, assocLayer);
                                     if (commonLayer != Cube3D.RubikPosition.None && c.Position.HasFlag(commonLayer))
                                     {
                                         f.Selection |= Face3D.SelectionMode.Possible;
                                     }
                                     else
                                     {
                                         f.Selection |= Face3D.SelectionMode.NotPossible;
                                     }
                                 }
                                 else
                                 {
                                     f.Selection |= Face3D.SelectionMode.NotPossible;
                                 }
                             }));
                             toolStripStatusLabel1.Text = "First selection: [" + currentSelection.CubePosition.ToString() + "] | " + currentSelection.FacePosition.ToString();;
                         }
                         else
                         {
                             rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                             toolStripStatusLabel1.Text = "Error: Invalid first selection, must not be a corner";
                         }
                     }
                 }
                 else
                 {
                     if (currentSelection.CubePosition == Cube3D.RubikPosition.None || currentSelection.FacePosition == Face3D.FacePosition.None)
                     {
                         toolStripStatusLabel1.Text = "Ready";
                     }
                     else
                     {
                         if (currentSelection.CubePosition != oldSelection.CubePosition)
                         {
                             if (!Cube3D.isCenter(currentSelection.CubePosition))
                             {
                                 if (oldSelection.FacePosition == currentSelection.FacePosition)
                                 {
                                     Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(oldSelection.FacePosition);
                                     Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(oldSelection.CubePosition, currentSelection.CubePosition, assocLayer);
                                     Boolean direction = true;
                                     if (commonLayer == Cube3D.RubikPosition.TopLayer || commonLayer == Cube3D.RubikPosition.MiddleLayer || commonLayer == Cube3D.RubikPosition.BottomLayer)
                                     {
                                         if (((oldSelection.FacePosition == Face3D.FacePosition.Back) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Left) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BackSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Front) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Right) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.FrontSlice)))
                                         {
                                             direction = false;
                                         }
                                     }
                                     if (commonLayer == Cube3D.RubikPosition.LeftSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice_Sides || commonLayer == Cube3D.RubikPosition.RightSlice)
                                     {
                                         if (((oldSelection.FacePosition == Face3D.FacePosition.Bottom) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BackSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Back) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.TopLayer)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Top) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.FrontSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Front) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BottomLayer)))
                                         {
                                             direction = false;
                                         }
                                     }
                                     if (commonLayer == Cube3D.RubikPosition.BackSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice || commonLayer == Cube3D.RubikPosition.FrontSlice)
                                     {
                                         if (((oldSelection.FacePosition == Face3D.FacePosition.Top) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Right) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BottomLayer)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Bottom) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Left) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.TopLayer)))
                                         {
                                             direction = false;
                                         }
                                     }
                                     if (commonLayer != Cube3D.RubikPosition.None)
                                     {
                                         if (groupBox1.Enabled)
                                         {
                                             groupBox1.Enabled = false;
                                             //rotationTicks = 25;
                                             if (commonLayer == Cube3D.RubikPosition.TopLayer || commonLayer == Cube3D.RubikPosition.LeftSlice || commonLayer == Cube3D.RubikPosition.FrontSlice)
                                             {
                                                 direction = !direction;
                                             }
                                             rubikRenderer.RubikManager.Rotate90(commonLayer, direction, rotationTime);
                                             comboBox1.Text             = commonLayer.ToString();
                                             toolStripStatusLabel1.Text = "Rotating " + commonLayer.ToString() + " " + ((direction) ? "Clockwise" : "Counter-Clockwise");
                                         }
                                     }
                                     else
                                     {
                                         toolStripStatusLabel1.Text = "Error: Invalid second selection, does not specify distinct layer";
                                     }
                                 }
                                 else
                                 {
                                     toolStripStatusLabel1.Text = "Error: Invalid second selection, must match orientation of first selection";
                                 }
                             }
                             else
                             {
                                 toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be a center";
                             }
                         }
                         else
                         {
                             toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be first selection";
                         }
                     }
                     rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                     oldSelection = new PositionSpec()
                     {
                         CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                     };
                     currentSelection = new PositionSpec()
                     {
                         CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                     };
                 }
             }
         }
     }
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         if ((Control.ModifierKeys & Keys.Shift) != 0)
         {
             if (currentSelection.CubePosition != Cube3D.RubikPosition.None && currentSelection.FacePosition != Face3D.FacePosition.None)
             {
                 Color clr = rubikRenderer.RubikManager.getFaceColor(currentSelection.CubePosition, currentSelection.FacePosition);
                 for (int i = 0; i < contextMenuStrip1.Items.Count; i++)
                 {
                     ((ToolStripMenuItem)contextMenuStrip1.Items[i]).Checked = (contextMenuStrip1.Items[i].Text == clr.Name);
                 }
                 contextMenuStrip1.Show(Cursor.Position);
             }
         }
     }
 }
 public bool Equals(PositionSpec compare)
 {
     return(CubePosition == compare.CubePosition && FacePosition == compare.FacePosition);
 }