Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 039: VIEW PRINT
#1
Every SCREEN ZERO HERO needs this keyword...

SYNTAX VIEW PRINT [topRow% TO bottomRow%]

Usage: Restricts the printable area of the screen.

Okay, let's take this puppy for a spin.

Use VIEW PRINT anytime you want to divide your text screen into a skin and message area.

Code: (Select All)
msg$ = "My Header"
COLOR 15, 1
LOCATE 1, 1: PRINT SPACE$(_WIDTH * 2);
LOCATE _HEIGHT - 1, 1: PRINT SPACE$(_WIDTH * 2);
LOCATE _HEIGHT, 1: PRINT SPACE$(_WIDTH);
LOCATE 1, _WIDTH / 2 - LEN(msg$) / 2: PRINT msg$;
LOCATE 2, 1: PRINT STRING$(_WIDTH, 196);
LOCATE _HEIGHT - 1, 1: PRINT STRING$(_WIDTH, 196);
PALETTE 5, 25
COLOR 7, 5
top% = 3
bottom% = _HEIGHT - 2
VIEW PRINT top% TO bottom%
CLS 2
msg$ = "Press [1] for info  /  Press [2] to make fun of Steve  /  Press [Esc] to end"
COLOR 15, 1: LOCATE _HEIGHT, _WIDTH / 2 - LEN(msg$) / 2: PRINT msg$; ' Look, we can print to the last row without changing VIEW PRINT.
LOCATE top%, 1
COLOR 7, 5
DO
    _LIMIT 30
    b$ = INKEY$
    IF LEN(b$) THEN
        SELECT CASE b$
            CASE "1"
                PRINT "INFO!"
            CASE "2"
                PRINT "Ha Ha Ha! ";
            CASE CHR$(27)
                EXIT DO
        END SELECT
    END IF
LOOP
SYSTEM

What's cool about VIEW PRINT is it leaves the last row unrestricted. That means we can print to the last row anytime we want, without changing the VIEW PRINT parameters.

What else do we need to know here, Pete?

Well, glad you asked!

1) CLEAR does not affect VIEW PRINT.

2) RUN removes VIEW PRINT.

3) CLS clears the whole screen.

4) CLS 2 only clears the VIEW PRINT area.

5) To get rid of the view print restriction, just code: VIEW PRINT

6) Remember when printing to the bottom of the screen to end your print statement with a semi-colon, so it doesn't scroll.

7) If you switch screens and switch back, you will have to redo your VIEW PRINT statement.

8) The top parameter must always be smaller than the bottom parameter. (If you're too dumb to figure that one out, switch to FreeBASIC).


Pete
Reply
#2
(12-19-2022, 04:48 AM)Pete Wrote: 6) Remember when printing to the bottom of the screen to end your print statement with a semi-colon, so it doesn't scroll.
Sometimes printing a character at the most bottom-right corner with "PRINT" scrolls regardless of presence of semicolon. This happened to me while I created this GIF file:

https://qb64phoenix.com/forum/attachment.php?aid=1234

I was forced to create another buffer which excluded the totally-black text line at the bottom. Actually off-topic because I didn't use "VIEW PRINT" for the program that created those images for the GIF file, but the thing about using "PRINT" on the bottom-most line is historical (not hysterical?) and even a semicolon might not prevent scrolling.
Reply
#3
Code: (Select All)
Screen _NewImage(80 * 8, 16 * 25, 32)
Locate 25, 80: Print "t";
_Delay 2
Do
    i = i + 1
    _PrintString (80 * 8 - i, 24 * 16), "AARGH, I killed it."
    _Limit 60
Loop Until i = 160
Sleep
b = b + ...
Reply
#4
(12-19-2022, 10:34 AM)mnrvovrfc Wrote:
(12-19-2022, 04:48 AM)Pete Wrote: 6) Remember when printing to the bottom of the screen to end your print statement with a semi-colon, so it doesn't scroll.
Sometimes printing a character at the most bottom-right corner with "PRINT" scrolls regardless of presence of semicolon. This happened to me while I created this GIF file:

https://qb64phoenix.com/forum/attachment.php?aid=1234

I was forced to create another buffer which excluded the totally-black text line at the bottom. Actually off-topic because I didn't use "VIEW PRINT" for the program that created those images for the GIF file, but the thing about using "PRINT" on the bottom-most line is historical (not hysterical?) and even a semicolon might not prevent scrolling.

You need to use LOCATE and then PRINT with a semicolon, to print on the bottom 2 lines of the screen without scrolling happening.  Wink
Reply
#5
Oh cool - I didn't know about the CLS 2 option to just clear the VIEW PRINT area.  Works great too.  I always had a problem messing up the last line of a screen trying to clear a VIEW PRINT area, like in the example code below.  Now with CLS 2 there is no problem.

Always something to learn.  Thanks for another keyword of the day!

- Dav

Code: (Select All)
View Print 1 To 1

Do
    Cls , Int(Rnd * 16) 'use this one, bottom line clears too
    'Cls 2, Int(Rnd * 16) 'use this one, bottom line does not clear
    _Display
Loop

Find my programs here in Dav's QB64 Corner
Reply




Users browsing this thread: 1 Guest(s)