Making overlays and screen savers

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Bluepixel
Posts: 4
Joined: Sat 21 Dec 2019, 15:43

Making overlays and screen savers

Post by Bluepixel »

Hi there, I just got BBC Basic and started making some graphical demos, and eventually I ended up with something quite nice, so I wanted to turn it into a screen saver, this can easily be done by changing the extension of an .exe file to a .scr file, however there are still some things that need to be done by the programmer to have the screen saver work correctly. Without further ado, let me ask some questions :)
  • How can I make my project Full Screen?
  • How do I read any general inputs? (aka mouse movement, clicks and keyboard input)
  • How can I make my project always be on top?
  • How do I make my project's background transparent to the desktop? (for widgets and overlays)
Thanks a lot! I hope to become a part of your community soon.
-Cheers!
mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

Re: Making overlays and screen savers

Post by mikeg »

This appears to be some of what you are looking for:

http://www.bbcbasic.co.uk/wiki/doku.php ... _20windows
Focus is on code subject. Feel free to judge the quality of my work.
RichardRussell

Re: Making overlays and screen savers

Post by RichardRussell »

Bluepixel wrote: Sat 21 Dec 2019, 16:06
  • How can I make my project Full Screen?
  • How do I read any general inputs? (aka mouse movement, clicks and keyboard input)
  • How can I make my project always be on top?
The information you seek is in the main Help documentation, supplied with BBC BASIC for Windows. Press F1 to open the Help viewer and enter 'screen saver' (or simply 'saver') in the Search tab; the first hit will be 'Creating a screen saver'. Alternatively the same instructions can be found in the online manual.

