LB Booster
Programming >> Compatibility with LB4 >> Mainwin Font
http://lbb.conforums.com/index.cgi?board=compatibility&action=display&num=1420991703

Mainwin Font
Post by Monkfish on Jan 11th, 2015, 2:55pm

New to LBB. Certainly faster. I like it!

I have an LB4 program that runs in mainwin (yes I know I shouldn't). The program allows the user to change the mainwin font by altering the respective lbasic404.ini file entry where the font is set.

Is there a way to change the font that mainwin uses in LBB?

Thank you smiley
Re: Mainwin Font
Post by Richard Russell on Jan 11th, 2015, 3:24pm

on Jan 11th, 2015, 2:55pm, Monkfish wrote:
Is there a way to change the font that mainwin uses in LBB?

Yes you can, although I can't guarantee it will be entirely free of side-effects. You can do it as follows:

Code:
    !*font Courier New,16
    print "Hello mainwin!" 

Note that as it's using the 'BBC BASIC escape' feature you must specify the font in a slightly different format from how you normally would in LB (no underscores, and a comma before the size).

Adding that code will make the program incompatible with LB 4.04 so if you want to retain compatibility put the font-change line in a separate file and use LBB's 'include facility:

Code:
'don't put the include as the first line
'include newfont.bas
    print "Hello mainwin!" 

LB 4 will treat the 'include as a comment and ignore it.

Richard.


Re: Mainwin Font
Post by Monkfish on Jan 14th, 2015, 10:41am

Hi Richard, I would like the user to be able to select the font using fontdialog. I have written a program to convert from the font format in LB to the one in BBC BASIC (and stored the font it in a string called font$), but I can't seem to be able to pass this to the escape function (as below):

!*font font$

e.g. font$="Courier New,16"
Re: Mainwin Font
Post by Richard Russell on Jan 14th, 2015, 11:43am

on Jan 14th, 2015, 10:41am, Monkfish wrote:
I can't seem to be able to pass this to the escape function (as below):

BBC BASIC's 'star' commands have the same limitation as LB's GUI commands: you can't pass a variable directly, instead you have to construct a string containing the command and its parameters.

The syntax you need to use is this:

Code:
    fontcmd$ = "font Courier New,16"
    !OSCLI fontcmd$
    print "Hello world!" 

Or this would work just as well:

Code:
    font$ = "Courier New,16"
    !OSCLI "font " + font$
    print "Hello world!" 

Richard.

Re: Mainwin Font
Post by Monkfish on Jan 14th, 2015, 6:25pm

Thanks again Richard, that worked fine. Strangely, changing the font changes the flashing input I-beam into a dot rather than an "I". No big deal, but worth pointing out.

There were two other anomalies that I discovered while testing my program under LBB instead of LB. However, both may be intentional.

1. Input statements (both input and input$) accept input from the mouse scroll wheel. So if someone scrolls their mouse wheel while at an input statement they will get a string of spurious characters appear.

2. LBB doesn't seem able to open a hidden file for writing. It can open a hidden file for reading just fine, but not for writing. I have to run a batch file to make the file visible, then open it for writing, write data, close it, and then run another batch file to reset the hidden attribute.

I must say, I much prefer using LBB to LB. Great job!
Re: Mainwin Font
Post by Richard Russell on Jan 14th, 2015, 7:28pm

on Jan 14th, 2015, 6:25pm, Monkfish wrote:
Strangely, changing the font changes the flashing input I-beam into a dot rather than an "I".

I said there might be side-effects!

Quote:
Input statements (both input and input$) accept input from the mouse scroll wheel.

True. It could ignore those characters if you think it would be preferable.

Quote:
LBB doesn't seem able to open a hidden file for writing.

My tests suggest that it can successfully open the file for update, i.e. for modifying an existing file, but won't replace the file with a new one. This is a Windows feature which is documented at MSDN:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx

"If CREATE_ALWAYS and FILE_ATTRIBUTE_NORMAL are specified, CreateFile fails and sets the last error to ERROR_ACCESS_DENIED if the file exists and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_SYSTEM attribute".

Quote:
I have to run a batch file to make the file visible, then open it for writing, write data, close it, and then run another batch file to reset the hidden attribute.

If the new file is the same length as, or longer than, the previous one you could open the file for update (OPEN for BINARY) and then it would work.
Alternatively you could reset and set the 'hidden' attribute using API calls, which in my opinion is nicer than messing around with batch files.

Richard.

Re: Mainwin Font
Post by Monkfish on Jan 14th, 2015, 9:17pm

Thanks Richard. That clears all that up smiley

Yes, I think input and input$ function should be isolated from all mouse functions. Sometimes a wireless mouse can send spurious data which would then appear as garbage at a waiting input statement.
Re: Mainwin Font
Post by Richard Russell on Jan 14th, 2015, 11:04pm

on Jan 14th, 2015, 9:17pm, Monkfish wrote:
Yes, I think input and input$ function should be isolated from all mouse functions.

I've been thinking about this and I've decided that it would be desirable to exclude the mouse-wheel codes from the INPUT statement but that it would not be desirable to exclude them from the INPUT$() function.

These codes are inserted into the keyboard buffer deliberately to make it easy to incorporate mouse-wheel functionality in a program, without the complications of API calls or (worse) having to use WMLiberty.DLL.

Quote:
Sometimes a wireless mouse can send spurious data

The mouse wheel functionality has been present in BBC BASIC (which is why it exists in LBB) for more than 13 years. Nobody has ever commented that it is undesirable or has ever reported 'spurious' keyboard input arising from this source.

So in the next release of LBB I will filter out the mouse-wheel codes in INPUT, but INPUT$(1) will continue to return them.

Richard.


Re: Mainwin Font
Post by Monkfish on Jan 15th, 2015, 12:09pm

That seem reasonable. You are more qualified than me to make that call. I just love the fact that you have gone to the trouble to create an alternative compiler for LB users. My program looks a lottle more professional, stable and it runs at least twice as fast. Thank you smiley
Re: Mainwin Font
Post by Richard Russell on Jan 15th, 2015, 3:39pm

on Jan 15th, 2015, 12:09pm, Monkfish wrote:
My program looks a lottle more professional, stable and it runs at least twice as fast.

Only twice as fast? A little disappointing! wink

Have you used LBB's profiler to see where the time is being spent? If your program plots graphics that could explain the improvement being only modest; there's a Wiki article about this. Another thing which can have an impact is doing a SCAN unnecessarily frequently; if you have a time-critical loop containing a SCAN try moving it out of the loop. WORD$() is quite slow in LBB too, especially if you don't specify an explicit delimiter.

Richard.
Re: Mainwin Font
Post by Monkfish on Jan 15th, 2015, 7:10pm

Thanks for the tips Richard. I will certainly remember them.

The speed of my program is reliant on nested array lookups, sometimes three deep. So the contents of one array points to the entry in the next and so on. I'm quite good at writing reasonably tight inner loops... my problem is that everything else is an unprofessional hack. I have been programming for about 35 years, but I'm not a serious programmer, just a BASIC mashuper. My code is awful. Even I can't understand it if I come back to it years later. I just like programming to get the computer to solve problems for me.

This program I have just finished is to create a league table for my bowls team. We have a team of say 12 players, but only 4 can play in each weekly game. So we have to select 4 from 12 so that everyone plays a similar number of games or a set number of games. That's not so difficult, but you also have allow partners to play together, keep certain players apart, holiday periods avoided, everyone's games spread out as evenly as possible thoughout the season and also maximise team variation, so everyone gets to play with everyone else... within the previous constraints.

In many cases there may not be one solution that fits to all the requirements. It is also sobering to realise that selecting 4 players from 12 for 30 games, produces a number of possible configurations that is roughly equivalent to the number of atoms in the known universe! And this program has to find the best one!

Now you know why I'm delighted with any speed increase I can get wink
Re: Mainwin Font
Post by Jack Kelly on Jan 21st, 2015, 05:30am

I read in another thread that the following BBC Basic command can be used to change the font in MainWin.
Code:
font$ = "Courier New, 14"
!OSCLI "font " + font$
 

You can search your system for LBB.ini, but it's not user-friendly. On XP it is in C:Documents and Settings\(myusername)\Programdata

And it's ok to write programs that run only in MainWin. In the old days that's how they all ran. Do what seems best for you.


Re: Mainwin Font
Post by Richard Russell on Jan 21st, 2015, 08:22am

on Jan 21st, 2015, 05:30am, Jack Kelly wrote:
You can search your system for LBB.ini

There's no reason why you should need to view or edit that file, since it only records settings that you can easily see and change in the IDE, but there's an easier way to find it should you want to: use the environment variable %APPDATA% (either in Windows Explorer or at a Command Prompt)

Quote:
And it's ok to write programs that run only in MainWin.

There are differing opinions on that! Some LB enthusiasts will argue that the mainwin should be used only for 'little programs' and for debugging GUI applications (which is certainly its principle use as far as I'm concerned). They would discourage its use as the main or only UI in a large program.

I won't take sides on that issue, but it's worth mentioning that LBB's mainwin does not have the high degree of compatibility with LB4 that the GUI features do. For example there is no menu, and you can only 'scroll back' a limited distance. On the other hand you can change the colour and even use graphics in the LBB mainwin, which you can't in LB4.

Richard.

Re: Mainwin Font
Post by Monkfish on Jan 21st, 2015, 12:35pm

Thanks Jack smiley

I wondered if LBB had an ini file. Changing the font within the program seems to work fine, but it's handy to know.

My program only uses text input because it's intended to be used by people who might not be confident in using a computer. If issues arise from using Mainwin, I will just have to shift all my input statements over to a separate window. Not sure what the benefits would be though?

I prefer to allow LBB to compile my code because the program it creates just feels more professional and produces a single executable... and it's faster wink
Re: Mainwin Font
Post by Richard Russell on Jan 21st, 2015, 2:06pm

on Jan 21st, 2015, 12:35pm, Monkfish wrote:
I wondered if LBB had an ini file. Changing the font within the program seems to work fine, but it's handy to know.

I'm not sure if there's been some misunderstanding. The LBB.INI file sets the font used in the IDE (program editor), but it has no influence at all on the font used in the mainwin. They are totally independent, as one would (hopefully) expect.

In LB 4.04 the font used in the mainwin of a compiled program is linked in some way with the font used in the IDE. Why? It reminds me of the 'spooky action at a distance' that so upset Einstein, and it's almost as strange. But then I find many things about LB 4 inexplicable! shocked

Richard.
Re: Mainwin Font
Post by Monkfish on Jan 21st, 2015, 5:26pm

Oh I understand now. Must admit that I hadn't looked at the LBB ini file.

I get the impression Richard, that your expertise and many years of experience with BASIC is a little more advanced than Carl's.

I am only happy that both of you are helping to keep the flag flying for BASIC, which is how I was introduced to programming back on my Atari 800... ignoring my old programmable Sinclair calculator wink
Re: Mainwin Font
Post by Richard Russell on Jan 21st, 2015, 5:56pm

on Jan 21st, 2015, 5:26pm, Monkfish wrote:
I get the impression Richard, that your expertise and many years of experience with BASIC is a little more advanced than Carl's.

I don't know Carl's background. He is obviously an extremely skilled and experienced SmallTalk programmer, but I get the impression that his knowledge of BASIC is (or at least was when he designed LB) a bit weak, and I don't think he's as familiar with some aspects of Windows as might be desirable.

I don't claim to be an expert in anything, but with more than 40 years of software and hardware engineering experience, and more than 30 years associated with BBC BASIC, I've acquired a certain degree of knowledge about a whole lot of things - and forgotten a whole lot more!

Richard.