SelectScreen

From QB64 Wiki
Revision as of 14:35, 1 August 2010 by imported>Clippy (Created page with 'This screen mode selector shows a list of common video modes found on desktop and laptops graphics cards, and some square modes. It has full mouse support. It also has the abilit…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This screen mode selector shows a list of common video modes found on desktop and laptops graphics cards, and some square modes. It has full mouse support. It also has the ability to filter video modes for a specific aspect ratio.

Some of you might have seen this in my previous graphics program. I'm now releasing it as a library.

It's a two-part library that can be plugged into any program (using $INCLUDE) and won't interfere with existing things (unless there are FUNCTIONs with the same name as my variables, which shouldn't happen because good naming convention states SUB/FUNCTION names should be verbs, and I haven't used verbs <- not entirely true, see: reprint%. Oops.). It's two-part because it contains definitions at the start of the program, and subroutines. Originally, $INCLUDE was made for compiled libraries, so there's no default support to include QuickBASIC code inside them, which is just what I've done. Therefore you need two files included at different locations.

Example BAS Code: SelectScreen.BAS

'Here you can place some declarations like DEFINT or OPTION BASE DEFINT A-Z '$INCLUDE: 'selectscreenmode.bi' 'There are 35 screen modes, so to make them fit, show more screen rows (optional!) WIDTH 80, 40 COLOR 11: LOCATE 2, 1: PRINT TAB(28); "selectScreenMode example" 'First parameter is the number of lines to skip from the top of the screen, so you can add some text above it, 'Second parameter is the BPP, or color depth, in this case borrowed from SCREEN 13. scr& = selectScreenMode&(3, 13) SCREEN scr& 'Do your graphics stuff. CIRCLE (_WIDTH \ 2, _HEIGHT \ 2), _HEIGHT \ 4, , , , 1 END '$INCLUDE: 'selectscreenmode.bm'


Put the .bi file on top of your program and the .bm file at the bottom, after your own SUBs.

selectscreenmode.bi Code:

'#################################################################################################################### '# Screen mode selector v1.11 (include) '# By Zom-B '#################################################################################################################### videoaspect: data "all aspect",15 data "4:3",11 data "16:10",10 data "16:9",14 data "5:4",13 data "3:2",12 data "5:3",9 data "1:1",7 data "other",8 data , videomodes: data 256,256,7 data 320,240,1 data 400,300,1 data 512,384,1 data 512,512,7 data 640,480,1 data 720,540,1 data 768,576,1 data 800,480,2 data 800,600,1 data 854,480,3 data 1024,600,8 data 1024,640,2 data 1024,768,1 data 1024,1024,7 data 1152,768,5 data 1152,864,1 data 1280,720,3 data 1280,768,6 data 1280,800,2 data 1280,854,5 data 1280,960,1 data 1280,1024,4 data 1366,768,3 data 1400,1050,1 data 1440,900,2 data 1440,960,5 data 1600,900,3 data 1600,1200,1 data 1680,1050,2 data 1920,1080,3 data 1920,1200,2 data 2048,1152,3 data 2048,1536,1 data 2048,2048,7 data ,,

selectscreenmode.bm Code:

'#################################################################################################################### '# Screen mode selector v1.11 (routines) '# By Zom-B '#################################################################################################################### FUNCTION selectScreenMode& (yOffset%, colors%) 'Start neatly (bugfix v1.11) COLOR 7 'READ the DATA from the include file, while storing it in local arrays. DIM aspectName$(0 to 9), aspectCol%(0 to 9) RESTORE videoaspect FOR y% = 0 TO 10 READ aspectName$(y%), aspectCol%(y%) IF aspectCol%(y%) = 0 THEN numAspect% = y% - 1: EXIT FOR NEXT DIM vidX%(1 to 100), vidY%(1 to 100), vidA%(1 to 100) RESTORE videomodes FOR y% = 1 TO 100 READ vidX%(y%), vidY%(y%), vidA%(y%) IF (vidX%(y%) <= 0) THEN numModes% = y% - 1: EXIT FOR NEXT 'Clip the number of modes to the height of the screen. IF numModes% > _HEIGHT - yOffset% - 1 THEN numModes% = _HEIGHT - yOffset% - 1 'Select the text mode's segment for later POKEing. DEF SEG = &HB800 LOCATE yOffset% + 1, 1 PRINT "Select video mode:"; TAB(61); "Click " ' Print the down-pointing triangle (which isn't a PRINTable character! (try it)) POKE (yOffset% * 80 + 66) * 2, 31 'Initialize some things before entering the loop. selectedAspect% = 0 ' The selected aspect ratio item lastY% = 0 'the screen Y coordinate of the previously highlighted item reprint% = -1 'Used to signal that a reprint of the screen is needed lastButton% = 0 ' memory variable to detect a 'depress' of the mouse button DO 'Exit on ESC, and don't show the "Press any key" IF INKEY$ = CHR$(27) THEN CLS: SYSTEM 'Don't reprint every iteration, only when something changed IF reprint% THEN reprint% = 0 FOR x% = 1 TO numModes% LOCATE yOffset% + x% + 1, 1 'Print the video mode number in gray COLOR 7, 0 PRINT USING "##:"; x%; 'Print the video mode data in it's assigned aspect ratio color (if no aspect ratio is selected), 'otherwise, make matching video modes white and others dark gray. IF selectedAspect% = 0 THEN COLOR aspectCol%(vidA%(x%)) ELSEIF selectedAspect% = vidA%(x%) THEN COLOR 15 ELSE COLOR 8 END IF PRINT STR$(vidX%(x%)); ","; vidY%(x%); NEXT FOR x% = 0 TO numAspect% 'Print the aspect ratios. The selected one (if any) with dark cyan background. IF x% > 0 AND selectedAspect% = x% THEN COLOR aspectCol%(x%), 3 ELSE COLOR aspectCol%(x%), 0 END IF LOCATE yOffset% + x% + 2, 64 PRINT "<"; aspectName$(x%); ">" NEXT END IF IF _MOUSEINPUT THEN IF lastY% > 0 THEN 'Un-highlight any selected item by reverting the color of the entire screen row (while leaving text intact) FOR x% = 0 TO 159 STEP 2 POKE lastY% + x%, PEEK(lastY% + x%) AND &HEF NEXT END IF x% = _MOUSEX y% = _MOUSEY - yOffset% - 1 'Check if we should highlight a video mode or aspect ratio. IF x% <= 60 THEN IF y% > 0 AND y% <= numModes% THEN 'Exit if the highlighted video mode has been 'clicked' (ie. when the mouse button is depressed) IF _MOUSEBUTTON(1) = 0 AND lastButton% THEN EXIT DO 'Highlight selected video mode by changing the color of the entire item (while leaving text intact) y% = (yOffset% + y%) * 160 + 1 FOR x% = 0 TO 119 STEP 2 POKE y% + x%, PEEK(y% + x%) OR &H10 NEXT ELSE y% = 0 END IF ELSE IF y% > 0 AND y% - 1 <= numAspect% THEN IF _MOUSEBUTTON(1) THEN selectedAspect% = y% - 1 reprint% = -1 END IF 'Highlight selected aspect ratio by changing the color of the entire item (while leaving text intact) y% = (yOffset% + y%) * 160 + 1 FOR x% = 120 TO 159 STEP 2 POKE y% + x%, PEEK(y% + x%) OR &H10 NEXT ELSE y% = 0 END IF END IF lastY% = y% lastButton% = _MOUSEBUTTON(1) END IF LOOP 'Create the screen mode to return. (give it to SCREEN to use it) selectScreenMode& = _NEWIMAGE(vidX%(y%), vidY%(y%), colors%) 'Exit neatly (bugfix v1.1) COLOR 7 CLS END FUNCTION


See also:

$INCLUDE (Metacommand)

PEEK, POKE

SCREEN (statement)



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page