DxGetFontHeight: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
Line 20: | Line 20: | ||
Returns an integer of the height of the text. | Returns an integer of the height of the text. | ||
==Example== | ==Example== | ||
The following example will draw two lines of text one above the other. | |||
<section name="Client" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution | ||
scale = 2 -- The scale of both texts | |||
-- We add an event handler to keep drawing the text | |||
addEventHandler("onClientRender",getRootElement(),function() | |||
-- Draw the first text 400 pixels from the top and left of the screen | |||
dxDrawText("Hello!", 400, 400, screenWidth,screenHeight,tocolor(255,255,255,255),scale,"pricedown") | |||
-- Draw the second text above the first one. | |||
-- The variable "offset" will return the height of the first text, so we can position the second text above the first one. | |||
-- If we changed the scale, the second text would still be above the first one, since we calculated the height of the font. | |||
offset = dxGetFontHeight("Hello!",scale,"pricedown") | |||
dxDrawText("Hello!", 400, 400 - offset, screenWidth, screenHeight,tocolor(255,255,255,255),scale,"pricedown") | |||
end) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{Drawing_functions}} | {{Drawing_functions}} | ||
[[Category:Needs_Example]] | [[Category:Needs_Example]] |
Revision as of 17:08, 1 May 2011
This function retrieves the theoretical height of a certain piece of text, if it were to be drawn using dxDrawText.
Syntax
int dxGetFontHeight ( [float scale=1, string font="default"] )
Required Arguments
None
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- scale: The size of the text.
- font: The font of the text.
- "default": Tahoma
- "default-bold": Tahoma Bold
- "clear": Verdana
- "arial": Arial
- "sans": Microsoft Sans Serif
- "pricedown": Pricedown (GTA's theme text)
- "bankgothic": Bank Gothic Medium
- "diploma": Diploma Regular
- "beckett": Beckett Regular
- "unifont": Unifont
Returns
Returns an integer of the height of the text.
Example
The following example will draw two lines of text one above the other.
Click to collapse [-]
ClientscreenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution scale = 2 -- The scale of both texts -- We add an event handler to keep drawing the text addEventHandler("onClientRender",getRootElement(),function() -- Draw the first text 400 pixels from the top and left of the screen dxDrawText("Hello!", 400, 400, screenWidth,screenHeight,tocolor(255,255,255,255),scale,"pricedown") -- Draw the second text above the first one. -- The variable "offset" will return the height of the first text, so we can position the second text above the first one. -- If we changed the scale, the second text would still be above the first one, since we calculated the height of the font. offset = dxGetFontHeight("Hello!",scale,"pricedown") dxDrawText("Hello!", 400, 400 - offset, screenWidth, screenHeight,tocolor(255,255,255,255),scale,"pricedown") end)
See Also
- dxConvertPixels
- dxCreateFont
- dxCreateRenderTarget
- dxCreateScreenSource
- dxCreateShader
- dxCreateTexture
- dxDrawCircle
- dxDrawImage
- dxDrawImageSection
- dxDrawLine
- dxDrawLine3D
- dxDrawMaterialLine3D
- dxDrawMaterialPrimitive
- dxDrawMaterialPrimitive3D
- dxDrawMaterialSectionLine3D
- dxDrawPrimitive
- dxDrawPrimitive3D
- dxDrawRectangle
- dxDrawText
- dxDrawWiredSphere
- dxGetBlendMode
- dxGetFontHeight
- dxGetMaterialSize
- dxGetPixelColor
- dxGetPixelsSize
- dxGetPixelsFormat
- dxGetStatus
- dxGetTextSize
- dxGetTextWidth
- dxGetTexturePixels
- dxIsAspectRatioAdjustmentEnabled
- dxSetAspectRatioAdjustmentEnabled
- dxSetBlendMode
- dxSetPixelColor
- dxSetRenderTarget
- dxSetShaderValue
- dxSetShaderTessellation
- dxSetShaderTransform
- dxSetTestMode
- dxSetTextureEdge
- dxSetTexturePixels
- dxUpdateScreenSource