Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QB64-PE Sample Showcase
#15
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.

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:

.zip   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".
Reply


Messages In This Thread
QB64-PE Sample Showcase - by SMcNeill - 08-14-2022, 04:00 PM
RE: QB64-PE Sample Showcase - by Pete - 08-14-2022, 04:29 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-14-2022, 04:42 PM
RE: QB64-PE Sample Showcase - by Pete - 08-14-2022, 05:39 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-14-2022, 05:08 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-14-2022, 05:42 PM
RE: QB64-PE Sample Showcase - by vince - 08-14-2022, 07:50 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-14-2022, 08:53 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-14-2022, 10:10 PM
RE: QB64-PE Sample Showcase - by dbox - 08-14-2022, 11:48 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-15-2022, 12:04 AM
RE: QB64-PE Sample Showcase - by bplus - 08-14-2022, 11:51 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-15-2022, 12:06 AM
RE: QB64-PE Sample Showcase - by bplus - 08-15-2022, 12:07 AM
RE: QB64-PE Sample Showcase - by mnrvovrfc - 08-16-2022, 09:16 AM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-16-2022, 01:39 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-21-2022, 07:00 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 08-21-2022, 07:07 PM
RE: QB64-PE Sample Showcase - by justsomeguy - 09-02-2022, 09:33 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 09-02-2022, 09:36 PM
RE: QB64-PE Sample Showcase - by grymmjack - 09-12-2023, 11:41 PM
RE: QB64-PE Sample Showcase - by grymmjack - 09-13-2023, 12:06 AM
RE: QB64-PE Sample Showcase - by TempodiBasic - 10-09-2023, 11:29 PM
RE: QB64-PE Sample Showcase - by SMcNeill - 10-10-2023, 12:05 AM
RE: QB64-PE Sample Showcase - by SpriggsySpriggs - 10-10-2023, 06:49 AM
RE: QB64-PE Sample Showcase - by bplus - 10-10-2023, 09:41 AM
RE: QB64-PE Sample Showcase - by TempodiBasic - 10-11-2023, 12:06 AM
RE: QB64-PE Sample Showcase - by TempodiBasic - 10-11-2023, 01:20 PM
RE: QB64-PE Sample Showcase - by TempodiBasic - 10-25-2023, 01:37 AM
RE: QB64-PE Sample Showcase - by TempodiBasic - 11-01-2023, 07:27 PM



Users browsing this thread: 17 Guest(s)