示例#1
0
        private FREObject RunArrayTests(FREContext ctx, uint argc, FREObject[] argv)
        {
            Trace("***********Start Array test***********");
            if (argc < 4)
            {
                return(new FreException("Not enough args").RawValue);
            }

            var airArray = new FREArray(argv[0]);
            var inFre1   = new FREArray(argv[1]);
            var inFre2   = new FREArray(argv[2]);
            var inFre3   = new FREArray(argv[3]);

            var airArrayList = airArray.AsArrayList();

            Trace("Convert FREArray to ArrayList :", airArrayList.Count, airArray.Length.Equals(6) ? "✅" : "❌");

            airArray.Push(77.ToFREObject(), 88);
            Trace("Get FREArray length after 2 appends:", airArray.Length, airArray.Length.Equals(8) ? "✅" : "❌");

            airArray[0] = 123.ToFREObject();
            foreach (var fre in airArray)
            {
                Trace("iterate over FREArray", fre.AsInt());
            }

            var airVectorString  = inFre1.AsStringArray();
            var airVectorNumber  = inFre2.AsDoubleArray();
            var airVectorBoolean = inFre3.AsBoolArray();

            Trace("Vector.<String> passed from AIR :",
                  string.Join(",", airVectorString.ToArray()),
                  string.Join(",", airVectorString.ToArray()).Equals("a,b,c,d") ? "✅" : "❌");

            Trace("Vector.<Number> passed from AIR :",
                  string.Join(",", airVectorNumber.ToArray()),
                  string.Join(",", airVectorNumber.ToArray()).Equals("1,0.5,2,3.3") ? "✅" : "❌");

            Trace("Vector.<Boolean> passed from AIR :",
                  string.Join(",", airVectorBoolean.ToArray()),
                  string.Join(",", airVectorBoolean.ToArray()).Equals("True,True,False,True") ? "✅" : "❌");

            var newFreArray = new FREArray("Object", 5, true);

            Trace("New FREArray of fixed length :", newFreArray.Length, newFreArray.Length.Equals(5) ? "✅" : "❌");

            airArray.Set(0, 56);
            var itemZero = airArray[0].AsInt();

            Trace("Set item 0 of FREArray:", itemZero, itemZero.Equals(56) ? "✅" : "❌");

            var marks = new[] { 99, 98, 92, 97, 95 };

            return(marks.ToFREObject());
        }
示例#2
0
        private FREObject GetDisplayDevices(FREContext ctx, uint argc, FREObject[] argv)
        {
            var vecDisplayDevices = new FREArray("com.tuarua.DisplayDevice");

            var dd = new DisplayDevice();

            dd.cb = Marshal.SizeOf(dd);

            _displayDeviceMap.Clear();

            try {
                uint index = 0;
                while (WinApi.EnumDisplayDevices(null, index++, ref dd, 0))
                {
                    dynamic displayDevice  = new FreObjectSharp("com.tuarua.DisplayDevice");
                    dynamic displayMonitor = new FreObjectSharp("com.tuarua.Monitor");

                    displayDevice.isPrimary       = dd.StateFlags.HasFlag(DisplayDeviceStateFlags.PrimaryDevice);
                    displayDevice.isActive        = dd.StateFlags.HasFlag(DisplayDeviceStateFlags.AttachedToDesktop);
                    displayDevice.isRemovable     = dd.StateFlags.HasFlag(DisplayDeviceStateFlags.Removable);
                    displayDevice.isVgaCampatible = dd.StateFlags.HasFlag(DisplayDeviceStateFlags.VgaCompatible);

                    var monitor = new DisplayDevice();
                    monitor.cb = Marshal.SizeOf(monitor);

                    if (!WinApi.EnumDisplayDevices(dd.DeviceName, index - 1, ref monitor, 0))
                    {
                        continue;
                    }

                    var dm = new Devmode();
                    dm.dmSize = (short)Marshal.SizeOf(dm);
                    if (WinApi.EnumDisplaySettings(dd.DeviceName, WinApi.EnumCurrentSettings, ref dm) == 0)
                    {
                        continue;
                    }

                    var availdm = new Devmode();
                    availdm.dmSize = (short)Marshal.SizeOf(availdm);
                    IList <DisplaySettings> availableDisplaySettings = new List <DisplaySettings>();

                    var freAvailableDisplaySettings = displayDevice.availableDisplaySettings;
                    for (var iModeNum = 0;
                         WinApi.EnumDisplaySettings(dd.DeviceName, iModeNum, ref availdm) != 0;
                         iModeNum++)
                    {
                        var settings = new DisplaySettings {
                            Width       = availdm.dmPelsWidth,
                            Height      = availdm.dmPelsHeight,
                            BitDepth    = Convert.ToInt32(availdm.dmBitsPerPel),
                            RefreshRate = availdm.dmDisplayFrequency
                        };

                        if (HasDisplaySetting(availableDisplaySettings, settings))
                        {
                            continue;
                        }
                        availableDisplaySettings.Add(settings);

                        dynamic displaySettings = new FreObjectSharp("com.tuarua.DisplaySettings");
                        displaySettings.width       = availdm.dmPelsWidth;
                        displaySettings.height      = availdm.dmPelsHeight;
                        displaySettings.refreshRate = availdm.dmDisplayFrequency;
                        displaySettings.bitDepth    = Convert.ToInt32(availdm.dmBitsPerPel);
                        freAvailableDisplaySettings.Push(displaySettings);
                    }

                    displayMonitor.friendlyName = monitor.DeviceString;
                    displayMonitor.name         = monitor.DeviceName;
                    displayMonitor.id           = monitor.DeviceID;
                    displayMonitor.key          = monitor.DeviceKey;

                    displayDevice.friendlyName = dd.DeviceString;
                    displayDevice.name         = dd.DeviceName;
                    displayDevice.id           = dd.DeviceID;
                    displayDevice.key          = dd.DeviceKey;

                    dynamic currentDisplaySettings = new FreObjectSharp("com.tuarua.DisplaySettings");
                    currentDisplaySettings.width       = dm.dmPelsWidth;
                    currentDisplaySettings.height      = dm.dmPelsHeight;
                    currentDisplaySettings.refreshRate = dm.dmDisplayFrequency;
                    currentDisplaySettings.bitDepth    = Convert.ToInt32(dm.dmBitsPerPel);

                    displayDevice.currentDisplaySettings = currentDisplaySettings;
                    displayDevice.monitor = displayMonitor;
                    vecDisplayDevices.Push(displayDevice);

                    _displayDeviceMap.Add(dd.DeviceKey, dd);
                }
            }
            catch (Exception e) {
                Trace(e.Message);
                Trace(e.Source);
                Trace(e.StackTrace);
            }

            return(vecDisplayDevices.RawValue);
        }