Announcement

Collapse
No announcement yet.

Console input with Graphic output

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Guy Dombrowski
    replied
    Dual mode window

    Arie,

    Very good thinking about that dual mode window that can be switched with a function key.
    I think I will go that way for now and I will study your last revision of PBScreen.

    Bye and many thanks again

    Guy

    Leave a comment:


  • Arie Verheul
    replied
    How to simulate a resizable window

    Guy,

    About your last question, how to obtain a resizable window, well that 's tricky one.
    The PBCC graphic window may programmatically be set to an arbitrary size, but it is not resizable. However, you could work around that.

    Often it will be sufficient to have a full screen window, and one reduced window size.
    You might consider to make your program dual mode, and toggle between full screen and reduced window size with a function key.

    I recently posted a revision of PBScreen to include the same style of mouse and keyboard support for an arbitrary graphic window.

    For a real resizable window some Windows programming would be required.
    Windows provides a ready-to-use edit window that can be tailored to many needs.
    If you are interested in this, you can find good examples of its use in the Petzold code collection by Keith A. Waters.
    See for example Chap. 8 "Poppad1.bas". This tutorial for Windows programming (753 kB) can be found in the PB download section at http://www.powerbasic.com/files/pub/pbwin/Petzold.zip

    Arie Verheul

    Leave a comment:


  • Guy Dombrowski
    replied
    Sleep

    Arie,

    Following your last post, I removed the SLEEP statements at both Process_SS_Message and Process_GS_Message and found that they are not needed. Did not see any speed change. But the GraphicScreen Function need it.

    As for the CMOS setting, it has been a long time since I have seen that I/O Recovery thing and I am in the Computer building business.
    Graphic cards today have evolved in graphical computer of their own and the memory they use is even faster than the one in the motherboard.
    The last Uber batch from Nvidia and ATI have twin cpus also. $$$$$$
    So I guess that we have to play with SLEEP command for now

    Thanks again for your nice code but I would like to have a regular resizable window instead of a full screen one ?
    What do I change ?

    Guy

    Leave a comment:


  • Arie Verheul
    replied
    Addition of Sleep statements after Graphic Attach

    Guy,

    You reported that you had to insert Sleep 25 statements after every Graphic Attach statement.

    It might be useful to mention that the Graphic Attach statements occur in different situations, and that for this reason the addition of a Sleep statement after it has different effects.

    In the SplitScreen and GraphicScreen functions they are used in the screen set-up, and there a Sleep statement does not hurt, as those functions are called only once.

    However, Graphic Attach statements also occur in the Process_SS_Message and Process_GS_Message subs.
    The purpose of these subs is to filter certain Windows messages out of a large stream, and to redirect them to the main program.
    As Windows may send lots of messages, these subs are called repeatedly, sometimes tens of times a second. For this reason, inserting a Sleep 25 statement there will seriously slow down your computer, and should be avoided by all means.
    If some delay appears to be absolutely necessary, it should be as short as possible.

    About the timing issue that you experienced: I understand that your computer has a separate video card, plugged into the bus.
    I remember that in the past, when all electronics were much slower and less advanced than it is the case today, these timing issues with peripherals were rather common, and they were usually solved by adjusting the "I/O recovery" setting in the C-MOS. I have actually no idea if modern computers still have such a setting, but it might be worthwile to see if it is present on your computer.

    Arie Verheul

    Leave a comment:


  • Michael Mayerhoffer
    replied
    Guy,

    Toy = any thing that makes me smile.

    Leave a comment:


  • Guy Dombrowski
    replied
    Sleep

    Hmmmmm....

    Arie, I had to add a SLEEP 25 after all your GRAPHIC ATTACH statements in your PBScreen program in order to prevent blank screen.
    Is my computer too fast ? I will test your code on my slow machine.

    Well, I tried it and it run well on the slow computer.
    Tried it also on another fast machine ( Xeon twin CPU 3.0g ) with a very slow video on board and the problem is even worse than with my X2. It look like a timing problem and a suitable SLEEP is needed.
    Last edited by Guy Dombrowski; 31 Mar 2008, 01:28 PM.

    Leave a comment:


  • Guy Dombrowski
    replied
    PBScreen

    Arie,

    Sorry about the mixup with Form2.bas.
    I had looked at that program just before finding your nice PBScreen code.
    It will enable me to write a much better toy like Michael called it in that next post and to answer his question :
    I use WinXP Pro with 2024 meg Ram and AMD X2-6000 twin CPU. As my VGA card is a 8800 GT I have to also use a old slow test machine to insure that my software won't need a Gamer's machine like mine to run properly.
    I am going to try to write an all graphic program without any console.
    As for that SLEEP I had to add after the ATTACH statement, to prevent a once in a while blank display, can anyone explain that behavior ?

    Leave a comment:


  • Arie Verheul
    replied
    Did you look at the right thing ?

    Guy,

    I suppose you accidentally looked at something else.
    The name of the code i referred to is not "FORM2.BAS" but PBScreen, and this is a link to it http://www.powerbasic.com/support/pb...ad.php?t=36795

    Arie Verheul

    Leave a comment:


  • Michael Mayerhoffer
    replied
    Guy
    Nice toy you have there.

    I am just wondering what version of Windows you are using.

    I think since Windows 2000 you can adjust the console for all sessions, per use or even make differnt short cuts for a style or styles you like to use.


    Just a thought.


    -Mike
    Last edited by Michael Mayerhoffer; 30 Mar 2008, 08:02 PM.

    Leave a comment:


  • Guy Dombrowski
    replied
    Suggestions

    Arie,

    Thank you so much for those suggestions.

    They were exactly what I was hoping for, as I do not want to start learning Windows coding at my advanced age.

    PBCC is a lot better than QB45 but my main beef was why I could not get rid of that crappy 80x25 console look while keeping everything else that was perfect for my needs.

    I will be studying both your FORM2.BAS programs and I think I will be working with your technique to improve my next programs.

    Again many thanks

    Guy Dombrowski

    Leave a comment:


  • Arie Verheul
    replied
    Suggestion for editor window improvement

    Guy,

    The one line console window is not needed.
    Please take a look at the source code section where i recently posted some screen handler code.
    This code includes a graphic screen with built-in support for keyboard and mouse.
    Example handlers are provided with the code.
    You simply could insert your editor code in such a keyboard handler, and get an even nicer result.

    Arie Verheul

    Leave a comment:


  • Guy Dombrowski
    started a topic Console input with Graphic output

    Console input with Graphic output

    Hi everybody,
    Here is a little program I wrote to see if it was possible to get rid of the crappy 80x25 console screen.
    It is a little rough and the technique I used reflect my old Dos upbringing but it is very eazy to follow the logic.
    For exemple, as I have a pair of twin 22 LCD I like to use long code lines instead of going vertical with more lines.
    What is missing so far is the Mouse in the window and a few other windows options.
    I tried Console Tools plus Graphics and it work fine but it is so slow that you must have a Gamer's Machine to use it properly.
    Any suggestions for improving that code will be welcomed.
    Code:
    'A better demo of console input with graphic output using a one line console stuck below the graphic window
    'The purpose is to get rid of the 80x25 console look but keep using PBCC
    'Will work well even on old slow computers
    
    #COMPILE EXE
    #DIM NONE
    DEFLNG a-z
    FUNCTION PBMAIN () AS LONG
    
     MOUSE 7,DOUBLE,DOWN: MOUSE ON       ' Activate Mouse (to be used later when I add more code)
     x=1: y=1                            ' Start position in Graphic Window
     REDIM txt$(999)                     ' Text to be displayed or modified
     DIM texte AS FIELD                  ' Text buffer for Disk IO
    
     DESKTOP GET CLIENT TO pixw,pixh     ' Find desktop size in pixels minus tray
     CONSOLE SET SCREEN 1,80             ' Console with only one line for input
     CONSOLE SET VIEW 1,80               ' Can be modified as needed
     COLOR 14,12: CLS                    ' Console color Yellow with Red Background
     CONSOLE GET SIZE TO Conw,Conh       ' Find Console size in pixels ( Bigger is better ) need at least 1024x768
     x0=pixw-conw: IF x0<0 THEN x0=0     ' Position x0 console align right
     x1=x0                               ' Position x1 window align with console
     y1=0                                ' Position y1 window align up
     x2=conw                             ' Position x2 windows align right
     w!=12: IF pixw<1280 THEN w!=9       ' Use 12 points if desktop is big enough (we want 90 columns)
     h!=24: IF pixh<1024-conh THEN h!=18 ' Use 24 pixels enough for 32 lines (we will find real text height later)
     y2=h!*32                            ' Position y2 far right like our one line console
    
     GRAPHIC WINDOW "Console input et graphic output" ,x1,y1,x2,y2 TO hwin
     GRAPHIC ATTACH hwin,0,REDRAW        ' Used to speed up graphics
     SLEEP 25                            ' Bizarre but needed as sometime the window will be blank if no Sleep used ?
     GRAPHIC CLEAR %BLACK,%GREEN
     GRAPHIC COLOR %GREEN,%BLACK
     GRAPHIC GET PIXEL (2,2) TO fond     ' Find Background color if other colors used instead of black
     GRAPHIC FONT "Lucida Console",w!,1  ' Use Courier New for Win 98
     GRAPHIC WIDTH 1
     GRAPHIC CHR SIZE TO cw!,ch!         ' Find real size of our graphic font
     y0=y2+conh/2                        ' Find our window bottom
     CONSOLE SET LOC x0,y0               ' Align console just below window
     MaxVid=31                           ' Lines used in our window
     MaxCar=90                           ' Width per lines
     MaxLgn=999                          ' Lines allowed in text
    
    ReadTxt:REM read our test file
     OPEN "c:\test.txt" FOR INPUT AS #1: z=0
      IF ERR>0 THEN ERR=0: GOTO CloseTxt ' First time with no text file
     WHILE EOF(1)=0:  z=z+1:LINE INPUT#1,txt$(z): WEND: CLOSE #1
    CloseTxt:REM end of read
    
    Heading:REM Make a one line box with text that could be placed anywhere
     GRAPHIC BOX (cw!*5,1)-(conw-cw!*5,ch!+2),5,%RED,%YELLOW
     GRAPHIC FONT "times new roman",w!-2,1
     GRAPHIC SET POS (cw!*6,2)
     GRAPHIC COLOR %BLACK,%YELLOW
     GRAPHIC PRINT "This is a Console Note Pad with 999 lines availables.  Use arrow to move around.  Esc to END.  Console Windows properties to ajust Font and Console size"
    
    ShowText:REM show first 31 lines in our graphic window
     GRAPHIC FONT "Lucida Console",w!,1: GRAPHIC COLOR %GREEN,%BLACK
      FOR t=1 TO 40: GRAPHIC SET POS((x*w!),(t*h!)): GRAPHIC PRINT txt$(t): NEXT: GRAPHIC REDRAW
     t=1: COLOR 14,12: LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$: x=LEN(txt$(t))+1
     k!=LEN(txt$(t))*cw!+cw!: GOSUB Curseur
    
    ConsoleInput: REM show yellow text with red background in console input at bottom and corresponding line in graphic window
     GRAPHIC COLOR %YELLOW,%RED: GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+" ": GRAPHIC REDRAW
     GOSUB Curseur ' Make a simple non blinking cursor for now
     LOCATE 1,x: CONSOLE SET FOCUS: ink$=WAITKEY$: ink%=0: IF ink$=CHR$(27) THEN EndConsole
      IF LEN(ink$)>1 THEN ink%=ASC(RIGHT$(ink$,1)):ink$="": GOSUB accents
     GRAPHIC COLOR %GREEN,fond: GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+" " : GRAPHIC REDRAW
    
    ScrollUp:REM Scroll window up if cursor is at bottom or PageUp is pressed
     IF ink%=73 OR (ink$=CHR$(13) AND t>MaxVid-1) OR (ink%=80 AND t>Maxvid-1) THEN
       IF t>=MaxLgn THEN BEEP: GOTO ConsoleInput ELSE t=t+1: v=MaxVid
      GRAPHIC COPY hwin,0,(0,h!*2)-(conw,h!*(MaxVid+1)) TO (0,h!)
      GRAPHIC SET POS((1*w!),(v*h!)): GRAPHIC PRINT txt$(t+v-1)+STRING$(Maxcar-LEN(txt$(t+v-1))," "): GRAPHIC REDRAW
      LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): x=LEN(txt$(t))+1: k!=x*cw!: GOTO consoleinput
     END IF
    
    ScrollDown:REM Scroll window down if cursor is at top or PageDown is pressed
     IF ink%=81 OR (ink%=72 AND t>y AND y=1) THEN
       IF t=y THEN BEEP: GOTO ConsoleInput ELSE t=t-1: v=MaxVid
      GRAPHIC COPY hwin,0,(0,h!*1)-(conw,h!*(MaxVid)) TO (0,h!*2)
      GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+STRING$(Maxcar-LEN(txt$(t))," "): GRAPHIC REDRAW
      LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): x=LEN(txt$(t)): k!=x*cw!: GOTO consoleinput
     END IF
    
    MoveDown:REM Move cursor down if Cr or Arrow down pressed
     IF ink$=CHR$(13) OR ink%=80 THEN
       IF y<32 THEN y=y+1:t=t+1 ELSE BEEP: GOTO ConsoleInput
      LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): x=LEN(txt$(t))+1: k!=x*cw!: GOTO ConsoleInput
     END IF
    
    MoveUp:REM Move cursor up if Up Arrow pressed
     IF ink%=72 THEN
       IF y>1 THEN y=y-1:t=t-1 ELSE BEEP: GOTO ConsoleInput
       LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): x=LEN(txt$(t))+1: k!=x*cw!: GOTO consoleinput
     END IF
    
    BackSpace:REM Move cursor left and erase everything right of it
     IF ink$=CHR$(8) AND x>1 THEN
        IF x>1 THEN x=x-1 ELSE BEEP: GOTO ConsoleInput
       txt$(t)=LEFT$(txt$(t),x-1)
       GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+STRING$(MaxCar-LEN(txt$(t))," "): GRAPHIC REDRAW
       LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): k!=x*cw!: GOTO consoleinput
     END IF
    
    MoveLeft:REM Move left if left arrow pressed
     IF ink%=75 THEN
        IF x>1 THEN x=x-1 ELSE BEEP: GOTO ConsoleInput
       GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+STRING$(Maxcar-LEN(txt$(t))," "): GRAPHIC REDRAW
       LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): k!=x*cw!: GOSUB Curseur: GOTO consoleinput
     END IF
    
    MoveHome:REM Move to left side of line
     IF ink%=71 THEN
        IF x>1 THEN x=1 ELSE BEEP: GOTO ConsoleInput
       GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+STRING$(Maxcar-LEN(txt$(t))," "): GRAPHIC REDRAW
       LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): k!=x*cw!: GOSUB Curseur: GOTO consoleinput
     END IF
    
    MoveRight:REM Move right if right arrow pressed
     IF ink%=77 THEN
        IF x <= LEN(txt$(t)) THEN x=x+1 ELSE BEEP: GOTO ConsoleInput
       GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+STRING$(MaxCar-LEN(txt$(t))," "): GRAPHIC REDRAW
       LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): k!=x*cw!: GOSUB Curseur: GOTO consoleinput
     END IF
    
    MoveEnd:REM move right side of line
     IF ink%=79 THEN
        IF x<LEN(txt$(t)) THEN x=LEN(txt$(t))+1 ELSE BEEP: GOTO ConsoleInput
       GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+STRING$(Maxcar-LEN(txt$(t))," "): GRAPHIC REDRAW
       LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): k!=x*cw!: GOSUB Curseur: GOTO consoleinput
     END IF
    
    DeleteOne:REM Delete one caracter and compress line left
     IF ink%=83 THEN
        IF x=>LEN(txt$(t)) THEN BEEP: z$="": GOTO ConsoleInput
       z$=LEFT$(txt$(y),x-1)+RIGHT$(txt$(y),LEN(txt$(y))-x): txt$(y)=z$
       GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(y)+STRING$(MaxCar-LEN(txt$(y))," "): GRAPHIC REDRAW
       LOCATE 1,1: z$=txt$(y): GOSUB AccentDos: PRINT z$;TAB(80): GOTO consoleinput
     END IF
    
    InsertOne:REM Insert one space ane move line right
     IF ink%=82 THEN
        IF LEN(txt$(t))>=MaxCar THEN BEEP: z$="": GOTO ConsoleInput
       z$=LEFT$(txt$(t),x-1)+" "+RIGHT$(txt$(t),LEN(txt$(t))-x+1): txt$(t)=z$
       GRAPHIC SET POS((1*w!),(y*h!)): GRAPHIC PRINT txt$(t)+STRING$(MaxCar-LEN(txt$(t))," "): GRAPHIC REDRAW
       LOCATE 1,1: z$=txt$(t): GOSUB AccentDos: PRINT z$;TAB(80): GOTO consoleinput
     END IF
    
    OutputConsole: REM Print caracter at both console and window
     z$=LEFT$(txt$(t),x-1)+ink$+MID$(txt$(t),x+1): txt$(t)=z$
     GRAPHIC SET POS((x*w!),(y*h!)): GRAPHIC PRINT ink$
     IF x<MaxCar THEN x=x+1 ELSE BEEP: GOTO ConsoleInput
     PRINT dos$: k!=x*cw!
     GOTO consoleinput
    
    EndConsole: REM End of demo and save new text
     OPEN "c:\test.txt" FOR OUTPUT AS #1
     FOR x=1 TO MaxLgn: PRINT#1,txt$(x): NEXT: CLOSE #1
     END
    
    '---------------------------------------------------------------------------------------------------------
    
    Accents:REM Map French Accents with F1 to F10 key  (ink$=Windows codes) (dos$=Dos codes)
     dos$=ink$
     IF ink%=59 THEN ink$="à": dos$="…" ' F1
     IF ink%=60 THEN ink$="â": dos$="ƒ" ' F2
     IF ink%=61 THEN ink$="ç": dos$="‡" ' F3
     IF ink%=62 THEN ink$="ô": dos$="“" ' F4
     IF ink%=63 THEN ink$="é": dos$="‚" ' F5
     IF ink%=64 THEN ink$="è": dos$="Š" ' F6
     IF ink%=65 THEN ink$="ê": dos$="ˆ" ' F7
     IF ink%=66 THEN ink$="ë": dos$="‰" ' F8
     IF ink%=67 THEN ink$="î": dos$="Œ" ' F9
     IF ink%=68 THEN ink$="û": dos$="–" ' F10
    RETURN
    
    AccentDos: REM Convert French Accents from Windows to Dos for console
     FOR z% = 1 TO LEN(z$)
      i% = ASC(MID$(z$, z%, 1))
      IF i% = 233 THEN MID$(z$, z%, 1) = CHR$(130) '‚
      IF i% = 226 THEN MID$(z$, z%, 1) = CHR$(131) 'ƒ
      IF i% = 224 THEN MID$(z$, z%, 1) = CHR$(133) '…
      IF i% = 231 THEN MID$(z$, z%, 1) = CHR$(135) '‡
      IF i% = 234 THEN MID$(z$, z%, 1) = CHR$(136) 'ˆ
      IF i% = 235 THEN MID$(z$, z%, 1) = CHR$(137) '‰
      IF i% = 232 THEN MID$(z$, z%, 1) = CHR$(138) 'Š
      IF i% = 238 THEN MID$(z$, z%, 1) = CHR$(140) 'Œ
      IF i% = 244 THEN MID$(z$, z%, 1) = CHR$(147) '“
      IF i% = 251 THEN MID$(z$, z%, 1) = CHR$(150) '–
      IF i% = 201THEN MID$(z$, z%, 1) = CHR$(144)  '
     NEXT
    RETURN
    
    Curseur:REM Simple non blinking cursor
     GRAPHIC BOX (k!,y*h!+h!-7)-(k!+cw!,y*h!+h!-4),0,%WHITE,%WHITE: SLEEP 5: GRAPHIC REDRAW
    RETURN
    
    END FUNCTION
Working...
X