/// <summary>
        /// Generate the GDI pages
        /// </summary>
        public void CreateGdiPage()
        {
            mainPage = new LcdGdiPage(lcd)
            {
                Children =
                {
                    new LcdGdiImage(mainIcon),
                    new LcdGdiText {
                        Text   = "This has been a test",
                        Margin = new MarginF(34.0f, 0.0f, 2.0f, 0.0f)
                    }
                }
            };

            warningPage = new LcdGdiPage(lcd)
            {
                Children =
                {
                    new LcdGdiImage(xMainIcon),
                    new LcdGdiText {
                        Text   = "Don't do that again",
                        Margin = new MarginF(34.0f, 0.0f, 2.0f, 0.0f)
                    }
                }
            };

            lcd.Pages.Add(mainPage);
            //I've not added the warning page but it doesn't appear to be an issue
            lcd.CurrentPage = mainPage;
        }
        // Event handler for the page update (invoked indirectly by DoUpdateAndDraw)
        public void updateNowPlayingMinPage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            if (m_playerDetails.privateSession == true)
            {
                page.Device.CurrentPage = m_privatePage;
            }
            else if (m_showTitles == true)
            {
                page.Device.CurrentPage = m_nowPlayingPage;
            }
            else
            {
                page.Device.CurrentPage = m_nowPlayingNoTitlesPage;
            }

            updateTextFields(page.Device,
                             page,
                             (LcdGdiScrollViewer)page.Children[1],
                             (LcdGdiScrollViewer)page.Children[2],
                             (LcdGdiScrollViewer)page.Children[3],
                             (LcdGdiText)page.Children[4]);

            // Turn on/off the playing symbol
            LcdGdiPolygon polygon = (LcdGdiPolygon)page.Children[5];

            polygon.Brush = m_playerDetails.playing ? Brushes.Black : Brushes.White;
            polygon.Pen   = m_playerDetails.playing ? Pens.Black : Pens.White;

            // Show offline or not
            LcdGdiImage image = (LcdGdiImage)page.Children[0];

            image.Image = m_playerDetails.online ? m_imageOnline : m_imageOffline;
        }
        private static void CreateMonochromeGdiPages(LcdDevice monoDevice)
        {
            // Image notUsing;
            Image myImage;

            myImage = (Image)GenerateMap();

            LcdGdiPage page1 = new LcdGdiPage(monoDevice)
            {
                Children = {
                    new LcdGdiImage((Image)GenerateMap()),
                    /*
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText("Hello World! This display is " + monoDevice.PixelWidth.ToString() + "x" + monoDevice.PixelHeight.ToString()),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                       	Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                        AutoScrollX = true,
                    } */
                }
            };
            page1.Updating += Page_Updating;
            monoDevice.Pages.Add(page1);
            monoDevice.CurrentPage = page1;
        }
Exemple #4
0
        private static void CreateMonochromeGdiPages(LcdDevice monoDevice)
        {
            // Image notUsing;
            Image myImage;

            myImage = (Image)GenerateMap();

            LcdGdiPage page1 = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiImage((Image)GenerateMap()),

                    /*
                     * new LcdGdiScrollViewer {
                     *  Child = new LcdGdiText("Hello World! This display is " + monoDevice.PixelWidth.ToString() + "x" + monoDevice.PixelHeight.ToString()),
                     *  HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                     *  VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                     *  Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                     *                          AutoScrollX = true,
                     * } */
                }
            };

            page1.Updating += Page_Updating;
            monoDevice.Pages.Add(page1);
            monoDevice.CurrentPage = page1;
        }
Exemple #5
0
            public LcdGdiPage GetPage(LcdDevice device)
            {
                LcdGdiPage page = new LcdGdiPage(device);

                page.Children.AddRange(new LcdGdiObject[] { _title, _message, _controlYes, _controlNo });

                return(page);
            }
Exemple #6
0
        private static void Page_Updating(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            if (_lastUpdate == 0 || (e.ElapsedTotalTime.TotalSeconds - _lastUpdate > 10) || _forceUpdate)
            {
                LcdGdiImage updateImage = (LcdGdiImage)page.Children[0];
                updateImage.Image = (Image)GenerateMap();
                ((LcdGdiPage)sender).Invalidate();
                _lastUpdate  = e.ElapsedTotalTime.TotalSeconds;
                _forceUpdate = false;
            }
        }
Exemple #7
0
        /// <summary>
        /// This event handler is called before the page starts its update.
        /// </summary>
        private static void Page_Updating(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            // Makes the progress bar fill 10% per second
            LcdGdiProgressBar progressBar = (LcdGdiProgressBar)page.Children[2];

            progressBar.Value = (int)((e.ElapsedTotalTime.TotalSeconds % 10.0) * 10.0);

            // Makes the polygon blink every 0.5 second
            LcdGdiPolygon polygon = (LcdGdiPolygon)page.Children[3];

            polygon.Brush = e.ElapsedTotalTime.Milliseconds < 500 ? Brushes.White : Brushes.Black;
        }
        // Update the Now Playing pagetext fields
        public void updateTextFields(LcdDevice device, LcdGdiPage page, LcdGdiScrollViewer scrollViewer,
                                     LcdGdiScrollViewer scrollViewer2, LcdGdiScrollViewer scrollViewer3, LcdGdiText playTime)
        {
            LcdGdiText track = (LcdGdiText)scrollViewer.Child;

            track.Text = m_playerDetails.currentTrack;


            LcdGdiText album = (LcdGdiText)scrollViewer2.Child;

            album.Text = m_playerDetails.currentAlbum;

            LcdGdiText artist = (LcdGdiText)scrollViewer3.Child;

            artist.Text = m_playerDetails.currentArtist;

            playTime.Text = m_playerDetails.playTime;
        }
