Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
01-25-2023, 01:24 AM
(This post was last modified: 01-25-2023, 01:26 AM by PhilOfPerth.)
Is there a (simple) way to define a new single character in QB64, without changing to a different character-set?
I need a vertical line (like |) but in the right-hand column of the character-space.
I know I can use graphics (Pset and Draw) to do this but this doesn't seem to render correctly on different screen resolutions.
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
Code: (Select All) print "Test this"; CHR$(179);"abc"
Any chr$(X) character is going to take up a one character space, but that might work for you, as your insert point.
I did use a graphics line for a text box cursor just like you see in forum editor. You could make it blink too.
You want this for that last word game as a cursor, correct?
b = b + ...
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
01-25-2023, 03:38 AM
(This post was last modified: 01-25-2023, 03:43 AM by PhilOfPerth.)
Yes, that's what it's for.
It's ok to take up a character space - I overwrite it when the cursor is moved, anyway (maybe wrap the cursor in spaces, so at the next print it gets removed). I just want it to be at the RHS of the character box, to make it clear where the insertion point will be.
The graphic version seems to be a problem for some users - maybe their screen resolution?
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
(01-25-2023, 03:38 AM)PhilOfPerth Wrote: The graphic version seems to be a problem for some users - maybe their screen resolution?
If you did your program in "text mode" you would notice better what is happening. That is, if the "DRAW" statement were turned into another "PRINT" which creates a vertical cursor.
One character overwrites the other and anything else that is in the way. In graphics modes as well as in text. It was that way in QuickBASIC/QBasic with nothing to do about it except draw only the pixels of the characters laboriously. QB64 has _PRINTMODE but it's some hassle. It's better to print the character first, then draw the vertical cursor with "DRAW" in your program in the other thread. Otherwise you would have to erase the whole field where the characters are printed, because only pixels would be drawn of the characters which causes the characters to overwrite each other and it could get messy quickly.
Code: (Select All) SCREEN 12
_PRINTMODE _KEEPBACKGROUND
LOCATE 1, 1 : PRINT "O"
LOCATE 1, 1 : PRINT "A"
Without the _PRINTMODE then this program would just print an "A" at top-left corner of the window. Instead it prints this mutated thing. Using the pipe symbol or a fuzzy block isn't going to help in that case.
What you could do is just print a "cursor", which is a pipe or whatever is not a letter, on the place where the player expects to insert a new letter in the game. Instead of using "DRAW" between characters. Like "BYS|T" as opposed to "BY|ST". Just print the "cursor" along with the rest of the text.
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
Here is start of a custom cursor:
Code: (Select All) _Title "MyCurs Test use left and right arrow keys to move cursor" 'b+ 2023-01-24
Screen _NewImage(800, 600, 32)
cursCol = 1: cursRow = 1
Do
Cls
Print " Hello World!"
lc = lc + 1
If lc Mod 20 = 0 Then toggle = 1 - toggle
If toggle Then c~& = _RGB32(255, 255, 255) Else c~& = _RGB32(0, 0, 0)
myCurs cursRow, cursCol, c~& ' at "H"
kh& = _KeyHit
If kh& = 19200 And cursCol > 1 Then cursCol = cursCol - 1
If kh& = 19712 And cursCol < 100 Then cursCol = cursCol + 1
_Display
_Limit 60
Loop
Sub myCurs (row, col, colr As _Unsigned Long) ' use row col like for Locate
'Locate row, col
Line ((col - 1) * 8, (row - 1) * 16)-Step(0, 15), colr
End Sub
b = b + ...
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
OK I moved all the stuff that controls the blinking into the myCurs sub so now main code can focus on it's job.
Code: (Select All) _Title "MyCurs Test use left and right arrow keys to move cursor" 'b+ 2023-01-24
Screen _NewImage(800, 600, 32)
cursCol = 1: cursRow = 1
Do
Cls
Print " Hello World!"
myCurs cursRow, cursCol
kh& = _KeyHit
If kh& = 19200 And cursCol > 1 Then cursCol = cursCol - 1
If kh& = 19712 And cursCol < 100 Then cursCol = cursCol + 1
_Display
_Limit 60
Loop
Sub myCurs (row, col) ' use row col like for Locate
'Locate row, col
Static As Long lc, toggle
lc = lc + 1
If lc >= 1000000 Then lc = 0
If lc Mod 20 = 0 Then toggle = 1 - toggle
If toggle Then c~& = _RGB32(255, 255, 255) Else c~& = _RGB32(0, 0, 0)
Line ((col - 1) * 8, (row - 1) * 16)-Step(0, 15), c~&
End Sub
b = b + ...
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
Oh check this out, a tiny editor started!
Code: (Select All) _Title "MyCurs Test use left and right arrow keys to move cursor" 'b+ 2023-01-24
Screen _NewImage(800, 600, 32)
cursCol = 1: cursRow = 1
text$ = "Hello World"
Do
Cls
Print text$
myCurs cursRow, cursCol
kh& = _KeyHit
If kh& = 19200 And cursCol > 1 Then cursCol = cursCol - 1
If kh& = 19712 And cursCol < 100 Then cursCol = cursCol + 1
If (kh& >= 65 And kh& <= 90) Or (kh& >= 97 And kh& <= 122) Then
text$ = Mid$(text$, 1, cursCol - 1) + Chr$(kh&) + Mid$(text$, cursCol)
End If
If kh& = 8 Then
If cursCol > 1 Then
text$ = Mid$(text$, 1, cursCol - 2) + Mid$(text$, cursCol)
cursCol = cursCol - 1
End If
End If
_Display
_Limit 60
Loop
Sub myCurs (row, col) ' use row col like for Locate
'Locate row, col
Static As Long lc, toggle
lc = lc + 1
If lc > 1000000 Then lc = 0
If lc Mod 20 = 0 Then toggle = 1 - toggle
If toggle Then c~& = _RGB32(255, 255, 255) Else c~& = _RGB32(0, 0, 0)
Line ((col - 1) * 8, (row - 1) * 16)-Step(0, 15), c~&
End Sub
Yeah should use ElseIf's...
b = b + ...
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
01-25-2023, 04:41 AM
(This post was last modified: 01-25-2023, 04:42 AM by bplus.)
Some more some better:
Code: (Select All) _Title "MyCurs Test use left and right arrow keys to move cursor" 'b+ 2023-01-24
Screen _NewImage(800, 600, 32)
cursCol = 1: cursRow = 1
text$ = "Hello World"
Do
Cls
Print text$
myCurs cursRow, cursCol
kh& = _KeyHit
If kh& = 19200 And cursCol > 1 Then
cursCol = cursCol - 1
ElseIf kh& = 19712 And cursCol < 100 Then
cursCol = cursCol + 1
ElseIf (kh& >= 32 And kh& <= 127) Then
If cursCol <= Len(text$) + 1 Then 'lets not be printing in no mans land!
text$ = Mid$(text$, 1, cursCol - 1) + Chr$(kh&) + Mid$(text$, cursCol)
cursCol = cursCol + 1
End If
ElseIf kh& = 8 Then ' back space
If cursCol > 1 Then
text$ = Mid$(text$, 1, cursCol - 2) + Mid$(text$, cursCol)
cursCol = cursCol - 1
End If
ElseIf kh& = 21248 Then 'delete
text$ = Mid$(text$, 1, cursCol - 2) + Mid$(text$, cursCol)
End If
_Display
_Limit 60
Loop
Sub myCurs (row, col) ' use row col like for Locate
'Locate row, col
Static As Long lc, toggle
lc = lc + 1
If lc > 1000000 Then lc = 0
If lc Mod 20 = 0 Then toggle = 1 - toggle
If toggle Then c~& = _RGB32(255, 255, 255) Else c~& = _RGB32(0, 0, 0)
Line ((col - 1) * 8, (row - 1) * 16)-Step(0, 15), c~&
End Sub
b = b + ...
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
Perhaps something simple like this?
Code: (Select All) SCREEN _NEWIMAGE(640, 480, 32)
_SCREENMOVE _MIDDLE
$COLOR:32
PRINT "Foo"; Line4Phil(Red); "foo?"; Line4Phil(Green)
FOR i = 0 TO 9
PRINT STR$(i); " "; Line4Phil(Red); STR$(i + 100); Line4Phil(Green)
NEXT
FUNCTION Line4Phil$ (kolor AS _UNSIGNED LONG)
PRINT " ";
y = CSRLIN - 1
x = POS(0) - 1
fw = _FONTWIDTH
fh = _FONTHEIGHT
LINE (x * fw - 2, y * fh)-STEP(1, fh), kolor, BF
END FUNCTION
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
01-25-2023, 09:21 AM
(This post was last modified: 01-25-2023, 09:24 AM by PhilOfPerth.)
Thanks for all the suggestions.
But, after trying them all, I feel that my original graphical cursor is the clearest and simplest for players to use.
@mnrvovrfc: Sorry, but I'm at a loss as to what was happening in your Worm game, and not sure what you mean by "after four words were added..." as only single letters should be added. Can you explain a bit more, and tell me what screen mode you are using?
I have made changes to clarify how/if the Wordlists files are being used, and will upload the new version shortly. I'm still experimenting with the suggestions made for using ASCII characters instead of graphics for the cursor.
|