LcdUpdateBitmap() private méthode

private LcdUpdateBitmap ( int device, IntPtr HBITMAP, int format ) : uint
device int
HBITMAP IntPtr
format int
Résultat uint
Exemple #1
0
 public void DisplayFrame()
 {
     if (!valid)
     {
         return;
     }
     DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), device_type);
 }
Exemple #2
0
 private void UpdateLCDPicture(Form form)
 {
     try
     {
         int    wid = form.Width;
         int    hgt = form.Height;
         Bitmap bm  = new Bitmap(wid, hgt);
         form.DrawToBitmap(bm, new System.Drawing.Rectangle(0, 0, wid, hgt));
         DMcLgLCD.LcdUpdateBitmap(_device, bm.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_QVGA);
         bm.Dispose();
     } catch (Exception ex) {
     }
 }
        private void Kodi_Applet_Load(object sender, EventArgs e)
        {
            if (DMcLgLCD.ERROR_SUCCESS == DMcLgLCD.LcdInit())
            {
                connection = DMcLgLCD.LcdConnectEx("Kodi Media Keys", 0, 0); // Initializes the display with a useful name to identify the application

                if (DMcLgLCD.LGLCD_INVALID_CONNECTION != connection)
                {
                    device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_QVGA);

                    if (DMcLgLCD.LGLCD_INVALID_DEVICE == device) // Determines whether or not the keyboard is a G15 or G19 (currently the application is only tested on a G15)
                    {
                        device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_BW);
                        if (DMcLgLCD.LGLCD_INVALID_DEVICE != device)
                        {
                            deviceType = DMcLgLCD.LGLCD_DEVICE_BW;
                        }
                    }
                    else
                    {
                        deviceType = DMcLgLCD.LGLCD_DEVICE_QVGA;
                    }

                    if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType)
                    {
                        LCD = new Bitmap(160, 43); // Sets the screen size of the keyboard display
                        Graphics g = Graphics.FromImage(LCD);
                        g.Clear(Color.White);
                        g.Dispose();

                        DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_BW);
                        DMcLgLCD.LcdSetAsLCDForegroundApp(device, DMcLgLCD.LGLCD_FORE_YES);

                        pbLCD.Width  = 160; // Sets the picture box display (that is shown when the user double clicks the icon).
                        pbLCD.Height = 43;
                    }

                    if (deviceType > 0) // Only update the screen if there is a screen to update.
                    {
                        DMcLgLCD.LcdSetConfigCallback(cfgCallback);

                        updateTimer = new System.Timers.Timer(100);

                        updateTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);

                        updateTimer.Interval = 100; // Wil. update the display every 100ms. Likely only required to use a value of 1000. This is required to update the current song time.
                        updateTimer.Enabled  = true;
                    }
                }
            }
        }
