08-16-2022, 09:16 AM
I resented the preview screens crunched up so I made a modification which looks ugly LOL.
It supports backspace key to toggle between program screen preview and the description.
Also this does only 20 entries in one screen pass, putting the tags on a separate line from program name.
Took the liberty of creating this file as well:
nopreview.png.zip (Size: 102.81 KB / Downloads: 57)
Unpack this PNG file, put it in the same directory as the BAS program and its related "screenshot.png".
It supports backspace key to toggle between program screen preview and the description.
Also this does only 20 entries in one screen pass, putting the tags on a separate line from program name.
Code: (Select All)
'QB64-PE Sample Showcase
'code by SMcNeill (c) 2022
'code is under standard MIT License -- https://en.wikipedia.org/wiki/MIT_License
'inspired by code sample archive from QB64.com which is also MIT Licensed
CONST LINECURSTEP = 20
TYPE Sample_Index_Type
title AS STRING
author AS STRING
tag AS STRING
description AS STRING
END TYPE
'format for data files is:
'Start line [START ENTRY]
'Title This is the same as the directory name
'Author(s)
'Tag(s)
'Description
'Continue Description as needed.
'Finish Line [END ENTRY]
'All sample information is kept in the above format and organized for ease of reference and editing in any text editor.
DIM descornot AS _BYTE
$COLOR:32
SCREEN _NEWIMAGE(1280, 720, 32)
REDIM SHARED SI(1000) AS Sample_Index_Type, count
_TITLE "QB64-PE Sample Showcase"
Load_Sample_Index
count = count - 1
_DELAY .5
_SCREENMOVE _MIDDLE
descornot = -1
screenchanged = -1
DO
IF screenchanged THEN
DisplayScreen start, selected, limit, descornot
screenchanged = 0
END IF
k = _KEYHIT
SELECT CASE k
CASE 8
descornot = NOT descornot
screenchanged = -1
CASE 27: SYSTEM
CASE 18432
selected = selected - 1: IF selected < 0 THEN selected = LINECURSTEP
screenchanged = -1
CASE 20480:
selected = selected + 1: IF selected > limit THEN selected = 0
screenchanged = -1
CASE ASC("N"), ASC("n")
start = start + LINECURSTEP: IF start > count THEN start = 0
screenchanged = -1
CASE ASC("P"), ASC("p"):
IF start = 0 THEN
start = count - LINECURSTEP
ELSE
start = start - LINECURSTEP: IF start < 0 THEN start = 0
END IF
screenchanged = -1
END SELECT
_LIMIT 30
_DISPLAY
LOOP
SUB DisplayScreen (start, selected, limit, toggle AS _BYTE)
STATIC screenshot, blankscreen, nopreview
IF blankscreen = 0 THEN blankscreen = _NEWIMAGE(920, 680, 32)
IF nopreview = 0 THEN nopreview = _LOADIMAGE("nopreview.png", 32)
finish = start + LINECURSTEP: IF finish > count THEN finish = count
limit = finish - start
IF selected < 0 THEN selected = 0
IF selected > limit THEN selected = limit
CLS , SkyBlue
COLOR Black, transparent
PRINT " ###"; TAB(10); "Title"; TAB(40); "Author"; TAB(60); "Tags"
FOR i = start TO finish
IF i = start + selected THEN
LINE (0, selected * 32 + 16)-STEP(770, 32), Red, BF
IF toggle THEN
IF screenshot <> 0 AND screenshot <> -1 THEN _FREEIMAGE screenshot
temp$ = "./" + SI(i).title + "/screenshot.png"
screenshot = _LOADIMAGE(temp$, 32)
IF screenshot <> -1 THEN
_PUTIMAGE (340, 20)-(1259, 699), screenshot
ELSEIF nopreview <> -1 THEN
_PUTIMAGE (340, 20)-(1259, 699), nopreview
END IF
ELSE
_DEST blankscreen
CLS , Black
COLOR White, Black
PRINT SI(i).description
_DEST 0
_PUTIMAGE (340, 20)-(1259, 699), blankscreen
END IF
END IF
PRINT i; TAB(6); LEFT$(SI(i).title, 25); TAB(33); LEFT$(SI(i).author, 25)
PRINT SI(i).tag;
NEXT
COLOR Red, Black
_PRINTSTRING (20, 700), "<P>revious Page <N>ext Page <UP/DOWN> change selection"
END SUB
SUB Load_Sample_Index
OPEN ".\index.txt" FOR INPUT AS #1 'The only file we should ever have open, in all honesty.
DO UNTIL EOF(1)
LINE INPUT #1, start$
'If start$ <> "[START ENTRY]" Then Print "ERROR Reading file. Invalid Start Entry Point.": End
LINE INPUT #1, title$
LINE INPUT #1, author$
LINE INPUT #1, tag$
description$ = "": finish$ = ""
DO UNTIL finish$ = "[END ENTRY]"
LINE INPUT #1, finish$
finish$ = _TRIM$(finish$)
IF finish$ <> "[END ENTRY]" THEN description$ = description$ + finish$ + CHR$(13)
LOOP
SI(count).title = _TRIM$(title$)
SI(count).author = _TRIM$(author$)
SI(count).tag = _TRIM$(tag$)
SI(count).description = _TRIM$(description$)
count = count + 1
LOOP
CLOSE
END SUB
Took the liberty of creating this file as well:
nopreview.png.zip (Size: 102.81 KB / Downloads: 57)
Unpack this PNG file, put it in the same directory as the BAS program and its related "screenshot.png".