private static BrushScript LoadBrush(Stream stream) { byte[] buffer = new byte[4]; stream.Read(buffer, 0, sizeof(int)); int width = BitConverter.ToInt32(buffer, 0); stream.Read(buffer, 0, sizeof(int)); int height = BitConverter.ToInt32(buffer, 0); stream.Read(buffer, 0, sizeof(float)); float power = BitConverter.ToSingle(buffer, 0); stream.Read(buffer, 0, sizeof(int)); int precision = BitConverter.ToInt32(buffer, 0); CSScript script = new CSScript(); script.Source = LoadText(stream); HeightBrush.SampleFunction sample; HeightBrush.BlendFunction blend; string errors; HeightBrush.CompileFunctions(script, out sample, out blend, out errors); BrushScript bs = new BrushScript() { brush = new HeightBrush(width, height, power, precision, sample, blend), script = script }; return(bs); }
private void compileButton_Click(object sender, EventArgs e) { script.Source = scriptBox.Text; HeightBrush.SampleFunction sample; HeightBrush.BlendFunction blend; string errors; switch (HeightBrush.CompileFunctions(script, out sample, out blend, out errors)) { case HeightBrush.CompileResult.WrongSampleSignature: MessageBox.Show("The method signature for the \"Sample\" function should be:\n\nfloat Sample(int x, int y, float intensity, int left, int right, int top int bottom)", "Script Error"); break; case HeightBrush.CompileResult.MissingSampleFunction: MessageBox.Show("The \"Sample\" function is missing from your script."); break; case HeightBrush.CompileResult.WrongBlendSignature: MessageBox.Show("The method signature for the \"Blend\" function should be:\n\nfloat Blend(float baseValue, float newValue)", "Script Error"); break; case HeightBrush.CompileResult.MissingBlendFunction: MessageBox.Show("The \"Blend\" function is missing from your script."); break; case HeightBrush.CompileResult.SyntaxError: MessageBox.Show("There was a compilation error in your script:\r\n" + errors, "Syntax Error"); break; case HeightBrush.CompileResult.Success: brush.Sample = sample; brush.Blend = blend; break; } }