Exemple #4
0
        private void Render(int LCDType = DMcLgLCD.LGLCD_DEVICE_QVGA)
        {
            if (this.Screens[this.currentScreen] == null)
            {
                return;
            }

            this.LCD = this.Screens[this.currentScreen];
            if (this.currentScreen > LCD_SCREEN_LOADING)
            {
                addHintText(ref this.LCD);
            }
            DMcLgLCD.LcdUpdateBitmap(this.device, this.LCD.GetHbitmap(), LCDType);
            DMcLgLCD.LcdSetAsLCDForegroundApp(this.device, DMcLgLCD.LGLCD_FORE_YES);
        }
        public void Render()
        {
            #region Clear and draw background

            Graphics g = Graphics.FromImage(LCD);
            g.Clear(Color.Black);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

            #endregion

            #region Draw to the screen
            LetterMgr.Instance.Render(g);
            g.DrawString(string.Format("{0}/{1}/{2}", LetterMgr.Instance.CorrectAnswersGiven, LetterMgr.Instance.LettersDone, LetterMgr.Instance.TotalLetters), GFont, Brushes.White, 0, 0);

            if (LetterMgr.Instance.State == eState.WrongChoice)
            {
                g.DrawImage(ErrorImg, ScreenRect);
            }
            else if (LetterMgr.Instance.State == eState.GoodChoice)
            {
                g.DrawImage(CorrectImg, new Rectangle(40, 0, 240, 240));
            }
            #endregion

            #region Send to LCD

            if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType)
            {
                DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_BW);
            }
            else
            {
                DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_QVGA);
            }

            #endregion

            #region Clean up

            g.Dispose();

            #endregion
        }
        public void RenderLoadingScreen(string loadText)
        {
            Graphics g = Graphics.FromImage(LCD);

            g.DrawImage(LoadingImg, ScreenRect);
            SizeF measure = g.MeasureString(loadText, GFont);

            g.DrawString(loadText, GFont, Brushes.White, 160 - measure.Width / 2, 185);
            g.Dispose();

            #region Send to LCD

            if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType)
            {
                DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_BW);
            }
            else
            {
                DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_QVGA);
            }

            #endregion
        }
        private void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            Font sFont;

            Graphics g = Graphics.FromImage(LCD); // Creates a graphics for the display

            g.Clear(Color.White);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

            sFont = new Font("Arial", 7, FontStyle.Regular); // Creates a font that is used to write to the display. Should be able to change this to whatever you want to use.

            if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType)
            {
                RectangleF rtTitle = new RectangleF(0, 20, 24, 10); // Writes all the information that the RPC has returned to the display using the font specified above.
                g.DrawString("Album: " + album, sFont, Brushes.Black, 0, 0);
                g.DrawString("Artist: " + artist, sFont, Brushes.Black, 0, 10);
                g.DrawString(title, sFont, Brushes.Black, rTitle);
                g.FillRectangle(Brushes.White, rtTitle);
                g.DrawString("Title: ", sFont, Brushes.Black, rtTitle);
                g.DrawString("Duration: " + cTime + " / " + tTime, sFont, Brushes.Black, 0, 30);
                DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_BW);

                #region
                int   charsTitle = 0;
                SizeF stringSize;

                if (title != null)
                {
                    charsTitle   = title.Length;
                    stringSize   = g.MeasureString(title, sFont);
                    rTitle.Width = stringSize.Width;
                }

                if (charsTitle > maxCharsTitle)
                {
                    if (!reverseTitle)
                    {
                        if (tmpLocationX >= -rTitle.Width + 150)
                        {
                            tmpLocationX = (int)rTitle.X - 1;
                            if (tmpLocationX <= -rTitle.Width + 150)
                            {
                                reverseTitle = true;
                            }
                        }
                    }
                    else
                    {
                        tmpLocationX = (int)rTitle.X + 1;
                        if (tmpLocationX >= 30)
                        {
                            reverseTitle = false;
                        }
                    }
                    rTitle.X = tmpLocationX;
                }
                else
                {
                    //Console.WriteLine(rtTitle.Width);
                    rTitle.X = rtTitle.Width;
                }
                #endregion
            }

            pbLCD.Image = LCD;

            sFont.Dispose(); // Disposes the fonts and graphics after the values were displayed on the screen.
            g.Dispose();

            bool audioPlaying = checkAudio(); // Checks to determine whether the audio is currently playing or not, which is then used to update the balloon.

            if (audioPlaying)
            {
                if (artist != "")
                {
                    if (title != previousSong) // Only display the balloon popup on a new song.
                    {
                        ResetTitleBox();
                        BalloonTimer();
                    }
                }

                btnRequest_Click(this, null); // Requests the song information. Required because the song updates the time every second.
            }
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            if (DMcLgLCD.ERROR_SUCCESS == DMcLgLCD.LcdInit())
            {
                Instance = this;
                LetterMgr.Instance.Init();

                SettingsMgr.Instance.Load();
                if (SettingsMgr.Instance.IsFirstRun)
                {
                    SettingsMgr.Instance.IsFirstRun = false;
                    SettingsMgr.Instance.Save();
                    try
                    {
                        AutoStart.SetAutoStart();
                    }
                    catch
                    {}
                }

                LCDShotFolder = string.Format("{0}/LCD Shots/", Application.StartupPath);
                if (!Directory.Exists(LCDShotFolder))
                {
                    Directory.CreateDirectory(LCDShotFolder);
                }

                Visible       = false;
                ShowInTaskbar = false;

                #region Tray
                if (SettingsMgr.Instance.UseTrayIcon)
                {
                    TrayMenu = new ContextMenu();
                    TrayMenu.MenuItems.Add("Take LCD &Shot", OnLCDShot);
                    TrayMenu.MenuItems.Add("&Config", OnConfig);
                    TrayMenu.MenuItems.Add("-");
                    TrayMenu.MenuItems.Add("&Exit", OnExit);
                    TrayIcon      = new NotifyIcon();
                    TrayIcon.Text = "Learn Japanese";

                    TrayIcon.Icon = new Icon(Application.StartupPath + "/Icon.ico", 32, 32);

                    // Add menu to tray icon and show it.
                    TrayIcon.ContextMenu = TrayMenu;
                    TrayIcon.Visible     = true;
                }
                #endregion

                #region Font

                if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType)
                {
                    GFont = new Font("Arial", 5, FontStyle.Regular);
                }
                else
                {
                    GFont = new Font("Arial", 12, FontStyle.Regular);
                }
                #endregion

                connection = DMcLgLCD.LcdConnectEx("Learn Japanese", 0, 0);

                if (DMcLgLCD.LGLCD_INVALID_CONNECTION != connection)
                {
                    device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_QVGA);

                    if (DMcLgLCD.LGLCD_INVALID_DEVICE == device)
                    {
                        device = DMcLgLCD.LcdOpenByType(connection, DMcLgLCD.LGLCD_DEVICE_BW);
                        if (DMcLgLCD.LGLCD_INVALID_DEVICE != device)
                        {
                            deviceType = DMcLgLCD.LGLCD_DEVICE_BW;
                        }
                    }
                    else
                    {
                        deviceType = DMcLgLCD.LGLCD_DEVICE_QVGA;
                    }

                    if (DMcLgLCD.LGLCD_DEVICE_BW == deviceType)
                    {
                        LCD = new Bitmap(160, 43);
                        Graphics g = Graphics.FromImage(LCD);
                        g.Clear(Color.White);
                        g.Dispose();

                        DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_BW);
                        DMcLgLCD.LcdSetAsLCDForegroundApp(device, DMcLgLCD.LGLCD_FORE_YES);
                    }
                    else
                    {
                        LCD = new Bitmap(320, 240);
                        Graphics g = Graphics.FromImage(LCD);
                        g.Clear(Color.White);
                        g.Dispose();

                        DMcLgLCD.LcdUpdateBitmap(device, LCD.GetHbitmap(), DMcLgLCD.LGLCD_DEVICE_QVGA);
                        DMcLgLCD.LcdSetAsLCDForegroundApp(device, DMcLgLCD.LGLCD_FORE_YES);
                    }

                    if (deviceType > 0)
                    {
                        //commented out in favor of polling routine.
                        //DMcLgLCD.LcdSetButtonCallback(btnCallback);
                        DMcLgLCD.LcdSetConfigCallback(cfgCallback);
                        //The fastest you should send updates to the LCD is around 30fps or 34ms.  100ms is probably a good typical update speed.
                        timInput.Enabled = true;
                    }
                    timWorkaround.Enabled = true; // sometimes the LCD just shows a white screen for some reason on startup. this 100ms delay fixes that.
                }
            }
            else
            {
                MessageBox.Show("Error: The G-keyboard was not detected. The application will not close.",
                                "Hardware not found.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
        }