123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- var UI = {};
- UI.Element = function () {};
- UI.Element.prototype = {
- setX: function ( value ) {
- this.dom.style.left = value;
- return this;
- },
- setY: function ( value ) {
- this.dom.style.top = value;
- return this;
- },
- setWidth: function ( value ) {
- this.dom.style.width = value;
- return this;
- },
- setHeight: function ( value ) {
- this.dom.style.height = value;
- return this;
- },
- // border
- setBorder: function ( value ) {
- this.dom.style.border = value;
- return this;
- },
- setBorderTop: function ( value ) {
- this.dom.style.borderTop = value;
- return this;
- },
- setBorderBottom: function ( value ) {
- this.dom.style.borderBottom = value;
- return this;
- },
- setBorderLeft: function ( value ) {
- this.dom.style.borderLeft = value;
- return this;
- },
- setBorderRight: function ( value ) {
- this.dom.style.borderRight = value;
- return this;
- },
- // margin
- setMargin: function ( value ) {
- this.dom.style.margin = value;
- return this;
- },
- setMarginTop: function ( value ) {
- this.dom.style.marginTop = value;
- return this;
- },
- setMarginBottom: function ( value ) {
- this.dom.style.marginBottom = value;
- return this;
- },
- setMarginLeft: function ( value ) {
- this.dom.style.marginLeft = value;
- return this;
- },
- setMarginRight: function ( value ) {
- this.dom.style.marginRight = value;
- return this;
- },
- // padding
- setPadding: function ( value ) {
- this.dom.style.padding = value;
- return this;
- },
- //
- setFontWeight: function ( value ) {
- this.dom.style.fontWeight = value;
- return this;
- },
- setColor: function ( value ) {
- this.dom.style.color = value;
- return this;
- },
- setBackgroundColor: function ( value ) {
- this.dom.style.backgroundColor = value;
- return this;
- }
- }
- // Panel
- UI.Panel = function ( position ) {
- UI.Element.call( this );
- this.dom = document.createElement( 'div' );
- this.dom.style.position = position || 'relative';
- this.dom.addEventListener( 'mousedown', function ( event ) { event.preventDefault() }, false );
- return this;
- };
- UI.Panel.prototype = new UI.Element();
- UI.Panel.prototype.constructor = UI.Panel;
- UI.Panel.prototype.add = function () {
- for ( var i = 0; i < arguments.length; i ++ ) {
- this.dom.appendChild( arguments[ i ].dom );
- }
- return this;
- };
- // Text
- UI.Text = function ( position ) {
- UI.Element.call( this );
- this.dom = document.createElement( 'span' );
- this.dom.style.position = position || 'relative';
- return this;
- };
- UI.Text.prototype = new UI.Element();
- UI.Text.prototype.constructor = UI.Text;
- UI.Text.prototype.setText = function ( value ) {
- this.dom.innerText = value;
- return this;
- };
- // IntNumber
- UI.IntNumber = function ( position ) {
- UI.Element.call( this );
- this.dom = document.createElement( 'span' );
- this.dom.style.position = position || 'relative';
- this.dom.innerText = '0.00';
- this.dom.style.marginTop = '2px';
- this.dom.style.color = '#0080f0';
- this.dom.style.fontSize = '12px';
- this.dom.style.textDecoration = 'underline';
- this.onChangedCallback = null;
- var scope = this;
- var onMouseDownValue, onMouseDownScreenX, onMouseDownScreenY;
- var onMouseDown = function ( event ) {
- event.preventDefault();
- onMouseDownValue = parseInt( scope.dom.innerText );
- onMouseDownScreenX = event.screenX;
- onMouseDownScreenY = event.screenY;
- document.addEventListener( 'mousemove', onMouseMove, false );
- document.addEventListener( 'mouseup', onMouseUp, false );
- }
- var onMouseMove = function ( event ) {
- var dx = event.screenX - onMouseDownScreenX;
- var dy = event.screenY - onMouseDownScreenY;
- scope.dom.innerText = ( onMouseDownValue + ( dx - dy ) / ( event.shiftKey ? 10 : 100 ) ).toFixed( 0 );
- scope.onChangedCallback();
- }
- var onMouseUp = function ( event ) {
- document.removeEventListener( 'mousemove', onMouseMove, false );
- document.removeEventListener( 'mouseup', onMouseUp, false );
- }
- this.dom.addEventListener( 'mousedown', onMouseDown, false );
- return this;
- };
- UI.IntNumber.prototype = new UI.Element();
- UI.IntNumber.prototype.constructor = UI.IntNumber;
- UI.IntNumber.prototype.getValue = function () {
- return parseInt( this.dom.innerText );
- };
- UI.IntNumber.prototype.setValue = function ( value ) {
- this.dom.innerText = value.toFixed( 0 );
- return this;
- };
- UI.IntNumber.prototype.onChanged = function ( callback ) {
- this.onChangedCallback = callback;
- return this;
- };
- // FloatNumber
- UI.FloatNumber = function ( position ) {
- UI.Element.call( this );
- this.dom = document.createElement( 'span' );
- this.dom.style.position = position || 'relative';
- this.dom.innerText = '0.00';
- this.dom.style.marginTop = '2px';
- this.dom.style.color = '#0080f0';
- this.dom.style.fontSize = '12px';
- this.dom.style.textDecoration = 'underline';
- this.onChangedCallback = null;
- var scope = this;
- var onMouseDownValue, onMouseDownScreenX, onMouseDownScreenY;
- var onMouseDown = function ( event ) {
- event.preventDefault();
- onMouseDownValue = parseFloat( scope.dom.innerText );
- onMouseDownScreenX = event.screenX;
- onMouseDownScreenY = event.screenY;
- document.addEventListener( 'mousemove', onMouseMove, false );
- document.addEventListener( 'mouseup', onMouseUp, false );
- }
- var onMouseMove = function ( event ) {
- var dx = event.screenX - onMouseDownScreenX;
- var dy = event.screenY - onMouseDownScreenY;
- scope.dom.innerText = ( onMouseDownValue + ( dx - dy ) / ( event.shiftKey ? 10 : 100 ) ).toFixed( 2 );
- scope.onChangedCallback();
- }
- var onMouseUp = function ( event ) {
- document.removeEventListener( 'mousemove', onMouseMove, false );
- document.removeEventListener( 'mouseup', onMouseUp, false );
- }
- this.dom.addEventListener( 'mousedown', onMouseDown, false );
- return this;
- };
- UI.FloatNumber.prototype = new UI.Element();
- UI.FloatNumber.prototype.constructor = UI.FloatNumber;
- UI.FloatNumber.prototype.getValue = function () {
- return parseFloat( this.dom.innerText );
- };
- UI.FloatNumber.prototype.setValue = function ( value ) {
- this.dom.innerText = value.toFixed( 2 );
- return this;
- };
- UI.FloatNumber.prototype.onChanged = function ( callback ) {
- this.onChangedCallback = callback;
- return this;
- };
- // Break
- UI.Break = function () {
- UI.Element.call( this );
- this.dom = document.createElement( 'br' );
- return this;
- };
- UI.Break.prototype = new UI.Element();
- UI.Break.prototype.constructor = UI.Break;
- // HorizontalRule
- UI.HorizontalRule = function ( position ) {
- UI.Element.call( this );
- this.dom = document.createElement( 'hr' );
- this.dom.style.position = position || 'relative';
- return this;
- };
- UI.HorizontalRule.prototype = new UI.Element();
- UI.HorizontalRule.prototype.constructor = UI.HorizontalRule;
- // Button
- UI.Button = function ( position ) {
- UI.Element.call( this );
- this.dom = document.createElement( 'button' );
- this.dom.style.position = position || 'relative';
- return this;
- };
- UI.Button.prototype = new UI.Element();
- UI.Button.prototype.constructor = UI.Button;
- UI.Button.prototype.setText = function ( value ) {
- this.dom.innerText = value;
- return this;
- };
|