SelectScreen - mkilgore/QB64pe GitHub Wiki
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). 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 text files included at different locations in a graphics program.
Example BAS Code: SelectResolution.BAS Demo example should be compiled by QB64 only.
DEFINT A-Z '$INCLUDE: 'selectResolution.bi' PRINT "This is screen mode 0. Select another screen mode after pressing a key." PRINT "Press any key..." i$ = INPUT (file mode)$(1) selectResolution 4, width, height IF width = 0 THEN PRINT PRINT "ESC pressed. Exiting." END END IF SCREEN (statement) _NEWIMAGE(width, height, 32) ' ' PRINT "This is your selected screen" PRINT "mode. Press any key to select" PRINT "another mode. To demonstrate" PRINT "that it keeps your screen mode" PRINT "in case you cancel, press ESC" PRINT "when selecting a mode." i$ = INPUT (file mode)$(1) selectResolution 4, width, height IF width = 0 THEN PRINT PRINT "ESC pressed. Exiting." END END IF SCREEN (statement) _NEWIMAGE(width, height, 32) PRINT "This is your selected screen mode." PRINT "Press any key to end." i$ = INPUT (file mode)$(1) '$INCLUDE: 'selectResolution.bm' |
To create the BI and BM files, copy them to Notepad and Save as ALL FILES with appropriate filename extensions!
SelectResolution.bi Code:
'######################################################################################### '# Resolution selector v1.2 (include at top of program code) '# By Zom-B '######################################################################################### videoaspect: [[DATA|DATA]] "all aspect",15 [[DATA|DATA]] "4:3",11 [[DATA|DATA]] "16:10",10 [[DATA|DATA]] "16:9",14 [[DATA|DATA]] "5:4",13 [[DATA|DATA]] "3:2",12 [[DATA|DATA]] "5:3",9 [[DATA|DATA]] "1:1",7 [[DATA|DATA]] "other",8 [[DATA|DATA]] , videomodes: [[DATA|DATA]] 256,256,7 [[DATA|DATA]] 320,240,1 [[DATA|DATA]] 400,300,1 [[DATA|DATA]] 512,384,1 [[DATA|DATA]] 512,512,7 [[DATA|DATA]] 640,480,1 [[DATA|DATA]] 720,540,1 [[DATA|DATA]] 768,576,1 [[DATA|DATA]] 800,480,2 [[DATA|DATA]] 800,600,1 [[DATA|DATA]] 854,480,3 [[DATA|DATA]] 1024,600,8 [[DATA|DATA]] 1024,640,2 [[DATA|DATA]] 1024,768,1 [[DATA|DATA]] 1024,1024,7 [[DATA|DATA]] 1152,768,5 [[DATA|DATA]] 1152,864,1 [[DATA|DATA]] 1280,720,3 [[DATA|DATA]] 1280,768,6 [[DATA|DATA]] 1280,800,2 [[DATA|DATA]] 1280,854,5 [[DATA|DATA]] 1280,960,1 [[DATA|DATA]] 1280,1024,4 [[DATA|DATA]] 1366,768,3 [[DATA|DATA]] 1400,1050,1 [[DATA|DATA]] 1440,900,2 [[DATA|DATA]] 1440,960,5 [[DATA|DATA]] 1600,900,3 [[DATA|DATA]] 1600,1200,1 [[DATA|DATA]] 1680,1050,2 [[DATA|DATA]] 1920,1080,3 [[DATA|DATA]] 1920,1200,2 [[DATA|DATA]] 2048,1152,3 [[DATA|DATA]] 2048,1536,1 [[DATA|DATA]] 2048,2048,7 [[DATA|DATA]] ,, |
SelectResolution.bm Code:
'#################################################################################################################### '# Resolution selector v1.3 (routines) '# By Zom-B '# 'Start in any mode' feature by codeguy. '#################################################################################################################### [[SUB|SUB]] selectResolution (row%, width%, height%) backupScreen& = [[_COPYIMAGE|_COPYIMAGE]] [[SCREEN (statement)|SCREEN]] 0 ' Start neatly. [[COLOR|COLOR]] 7 yOffset% = row% - 1 [[READ|<span style="color:blue;">READ</span>]] the [[DATA|DATA]] from the include file, while storing it in local arrays. [[DIM|DIM]] aspectName$(0 to 9), aspectCol%(0 to 9) [[RESTORE|RESTORE]] videoaspect [[FOR|FOR]] y% = 0 [[TO|TO]] 10 [[READ|READ]] aspectName$(y%), aspectCol%(y%) [[IF|IF]] aspectCol%(y%) = 0 [[THEN|THEN]] numAspect% = y% - 1: [[EXIT|EXIT]] [[FOR|FOR]] [[NEXT|NEXT]] [[DIM|DIM]] vidX%(1 to 100), vidY%(1 to 100), vidA%(1 to 100) [[RESTORE|RESTORE]] videomodes [[FOR|FOR]] y% = 1 [[TO|TO]] 100 [[READ|READ]] vidX%(y%), vidY%(y%), vidA%(y%) [[IF|IF]] vidX%(y%) <= 0 [[THEN|THEN]] numModes% = y% - 1: [[EXIT|EXIT]] [[FOR|FOR]] [[NEXT|NEXT]] ' If not called from [[SCREEN (statement)|SCREEN]] 0, set the number of screen rows to maximum. ' Otherwise, the height of the old screen is re-used. [[IF|IF]] [[_PIXELSIZE|_PIXELSIZE]](backupScreen&) [[THEN|THEN]] [[WIDTH|WIDTH]] , numModes% + row%: [[_FONT|_FONT ]]16 ' Clip the number of modes to the height of the screen. [[IF|IF]] numModes% > [[_HEIGHT|_HEIGHT]] - yOffset% - 1 [[THEN|THEN]] numModes% = [[_HEIGHT|_HEIGHT]] - yOffset% - 1 ' Select the text mode's segment for later [[SCREEN (statement)|SCREEN]] 0 [[POKE|POKE]]ing. [[DEF SEG|DEF SEG]] = [[&H|&H]]B800 [[LOCATE|LOCATE]] yOffset% + 1, 1 [[PRINT|PRINT]] "Select video mode:"; [[TAB|TAB]](61); "Click" ' Print the down-pointing triangle (which isn't a [[PRINT|PRINT]]able character! (try it)) [[POKE|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|DO]] ' Cancel on ESC. [[IF|IF]] [[INKEY$|INKEY$]] = [[CHR$|CHR$]](27) [[THEN|THEN]] width% = 0 height% = 0 [[EXIT DO|EXIT DO]] [[END IF|END IF]] ' Don't reprint every iteration, only when something changed. [[IF|IF]] reprint% [[THEN|THEN]] reprint% = 0 [[FOR|FOR]] x% = 1 [[TO|TO]] numModes% [[LOCATE|LOCATE]] yOffset% + x% + 1, 1 ' Print the video mode number in gray. [[COLOR|COLOR]] 7, 0 [[PRINT USING|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|IF]] selectedAspect% = 0 [[THEN|THEN]] [[COLOR|COLOR]] aspectCol%(vidA%(x%)) [[ELSEIF|ELSEIF]] selectedAspect% = vidA%(x%) [[THEN|THEN]] [[COLOR|COLOR]] 15 [[ELSE|ELSE]] [[COLOR|COLOR]] 8 [[END IF|END IF]] [[PRINT|PRINT]] [[STR$|STR$]](vidX%(x%)); ","; vidY%(x%); [[NEXT|NEXT]] [[FOR|FOR]] x% = 0 [[TO|TO]] numAspect% ' Print the aspect ratios. The selected one (if any) with dark cyan background. [[IF|IF]] x% > 0 [[AND (boolean)|AND]] selectedAspect% = x% [[THEN|THEN]] [[COLOR|COLOR]] aspectCol%(x%), 3 [[ELSE|ELSE]] [[COLOR|COLOR]] aspectCol%(x%), 0 [[END IF|END IF]] [[LOCATE|LOCATE]] yOffset% + x% + 2, 64 [[PRINT|PRINT]] "<"; aspectName$(x%); ">" [[NEXT|NEXT]] [[END IF|END IF]] [[IF|IF]] [[_MOUSEINPUT|_MOUSEINPUT]] [[THEN|THEN]] [[IF|IF]] lastY% > 0 [[THEN|THEN]] ' Un-highlight any selected item by reverting the color of the entire screen row (while leaving text intact). [[FOR|FOR]] x% = 0 [[TO|TO]] 159 [[STEP|STEP]] 2 [[POKE|POKE]] lastY% + x%, [[PEEK|PEEK]](lastY% + x%) [[AND (boolean)|AND]] [[&H|&H]]EF [[NEXT|NEXT]] [[END IF|END IF]] x% = [[_MOUSEX|_MOUSEX]] y% = [[_MOUSEY|_MOUSEY]] - yOffset% - 1 ' Check if we should highlight a video mode or aspect ratio. [[IF|IF]] x% <= 60 [[THEN|THEN]] [[IF|IF]] y% > 0 [[AND (boolean)|AND]] y% <= numModes% [[THEN|THEN]] ' Exit if the highlighted video mode has been 'clicked' (ie. when the mouse button is depressed). [[IF|IF]] [[_MOUSEBUTTON|_MOUSEBUTTON]](1) = 0 [[AND (boolean)|AND]] lastButton% [[THEN|THEN]] width% = vidX%(y%) height% = vidY%(y%) [[EXIT DO|EXIT DO]] [[END IF|END IF]] ' Highlight selected video mode by changing the color of the entire item (while leaving text intact). y% = (yOffset% + y%) * 160 + 1 [[FOR|FOR]] x% = 0 [[TO|TO]] 119 [[STEP|STEP]] 2 [[POKE|POKE]] y% + x%, [[PEEK|PEEK]](y% + x%) [[OR|OR]] [[&H|&H]]10 [[NEXT|NEXT]] [[ELSE|ELSE]] y% = 0 [[END IF|END IF]] [[ELSE|ELSE]] [[IF|IF]] y% > 0 [[AND (boolean)|AND]] y% - 1 <= numAspect% [[THEN|THEN]] [[IF|IF]] [[_MOUSEBUTTON|_MOUSEBUTTON]](1) [[THEN|THEN]] selectedAspect% = y% - 1 reprint% = -1 [[END IF|END IF]] ' Highlight selected aspect ratio by changing the color of the entire item (while leaving text intact). y% = (yOffset% + y%) * 160 + 1 [[FOR|FOR]] x% = 120 [[TO|TO]] 159 [[STEP|STEP]] 2 [[POKE|POKE]] y% + x%, [[PEEK|PEEK]](y% + x%) [[OR|OR]] [[&H|&H]]10 [[NEXT|NEXT]] [[ELSE|ELSE]] y% = 0 [[END IF|END IF]] [[END IF|END IF]] lastY% = y% lastButton% = [[_MOUSEBUTTON|_MOUSEBUTTON]](1) [[END IF|END IF]] [[LOOP|LOOP]] ' Exit neatly. [[SCREEN (statement)|SCREEN]] backupScreen& [[END SUB|END SUB]] |
See also:
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page