Announcement

Collapse
No announcement yet.

Text Overlap Instead of Text Overwrite When Using Image Backgrounds

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Text Overlap Instead of Text Overwrite When Using Image Backgrounds

    Hi,

    I own a ulcd-50dt and am working on a part of my project involving printing characters to the screen as I type them. When I am using an image background, the characters remain on the screen regardless of using the backspace key and instead moves the cursor back. When I am using a color background, the characters are removed with the backspace key. I cannot figure out a way around this so any help would be much appreciated.

    MagicCode0.inc
    Code:
    func resetChars()
        var i;
        for(i := 0; i < 30; i++)
            char[i] := 0;
        next
        txt_MoveCursor(3,0);
        print("                              ");
        txt_MoveCursor(3,0);
        counter := 0;
    endfunc
    
    func printStr()
        var i;
        str := str_Ptr(char);
        txt_MoveCursor(1,13);
        txt_Set(TEXT_WIDTH, 2);
        txt_Set(TEXT_HEIGHT, 3);
        print("                              ");
        txt_MoveCursor(1,13);
        for( i := 0; i < 30; i++)
            putch(char[i]);
        next
    endfunc
    
    var char[30]; // Variable to store keyboard values
    var str;
    var counter := 0; //Variable to count total number of keyboard inputs
    MagicKbClrEvent0.inc
    Code:
    func rMagicKbClrEvent0(var reportID, var objType, var objHash, var value)
        txt_Set(TEXT_WIDTH, 2);
        txt_Set(TEXT_HEIGHT, 3);
        if((value>=32) && (value<=126) && counter <30)   //check of characters are input and if less than 30
            char[counter] := value; //store keyboard value to character array
            txt_MoveCursor(3, counter);
            putch(char[counter]);   //print value
            counter++;              //to increment index of array everytime an input from keyboard is recieved
        else if(value == 8)         //check if backspace is pressed
            if(counter)             //check if counter is not less than 0
                counter--;          //decrement array index
                char[counter] := 0; //store NULL to array
                txt_MoveCursor(3, counter); //Move Cursor to character that will be deleted
                putch(' ');                 //Replace with Space ' '
                txt_MoveCursor(3, counter); //Move Cursor to replace Space if a character key is pressed
            endif
        else if(value == 13)
            txt_MoveCursor(3,0);
            printStr();
            resetChars();
        endif
    
    endfunc
    P.S. Any of my attempts to use putStrCentred only prints one character from the char[30] array. Eventually I will need to send this string to my arduino so I'm not sure whether the char array or a string would be better.

  • #2
    Hello and welcome to the forum

    Yes this is normal behaviour when printing on an image as the space will have no effect. When using a coloured background the text background colour is the same as the background and gets drawn with each character so when you print a space you are actually drawing a rectangle of that colour.

    We have a library that can draw just part of your background image, it isn't lightning fast at doing this but for text it will be more than acceptable. The only issue you will have is that the txt_MoveCursor may not work that well for you and you might have to change to gfx_MoveTo calculating each new position of a printed character.

    So if I wanted to print a space at pixel co-ordinates 100, 100 of size 8 x 16, and assuming Form1 was the background image I would use this command from the library,

    img_UserImageDR(hndl , iForm1, 100, 100, 8, 16, 100, 100); //This will draw the rectangular segment of the image from pixel co-ordinates 100, 100 and size of 8 x 16 in the same position 100, 100

    You will need to add this line to your magic code in the Globals/Data area

    #inherit "gfxFunctions.inc"

    I have attached the library below and you will need to extract this to your project folder

    I hope this makes sense and you can use the method.

    Best regards

    Paul
    Attached Files

    Comment


    • #3
      Ah. That makes since. Thanks for getting back to me so quickly. I will your gfx library a shot. Also, what is the best way to convert the char[30] into a string so that I can use putStrCentred in my printStr() function?

      Comment


      • #4
        I've posted below how I managed to convert the character array to a string if anyone is interested.

        MagicCode0.inc
        Code:
        //
        // Added 4/9/2015 11:46:29 AM
        //
        // MagicCode0
        //
        
        #inherit "gfxFunctions.inc"
        
        func resetChars()
            var i;
            for(i := 0; i < 30; i++)
                char[i] := 0;
            next
            img_UserImageDR(hndl , iForm3, 0, 150, 600, 45, 0, 150);
            txt_MoveCursor(3,0);
            counter := 0;
        endfunc
        
        func printStr()
            var i;
            strPtr := str_Ptr(str);
            txt_MoveCursor(1,13);
            txt_Set(TEXT_WIDTH, 2);
            txt_Set(TEXT_HEIGHT, 3);
            img_UserImageDR(hndl , iForm3, 0, 150, 600, 45, 0, 150);
            putstrCentred(400, 80, str);
        endfunc
        
        func charToStr()
            var i;
            strPtr := str_Ptr(str);
            for(i := 0; i <= counter; i++) str_PutByte(strPtr + i, char[i]);
        endfunc
        
        var char[30]; // Variable to store keyboard values
        var str[15];  // variable to hold converted string
        var strPtr;     // pointer to str
        var counter := 0; //Variable to count total number of keyboard inputs

        Comment

        Working...
        X