Window Screen Command?

General FreeBASIC programming questions.
Post Reply
xbgtc
Posts: 253
Joined: Oct 14, 2007 5:40
Location: Australia

Window Screen Command?

Post by xbgtc »

Hi, I've tried to use this command but doesn't seem to work.
What is it meant to do?
I assumed (from FB help) that in your say 1440x900 graphics screen i can use WINDOW SCREEN (320,150)-(1120,750) to get an 800x600 screen so the program written for a 800x600 screen now runs as normal but centrally in your bigger screen.

The program runs but text still prints at 0,0 and images start in the negative hence you only see about a 1/4 of them like they are put at -200,-150.

Any idea what's wrong or what i should be doing instead?
fxm
Moderator
Posts: 12182
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Window Screen Command?

Post by fxm »

Instead of 'WINDOW SCREEN .....', use 'VIEW SCREEN .....' instead.
But no solution for 'PRINT' which is not a graphic instruction. Use 'DRAW STRING' instead.
xbgtc
Posts: 253
Joined: Oct 14, 2007 5:40
Location: Australia

Re: Window Screen Command?

Post by xbgtc »

thanks FXM i'll check out view screen but drawstring no good here as i use a routine for text (see below) but no nig deal if i can't do it :)

Code: Select all

sub textsound(text as string,stp as ubyte,sp as ubyte,cr as ubyte)
    dim x as uinteger
    FSOUND_PlaySound(0,wavefile(3))
    for i as integer=1 to len(text) step stp
        ?mid(text,i,stp);
        ?chr(219);chr(8);
        sleep 30
        if inkey=chr(27)then ex
    next
    if sp=0 then ?" "
    if cr=1 then ?" ";
    if cr=2 then
        ?" "
        ?" ";chr(219);
        locate,2
    end if
    if cr=3 then
        ?" "
        ?chr(219);
        locate,1
    end if
    if len(text)=1 then sleep 20
    FSOUND_Stopsound 0
end sub
paul doe
Moderator
Posts: 1745
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Window Screen Command?

Post by paul doe »

I don't see any reason why you couldn't convert that code to use draw string instead of print...
xbgtc
Posts: 253
Joined: Oct 14, 2007 5:40
Location: Australia

Re: Window Screen Command?

Post by xbgtc »

Ahhh never thought of it that way. Will try it and see if it can do the chr(8) :)
fxm
Moderator
Posts: 12182
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Window Screen Command?

Post by fxm »

xbgtc wrote: May 21, 2024 11:50 ..... chr(8) :)
These kinds of characters, which are in fact text cursor positioning commands (for use with 'Print'), are obviously not compatible with 'DrawString'.

To simulate a sort of "teletype effect" with 'DrawString', one can code something like this:

Code: Select all

Function fontHeight() As Ulong  '' return current character height (in pixel)
    Dim As Ulong h, r, f = 8
    Screeninfo( , h)
    r = Hiword(Width)
    If h \ 14 = r Then f = 14
    If h \ 16 = r Then f = 16
    Return f
End Function

Function teletypePrint(Byref text As String, Byval x As Ulong, Byval y As Ulong, Byval stp As Ubyte, Byval t As Ulong = 30) As Boolean
    Dim As Any Ptr pi = Imagecreate(8, fontHeight())  '' in order to clear the teletype cursor (Chr(219))
    Draw String (x, y), Chr(219)  '' print first teletype cursor
    Sleep t
    For i As Integer = 1 To Len(text) Step stp
        Put (x + (i - 1) * 8, y), pi, Pset  '' clear previous teletype cursor
        If Inkey = Chr(27) Then
            Imagedestroy pi
            Return False
        End If
        Draw String Step(0, 0), Mid(text, i, stp) & Chr(219)  '' print text part + next teletype cursor
        Sleep t
    Next i
    Put (x + Len(text) * 8, y), pi, Pset  '' clear last teletype cursor
    Imagedestroy pi
    Return True
End Function

Screen 12
Dim As Ubyte stp = 1
For i As Integer = 0 to 5
    If teletypePrint("Teletype effect with visible text cursor (step = " & stp & ")", i * 8, i * fontHeight(), stp, 250) = False Then
        Exit For
    End If
    stp += i + 1
Next I

Sleep
Last edited by fxm on May 23, 2024 13:22, edited 5 times in total.
Reason: Updated example with 'Escape' to quit.
xbgtc
Posts: 253
Joined: Oct 14, 2007 5:40
Location: Australia

Re: Window Screen Command?

Post by xbgtc »

sorry not to get back sooner but wow! pretty much does what my print code does. It does print slower then after examining i see it's using 250ms so no probs (interesting to see if this is faster than my print code). will have to study this a bit to see how it all works, thanks for all that effort fxm :)
Post Reply