Exemplo n.º 1
0
        public void Instance(string[] args, bool isPathFolder)
        {
            try
            {
                Form form = new Form();
                GraphicsDeviceService gds      = GraphicsDeviceService.AddRef(form.Handle, form.ClientSize.Width, form.ClientSize.Height);
                ServiceContainer      services = new ServiceContainer();
                services.AddService <IGraphicsDeviceService>(gds);
                var content = new ContentManager(services);

                if (!isPathFolder)  //if we get a file
                {
                    foreach (string file in args)
                    {
                        Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " " + file);
                        if (File.Exists(file))
                        {
                            if (Path.GetExtension(file).Equals(".xnb"))
                            {
                                ConvertToPng(content, file);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid file path or file");
                        }
                    }
                }
                else      //if we get a folder
                {
                    DirectoryInfo dir = new DirectoryInfo(args[0]);

                    foreach (var file in dir.GetFiles("*.xnb", SearchOption.AllDirectories))   //we search for every file in all subdirectories
                    {
                        Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " " + file.FullName);
                        if (File.Exists(file.FullName))
                        {
                            if (Path.GetExtension(file.FullName).Equals(".xnb"))
                            {
                                ConvertToPng(content, file.FullName);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid file path or file");
                        }
                    }
                }

                foreach (string f in filesToDelete)
                {
                    File.Delete(f);
                }
                content.Unload();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
 public MainForm()
 {
     InitializeComponent();
     StatusManager.RegisterDelegate(this.logTextBox.AppendText);
     ContentManager.SetGraphicsDevice(GraphicsDeviceService.AddRef(this.Handle, 50, 50).GraphicsDevice);
     StatusManager.AddLog("ROSE Online UI Editor Vs 2.0 By Jiwan : Ready to use");
 }
    public static GraphicsDeviceService AddRef(int width, int height)
    {
        if (_invisibleRenderTarget == null)
        {
            _invisibleRenderTarget = new Form();
        }

        return(GraphicsDeviceService.AddRef(_invisibleRenderTarget.Handle, width, height));
    }
Exemplo n.º 4
0
        private void OnXnaWindowHostLoaded(object sender, RoutedEventArgs e)
        {
            // If we don't yet have a GraphicsDeviceService reference, we must add one for this control
            if (_graphicsService == null)
            {
                _graphicsService = GraphicsDeviceService.AddRef((int)ActualWidth, (int)ActualHeight);

                // Invoke the LoadContent event
                RaiseLoadContent(new GraphicsDeviceEventArgs(_graphicsService.GraphicsDevice));
            }
        }
 protected override void OnCreateControl()
 {
     if (!designMode)
     {
         _graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height);
         _chain = new SwapChainRenderTarget(_graphicsDeviceService.GraphicsDevice, Handle, ClientSize.Width,
                                            ClientSize.Height);
         Services.AddService <IGraphicsDeviceService>(_graphicsDeviceService);
         Initialize();
     }
     base.OnCreateControl();
 }
Exemplo n.º 6
0
            /// <summary>
            /// This property is a bit hacking to get a GraphicsDevice.
            ///
            /// Extracting textures in Celeste (or in XNA) needs to construct Texture2D objects
            /// which requires a valid GraphicsDevice.
            ///
            /// Since it is a command-line app, in order to get the GraphicsDevice,
            /// I have to create an invisible form to acquire a handle and get the device.
            /// </summary>
            private static void Initialize()
            {
                Form form = new Form(); // Invisible form to get a valid GraphicsDevice.
                GraphicsDeviceService gds      = GraphicsDeviceService.AddRef(form.Handle, form.ClientSize.Width, form.ClientSize.Height);
                ServiceContainer      services = new ServiceContainer();

                services.AddService <IGraphicsDeviceService>(gds);
                _content = new ContentManager(services, "Content");
                IGraphicsDeviceService graphicsDeviceService = services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;

                _graphicsDevice = graphicsDeviceService.GraphicsDevice;
            }
 #pragma warning disable 1591
 protected override void OnCreateControl()
 {
     if (!designMode)
     {
         _graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height, GraphicsProfile);
         _chain = new SwapChainRenderTarget(_graphicsDeviceService.GraphicsDevice, Handle, ClientSize.Width,
                                            ClientSize.Height);
         Services.AddService <IGraphicsDeviceService>(_graphicsDeviceService);
         Initialize();
         Microsoft.Xna.Framework.Input.Mouse.WindowHandle = Handle;
     }
     base.OnCreateControl();
 }
 //void XnaWindowHost_Loaded(object sender, RoutedEventArgs e)
 public void Start()
 {
     // If we don't yet have a GraphicsDeviceService reference, we must add one for this control
     if (graphicsService == null)
     {
         graphicsService = GraphicsDeviceService.AddRef(hWnd, (int)ActualWidth, (int)ActualHeight);
         //
         // Invoke the LoadContent event
         if (LoadContent != null)
         {
             LoadContent(this, new GraphicsServiceEventArgs(graphicsService));
         }
     }
 }
