コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: chantsunman/sharpgl
        private void DoFileNewCommand(object parameter)
        {
            //  Create a new shader view model.
            ShaderViewModel shaderViewModel = new ShaderViewModel()
            {
                Name = "New Shader"
            };

            //  Add it to the shaders.
            shaders.Add(shaderViewModel);

            //  Set it as the active shader.
            CurrentShader = shaderViewModel;
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: chantsunman/sharpgl
        private void DoFileOpenCommand(object parameter)
        {
            //  The parameter must be a string.
            if (parameter is string == false)
                throw new ArgumentException("The parameter to the command must be a valid file path.");

            //  Read the file.
            string source;
            try
            {
                //  Open the file stream.
                using (FileStream stream = new FileStream(parameter as string, FileMode.Open))
                {
                    //  Create a streamreader and read the source.
                    TextReader reader = new StreamReader(stream);
                    source = reader.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                //  Re-throw the exception.
                throw new ApplicationException("Failed to load the shader source.", e);
            }

            //  Create a new shader view model.
            ShaderViewModel shaderViewModel = new ShaderViewModel()
            {
                Name = Path.GetFileNameWithoutExtension(parameter as string),
                Source = source
            };

            //  Add it to the shaders.
            shaders.Add(shaderViewModel);

            //  Set it as the active shader.
            CurrentShader = shaderViewModel;
        }