DEFAULTCOLOR: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:_DEFAULTCOLOR}}
{{DISPLAYTITLE:_DEFAULTCOLOR}}
The [[_DEFAULTCOLOR]] function returns the current default text color for an image handle or page.
The '''_DEFAULTCOLOR''' function returns the current default (text/drawing) color for an image handle or page.




{{PageSyntax}}
{{PageSyntax}}
:{{Parameter|result&}} = [[_DEFAULTCOLOR]] [({{Parameter|imageHandle&}})]
:{{Parameter|col~&}} = [[_DEFAULTCOLOR]] [({{Parameter|imageHandle&}})]


{{PageParameters}}
* If {{Parameter|imageHandle&}} is omitted, it is assumed to be the current write page or image designated by [[_DEST]].
* If {{Parameter|imageHandle&}} is an invalid handle, an [[ERROR Codes|Invalid handle]] error occurs. Check handle values first. Zero designates the current screen.


{{PageDescription}}
{{PageDescription}}
* If {{Parameter|imageHandle&}} is omitted, it is assumed to be the current write page or image designated by [[_DEST]].
* Use it to get the current default (foreground) color to restore it later in a program.
* If {{Parameter|imageHandle&}} is an invalid handle, an [[ERROR Codes|invalid handle]] error occurs. Check handle values first. Zero designates the current screen.
* In legacy [[SCREEN]] modes and in [[_NEWIMAGE]] 256 colors mode the color attribute/palette index is returned.
* Default foreground colors are: [[SCREEN]] 0 = 7, [[SCREEN]] 1 and 10 = 3, [[SCREEN]] 2 and 11 = 1. All other [[SCREEN]]s = 15.  
* In [[_NEWIMAGE]] 32-bit mode the [[_RGBA32]] value ('''&H00{{text|00|red}}{{text|00|green}}{{text|00|blue}}''' to '''&HFF{{text|FF|red}}{{text|FF|green}}{{text|FF|blue}}''') is returend, make sure to store it in an [[_UNSIGNED]] [[LONG]] variable (as seen in the syntax above with the '''~&''' symbol), otherwise the blue component may be lost.




{{PageExamples}}
{{PageExamples}}
''Example:'' The default color is the color assigned to the text foreground. The [[SCREEN]] 12 default is [[COLOR]] 15.
;Example:Storing the default color for later use. The default color is the color set as foreground.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN}} 12
{{Cl|SCREEN}} 0
{{Cl|OUT}} {{Cl|&H}}3C8, 0: {{Cl|OUT}} {{Cl|&H}}3C9, 63: {{Cl|OUT}} {{Cl|&H}}3C9, 63: {{Cl|OUT}} {{Cl|&H}}3C9, 63  'assign background RGB intensities
{{Cl|COLOR}} 4, 7 'set color 4 as foreground, color 7 as background
{{Cl|OUT}} {{Cl|&H}}3C8, 8: {{Cl|OUT}} {{Cl|&H}}3C9, 0: {{Cl|OUT}} {{Cl|&H}}3C9, 0: {{Cl|OUT}} {{Cl|&H}}3C9, 0    'assign RGB intensities to COLOR 8
{{Cl|CLS}}
{{Cl|_PRINTMODE }} {{Cl|_KEEPBACKGROUND}}
col~& = {{Cl|_DEFAULTCOLOR}}
{{Cl|COLOR}} 8                                                    'assign color 8 to text foreground
{{Cl|PRINT}} col~&
{{Cl|PRINT}} "The default color is attribute"; {{Cl|_DEFAULTCOLOR}} '' ''
{{CodeEnd}}
{{CodeEnd}}
{{OutputStartBG7}}
{{Text|4|#aa0000}}
{{OutputEnd}}




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[COLOR]]
* [[_BACKGROUNDCOLOR]]
* [[_DEST]]
* [[COLOR]], [[_DEST]]
* [[Images]]
* [[SCREEN]], [[SCREEN (function)]]
* [[Windows_Libraries#Color_Dialog_Box|Color Dialog Box]]
* [[Windows_Libraries#Color_Dialog_Box|Color Dialog Box]]




{{PageNavigation}}
{{PageNavigation}}
[[Category:Final]]

Revision as of 00:48, 14 November 2022

The _DEFAULTCOLOR function returns the current default (text/drawing) color for an image handle or page.


Syntax

col~& = _DEFAULTCOLOR [(imageHandle&)]


Parameters

  • If imageHandle& is omitted, it is assumed to be the current write page or image designated by _DEST.
  • If imageHandle& is an invalid handle, an Invalid handle error occurs. Check handle values first. Zero designates the current screen.

Description

  • Use it to get the current default (foreground) color to restore it later in a program.
  • In legacy SCREEN modes and in _NEWIMAGE 256 colors mode the color attribute/palette index is returned.
  • In _NEWIMAGE 32-bit mode the _RGBA32 value (&H00000000 to &HFFFFFFFF) is returend, make sure to store it in an _UNSIGNED LONG variable (as seen in the syntax above with the ~& symbol), otherwise the blue component may be lost.


Examples

Example
Storing the default color for later use. The default color is the color set as foreground.
SCREEN 0
COLOR 4, 7 'set color 4 as foreground, color 7 as background
CLS
col~& = _DEFAULTCOLOR
PRINT col~&
4


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link