mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-13 22:48:33 +00:00
Bindings for Color
This commit is contained in:
parent
8eba76a670
commit
7f7447e633
@ -59,6 +59,7 @@
|
||||
<Compile Include="SettingsTests.cs" />
|
||||
<Compile Include="Solids\CubeTests.cs" />
|
||||
<Compile Include="Solids\CylinderTests.cs" />
|
||||
<Compile Include="Transforms\ColorTests.cs" />
|
||||
<Compile Include="Transforms\HullTests.cs" />
|
||||
<Compile Include="InterpolationTests.cs" />
|
||||
<Compile Include="Transforms\MirrorTests.cs" />
|
||||
|
||||
31
OSCADSharp/OSCADSharp.UnitTests/Transforms/ColorTests.cs
Normal file
31
OSCADSharp/OSCADSharp.UnitTests/Transforms/ColorTests.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Solids;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OSCADSharp.UnitTests.Transforms
|
||||
{
|
||||
[TestClass]
|
||||
public class ColorTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Color_BoundFieldsAppearInOutput()
|
||||
{
|
||||
Variable colorVar = new Variable("myFavoriteColor", "blue");
|
||||
Variable cubeOpacity = new Variable("cubeOpacity", .6);
|
||||
|
||||
var obj = new Cube().Color("Red", .5);
|
||||
obj.Bind("color", colorVar);
|
||||
obj.Bind("opacity", cubeOpacity);
|
||||
|
||||
string script = obj.ToString();
|
||||
|
||||
Assert.IsTrue(script.Contains("myFavoriteColor"));
|
||||
Assert.IsTrue(script.Contains("cubeOpacity"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,12 @@ namespace OSCADSharp.Transforms
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string colorCommand = String.Format("color(\"{0}\", {1})", this.ColorName, this.Opacity);
|
||||
string colorName = this.bindings.Contains("color") ? this.bindings.Get("color").BoundVariable.Name :
|
||||
this.ColorName;
|
||||
string opacity = this.bindings.Contains("opacity") ? this.bindings.Get("opacity").BoundVariable.Name
|
||||
: this.Opacity.ToString();
|
||||
|
||||
string colorCommand = String.Format("color(\"{0}\", {1})", colorName, opacity);
|
||||
var formatter = new SingleBlockFormatter(colorCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
@ -55,9 +60,13 @@ namespace OSCADSharp.Transforms
|
||||
return this.obj.Bounds();
|
||||
}
|
||||
|
||||
private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary<string, string>() {
|
||||
{"color", "color" },
|
||||
{"opacity", "opacity" }
|
||||
});
|
||||
public override void Bind(string property, Variable variable)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
this.bindings.Add<ColoredObject>(this, property, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user