Example #1
0
        static void ExampleWithSystemDrawing(IStreamDeck deck)
        {
            //Create a key with lambda graphics
            var key = KeyBitmap.FromGraphics(g =>
            {
                //See https://stackoverflow.com/questions/6311545/c-sharp-write-text-on-bitmap for details
                g.SmoothingMode     = SmoothingMode.AntiAlias;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                //Fill background black
                g.FillRectangle(Brushes.Black, 0, 0, deck.IconSize, deck.IconSize);

                //Write text to graphics
                var f = new Font("Arial", 13);
                g.DrawString("Drawing", f, Brushes.White, new PointF(5, 20));

                //Draw other stuff to image
                //g.DrawImage
                //g.DrawLine
            });

            deck.SetKeyBitmap(7, key);
        }
        private static void startGame(IStreamDeck deck)
        {
            //suffle memory cards
            openCard[0] = -1;
            openCard[1] = -1;
            mode        = 0;
            suffleArray(gameState, rnd);

            for (int i = 0; i < cardVisible.Length; i++)
            {
                cardVisible[i] = false;
            }

            //Clear all tiles (except restart key)
            for (int i = 0; i < deck.KeyCount; i++)
            {
                if (i != restartKey)
                {
                    deck.ClearKey(i);
                }
            }

            //(Re-)Draw restart key image
            deck.SetKeyBitmap(restartKey, restartIcon);
        }
 /// <summary>
 /// Sets a background image for all keys
 /// </summary>
 /// <param name="deck"></param>
 /// <param name="bitmap"></param>
 public static void SetKeyBitmap(this IStreamDeck deck, KeyBitmap bitmap)
 {
     for (int i = 0; i < deck.KeyCount; i++)
     {
         deck.SetKeyBitmap(i, bitmap);
     }
 }
        static void PlayVideoAForgeFFMPEG(IStreamDeck deck, string videoPath)
        {
            using (VideoFileReader reader = new VideoFileReader())
            {
                reader.Open(videoPath);
                var fr          = reader.FrameRate;
                int frameLength = (int)Math.Round(1000.0 / fr);

                while (true)
                {
                    var sw = Stopwatch.StartNew();
                    using (var frame = reader.ReadVideoFrame())
                    {
                        if (frame == null)
                        {
                            return;
                        }
                        deck.DrawFullScreenBitmap(frame);
                        var wait = frameLength - (int)sw.ElapsedMilliseconds;
                        sw.Restart();
                        if (wait > 0)
                        {
                            Thread.Sleep(wait);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Sets a background image for all keys
 /// </summary>
 /// <param name="deck"></param>
 /// <param name="bitmap"></param>
 public static void SetKeyBitmap(this IStreamDeck deck, StreamDeckKeyBitmap bitmap)
 {
     for (int i = 0; i < StreamDeckHID.numOfKeys; i++)
     {
         deck.SetKeyBitmap(i, bitmap.rawBitmapData);
     }
 }
Example #6
0
 public static void DrawFullScreenBitmap(this IStreamDeck deck, byte[] imgData)
 {
     for (int i = 0; i < deck.KeyCount; i++)
     {
         var img = GetKeyImageFromFull(i, imgData);
         deck.SetKeyBitmap(i, img);
     }
 }
        public async Task Disconnect()
        {
            await this.ConnectionWrapper((deck) =>
            {
                deck.ClearKeys();
                deck.ConnectionStateChanged -= Deck_ConnectionStateChanged;
                deck.KeyStateChanged        -= Deck_KeyStateChanged;
                return(Task.FromResult(0));
            });

            this.deck.Dispose();
            this.deck = null;
        }
        public static void DrawFullScreenBitmap(this IStreamDeck deck, Bitmap b)
        {
            byte[] imgData = null;
            using (var resizedImage = ResizeToFullStreamDeckImage(b))
            {
                imgData = GetRgbArray(resizedImage);
            }

            for (int i = 0; i < deck.KeyCount; i++)
            {
                var img = GetKeyImageFromFull(i, imgData);
                deck.SetKeyBitmap(i, img);
            }
        }
Example #9
0
        private void InitDeck(IStreamDeck deck)
        {
            deck.SetBrightness(100);
            deck.ClearKeys();
            var bitmap = KeyBitmap.FromFile(@"Resources\drum.png");

            deck.SetKeyBitmap(0, bitmap);
            var bitmapSad = KeyBitmap.FromFile(@"Resources\trumpet.png");

            deck.SetKeyBitmap(1, bitmapSad);
            var bitmapSnip = KeyBitmap.FromFile(@"Resources\snipping.png");

            deck.SetKeyBitmap(4, bitmapSnip);
        }
 private static void closeCards(IStreamDeck deck)
 {
     lock (closeCardLock)
     {
         if (mode != 2)
         {
             return;
         }
         cardVisible[openCard[0]] = false;
         cardVisible[openCard[1]] = false;
         var c1 = openCard[0];
         var c2 = openCard[1];
         openCard[0] = -1;
         openCard[1] = -1;
         refreshKeyIcon(deck, c1);
         refreshKeyIcon(deck, c2);
         mode = 0;
     }
 }
Example #11
0
        private static void InitDeck(IStreamDeck deck)
        {
            deck.SetBrightness(100);
            deck.ClearKeys();
            var bitmap = KeyBitmap.FromFile(@"C:\Users\oddva\Downloads\streamdeck_key.png");

            deck.SetKeyBitmap(1, bitmap);
            var bitmapTBK = KeyBitmap.FromFile(@"C:\Users\oddva\Downloads\tbk.png");

            deck.SetKeyBitmap(0, bitmapTBK);
            var bitmapPanic = KeyBitmap.FromFile(@"C:\Users\oddva\Downloads\power_icon.png");

            deck.SetKeyBitmap(4, bitmapPanic);
            var bitmapCopy1 = KeyBitmap.FromRGBColor(55, 200, 55);

            deck.SetKeyBitmap(10, bitmapCopy1);
            var bitmapCopy2 = KeyBitmap.FromRGBColor(255, 200, 55);

            deck.SetKeyBitmap(11, bitmapCopy2);
        }
        private static void refreshKeyIcon(IStreamDeck deck, int cardId)
        {
            var keyId = cardId >= restartKey ? cardId + 1 : cardId;

            if (cardVisible[cardId])
            {
                if ((openCard[0] == cardId || openCard[1] == cardId))
                {
                    deck.SetKeyBitmap(keyId, iconsInactive[gameState[cardId]]);
                }
                else
                {
                    deck.SetKeyBitmap(keyId, iconsActive[gameState[cardId]]);
                }
            }
            else
            {
                deck.SetKeyBitmap(keyId, KeyBitmap.Black);
            }
        }
Example #13
0
        public DeckHandler()
        {
            //Load the default profile
            var path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/OpenStreamDeck/profiles/default.json";

            try
            {
                CurrentProfile = ProfileManager.loadProfile(path);
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("An error occurred while loading your default profile. Generating a new default profile. ({0})", e.Message));
                if (CurrentProfile == null)
                {
                    CurrentProfile = new Profile("Default");
                    ProfileManager.saveProfile(CurrentProfile);
                }
            }

            try
            {
                Deck = StreamDeck.FromHID();
            }
            catch (Exception e)
            {
                //MessageBox.Show(String.Format("Cannot connect to StreamDeck ({0})", e.Message));
                Debug.WriteLine("Cannot connect to StreamDeck {0}", e.Message);
                return;
            }
            Application.ApplicationExit += onApplicationExit;
            Deck.ClearKeys();
            Deck.SetBrightness(DeckBrightness);
            Deck.KeyPressed         += onKeyPressed;
            KeyPressedTimer          = new System.Timers.Timer();
            KeyPressedTimer.Interval = 10;
            KeyPressedTimer.Elapsed += onKeyHeld;

            CurrentPage = CurrentProfile.MainPage;
            PageStack   = new Stack <Page>();
            renderPage();
        }
Example #14
0
 public override void Process(IStreamDeck deck)
 {
     if (!captureStarted)
     {
         try
         {
             cfs.StartFrameCapture();
             stopWatch.Start();
             captureStarted = true;
         }
         catch (Exception exc)
         {
         }
     }
     if (imgData.Length != 0)
     {
         // StreamDeckSharp.Extensions.StreamDeckFullScreenDrawingExtension.DrawFullScreenBitmap(deck, imgData);
     }
     if (enabled)
     {
         StreamDeckSharp.Extensions.StreamDeckFullScreenDrawingExtension.DrawFullScreenBitmap(StreamDeckWrapper.getInstance().getDeck(), imgData);
     }
 }
Example #15
0
        static void ExampleWithWpfElement(IStreamDeck deck)
        {
            var c = new Canvas();

            c.Width      = deck.IconSize;
            c.Height     = deck.IconSize;
            c.Background = System.Windows.Media.Brushes.Black;

            var t = new TextBlock();

            t.Text       = "WPF";
            t.FontFamily = new System.Windows.Media.FontFamily("Arial");
            t.FontSize   = 13;
            t.Foreground = System.Windows.Media.Brushes.White;

            Canvas.SetLeft(t, 10);
            Canvas.SetTop(t, 10);

            c.Children.Add(t);

            var k = KeyBitmap.FromWpfElement(c);

            deck.SetKeyBitmap(7, k);
        }
        public async Task <bool> Connect()
        {
            bool result = false;

            try
            {
                this.deck = StreamDeck.OpenDevice();
                await this.ConnectionWrapper((deck) =>
                {
                    deck.ConnectionStateChanged -= Deck_ConnectionStateChanged;
                    deck.KeyStateChanged        -= Deck_KeyStateChanged;

                    deck.ShowLogo();
                    deck.ConnectionStateChanged += Deck_ConnectionStateChanged;
                    deck.KeyStateChanged        += Deck_KeyStateChanged;

                    result = true;

                    return(Task.FromResult(0));
                });
            }
            catch (Exception ex) { Logger.Log(ex); }
            return(result);
        }
 /// <summary>
 /// Sets background to black for all given keys
 /// </summary>
 /// <param name="deck"></param>
 public static void ClearKeys(this IStreamDeck deck)
 {
     deck.SetKeyBitmap(StreamDeckKeyBitmap.Black);
 }
 /// <summary>
 /// Sets background to black for a given key
 /// </summary>
 /// <param name="deck"></param>
 /// <param name="keyId"></param>
 public static void ClearKey(this IStreamDeck deck, int keyId)
 {
     deck.SetKeyBitmap(keyId, StreamDeckKeyBitmap.Black);
 }
 /// <summary>
 /// Sets a background image for a given key
 /// </summary>
 /// <param name="deck"></param>
 /// <param name="keyId"></param>
 /// <param name="bitmap"></param>
 public static void SetKeyBitmap(this IStreamDeck deck, int keyId, StreamDeckKeyBitmap bitmap)
 {
     deck.SetKeyBitmap(keyId, bitmap.rawBitmapData);
 }