Exemple #1
0
        private Mouse()
        {
            var core = GraphicCore.getInstance();

            core.form.MouseMove += (sender, args) =>
            {
                x = args.X;
                y = args.Y;
                dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_MOVE, x, y));
            };
            core.form.MouseWheel += (sender, args) =>
            {
                _delta = args.Delta;
                dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_WHEEL, args.X, args.Y, false, args.Delta));
            };
            core.form.MouseClick += (sender, args) =>
            {
                x = args.X;
                y = args.Y;
                dispatchEvent(new MouseEvent(this, MouseEvent.CLICK, x, y, true));
            };
            core.form.MouseUp += (sender, args) =>
            {
                x = args.X;
                y = args.Y;
                dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_UP, x, y, false));
            };
            core.form.MouseDown += (sender, args) =>
            {
                x = args.X;
                y = args.Y;
                dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_DOWN, x, y, true));
            };
        }
Exemple #2
0
 public static GraphicCore getInstance()
 {
     if (_instance == null)
     {
         _instance = new GraphicCore();
     }
     return(_instance);
 }
Exemple #3
0
        private Stage()
        {
            GraphicCore core = GraphicCore.getInstance();

            core.addEventListener(Event.ENTER_FRAME, handleEvent);
            _isDisplayed = true;
            _rendertype  = RenderType.STAGE;
        }
Exemple #4
0
        public void loadFromFile(string file)
        {
            if (!File.Exists(file))
            {
                Console.WriteLine("Не найден файл " + file);
                throw new Exception("Не найден файл " + file);
            }
            using (var bitmap = (System.Drawing.Bitmap)Image.FromFile(file))
            {
                var sourceArea       = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                var bitmapProperties =
                    new BitmapProperties(new PixelFormat(Format.B8G8R8A8_UNorm,
                                                         AlphaMode.Premultiplied));
                var size = new Size(bitmap.Width, bitmap.Height);

                // Transform pixels from BGRA to RGBA
                int stride = bitmap.Width * sizeof(int);
                using (var tempStream = new DataStream(bitmap.Height * stride, true, true))
                {
                    // Lock System.Drawing.Bitmap
                    var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.ReadOnly,
                                                     System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                    // Convert all pixels
                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        int offset = bitmapData.Stride * y;
                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            // Not optimized
                            byte R    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            byte G    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            byte B    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            byte A    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            int  rgba = R | (G << 8) | (B << 16) | (A << 24);
                            tempStream.Write(rgba);
                        }
                    }
                    bitmap.UnlockBits(bitmapData);
                    _width              = bitmap.Width;
                    _height             = bitmap.Height;
                    tempStream.Position = 0;
                    GraphicCore core = GraphicCore.getInstance();
                    source = new SharpDX.Direct2D1.Bitmap(core.render2d, size, tempStream, stride, bitmapProperties);
                }
            }
            _isLoaded = true;
            dispatchEvent(new Event(this, Event.COMPLETE));
        }
Exemple #5
0
        public static SharpDX.Direct2D1.Bitmap getSource(String path)
        {
            using (var bitmap = (System.Drawing.Bitmap)Image.FromFile(path))
            {
                var sourceArea       = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                var bitmapProperties =
                    new BitmapProperties(new PixelFormat(Format.B8G8R8A8_UNorm,
                                                         AlphaMode.Premultiplied));
                var size = new Size(bitmap.Width, bitmap.Height);

                // Transform pixels from BGRA to RGBA
                int stride = bitmap.Width * sizeof(int);
                using (var tempStream = new DataStream(bitmap.Height * stride, true, true))
                {
                    // Lock System.Drawing.Bitmap
                    var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.ReadOnly,
                                                     System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                    // Convert all pixels
                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        int offset = bitmapData.Stride * y;
                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            // Not optimized
                            byte R    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            byte G    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            byte B    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            byte A    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                            int  rgba = R | (G << 8) | (B << 16) | (A << 24);
                            tempStream.Write(rgba);
                        }
                    }
                    bitmap.UnlockBits(bitmapData);
                    tempStream.Position = 0;
                    GraphicCore core = GraphicCore.getInstance();
                    return(new SharpDX.Direct2D1.Bitmap(core.render2d, size, tempStream, stride, bitmapProperties));
                }
            }
        }
Exemple #6
0
 public Camera()
 {
     dpi = Matrix.Scaling(GraphicCore.getInstance().form.Width / (float)sw,
                          GraphicCore.getInstance().form.Height / (float)sh, 1);
 }