Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'In der unteren Leiste offene Dateien anzeigen
  2.  
  3. dim shared as integer xscale, yscale, scrollx, scrolly=1, num_lines
  4.  
  5. xscale=loword(width)
  6. yscale=hiword(width)
  7.  
  8. dim shared as ushort feld(xscale, yscale)
  9. dim shared as ubyte feld_clr_fg(xscale,yscale),feld_clr_bg(xscale,yscale),old_bg
  10. old_bg=hiword(color)
  11. redim as string lines(0 to 1000)
  12.  
  13. sub change_backcolor(y as integer, clr as integer)
  14.     for i as integer=4 to xscale-1
  15.         feld_clr_bg(i,y)=clr
  16.     next
  17. end sub
  18.  
  19. sub clear_text()
  20.     for y as integer=0 to yscale-2
  21.         for x as integer=0 to xscale-1
  22.             feld(x,y)=0
  23.             feld_clr_fg(x,y)=0
  24.             feld_clr_bg(x,y)=0
  25.         next
  26.     next
  27. end sub
  28.  
  29. sub render_text()
  30.     locate 1,1,0
  31.     for y as integer=0 to yscale-2
  32.         for x as integer=0 to xscale-1
  33.             color feld_clr_fg(x,y),old_bg
  34.             if feld_clr_bg(x,y)<>0 then color ,feld_clr_bg(x,y)
  35.             if feld(x,y)=0 then
  36.                 print " ";
  37.             else
  38.                 print wchr(feld(x,y));
  39.             end if
  40.         next
  41.         print
  42.     next
  43. end sub
  44.  
  45. sub print_text(text as string, x as integer, y as integer, clr as integer=15)
  46.     for i as integer=0 to len(text)-1
  47.         if text[i]<>&hA then feld(x+i,y)=text[i]
  48.         feld_clr_fg(x+i,y)=clr
  49.     next
  50. end sub
  51.  
  52. sub print_char(char as ushort, x as integer, y as integer, clr as integer=15)
  53.     feld(x,y)=char
  54.     feld_clr_fg(x,y)=clr
  55. end sub
  56.  
  57. var ff=freefile
  58. open "test.bas" for input as #ff
  59.     do
  60.         num_lines+=1
  61.         line input #ff,lines(num_lines)
  62.         for i as integer=0 to len(lines(num_lines))-1
  63.             if lines(num_lines)[i]=9 then
  64.                 if i=0 then
  65.                     lines(num_lines)=space(3)+mid(lines(num_lines),i+2)
  66.                 else
  67.                     lines(num_lines)=mid(lines(num_lines),1,i-1)+space(3)+mid(lines(num_lines),i+2)
  68.                 end if
  69.             end if
  70.         next
  71.     loop until eof(ff)
  72. close #ff
  73.  
  74. dim shared as integer mousex,mousey,mousez,old_mousez,mouseb,cursorx,cursory
  75.  
  76. function keypress(key as integer) as integer
  77.     static lastkey(255) as integer
  78.     static keytimer as double
  79.     if multikey(key) and not lastkey(key) then
  80.         keytimer=timer
  81.     end if
  82.     if timer>keytimer+0.5 then
  83.         return multikey(key)
  84.     end if
  85.     function = (multikey(key) and not lastkey(key))
  86.     lastkey(key) = multikey(key)
  87. end function
  88.  
  89. dim shared as ubyte change=1
  90. dim as ubyte key
  91.  
  92. do
  93.     key=asc(inkey())
  94.     select case as const key
  95.         case 32 to 254
  96.             lines(cursory)=mid(lines(cursory),1,cursorx-4)+chr(key)+mid(lines(cursory),cursorx-3)
  97.             cursorx+=1
  98.             change=1   
  99.     end select
  100.     getmouse mousex,mousey,mousez,mouseb
  101.    
  102.     if mousez<>old_mousez and mousez<>-1 then
  103.         scrolly+=(old_mousez-mousez)*4
  104.         change=1
  105.     end if
  106.     old_mousez=mousez
  107.    
  108.     if keypress(&h50) then          'Hoch
  109.         cursory+=1
  110.         if cursory>yscale-1 then scrolly+=1
  111.         change=1
  112.     elseif keypress(&h48) then      'Runter
  113.         cursory-=1
  114.         if cursory<scrolly then scrolly-=1
  115.         if scrolly<1 then scrolly=1
  116.         change=1
  117.     elseif keypress(&h4D) then      'Rechts
  118.         cursorx+=1
  119.         change=1
  120.     elseif keypress(&h4B) then      'Links
  121.         cursorx-=1
  122.         change=1
  123.     elseif keypress(&h51) then      'Bild Runter
  124.         cursory+=yscale
  125.         scrolly+=yscale
  126.         change=1
  127.     elseif keypress(&h49) then      'Bild Rauf
  128.         cursory-=yscale
  129.         scrolly-=yscale
  130.         change=1
  131.     elseif keypress(&h47) then      'Pos1
  132.         cursorx=4
  133.         change=1
  134.     elseif keypress(&h4F) then      'Ende
  135.         cursorx=4+len(lines(cursory))
  136.         change=1
  137.     end if
  138.    
  139.     if mouseb=1 then
  140.         cursorx=mousex
  141.         cursory=mousey+scrolly
  142.         change=1
  143.         mouseb=0
  144.     end if
  145.    
  146.     if cursory<1 then cursory=1
  147.     if cursory>num_lines then cursory=num_lines
  148.     if cursorx<4 then cursorx=4
  149.     if cursorx>4+len(lines(cursory)) then cursorx=4+len(lines(cursory))
  150.     if scrolly<1 then scrolly=1
  151.     if scrolly>num_lines-1 then scrolly=num_lines-1
  152.    
  153.     if change=1 then clear_text
  154.    
  155.     for i as integer=scrolly to scrolly+yscale-1
  156.         if i<10 then
  157.             print_text("  "+str(i),0,i-scrolly,8)
  158.         elseif i<100 then
  159.             print_text(" "+str(i),0,i-scrolly,8)
  160.         else
  161.             print_text(str(i),0,i-scrolly,8)
  162.         end if
  163.         print_text(lines(i),4,i-scrolly,15)
  164.        
  165.         if cursory=i then
  166.             change_backcolor(i-scrolly,8)
  167.             print_char(&h2588,cursorx,i-scrolly,15)
  168.         end if
  169.     next
  170.    
  171.     if change=1 then
  172.         render_text()
  173.         change=0
  174.     end if
  175.     sleep 2,1
  176. loop 'until key=chr(27)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement