Main Site Documentation

SimpleGraphics ClearLine function


#1

In celebration of my recent promotion from “noob” to “minor” (is there a raise involved? ;)), I thought I’d share a solution for my fellow “nobs” and “minors”.

Given the limited real estate (320x240) in the T35 display, it makes sense to rewrite various lines to change button, network, etc. state indications, rather than clear and redraw the entire display.

The first problem is that you can’t simply call DisplayText in the same location as the previously-written line because instead of a complete overwrite of he original text, you actually get a merge of the previous and current text on that line (original function follows).


       void ClearLine(uint x, uint y, Font FontName)
        {
            string CleanText = new string(' ', SystemMetrics.ScreenWidth / FontName.CharWidth(' '));
            display.SimpleGraphics.DisplayText(CleanText,FontName,GT.Color.Black,x,y);
        }

The main problem with that method is that you can’t simply overwrite the previous text with “spaces” as you would a “normal” text display, either. The method call appears to work (no errors, etc.), but the original text remains; even if I call Redraw(). While this may be a problem only for the “space” character in the default tinyfonts provided in the Spider, it also means that I’d need to understand the contents of the selected font in order to find an appropriate “fill” character. t’ain’t happenin…

The solution turned out to be a minor “duh” moment. Instead of calling DisplayText, I should be using DisplayRectangle, with the forground and fill colors set to match the background color.

The working function follows:


        private void ClearLine(uint Xpos, uint Ypos, Font thisfont)
        {
            display.SimpleGraphics.DisplayRectangle(display.SimpleGraphics.BackgroundColor, 
                                                    1, 
                                                    display.SimpleGraphics.BackgroundColor, 
                                                    Xpos, 
                                                    Ypos, 
                                                    (uint)display.SimpleGraphics.Width-Xpos, 
                                                    (uint)thisfont.Height);
        }

…works like a charm…