Exemple #9
0
            public static LcdGdiPage GetPage(LcdDevice device)
            {
                LcdGdiPage page = new LcdGdiPage(device);

                /*LcdGdiText title = new LcdGdiText();
                 * title.Text = "Config Mode";
                 * title.Font = new Font("Microsoft Sans Serif", 7.5f, FontStyle.Bold);
                 * title.Margin = new MarginF(0, 0, 0, 0);*/

                LcdGdiText message = new LcdGdiText();

                message.Font   = new Font("Microsoft Sans Serif", 7.5f, FontStyle.Regular);
                message.Margin = new MarginF(0, 3, 0, 0);
                message.Text   = "G15 AppStart is currently locked.\nTo continue operation\nclose Config application.";

                page.Children.AddRange(new LcdGdiObject[] { /*title,*/ message });

                return(page);
            }
Exemple #10
0
            public LcdGdiPage GetPage(LcdDevice device)
            {
                LcdGdiPage page = new LcdGdiPage(device);

                if (_enabled)
                {
                    page.Children.AddRange(new LcdGdiObject[] {
                        _item1, _item2, _item3, _imgSelector, _imgControls0, _imgControls1, _imgControls2, _imgControls3
                    });
                }
                else
                {
                    page.Children.AddRange(new LcdGdiObject[] {
                        _item1, _item2, _item3, _imgControls3
                    });
                }

                return(page);
            }
        // Event handler for the page update (invoked indirectly by DoUpdateAndDraw)
        public void updatePrivatePage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            if (m_playerDetails.privateSession == true)
            {
                page.Device.CurrentPage = m_privatePage;
            }
            else
            {
                page.Device.CurrentPage = m_nowPlayingPage;
            }

            // Turn on/off the playing symbol
            LcdGdiPolygon polygon = (LcdGdiPolygon)page.Children[4];

            polygon.Brush = m_playerDetails.playing ? Brushes.Black : Brushes.White;
            polygon.Pen   = m_playerDetails.playing ? Pens.Black : Pens.White;
        }
        private static void CreateGDIPages()
        {
            Process[] ProcessList = GetProcesses();
            LcdGdiPage page = new LcdGdiPage(Device)
            {
                Children = {
                    new LcdGdiLine (Pens.Black,new PointF(00.0f,32.0f) , new PointF(260.0f,32.0f)),
                    new LcdGdiText {
                        //Up
                        Text = "Up",
                        Margin = new MarginF(5.0f,32.0f),
                    },
                    new LcdGdiText {
                        //Down
                        Text = "Down",
                         Margin = new MarginF(20.0f,32.0f),
                    },
                     new LcdGdiText {
                        //Kill
                        Text = "Kill",
                        Margin = new MarginF(100.0f,32.0f),
                    },
                       new LcdGdiText {
                        //Exit
                        Text = "Exit",
                        Margin = new MarginF(135,32.0f),
                    },
                    new LcdGdiPolygon(Pens.Black,Brushes.White,new [] { new PointF(1.0f,0.1f) , new PointF(159.0f,0.1f) , new PointF(159.0f,9.5f),new PointF(1.0f,9.5f)},false),
                    new LcdGdiText {
                        //Current Process
                        Text = ProcessList[CurrentIndex].ProcessName.ToString(),
                        Font = TextFontCurrent,
                        Margin = new MarginF(10.0f,0.0f),
                    },
                      new LcdGdiText {
                        //Current Process Info
                        Text = ProcessList[CurrentIndex].MainWindowTitle,
                        Font = TextFontCurrent,
                        Margin = new MarginF(60.0f,0.0f),
                    },
                    new LcdGdiText {
                        //+1
                        Text = ProcessList[CurrentIndex+1].ProcessName,
                        Font = TextFont,
                        Margin = new MarginF(10.0f,9.0f),
                    },
                    new LcdGdiText {
                        //+2
                        Text = ProcessList[CurrentIndex+2].ProcessName,
                        Font = TextFont,
                        Margin = new MarginF(10.0f,16.0f),
                    },
                    new LcdGdiText {
                        //+3
                        Text = ProcessList[CurrentIndex+3].ProcessName,
                        Font = TextFont,
                        Margin = new MarginF(10.0f,23.0f),
                    }
               		}
            };
            page.Updating += Page_Updating;

            // Adds page to the device's Pages collection (not mandatory, but helps for storing pages),
            // and sets the first page as the current page
            //Device.Pages.Clear();
            //Device.Pages.Add(page);
            Device.CurrentPage = page;
        }
        /// <summary>
        /// Event handler for button press on a device.
        /// </summary>
        /// <param name="sender">Device on which button was pressed</param>
        /// <param name="e">Button event arguments</param>
        private static void DeviceSoftButtonsChanged(object sender, LcdSoftButtonsEventArgs e)
        {
            LcdDeviceMonochrome device = (LcdDeviceMonochrome)sender;

            // First button
            if ((e.SoftButtons & LcdSoftButtons.Button0) == LcdSoftButtons.Button0)
            {
                if (button0Up)
                {
                    button0Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        DecrementListState(ref devicesList);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        DecrementListState(ref entriesList);
                    }
                }
            }
            else
            {
                button0Up = true;
            }

            // Second button
            if ((e.SoftButtons & LcdSoftButtons.Button1) == LcdSoftButtons.Button1)
            {
                if (button1Up)
                {
                    button1Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        IncrementListState(ref devicesList, 3);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        IncrementListState(ref entriesList, 3);
                    }
                }
            }
            else
            {
                button1Up = true;
            }

            // Third button
            if ((e.SoftButtons & LcdSoftButtons.Button2) == LcdSoftButtons.Button2)
            {
                if (button2Up)
                {
                    button2Up = false;

                    if (device.CurrentPage == device.Pages[0])
                    {
                        lock (devicesList.Lock)
                        {
                            if (devicesList.Items != null && devicesList.Items.Length > 0)
                            {
                                actions.Add(Action.Connect);
                                device.Pages[1].SetAsCurrentDevicePage();
                            }
                        }
                    }
                    else if (device.CurrentPage == device.Pages[1] && ccid == null)
                    {
                        actions.Add(Action.Connect);
                    }
                    else if (device.CurrentPage == device.Pages[2])
                    {
                        lock (entriesList.Lock)
                        {
                            if (entryCode.HasValue && !entryCode.Value.Credential.Name.Equals(entriesList.Items[entriesList.Selected].Name))
                            {
                                // Reset code object
                                entryCode = null;

                                // Reset text elements
                                LcdGdiPage         page       = (LcdGdiPage)device.Pages[3];
                                LcdGdiScrollViewer scrollView = (LcdGdiScrollViewer)page.Children[4];
                                LcdGdiText         textName   = (LcdGdiText)scrollView.Child;
                                LcdGdiText         textCode   = (LcdGdiText)page.Children[5];
                                textName.Text = null;
                                textCode.Text = null;
                            }
                        }

                        device.Pages[3].SetAsCurrentDevicePage();
                    }
                    else if (device.CurrentPage == device.Pages[3])
                    {
                        lock (entriesList.Lock)
                        {
                            LcdGdiPage  page        = (LcdGdiPage)device.Pages[3];
                            LcdGdiImage refreshIcon = (LcdGdiImage)page.Children[0];

                            if (refreshIcon.IsVisible)
                            {
                                entryCode = null;
                            }
                        }
                    }
                }
            }
            else
            {
                button2Up = true;
            }

            // Fourth button
            if ((e.SoftButtons & LcdSoftButtons.Button3) == LcdSoftButtons.Button3)
            {
                if (button3Up)
                {
                    button3Up = false;

                    if (device.CurrentPage == device.Pages[1] || device.CurrentPage == device.Pages[2])
                    {
                        device.Pages[0].SetAsCurrentDevicePage();
                    }
                    else if (device.CurrentPage == device.Pages[3])
                    {
                        device.Pages[2].SetAsCurrentDevicePage();
                    }
                }
            }
            else
            {
                button3Up = true;
            }
        }
        /// <summary>
        /// Updates the code page before rendering it.
        /// </summary>
        /// <param name="sender">Page being updated</param>
        /// <param name="e">Update event arguments</param>
        private static void UpdateEntryPage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage         page        = (LcdGdiPage)sender;
            LcdGdiImage        refreshIcon = (LcdGdiImage)page.Children[0];
            LcdGdiProgressBar  progressBar = (LcdGdiProgressBar)page.Children[2];
            LcdGdiScrollViewer scrollView  = (LcdGdiScrollViewer)page.Children[4];
            LcdGdiText         textName    = (LcdGdiText)scrollView.Child;
            LcdGdiText         textCode    = (LcdGdiText)page.Children[5];

            lock (entriesList.Lock)
            {
                progressBar.IsVisible = false;

                if (!entryCodeRequested && !entryCode.HasValue)
                {
                    textName.Text      = entriesList.Items[entriesList.Selected].Name;
                    entryCodeRequested = true;

                    if (entriesList.Items[entriesList.Selected].Touch)
                    {
                        textCode.Text         = "Touch your YubiKey...";
                        refreshIcon.IsVisible = false;
                        return;
                    }
                }
                entryCodeRequested = false;

                DateTime time      = DateTime.UtcNow;
                Int32    timestamp = (Int32)(time.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                if (!entryCode.HasValue || entryCode.Value.ValidTo != 0 && entryCode.Value.ValidTo < timestamp && entriesList.Items[entriesList.Selected].Type == OATHController.Type.TOTP && !entriesList.Items[entriesList.Selected].Touch)
                {
                    try
                    {
                        entryCode     = oath.Calculate(entriesList.Items[entriesList.Selected], time);
                        textCode.Text = entryCode.Value.Value;
                    }
                    catch (UnexpectedResponseException ex)
                    {
                        entryCode = new OATHController.Code(); // Hack: Set empty code object to prevent code regen
                        if (ex.SW == APDUResponse.StatusWord.AUTH_REQUIRED)
                        {
                            textCode.Text = "Touch timeout.";
                        }
                        else
                        {
                            textCode.Text = "Error: " + ex.SW.ToString();
                        }
                        refreshIcon.IsVisible = true;
                        return;
                    }
                }

                if (entriesList.Items[entriesList.Selected].Type == OATHController.Type.TOTP && entryCode.HasValue && entryCode.Value.ValidTo != 0)
                {
                    if (entryCode.Value.ValidTo > timestamp)
                    {
                        progressBar.IsVisible = true;
                        progressBar.Value     = (int)(((float)(entryCode.Value.ValidTo - timestamp) / entriesList.Items[entriesList.Selected].Period) * 100);
                    }
                    else if (entriesList.Items[entriesList.Selected].Touch)
                    {
                        textCode.Text         = "Code expired.";
                        progressBar.IsVisible = false;
                        refreshIcon.IsVisible = true;
                    }
                }
            }
        }
        // Update the Now Playing pagetext fields
        public void updateTextFields(LcdDevice device, LcdGdiPage page, LcdGdiScrollViewer scrollViewer,
            LcdGdiScrollViewer scrollViewer2, LcdGdiScrollViewer scrollViewer3, LcdGdiText playTime)
        {
            LcdGdiText track = (LcdGdiText)scrollViewer.Child;
            track.Text = m_playerDetails.currentTrack;

            LcdGdiText album = (LcdGdiText)scrollViewer2.Child;
            album.Text = m_playerDetails.currentAlbum;

            LcdGdiText artist = (LcdGdiText)scrollViewer3.Child;
            artist.Text = m_playerDetails.currentArtist;

            playTime.Text = m_playerDetails.playTime;
        }
