Beispiel #1
0
        public bool SendNotification(string text, string bitmapKey = null, int displayForMs = 2000)
        {
            NotificationBitmap_t bmp = new NotificationBitmap_t();

            if (bitmapKey != null)
            {
                if (!_icons.ContainsKey(bitmapKey))
                {
                    throw new Exception("Invalid Bitmap Key");
                }

                bmp.m_nBytesPerPixel = 4;
                bmp.m_nHeight        = _icons[bitmapKey].Bitmap.Height;
                bmp.m_nWidth         = _icons[bitmapKey].Bitmap.Width;
                bmp.m_pImageData     = (IntPtr)(_icons[bitmapKey].glTextureId);
            }

            uint notId = 0;
            EVRNotificationError err = EVRNotificationError.OK;

            err = OpenVR.Notifications.CreateNotification(_overlay.Handle, 0, EVRNotificationType.Transient, text, EVRNotificationStyle.Application, ref bmp, ref notId);

            if (err != EVRNotificationError.OK)
            {
                NexHudEngine.Log("Notification Failure: " + err.ToString());
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public void ShowNotification(string message)
        {
            OpenVR.Notifications.RemoveNotification(currentNotificationId);



            //overlayInstance.showMessage(message);
            uint ID = GetRandomID();

            /// https://github.com/ValveSoftware/openvr/issues/1133#issuecomment-460575906
            // TODO: allow for custom images (e.g. emojis) specified in mobile app
            var image  = new NotificationBitmap_t();
            var bitmap = new Bitmap("Resources/vrknock-x512.png");

            System.Drawing.Imaging.BitmapData TextureData =
                bitmap.LockBits(
                    new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppArgb
                    );

            image.m_pImageData     = TextureData.Scan0;
            image.m_nWidth         = TextureData.Width;
            image.m_nHeight        = TextureData.Height;
            image.m_nBytesPerPixel = 4;

            OpenVR.Notifications.CreateNotification(notificationHandle, 0, EVRNotificationType.Transient, message,
                                                    EVRNotificationStyle.None, ref image, ref ID);
            currentNotificationId = ID;

            //Unlocks Image Data
            bitmap.UnlockBits(TextureData);

            OpenVR.Overlay.ShowOverlay(notificationHandle);
        }
Beispiel #3
0
        static void Main()
        {
#if DEBUG
            AllocConsole();
#endif

            var e = EVRInitError.None;
            OpenVR.Init(ref e, EVRApplicationType.VRApplication_Overlay);

            ulong handle = 0;
            var   error  = OpenVR.Overlay.CreateOverlay("pushbullet", "Pushbullet", ref handle);
            Console.WriteLine($"CreateOverlay Result: {error.ToString()}");

            var conf   = Common.Config.Read();
            var stream = new PushbulletStream(conf.PushbulletToken);

            stream.MessageReceived += (sender, push) =>
            {
                OpenVR.Overlay.SetOverlayName(handle, $"Pushbullet - {push.ApplicationName}");

                uint id = 0;

                var notifIcon = new NotificationBitmap_t();

                var bmp = push.IconAsBitmap();
                Utils.FixBitmapForOpenVR(ref bmp);
                var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                notifIcon.m_pImageData     = bmpData.Scan0;
                notifIcon.m_nWidth         = bmpData.Width;
                notifIcon.m_nHeight        = bmpData.Height;
                notifIcon.m_nBytesPerPixel = 4;

                var notifError = OpenVR.Notifications.CreateNotification(handle, 0, EVRNotificationType.Transient, $"{push.Title.Replace("\n", " / ")}\n{push.Body.Replace("\n", " / ")}", EVRNotificationStyle.Application, ref notifIcon, ref id);
                Console.WriteLine($"CreateNotification Result: {notifError.ToString()}");
                Console.WriteLine($"Received mirror push: [{push.ApplicationName}] {push.Title}: {push.Body}");

                bmp.UnlockBits(bmpData);
            };

            stream.Start();

            var res = new ManualResetEvent(false);

            VREvent_t ev   = new VREvent_t();
            var       size = (uint)Marshal.SizeOf(typeof(VREvent_t));
            while (OpenVR.Overlay.PollNextOverlayEvent(handle, ref ev, size))
            {
                if (ev.eventType == (uint)EVREventType.VREvent_Quit)
                {
                    Console.WriteLine("SteamVR is quitting, shutting down...");
                    OpenVR.Shutdown();
                    res.Set();
                    Environment.Exit(0);
                }
            }

            res.WaitOne();
        }
Beispiel #4
0
        public void ShowNotification(string p_message)
        {
            uint l_notification           = 0;
            NotificationBitmap_t l_bitmap = new NotificationBitmap_t();

            l_bitmap.m_pImageData     = (IntPtr)0;
            l_bitmap.m_nHeight        = 0;
            l_bitmap.m_nWidth         = 0;
            l_bitmap.m_nBytesPerPixel = 0;
            OpenVR.Notifications.CreateNotification(m_notificationOverlay, 500, EVRNotificationType.Transient, p_message, EVRNotificationStyle.None, ref l_bitmap, ref l_notification);
        }
        private void PostNotification(WebSocketSession session, Payload payload)
        {
            // Overlay
            Session.OverlayHandles.TryGetValue(session, out ulong overlayHandle);
            if (overlayHandle == 0L)
            {
                if (Session.OverlayHandles.Count >= 32)
                {
                    Session.OverlayHandles.Clear();                                     // Max 32, restart!
                }
                overlayHandle = _vr.InitNotificationOverlay(payload.basicTitle);
                Session.OverlayHandles.TryAdd(session, overlayHandle);
            }

            // Image
            Debug.WriteLine($"Overlay handle {overlayHandle} for '{payload.basicTitle}'");
            Debug.WriteLine($"Image Hash: {CreateMD5(payload.imageData)}");
            NotificationBitmap_t bitmap = new NotificationBitmap_t();

            try
            {
                Bitmap bmp = null;
                if (payload.imageData?.Length > 0)
                {
                    var imageBytes = Convert.FromBase64String(payload.imageData);
                    bmp = new Bitmap(new MemoryStream(imageBytes));
                }
                else if (payload.imagePath.Length > 0)
                {
                    bmp = new Bitmap(payload.imagePath);
                }
                if (bmp != null)
                {
                    Debug.WriteLine($"Bitmap size: {bmp.Size.ToString()}");
                    bitmap = BitmapUtils.NotificationBitmapFromBitmap(bmp, true);
                    bmp.Dispose();
                }
            }
            catch (Exception e)
            {
                var message = $"Image Read Failure: {e.Message}";
                Debug.WriteLine(message);
                _server.SendMessage(session, JsonConvert.SerializeObject(new Response(payload.customProperties.nonce, "Error", message)));
            }
            // Broadcast
            if (overlayHandle != 0)
            {
                GC.KeepAlive(bitmap);
                _vr.EnqueueNotification(overlayHandle, payload.basicMessage, bitmap);
            }
        }
        private void PostNotification(WebSocketSession session, Payload payload)
        {
            // Overlay
            _overlayHandles.TryGetValue(session, out ulong overlayHandle);
            if (overlayHandle == 0L)
            {
                if (_overlayHandles.Count >= 32)
                {
                    _overlayHandles.Clear();                              // Max 32, restart!
                }
                overlayHandle = _vr.InitNotificationOverlay(payload.title);
                _overlayHandles.TryAdd(session, overlayHandle);
            }
            // images.TryGetValue(session, out byte[] imageBytes);

            // Image
            Debug.WriteLine($"Overlay handle {overlayHandle} for '{payload.title}'");
            Debug.WriteLine($"Image: {payload.image}");
            NotificationBitmap_t bitmap = new NotificationBitmap_t();

            try
            {
                var imageBytes = Convert.FromBase64String(payload.image);
                var bmp        = new Bitmap(new MemoryStream(imageBytes));
                Debug.WriteLine($"Bitmap size: {bmp.Size.ToString()}");
                bitmap = BitmapUtils.NotificationBitmapFromBitmap(bmp, true);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Reading image failed: {e.Message}");
            }
            // Broadcast
            if (overlayHandle != 0)
            {
                GC.KeepAlive(bitmap);
                _vr.EnqueueNotification(overlayHandle, payload.message, bitmap);
            }
        }
        static void Main(string[] args)
        {
            // Initializing connection to OpenVR
            var error = EVRInitError.None;

            OpenVR.Init(ref error, EVRApplicationType.VRApplication_Background);
            if (error != EVRInitError.None)
            {
                Utils.PrintError($"OpenVR initialization errored: {Enum.GetName(typeof(EVRInitError), error)}");
            }
            else
            {
                Utils.PrintInfo("OpenVR initialized successfully.");

                // Initializing notification overlay
                ulong handle       = 0;
                var   overlayError = OpenVR.Overlay.CreateOverlay(Guid.NewGuid().ToString(), "Test Overlay", ref handle);
                if (overlayError == EVROverlayError.None)
                {
                    Utils.PrintInfo("Successfully initiated notification overlay.");
                }
                else
                {
                    Utils.PrintError("Failed to initialize notification overlay.");
                }

                // Loading bitmap from disk
                var    currentDir = Directory.GetCurrentDirectory();
                var    path       = $"{currentDir}\\boll_alpha.png";
                Bitmap bitmap     = null;
                try
                {
                    bitmap = new Bitmap(path);
                    Utils.PrintInfo("Successfully loaded image from disk.");
                } catch (FileNotFoundException e)
                {
                    Utils.PrintError($"Failed to load image from disk: {e.Message}");
                }

                // Flip R & B channels in bitmap so it displays correctly
                int bytesPerPixel = Bitmap.GetPixelFormatSize(bitmap.PixelFormat) / 8;
                Utils.PrintDebug($"Pixel format of input bitmap: {bitmap.PixelFormat}");
                BitmapData data = bitmap.LockBits(
                    new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    ImageLockMode.ReadWrite,
                    bitmap.PixelFormat
                    );
                int length = Math.Abs(data.Stride) * bitmap.Height;
                unsafe
                {
                    byte *rgbValues = (byte *)data.Scan0.ToPointer();
                    for (int i = 0; i < length; i += bytesPerPixel)
                    {
                        byte dummy = rgbValues[i];
                        rgbValues[i]     = rgbValues[i + 2];
                        rgbValues[i + 2] = dummy;
                    }
                }
                bitmap.UnlockBits(data);

                // Preparing notification bitmap
                BitmapData bitmapData = bitmap.LockBits(
                    new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    ImageLockMode.ReadOnly,
                    PixelFormat.Format32bppArgb // Alawys the same format here.
                    );
                NotificationBitmap_t notificationBitmap = new NotificationBitmap_t
                {
                    m_pImageData     = bitmapData.Scan0,
                    m_nWidth         = bitmapData.Width,
                    m_nHeight        = bitmapData.Height,
                    m_nBytesPerPixel = 4
                };

                // Creating notification
                var rnd = new Random();
                var id  = (uint)rnd.Next();
                var notificationError = OpenVR.Notifications.CreateNotification(handle, 0, EVRNotificationType.Transient, "This is a test.", EVRNotificationStyle.Application, ref notificationBitmap, ref id);
                if (notificationError == EVRNotificationError.OK)
                {
                    Utils.PrintInfo("Notification was displayed successfully.");
                }
                else
                {
                    Utils.PrintError($"Error creating notification: {Enum.GetName(typeof(EVRNotificationError), notificationError)}");
                }

                bitmap.UnlockBits(bitmapData);
            }
            Console.ReadLine();
            OpenVR.Shutdown();
        }
Beispiel #8
0
 public abstract EVRNotificationError CreateNotification(ulong ulOverlayHandle,ulong ulUserValue,EVRNotificationType type,string pchText,EVRNotificationStyle style,ref NotificationBitmap_t pImage,ref uint pNotificationId);
Beispiel #9
0
 public override EVRNotificationError CreateNotification(ulong ulOverlayHandle,ulong ulUserValue,EVRNotificationType type,string pchText,EVRNotificationStyle style,ref NotificationBitmap_t pImage,ref uint pNotificationId)
 {
     CheckIfUsable();
     pNotificationId = 0;
     EVRNotificationError result = VRNativeEntrypoints.VR_IVRNotifications_CreateNotification(m_pVRNotifications,ulOverlayHandle,ulUserValue,type,pchText,style,ref pImage,ref pNotificationId);
     return result;
 }
Beispiel #10
0
        private void ScreenShotTaken(VREvent_Data_t eventData)
        {
            var handle             = eventData.screenshot.handle;
            var notificationBitmap = new NotificationBitmap_t();

            if (_screenshotQueue.ContainsKey(handle))
            {
                var data       = _screenshotQueue[handle];
                var result     = data.result;
                var filePath   = $"{result.filePath}.png";
                var filePathVR = $"{result.filePathVR}.png";
                var filePathR  = $"{result.filePath}_r.png";
                var rect       = new Rectangle();
                if (File.Exists(filePath))
                {
                    rect = GetImageRectangle(filePath);
                    if (_settings.SubmitToSteam && _currentAppId != string.Empty)
                    {
                        var submitted = _ovr.SubmitScreenshotToSteam(result);
                        Debug.WriteLine($"Managed to submit the screenshot to Steam: {submitted}");
                    }
                    else
                    {
                        Debug.WriteLine("Will not submit the screenshot to Steam.");
                    }

                    if (_settings.SaveRightImage && File.Exists(filePathVR))
                    {
                        var bitmapR = GetRightEyeBitmap(rect, filePathVR);
                        SaveBitmapToPngFile(bitmapR, filePathR);
                    }

                    var image = Image.FromFile(filePath);
                    var msg   = data.screenshotMessage;
                    if (msg != null || _settings.TransmitAll)
                    {
                        var resIndex = _settings.ResponseResolution;
                        var res      = MainWindow.RES_MAP.Length > resIndex ? MainWindow.RES_MAP[resIndex] : 256;
                        var bitmap   = ResizeImage(image, res, res);
                        SetAlpha(ref bitmap, 255);
                        var imgb64data = GetBase64Bytes(bitmap);
                        if (msg != null)
                        {
                            _server.SendMessage(
                                msg.session,
                                JsonConvert.SerializeObject(new ScreenshotResponse
                            {
                                nonce = msg.nonce,
                                image = imgb64data
                            })
                                );
                        }
                        else if (data.byUser)
                        {
                            _server.SendMessageToAll(
                                JsonConvert.SerializeObject(new ScreenshotResponse
                            {
                                nonce = "",
                                image = imgb64data
                            })
                                );
                        }
                    }

                    if (_settings.Notifications && _settings.Thumbnail)
                    {
                        var bitmap = ResizeImage(image, 255, 255); // 256x256 should be enough for notification
                        SetAlpha(ref bitmap, 255);
                        notificationBitmap = BitmapUtils.NotificationBitmapFromBitmap(bitmap);
                    }
                    else
                    {
                        notificationBitmap = BitmapUtils.NotificationBitmapFromBitmap(Properties.Resources.logo);
                    }
                }
                else
                {
                    Debug.WriteLine($"Could not find screenshot after taking it: {filePath}");
                }

                if (_settings.Notifications && data.byUser)
                {
                    _ovr.EnqueueNotification(_notificationOverlayHandle, $"Screenshot taken!\n{rect.Width}x{rect.Height}px", notificationBitmap);
                }
                _screenshotQueue.Remove(handle);
            }
            else
            {
                if (_settings.Notifications)
                {
                    _ovr.EnqueueNotification(_notificationOverlayHandle, "Screenshot taken! (Unknown)", notificationBitmap);
                }
                Debug.WriteLine($"Screenshot handle does not exist in queue? Handle: {handle}");
            }
            Debug.WriteLine($"Screenshot taken done, handle: {eventData.screenshot.handle}");
        }
Beispiel #11
0
        public uint DisplayNotification(string Message, Overlay Overlay, EVRNotificationType Type, EVRNotificationStyle Style, NotificationBitmap_t Bitmap)
        {
            uint ID = GetNewNotificationID();

            OpenVR.Notifications.CreateNotification(Overlay.Handle, 0, Type, Message, Style, ref Bitmap, ref ID);
            Notifications.Add(ID);
            return(ID);
        }