mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-30 18:50:15 +00:00
141 lines
5.4 KiB
Text
141 lines
5.4 KiB
Text
|
The '''PRESET''' graphic [[SCREEN]] statement turns a pixel at a coordinate to the background color or a designated color attribute.
|
||
|
|
||
|
|
||
|
{{PageSyntax}}
|
||
|
:: '''PRESET''' [STEP]'''(''column%'', ''row%'')'''[, color_attribute]
|
||
|
|
||
|
|
||
|
''[[Parameters]]:''
|
||
|
* Can use [[STEP]] when relative graphics coordinates are required.
|
||
|
* ''column'' and ''row'' coordinates can be literal ot variable [[INTEGER]] values which can be offscreen.
|
||
|
* If the ''color attribute'' is omitted, a PRESET will be the background color, normally black.
|
||
|
|
||
|
|
||
|
''Usage:''
|
||
|
* Color attributes are limited to those available in the [[SCREEN]] mode used. [[PSET]] can be used to adopt previously used colors.
|
||
|
* Any color value other than 0 will be white in monochrome [[SCREEN]] modes 2 and 11 where the [[COLOR]] statement cannot be used.
|
||
|
* PRESET can invisibly locate other graphics objects like [[CIRCLE]]s and add color to subsequent graphic objects and [[DRAW]] when used.
|
||
|
* The PRESET action can be used in a graphics [[PUT (graphics statement)|PUT]] to produce a color inverted image on any background. See Example 2.
|
||
|
* '''PRESET can be used in any graphic screen mode, but cannot be used in the default screen mode 0 as it is text only!'''
|
||
|
|
||
|
|
||
|
''Example 1:'' Using PRESET to locate a [[DRAW]] statement that draws a box that is bright red.
|
||
|
{{CodeStart}} '' ''
|
||
|
SCREEN 12
|
||
|
{{Cl|PRESET}}(100, 100)
|
||
|
{{Cl|DRAW}} "C12 U20 R20 D20 L20" '' ''
|
||
|
{{CodeEnd}}
|
||
|
:''Explanation:'' The [[DRAW]] string required a color designation as PRESET defaulted to the black background color.
|
||
|
|
||
|
|
||
|
|
||
|
''Example 2:'' Displays the flags of countries that use simple horizontal or vertical color blocks using a highlighted arrow key selection menu.
|
||
|
{{CodeStart}} '' ''
|
||
|
{{Cl|DIM}} {{Cl|SHARED}} c$(21), x$(21), gg%(477)
|
||
|
|
||
|
ARRAY
|
||
|
SETUP
|
||
|
SELECTION
|
||
|
TERMINATE
|
||
|
|
||
|
{{Cl|END}}
|
||
|
|
||
|
{{Cl|SUB}} ARRAY
|
||
|
c$(1) = "Armenia H040914"
|
||
|
c$(2) = "Austria H041504"
|
||
|
c$(3) = "Belgium V001404"
|
||
|
c$(4) = "Bulgaria H150204"
|
||
|
c$(5) = "Chad V011404"
|
||
|
c$(6) = "C“te D'Ivoire V061502"
|
||
|
c$(7) = "Estonia H090015"
|
||
|
c$(8) = "France V011504"
|
||
|
c$(9) = "Germany H000414"
|
||
|
c$(10) = "Hungary H041502"
|
||
|
c$(11) = "Ireland V021506"
|
||
|
c$(12) = "Italy V021504"
|
||
|
c$(13) = "Lithuania H140204"
|
||
|
c$(14) = "Luxembourg H041509"
|
||
|
c$(15) = "Mali V021404"
|
||
|
c$(16) = "Netherlands H041501"
|
||
|
c$(17) = "Nigeria V021502"
|
||
|
c$(18) = "Romania V091404"
|
||
|
c$(19) = "Russia H150104"
|
||
|
c$(20) = "Sierra Leone H021509"
|
||
|
c$(21) = "Yemen H041500"
|
||
|
{{Cl|END SUB}}
|
||
|
|
||
|
{{Cl|SUB}} DISPLAY.FLAG (calc%)
|
||
|
f% = {{Cl|VAL}}({{Cl|MID$}}(x$(calc%), 2, 2))
|
||
|
s% = {{Cl|VAL}}({{Cl|MID$}}(x$(calc%), 4, 2))
|
||
|
t% = {{Cl|VAL}}({{Cl|MID$}}(x$(calc%), 6, 2))
|
||
|
|
||
|
{{Cl|IF...THEN|IF}} {{Cl|LEFT$}}(x$(calc%), 1) = "V" {{Cl|THEN}}
|
||
|
{{Cl|LINE}} (120, 225)-(253, 465), f%, BF
|
||
|
{{Cl|LINE}} (254, 225)-(385, 465), s%, BF
|
||
|
{{Cl|LINE}} (386, 225)-(519, 465), t%, BF
|
||
|
{{Cl|END IF}}
|
||
|
|
||
|
{{Cl|IF...THEN|IF}} {{Cl|LEFT$}}(x$(calc%), 1) = "H" {{Cl|THEN}}
|
||
|
{{Cl|LINE}} (120, 225)-(519, 305), f%, BF
|
||
|
{{Cl|LINE}} (120, 306)-(519, 386), s%, BF
|
||
|
{{Cl|LINE}} (120, 387)-(519, 465), t%, BF
|
||
|
{{Cl|END IF}}
|
||
|
{{Cl|END SUB}}
|
||
|
|
||
|
{{Cl|SUB}} SELECTION 'menu selection using arrow keys
|
||
|
x% = 2: y% = 4
|
||
|
|
||
|
DO
|
||
|
{{Cl|WHILE}} (x% <> prevx% {{Cl|OR (boolean)|OR}} y% <> prevy%) {{Cl|AND (boolean)|AND}} k$ <> {{Cl|CHR$}}(27)
|
||
|
k$ = {{Cl|INKEY$}}
|
||
|
x% = x% + (k$ = ({{Cl|CHR$}}(0) + "K") {{Cl|AND (boolean)|AND}} x% > 1) + {{Cl|ABS}}(k$ = ({{Cl|CHR$}}(0) + "M") {{Cl|AND (boolean)|AND}} x% < 3)
|
||
|
y% = y% + (k$ = ({{Cl|CHR$}}(0) + "H") {{Cl|AND (boolean)|AND}} y% > 1) + {{Cl|ABS}}(k$ = ({{Cl|CHR$}}(0) + "P") {{Cl|AND (boolean)|AND}} y% < 7)
|
||
|
calc% = (x% - 1) * 7 + y%: {{Cl|LOCATE}} 14, 18: {{Cl|PRINT}} c$(calc%); {{Cl|SPACE$}}(10)
|
||
|
x1% = 140 + (x% - 1) * 128
|
||
|
x2% = x1% + {{Cl|LEN}}(c$(calc%)) * 8 + 7
|
||
|
y1% = 48 + y% * 16
|
||
|
{{Cl|IF...THEN|IF}} x1% <> prevx1% {{Cl|OR (boolean)|OR}} y1% <> prevy1% {{Cl|THEN}}
|
||
|
{{Cl|IF...THEN|IF}} g% {{Cl|THEN}} {{Cl|PUT (graphics statement)|PUT}}(prevx1%, prevy1%), gg%(), {{Cl|PSET}}
|
||
|
{{Cl|GET (graphics statement)|GET}}(x1%, y1%)-(x2%, y1% + 16), gg%(): g% = 1
|
||
|
{{Cl|PUT (graphics statement)|PUT}}(x1%, y1%), gg%(), {{Cl|PRESET}}
|
||
|
prevx1% = x1%: prevx2% = x2%: prevy1% = y1%
|
||
|
DISPLAY.FLAG calc%
|
||
|
{{Cl|END IF}}
|
||
|
{{Cl|WEND}}
|
||
|
{{Cl|LOOP}} {{Cl|UNTIL}} k$ = {{Cl|CHR$}}(27)
|
||
|
{{Cl|END SUB}}
|
||
|
|
||
|
{{Cl|SUB}} SETUP
|
||
|
{{Cl|SCREEN}} 12
|
||
|
{{Cl|COLOR}} 6
|
||
|
c% = 1
|
||
|
|
||
|
{{Cl|FOR...NEXT|FOR}} x% = 11 {{Cl|TO}} 50 {{Cl|STEP}} 16
|
||
|
{{Cl|FOR...NEXT|FOR}} y% = 1 {{Cl|TO}} 7
|
||
|
x$(c%) = {{Cl|RIGHT$}}(c$(c%), 7)
|
||
|
c$(c%) = {{Cl|RTRIM$}}({{Cl|LEFT$}}(c$(c%), {{Cl|LEN}}(c$(c%)) - 7))
|
||
|
{{Cl|LOCATE}} y% + 4, x% + 8: {{Cl|PRINT}} c$(c%)
|
||
|
c% = c% + 1
|
||
|
{{Cl|NEXT}} y%, x%
|
||
|
|
||
|
{{Cl|COLOR}} 11: {{Cl|LOCATE}} 3, 20: {{Cl|PRINT}} "Use the Cursor Keys to Select a Country:"
|
||
|
{{Cl|LINE}} (119, 224)-(520, 466), 7, B
|
||
|
{{Cl|END SUB}}
|
||
|
|
||
|
{{Cl|SUB}} TERMINATE
|
||
|
{{Cl|FOR...NEXT|FOR}} c% = 1 {{Cl|TO}} 219
|
||
|
{{Cl|LINE}} (116 + c%, 29 + c%)-(523 - c%, 469 - c%), 0, B
|
||
|
{{Cl|NEXT}}
|
||
|
{{Cl|END SUB}}
|
||
|
{{CodeEnd}}{{small|Code by AlGoreIthm}}
|
||
|
: ''Explanation:'' Using the [[PUT (graphics statement)|PUT]] PRESET action highlights the menu selection in graphic screen modes by returning a negative image.
|
||
|
|
||
|
|
||
|
''See also:''
|
||
|
|
||
|
* [[PUT (graphics statement)]]
|
||
|
* [[GET (graphics statement)]]
|
||
|
* [[CIRCLE]], [[LINE]], [[PSET]]
|
||
|
|
||
|
|
||
|
{{PageNavigation}}
|