DxDrawColorText
From Multi Theft Auto: Wiki
| | This function is deprecated. This means that its use is discouraged and that it might not exist in future versions, but there should be an alternative (usually more generic) way of performing what it once did. |
Please use DxDrawText
Draws a string of text colored with hex codes (in #RRGGBB format) on the screen for one frame. In order for the text to stay visible continuously, you need to call this function with the same parameters on each frame update (see onClientRender).
It works the same as dxDrawText, except clipping and word-wrapping (not implemented yet).
Syntax
Required Arguments
- text: the text to draw
- left: the absolute X coordinate of the top left corner of the text
- top: the absolute Y coordinate of the top left corner of the text
Optional Arguments
- right: the absolute X coordinate of the right side of the text bounding box. Used for text aligning.
- bottom: the absolute Y coordinate of the bottom side of the text bounding box. Used for text aligning.
- color: the color of the text, a value produced by tocolor. Note: alpha value of this color will be used for the whole string.
- scale: the size of the text.
- font: Either a custom DX font element or the name of a built-in DX font:
- "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
- alignX: horizontal alignment of the text within the bounding box. Can be "left", "center" or "right".
- alignY: vertical alignment of the text within the bounding box. Can be "top", "center" or "bottom".
Code
Click to collapse [-]
Function sourcefunction dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default" if alignX then if alignX == "center" then ax = ax + (bx - ax - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font))/2 elseif alignX == "right" then ax = bx - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) end end if alignY then if alignY == "center" then ay = ay + (by - ay - dxGetFontHeight(scale, font))/2 elseif alignY == "bottom" then ay = by - dxGetFontHeight(scale, font) end end local alpha = string.format("%08X", color):sub(1,2) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then color = tocolor(getColorFromString("#"..col..alpha)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) ax = ax + w color = tocolor(getColorFromString("#"..col..alpha)) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) dxDrawText(cap, ax, ay, ax + dxGetTextWidth(cap, scale, font), by, color, scale, font) end end
Author: Aibo
See Also
- callClientFunction » This function allows you to call any clientside function from the server's side.
- callServerFunction » This function allows you to call any server-side function from the client's side.
- centerWindow » This function center the window in any resolution.
- Check » This function checks if it's arguments are of the right types and calls the error-function if one isn't.
- convertNumber » This function converts large numbers and adds commas to it. (Example: 100000 -> 100,000)
- coroutine.resume » Fix for hidden coroutine error messages
- dxDrawColorText » This function draws a dx text with #RRGGBB color codes support.
- dxDrawGifImage » This function simulates the effect of a GIF image by using image sprites.
- dxDrawImage3D » This function draws a 3D image.
- dxDrawRectangle3D » This function draws a 3D rectangle.
- dxGetFontSizeFromHeight » This function calculate a font size from given height for dxDraw.
- dxGetRealFontHeight » Accurately measures the pixel height of a font.
- findRotation » Takes two points and returns the direction from point A to point B.
- FormatDate » Formats a date on the basis of a format string and returns it.
- GenerateString » With this function you can generate a random string with any characters.
- getAge » This function calculates the age of a birthday.
- getAlivePlayers » This function returns all the alive players by a client side, so you can store them into a Gridlist or something like that, faster.
- getAlivePlayersInTeam » This function returns a table of the alive players in a team.
- getCursorMoveOn » This function checks in which way the cursor is currently moving.
- getDistanceBetweenPointAndSegment2D » Takes point coordinates and line (a segment) starting and ending coordinates. It returns the shortest distance between the point and the line.
- getElementSpeed » This function allows you to get element speed in kph or mph units.
- getJetpackWeaponsEnabled » This function returns a table of enabled weapons usable on a jetpack.
- getOffsetFromXYZ » This function allows you to take an entity and a position and calculate the relative offset between them accounting for rotations.
- getOnlineAdmins » This function will give the online admins.
- getOnlineStaff » Returns all online staff, names separated by two spaces.
- getPlayersByData » This function gets players who have data name you passed to it.
- getPlayerFromNamePart » This function allows you to get player From his Name part.
- getPlayersInPhotograph » This function gets all the players in a photograph.
- getPlayerFromSerial » This function gets an online player from their serial.
- getPointFromDistanceRotation » Finds a point based on a starting point, direction and distance.
- getResourceSettings » This function returns a table of the resource settings.
- getTeamFromColor » This function gets a team from it's color. (Related to: getTeamFromName)
- getTimestamp » With this function you can get the UNIX timestamp.
- getXMLNodes » Returns all children of a node
- getVehicleRespawnPosition » This function allows you to get the spawn position of a vehicle.
- guiComboBoxAdjustHeight » Adjusts the combobox to have a correct height.
- IfElse » Returns one of two values based on a boolean expression.
- isElementInPhotograph » This function checks if an element was in the player's camera picture.
- isElementInRange » This function allows you to check is the element's range to the main point is smaller than (or as big as) the maximum range.
- isElementMoving» This function checks if an element is moving.
- isPedAiming» This function checks if a ped is aiming.
- isPlayerInTeam » This function check if the player in the team.
- isLeapYear » Checks if the given year is a leap year.
- isVehicleOnRoof » This function checks whether vehicle is on roof.
- iterElements » Returns an iterator for your for loops saving time typing ipairs( getElementsByType( type ) ), instead you type: iterElements( type ).
- mathNumber » This function is a workaround for the clientside floating-point precision of 24-bits
- math.round » Rounds a number whereas the number of decimals to keep and the method may be set.
- multi_check » This function checks one element to many, handy and clean.
- onVehicleWeaponFire » This code implements an event that is triggered when a player in a vehicle fires a vehicles weapon.
- RGBToHex » This function returns a string representing the color in hexadecimal.
- setElementSpeed » This function allows you to set moving element speed in kph or mph units.
- setTableProtected » Protects a table and makes it read-only.
- setVehicleGravityPoint » This clientside function sets a vehicle's gravity in the direction of a 3 dimensional coordinate with the strength specified.
- smoothMoveCamera » This clientside function allows you to create a cinematic camera flight.
- string.count » This function counts a text from a text.
- string.explode » This function splits a string at a given separator pattern and returns a table with the pieces.
- switch » This function allow the value of a variable or expression to control the flow of program execution via a multiway branch.
- table.copy » This function copies a whole table and all the tables in that table.
- table.compare » This function check if both tables is equal.
- table.empty » This function check is empty table or not.
- table.map » This function goes through a table and replaces every field with the return of the passed function, where the field's value is passed as first argument and optionally more arguments.
- table.random » This function retrieves a random variable from a table.
- table.size » Finds the absolute size of a table.
- toHex » This function converts a decimal number to a hexadecimal number, as a fix to be used clientside.
- var dump » This function outputs information about one or more variables using outputConsole()
- wavelengthToRGBA » This function converts a phisical wavelength of light to a RGBA color.