OsGetDrawStringSize
De DigiWiki.
(Différences entre les versions)
(Page créée avec « <lsl> // ---------------------------------------------------------------- // Example / Sample Script to show function use. // // Script Title: osGetDrawStringSize.lsl // S… ») |
|||
Ligne 1 : | Ligne 1 : | ||
<lsl> | <lsl> | ||
- | // -- | + | // Example of osGetDrawStringSize |
+ | default | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | string CommandList = ""; // Storage for our drawing commands | ||
+ | string TextToDraw = "Hello, World!"; // text to draw | ||
+ | |||
+ | vector Extents = osGetDrawStringSize( "vector", TextToDraw, "Arial", 14 ); | ||
+ | |||
+ | integer xpos = 128 - ((integer) Extents.x >> 1); // Center the text horizontally | ||
+ | integer ypos = 127 - ((integer) Extents.y >> 1); // and vertically | ||
+ | CommandList = osMovePen( CommandList, xpos, ypos ); // Position the text | ||
+ | CommandList = osDrawText( CommandList, TextToDraw ); // Place the text | ||
+ | |||
+ | // Now draw the text | ||
+ | osSetDynamicTextureData( "", "vector", CommandList, "width:256,height:256", 0 ); | ||
+ | } | ||
+ | } | ||
+ | </lsl> | ||
+ | |||
+ | <lsl> | ||
// Example / Sample Script to show function use. | // Example / Sample Script to show function use. | ||
// | // | ||
Ligne 14 : | Ligne 35 : | ||
// Threat Levels only apply to OSSL & AA Functions | // Threat Levels only apply to OSSL & AA Functions | ||
// See http://opensimulator.org/wiki/Threat_level | // See http://opensimulator.org/wiki/Threat_level | ||
- | // | + | // |
- | // Inworld Script Line: | + | // Inworld Script Line : vector osGetDrawStringSize( string contentType, string text, string fontName, integer fontSize); |
// | // | ||
// Example of osGetDrawStringSize | // Example of osGetDrawStringSize | ||
Ligne 23 : | Ligne 44 : | ||
string contentType = "vector"; | string contentType = "vector"; | ||
string text = "Hello"; | string text = "Hello"; | ||
- | + | // Valid Fonts that are usable See: http://www.w3schools.com/css/css_websafe_fonts.asp | |
+ | string fontName = "Arial"; | ||
integer fontSize = 14; | integer fontSize = 14; | ||
// | // | ||
Ligne 31 : | Ligne 53 : | ||
state_entry() | state_entry() | ||
{ | { | ||
- | llSay( | + | llSay(PUBLIC_CHANNEL, "Touch to see osGetDrawStringSize to write some text on the Prim Faces"); |
} | } | ||
touch_end(integer num) | touch_end(integer num) | ||
Ligne 46 : | Ligne 68 : | ||
Touched = TRUE; | Touched = TRUE; | ||
string DrawList = ""; | string DrawList = ""; | ||
- | string TextToDraw = text+" "+AvatarName; | + | string TextToDraw = text + " " + AvatarName; // text to display |
vector Extents = osGetDrawStringSize( contentType, TextToDraw, fontName, fontSize ); | vector Extents = osGetDrawStringSize( contentType, TextToDraw, fontName, fontSize ); |
Version actuelle en date du 18 décembre 2014 à 12:36
// Example of osGetDrawStringSize default { state_entry() { string CommandList = ""; // Storage for our drawing commands string TextToDraw = "Hello, World!"; // text to draw vector Extents = osGetDrawStringSize( "vector", TextToDraw, "Arial", 14 ); integer xpos = 128 - ((integer) Extents.x >> 1); // Center the text horizontally integer ypos = 127 - ((integer) Extents.y >> 1); // and vertically CommandList = osMovePen( CommandList, xpos, ypos ); // Position the text CommandList = osDrawText( CommandList, TextToDraw ); // Place the text // Now draw the text osSetDynamicTextureData( "", "vector", CommandList, "width:256,height:256", 0 ); } }
// Example / Sample Script to show function use. // // Script Title: osGetDrawStringSize.lsl // Script Author: // Threat Level: VeryLow // Script Source: // REFERENCES: http://opensimulator.org/wiki/osGetDrawStringSize // http://opensimulator.org/wiki/Drawing_commands // // Notes: See Script Source reference for more detailed information // This sample is full opensource and available to use as you see fit and desire. // Threat Levels only apply to OSSL & AA Functions // See http://opensimulator.org/wiki/Threat_level // // Inworld Script Line : vector osGetDrawStringSize( string contentType, string text, string fontName, integer fontSize); // // Example of osGetDrawStringSize // // SPECIAL NOTES See References for breakdown of values // string contentType = "vector"; string text = "Hello"; // Valid Fonts that are usable See: http://www.w3schools.com/css/css_websafe_fonts.asp string fontName = "Arial"; integer fontSize = 14; // integer Touched = FALSE; default { state_entry() { llSay(PUBLIC_CHANNEL, "Touch to see osGetDrawStringSize to write some text on the Prim Faces"); } touch_end(integer num) { string AvatarName = llKey2Name(llDetectedKey(0)); if(Touched) { Touched = FALSE; llSetTexture(TEXTURE_PLYWOOD, ALL_SIDES); } else { Touched = TRUE; string DrawList = ""; string TextToDraw = text + " " + AvatarName; // text to display vector Extents = osGetDrawStringSize( contentType, TextToDraw, fontName, fontSize ); integer xpos = 128 - ((integer) Extents.x >> 1); // Center the text horizontally integer ypos = 128 - ((integer) Extents.y >> 1); // and vertically DrawList = osMovePen( DrawList, xpos, ypos ); // Position the text DrawList = osDrawText( DrawList, TextToDraw ); // Place the text // Now draw the text osSetDynamicTextureData( "", "vector", DrawList, "width:256,height:256", 0 ); } } }