finding out the size of text
finding out the size of text
I'm trying to make a simple text editor for some projects I have in mind and I'm trying to figure out how big the character bitmaps are for text so I can allocate my line list strings to be the same width as the viewing area. The chart in the manual (I'm using gfxlib) lists two different character sizes for each mode, but I have no way selecting, or knowing which is being used. This problem is compounded by the fact that an equivalent call to screenres has a different text size. So my question is how can I find out how big the characters are?
SCREENRES always uses 8x8 as the character size. SCREEN uses one of the character sizes in that table (yeah, default should be indicated). The character size is indirectly set with the WIDTH statement.
WIDTH() can also be used as a function to get number of columns and rows:
WIDTH() can also be used as a function to get number of columns and rows:
Code: Select all
SCREEN 13
Dim As Integer w
w = Width
Print "rows: " & HiWord(w)
Print "cols: " & LoWord(w)
'' OUTPUT:
'' rows: 25
'' cols: 40
I decided to post this here since there both related to what I'm working on. Anyway, what's the best way to 'erase' the last character in a string that you typed? I'm allocating a zstring for the thing I'm working on and I would like the last character I typed to be removed when I hit the backspace key. I don't plan on doing any fancy cursor stuff I just want to be able to type out a string or write over it with blank spaces using the back key. I guess I could use a separate pointer to simulate a fake cursor position then write the space character to it after it's decremented when backspace is pressed. I'll try that, but if anyone else has a better idea feel free to post it. Thanks.
(text editors are a pain in the ass)
(text editors are a pain in the ass)
If there is no fancy cursor stuff and you are using a zstring, you could just set the last character to chr(0), effectively removing the last character, since chr(0) marks the end of a zstring. For example,
Code: Select all
dim k as string
dim buffer as zstring ptr
dim n as integer, c as integer
const MAX_LEN = 20
buffer = callocate( MAX_LEN + 1 )
do
print "buffer = """; *buffer; """"
do
k = inkey
loop until k > ""
n = len( *buffer )
c = asc( k )
select case c
case 27
exit do
case 8
if( n > 0 ) then
buffer[n-1] = 0
end if
case 32 to 126
if( n < MAX_LEN ) then
buffer[n] = c
buffer[n+1] = 0
end if
end select
loop
deallocate buffer