Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
04-22-2024, 02:25 AM
(This post was last modified: 04-22-2024, 02:28 AM by PhilOfPerth.)
The Site Suggestions area presumably is to suggest changes to the site layout. It doesn't seem to cover suggestions about improving the language - adding, removing or changing functions etc. Is there, or can there be, an area that does this?
Here's an example of what I meant in the previous post:
I often need to clear one or more lines of my screen during programme running – prompts, warnings etc. or to centre text on a selected column. Are there functions for either of these? I’m sure if there aren’t, someone could write one and include it in the PE list of functions. I have been using the two Subs below, which both work for any screen-size setting with a Monospace font.
(CPL is CharsPerLine of the set screen size : CPL = Width / _PrintWidth("X"), and LN$ is a string of 2-digit line numbers).
We can write Locate line-number,1 : Print space$(80) or whatever the line-length is, repeatedly, to clear each line, but it’s easier to use and visualize: Wipe “080910” (to clear rows 8, 9 and 10) with this sub:
Sub WIPE (ln$) ’ To clear selected screen rows
‘ Call this sub with a string of 2-digit row-numbers e.g. Wipe ”080910” for rows 8, 9 and 10
If Len(ln$) = 1 Then ln$ = "0" + ln$ ' catch single-digit line numbers
For a = 1 To Len(ln$) - 1 Step 2 ‘ step through LN$ in 2 digit steps
wl = Val(Mid$(ln$, a, 2)) ’ line to be wiped is value of the 2 digits
Locate wl, 1: Print Space$(CPL)’ print a full line of spaces
Next
End Sub
And we can use LeftPos=80-int(len(txt$)/2) : Locate line-number,LeftPos : Print Txt$ to centre a line of text, but it’s
simpler to write: Centre txt$ , 10 (to centralize Txt$ on line 10) with this sub:
Sub Centre (txt$, linenum)
‘ Call this sub with a text string and line-number e.g. Centre Txt$,10
CtrPos = Int(CPL / 2 - Len(txt$) / 2) + 1
Locate linenum, CtrPos
Print txt$
End Sub
They’re both very primitive, but I think the general ideas, cleaned up, could be useful to others.
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
The problem with adding code into QB64PE itself is that it has to try and account for all the endless possibilities when being in use. Let's take your SUB Wipe, for example.
How would that work on a text screen? A graphic screen? With all the various _PrintModes in effect? With 0 alpha colors set? With non-0 alpha colors? Do you wipe the text off an image and leave a black spot there? And on and on...
Which is why, sometimes, simple things like these are best left for the user to sort out and add to their own code. One of the best type "Wipe" routines is this simple snippet:
PCOPY 0, 1' make a copy of the screen
Print "Whatever you want on the screen"
SLEEP 'Give time for the user to see the screen. Delay and such also can work here, or a user input prompt...
PCOPY 1, 0 'restore the screen to the copy you made before
Now the above does a TRUE wipe of the screen. It restores images and everything to the exact same point as where it was before you printed on it and "ruined" it with a temp pop-up or whatnot.
Some things, users need to code for themselves, just to suit the flexibility of their own stuff. The command you've written above works -- as long as the COLOR matches the _BACKGROUNDCOLOR, _PRINTMODE isn't affecting things, _DEST isn't somewhere odd, the coordinates sent aren't ones which are off screen and error out, a "MONOSPACE" font is in use.... (and probably more things to account for that I'm just not thinking of).
It's all these various little things in play, that often lead to such overhead for a QB64PE command. It's quick and simple to write a routine to print a few rows of blank spaces in your own program, as you *know* which of those toggles and modifiers are and aren't in effect. As a generic language-level command though?? THAT'S got to take all the various options into account and error trap and respond to them!
And with all that said, the best place would probably be "Works in Progress", if you're looking for feedback for such functions to see what toggles/modifiers you might need to account for, to make an "universal-use" type command; and "Utilities" once you've got it perfected to what you think is worthwhile in sharing for others to use.
And once you make a whole collection, or "toolbox", of such utilities and wrap it all up together so someone can just $INCLUDE them into their code, then that whole collection can be moved into "Libraries" for folks to find and make use of.
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
Ok, thanks Steve. As they say, "a little knowledge is dangerous". Just an idea.
Posts: 3,974
Threads: 177
Joined: Apr 2022
Reputation:
220
04-22-2024, 12:59 PM
(This post was last modified: 04-22-2024, 01:02 PM by bplus.)
unless i missed your point phil, that is beauty of subs and functions you can tweak the PL with your particular needs and reuse these over and over with simple copy/paste or a library to include without having to bloat the PL
your wipe routine might make a great utility to share with others with similar needs and might get improvements from the amazing Steve very likely simplification unless he goes Swiss Army knife on you and mods your routine with 100 bells and whistles lol
b = b + ...
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
04-22-2024, 02:44 PM
(This post was last modified: 04-22-2024, 02:52 PM by TerryRitchie.)
(04-22-2024, 06:23 AM)SMcNeill Wrote: PCOPY 0, 1' make a copy of the screen
Print "Whatever you want on the screen"
SLEEP 'Give time for the user to see the screen. Delay and such also can work here, or a user input prompt...
PCOPY 1, 0 'restore the screen to the copy you made before I recently added PCOPY under the "SCREEN Pages and Flipping" section in Lesson 5 if you need a quick intro to PCOPY.
Oops, I didn't publish it yet. I'll finish that up today and get it posted.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
(04-22-2024, 04:46 PM)SMcNeill Wrote: (04-22-2024, 02:44 PM)TerryRitchie Wrote: (04-22-2024, 06:23 AM)SMcNeill Wrote: PCOPY 0, 1' make a copy of the screen
Print "Whatever you want on the screen"
SLEEP 'Give time for the user to see the screen. Delay and such also can work here, or a user input prompt...
PCOPY 1, 0 'restore the screen to the copy you made before I recently added PCOPY under the "SCREEN Pages and Flipping" section in Lesson 5 if you need a quick intro to PCOPY.
Oops, I didn't publish it yet. I'll finish that up today and get it posted.
Well darn! I studied and studied what you (didn't) have up there, and still have no more of an idea about PCOPY than what I had before I started that lesson! LOL, sorry about that.
PCOPY and an example game have been added showing its use. I started it over a week ago but forgot to finish it.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
04-23-2024, 12:32 AM
(This post was last modified: 04-23-2024, 12:32 AM by PhilOfPerth.)
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
04-23-2024, 03:40 AM
(This post was last modified: 04-23-2024, 03:41 AM by TerryRitchie.)
(04-23-2024, 12:32 AM)PhilOfPerth Wrote: PCOPY is something I haven't played with yet, so I'll be interested to see what you come up with. Sounds interesting! It's a really handy and overlooked statement. QB64 allows you to have multiple pages of the screen, as many as memory in your system will allow! (QuickBasic only offered up to 8 pages in some screen modes)
You can create or load an image to the screen and then copy it to another screen page:
PCOPY 0, 1 ' copy current screen to screen page 1
Load or create another one and then:
PCOPY 0, 2 ' copy current screen to page 2
etc..
Now, when you need to display those images simply copy them back:
PCOPY 1, 0 ' copy screen page 1 to current screen
SLEEP
PCOPY 2, 0 ' copy screen page 2 to current screen
In theory you could load thousands of frames of animation in screen pages and then flip through them like a flip book.
The PCOPY statement really shines when paired with the SCREEN statement and its use of active and visual screen pages which is also now covered in lesson 5.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 2,177
Threads: 222
Joined: Apr 2022
Reputation:
103
In the old days, PCOPY was great to make it look like your slow ASCII computer actually wasn't flickering to put a lot of stuff on the screen. You let the code do all the display stuff in the background, and when it finished, just PCOPY it to the visual screen. Changing screen modes had the same effect. Machines are so fast today, flicker just isn't an issue anymore, but I still use PCOPY for popup boxes.
PeteCOPY
|