示例#1
0
        private void Button_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var sf = $"{{\"id\": \"{_id}\", \"event\": \"mouseDown\"}}";

            FreSharpHelper.DispatchEvent(ref _ctx, AsCallbackEvent, sf);
            Source = _downState;
        }
示例#2
0
        private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            var sf = $"{{\"id\": \"{_id}\", \"event\": \"mouseOut\"}}";

            FreSharpHelper.DispatchEvent(ref _ctx, AsCallbackEvent, sf);
            Source = _upState;
            Cursor = Cursors.Arrow;
        }
示例#3
0
        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            var sf = $"{{\"id\": \"{_id}\", \"event\": \"mouseOver\"}}";

            FreSharpHelper.DispatchEvent(ref _ctx, AsCallbackEvent, sf);
            Source = _overState;
            Cursor = Cursors.Hand;
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="argc"></param>
        /// <param name="argv"></param>
        /// <returns></returns>
        public static FREObject Init(FREContext ctx, uint argc, FREObject[] argv)
        {
            var inFre0 = argv[0];
            var inFre1 = argv[1];
            var inFre2 = argv[2];
            var inFre3 = argv[3];

            if (inFre0 == FREObject.Zero)
            {
                return(FREObject.Zero);
            }
            if (inFre1 == FREObject.Zero)
            {
                return(FREObject.Zero);
            }
            if (inFre2 == FREObject.Zero)
            {
                return(FREObject.Zero);
            }
            if (inFre3 == FREObject.Zero)
            {
                return(FREObject.Zero);
            }

            var rgb = FreSharpHelper.GetAsUInt(new FreObjectSharp(inFre3).RawValue);

            BackgroundColor = Color.FromRgb(
                Convert.ToByte((rgb >> 16) & 0xff),
                Convert.ToByte((rgb >> 8) & 0xff),
                Convert.ToByte((rgb >> 0) & 0xff));

            _viewPort   = new FreRectangleSharp(inFre0).Value;
            _visible    = Convert.ToBoolean(new FreObjectSharp(inFre1).Value);
            Transparent = Convert.ToBoolean(new FreObjectSharp(inFre2).Value);
            _airWindow  =
                System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; //get the reference to the AIR Window

            _parameters = new HwndSourceParameters();
            _parameters.SetPosition(Convert.ToInt32(_viewPort.X), Convert.ToInt32(_viewPort.Y));
            _parameters.SetSize(Convert.ToInt32(_viewPort.Width), Convert.ToInt32(_viewPort.Height));
            _parameters.ParentWindow = _airWindow;
            _parameters.WindowName   = "AIRNativeStageWindow";
            _parameters.WindowStyle  = _visible
                ? (int)(WindowStyles.WS_CHILD | WindowStyles.WS_VISIBLE)
                : (int)WindowStyles.WS_CHILD;

            if (Transparent && WinApi.GetOsVersion().Item1 > 7)
            {
                _parameters.ExtendedWindowStyle      = (int)WindowExStyles.WS_EX_LAYERED;
                _parameters.UsesPerPixelTransparency = true;
            }

            _parameters.AcquireHwndFocusInMenuMode = false;
            return(FREObject.Zero);
        }
示例#5
0
        /// <inheritdoc />
        /// <summary></summary>
        /// <param name="value"></param>
        public FrePointSharp(Point value)
        {
            uint resultPtr = 0;
            var  args      = new ArrayList {
                value.X,
                value.Y
            };

            RawValue = FreSharpHelper.Core.getFREObject("flash.geom.Point", FreSharpHelper.ArgsToArgv(args),
                                                        FreSharpHelper.GetArgsC(args), ref resultPtr);
            var status = (FreResultSharp)resultPtr;

            if (status == FreResultSharp.Ok)
            {
                return;
            }
            FreSharpHelper.ThrowFreException(status, "cannot create point ", RawValue);
        }