Exemplo n.º 9
0
        public void initialize()
        {
            // Initialize graphics device service
            _graphicsDeviceService = GraphicsDeviceService.AddRef(view.Handle, view.Width, view.Height);

            // Initialize core resource controller
            ResourceManager.initialize(_graphicsDeviceService.GraphicsDevice);
            ResourceManager.rootDirectory = resourcesSourcePath + "\\";

            // Create controllers
            _levelController      = new LevelController(this, _editorView.levelView);
            _materialController   = new MaterialController(this, _editorView.materialView);
            _blueprintController  = new BlueprintController(this, _editorView.blueprintView);
            _circuitController    = new CircuitController(this, _editorView.circuitsView);
            _backgroundController = new BackgroundController(this, _editorView.backgroundView);
        }
Exemplo n.º 10
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (_graphicsDeviceService == null)
            {
                // We use a render target, so the back buffer dimensions don't matter.
                _graphicsDeviceService = GraphicsDeviceService.AddRef(1, 1);
                _graphicsDeviceService.DeviceResetting += OnGraphicsDeviceServiceDeviceResetting;

                // Invoke the LoadContent event
                RaiseLoadContent(new GraphicsDeviceEventArgs(_graphicsDeviceService.GraphicsDevice));

                EnsureRenderTarget();

                CompositionTarget.Rendering += OnCompositionTargetRendering;

                _contentNeedsRefresh = true;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void OnCreateControl()
        {
            // Don't initialize the graphics device if we are running in the designer.
            if (!DesignMode)
            {
                graphicsDeviceService = GraphicsDeviceService.AddRef(Handle,
                                                                     ClientSize.Width,
                                                                     ClientSize.Height);

                // Register the service, so components like ContentManager can find it.
                services.AddService <IGraphicsDeviceService>(graphicsDeviceService);

                // Give derived classes a chance to initialize themselves.
                Initialize();
            }

            base.OnCreateControl();
        }
Exemplo n.º 12
0
        void DrawingSurface_Loaded(object sender, RoutedEventArgs e)
        {
            if (GraphicsDeviceService == null)
            {
                GraphicsDeviceService = GraphicsDeviceService.AddRef(IntPtr.Zero, (int)ActualWidth, (int)ActualHeight, GraphicsProfile);
                GraphicsDeviceService.DeviceResetting += GraphicsDeviceService_DeviceResetting;

                D3dImage.Lock();
                D3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, backbuffer = Interop.GetBackBuffer(GraphicsDeviceService.GraphicsDevice));
                D3dImage.Unlock();
                Marshal.Release(backbuffer);

                CompositionTarget.Rendering += CompositionTarget_Rendering;

                stopWatch           = Stopwatch.StartNew();
                lastDrawTimestamp   = TimeSpan.Zero;
                contentNeedsRefresh = true;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Constructs a new PForm.
        /// </summary>
        public PForm()
        {
            InitializeComponent();

            // Don't initialize the graphics device if we are running in the designer.
            if (!DesignMode)
            {
                graphicsDeviceService = GraphicsDeviceService.AddRef(Handle,
                                                                     ClientSize.Width,
                                                                     ClientSize.Height);

                // Register the service, so components like ContentManager can find it.
                services.AddService <IGraphicsDeviceService>(graphicsDeviceService);

                InitializePiccolo(false, null);

                OpenDefaultProject();
                RefreshProject();
            }
        }
Exemplo n.º 14
0
        private void _tkControl_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                _deviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height);

                _services.AddService <IGraphicsDeviceService>(_deviceService);

                if (ControlInitializing != null)
                {
                    ControlInitializing(this, EventArgs.Empty);
                }

                Initialize();

                if (ControlInitialized != null)
                {
                    ControlInitialized(this, EventArgs.Empty);
                }
            }
        }
        void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // if we're not in design mode, initialize the graphics device
            if (DesignerProperties.GetIsInDesignMode(this) == false && graphicsService == null)
            {
                // add a reference to the graphics device
                graphicsService = GraphicsDeviceService.AddRef((PresentationSource.FromVisual(this) as HwndSource).Handle);

                // create the image source
                imageSource      = new RenderTargetImageSource(GraphicsDevice, (int)ActualWidth, (int)ActualHeight);
                rootImage.Source = imageSource.WriteableBitmap;

                // hook the rendering event
                CompositionTarget.Rendering += CompositionTarget_Rendering;

                // Invoke the ControlLoaded event
                if (ControlLoaded != null)
                {
                    ControlLoaded(this, new GraphicsDeviceEventArgs(graphicsService.GraphicsDevice));
                }
            }
        }
