Author Topic: Pipecom Browser for Filename$  (Read 10802 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #15 on: February 09, 2021, 12:06:06 am »
Ok here is a negative h BMP

W = 1024
H = -831

It says 831 at the bottom of the image, but that is an ABS value




* engine3.bmp (Filesize: 2.43 MB, Dimensions: 1024x831, Views: 436)
« Last Edit: February 09, 2021, 12:18:23 am by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #16 on: February 09, 2021, 02:51:28 pm »
@NOVARSEG

Thanks I am convinced just changing H to Long Type is not enough. But we knew that, I guess, I did after I went and reread everything again. Steve never updated his fixed Sub with another?

I checked back to last version you posted, it may work but it isn't in a handy, portable and convenient Sub like I have here. So get to work man!  ;-))

Sorry, the Interpreter muse has struck me again (won't Aurel be thrilled?) or I'd be fixing myself.

This pipecom code and array displayer are some new features planned for making editable code as well as retrieving files.
I have found my way to a "No double quotes for strings" theory, just bare naked text.

PS might need a Line Editor, not a full fledged WP.
« Last Edit: February 09, 2021, 02:53:49 pm by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #17 on: February 09, 2021, 08:12:27 pm »
Been awhile since I wrote a SUB

Do I have to put my DIMS inside the sub?   I like my DIMS at the start of a program.




« Last Edit: February 09, 2021, 08:20:35 pm by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pipecom Browser for Filename$
« Reply #18 on: February 09, 2021, 08:30:33 pm »
Been awhile since I wrote a SUB

Do I have to put my DIMS inside the sub?   I like my DIMS at the start of a program.

Are the global, or local variables?

DIM inside a sub keeps the values local to the sub, whereas DIM SHARED in the main module makethem global.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #19 on: February 09, 2021, 09:37:24 pm »
OK the sub would have to be something like

SUB loadBMP24 (Filename as string$, W AS LONG, H AS LONG, HANDLE AS LONG)
retunrs W  width of BMP
returns  H height of BMP
returns handle   generated from   " HANDLE = _NEWIMAGE(W, ABS(H), 32) "
input Filename
****

Gettimg a "memory not initialized"  these lines of code are inside the sub

    SCREEN _NEWIMAGE(W, (ABS(H)), 32)
    _PUTIMAGE (0, 0), HANDLE
    _MEMFREE a

the  _MEMFREE a  is throwing the error

*******
later   DIM SHARED a AS _MEM

fixed that error
« Last Edit: February 09, 2021, 09:44:33 pm by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #20 on: February 09, 2021, 09:46:24 pm »
@NOVARSEG

Once you get image loaded under handle you should be able to just pass handle back to main code through a Function that has type Long & on end of it's name.

I've got you started in BMP thread.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #21 on: February 09, 2021, 10:06:30 pm »
I  have a SUB working

SUB loadBMP24 (FILENAME AS STRING, W AS LONG, H AS LONG, HANDLE AS LONG)

returns W  width of BMP
returns  H height of BMP
returns handle   generated from   " HANDLE = _NEWIMAGE(W, ABS(H), 32) "
input Filename


the SUB  does not display any image. That has to be done outside the SUB

Over to the other thread
« Last Edit: February 09, 2021, 10:07:50 pm by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pipecom Browser for Filename$
« Reply #22 on: February 09, 2021, 10:12:16 pm »
Since you guys are almost done reinventing the wheel (24-bit BMP loader in this case), I’d like to also refer you to the wiki: https://www.qb64.org/wiki/Bitmaps

With it as a reference, you can expand and load 1, 4, 8 bit BMP files too, next.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #23 on: February 09, 2021, 11:51:00 pm »
Gonna try LOADIMAGE one day :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #24 on: February 10, 2021, 12:43:12 am »
Gonna try LOADIMAGE one day :)

Pipecom Browser 3 All da Images! Kicks Butt with BMP24 files, gets them right, in fact this is faster than Windows.
But my fan is running?
Code: QB64: [Select]
  1. _Title "Pipecom Browser for BMP24 File Display" 'b+ testing one array system with pipecom
  2. ' Thanks to Spriggsy, Zak, for convincing me pipecom is better!
  3. ' Using Steve's fixed BMP24 loader
  4. ' Also thanks to Dav for 1 window for file and folder selection idea
  5. ' Also thanks to NOVARSEG who got me going on this for a better filename$ retriever
  6. ' 2021-02-10 Browser 2 update with LoadBMP24 Sub
  7. ' 2021-02-10 Browser 3, just _Loadimage
  8.  
  9. Declare Library "pipecom"
  10.     Function pipecom$ (cmd As String)
  11.  
  12. Screen _NewImage(1280, 740, 32)
  13. _Delay .25
  14. _ScreenMove 65, 0 ' your screen might need different
  15.  
  16. ReDim myFile$
  17. ReDim As Long col, row, charW, charH, W, H, image
  18. Color , &HFF000033
  19. Do 'test our new function
  20.     ScnState 0
  21.     col = 16: row = 3: charW = 128: charH = 40
  22.     myFile$ = GetFileName$(row, col, charW, charH)
  23.     ScnState -1 ' <<<<<<<<<<<<<<<<<<<<<<<<<<< this is supposed to restore back color
  24.     'image& = loadBMP24&(myFile$)
  25.     image = _LoadImage(myFile$)
  26.     'loadBMP24 myFile$, W, H, image
  27.     Color , &HFF000033
  28.     Cls
  29.     If image <> 0 Then
  30.         _Title myFile$ + " press any to get another BMP24 file image, esc to quit"
  31.         _PutImage ((_Width - _Width(image&)) / 2, (_Height - _Height(image&)) / 2)-Step(_Width(image&), _Height(image&)), image&, 0
  32.         Sleep
  33.         _FreeImage image&
  34.     End If
  35.  
  36. Function GetFileName$ (LocateR, LocateC, CharWide, CharHigh) ' < careful Locate Row, Col NOT x, y
  37.     'This Funtion needs:
  38.     ' pipecom.h in same folder as QB64.exe
  39.     ' This in main code section near top:
  40.     ' Declare Library "pipecom"
  41.     '    Function pipecom$ (cmd As String)
  42.     ' End Declare
  43.     ' sub  Split source$, delimiter$, arr$()
  44.     ' function GetArrayItem$(x, y, w, h, arr$())
  45.  
  46.     ReDim As String d, s, dr
  47.     ReDim As _Unsigned Long fc, bc
  48.     fc = _DefaultColor: bc = _BackgroundColor ' save colors
  49.     Getfolder:
  50.     Color fc, bc: Cls
  51.     d = pipecom("dir /n /o:gend") '/n files on right (40) /o = order g for group dirs first, e extension, name, date
  52.     d = Left$(d, Len(d) - 1) ' always ends with delimiter
  53.     ReDim dir(1 To 1) As String
  54.     Split d, Chr$(10), dir()
  55.     s = GetArrayItem$(LocateR, LocateC, CharWide, CharHigh, dir())
  56.     If InStr(s, "<DIR>") Then 'isolate name
  57.         dr = _Trim$(Mid$(s, InStr(s, "<DIR>") + 6))
  58.         ChDir dr
  59.         GoTo Getfolder
  60.     ElseIf InStr(s, "AM") Or InStr(s, "PM") Then
  61.         GetFileName$ = _Trim$(Mid$(s, 40))
  62.         Color fc, bc: Cls
  63.     ElseIf s = "" Then 'cancel, escape, bad line
  64.         Color fc, bc: Cls ' will return empty string
  65.     End If
  66.  
  67. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  68.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  69.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  70.     dpos = InStr(curpos, SplitMeString, delim)
  71.     Do Until dpos = 0
  72.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  73.         arrpos = arrpos + 1
  74.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  75.         curpos = dpos + LD
  76.         dpos = InStr(curpos, SplitMeString, delim)
  77.     Loop
  78.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  79.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  80.  
  81.  
  82. ' Help: all this I hope is intuitive so Help window is provided
  83. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  84. ' "Press spacebar to select a highlighted item or just click it."
  85. ' "Use number(s) + enter to select an array item by it's index number,"
  86. ' "backspace will remove last number pressed, delete will clear a number started.
  87. ' "Numbers started are shown in bottom right PgDn bar."
  88. ' "Enter will also select the highlighted item, if no number has been started."
  89. ' "Home starts you at lowest array index, End highlights then highest index."
  90. ' "Use PgUp and PgDn keys to flip through pages of array items."
  91. '
  92. ' Escape to Cancel Return "" else Return the selected string from the array
  93. Function GetArrayItem$ (LocateRoww, LocateColumn, BoxWidth, BoxHeight, Arr() As String)
  94.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  95.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  96.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  97.  
  98.     ReDim As Long maxWidth, maxHeight, page, hlite, mx, my, locateRow, lastMX, lastMY, row, mb
  99.     ReDim As Long lba, uba, choice, kh, index
  100.     Dim clrStr As String, b As String
  101.  
  102.     'ScnState 0 ' use out side this function before and after
  103.     locateRow = LocateRoww + 1 'fix a miscalc in coding
  104.     maxWidth = BoxWidth '       number of characters in box
  105.     maxHeight = BoxHeight - 2 ' number of lines displayed of array at one time = 1 page
  106.     lba = LBound(arr)
  107.     uba = UBound(arr)
  108.     page = 0
  109.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  110.     clrStr$ = Space$(maxWidth) 'clearing a display line
  111.  
  112.     GoSub update '              show the beginning of the array items for selection
  113.     choice = -1719
  114.     Do 'until get a selection or demand exit
  115.  
  116.         'handle the key stuff
  117.         kh& = _KeyHit
  118.         If kh& Then
  119.             If kh& > 0 And kh& < 255 Then
  120.                 If InStr("0123456789", Chr$(kh&)) > 0 Then
  121.                     b$ = b$ + Chr$(kh&): GoSub update
  122.                 ElseIf kh& = 13 Then 'enter pressed check if number is being entered?
  123.                     If Len(b$) Then
  124.                         If Val(b$) >= lba And Val(b$) <= uba Then 'we have number started
  125.                             choice = Val(b$): Exit Do
  126.                         Else 'clear b$ to show some response to enter
  127.                             b$ = "": GoSub update 'clear the value that doesn't work
  128.                         End If
  129.                     Else
  130.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  131.                     End If
  132.                 ElseIf kh& = 27 Then
  133.                     Exit Do 'escape clause offered to Cancel selection process
  134.                 ElseIf kh& = 32 Then
  135.                     choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  136.                 ElseIf kh& = 8 Then 'backspace to edit number
  137.                     If Len(b$) Then b$ = Left$(b$, Len(b$) - 1): GoSub update
  138.                 End If
  139.             Else
  140.                 Select Case kh& 'choosing sections of array to display and highlighted item
  141.                     Case 21248 ' delete so clear b$
  142.                         b$ = "": GoSub update
  143.                     Case 20736 ' pg dn
  144.                         If (page + 1) * maxHeight + lba <= uba Then page = page + 1: GoSub update
  145.                     Case 18688 ' pg up
  146.                         If (page - 1) * maxHeight + lba >= lba Then page = page - 1: GoSub update
  147.                     Case 18432 ' up
  148.                         If hlite - 1 < 0 Then
  149.                             If page > 0 Then
  150.                                 page = page - 1: hlite = maxHeight - 1: GoSub update
  151.                             End If
  152.                         Else
  153.                             hlite = hlite - 1: GoSub update
  154.                         End If
  155.                     Case 20480 'down
  156.                         If (hlite + 1) + page * maxHeight + lba <= uba Then 'ok to move up
  157.                             If hlite + 1 > maxHeight - 1 Then
  158.                                 page = page + 1: hlite = 0: GoSub update
  159.                             Else
  160.                                 hlite = hlite + 1: GoSub update
  161.                             End If
  162.                         End If
  163.                     Case 18176 'home
  164.                         page = 0: hlite = 0: GoSub update
  165.                     Case 20224 ' end
  166.                         page = Int((uba - lba) / maxHeight): hlite = maxHeight - 1: GoSub update
  167.                 End Select
  168.             End If
  169.         End If
  170.  
  171.         'handle the mouse stuff
  172.         While _MouseInput
  173.             If _MouseWheel = -1 Then 'up?
  174.                 If hlite - 1 < 0 Then
  175.                     If page > 0 Then
  176.                         page = page - 1: hlite = maxHeight - 1: GoSub update
  177.                     End If
  178.                 Else
  179.                     hlite = hlite - 1: GoSub update
  180.                 End If
  181.             ElseIf _MouseWheel = 1 Then 'down?
  182.                 If (hlite + 1) + page * maxHeight + lba <= uba Then 'ok to move up
  183.                     If hlite + 1 > maxHeight - 1 Then
  184.                         page = page + 1: hlite = 0: GoSub update
  185.                     Else
  186.                         hlite = hlite + 1: GoSub update
  187.                     End If
  188.                 End If
  189.             End If
  190.         Wend
  191.         mx = Int((_MouseX - LocateColumn * 8) / 8) + 2: my = Int((_MouseY - locateRow * 16) / 16) + 2
  192.         If _MouseButton(1) Then 'click contols or select array item
  193.             'clear mouse clicks
  194.             mb = _MouseButton(1)
  195.             If mb Then 'clear it
  196.                 While mb 'OK!
  197.                     If _MouseInput Then mb = _MouseButton(1)
  198.                     _Limit 100
  199.                 Wend
  200.             End If
  201.  
  202.             If mx >= 1 And mx <= maxWidth And my >= 1 And my <= maxHeight Then
  203.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  204.             ElseIf mx >= 1 And mx <= maxWidth And my = 0 Then 'page up or exit
  205.                 If my = 0 And (mx <= maxWidth And mx >= maxWidth - 2) Then 'exit sign
  206.                     Exit Do 'escape plan for mouse click top right corner of display box
  207.                 Else 'PgUp bar clicked
  208.                     If (page - 1) * maxHeight + lba >= lba Then page = page - 1: GoSub update
  209.                 End If
  210.             ElseIf mx >= 1 And mx <= maxWidth And my = maxHeight + 1 Then 'page down bar clicked
  211.                 If (page + 1) * maxHeight + lba <= uba Then page = page + 1: GoSub update
  212.             End If
  213.         Else '   mouse over highlighting, only if mouse has moved!
  214.             If mx >= 1 And mx <= maxWidth And my >= 1 And my <= maxHeight Then
  215.                 If mx <> lastMX Or my <> lastMY Then
  216.                     If my - 1 <> hlite And (my - 1 + page * maxHeight + lba <= uba) Then
  217.                         hlite = my - 1
  218.                         lastMX = mx: lastMY = my
  219.                         GoSub update
  220.                     End If
  221.                 End If
  222.             End If
  223.         End If
  224.         _Limit 200
  225.     Loop Until choice >= lba And choice <= uba
  226.     If choice <> -1719 Then GetArrayItem$ = Arr(choice) 'set function and restore screen
  227.     'ScnState -1 'restore
  228.  
  229.     'display of array sections and controls on screen  ====================================================
  230.     update:
  231.  
  232.     'fix hlite if it has dropped below last array item
  233.     While hlite + page * maxHeight + lba > uba
  234.         hlite = hlite - 1
  235.     Wend
  236.  
  237.     'main display of array items at page * maxHeight (lines high)
  238.     For row = 0 To maxHeight - 1
  239.         If hlite = row Then Color _RGB(200, 200, 255), _RGB32(0, 0, 88) Else Color _RGB32(0, 0, 88), _RGB(200, 200, 255)
  240.         Locate locateRow + row, LocateColumn: Print clrStr$;
  241.         index = row + page * maxHeight + lba
  242.         If index >= lba And index <= uba Then
  243.             Locate locateRow + row, LocateColumn
  244.             Print Left$(LTrim$(Str$(index)) + ") " + Arr(index), maxWidth);
  245.         End If
  246.     Next
  247.  
  248.     'make page up and down bars to click, print PgUp / PgDn if available
  249.     Color _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  250.     Locate locateRow - 1, LocateColumn: Print Space$(maxWidth);
  251.     If page <> 0 Then Locate locateRow - 1, LocateColumn: Print Left$(" Pg Up" + Space$(maxWidth), maxWidth);
  252.     Locate locateRow + maxHeight, LocateColumn: Print Space$(maxWidth);
  253.     If page <> Int(uba / maxHeight) Then
  254.         Locate locateRow + maxHeight, LocateColumn: Print Left$(" Pg Dn" + Space$(maxWidth), maxWidth);
  255.     End If
  256.     'make exit sign for mouse click
  257.     Color _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  258.     Locate locateRow - 1, LocateColumn + maxWidth - 3
  259.     Print " X ";
  260.  
  261.     'if a number selection has been started show it's build = b$
  262.     If Len(b$) Then
  263.         Color _RGB(255, 255, 0), _RGB32(0, 0, 0)
  264.         Locate locateRow + maxHeight, LocateColumn + maxWidth - Len(b$) - 1
  265.         Print b$;
  266.     End If
  267.     _Display
  268.     _Limit 100
  269.     Return
  270.  
  271. Sub ScnState (restoreTF As Long) 'Thanks Steve McNeill  should we get a snap shot of screen?
  272.     Static As _Unsigned Long defaultColor, backGroundColor
  273.     Static As Long font, dest, source, row, col, autodisplay, mb, snap
  274.     If restoreTF Then
  275.         _Font font
  276.         Color defaultColor, backGroundColor
  277.         _Dest dest
  278.         _Source source
  279.  
  280.         _KeyClear
  281.         While _MouseInput: Wend 'clear mouse clicks
  282.         mb = _MouseButton(1)
  283.         If mb Then 'need this if line ?
  284.             Do
  285.                 While _MouseInput: Wend
  286.                 mb = _MouseButton(1)
  287.                 _Limit 100
  288.             Loop Until mb = 0
  289.         End If
  290.         _PutImage , snap, dest
  291.         _FreeImage snap
  292.         _Display
  293.         If autodisplay Then _AutoDisplay Else _Display
  294.         Locate row, col
  295.     Else
  296.         snap = _NewImage(_Width, _Height, 32)
  297.         _PutImage , 0, snap
  298.         font = _Font: defaultColor = _DefaultColor: backGroundColor = _BackgroundColor
  299.         dest = _Dest: source = _Source
  300.         row = CsrLin: col = Pos(0): autodisplay = _AutoDisplay
  301.         While _MouseInput: Wend 'clear mouse clicks
  302.         mb = _MouseButton(1)
  303.         If mb Then 'need this if line ?
  304.             Do
  305.                 While _MouseInput: Wend
  306.                 mb = _MouseButton(1)
  307.                 _Limit 100
  308.             Loop Until mb = 0
  309.         End If
  310.         _KeyClear
  311.     End If
  312.  
  313.  

You will need this in your QB64.exe file:


Pipecom Browser 3 All da Image Files!.PNG
* Pipecom Browser 3 All da Image Files!.PNG (Filesize: 32.64 KB, Dimensions: 1294x765, Views: 145)
* pipecom.h (Filesize: 0.45 KB, Downloads: 120)
« Last Edit: February 10, 2021, 12:48:29 am by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #25 on: February 10, 2021, 02:15:49 am »
 

fast viewer.   Gonna do another ver of BMP 24 viewer for speed.

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #26 on: February 10, 2021, 03:21:41 am »
 (won't Aurel be thrilled?)

Youhooooo Mark....
very nice ......
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #27 on: February 10, 2021, 04:23:30 pm »
If someone could provide a Linux command that produces a Directory Listing that distinguishes Files from Folders and provides a Sample Output Directory, I could adapt this for Linux.

@johnno56  can you help with this?
Logic is the beginning of wisdom.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #28 on: February 10, 2021, 04:24:07 pm »
If someone could provide a Linux command that produces a Directory Listing that distinguishes Files from Folders and provides a Sample Output Directory, I could adapt this for Linux.

@johnno56  can you help with this?

idk, can you?
You're not done when it works, you're done when it's right.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pipecom Browser for Filename$
« Reply #29 on: February 10, 2021, 04:47:42 pm »
Ho Ho. It is to laugh... lol

I was replying and hit ENTER before I had finished... Doh!

BPlus,

The commands 'ls' and 'dir' will display current directory contents. Main difference... the 'ls' command will display directories, executables and files in different colours. 'dir' is only white. Adding '-l' to the command will give a detailed list. To easily distinguish folders, commands and files, 'ls' or ls -l' would be the best.

There is probably a better way to do this but these are the commands that "I" use....

 
ls.png


 
ls-l.png
Logic is the beginning of wisdom.