DISPLAY (function): Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 15: Line 15:
''Example:'' Creating a mouse cursor using a page number that '''you create''' in memory without setting up page flipping.
''Example:'' Creating a mouse cursor using a page number that '''you create''' in memory without setting up page flipping.
{{CodeStart}}
{{CodeStart}}
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32) 'any graphics mode should work without setting up pages
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}}) {{Text|<nowiki>'any graphics mode should work without setting up pages</nowiki>|#919191}}
{{Cl|_MOUSEHIDE}}
{{Cl|_MOUSEHIDE}}
SetupCursor
{{Text|SetupCursor|#55FF55}}
{{Cl|PRINT}} "Hello World!"
{{Cl|PRINT}} {{Text|<nowiki>"Hello World!"</nowiki>|#FFB100}}
{{Cl|DO}}: {{Cl|_LIMIT}} 30
{{Cl|DO}}: {{Cl|_LIMIT}} {{Text|30|#F580B1}}
  {{Cl|DO}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}}: {{Cl|LOOP}} 'main loop must contain _MOUSEINPUT
    {{Cl|DO...LOOP|DO WHILE}} {{Cl|_MOUSEINPUT}}: {{Cl|LOOP}} {{Text|<nowiki>'main loop must contain _MOUSEINPUT</nowiki>|#919191}}
'      other program code
    {{Text|<nowiki>'      other program code</nowiki>|#919191}}
{{Cl|LOOP}}
{{Cl|LOOP}}


{{Cl|SUB}} SetupCursor
{{Cl|SUB}} {{Text|SetupCursor|#55FF55}}
{{Cl|ON TIMER(n)|ON TIMER}}(0.02) UpdateCursor
    {{Cl|ON TIMER(n)|ON TIMER}}({{Text|0.02|#F580B1}}) {{Text|UpdateCursor|#55FF55}}
{{Cl|TIMER}} ON
    {{Cl|TIMER}} {{Cl|ON}}
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} UpdateCursor
{{Cl|SUB}} {{Text|UpdateCursor|#55FF55}}
{{Cl|PCOPY}} {{Cl|_DISPLAY (function)|_DISPLAY}}, 100 'any page number as desination with the _DISPLAY function as source
    {{Cl|PCOPY}} {{Cl|_DISPLAY (function)|_DISPLAY}}, {{Text|100|#F580B1}} {{Text|<nowiki>'any page number as desination with the _DISPLAY function as source</nowiki>|#919191}}
{{Cl|PSET}} ({{Cl|_MOUSEX}}, {{Cl|_MOUSEY}}), {{Cl|_RGB}}(0, 255, 0)
    {{Cl|PSET}} ({{Cl|_MOUSEX}}, {{Cl|_MOUSEY}}), {{Cl|_RGB}}({{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|0|#F580B1}})
{{Cl|DRAW}} "ND10F10L3F5L4H5L3"
    {{Cl|DRAW}} {{Text|<nowiki>"ND10F10L3F5L4H5L3"</nowiki>|#FFB100}}
{{Cl|_DISPLAY}}                 'statement shows image
    {{Cl|_DISPLAY}} {{Text|<nowiki>'statement shows image</nowiki>|#919191}}
{{Cl|PCOPY}} 100, {{Cl|_DISPLAY (function)|_DISPLAY}} 'with the function return as destination page
    {{Cl|PCOPY}} {{Text|100|#F580B1}}, {{Cl|_DISPLAY (function)|_DISPLAY}} {{Text|<nowiki>'with the function return as destination page</nowiki>|#919191}}
{{Cl|END SUB}}
{{Cl|END SUB}}
{{CodeEnd}}
{{CodeEnd}}

Latest revision as of 21:24, 27 March 2023

The _DISPLAY function returns the handle of the current image that is displayed on the screen.


Syntax

currentImage& = _DISPLAY


Description

  • Returns the current image handle value that is being displayed. Returns 0 if in the default screen image.
  • Not to be confused with the _DISPLAY statement that displays the screen when not using _AUTODISPLAY.


Examples

Example: Creating a mouse cursor using a page number that you create in memory without setting up page flipping.

SCREEN _NEWIMAGE(640, 480, 32) 'any graphics mode should work without setting up pages
_MOUSEHIDE
SetupCursor
PRINT "Hello World!"
DO: _LIMIT 30
    DO WHILE _MOUSEINPUT: LOOP 'main loop must contain _MOUSEINPUT
    '       other program code
LOOP

SUB SetupCursor
    ON TIMER(0.02) UpdateCursor
    TIMER ON
END SUB

SUB UpdateCursor
    PCOPY _DISPLAY, 100 'any page number as desination with the _DISPLAY function as source
    PSET (_MOUSEX, _MOUSEY), _RGB(0, 255, 0)
    DRAW "ND10F10L3F5L4H5L3"
    _DISPLAY 'statement shows image
    PCOPY 100, _DISPLAY 'with the function return as destination page
END SUB

Note: Works with the _DISPLAY function return as the other page. If mouse reads are not crucial, put the _MOUSEINPUT loop inside of the UpdateCursor SUB.


See also



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