Horizontal scrolling

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
niston
LCD Geek
Posts: 24
Joined: Thu Sep 25, 2014 4:55 pm

Horizontal scrolling

Post by niston » Fri Sep 26, 2014 4:31 am

I need to implement horizontal scrolling i.e. just a portion of a line of text. Now I could work with string manipulation, but I'm using a proportional font, so a string of a given length (in chars) doesn't always fill the same space on the display (in pixels). I prefer not to use a fixed-width font due to space constraints.

I really think there should be support in the display to scroll, say a label, and I wonder if it's maybe an oversight on my part and I just couldn't find the right commands to do it in the manual. If there is however no support for this on the display, I need a way to determine the actual length of a given string in pixels, using a given font.

I think I could parse the font files for the character width information, but maybe there's an easier way to achieve horizontal scrolling in a label?

Also I'm reluctant to implement this on the host as it will be messy: How does the host know which font ID on the display corresponds to what font file? And why should the host have to care? This should really be done right on the display!

niston
LCD Geek
Posts: 24
Joined: Thu Sep 25, 2014 4:55 pm

Re: Horizontal scrolling

Post by niston » Fri Sep 26, 2014 6:49 am

Here's my C# code for horizontal text scrolling for fixed-width fonts (such as default font #1). Enjoy :)

Code: Select all

            if (_ArtistAndTitle.Length > 27)
            {
                // increase current start position
                _artistTitleScrollPosition++;

                // add spacers to the artist/title
                string lineText  = "   " + _ArtistAndTitle + "        ";
                
                // take string from start position
                string lineDisplay = lineText.Substring(_artistTitleScrollPosition);
                
                // result is shorter than line length?
                if (lineDisplay.Length < 27)
                {
                    // fill up, restarting at position 0
                    lineDisplay = lineDisplay + lineText.Substring(0, 27 - lineDisplay.Length);
                }

                if (lineDisplay.Length > 27)
                {
                    // truncate to line length
                    lineDisplay = lineDisplay.Left(27);
                }

                if (_artistTitleScrollPosition == lineText.Length)
                {
                    // wrap over if end of string reached
                    _artistTitleScrollPosition = 0;
                }

                // cursor to 1,17
                Send(new byte[] { 254, 121, 1, 17 });
                // set default font
                Send(new byte[] { 254, 49, 1, 0 });
                // cursor to 1,30
                Send(new byte[] { 254, 121, 1, 30 });
                // write title & artist
                Send(lineDisplay);
            }
Some notes:
- The code is designed to run from a timer event (example: every 500ms)
- The assumed max number of chars per line is 27 (for default font #1). change accordingly!
- _ArtistAndTitle is the string variable containing the line to display
- _artistTitleScrollPosition++ is a global int variable (you must add) used to track scrolling position
- the code every time the code runs, it will advance scrolling by one char

I still need something for proportional font scrolling. Ideas, anyone?

Clark
Matrix Orbital
Matrix Orbital
Posts: 859
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Re: Horizontal scrolling

Post by Clark » Fri Sep 26, 2014 1:07 pm

Hi Niston,

For a scrolling, or marquee effect, a fixed width font is definitely preferred. Your GLK19264 ships with a Small Filled font in slot 1 which is a monospaced and 6x7 pixels size. It also has a Scroll Screen command which should work well for this application. I wrote up a quick demo to showcase marquee style text scrolling on the GLK19264.

Code: Select all

        public void MarqueeText(byte x, byte y, byte width, string message, int delay, int count)
        {
            byte character_width = 6;
            byte character_height = 7;  //Use Small Filled, Default Font 1
            byte character_x_position = (byte)(x + width - character_width);
            int length = message.Length;
            char[] characters = message.ToCharArray();
            testDisplay.SelectFont(1);
            testDisplay.FillRectangle(MonoColour.Inactive, x, y, (byte)(x + width), (byte)(y + character_height));
            for (int i = 0; i < count; i++)
            {
                foreach (char character in characters)
                {
                    testDisplay.SetCursorCoordinate(character_x_position, y);
                    testDisplay.WriteString(new string(character, 1));
                    System.Threading.Thread.Sleep(delay);
                    testDisplay.ScrollScreen(x, y, (byte)(x + width), (byte)(y + character_height), (short)(-character_width), 0);
                }
                for(int j = 0; j < (width / character_width); j ++)
                {
                    System.Threading.Thread.Sleep(delay);
                    testDisplay.ScrollScreen(x, y, (byte)(x + width), (byte)(y + character_height), (short)(-character_width), 0);
                }
            }
        }
The function call I've chosen scrolls a simple Hello World! message across the centre of the screen three times, with a 250ms delay between characters to keep the effect visible.

Code: Select all

scrollingTest.MarqueeText(71, 29, 50, "Hello World!", 250, 3);
Unfortunately, we can only pack a fraction of the power available on a PC into the GLK19264, and while it does allow for a number of advanced features, text scrolling is a rather intensive operation for the display to handle. Given a fixed width font, implementation on the PC side can be quite clean.

Cheers,
Troy
Troy Clark
Design & Development
Matrix Orbital

niston
LCD Geek
Posts: 24
Joined: Thu Sep 25, 2014 4:55 pm

Re: Horizontal scrolling

Post by niston » Fri Sep 26, 2014 1:42 pm

Clark wrote:For a scrolling, or marquee effect, a fixed width font is definitely preferred.
Simpler, yes. Preferred, no :P
Unfortunately, fixed width fonts waste a lot of precious screen space.
Clark wrote:It also has a Scroll Screen command which should work well for this application.
Exactly what I've been looking for, FE 59. Thanks for the pointer!
Clark wrote: Unfortunately, we can only pack a fraction of the power available on a PC into the GLK19264
I see. What kind of controller does it use? ATmega? PIC? Something more exotic perhaps? Just curious... Anyway, I shall see about parsing character width information from a font file. This will have to be properly set up, but should enable us then to use proportional fonts. Will post code here, I guess :)

Clark
Matrix Orbital
Matrix Orbital
Posts: 859
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Re: Horizontal scrolling

Post by Clark » Fri Sep 26, 2014 3:21 pm

Hi Niston,

It sounds like you have a direction now, I'll leave you to writing the code.

If you're looking for the character size information for a specific font, any time a font is generated in MOGD# a folder containing an image for every character is created in the ...\Program Files (x86)\Matrix Orbital\MogdSharp\Fonts directory. Alternatively, you can download any font file from the display and parse the header for character data using the information in your manual.

Of course, we'd love to see any code you'd be willing to share once it's all done.

We always appreciate customer feedback and will make improvements where we can. The new GLK19264 units were recently upgraded to a more exotic LPC1700 series controller from NXP. It does have more processing power than the old Atmega164P, but I can't confirm that it will afford the resources required to implement full text scrolling on the display side.

Cheers,
Troy
Troy Clark
Design & Development
Matrix Orbital

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest