public FreNativeSprite(FreObjectSharp freObjectSharp)
        {
            HorizontalAlignment = HorizontalAlignment.Left;
            VerticalAlignment   = VerticalAlignment.Top;

            X          = Convert.ToDouble(freObjectSharp.GetProperty("x").Value);
            Y          = Convert.ToDouble(freObjectSharp.GetProperty("y").Value);
            Visibility = Convert.ToBoolean(freObjectSharp.GetProperty("visible").Value)
                ? Visibility.Visible
                : Visibility.Hidden;
            RenderTransform = new TranslateTransform(X, Y);
            Opacity         = Convert.ToDouble(freObjectSharp.GetProperty("alpha").Value);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="argc"></param>
        /// <param name="argv"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static FREObject AddChild(FREContext ctx, uint argc, FREObject[] argv)
        {
            var inFre0 = argv[0];

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

            var inFre1 = argv[1];

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

            var parentId = new FreObjectSharp(inFre0).Value as string;
            var child    = new FreObjectSharp(inFre1);
            var id       = Convert.ToString(child.GetProperty("id").Value);
            var type     = (FreStageSharp.FreNativeType)Convert.ToInt32(child.GetProperty("type").Value);

            switch (type)
            {
            case FreStageSharp.FreNativeType.Image:
                var nativeImage = new FreNativeImage(child);
                AddToParent(parentId, nativeImage);
                Children.Add(id, new Tuple <string, object>(parentId, nativeImage));
                break;

            case FreStageSharp.FreNativeType.Button:
                var nativeButton = new FreNativeButton(child, id, ref ctx);
                AddToParent(parentId, nativeButton);
                Children.Add(id, new Tuple <string, object>(parentId, nativeButton));
                break;

            case FreStageSharp.FreNativeType.Sprite:
                var nativeSprite = new FreNativeSprite(child);
                AddToParent(parentId, nativeSprite);
                Children.Add(id, new Tuple <string, object>(parentId, nativeSprite));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            return(FREObject.Zero);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="freObjectSharp"></param>
        /// <param name="id"></param>
        /// <param name="ctx"></param>
        public FreNativeButton(FreObjectSharp freObjectSharp, string id, ref FREContext ctx)
        {
            _ctx     = ctx;
            _upState = BitmapUtils.BitmapToSource(
                new FreBitmapDataSharp(freObjectSharp.GetProperty("upStateData").RawValue).GetAsBitmap());
            _overState =
                BitmapUtils.BitmapToSource(new FreBitmapDataSharp(freObjectSharp.GetProperty("overStateData").RawValue)
                                           .GetAsBitmap());
            _downState =
                BitmapUtils.BitmapToSource(new FreBitmapDataSharp(freObjectSharp.GetProperty("downStateData").RawValue)
                                           .GetAsBitmap());
            _id = id;

            Width  = _upState.Width;
            Height = _upState.Height;
            HorizontalAlignment = HorizontalAlignment.Left;
            VerticalAlignment   = VerticalAlignment.Top;
            Source      = _upState;
            MouseEnter += Button_MouseEnter;
            MouseLeave += Button_MouseLeave;
            MouseDown  += Button_MouseDown;
            MouseUp    += Button_MouseUp;

            X          = Convert.ToDouble(freObjectSharp.GetProperty("x").Value);
            Y          = Convert.ToDouble(freObjectSharp.GetProperty("y").Value);
            Visibility = Convert.ToBoolean(freObjectSharp.GetProperty("visible").Value)
                ? Visibility.Visible
                : Visibility.Hidden;
            RenderTransform = new TranslateTransform(X, Y);
            Opacity         = Convert.ToDouble(freObjectSharp.GetProperty("alpha").Value);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="freObjectSharp"></param>
        public FreNativeImage(FreObjectSharp freObjectSharp)
        {
            var bitmap = new FreBitmapDataSharp(freObjectSharp.GetProperty("bitmapData").RawValue).GetAsBitmap();

            Width  = bitmap.Width;
            Height = bitmap.Height;
            HorizontalAlignment = HorizontalAlignment.Left;
            VerticalAlignment   = VerticalAlignment.Top;
            Source = BitmapUtils.BitmapToSource(bitmap);

            X          = Convert.ToDouble(freObjectSharp.GetProperty("x").Value);
            Y          = Convert.ToDouble(freObjectSharp.GetProperty("y").Value);
            Visibility = Convert.ToBoolean(freObjectSharp.GetProperty("visible").Value)
                ? Visibility.Visible
                : Visibility.Hidden;
            RenderTransform = new TranslateTransform(X, Y);
            Opacity         = Convert.ToDouble(freObjectSharp.GetProperty("alpha").Value);
        }
Beispiel #5
0
        public FREObject InitView(FREContext ctx, uint argc, FREObject[] argv)
        {
            _airWindow = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            var inFre5         = new FreObjectSharp(argv[5]); //settings
            var cefSettingsFre = inFre5.GetProperty("cef");

            //Trace("initing view and here is a trace");

            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(inFre5.GetProperty("urlWhiteList").RawValue).GetAsArrayList();

            _view = new CefView {
                InitialUrl            = Convert.ToString(new FreObjectSharp(argv[0]).Value),
                Background            = _backgroundColorBrush,
                X                     = Convert.ToInt32(new FreObjectSharp(argv[1]).Value),
                Y                     = Convert.ToInt32(new FreObjectSharp(argv[2]).Value),
                ViewWidth             = Convert.ToInt32(new FreObjectSharp(argv[3]).Value),
                ViewHeight            = Convert.ToInt32(new FreObjectSharp(argv[4]).Value),
                RemoteDebuggingPort   = Convert.ToInt32(cefSettingsFre.GetProperty("remoteDebuggingPort").Value),
                CachePath             = Convert.ToString(cefSettingsFre.GetProperty("cachePath").Value),
                LogLevel              = Convert.ToInt32(cefSettingsFre.GetProperty("logSeverity").Value),
                BrowserSubprocessPath = Convert.ToString(cefSettingsFre.GetProperty("browserSubprocessPath").Value),
                EnableDownloads       = Convert.ToBoolean(cefSettingsFre.GetProperty("enableDownloads").Value),
                UserAgent             = Convert.ToString(inFre5.GetProperty("userAgent").Value),
                CommandLineArgs       = argsDict,
                WhiteList             = whiteList,
                PopupBehaviour        = (PopupBehaviour)inFre5.GetProperty("popup").GetProperty("behaviour").Value,
                PopupDimensions       = new Tuple <int, int>(
                    Convert.ToInt32(inFre5.GetProperty("popup").GetProperty("dimensions").GetProperty("width").Value),
                    Convert.ToInt32(inFre5.GetProperty("popup").GetProperty("dimensions").GetProperty("height").Value)
                    )
            };



            _view.Init();

            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);
        }
Beispiel #6
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);
        }