OsDrawText
From OpenSimulator
m (Removed 'Template:' prefix from template includings and/or changed external-link into internal-link) |
|||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{osslfunc |
− | + | |threat_level=None | |
− | | | + | |function_syntax=string osDrawText(string drawList, string text) |
− | + | |ossl_example=<source lang="lsl"> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
// Example of osDrawText | // Example of osDrawText | ||
default | default | ||
Line 27: | Line 18: | ||
} | } | ||
</source> | </source> | ||
− | + | ''' And with background image: ''' | |
− | Appends a [[ | + | <source lang="lsl"> |
+ | // Example of osDrawText used to put date over a image on each face of a prim | ||
+ | |||
+ | string ImageUrl = "http://opensimulator.org/skins/osmonobook/images/headerLogo.png"; | ||
+ | string FontName = "Arial"; | ||
+ | integer FontSize = 24; | ||
+ | |||
+ | NumberEachFace() | ||
+ | { | ||
+ | integer face = llGetNumberOfSides(); | ||
+ | string text = llGetDate(); | ||
+ | vector size = osGetDrawStringSize("vector", text, FontName, FontSize); | ||
+ | integer xpos = (256 - (integer)size.x) >> 1; | ||
+ | integer ypos = (256 - 200 - (integer)size.y) >> 1; | ||
+ | |||
+ | while (face--) | ||
+ | { | ||
+ | string commandList = ""; | ||
+ | commandList = osMovePen(commandList, 0, 0); | ||
+ | commandList = osDrawImage(commandList, 256, 256, ImageUrl); | ||
+ | commandList = osMovePen(commandList, xpos, ypos); | ||
+ | commandList = osSetFontName(commandList, FontName); | ||
+ | commandList = osSetFontSize(commandList, FontSize); | ||
+ | commandList = osSetPenColor(commandList, "white"); | ||
+ | commandList = osDrawText(commandList, text); | ||
+ | osSetDynamicTextureDataBlendFace("", "vector", commandList, "width:256,height:256", TRUE, 2, 0, 255, face); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | default { | ||
+ | state_entry() { | ||
+ | NumberEachFace(); | ||
+ | } | ||
+ | |||
+ | changed(integer change) { | ||
+ | if (change & CHANGED_SHAPE) | ||
+ | NumberEachFace(); | ||
+ | } | ||
+ | }</source> | ||
+ | |description=Appends a [[Drawing commands#Text|Text]] drawing command to the string provided in '''drawList''' and returns the result. | ||
− | The specified text will be drawn with the current pen color, using the currently defined [[ | + | The specified text will be drawn with the current pen color, using the currently defined [[Drawing commands#FontName|font]], [[OsSetFontSize|size]] and [[Drawing commands#FontProp|properties]] (which default to regular 14-point Arial). |
The text will be drawn with the upper left corner of the first glyph at the pen's current position (however, note that glyphs within the font may be defined to extend to the left of their origin point). | The text will be drawn with the upper left corner of the first glyph at the pen's current position (however, note that glyphs within the font may be defined to extend to the left of their origin point). | ||
− | If you need to include a semicolon in the text to be displayed, you will need to directly manipulate the draw list string using the [[ | + | If you need to include a semicolon in the text to be displayed, you will need to directly manipulate the draw list string using the [[drawing commands]] rather than the dynamic texture convenience functions, then specify an alternate data delimiter in the <tt>extraParams</tt> parameter to the <tt>osSetDynamicTexture*</tt> functions. The convenience functions (including '''osDrawImage''') are hardcoded to terminate each command with a semicolon. |
The text may or may not be antialiased, depending on the system settings of the machine upon which the simulator is running. Furthermore, if the system is configured to use LCD subpixel antialiasing (e.g. ClearType), the text may have colored fringes on the smoothed pixels, which may result in a less than optimum image. | The text may or may not be antialiased, depending on the system settings of the machine upon which the simulator is running. Furthermore, if the system is configured to use LCD subpixel antialiasing (e.g. ClearType), the text may have colored fringes on the smoothed pixels, which may result in a less than optimum image. | ||
Please note that the pen position is ''not'' updated after this call. | Please note that the pen position is ''not'' updated after this call. | ||
− | + | | | |
− | + | }} | |
− | + |
Latest revision as of 10:37, 7 December 2018
string osDrawText(string drawList, string text)
| |
Appends a Text drawing command to the string provided in drawList and returns the result.
The specified text will be drawn with the current pen color, using the currently defined font, size and properties (which default to regular 14-point Arial). The text will be drawn with the upper left corner of the first glyph at the pen's current position (however, note that glyphs within the font may be defined to extend to the left of their origin point). If you need to include a semicolon in the text to be displayed, you will need to directly manipulate the draw list string using the drawing commands rather than the dynamic texture convenience functions, then specify an alternate data delimiter in the extraParams parameter to the osSetDynamicTexture* functions. The convenience functions (including osDrawImage) are hardcoded to terminate each command with a semicolon. The text may or may not be antialiased, depending on the system settings of the machine upon which the simulator is running. Furthermore, if the system is configured to use LCD subpixel antialiasing (e.g. ClearType), the text may have colored fringes on the smoothed pixels, which may result in a less than optimum image. Please note that the pen position is not updated after this call. | |
Threat Level | None |
Permissions | No permissions specified |
Extra Delay | No function delay specified |
Example(s) | |
// Example of osDrawText default { state_entry() { string CommandList = ""; // Storage for our drawing commands CommandList = osMovePen( CommandList, 10, 10 ); // Upper left corner at <10,10> CommandList = osDrawText( CommandList, "Hello, World!" ); // Place some text // Now draw the image osSetDynamicTextureData( "", "vector", CommandList, "width:256,height:256", 0 ); } } And with background image: // Example of osDrawText used to put date over a image on each face of a prim string ImageUrl = "http://opensimulator.org/skins/osmonobook/images/headerLogo.png"; string FontName = "Arial"; integer FontSize = 24; NumberEachFace() { integer face = llGetNumberOfSides(); string text = llGetDate(); vector size = osGetDrawStringSize("vector", text, FontName, FontSize); integer xpos = (256 - (integer)size.x) >> 1; integer ypos = (256 - 200 - (integer)size.y) >> 1; while (face--) { string commandList = ""; commandList = osMovePen(commandList, 0, 0); commandList = osDrawImage(commandList, 256, 256, ImageUrl); commandList = osMovePen(commandList, xpos, ypos); commandList = osSetFontName(commandList, FontName); commandList = osSetFontSize(commandList, FontSize); commandList = osSetPenColor(commandList, "white"); commandList = osDrawText(commandList, text); osSetDynamicTextureDataBlendFace("", "vector", commandList, "width:256,height:256", TRUE, 2, 0, 255, face); } } default { state_entry() { NumberEachFace(); } changed(integer change) { if (change & CHANGED_SHAPE) NumberEachFace(); } } |