示例#6
0
        public FREObject Upload(FREContext ctx, uint argc, FREObject[] argv)
        {
            if (_uploadInProgress == false)
            {
                try {
                    if (_clientInitialized == false)
                    {
                        FreSharpHelper.ThrowFreException(FreResultSharp.FreActionscriptError, "[ERROR] AWS Client has not been initilized properly.", FREObject.Zero);
                    }
                }
                catch (Exception ex) {
                    return(new FreException(ex).RawValue);
                }

                UploadObject();
            }
            return(FREObject.Zero);
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourcePoint"></param>
        public void CopyFrom(FrePointSharp sourcePoint)
        {
            uint resultPtr = 0;
            var  args      = new ArrayList {
                sourcePoint.RawValue,
            };

            FreSharpHelper.Core.callMethod(RawValue, "copyFrom", FreSharpHelper.ArgsToArgv(args),
                                           FreSharpHelper.GetArgsC(args), ref resultPtr);


            var status = (FreResultSharp)resultPtr;

            if (status == FreResultSharp.Ok)
            {
                return;
            }
            FreSharpHelper.ThrowFreException(status, "cannot copyFrom ", FREObject.Zero);
        }
示例#8
0
        public FREObject InitView(FREContext ctx, uint argc, FREObject[] argv)
        {
            _airWindow = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            if (_airWindow == Hwnd.Zero)
            {
                var e = new Exception(
                    "Cannot find AIR window to attach webView to. Ensure you init the ANE AFTER your main Sprite is initialised. " +
                    "Please see https://forum.starling-framework.org/topic/webviewane-for-osx/page/7?replies=201#post-105524 for more details");
                return(new FreException(e).RawValue);
            }

            try {
                var inFre1         = new FreRectangleSharp(argv[1]); //viewport
                var inFre2         = new FreObjectSharp(argv[2]);    //settings
                var inFre4         = new FreObjectSharp(argv[4]);    //backgroundColor
                var cefSettingsFre = inFre2.GetProperty("cef");

                var googleApiKeyFre              = cefSettingsFre.GetProperty("GOOGLE_API_KEY");
                var googleDefaultClientIdFre     = cefSettingsFre.GetProperty("GOOGLE_DEFAULT_CLIENT_ID");
                var googleDefaultClientSecretFre = cefSettingsFre.GetProperty("GOOGLE_DEFAULT_CLIENT_SECRET");

                if (FreObjectTypeSharp.String == googleApiKeyFre.GetType())
                {
                    Environment.SetEnvironmentVariable("GOOGLE_API_KEY", Convert.ToString(googleApiKeyFre.Value));
                }
                if (FreObjectTypeSharp.String == googleDefaultClientIdFre.GetType())
                {
                    Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID",
                                                       Convert.ToString(googleDefaultClientIdFre.Value));
                }
                if (FreObjectTypeSharp.String == googleDefaultClientSecretFre.GetType())
                {
                    Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET",
                                                       Convert.ToString(googleDefaultClientSecretFre.Value));
                }

                var clArr    = new FreArraySharp(cefSettingsFre.GetProperty("commandLineArgs").RawValue);
                var argsDict = new Dictionary <string, string>();

                uint i;
                for (i = 0; i < clArr.Length; ++i)
                {
                    var argFre = clArr.GetObjectAt(i);
                    var key    = Convert.ToString(argFre.GetProperty("key").Value);
                    var val    = Convert.ToString(argFre.GetProperty("value").Value);
                    if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(val))
                    {
                        continue;
                    }
                    argsDict.Add(key, val);
                }

                var whiteList = new FreArraySharp(inFre2.GetProperty("urlWhiteList").RawValue).GetAsArrayList();
                var blackList = new FreArraySharp(inFre2.GetProperty("urlBlackList").RawValue).GetAsArrayList();

                var rgb = FreSharpHelper.GetAsUInt(inFre4.RawValue);
                _backgroundColor = Color.FromRgb(
                    Convert.ToByte((rgb >> 16) & 0xff),
                    Convert.ToByte((rgb >> 8) & 0xff),
                    Convert.ToByte((rgb >> 0) & 0xff));

                var viewPort = inFre1.Value;
                _view = new CefView {
                    InitialUrl            = Convert.ToString(new FreObjectSharp(argv[0]).Value),
                    Background            = new SolidColorBrush(_backgroundColor),
                    X                     = Convert.ToInt32(viewPort.X),
                    Y                     = Convert.ToInt32(viewPort.Y),
                    ViewWidth             = Convert.ToInt32(viewPort.Width),
                    ViewHeight            = Convert.ToInt32(viewPort.Height),
                    RemoteDebuggingPort   = Convert.ToInt32(cefSettingsFre.GetProperty("remoteDebuggingPort").Value),
                    CachePath             = Convert.ToString(cefSettingsFre.GetProperty("cachePath").Value),
                    CacheEnabled          = Convert.ToBoolean(inFre2.GetProperty("cacheEnabled").Value),
                    LogLevel              = Convert.ToInt32(cefSettingsFre.GetProperty("logSeverity").Value),
                    BrowserSubprocessPath = Convert.ToString(cefSettingsFre.GetProperty("browserSubprocessPath").Value),
                    ContextMenuEnabled    = Convert.ToBoolean(cefSettingsFre.GetProperty("contextMenu")
                                                              .GetProperty("enabled")
                                                              .Value),
                    EnableDownloads = Convert.ToBoolean(cefSettingsFre.GetProperty("enableDownloads").Value),
                    UserAgent       = Convert.ToString(inFre2.GetProperty("userAgent").Value),
                    CommandLineArgs = argsDict,
                    WhiteList       = whiteList,
                    BlackList       = blackList,
                    PopupBehaviour  = (PopupBehaviour)inFre2.GetProperty("popup").GetProperty("behaviour").Value,
                    PopupDimensions = new Tuple <int, int>(
                        Convert.ToInt32(
                            inFre2.GetProperty("popup").GetProperty("dimensions").GetProperty("width").Value),
                        Convert.ToInt32(inFre2.GetProperty("popup").GetProperty("dimensions").GetProperty("height")
                                        .Value)
                        )
                };

                _view.Init();
            }
            catch (Exception e) {
                return(new FreException(e).RawValue); //return as3 error and throw in swc
            }

            var parameters = new HwndSourceParameters();

            parameters.SetPosition(_view.X, _view.Y);
            parameters.SetSize(_view.ViewWidth, _view.ViewHeight);
            parameters.ParentWindow = _airWindow;
            parameters.WindowName   = "Cef Window";
            parameters.WindowStyle  = (int)WindowStyles.WS_CHILD;
            parameters.AcquireHwndFocusInMenuMode = true;
            var source = new HwndSource(parameters)
            {
                RootVisual = _view
            };

            _cefWindow = source.Handle;

            WinApi.RegisterTouchWindow(_cefWindow, TouchWindowFlags.TWF_WANTPALM);

            return(FREObject.Zero);
        }