1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-26 16:45:53 +00:00
QB64-PE/internal/help/_WIDTH_(function).txt
SMcNeill 6e01fc8dce Altered string compare routines (<,<=,>,>=) so they don't give false results with CHR$(0).
Added new _STRCMP and _STRICMP commands for quick string comparisons.
Cleaned up QB64 to finish removing the QUI (quick user insert) code and folders.
Altered UCASE and LCASE routines to be faster in some situations for us.
2014-09-22 08:19:03 -04:00

48 lines
2.5 KiB
Plaintext

The {{KW|_WIDTH (function)|_WIDTH}} function returns the width of an image handle or current write page.
{{PageSyntax}}
:''result&amp;'' = {{KW|_WIDTH (function)|_WIDTH}}[({{Parameter|imageHandle&amp;}})]
{{PageDescription}}
* If {{Parameter|imageHandle&amp;}} is omitted, it's assumed to be the handle of the current [[SCREEN]] or write page.
* To get the width of the current program [[SCREEN|screen]] window use zero for the handle value: wide&amp; = _WIDTH(0)
* If the image specified by {{Parameter|imageHandle&amp;}} is in text only([[SCREEN]] 0) mode, the number of characters per row is returned.
* If the image specified by {{Parameter|imageHandle&amp;}} is in graphics mode, the number of pixels per row is returned.
* If {{Parameter|imageHandle&amp;}} is an invalid handle, then an [[ERROR Codes|invalid handle error]] is returned.
* The maximum pixel coordinate of a program [[SCREEN|screen]] is one less than what the function returns.
''Example:'' A SUB program that centers text in any graphic screen mode except text mode [[SCREEN (statement)|SCREEN]] 0 using '''QB64'''.
{{CodeStart}}
s&amp; = {{Cl|_NEWIMAGE}}(800, 600, 256)
SCREEN s&amp;
Align 15, 5, s&amp;, &quot;This text is centered on the screen!&quot;
SUB Align (Tcolor, Trow, mode&amp;, txt$)
center&amp; = {{Cl|_WIDTH (function)|_WIDTH}} (mode&amp;) \ 2 'returns pixels in graphic modes
MaxCol = (center&amp; \ 8) + 1 'screen text width = 8 pixels
Tcol = MaxCol - ({{Cl|LEN}}(txt$) \ 2)
{{Cl|COLOR}} Tcolor: {{Cl|LOCATE}} Trow, Tcol: {{Cl|PRINT}} txt$;
END SUB
{{CodeEnd}}
: ''Explanation:'' [[_NEWIMAGE]] enlarges a screen to 800 pixels wide which is what [[_WIDTH (function)|_WIDTH]] will return. The center is 800 \ 2 or 400. Since the text width is 8 pixels, that is divided by 8 to get 50 as the center text column. Then half of the text length is subtracted to find the starting text print [[LOCATE]] column.
: ''Note:'' The screen handle parameter is required because using no handle could assume other page handles created by functions like [[_NEWIMAGE]] or [[_PUTIMAGE]]! Use the correct handle in the SUB call! When using SCREEN 0, the MaxCol variable is not needed because _WIDTH returns the number of text columns, not pixels. Use the center value and add 1.
&lt;center&gt;Tcol = (center&amp; + 1) - LEN(txt$) \ 2 &lt;/center&gt;
{{PageSeeAlso}}
* {{KW|_HEIGHT}}, {{KW|_LOADIMAGE}}, {{KW|_NEWIMAGE}}
* {{KW|WIDTH}} (statement)
* {{KW|Bitmaps}}
{{PageNavigation}}