Exemple #1
0
    public static void Main(string[] args)
    {
        var obj1 = (dynamic)Verbatim.Expression("{}");
        var obj2 = (dynamic)Verbatim.Expression("{obj1: JSON.stringify($0)}", obj1);

        Console.WriteLine(Verbatim.Expression("JSON.stringify($0)", obj2));
    }
Exemple #2
0
        public void Scale(float x, float y)
        {
            Verbatim.Expression(@"
				var ctxt = $0;
				ctxt.scale($1,$2);
			"            , ctxt, x, y);
        }
Exemple #3
0
        public void LoadImage(string imageUrl, Action <object> loadedCB)
        {
            if (imageCache.ContainsKey(imageUrl))
            {
                object cacheObj = imageCache[imageUrl];
                if (Verbatim.Expression(@"$0.Loaded==true", cacheObj))
                {
                    loadedCB(cacheObj);
                }
                else
                {
                    Verbatim.Expression(@"
						$0.onloadCBList.push($1);
					"                    , cacheObj, loadedCB);
                }
            }
            else
            {
                Verbatim.Expression(@"
					var imageObj = new Image();
					imageObj.Loaded = false;
					imageObj.onloadCBList = [$1];
	                imageObj.onload= function(){
						imageObj.Loaded=true;
	                    imageObj.onloadCBList.forEach(
							function(entry){
								entry(imageObj);
							}
						);
	                };
					CanvasManager_AddToImageCache.call(this,$1,imageObj);
					imageObj.src = $0;
				"                , imageUrl, loadedCB);
            }
        }
Exemple #4
0
        private void SetFilter(string filter)
        {
            // Process the filter list to convert the syntax from C# standard filter syntax to HTML5:
            // Windows application filter syntax: Image Files (*.bmp, *.jpg)|*.bmp;*.jpg|All Files (*.*)|*.*
            // HTML5 filter syntax: .gif, .jpg, .png, .doc
            var fileTypes     = filter.Split('|');
            var htmlFileTypes = new List <string>();

            if (fileTypes.Length == 1)
            {
                htmlFileTypes.Add(fileTypes[0]);
            }
            else
            {
                for (var i = 1; i < fileTypes.Length; i += 2)
                {
                    htmlFileTypes.Add(fileTypes[i]);
                }
            }
            var htmlFilter = string.Join(",", htmlFileTypes).Replace("*", "").Replace(";", ",");

            // Apply the filter:
            if (!string.IsNullOrWhiteSpace(htmlFilter))
            {
                Verbatim.Expression(@"$0.accept = $1", InternalElement.DomObjectHandle, htmlFilter);
            }
            else
            {
                Verbatim.Expression(@"$0.accept = """"", InternalElement.DomObjectHandle);
            }
        }
Exemple #5
0
        public void SetDiv(string divName)
        {
            this.divName = divName;
            Verbatim.Expression(@"
				var c = document.getElementById($1);
				$0 = c.getContext(""2d"");
				// 
				// set up mouse listeners
				var _self = this;
				function MouseMotion(canvas, evt) {
                    var rect = c.getBoundingClientRect();
                    var x = evt.clientX - rect.left;
                    var y = evt.clientY - rect.top;
					CanvasManager_DoMouseMotion.call(_self,$0,x,y);
                }

				function MouseDown(canvas, evt) {
                    var rect = c.getBoundingClientRect();
                    var x = evt.clientX - rect.left;
                    var y = evt.clientY - rect.top;
					CanvasManager_DoMouseDown.call(_self,$0,x,y,evt.button);
                }

				function MouseUp(canvas, evt) {
                    var rect = c.getBoundingClientRect();
                    var x = evt.clientX - rect.left;
                    var y = evt.clientY - rect.top;
					CanvasManager_DoMouseUp.call(_self,$0,x,y,evt.button);
                }

				function MouseWheel(canvas, evt) {
                    var rect = c.getBoundingClientRect();
                    var x = evt.clientX - rect.left;
                    var y = evt.clientY - rect.top;
					CanvasManager_DoMouseWheel.call(_self,$0,x,y,evt.wheelDelta);
                }
      
                c.addEventListener('mousemove', function(evt) {
                    MouseMotion($0, evt);
                }, false);

				c.addEventListener('mousedown', function(evt) {
                    MouseDown($0, evt);
                }, false);

				c.addEventListener('mouseup', function(evt) {
                    MouseUp($0, evt);
                }, false);
				c.addEventListener('mousewheel', function(evt) {
                    MouseWheel($0,evt);
				});
				//just for firefox which doesnt do mousewheel event
				c.addEventListener('DOMMouseScroll', function(evt) {
                    MouseWheel($0,evt);
				});

			"            , ctxt, divName);
            SetFont(fontName);
        }
Exemple #6
0
        public void SetFont(string font)
        {
            fontName = font;
            Verbatim.Expression(@"
				var ctxt = $0;
				ctxt.font = $1;
			"            , ctxt, fontName);
        }
Exemple #7
0
    public static void Main(string[] args)
    {
        Verbatim.Expression("print($0)", "hello");
        var a = 2;
        var b = 5;

        Console.WriteLine(Verbatim.Expression("$0 + $1", a, b));
    }
Exemple #8
0
 private void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
 {
     Verbatim.Expression(@"
         if (args.PropertyName == this._sourceProperty) {
             this._targetHost[this._targetProperty] = this._sourceHost[this._sourceProperty];
         }
     ");
 }
Exemple #9
0
        public void Rotate(float radians)
        {
            Verbatim.Expression(@"
				var ctxt = $0;
				var radians= $1;
				ctxt.rotate(radians);
			"            , ctxt, radians);
        }
Exemple #10
0
        public void Translate(int x, int y)
        {
            Verbatim.Expression(@"
				var ctxt = $0;
				var x= $1;
				var y= $2;
				ctxt.translate(x,y);
			"            , ctxt, x, y);
        }
Exemple #11
0
        private void OnMessageCallback(object e)
        {
            var data = Convert.ToString(Verbatim.Expression("$0.data", e));

            if (OnMessage != null)
            {
                OnMessage(this, new OnMessageEventArgs(data));
            }
        }
Exemple #12
0
 public WebApplication(CSSUITheme theme)
 {
     if (Verbatim.Expression("0") == null)
     {
         throw new RequiresJSILRuntimeException();
     }
     UITheme      = theme;
     CurrentTheme = UITheme;
 }
Exemple #13
0
        public static Element[] GetElementsByTag <T>() where T : Element, new()
        {
            var elementInstance = new T();

            return
                (((object[])
                  Verbatim.Expression(
                      "Array.prototype.slice.call(document.getElementsByTagName(elementInstance.TagName))")).Select(
                     Element.GetElement).ToArray());
        }
Exemple #14
0
    public static void Main(string[] args)
    {
        var arr  = ((object[])Verbatim.Expression("[1,2,3]")) ?? new object[] { 1, 2, 3 };
        var arr2 = (object[])arr.Clone();

        foreach (var item in arr2)
        {
            Console.Write(item);
        }
    }
Exemple #15
0
        internal static Element GetById(string id)
        {
            var element = GetElement(Verbatim.Expression("document.getElementById(id)"));

            if (element == null)
            {
                throw new ArgumentOutOfRangeException("id");
            }
            return(element);
        }
Exemple #16
0
        public Vector2 <float> GetImageSize(object jsImage)
        {
            Vector2 <float> size = new Vector2 <float> ();

            Verbatim.Expression(@"
				$1.X = $0.naturalWidth;
				$1.Y = $0.naturalHeight;
			"            , jsImage, size);
            return(size);
        }
Exemple #17
0
        public void FillText(string txt, int x, int y)
        {
            Verbatim.Expression(@"
				var ctxt = $0;
				var txt= $1;
				var x=$2;
				var y=$3; 
				ctxt.fillText(txt,x,y);
			"            , ctxt, txt, x, y);
        }
Exemple #18
0
        public void LoadTextFile(string fileUrl, Action <string> loadedCB)
        {
            Verbatim.Expression(@"
				var oReq = new XMLHttpRequest();
				oReq.onload = function(){
					$1(oReq.responseText);
				}
				oReq.open(""get"", $0,true);
				oReq.send(null);
			"            , fileUrl, loadedCB);
        }
Exemple #19
0
        public static T CreateFromTemplate <T>(string templateId) where T : Element, new()
        {
            _creatingTemplate = true;
            var element = new T();

            _creatingTemplate      = false;
            element._element       = Verbatim.Expression("document.getElementById(templateId)");
            element._selfReference = element;
            element.TemplateApplied();
            return(element);
        }
Exemple #20
0
 public void RunNextTick()
 {
     IsRunning = InnerLoopTick();
     if (IsRunning)
     {
         Verbatim.Expression("window.requestAnimationFrame($0)", _RunNextTick);
     }
     else
     {
         Exit();
     }
 }
Exemple #21
0
 public static void SaveJSBlobToFile(object javaScriptBlob, string filename)
 {
     if (javaScriptBlob == null)
     {
         throw new ArgumentNullException(nameof(javaScriptBlob));
     }
     if (filename == null)
     {
         throw new ArgumentNullException(nameof(filename));
     }
     Verbatim.Expression(@"saveAs($0, $1)", javaScriptBlob, filename);
 }
Exemple #22
0
        private string[] ParseFont(string fnt)
        {
            string[] results = new String[3];
            Verbatim.Expression(@"
				var matches = /([0-9]+)(pt|px)\s*([a-zA-Z]+)/g.exec($0);
				$1[0] = matches[1];
				$1[1] = matches[2];
				$1[2] = matches[3];
			"            , fnt, results);
            DEBUG("matches = " + results);
            return(results);
        }
Exemple #23
0
        public static void Initialize()
        {
            var jQueryHandle = Verbatim.Expression("jQuery.noConflict()");

            if (jQueryHandle == null)
            {
                throw new InvalidOperationException("Cannot use jQuery with SharpJS if the jQuery library has not been loaded.");
            }
            //JQuery successfully initialized
            IsInitialized = true;
            _jq           = jQueryHandle;
        }
Exemple #24
0
 public static void Print(Element elementToPrint)
 {
     Verbatim.Expression(@"
             var printPreview = window.open('about:blank', 'print_preview', 'resizable=yes,scrollbars=yes,status=yes');
             var printDocument = printPreview.document;
             printDocument.open();
             printDocument.write('<!DOCTYPE html>'+
             '<html>'+
                 $0.innerHTML+
             '</html>');
             printDocument.close();
             printPreview.print();", elementToPrint.InnerHtml);
 }
Exemple #25
0
        public StorageBase(WebStorageType storageType)
        {
            switch (storageType)
            {
            case WebStorageType.LocalStorage:
                _storageHandle = Verbatim.Expression("window.localStorage");
                break;

            case WebStorageType.SessionStorage:
                _storageHandle = Verbatim.Expression("window.sessionStorage");
                break;
            }
        }
Exemple #26
0
        public static void StartApplication(NKApplication app, string targetElementSelector)
        {
            //Verify that we are running on JSIL
            if (Verbatim.Expression("0") == null)
            {
                throw new RequiresJSILRuntimeException();
            }
            //TODO: Initialize DOM host object with jQuery
            var targetElement = new JQElement(JQuery.FromSelector(targetElementSelector).DomElement);

            app.HostElement = targetElement;
            app.Create();
        }
Exemple #27
0
    public static void Main()
    {
        object instance = null;

        if (Builtins.IsJavascript)
        {
            instance = Verbatim.Expression("JSIL.CreateInstanceOfType(TestClass.__Type__)");
        }
        else
        {
            instance = new TestClass();
        }
        Console.WriteLine(instance);
    }
Exemple #28
0
        internal static Element GetElement(object handle)
        {
            if (handle == null)
            {
                return(null);
            }

            var element = Verbatim.Expression("handle._selfReference");

            if (element == null || element == Verbatim.Expression("undefined"))
            {
                return(new Element(handle));
            }
            return((Element)element);
        }
Exemple #29
0
        internal static T GetElement <T>(object handle) where T : Element, new()
        {
            if (handle == null)
            {
                return(null);
            }

            var element = Verbatim.Expression("handle._selfReference");

            if (element == null || element == Verbatim.Expression("undefined"))
            {
                return((T)Activator.CreateInstance(typeof(T), handle)); // equivalent to: new T(handle);
            }
            return((T)element);
        }
Exemple #30
0
 public static void SaveTextToFile(string text, string fileName)
 {
     if (text == null)
     {
         throw new ArgumentNullException(nameof(text));
     }
     if (fileName == null)
     {
         throw new ArgumentNullException(nameof(fileName));
     }
     Verbatim.Expression(@"
         var blob = new Blob([$0], { type: ""text/plain;charset=utf-8""});
         saveAs(blob, $1)
     ", text, fileName);
 }