Moved ColorValues

Moved ColorValues
This commit is contained in:
Lukasz Baldyga committed 2020-11-27 21:00:09 +00:00
1 parent 46804ab01d
commit 055b31c16e
3 files changed
+69 -51

No files matched your search

@@ -89,6 +89,7 @@
<Compile Include="Verbs\DrawingVerbs\ResetPen.cs" />
<Compile Include="Verbs\DrawingVerbs\Square.cs" />
<Compile Include="Verbs\DrawingVerbs\Triangle.cs" />
<Compile Include="Verbs\Value\ValueObjects\PointValue.cs" />
<Compile Include="Verbs\Value\ValueTypes\ExpressionValue.cs" />
<Compile Include="Verbs\Value\DeclareVariable.cs" />
<Compile Include="Verbs\Value\UpdateVariable.cs" />
@@ -97,7 +98,7 @@
<Compile Include="Verbs\Value\ValueHelper.cs" />
<Compile Include="Verbs\IVerb.cs" />
<Compile Include="Verbs\Value\ValueTypes\BoolValue.cs" />
<Compile Include="Verbs\Value\ValueTypes\ColorValue.cs" />
<Compile Include="Verbs\Value\ValueObjects\ColorValue.cs" />
<Compile Include="Verbs\Value\ValueTypes\DoubleValue.cs" />
<Compile Include="Verbs\Value\ValueTypes\IntValue.cs" />
<Compile Include="Verbs\Value\ValueTypes\VariableValue.cs" />
@@ -0,0 +1,67 @@
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
using System;
using System.Drawing;
namespace Advanced_Software_Engineering.Verbs.Value.ValueObjects {
internal class ColorValue : IValue {
private IValue r;
private IValue g;
private IValue b;
bool hasAlpha;
private IValue a;
public ColorValue(Color value) {
r = new IntValue(value.R);
g = new IntValue(value.G);
b = new IntValue(value.B);
a = new IntValue(value.A);
hasAlpha = true;
}
public ColorValue(IValue r, IValue g, IValue b, IValue a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
hasAlpha = true;
}
public ColorValue(IValue r, IValue g, IValue b) {
this.r = r;
this.g = g;
this.b = b;
hasAlpha = false;
}
public string GetDescription() {
return "A color value";
}
public string GetOriginalType() {
return "color";
}
public bool ToBool() {
return ToColor().GetBrightness() > 0.5;
}
public Color ToColor() {
if (hasAlpha) return Color.FromArgb(a.ToInt(), r.ToInt(), g.ToInt(), b.ToInt());
else return Color.FromArgb(r.ToInt(), g.ToInt(), b.ToInt());
}
public double ToDouble() {
return ToColor().GetBrightness();
}
public int ToInt() {
return ToColor().ToArgb();
}
public bool isInitialised() {
return true;
}
}
}
@@ -1,50 +0,0 @@
using System;
using System.Drawing;
namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
internal class ColorValue : IValue {
private bool initialised = false;
private Color value;
private Type type = typeof(Color);
public ColorValue(Color value) {
this.value = value;
initialised = true;
}
public ColorValue() {
}
public string GetDescription() {
if (initialised) return "A color with description " + value.ToString();
else return "An uninitialised color";
}
public string GetOriginalType() {
return "color";
}
public bool ToBool() {
return ToColor().GetBrightness() > 0.5;
}
public Color ToColor() {
if (initialised) return value;
else throw new Exception("Color value not set");
}
public double ToDouble() {
return ToColor().GetBrightness();
}
public int ToInt() {
return ToColor().ToArgb();
}
public bool isInitialised() {
return initialised;
}
}
}