[I apologise for posting here again when I promised that I wouldn't, but for some inexplicable reason nobody had provided this answer several hours after the question was asked. Of course they may have by the time this gets approved, in which case will the moderator(s) please delete this post.]
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Making overlays and screen savers

Post by KenDown »

Making a project full screen
============================
Go to the Help menu and click on "Help Topics". Click on the "Search" tab rather than the "Index" one, and type in "full screen". The final entry - "Using the entire screen" - is the one you want. The example given uses the full names for various variables, which is good as it tells you what they do and why they are included, but they do make the program rather long-winded. I'm afraid, therefore, that I simply type

Code: Select all

SYS"SetWindowLong",@hwnd%,-16,&70000000
SYS"SetWindowPos",@hwnd%,-1,0,0,xscreen%,yscreen%
The VDU26 is important, as otherwise any graphics are going to end up in strange locations - though note the caveat in the help.

Read inputs
===========
To detect keyboard inputs you are spoiled for choice. There is GET, INKEY(time%) and, which may be the most useful for you, negative inkeys, which test for a specific key.

Click on the "Index" tab in the Help and type in "inkey". The first entry is "INKEY negative argument" and you use it by

Code: Select all

IFINKEY-2=-1 REPEATUNTILINKEY-2=0:REM Check for Ctrl
Note the REPEATUNTIL. INKEY cycles around so fast that you can easily clock up half a dozen key presses before you can take your finger off the key. Of course, that may be what you want, in which case leave out the REPEATUNITL. If you just want to detect a single keypress, then making sure that the key has been released is a good idea. And, obviously, where I have the REM, you will have the code to do whatever the keypress is for.

Mouse movements and mouse button clicks are also easy.

Code: Select all

REPEAT:MOUSEmx%,my%,mb%:UNTILmb%=4
REPEAT:MOUSEtx%,ty%,tb%:UNTILtb%=0
The first loop will repeat until the left-hand mouse button is clicked. Again, it is a good idea to wait until the mouse button has been released. The coordinates of the pointer are then given in mx% and my%. The different variables (tx%,ty% etc) are in case the mouse moves between pressing the button and releasing it.

However there is another method using ON MOUSE With the "Index" tab still selected enter "ON MOUSE" and click on the entry, which will tell you all that you need to know. However this routine is less easy to use - note the complicated way of finding the x and y coordinates.

Window always on top
====================
In the Help use the "Search" tab and type in "window". You will have to scroll down the results, one of which is "Forcing the window to stay on top".

Transparent window
==================
Richard will no doubt massacre me (and probably deservedly) but I simply cannot find how to make a window transparent in the Help file. However the solution is in the Wiki - not that I can find an index entry for it, I had to use the search box.

https://www.bbcbasic.co.uk/wiki/doku.ph ... ransparent

The only annoying thing is that you have to designate one particular colour as the transparent one, which means that you cannot use that colour in your program. I don't know what your screen-saver does, but suppose you have selected COLOUR 1 as your transparent colour and that your screen-saver produces swirls of every colour. Whenever one of those swirls uses COLOUR1, you will simply get a hole in your graphics, revealing whatever is underneath!
RichardRussell

Re: Making overlays and screen savers

Post by RichardRussell »

KenDown wrote: Sun 22 Dec 2019, 11:26The final entry - "Using the entire screen" - is the one you want.
No it isn't, because a screen saver is special. You should instead use the code to which I linked in my reply.
To detect keyboard inputs you are spoiled for choice.
No you aren't, because a screen saver is special. You should use the code to which I linked in my reply.
Mouse movements and mouse button clicks are also easy.
But a screen saver is special, and you should use the code to which I linked in my reply.
You will have to scroll down the results, one of which is "Forcing the window to stay on top".
You should never force a screen saver to stay on top that way. Screen savers are special, and you should use the code to which I linked in my reply.
I simply cannot find how to make a window transparent in the Help file.
It's not in the Help file, it's in the Wiki. Member mikeg linked to it a few posts ago in this very thread.
The only annoying thing is that you have to designate one particular colour as the transparent one
Why is that "annoying"? There are approximately 16 million different colours, many of which cannot be distingushed as different by the human eye. Reserving one of those as the 'transparent' colour isn't a significant limitation; it would be impossible to see any difference.

Anyway, it's not even true that you have to desigate one colour as transparent; that's just one way of doing it. An alternative way is to use an image with an 'alpha' (opacity) channel, then you can have transparent areas with all 2^24 colours available.
Bluepixel
Posts: 4
Joined: Sat 21 Dec 2019, 15:43

Re: Making overlays and screen savers

Post by Bluepixel »

RichardRussell wrote: Sun 22 Dec 2019, 10:22 [I apologise for posting here again when I promised that I wouldn't, but for some inexplicable reason nobody had provided this answer several hours after the question was asked. Of course they may have by the time this gets approved, in which case will the moderator(s) please delete this post.]
Dont worry about it, im not sure if that message was meant for me or for any moderators, however your posts have been very usefull!
Bluepixel
Posts: 4
Joined: Sat 21 Dec 2019, 15:43

Re: Making overlays and screen savers

Post by Bluepixel »

@KenDown
Wow, thanks for the detailed reply! Time to make some screen savers :)
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Making overlays and screen savers

Post by KenDown »

Please note Richard's point, that a screen saver requires different code to the points I suggested. I believe my answers were correct for those specific questions, but in the context of a screen saver they were - as Richard has pointed out - incorrect.

I also find his point about an alpha channel very interesting. One learns something new every time Richard posts!
RichardRussell

Re: Making overlays and screen savers

Post by RichardRussell »

Bluepixel wrote: Mon 23 Dec 2019, 01:55 @KenDown
Wow, thanks for the detailed reply! Time to make some screen savers :)
I also posted a reply, in which I linked to the specific section of the Help documentation which describes how to create a Screen Saver. It covers making the window 'full screen' but also takes into account the requirement that a screen saver must support the 'preview' mechanism. It also covers automatically quitting the screen saver when mouse or keyboard activity is detected.

If you choose to ignore that documentation and instead follow the advice given by the other respondent (which was admittedly much more prominent in the thread), that is your prerogative. However it is likely that the resulting program will not work correctly as a screen saver. Strictly speaking there are other requirements that a screen saver should meet, as outlined by Microsoft here, but they are not easy for a BBC BASIC program to fulfil.
Bluepixel
Posts: 4
Joined: Sat 21 Dec 2019, 15:43

Re: Making overlays and screen savers

Post by Bluepixel »

@KenDown
Very true, however it has also been very usefull to know how to do these things alone. Thanks KenDown and RichardRussel for your replies!