Glide for T43

Hello,

I would like to modify the Glide source to make it possible to load and use a larger keyboard.

Besides enlarging the 4 gif keyboard image resources loaded in Glide.DefaultKeyboard(), and have modifying the sizes in Keyboard.DefaultKeyWidth(), does anyone know what other modifications will be required in order to achieve resizing of the keyboard.

Many thanks

You can use the existing GLIDE in the SDK and just remap the keyboard. I use this for my 800 x 480 LCD. You’ll need to make changes to support your 4.3 and include the BITMAPS in your resources.

Actually, there used to be source and bitmaps for the 4.3 on the GHI website but I can’t find it now.

Just make this call at the start of your programme to tell Glide which keyboard to use.


Glide.Keyboard = CreateKeyboard();


        static Keyboard CreateKeyboard()
        {
            Keyboard keyboard = new Keyboard(680, 272, 3, 68, 0);

            keyboard.BitmapUp = new Bitmap[4]
            { 
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_680x272_Uppercase_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_680x272_Lowercase_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_680x272_Numbers_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_680x272_Symbols_small), Bitmap.BitmapImageType.Gif)
            };           
            // set the default key content.

            string[][] keyContent = new string[4][];

            // letters
            keyContent[0] = new string[10] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p" };
            keyContent[1] = new string[9] { "a", "s", "d", "f", "g", "h", "j", "k", "l" };
            keyContent[2] = new string[9] { Keyboard.ActionKey.ToggleCase, "z", "x", "c", "v", "b", "n", "m", Keyboard.ActionKey.Backspace };
            keyContent[3] = new string[5] { Keyboard.ActionKey.ToNumbers, ",", Keyboard.ActionKey.Space, ".", Keyboard.ActionKey.Return };
            keyboard.SetViewKeyContent(Keyboard.View.Letters, keyContent);

            // numbers
            keyContent[0] = new string[10] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
            keyContent[1] = new string[10] { "@ ", "#", "$", "%", "&", "*", "-", "+", "(", ")" };
            keyContent[2] = new string[9] { Keyboard.ActionKey.ToSymbols, "!", "\"", "'", ":", ";", "/", "?", Keyboard.ActionKey.Backspace };
            keyContent[3] = new string[5] { Keyboard.ActionKey.ToLetters, ",", Keyboard.ActionKey.Space, ".", Keyboard.ActionKey.Return };
            keyboard.SetViewKeyContent(Keyboard.View.Numbers, keyContent);

            // symbols
            keyContent[0] = new string[10] { "~", "`", "|", "•", "√", "π", "÷", "×", "{", "}" };
            keyContent[1] = new string[10] { Keyboard.ActionKey.Tab, "£", "¢", "€", "º", "^", "_", "=", "[", "]" };
            keyContent[2] = new string[9] { Keyboard.ActionKey.ToNumbers, "™", "®", "©", "¶", "\\", "<", ">", Keyboard.ActionKey.Backspace };
            keyContent[3] = new string[5] { Keyboard.ActionKey.ToLetters, ",", Keyboard.ActionKey.Space, ".", Keyboard.ActionKey.Return };
            keyboard.SetViewKeyContent(Keyboard.View.Symbols, keyContent);

            // or we could just call this:
            // keyboard.DefaultKeyContent();

            int[][] keyWidth = new int[4][];

            // Each array entry represents a row of keys on the keyboard top-down (0-3)
            // Each array within these entries contains the widths of the keys for that row.
            // For example: keyWidth[0] = new int[10] { 68, 68, 68, 68, 68, 68, 68, 68, 68, 68 }
            // represents the first row (0) which contains the keys Q, W, E, R, T, Y, U, I, O, P

            // Letters
            keyWidth[0] = new int[10] { 68, 68, 68, 68, 68, 68, 68, 68, 68, 68 };
            keyWidth[1] = new int[9] { 68, 68, 68, 68, 68, 68, 68, 68, 68 };
            keyWidth[2] = new int[9] { 102, 68, 68, 68, 68, 68, 68, 68, 102 };
            keyWidth[3] = new int[5] { 102, 68, 340, 68, 102 };

            keyboard.SetViewKeyWidth(Keyboard.View.Letters, keyWidth);

            // Numbers
            keyWidth[0] = new int[10] { 68, 68, 68, 68, 68, 68, 68, 68, 68, 68 };
            keyWidth[1] = new int[10] { 68, 68, 68, 68, 68, 68, 68, 68, 68, 68 };
            keyWidth[2] = new int[9] { 102, 68, 68, 68, 68, 68, 68, 68, 102 };
            keyWidth[3] = new int[5] { 102, 68, 340, 68, 102 };

            keyboard.SetViewKeyWidth(Keyboard.View.Numbers, keyWidth);

            // Symbols
            keyWidth[0] = new int[10] { 68, 68, 68, 68, 68, 68, 68, 68, 68, 68 };
            keyWidth[1] = new int[10] { 68, 68, 68, 68, 68, 68, 68, 68, 68, 68 };
            keyWidth[2] = new int[9] { 102, 68, 68, 68, 68, 68, 68, 68, 102 };
            keyWidth[3] = new int[5] { 102, 68, 340, 68, 102 };

            keyboard.SetViewKeyWidth(Keyboard.View.Symbols, keyWidth);

            keyboard.CalculateKeys();
            return keyboard;
        }

