Difference between revisions of "PRESET"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 3: Line 3:
  
 
{{PageSyntax}}
 
{{PageSyntax}}
:: PRESET [STEP](column%, row%)[, color_attribute]
+
:: '''PRESET''' [STEP]'''(''column%'', ''row%'')'''[, color_attribute]
  
  
* Can use [[STEP]] relative graphics coordinates.
+
''[[Parameters]]:''
* Column and row coordinates can be offscreen  
+
* Can use [[STEP]] when relative graphics coordinates are required.
* If the color attribute is omitted, a PRESET will be the background color, normally black.
+
* ''column'' and ''row'' coordinates can be literal ot variable [[INTEGER]] values which can be offscreen.
* Color attributes are limited to the SCREEN mode used.
+
* If the ''color attribute'' is omitted, a PRESET will be the background color, normally black.
* Any color value other than 0 will be white in monochrome SCREEN modes.
+
 
* PRESET can locate other graphics objects and add color to [[DRAW]] statements.
+
 
 +
''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.
 
* '''PRESET can be used in any graphic screen mode, but cannot be used in the default screen mode 0 as it is text only!'''  
 
* '''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:'' Using PRESET to locate a [[DRAW]] statement.
+
''Example 1:'' Using PRESET to locate a [[DRAW]] statement that draws a box that is bright red.
 
{{CodeStart}} '' ''
 
{{CodeStart}} '' ''
 
SCREEN 12
 
SCREEN 12
 
{{Cl|PRESET}}(100, 100)
 
{{Cl|PRESET}}(100, 100)
 
{{Cl|DRAW}} "C12 U20 R20 D20 L20" '' ''
 
{{Cl|DRAW}} "C12 U20 R20 D20 L20" '' ''
((CodeEnd}}
+
{{CodeEnd}}
:''Explanation:'' DRAW string required a color designation as PRESET defaulted to black background color.  
+
:''Explanation:'' The [[DRAW]] string required a color designation as PRESET defaulted to the black background color.  
:''Screen results:'' A drawn box that is bright red.
+
 
 +
 
 +
 
 +
''Example 2:'' Displays the flags of countries that use simple horizontal or vertical color blocks using a highlighted arrow key selection menu.
 +
{{CodeStart}} '' ''
 +
{{Cl|DECLARE}} {{Cl|SUB}} ARRAY ()
 +
{{Cl|DECLARE}} {{Cl|SUB}} SETUP ()
 +
{{Cl|DECLARE}} {{Cl|SUB}} SELECTION ()
 +
{{Cl|DECLARE}} {{Cl|SUB}} TERMINATE ()
 +
{{Cl|DECLARE}} {{Cl|SUB}} DISPLAY.FLAG (calc%)
 +
 
 +
{{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:''  
 
''See also:''  
  
* [[PSET]], [[CIRCLE]], [[LINE]]
+
* [[PUT (graphics statement)]]
 +
* [[GET (graphics statement)]]
 +
* [[CIRCLE]], [[LINE]], [[PSET]]
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Revision as of 18:15, 22 September 2012

The PRESET graphic SCREEN statement turns a pixel at a coordinate to the background color or a designated color attribute.


Syntax

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 CIRCLEs and add color to subsequent graphic objects and DRAW when used.
  • 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.

SCREEN 12 PRESET(100, 100) DRAW "C12 U20 R20 D20 L20"

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.

DECLARE SUB ARRAY () DECLARE SUB SETUP () DECLARE SUB SELECTION () DECLARE SUB TERMINATE () DECLARE SUB DISPLAY.FLAG (calc%) DIM SHARED c$(21), x$(21), gg%(477) ARRAY SETUP SELECTION TERMINATE END 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" END SUB SUB DISPLAY.FLAG (calc%) f% = VAL(MID$(x$(calc%), 2, 2)) s% = VAL(MID$(x$(calc%), 4, 2)) t% = VAL(MID$(x$(calc%), 6, 2)) IF LEFT$(x$(calc%), 1) = "V" THEN LINE (120, 225)-(253, 465), f%, BF LINE (254, 225)-(385, 465), s%, BF LINE (386, 225)-(519, 465), t%, BF END IF IF LEFT$(x$(calc%), 1) = "H" THEN LINE (120, 225)-(519, 305), f%, BF LINE (120, 306)-(519, 386), s%, BF LINE (120, 387)-(519, 465), t%, BF END IF END SUB SUB SELECTION 'menu selection using arrow keys x% = 2: y% = 4 DO WHILE (x% <> prevx% OR y% <> prevy%) AND k$ <> CHR$(27) k$ = INKEY$ x% = x% + (k$ = (CHR$(0) + "K") AND x% > 1) + ABS(k$ = (CHR$(0) + "M") AND x% < 3) y% = y% + (k$ = (CHR$(0) + "H") AND y% > 1) + ABS(k$ = (CHR$(0) + "P") AND y% < 7) calc% = (x% - 1) * 7 + y%: LOCATE 14, 18: PRINT c$(calc%); SPACE$(10) x1% = 140 + (x% - 1) * 128 x2% = x1% + LEN(c$(calc%)) * 8 + 7 y1% = 48 + y% * 16 IF x1% <> prevx1% OR y1% <> prevy1% THEN IF g% THEN PUT(prevx1%, prevy1%), gg%(), PSET GET(x1%, y1%)-(x2%, y1% + 16), gg%(): g% = 1 PUT(x1%, y1%), gg%(), PRESET prevx1% = x1%: prevx2% = x2%: prevy1% = y1% DISPLAY.FLAG calc% END IF WEND LOOP UNTIL k$ = CHR$(27) END SUB SUB SETUP SCREEN 12 COLOR 6 c% = 1 FOR x% = 11 TO 50 STEP 16 FOR y% = 1 TO 7 x$(c%) = RIGHT$(c$(c%), 7) c$(c%) = RTRIM$(LEFT$(c$(c%), LEN(c$(c%)) - 7)) LOCATE y% + 4, x% + 8: PRINT c$(c%) c% = c% + 1 NEXT y%, x% COLOR 11: LOCATE 3, 20: PRINT "Use the Cursor Keys to Select a Country:" LINE (119, 224)-(520, 466), 7, B END SUB SUB TERMINATE FOR c% = 1 TO 219 LINE (116 + c%, 29 + c%)-(523 - c%, 469 - c%), 0, B NEXT END SUB

Code by AlGoreIthm
Explanation: Using the PUT PRESET action highlights the menu selection in graphic screen modes by returning a negative image.


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page