#pragma warning disable 1591
        protected override void OnCreateControl()
        {
            if (!designMode && ClientSize.Width > 0 && ClientSize.Height > 0)
            {
                _graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height, GraphicsProfile);
                Services.AddService <IGraphicsDeviceService>(_graphicsDeviceService);
#if DX
                _chain = new SwapChainRenderTarget(_graphicsDeviceService.GraphicsDevice, Handle, ClientSize.Width, ClientSize.Height);

                Microsoft.Xna.Framework.Input.Mouse.WindowHandle = Handle;
#elif GL
                _chain = new SwapChainRenderTarget_GL(_graphicsDeviceService.GraphicsDevice, ClientSize.Width, ClientSize.Height);

                _Intervall.Enabled = true;
                _Intervall.Start();
                _Intervall.Tick += (sender, e) => { PresentDirty(); };
#endif
                AutomaticInvalidation = true;
                Initialize();
            }
            base.OnCreateControl();
        }
Exemplo n.º 17
0
        public void instance(string[] args)
        {
            try
            {
                Form form = new Form();
                GraphicsDeviceService gds      = GraphicsDeviceService.AddRef(form.Handle, form.ClientSize.Width, form.ClientSize.Height);
                ServiceContainer      services = new ServiceContainer();
                services.AddService <IGraphicsDeviceService>(gds);
                var content = new ContentManager(services);

                foreach (string p in args)
                {
                    Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " " + p);
                    if (File.Exists(p))
                    {
                        if (Path.GetExtension(p).Equals(".xnb"))
                        {
                            ConvertToPng(content, p);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid file path or file");
                    }
                }

                foreach (string f in filesToDelete)
                {
                    File.Delete(f);
                }
                content.Unload();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 18
0
        protected override void OnCreateControl()
        {
            if (!DesignMode)
            {
                _deviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height);

                ServiceLocator.Add <IGraphicsDeviceService>(_deviceService);
                ServiceLocator.Add(_deviceService.GraphicsDevice);
                ServiceLocator.Add <IEntityService>(new EntityService());
                ServiceLocator.Add <ICollisionService>(new CollisionService());

                _camera = new Camera(_deviceService.GraphicsDevice.Viewport);

                if (!ServiceLocator.Has <Camera>())
                {
                    ServiceLocator.Add(_camera);
                }

                if (ControlInitializing != null)
                {
                    ControlInitializing(this, EventArgs.Empty);
                }

                // Start the animation timer.
                _timer = Stopwatch.StartNew();

                Initialize();

                if (ControlInitialized != null)
                {
                    ControlInitialized(this, EventArgs.Empty);
                }

                Application.Idle += (o, args) => Invalidate(true);
            }
        }
Exemplo n.º 19
0
 public void Initialize()
 {
     ContentBuilder        = new ContentBuilder();
     Content               = new ContentManager(GraphicsDeviceService.AddRef());
     Content.RootDirectory = ContentBuilder.OutputDirectory;
 }
Exemplo n.º 20
0
        public WriteableBitmap ToImage(bool opaqueAlpha)
        {
            if (this.textureType != 21)
            {
                using (var stream = new MemoryStream())
                {
                    stream.WriteU32(0x20534444); // 'DDS '
                    stream.WriteU32(0x7C);       // header size
                    stream.WriteU32(0xA1007);    // flags:
                    stream.WriteU32(height);
                    stream.WriteU32(width);
                    stream.WriteU32((uint)height * (uint)width);  // size of top mipmap level... at least in DXT5 for >4x4
                    stream.WriteU32(0);
                    stream.WriteU32(mipmapInfo / 0x100);
                    for (int i = 0; i < 11; i++)
                    {
                        stream.WriteU32(0);
                    }

                    // pixel format
                    stream.WriteU32(32);
                    stream.WriteU32(4);  // DDPF_FOURCC?
                    stream.WriteU32(textureType);
                    stream.WriteU32(32);
                    stream.WriteU32(0xff0000);
                    stream.WriteU32(0x00ff00);
                    stream.WriteU32(0x0000ff);
                    stream.WriteU32(0xff000000);
                    stream.WriteU32(0);  // 0x41008
                    for (int i = 0; i < 4; i++)
                    {
                        stream.WriteU32(0);
                    }

                    stream.Write(texData.blob, 0, texData.blob.Length);

                    GraphicsDeviceService.AddRef(new WindowInteropHelper(Application.Current.MainWindow).Handle);
                    Texture2D texture;

                    try
                    {
                        DDSLib.DDSFromStream(stream, GraphicsDeviceService.Instance.GraphicsDevice, 0, true, out texture);
                        return(new WriteableBitmap(DDSLib.Texture2Image(texture)));
                    }
                    catch
                    {
                        return(null);
                    }
                }
            }
            else //In this case it's a regular bitmap saved as a texture
            {
                using (MemoryStream byteStream = new MemoryStream(this.texData.blob, 0, this.texData.blob.Length))
                {
                    for (int i = 0; i < this.mipmapInfo; i++)
                    {
                        //  uint blockSize = byteStream.ReadU32().Swap();
                        WriteableBitmap bitmap = new WriteableBitmap((int)this.width, (int)this.height, 300, 300, PixelFormats.Pbgra32, BitmapPalettes.Halftone64);
                        if (this.textureType == 21)
                        {
                            for (int j = 0; j < (byteStream.Length / 4); j++)
                            {
                                byte b = byteStream.ReadU8();
                                byte g = byteStream.ReadU8();
                                byte r = byteStream.ReadU8();
                                byte a = byteStream.ReadU8();

                                if (opaqueAlpha)
                                {
                                    a = 255;
                                }

                                try
                                {
                                    if ((j / this.width) < this.height)
                                    {
                                        bitmap.SetPixel((int)(j % this.width), (int)(j / this.width), a, r, g, b);
                                    }
                                }
                                catch
                                {
                                }
                            }

                            return(bitmap);
                        }
                    }
                }
            }
            return(null);
        }