@ Dave - Thank you for your detailed response.

I created a small test app, Glide1, with a static class Util, containing the code.

After ensuring that the 4 gif files are 480 x 192, with each button 48 x 48, I modified the code in the CreateKeyboard() method you provided, accordingly, as below.

An exception occurs when the code attempts to load the first gif file.

“An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Graphics.dll”

" #### Exception System.Exception - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Bitmap::.ctor [IP: 0000] ####
#### Glide1.Util::CreateKeyboard [IP: 0029] ####
#### Glide1.Program::Main [IP: 0016] ####
A first chance exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Graphics.dll
An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Graphics.dll"

I stepped throught the code and noticed that the exception occurs just after the first "new Bitmap)…"
keyboard.BitmapUp = new Bitmap[4]
{
new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Uppercase_large), Bitmap.BitmapImageType.Gif),

Do you perhaps have any further ideas regarding what may be causing this, and how to get past it?

Many thanks.


       // modified code
        public static Keyboard CreateKeyboard()
        {
            Keyboard keyboard = new Keyboard(480, 192, 3, 48, 0);

            keyboard.BitmapUp = new Bitmap[4]
            { 
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Uppercase_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Lowercase_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Numbers_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Symbols_small), Bitmap.BitmapImageType.Gif)
            };
            // set the default key content.

            string[][] keyContent = new string[4][];

            // letters
            keyContent[0] = new string[10] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p" };
            keyContent[1] = new string[9] { "a", "s", "d", "f", "g", "h", "j", "k", "l" };
            keyContent[2] = new string[9] { Keyboard.ActionKey.ToggleCase, "z", "x", "c", "v", "b", "n", "m", Keyboard.ActionKey.Backspace };
            keyContent[3] = new string[5] { Keyboard.ActionKey.ToNumbers, ",", Keyboard.ActionKey.Space, ".", Keyboard.ActionKey.Return };
            keyboard.SetViewKeyContent(Keyboard.View.Letters, keyContent);

            // numbers
            keyContent[0] = new string[10] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
            keyContent[1] = new string[10] { "@ ", "#", "$", "%", "&", "*", "-", "+", "(", ")" };
            keyContent[2] = new string[9] { Keyboard.ActionKey.ToSymbols, "!", "\"", "'", ":", ";", "/", "?", Keyboard.ActionKey.Backspace };
            keyContent[3] = new string[5] { Keyboard.ActionKey.ToLetters, ",", Keyboard.ActionKey.Space, ".", Keyboard.ActionKey.Return };
            keyboard.SetViewKeyContent(Keyboard.View.Numbers, keyContent);

            // symbols
            keyContent[0] = new string[10] { "~", "`", "|", "•", "v", "p", "÷", "×", "{", "}" };
            keyContent[1] = new string[10] { Keyboard.ActionKey.Tab, "£", "¢", "€", "º", "^", "_", "=", "[", "]" };
            keyContent[2] = new string[9] { Keyboard.ActionKey.ToNumbers, "™", "®", "©", "¶", "\\", "<", ">", Keyboard.ActionKey.Backspace };
            keyContent[3] = new string[5] { Keyboard.ActionKey.ToLetters, ",", Keyboard.ActionKey.Space, ".", Keyboard.ActionKey.Return };
            keyboard.SetViewKeyContent(Keyboard.View.Symbols, keyContent);

            // or we could just call this:
            // keyboard.DefaultKeyContent();

            int[][] keyWidth = new int[4][];

            // Each array entry represents a row of keys on the keyboard top-down (0-3)
            // Each array within these entries contains the widths of the keys for that row.
            // For example: keyWidth[0] = new int[10] { 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 }
            // represents the first row (0) which contains the keys Q, W, E, R, T, Y, U, I, O, P

            // Letters
            keyWidth[0] = new int[10] { 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 };
            keyWidth[1] = new int[9] { 48, 48, 48, 48, 48, 48, 48, 48, 48 };
            keyWidth[2] = new int[9] { 72, 48, 48, 48, 48, 48, 48, 48, 72 };
            keyWidth[3] = new int[5] { 72, 48, 240, 48, 72 };

            keyboard.SetViewKeyWidth(Keyboard.View.Letters, keyWidth);

            // Numbers
            keyWidth[0] = new int[10] { 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 };
            keyWidth[1] = new int[10] { 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 };
            keyWidth[2] = new int[9] { 72, 48, 48, 48, 48, 48, 48, 48, 72 };
            keyWidth[3] = new int[5] { 72, 48, 240, 48, 72 };

            keyboard.SetViewKeyWidth(Keyboard.View.Numbers, keyWidth);

            // Symbols
            keyWidth[0] = new int[10] { 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 };
            keyWidth[1] = new int[10] { 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 };
            keyWidth[2] = new int[9] { 72, 48, 48, 48, 48, 48, 48, 48, 72 };
            keyWidth[3] = new int[5] { 72, 48, 240, 48, 72 };

            keyboard.SetViewKeyWidth(Keyboard.View.Symbols, keyWidth);

            keyboard.CalculateKeys();
            return keyboard;
        }

