font won't change

New to FreeBASIC? Post your questions here.
Jan-K
Posts: 4
Joined: Apr 23, 2020 6:39

font won't change

Postby Jan-K » Apr 23, 2020 7:06

Hello all,
I got freebasic for three days now, and leaning on my experience (from >20 years ago) with qb, dbaseIII/clipper, and several more obscure languages, i managed to get a program running in a rather primitive mode :-)
And now i want to give it a more useful face, by introducing an output screen (instead of an output file).
But that 8x8 font that i get in a graphic screen is horrible, so i wanted to get a 8x14 or 8x16 font, but whatever i try, i can't seem to get that working.
I'll include the relevant code, hoping someone can put me on the right track.

Jan-K

Code: Select all

dim shared col as uinteger
dim shared row as uinteger

screenres 800, 600, 16
color &h000000ff, &h00f0f0f0
row= hiword(width())
col= loword(width())
Width col\8, row\14
cls
? row, col
? "did the font change?"
sleep

Imortis
Moderator
Posts: 1734
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: font won't change

Postby Imortis » Apr 23, 2020 12:58

From the documentation on WIDTH:

In graphics modes Width is used to indirectly select the font size by setting one of the character height * width pairs allowed (See Screen (Graphics)). If rows / cols is an invalid combination, no changes are made to the screen display.

Valid font heights are 8 pixels, 14 pixels and 16 pixels. The fonts all have a fixed width of 8 pixels.
dodicat
Posts: 6728
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: font won't change

Postby dodicat » Apr 23, 2020 13:07

Just do

Code: Select all

dim shared col as uinteger
dim shared row as uinteger

screenres 800, 600, 16
width 800\8,600\16  ''< change font here, go by pixel width and height of the screen

color &h000000ff, &h00f0f0f0
row= hiword(width())
col= loword(width())
cls
? row, col
? "did the font change?"
?"YES"
sleep
 
Jan-K
Posts: 4
Joined: Apr 23, 2020 6:39

Re: font won't change

Postby Jan-K » Apr 23, 2020 17:42

Hello again, and thanks for the quick reaction.
Reading the documentation over and over again, i concentrated on the line:
"If rows / cols is an invalid combination, no changes are made to the screen display."
At first, i figured that any screen size large enough to hold a certain number of columns/rows should work.
That turned out to be a misinterpretation.
I found that the screenres has to be an exact multitude of the character size.
And since 600 (height) is not an exact multitude of 14 nor 16, it didn't work, the 800 (width) was actually correct (by coincidence).
So i tried 672 for the height, (672/16=42 without remainder) and lo and behold, it worked !
Maybe the documentation could stress on these exact multitudes ?

Code: Select all


dim shared col as uinteger
dim shared row as uinteger

screenres 800, 672, 16  \changed 600 to 672
color &h000000ff, &h00f0f0f0
row= hiword(width())
col= loword(width())
width col, row/2
cls
? row, col
? "did the font change?"
? "Yup, totally :-)"
sleep



So as far as i'm concerned this topic is solved.
MrSwiss
Posts: 3636
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: font won't change

Postby MrSwiss » Apr 23, 2020 18:11

Sorry, but some assumptions are simply incorrect.
This is compounded with a coding mistake: using float divide '/', instead of integer divide '\'
Jan-K wrote:I found that the screenres has to be an exact multitude of the character size.
Not correct, that is, if you're using the method of dodicat (as written, not 'self modified').
Therefore, your conclusions are simply without substance ...
Jan-K wrote:Maybe the documentation could stress on these exact multitudes ?
No, documentation doesn't need any updates after all.

NOTE: certain things need to be done exactly as written (to work 'as expected').
dodicat
Posts: 6728
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: font won't change

Postby dodicat » Apr 23, 2020 18:24

The criterion for text size is the screen resolution in pixels.
No need for any multiples of anything, the way to get your text is independent of rows/columns.
I remember when I was young and green at sea I would look up the Boatswain's manual for various deck tasks.
When I got out there the old hands often said, never mind all that book stuff, this is the AB's way of doing it.
Well this is the AB's way of doing it.

Code: Select all

dim shared col as uinteger
dim shared row as uinteger
dim as integer w,h
dim as integer k=1,n=1
windowtitle "Press space key to refresh. press escape to end"
do
  k=-k
  n+=1
if n mod 2=0 then screenres 200+rnd*700, 200+rnd*500, 16
screeninfo w,h
color &h000000ff, &h00f0f0f0
if k=1 then width w\8,h\16 else width w\8,h\8
row= hiword(width())
col= loword(width())

cls
print row, col,w,h
if k=1 then
print "height 16"
else
  print "height 8"
  end if
 
sleep
loop until inkey=chr(27)
 

Just touch a key to refresh.
Jan-K
Posts: 4
Joined: Apr 23, 2020 6:39

Re: font won't change

Postby Jan-K » Apr 23, 2020 19:25

You guys are perfectly right, this works too.


Code: Select all

screenres 800, 600, 16
color &h000000ff, &h00f0f0f0
row= hiword(width())
col= loword(width())
width col, row\2

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 8 guests