Announcement

Collapse
No announcement yet.

txt_MoveCursor() problem

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

  • txt_MoveCursor() problem

    Hi, i am doing a qwerty keyboard, thanks to 4D Systems for helping me whit the graphic composer. I am trying to do the backspace function but i founded lots of issues. For example, txt_MoveCursor() doesnt change when i put the screen on landscape mode it keeps whit portrait mode: this is column (horizontal)^ this is line (vertical) | |I found that so i correct it in my program but i am getting and extrange behaviour, for example i write a text, the keys are returned by the function get qwerty, the function return the character pressed, returns -1 if no one pressed: gfx_Cls(); gfx_Set(SCREEN_MODE, LANDSCAPE); txt_MoveCursor(0,0); txt_Set(FONT_SIZE, FONT3); txt_Set(TEXT_OPACITY, OPAQUE); txt_FGcolour(WHITE); img_Show(img_qwerty,ALL); txt_Wrap(280); repeat j := get_qwerty(); if(j == BACKSPACE) if(cursor_x > 0) --cursor_x; txt_MoveCursor(cursor_y,cursor_x); endif putch(' '); else if(j == BACK) gfx_Set(SCREEN_MODE,PORTRAIT); return;
    else
    if(j != -1)
    print( [CHR] j);
    ++cursor_x;
    endif
    endif
    forever

    What i do is to count in a variable i have the actual position of the cursor. If press BACKSPACE key i return 1 cursor position and put ' ' to delete de previous character and when i put that ' ' the cursor is increased by one. The problem i am having is that when i write the text and press BACKSPACE for the first time it delete ok:
    Hello people how are you

    When i press BACKSPACE five times for example:
    Hello people how ar

    But when i write again:
    Hello people how ar e

    And the when i delete 2 times for example:
    Hello people how a e

    Hope you can understand me. I think the problems comes from the first time, if i delete and when i write again it write whit an space the cursor i am counting is diferent from the real one in the LCD. So the obvious solution is to add this:
    --cursor_x;
    txt_MoveCursor(cursor_y,cursor_x);

    After putch(' '); but it is what happen:
    Hello people how are you

    I press BACKSPACE once
    Hello people how are yo

    One more time:
    Hello people how are o

    And when i write:
    Hello people how arey o

    It strange, hope you can understand me.

  • #2


    Gee, I'd typed up a reply but lost it when you deleted the original copy of this and reposted it.

    So I'm not going to retype it.

    Just have a think about where X and Y are after the putch(' ') ;
    Mark

    Comment


    • #3


      :S :S sorry i clicked wrong i wanted to click on preview and click on post is there any way to recover it?
      I suppose if Y doesnt change X should be on the right side of the space putch(' '), if i delete the cursor is in the right side of the letter i have deleted and when i write putch th cursor is in the right side of that ' ' right?

      Comment


      • #4


        Right, and where should it be and where is it relevant to cursor_x and cursor_y? You want them to be the same don't you?
        Mark

        Comment


        • #5


          The cursor must be in the left side of the character i have just deleted. So when i return 1 position i am behind the character i want to delete, the i print putch(' ') so i am in the right side of the character i have just deleted and then to come back where i start i return the position which was increased because i print putch(' ') that is how it work but for some reason always apear an error it doesnt have sense.

          Comment


          • #6


            Gee, you may have described the process correctly, but that's not what your code does
            Mark

            Comment


            • #7


              gfx_Cls(); gfx_Set(SCREEN_MODE, LANDSCAPE); txt_MoveCursor(0,0); txt_Set(FONT_SIZE, FONT3); txt_Set(TEXT_OPACITY, OPAQUE); txt_FGcolour(WHITE); img_Show(img_qwerty,ALL); txt_Wrap(280); repeat j := get_qwerty(); if(j == BACKSPACE) if(cursor_x > 0) --cursor_x; txt_MoveCursor(cursor_y,cursor_x); endif putch(' '); if(cursor_x > 0) --cursor_x; txt_MoveCursor(cursor_y,cursor_x); endif
              else if(j == BACK)
              gfx_Set(SCREEN_MODE,PORTRAIT);
              return;

              else
              if(j != -1)
              print( [CHR] j);
              ++cursor_x;
              endif
              endif
              forever

              That should be the correct way, i decrease a position, write, and then decrease again but i have the error :S.

              Comment


              • #8


                Well that will be different to you last try, but it's still not right.

                Try walking through your code, writing down changes in variables and cursor positions on a piece of paper.
                Mark

                Comment


                • #9


                  There is any way of see the cursor position of the LCD? No pixel position, cursor position. Because when i write the character i increase my cursor_x because i suppose that cursor of the LCD is increased right? But what increase the LCD line or column because they are inverted in landscape

                  Comment


                  • #10


                    You could always putputch('_');
                    txt_MoveCursor(cursor_y,cursor_x);

                    at the start of your main loop.

                    Not only will it show you were you are going wrong, but even the code itself give a hint as to why you are going wrong.
                    Mark

                    Comment


                    • #11


                      Please have a look at the serialKeypad.4DG demo to get some fundamental understanding. (look at the updateTextBuf() function)
                      Regards,
                      Dave

                      Comment


                      • #12


                        gfx_Cls(); gfx_Set(SCREEN_MODE, LANDSCAPE); txt_MoveCursor(0,0); txt_Set(FONT_SIZE, FONT3); txt_Set(TEXT_OPACITY, OPAQUE); txt_FGcolour(WHITE); img_Show(img_qwerty,ALL); txt_Wrap(280); repeat j := get_qwerty(); if(j == BACKSPACE) if(cursor_x > 0) --cursor_x; txt_MoveCursor(cursor_y,cursor_x); endif putch(' '); txt_MoveCursor(cursor_y,cursor_x); endif
                        else if(j == BACK)
                        gfx_Set(SCREEN_MODE,PORTRAIT);
                        return;

                        else
                        if(j != -1)
                        print( [CHR] j);
                        ++cursor_x;
                        endif
                        endif
                        forever

                        This is the right way because i decrement my cursor and the cursor of the LCD, when i write it increase the LCD cursor and i wasnt increasing my cursor, now i return to the last position i was just behind the character i deleted .
                        Thanks

                        Comment

                        Working...
                        X