Trouble with OUTTEXT to text window

Trouble with OUTTEXT to text window

I find it impossible to "print" a character to the bottom right position in a text window. This simple program demonstrates:

Program Trouble
use ifqwin
type (rccoord) t
call settextwindow (2, 2, 3, 11) ! set window 2 rows x 10 cols
call settextposition (1, 1, t) ! go to upper left corner
call outtext ('1234567890') ! Print to first row works OK
! Uncomment one of the following statements to print to second row
! call outtext ('1234567890') ! Shows nothing
! call outtext ('123456789') ! Works OK because last column is avoided
end program Trouble

Is there an explanation for this, or is it a bug?

publicaciones de 5 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

You need to be aware that the SETTEXTPOSITION units are relative to the start of the text window, so if your window starts in row 7, column 21, then SETTEXTPOSITION(1,2,t) will appear in window row 7, window column 22.
Also, I find that SETTEXTWINDOW(row1,col1, row2, col2) actually provides (row2-row1) rows and not (row2-row1+1), whereas it does provide
(col2-col1+1) columns. Do not ask me why, as I cannot explain it.
If you try and print to a row below the bottom of the text window, the text will be output to the last row after the text in the window is scrolled up, so you will lose the top row, and so on.

Here is some sample code to produce successive rows of 10 digits in a window positioned somewhere inside the QuickWin graphics window.
It is worth adding a break point to the code and executing it in the debugger so that you can see how the contents of TOLD and TNEW change as you proceed through the code.

Program Trouble
use ifqwin
type (rccoord) TOLD,TNEW
call settextwindow (7, 21, 11, 31) ! set window ACTUALLY GIVES ONLY 4 rows x 11 cols,
! i.e.(11-7)rows X (31-21+1) columns and not (11-7+1) rows X (31-21+1) columns.
! Do not ask me why!
call settextwindow (7, 21, 12, 31) ! set window ACTUALLY GIVE 5 rows x 11 cols
! Thus in the first SETTEXTPOSITION, the text starts in the FIRST ROW OF THE WINDOW
! and hence it appears in ROW 7 ON THe SCREEN.
! The text also starts in the SECOND COLUMN of the WINDOW, and hence in column 22 ON THE SCREEN
! Similarly for the other SETTEXTWINDOW commands.
! Using the SECOND SETTEXTWINDOW command above,
!The program positions a block of 5 rows of 11 columns starting in window row 7, window column 21.
!After completion, there will be 5 rows of 10 characters of text, successive rows beginning 1,2,3,4,5 and ending
! 0,1,2,3,4
! If you try to output beyond the window, the text inside it will scrollup to fit the next row in.
call settextposition (1, 2, TOLD) !
call outtext ('1234567890') !
call settextposition (2, 2, TNEW) !
call outtext ('2345678901') !
call settextposition (3, 2, TNEW) !
call outtext ('3456789012') !
call settextposition (4, 2, TNEW) !
call outtext ('4567890123') !
call settextposition (5, 2, TNEW) !
call outtext ('5678901234') !
! add some code to do nothing so you can see the text window
! after executing the code without debugging
do while (1.eq.1)
end do
end program Trouble


Descargar quickwintextwindow.jpg36.74 KB

Thanks for the response Anthony, but I have to disagree with you. Why do you think that SETTEXTWINDOW (R1, C1, R2, C2, T) only gives R2-R1 rows, not R2-R1+1? If you call CLEARSCREEN ($GWINDOW) to color the window background you will see that all of the expected rows are there. Also, you can write to this last R2 row just fine, as long as you don't write to the last column C2. In your test program, you provided a text window in rows 7, 8, 9, 10, 11, AND 12. You only wrote text to rows 7 - 11. If you tried to write to row 12 it would fail, not because there is no row 12, but because you are trying to write to all 10 columns.

If the system behaved as you clain, then SETTEXTWINDOW (N, 1, N, 10) would not give a text window at all. But it does: one row high by 10 columns wide. I do this frequently, and write to it without any problem--until I try to use column 10.

I did some more testing and got a clue as what's happening. Call SETTEXTWINDOW (11, 11, 12, 21) to create a text window two rows high and 10 columns wide. Turn the text cursor on using I2 = DISPLAYCURSOR ($GCURSORON). Then write a string, say '12345' to the window row 1, and you will see the cursor blinking away in row 1 column 6, i.e. the next text position. If instead you wrote a string '1234567890' you would see that in row 1, but the cursor would be blinking away in row 2, column 1.

In other words, the OUTTEXT command outputs a cr/lf when it "bumps into" the right edge of a text window. If it happens to be in the last row when that happens, the text will scroll up and mess things up.

I think that this behavior is wrong. It makes it impossible to output text to the last row and column in a text window (as in my original complaint).

Following up on my last entry, I have found and fixed the problem. The key is a function WRAPON that I discovered by poking around; it controls whether the text cursor wraps. If I call this (using i2 = WRAPON ($GWRAPOFF) then it will not output a cr/lf when encountering the right border of a text window. Sometimes this is not what you want, but in my case it is. At least it allows one to write a character to the bottom right position in a text window!

Thanks for correcting me.

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya