diff --git a/lib/phast/client/scripts/controls/BinarySwitch.js b/lib/phast/client/scripts/controls/BinarySwitch.js new file mode 100644 index 0000000..fe8d4c1 --- /dev/null +++ b/lib/phast/client/scripts/controls/BinarySwitch.js @@ -0,0 +1,47 @@ +function BinarySwitch(parentElement) +{ + this.ParentElement = parentElement; + this.SwitchesElement = this.ParentElement.children[0]; + this.InputElement = this.ParentElement.children[1]; + + var switches = this.SwitchesElement.children; + for (var i = 0; i < switches.length; i++) + { + switches[i].__BinarySwitch = this; + switches[i].addEventListener("change", function(e) + { + this.__BinarySwitch.update(); + }, true); + } + + this.update = function() + { + var value = 0; + var switches = this.SwitchesElement.children; + for (var i = 0; i < switches.length; i++) + { + if (System.ClassList.Contains(switches[i], "uwt-selected")) + { + if (this.ParentElement.getAttribute("data-endianness") == "little") + { + value += (2 ** (switches.length - i - 1)); + } + else + { + value += (2 ** i); + } + } + } + + this.InputElement.value = value; + }; +} + +window.addEventListener("load", function() +{ + var items = document.getElementsByClassName("uwt-binaryswitch"); + for (var i = 0; i < items.length; i++) + { + items[i].NativeObject = new BinarySwitch(items[i]); + } +}); \ No newline at end of file diff --git a/lib/phast/client/scripts/controls/RotarySwitch.js b/lib/phast/client/scripts/controls/RotarySwitch.js new file mode 100644 index 0000000..fd7572d --- /dev/null +++ b/lib/phast/client/scripts/controls/RotarySwitch.js @@ -0,0 +1,40 @@ +function RotarySwitch(parentElement) +{ + console.log("found rotarySwitch"); + console.log(parentElement); + + this.ParentElement = parentElement; + this.ValueElement = this.ParentElement.children[0]; + this.ListElement = this.ParentElement.children[1]; + this.IndicatorElement = this.ParentElement.children[2]; + this.AngleOffset = -135; + + this.setValue = function(value, angle) + { + this.ValueElement.value = value; + console.log("new angle: " + (angle + this.AngleOffset)); + this.IndicatorElement.style.transform = "rotate(" + (angle + this.AngleOffset) + "deg)"; + }; + + for (var i = 0; i < this.ListElement.children.length; i++) + { + this.ListElement.children[i].children[0].NativeObject = this; + this.ListElement.children[i].children[0].addEventListener("click", function(e) + { + this.NativeObject.setValue(this.getAttribute("data-value"), parseFloat(this.getAttribute("data-angle"))); + + e.preventDefault(); + e.stopPropagation(); + return false; + }); + } +} + +window.addEventListener("load", function() +{ + var items = document.getElementsByClassName("uwt-rotaryswitch"); + for (var i = 0; i < items.length; i++) + { + items[i].NativeObject = new RotarySwitch(items[i]); + } +}); \ No newline at end of file diff --git a/lib/phast/client/scripts/controls/Switch.js b/lib/phast/client/scripts/controls/Switch.js new file mode 100644 index 0000000..0819c53 --- /dev/null +++ b/lib/phast/client/scripts/controls/Switch.js @@ -0,0 +1,19 @@ +function Switch(parentElement) +{ + this.ParentElement = parentElement; + this.ParentElement.addEventListener("click", function() + { + System.ClassList.Toggle(this, "uwt-selected"); + + System.RaiseEvent(this, "change", null); + }); +} + +window.addEventListener("load", function() +{ + var items = document.getElementsByClassName("uwt-switch"); + for (var i = 0; i < items.length; i++) + { + items[i].NativeObject = new Switch(items[i]); + } +}); \ No newline at end of file diff --git a/lib/phast/server/WebControls/BinarySwitch.inc.php b/lib/phast/server/WebControls/BinarySwitch.inc.php new file mode 100644 index 0000000..d3fab2c --- /dev/null +++ b/lib/phast/server/WebControls/BinarySwitch.inc.php @@ -0,0 +1,130 @@ +TagName = "div"; + $this->ClassList[] = "uwt-binaryswitch"; + + $this->MinimumValue = 0; + $this->MaximumValue = 255; + + $this->Value = 0; + + $this->Endianness = BinarySwitchEndianness::BigEndian; + } + + /** + * Gets the number of switches necessary to represent values less than or equal to MaximumValue. + */ + private function getNumSwitches() + { + return ceil(log(($this->MaximumValue - $this->MinimumValue) + 1, 2)); + } + private function getSwitchState() + { + $ary = []; + $n = $this->getNumSwitches(); + for ($i = 0; $i < $n; $i++) + { + if ($this->Endianness == BinarySwitchEndianness::BigEndian) + { + $v = pow(2, $i); + } + else + { + $v = pow(2, ($n - $i - 1)); + } + $val = (($this->Value & $v) == $v); + $ary[] = $val; + } + return $ary; + } + + protected function RenderBeginTag() + { + if ($this->Endianness == BinarySwitchEndianness::BigEndian) + { + $this->Attributes[] = new WebControlAttribute("data-endianness", "big"); + } + else if ($this->Endianness == BinarySwitchEndianness::LittleEndian) + { + $this->Attributes[] = new WebControlAttribute("data-endianness", "little"); + } + + parent::RenderBeginTag(); + + echo("
"); + + $nSwitches = $this->getSwitchState(); + + for ($i = 0; $i < count($nSwitches); $i++) + { + if ($this->Endianness == BinarySwitchEndianness::BigEndian) + { + $val = pow(2, $i); + } + else + { + $val = pow(2, (count($nSwitches) - $i - 1)); + } + + echo ("
"); + echo (""); + echo ("
 
"); + echo ("
"); + } + + echo ("
"); + echo ("Name . "\" value=\"" . $this->Value . "\" />"); + echo (""); + } + + protected function RenderContent() + { + + } + + + } + +?> \ No newline at end of file diff --git a/lib/phast/server/WebControls/RotarySwitch.inc.php b/lib/phast/server/WebControls/RotarySwitch.inc.php new file mode 100644 index 0000000..62ca6d8 --- /dev/null +++ b/lib/phast/server/WebControls/RotarySwitch.inc.php @@ -0,0 +1,80 @@ +Value = $value; + } + } + + class RotarySwitch extends WebControl + { + public $Name; + public $Value; + + public array $Options; + + public function __construct() + { + parent::__construct(); + + $this->TagName = "div"; + $this->ClassList[] = "uwt-rotaryswitch"; + $this->Options = array(); + + $this->Value = ""; + } + + + protected function RenderBeginTag() + { + parent::RenderBeginTag(); + + echo (""); + + $circle_size = 64; + echo (""); + + echo ("
 
"); + + } + + protected function RenderContent() + { + + } + + + } + +?> \ No newline at end of file