Exemple #16
0
        /// <summary>
        /// Creates two new LcdGdiPages for a monochrome device.
        /// </summary>
        /// <param name="monoDevice">Device to use for page creation.</param>
        private static void CreateMonochromeGdiPages(LcdDevice monoDevice)
        {
            // Creates first page
            Page_MainPage = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiText
                    {
                        Text = "Baron: ",

                        Margin = new MarginF(0.0f, 5f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                    },
                    new LcdGdiText
                    {
                        Text = TimeSpan.FromSeconds(RespawnTimes[(int)Mobs.Baron]).ToString(@"m\:ss"),
                        Tag = TagNames[(int)Mobs.Baron],

                        Margin = new MarginF(28.0f, -2.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif, 16)
                    },
                   new LcdGdiText
                   {
                        Text = "Dragon: ",

                        Margin = new MarginF(75.0f, 5f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                    },
                    new LcdGdiText
                    {
                        Text = TimeSpan.FromSeconds(RespawnTimes[(int)Mobs.Dragon]).ToString(@"m\:ss"),
                        Tag = TagNames[(int)Mobs.Dragon],

                        Margin = new MarginF(110.0f, -2.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif, 16)
                    },
                   new LcdGdiText
                   {
                        Text = "Blue Golem: ",

                        Margin = new MarginF(0.0f, 20.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)

                    },
                    new LcdGdiText
                   {
                        Text = TimeSpan.FromSeconds(RespawnTimes[(int)Mobs.Golem_Blue]).ToString(@"m\:ss"),
                        Tag = TagNames[(int)Mobs.Golem_Blue],

                        Margin = new MarginF(55.0f, 20.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                    },
                   new LcdGdiText
                   {
                        Text = "Blue Lizard : ",

                        Margin = new MarginF(0.0f, 30.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                    },
                    new LcdGdiText
                   {
                        Text = TimeSpan.FromSeconds(RespawnTimes[(int)Mobs.Lizard_Blue]).ToString(@"m\:ss"),
                        Tag = TagNames[(int)Mobs.Lizard_Blue],

                        Margin = new MarginF(55.0f, 30.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                    },
                   new LcdGdiText
                   {
                        Text = "Purple Golem: ",
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(75.0f, 20.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                   },
                   new LcdGdiText
                   {
                        Text = TimeSpan.FromSeconds(RespawnTimes[(int)Mobs.Golem_Purple]).ToString(@"m\:ss"),
                        Tag = TagNames[(int)Mobs.Golem_Purple],

                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(138.0f, 20.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                    },
                   new LcdGdiText
                   {
                        Text = "Purple Lizard : ",
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(75.0f, 30.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7),
                    },
                    new LcdGdiText
                   {
                        Text = TimeSpan.FromSeconds(RespawnTimes[(int)Mobs.Lizard_Purple]).ToString(@"m\:ss"),
                        Tag = TagNames[(int)Mobs.Lizard_Purple],

                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(138.0f, 30.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,7)
                    },
                    new LcdGdiLine
                    {
                        Pen = Pens.Black,
                        Tag = "currentSelectionLine",
                        StartPoint = new PointF(56.0f, 30.0f),
                        EndPoint = new PointF(74.0f, 30.0f)
                    }
                }
            };
            Page_MainPage.Updating += Page_Updating;
            Page_MainPage.DesiredFramerate = 10;

            // Adds page to the device's Pages collection (not mandatory, but helps for storing pages),
            // and sets the first page as the current page
            monoDevice.Pages.Add(Page_MainPage);
            monoDevice.CurrentPage = Page_MainPage;

            Page_RespawnDragon = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiImage
                    {
                        Image = LoLTimer.Resources.img_dragon,
                        Margin = new MarginF(5.0f, 0.0f, 0.0f, 0.0f),
                    },
                    new LcdGdiText
                    {
                        Text = "Dragon",
                        Margin = new MarginF(50.0f, -5.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,22)
                    },
                    new LcdGdiText
                    {
                        Text = "Has Respawned",
                        Margin = new MarginF(48.0f, 25.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif, 11)
                    }
                }
            };
            Page_RespawnBaron = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiImage
                    {
                        Image = LoLTimer.Resources.img_baron,
                        Margin = new MarginF(5.0f, 6.0f, 0.0f, 0.0f),
                    },
                    new LcdGdiText
                    {
                        Text = "Baron",
                        Margin = new MarginF(60.0f, -5.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif,22)
                    },
                    new LcdGdiText
                    {
                        Text = "Has Respawned",
                        Margin = new MarginF(48.0f, 25.0f, 0.0f, 0.0f),
                        Font = new Font(FontFamily.GenericSansSerif, 11)
                    }
                }
            };

            monoDevice.Pages.Add(Page_RespawnDragon);
            monoDevice.Pages.Add(Page_RespawnBaron);
        }
        // Create the Mono Pages
        public void createMonochromeGdiPages(LcdDevice monoDevice)
        {
            // Get the images from the assembly
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifyStatusApplet.lcdIcon.bmp"))
                m_imageOnline = Image.FromStream(stream);
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifyStatusApplet.lcdIcon_offline.bmp"))
                m_imageOffline = Image.FromStream(stream);

            m_nowPlayingPage = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiImage(m_imageOffline),
                    new LcdGdiText {
                        Text   = CURRENT_TRACK_FIELD_TITLE + ": ",
                        Margin = new MarginF(34.0f,           0.0f,            2.0f,                               0.0f)
                    },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        Margin      = new MarginF(64.0f,      0.0f,            2.0f,     0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText {
                        Text   = CURRENT_ALBUM_FIELD_TITLE + ": ",
                        Margin = new MarginF(34.0f,          10.0f,            2.0f,                               0.0f)
                    },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        Margin      = new MarginF(64.0f,     10.0f,            2.0f,     0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText {
                        Text   = CURRENT_ARTIST_FIELD_TITLE + ": ",
                        Margin = new MarginF(34.0f,          20.0f,            2.0f,                               0.0f)
                    },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        Margin      = new MarginF(64.0f,     20.0f,            2.0f,     0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText {
                        Text   = "",
                        Margin = new MarginF(34.0f,          30.0f,            2.0f,                               0.0f)
                    },
                    new LcdGdiPolygon(Pens.Black,   Brushes.Black,  new[] {
                        new PointF(0.0f,                    10.0f), new PointF(0.0f,     0.0f),new PointF(10.0f,5.0f),
                    },                              false)
                    {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Left,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Bottom,
                        Margin = new MarginF(0.0f,            0.0f,            5.0f, 5.0f)
                    }
                }
            };
            m_nowPlayingPage.Updating += updateNowPlayingPage;

            m_nowPlayingNoTitlesPage = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiImage(m_imageOffline),
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        Margin      = new MarginF(34.0f,      0.0f,            2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        Margin      = new MarginF(34.0f,     10.0f,            2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        Margin      = new MarginF(34.0f,     20.0f,            2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText {
                        Text   = "",
                        Margin = new MarginF(34.0f,          30.0f,            2.0f,                               0.0f)
                    },
                    new LcdGdiPolygon(Pens.Black,   Brushes.Black,  new[] {
                        new PointF(0.0f,                    10.0f), new PointF(0.0f, 0.0f),new PointF(10.0f,5.0f),
                    },                              false)
                    {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Left,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Bottom,
                        Margin = new MarginF(0.0f,            0.0f,            5.0f, 5.0f)
                    }
                }
            };
            m_nowPlayingNoTitlesPage.Updating += updateNowPlayingMinPage;

            m_privatePage = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiImage(m_imageOffline),
                    new LcdGdiText {
                        Text   = "Warning!",
                        Margin = new MarginF(24.0f,           0.0f,            2.0f, 0.0f),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Center
                    },
                    new LcdGdiText {
                        Text   = "Spotify in private mode.",
                        Margin = new MarginF(24.0f,          10.0f,            2.0f, 0.0f),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Center
                    },
                    new LcdGdiText {
                        Text   = "No track info.",
                        Margin = new MarginF(24.0f,          20.0f,            2.0f, 0.0f),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Center
                    },
                    new LcdGdiPolygon(Pens.Black,   Brushes.Black,  new[] {
                        new PointF(0.0f,                    10.0f), new PointF(0.0f, 0.0f),new PointF(10.0f,5.0f),
                    },                              false)
                    {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Left,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Bottom,
                        Margin = new MarginF(0.0f,            0.0f,            5.0f, 5.0f)
                    }
                }
            };
            m_privatePage.Updating += updatePrivatePage;

            // Finally add page to the device's Pages collection set the current page
            monoDevice.Pages.Add(m_nowPlayingPage);
            monoDevice.Pages.Add(m_nowPlayingNoTitlesPage);
            if (m_showTitles)
            {
                monoDevice.CurrentPage = m_nowPlayingPage;
            }
            else
            {
                monoDevice.CurrentPage = m_nowPlayingNoTitlesPage;
            }
        }
Exemple #18
0
 public MyLcdGdiPage(LcdDevice Device, LCDHandler Handler)
 {
     this._Page    = new LcdGdiPage(Device);
     this._Handler = Handler;
 }
        /// <summary>
        /// Creates default state of pages on the device.
        /// </summary>
        /// <param name="device">Logitech LCD device</param>
        private static void CreatePages(LcdDeviceMonochrome device)
        {
            // LCD Resolution = 160x43

            LcdGdiPage pageDevices = new LcdGdiPage(device);

            pageDevices.Updating += UpdateDevicePage;
            device.Pages.Add(pageDevices);

            LcdGdiPage pageConnectionStatus = new LcdGdiPage(device)
            {
                Children =
                {
                    new LcdGdiImage
                    {
                        Image     = Properties.Resources.Refresh,
                        Margin    = new MarginF(97.0f, 33.0f, 0.0f, 0.0f),
                        IsVisible = false
                    },
                    new LcdGdiImage
                    {
                        Image     = Properties.Resources.Back,
                        Margin    = new MarginF(138.0f, 33.0f, 0.0f, 0.0f),
                        IsVisible = false
                    },
                    new LcdGdiRectangle
                    {
                        Size  = new SizeF(160.0f, 12.0f),
                        Brush = Brushes.Black
                    },
                    new LcdGdiScrollViewer
                    {
                        Child = new LcdGdiText
                        {
                            Brush = Brushes.White
                        },
                        Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        AutoScrollX         = true
                    },
                    new LcdGdiText
                    {
                        Margin = new MarginF(0.0f, 12.0f, 0.0f, 0.0f)
                    }
                }
            };

            pageConnectionStatus.Updating += UpdateConnectionStatusPage;
            device.Pages.Add(pageConnectionStatus);

            LcdGdiPage pageEntries = new LcdGdiPage(device);

            pageEntries.Updating += UpdateEntriesPage;
            device.Pages.Add(pageEntries);

            LcdGdiPage pageEntry = new LcdGdiPage(device)
            {
                Children =
                {
                    new LcdGdiImage
                    {
                        Image     = Properties.Resources.Refresh,
                        Margin    = new MarginF(97.0f, 33.0f, 0.0f, 0.0f),
                        IsVisible = false
                    },
                    new LcdGdiImage
                    {
                        Image  = Properties.Resources.Back,
                        Margin = new MarginF(138.0f, 33.0f, 0.0f, 0.0f)
                    },
                    new LcdGdiProgressBar
                    {
                        Margin        = new MarginF(0.0f, 28.0f, 0.0f, 0.0f),
                        Size          = new SizeF(160.0f, 5.0f),
                        Brush         = Brushes.White,
                        ProgressBrush = Brushes.Black,
                        Minimum       = 0,
                        Maximum       = 100,
                        Value         = 50,
                        IsVisible     = false
                    },
                    new LcdGdiRectangle
                    {
                        Size  = new SizeF(160.0f, 12.0f),
                        Brush = Brushes.Black
                    },
                    new LcdGdiScrollViewer
                    {
                        Child = new LcdGdiText
                        {
                            Brush = Brushes.White
                        },
                        Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        AutoScrollX         = true
                    },
                    new LcdGdiText
                    {
                        Margin = new MarginF(0.0f, 11.0f, 0.0f, 0.0f),
                        Font   = new Font(FontFamily.GenericSansSerif, 11.0f)
                    }
                }
            };

            pageEntry.Updating += UpdateEntryPage;
            device.Pages.Add(pageEntry);

            pageDevices.SetAsCurrentDevicePage();
        }
Exemple #20
0
 private static LcdGdiText getPageTextElement(LcdGdiPage page, String tag)
 {
     return ((LcdGdiText)page.Children.Find(child => (String)child.Tag == tag));
 }
        /// <summary>
        /// Updates the device selection page before rendering it.
        /// </summary>
        /// <param name="sender">Page being updated</param>
        /// <param name="e">Update event arguments</param>
        private static void UpdateDevicePage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            lock (devicesList.Lock)
            {
                // Update list items
                string[] newItems = CCIDDriver.ListReaders();
                if (!newItems.Equals(devicesList.Items))
                {
                    devicesList.Changed = true;
                }

                if (!devicesList.Changed)
                {
                    return;
                }

                page.Children.Clear();
                devicesList.Items = newItems;

                if (devicesList.Items == null || devicesList.Items.Length == 0)
                {
                    page.Children.Add(new LcdGdiText
                    {
                        Text   = "No YubiKey detected.",
                        Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                        Font   = new Font(FontFamily.GenericSansSerif, 7.0f, FontStyle.Underline)
                    });
                }
                else
                {
                    // Update list selected state based on new items
                    while (devicesList.Selected >= devicesList.Items.Length && devicesList.Selected > 0)
                    {
                        devicesList.Selected--;
                    }

                    // Add button icons
                    page.Children.Add(new LcdGdiImage
                    {
                        Image  = Properties.Resources.ArrowUP,
                        Margin = new MarginF(12.0f, 33.0f, 0.0f, 0.0f)
                    });
                    page.Children.Add(new LcdGdiImage
                    {
                        Image  = Properties.Resources.ArrowDN,
                        Margin = new MarginF(55.0f, 33.0f, 0.0f, 0.0f)
                    });
                    page.Children.Add(new LcdGdiImage
                    {
                        Image  = Properties.Resources.Check,
                        Margin = new MarginF(97.0f, 33.0f, 0.0f, 0.0f)
                    });

                    // Add list items
                    for (int i = devicesList.Offset, j = 0; i < devicesList.Items.Length && j < 3; i++, j++)
                    {
                        if (i == devicesList.Selected)
                        {
                            page.Children.Add(new LcdGdiRectangle(Brushes.Black, new RectangleF(0.0f, j * 11.0f, 161.0f, 12.0f)));
                        }

                        page.Children.Add(new LcdGdiScrollViewer
                        {
                            Child = new LcdGdiText
                            {
                                Text  = devicesList.Items[i],
                                Brush = i == devicesList.Selected ? Brushes.White : Brushes.Black
                            },
                            Margin = new MarginF(0.0f, j * 11.0f, 0.0f, 0.0f),
                            HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                            VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                            AutoScrollX         = i == devicesList.Selected
                        });
                    }
                }
            }
        }
        // Create the Mono Pages
        public void createMonochromeGdiPages(LcdDevice monoDevice)
        {
            // Get the images from the assembly
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifyStatusApplet.lcdIcon.bmp"))
                m_imageOnline = Image.FromStream(stream);
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifyStatusApplet.lcdIcon_offline.bmp"))
                m_imageOffline = Image.FromStream(stream);

            m_nowPlayingPage = new LcdGdiPage(monoDevice)
            {
                Children = {
                    new LcdGdiImage(m_imageOffline),
                    new LcdGdiText{Text = CURRENT_TRACK_FIELD_TITLE + ": ",
                                    Margin = new MarginF(34.0f, 0.0f, 2.0f, 0.0f) },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(64.0f, 0.0f, 2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText{Text = CURRENT_ALBUM_FIELD_TITLE + ": ",
                                    Margin = new MarginF(34.0f, 10.0f, 2.0f, 0.0f) },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(64.0f, 10.0f, 2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText{Text = CURRENT_ARTIST_FIELD_TITLE + ": ",
                                    Margin = new MarginF(34.0f, 20.0f, 2.0f, 0.0f) },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText( ""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(64.0f, 20.0f, 2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText{Text = "",
                        Margin = new MarginF(34.0f, 30.0f, 2.0f, 0.0f) },
                    new LcdGdiPolygon(Pens.Black, Brushes.Black, new[] {
                        new PointF(0.0f, 10.0f), new PointF(0.0f, 0.0f), new PointF(10.0f, 5.0f),
                    }, false) {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Left,
                        VerticalAlignment = LcdGdiVerticalAlignment.Bottom,
                        Margin = new MarginF(0.0f, 0.0f, 5.0f, 5.0f)
                    }
                }
            };
            m_nowPlayingPage.Updating += updateNowPlayingPage;

            m_nowPlayingNoTitlesPage = new LcdGdiPage(monoDevice)
            {
                Children = {
                    new LcdGdiImage(m_imageOffline),
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(34.0f, 0.0f, 2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText(""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(34.0f, 10.0f, 2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText( ""),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment = LcdGdiVerticalAlignment.Stretch,
                        Margin = new MarginF(34.0f, 20.0f, 2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiText{Text = "",
                        Margin = new MarginF(34.0f, 30.0f, 2.0f, 0.0f) },
                    new LcdGdiPolygon(Pens.Black, Brushes.Black, new[] {
                        new PointF(0.0f, 10.0f), new PointF(0.0f, 0.0f), new PointF(10.0f, 5.0f),
                    }, false) {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Left,
                        VerticalAlignment = LcdGdiVerticalAlignment.Bottom,
                        Margin = new MarginF(0.0f, 0.0f, 5.0f, 5.0f)
                    }
                }
            };
            m_nowPlayingNoTitlesPage.Updating += updateNowPlayingMinPage;

            m_privatePage = new LcdGdiPage(monoDevice)
            {
                Children = {
                    new LcdGdiImage(m_imageOffline),
                    new LcdGdiText{Text = "Warning!",
                                    Margin = new MarginF(24.0f, 0.0f, 2.0f, 0.0f),
                                    HorizontalAlignment = LcdGdiHorizontalAlignment.Center },
                    new LcdGdiText{Text = "Spotify in private mode.",
                                    Margin = new MarginF(24.0f, 10.0f, 2.0f, 0.0f),
                                    HorizontalAlignment = LcdGdiHorizontalAlignment.Center },
                    new LcdGdiText{Text = "No track info.",
                                    Margin = new MarginF(24.0f, 20.0f, 2.0f, 0.0f),
                                    HorizontalAlignment = LcdGdiHorizontalAlignment.Center },
                    new LcdGdiPolygon(Pens.Black, Brushes.Black, new[] {
                        new PointF(0.0f, 10.0f), new PointF(0.0f, 0.0f), new PointF(10.0f, 5.0f),
                    }, false) {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Left,
                        VerticalAlignment = LcdGdiVerticalAlignment.Bottom,
                        Margin = new MarginF(0.0f, 0.0f, 5.0f, 5.0f)
                    }
                }
            };
            m_privatePage.Updating += updatePrivatePage;

            // Finally add page to the device's Pages collection set the current page
            monoDevice.Pages.Add(m_nowPlayingPage);
            monoDevice.Pages.Add(m_nowPlayingNoTitlesPage);
            if (m_showTitles)
            {
                monoDevice.CurrentPage = m_nowPlayingPage;
            }
            else
            {
                monoDevice.CurrentPage = m_nowPlayingNoTitlesPage;
            }
        }
        /// <summary>
        /// Updates the connection status page before rendering it.
        /// </summary>
        /// <param name="sender">Page being updated</param>
        /// <param name="e">Update event arguments</param>
        private static void UpdateConnectionStatusPage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage         page             = (LcdGdiPage)sender;
            LcdGdiImage        refreshButton    = (LcdGdiImage)page.Children[0];
            LcdGdiImage        backButton       = (LcdGdiImage)page.Children[1];
            LcdGdiScrollViewer deviceScrollView = (LcdGdiScrollViewer)page.Children[3];
            LcdGdiText         deviceText       = (LcdGdiText)deviceScrollView.Child;
            LcdGdiText         statusText       = (LcdGdiText)page.Children[4];

            if (oath != null && oath.HasChallenge())
            {
                using (var dialog = new PasswordDialog())
                {
                    dialog.OKButton.Click += (_sender, _e) =>
                    {
                        try
                        {
                            oath.Validate(dialog.PasswordBox.Text);
                            statusText.Text = "Connected.";
                            CreateTimer("ConnectionStatusSwitchPage", 2);
                        }
                        catch (UnexpectedResponseException)
                        {
                            statusText.Text = "Invalid password, try again...";
                        }
                        dialog.Close();
                    };
                    dialog.CancelButton.Click += (_sender, _e) =>
                    {
                        oath = null;
                        ccid = null;
                        page.Device.Pages[0].SetAsCurrentDevicePage();
                        dialog.Close();
                    };
                    dialog.ShowDialog();
                }
            }

            if (CheckTimer("ConnectionStatusSwitchPage"))
            {
                // Update list items
                lock (entriesList.Lock)
                {
                    entriesList.Items   = oath.List();
                    entriesList.Changed = true;

                    // Calculate all keys and update touch info
                    var codes = oath.CalculateAll();
                    foreach (var code in codes)
                    {
                        if (code.Credential.Touch)
                        {
                            var idx = entriesList.Items.FindIndex(item => item.Name.Equals(code.Credential.Name));
                            if (idx != -1)
                            {
                                var item = entriesList.Items[idx];
                                item.Touch             = code.Credential.Touch;
                                entriesList.Items[idx] = item;
                            }
                        }
                    }
                }

                // Switch page
                page.Device.Pages[2].SetAsCurrentDevicePage();
                return;
            }

            lock (devicesList.Lock)
            {
                while (actions.TryTake(out Action a))
                {
                    switch (a)
                    {
                    case Action.Connect:
                        try
                        {
                            ccid                    = CCIDDriver.OpenDevice(devicesList.Items[devicesList.Selected]);
                            oath                    = new OATHController(ccid);
                            deviceText.Text         = devicesList.Items[devicesList.Selected];
                            backButton.IsVisible    = false;
                            refreshButton.IsVisible = false;

                            if (oath.HasChallenge())
                            {
                                statusText.Text = "Waiting for password...";
                            }
                            else
                            {
                                statusText.Text = "Connected.";
                                CreateTimer("ConnectionStatusSwitchPage", 2);
                            }
                        }
                        catch (ConnectionException)
                        {
                            oath                    = null;
                            ccid                    = null;
                            deviceText.Text         = devicesList.Items[devicesList.Selected];
                            statusText.Text         = "Unable to connect.";
                            backButton.IsVisible    = true;
                            refreshButton.IsVisible = true;
                        }
                        break;
                    }
                }
            }
        }
Exemple #24
0
        /// <summary>
        /// Creates two new LcdGdiPages for a monochrome device.
        /// </summary>
        /// <param name="monoDevice">Device to use for page creation.</param>
        private static void CreateMonochromeGdiPages(LcdDevice monoDevice)
        {
            // Gets the test.bmp image from the assembly
            Image image;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GammaJul.LgLcd.Samples.Gdi.test.bmp"))
                image = Image.FromStream(stream);

            // Creates first page
            LcdGdiPage page1 = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiImage(image),
                    new LcdGdiScrollViewer {
                        Child = new LcdGdiText("Hello there! Please press the fourth soft button to exit the program."),
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                        Margin      = new MarginF(34.0f,       0.0f,            2.0f, 0.0f),
                        AutoScrollX = true,
                    },
                    new LcdGdiProgressBar {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Top,
                        Margin = new MarginF(34.0f,           14.0f,            2.0f, 0.0f),
                        Size   = new SizeF(0.0f,                            7.0f)
                    },
                    new LcdGdiPolygon(Pens.Black,Brushes.White,      new[] {
                        new PointF(0.0f,                     10.0f), new PointF(5.0f, 0.0f),new PointF(10.0f,10.0f),
                    },                           false)
                    {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Center,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Bottom,
                        Margin = new MarginF(0.0f,             0.0f,            0.0f, 5.0f)
                    }
                }
            };

            page1.Updating += Page_Updating;

            // Creates second page
            LcdGdiPage page2 = new LcdGdiPage(monoDevice)
            {
                Children =
                {
                    new LcdGdiRectangle {
                        Pen = Pens.Black,
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch
                    },
                    new LcdGdiLine(Pens.Black, new PointF(0.0f, 0.0f), new PointF(159.0f, 42.0f))
                    {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch
                    },
                    new LcdGdiLine(Pens.Black, new PointF(0.0f, 42.0f), new PointF(159.0f, 0.0f))
                    {
                        HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                        VerticalAlignment   = LcdGdiVerticalAlignment.Stretch
                    }
                }
            };

            page2.GdiDrawing += Page2_GdiDrawing;

            // Adds page to the device's Pages collection (not mandatory, but helps for storing pages),
            // and sets the first page as the current page
            monoDevice.Pages.Add(page1);
            monoDevice.Pages.Add(page2);
            monoDevice.CurrentPage = page1;
        }
        /// <summary>
        /// Updates the entries page before rendering it.
        /// </summary>
        /// <param name="sender">Page being updated</param>
        /// <param name="e">Update event arguments</param>
        private static void UpdateEntriesPage(object sender, UpdateEventArgs e)
        {
            LcdGdiPage page = (LcdGdiPage)sender;

            lock (entriesList.Lock)
            {
                if (!entriesList.Changed)
                {
                    return;
                }

                entriesList.Changed = false;
                page.Children.Clear();

                if (entriesList.Items == null || entriesList.Items.Count == 0)
                {
                    page.Children.Add(new LcdGdiText
                    {
                        Text   = "YubiKey has no entries.",
                        Margin = new MarginF(0.0f, 0.0f, 0.0f, 0.0f),
                        Font   = new Font(FontFamily.GenericSansSerif, 7.0f, FontStyle.Underline)
                    });
                }
                else
                {
                    // Update list selected state based on new items
                    while (entriesList.Selected >= entriesList.Items.Count && entriesList.Selected > 0)
                    {
                        entriesList.Selected--;
                    }

                    // Add button icons
                    page.Children.Add(new LcdGdiImage
                    {
                        Image  = Properties.Resources.ArrowUP,
                        Margin = new MarginF(12.0f, 33.0f, 0.0f, 0.0f)
                    });
                    page.Children.Add(new LcdGdiImage
                    {
                        Image  = Properties.Resources.ArrowDN,
                        Margin = new MarginF(55.0f, 33.0f, 0.0f, 0.0f)
                    });
                    page.Children.Add(new LcdGdiImage
                    {
                        Image  = Properties.Resources.Check,
                        Margin = new MarginF(97.0f, 33.0f, 0.0f, 0.0f)
                    });
                    page.Children.Add(new LcdGdiImage
                    {
                        Image  = Properties.Resources.Back,
                        Margin = new MarginF(138.0f, 33.0f, 0.0f, 0.0f)
                    });

                    // Add list items
                    for (int i = entriesList.Offset, j = 0; i < entriesList.Items.Count && j < 3; i++, j++)
                    {
                        if (i == entriesList.Selected)
                        {
                            page.Children.Add(new LcdGdiRectangle(Brushes.Black, new RectangleF(0.0f, j * 11.0f, 161.0f, 12.0f)));
                        }

                        page.Children.Add(new LcdGdiScrollViewer
                        {
                            Child = new LcdGdiText
                            {
                                Text  = entriesList.Items[i].Issuer + " | " + entriesList.Items[i].Account,
                                Brush = i == entriesList.Selected ? Brushes.White : Brushes.Black
                            },
                            Margin = new MarginF(0.0f, j * 11.0f, 0.0f, 0.0f),
                            HorizontalAlignment = LcdGdiHorizontalAlignment.Stretch,
                            VerticalAlignment   = LcdGdiVerticalAlignment.Stretch,
                            AutoScrollX         = i == entriesList.Selected
                        });
                    }
                }
            }
        }