@ Dave - I managed to get past the bitmap issue by changing this code from


            { 
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Uppercase_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Lowercase_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Numbers_large), Bitmap.BitmapImageType.Gif),
                new Bitmap(Resources.GetBytes(Resources.BinaryResources.Keyboard_480x192_Symbols_small), Bitmap.BitmapImageType.Gif)
            };

	    // to this
	    
            keyboard.BitmapUp = new Bitmap[4]
            { 

                Resources.GetBitmap(Resources.BitmapResources.Keyboard_480x192_Up_Uppercase),
                Resources.GetBitmap(Resources.BitmapResources.Keyboard_480x192_Up_Lowercase),
                Resources.GetBitmap(Resources.BitmapResources.Keyboard_480x192_Up_Numbers),
                Resources.GetBitmap(Resources.BitmapResources.Keyboard_480x192_Up_Symbols),
            };

Now when I tap on the TextBox which causes the keyboard to load, a further exception occurs in
the DrawImage(int xDst, int yDst, Bitmap bitmap, int xSrc, int ySrc, int width, int height) method in
Graphics.cs.

#### Exception System.Exception - CLR_E_WRONG_TYPE (3) ####
#### Message: 
#### Microsoft.SPOT.Bitmap::DrawImage [IP: 0000] ####
#### Microsoft.SPOT.Bitmap::DrawImage [IP: 0014] ####
#### GHI.Glide.Display.Graphics::DrawImage [IP: 0013] ####
#### GHI.Glide.UI.Keyboard::Render [IP: 0068] ####
#### GHI.Glide.Display.DisplayObjectContainer::Render [IP: 0021] ####
#### GHI.Glide.Display.Window::Invalidate [IP: 0005] ####
#### GHI.Glide.Glide::OpenKeyboard [IP: 0068] ####
#### GHI.Glide.Display.DisplayObject::TriggerTapEvent [IP: 0014] ####
#### GHI.Glide.UI.InputBox::OnTouchUp [IP: 0032] ####
#### GHI.Glide.Display.DisplayObjectContainer::OnTouchUp [IP: 0044] ####
#### GHI.Glide.Display.Window::TouchUpEvent [IP: 0027] ####
#### GHI.Glide.TouchEventHandler::Invoke [IP: a0e7ff3c] ####
#### GHI.Glide.GlideTouch::RaiseTouchUpEvent [IP: 0009] ####
#### GHI.Glide.GlideTouch+TouchConnection::OnEvent [IP: 00d6] ####
#### Microsoft.SPOT.EventSink::ProcessEvent [IP: 0023] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####

A first chance exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Graphics.dll
An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Graphics.dll

Stepping through the code I notice a difference between how intellisense reports the bitmaps in the Render() method in
Keyboard.cs. If I mouse_over the Bitmap parameter in

        public override void Render()
        {
            int x = Parent.X + X;
            int y = Parent.Y + Y;

            Parent.Graphics.DrawRectangle(0, 0, x, y, Glide.LCD.Width, Height, 0, 0, Colors.DarkGray, 0, 0, 0, 0, 0, 255);
            Parent.Graphics.DrawImage(_bitmapX, y, BitmapUp[_bitmapIndex], 0, 0, Width, Height);

            for (int i = 0; i < _keyActive.Length; i++)
            {
                if (!_keyActive[i])
                    Parent.Graphics.DrawRectangle(_keyCoords[i], Colors.DarkGray, 200);
            }
        }

the resulting drop-down presents 4 array members as [0] {byte[33770]} , [1] {byte[33645]} , [2] {byte[33847]} , [3] {byte[33566]} , whereas while running the code which loads the 320 x 240 bitmaps, theresulting drop-down presents 4 array members as [0] {Microsoft.SPOT.Bitmap}, [1] {Microsoft.SPOT.Bitmap}, [2] {Microsoft.SPOT.Bitmap}, [3] {Microsoft.SPOT.Bitmap}.

Are you able to shed some light on what may be the problem here please.

Thanks.

@ Dave - I found the resources files to be byte[] instead of Bitmap, I had to hack the Resources.resx and Resources.Designer.cs files to correct this, because the VS2013 resources dialog does not produce the desired results when adding an image resource.

Although no further exceptions occur, and the resized keyboard is displayed, the touch functionality is incorrect. Touching the screen on the right produces a respose one or two key positions to the left, and one row above the row touched.

I assume something is still missing here. Any pointers towards resolving this will be appreciated.

Thanks.

@ andre - I have done calibration with the save option. As a test, I reload the 320 x 240 keyboard, and it works as expected.

edit:
@ andre - You were right. It appears I spoke too quickly. Thanks for the reminder.