Exemple #1
0
 private void Control1_MouseClick(Object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         GraphicalHelirin gh = new GraphicalHelirin((int)((e.X - computed_bmp_start_x) / computed_scale + computed_start_pixel.x),
                                                    (int)((e.Y - computed_bmp_start_y) / computed_scale + computed_start_pixel.y), 0, /* TODO */ false, 0);
         p.SetHelirinState(Physics.FromGraphicalHelirin(gh, true));
     }
     if (e.Button == MouseButtons.Right)
     {
         GraphicalHelirin gh = new GraphicalHelirin((int)((e.X - computed_bmp_start_x) / computed_scale + computed_start_pixel.x),
                                                    (int)((e.Y - computed_bmp_start_y) / computed_scale + computed_start_pixel.y), 0, /* TODO */ false, 0);
         p.SetHelirinState(Physics.FromGraphicalHelirin(gh, false));
     }
 }
Exemple #2
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            Graphics g = CreateGraphics();

            g.Clear(BackColor);

            int   start_x = 0;
            int   start_y = 0;
            float scale   = 1;

            if (bmap != null)
            {
                scale   = Math.Min((float)Width / bmap.Width, (float)Height / bmap.Height);
                start_x = (Width - (int)(bmap.Width * scale)) / 2;
                start_y = (Height - (int)(bmap.Height * scale)) / 2;
                g.DrawImage(bmap, start_x, start_y, bmap.Width * scale, bmap.Height * scale);

                computed_bmp_start_x = start_x;
                computed_bmp_start_y = start_y;
            }

            computed_bmp_start_x = start_x;
            computed_bmp_start_y = start_y;
            computed_scale       = scale;

            if (highlight_map != null)
            {
                Brush b    = new SolidBrush(highlight_color);
                int   size = (int)Math.Ceiling(computed_scale);
                for (int i = 0; i < highlight_map.GetLength(0); i++)
                {
                    for (int j = 0; j < highlight_map.GetLength(1); j++)
                    {
                        if (highlight_map[i, j])
                        {
                            Rectangle dest = new Rectangle((int)(computed_bmp_start_x + j * computed_scale), (int)(computed_bmp_start_y + i * computed_scale), size, size);
                            g.FillRectangle(b, dest);
                        }
                    }
                }
            }

            int real_start_x = start_x - (int)(computed_start_pixel.x * scale);
            int real_start_y = start_y - (int)(computed_start_pixel.y * scale);

            void drawRectangle(Rectangle r, Color c, bool fill = true)
            {
                float x = r.X;
                float y = r.Y;
                float w = r.Width;
                float h = r.Height;

                if (fill)
                {
                    g.FillRectangle(new SolidBrush(c), real_start_x + x * scale, real_start_y + y * scale, w * scale, h * scale);
                }
                else
                {
                    g.DrawRectangle(new Pen(c, 1), real_start_x + x * scale, real_start_y + y * scale, (w - 1) * scale, (h - 1) * scale);
                }
            }

            void drawCircle(int cx, int cy, int r, Color c, bool fill = true)
            {
                float x = cx - r;
                float y = cy - r;
                float w = 2 * r - 1;
                float h = 2 * r - 1;

                if (fill)
                {
                    g.FillEllipse(new SolidBrush(c), real_start_x + x * scale, real_start_y + y * scale, w * scale, h * scale);
                }
                else
                {
                    g.DrawEllipse(new Pen(c, 1), real_start_x + x * scale, real_start_y + y * scale, w * scale, h * scale);
                }
            }

            if (showO && m != null && (helirin == null || !helirin.Value.hasBonus))
            {
                Rectangle?bonus = m.GetBonusPxRect();
                if (bonus.HasValue)
                {
                    drawRectangle(bonus.Value, Color.MediumPurple);
                }
                if (helirin != null && Settings.enable_moving_objects)
                {
                    foreach (Piston p in m.Pistons)
                    {
                        drawRectangle(p.PreciseBoxAtTime(helirin.Value.frameNumber), Color.FromArgb(0xFF, 0x77, 0x22, 0x77), false);
                    }
                    foreach (Roller r in m.Rollers)
                    {
                        Roller.Ball b = r.PreciseBoxAtTime(helirin.Value.frameNumber);
                        if (b != null)
                        {
                            drawCircle(b.cx, b.cy, b.r, Color.FromArgb(0xFF, 0x77, 0x77, 0x22), false);
                        }
                    }
                }
            }

            if (helirin != null)
            {
                GraphicalHelirin h = helirin.Value;
                Pen myPen          = new Pen(Color.Black, 1);

                int offset_x = h.pixelX - Map.helirin_radius;
                int offset_y = h.pixelY - Map.helirin_radius;
                int size     = Map.helirin_radius * 2;
                g.DrawEllipse(myPen, real_start_x + offset_x * scale, real_start_y + offset_y * scale, size * scale, size * scale);

                offset_x = h.pixelX - 2;
                offset_y = h.pixelY - 2;
                size     = 4;
                g.DrawEllipse(myPen, real_start_x + offset_x * scale, real_start_y + offset_y * scale, size * scale, size * scale);

                Size  o  = new Size(real_start_x, real_start_y);
                Point p1 = new Point((int)(h.pixelX + Math.Sin(h.angle) * Map.helirin_radius), (int)(h.pixelY - Math.Cos(h.angle) * Map.helirin_radius));
                Point p2 = new Point((int)(h.pixelX - Math.Sin(h.angle) * Map.helirin_radius), (int)(h.pixelY + Math.Cos(h.angle) * Map.helirin_radius));
                p1 = new Point((int)(p1.X * scale), (int)(p1.Y * scale));
                p2 = new Point((int)(p2.X * scale), (int)(p2.Y * scale));
                g.DrawLine(myPen, Point.Add(p1, o), Point.Add(p2, o));
            }
        }