Change font size
It is currently Tue Aug 20, 2019 4:39 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 2   [ 12 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: [Help Required]osSetDynamicTextureData
PostPosted: Wed Jun 12, 2019 7:21 am 

Joined: Thu Aug 16, 2018 6:41 am
Posts: 28
Afternoon,
I am trying to create a sign that will be updated when the object name is changed. Te sign will be simple prim 1m x 0.5m x .01m. I am trying to find a way to center the text horizontally and vertically within the prim, and for it to be ble to use any available font and still be in the right position. The only changes that I want to make will be name for example, Avatars, Furniture etc.

The code below is what I'm working with so far.
{L_CODE}:
string gSTRING__draw_data;
string gSTRING__object_name;
string gSTRING__draw_spaces = "";

integer gINTEGER__text_box_space;
integer gINTEGER__object_name_length;
default
{
    state_entry()
    {
        llSay(0, "Script Running!");
    }
    touch_start(integer total_number)
    {
        gSTRING__object_name = llGetObjectName();
        gINTEGER__object_name_length = llStringLength(gSTRING__object_name);
        gINTEGER__text_box_space = (13 - gINTEGER__object_name_length) / 2;
        for(; gINTEGER__text_box_space > 0; --gINTEGER__text_box_space)
        {
            gSTRING__draw_spaces += " ";
        }
        gSTRING__draw_data += "PenColour Black; FillRectangle 1024, 512;"; // A solid box, filled with the PenColour
        gSTRING__draw_data += "PenColour White; FontName Arial; FontSize 100;"; // Change the PenColour to the text colour we want and set the text size to 100
        gSTRING__draw_data += "MoveTo 40, 40; FontProp B,I; Text " + gSTRING__draw_spaces + gSTRING__object_name + ";"; // move in by 40 points, and down by 40 points and set bold and italic on
        gSTRING__draw_data += "FontProp R;"; // Set FontProp back to regular
        osSetDynamicTextureData("","vector", gSTRING__draw_data,"width:1024,height:512,alpha:254", 0);
    }
}

Any help / pointers would be appreciated.

Thanks in advance
Baron


Top
 OnlineProfile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Wed Jun 12, 2019 11:35 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 226
Location: Belgium / Brussels
- To center a text you can use osGetDrawStringSize.
- For fonts you can always propose a list of choices.
But beware because there are differences between fonts linux and fonts windows.
Choose the ones that are compatible.

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Thu Jun 13, 2019 6:48 am 

Joined: Thu Aug 16, 2018 6:41 am
Posts: 28
Cheers Phil
{L_QUOTE}:
To center a text you can use osGetDrawStringSize.
that is getting me in the right area. I have read the notes, and there does not seem to be a way of using osGetDrawStringSize with the FontProp modifiers for example bold, italic etc. Do you know a work around?
{L_CODE}:
string gSTRING__font_name = "Arial";
integer gINTEGER__font_size = 200;
integer gINTEGER__border = 20;

draw_text()
{
    llSetText("Working...",<1,0,0>,1.0);
    string lSTRING__text = llGetObjectName();
    vector lVECTOR__string_size = osGetDrawStringSize("vector", lSTRING__text, gSTRING__font_name, gINTEGER__font_size);
    integer lINTEGER__x_pos = (256 - (integer)lVECTOR__string_size.x) >> 1;
    while (lINTEGER__x_pos <= gINTEGER__border)
    {
        gINTEGER__font_size = gINTEGER__font_size -1;
        lVECTOR__string_size = osGetDrawStringSize("vector", lSTRING__text, gSTRING__font_name, gINTEGER__font_size);
        lINTEGER__x_pos = (256 - (integer)lVECTOR__string_size.x) >> 1;
        llSetText("Shrinking Font to " + gINTEGER__font_size, <1,1,0>,1.0);
    }

    while (lINTEGER__x_pos >= gINTEGER__border)
    {
        gINTEGER__font_size = gINTEGER__font_size +1;
        lVECTOR__string_size = osGetDrawStringSize("vector", lSTRING__text, gSTRING__font_name, gINTEGER__font_size);
        lINTEGER__x_pos = (256 - (integer)lVECTOR__string_size.x) >> 1;
        llSetText("Enlargeing Font to " + gINTEGER__font_size, <1,1,0>,1.0);
    }
    integer lINTEGER__y_pos = (256 - (integer)lVECTOR__string_size.y) >> 1;
    while (lINTEGER__y_pos <= gINTEGER__border)
    {
        gINTEGER__font_size = gINTEGER__font_size -1;
        lVECTOR__string_size = osGetDrawStringSize("vector", lSTRING__text, gSTRING__font_name, gINTEGER__font_size);
        lINTEGER__y_pos = (256 - (integer)lVECTOR__string_size.y) >> 1;
        llSetText("Shrinking Font to " + gINTEGER__font_size, <1,1,0>,1);
    }
    string lSTRING__draw_data = "";
    lSTRING__draw_data = osMovePen(lSTRING__draw_data, 0, 0);
    lSTRING__draw_data = osSetPenColor(lSTRING__draw_data, "Black");
    lSTRING__draw_data = osDrawFilledRectangle(lSTRING__draw_data, 256,256);
    lSTRING__draw_data = osMovePen(lSTRING__draw_data, lINTEGER__x_pos, lINTEGER__y_pos);
    lSTRING__draw_data = osSetFontName(lSTRING__draw_data, gSTRING__font_name);
    lSTRING__draw_data = osSetFontSize(lSTRING__draw_data, gINTEGER__font_size);
    lSTRING__draw_data = osSetPenColor(lSTRING__draw_data, "white");
    lSTRING__draw_data = osDrawText(lSTRING__draw_data, lSTRING__text);
    osSetDynamicTextureData("", "vector", lSTRING__draw_data, "width:256,height:256,alpha:254", 0);
    llSetText("",<0,0,0>,0.0);
}

default {
    state_entry() {
        draw_text;
    }

    changed(integer change) {
        if (change & CHANGED_SHAPE)
            draw_text();
    }
    touch (integer lINTEGER__touched)
    {
        draw_text();
    }
}


Top
 OnlineProfile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Thu Jun 13, 2019 8:28 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 226
Location: Belgium / Brussels
Maybee something like this ... :roll:
{L_CODE}:
// Fonts Propper v0.1 by djphil (CC_BY-NC-SA 4.0)

list FontProp = ["R", "B", "U", "I", "S"];
string FontName = "Arial";
integer FontSize = 48;
integer height = 256;
integer width = 256;
integer alpha = 255;
integer count;

default
{
    state_entry() {;}

    touch_start(integer n)
    {
        string cmd;
        string name = llGetObjectName();
        vector size = osGetDrawStringSize("vector", name, FontName, FontSize);
        integer xpos = (width - (integer)size.x) >> 1;
        integer ypos = (height - (integer)size.y) >> 1;
        cmd = osDrawFilledRectangle(cmd, width, height);
        cmd = osSetPenColor(cmd, "White");
        cmd = osMovePen(cmd, 0, 0);
        cmd = osSetPenSize(cmd, 20);
        cmd = osDrawRectangle(cmd, width, height);
        cmd = osSetFontName(cmd, FontName);
        cmd = osSetFontSize(cmd, FontSize);
        cmd = osMovePen(cmd, xpos, ypos);
        cmd += "FontProp "+llList2String(FontProp, count++) +";";
        cmd = osDrawText(cmd, name);
        string params =  "width:"+width+", height:"+height+", alpha:"+alpha+" ";
        osSetDynamicTextureData("", "vector", cmd, params, 0);
        if (count > 4) count = 0;
    }
}

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Fri Jun 14, 2019 2:45 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 226
Location: Belgium / Brussels
I've written a TextBoard in the past and never had a problem with it to use FontProp :roll:


Attachments:
OpenSimulator W3 TextBoard v0.1.png
OpenSimulator W3 TextBoard v0.1.png [ 83.56 KiB | Viewed 207 times ]

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr
Top
 Profile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Fri Jun 14, 2019 5:51 am 

Joined: Thu Aug 16, 2018 6:41 am
Posts: 28
Hi Phil,

The problem is not with applying the FontProp, but the fact that when I use the osGetDrawStringSize there is no way that I can see to add the modifier for bold, so the text no longer is centered.
{L_ATTACHMENT}:
Sandbox Text.png
Sandbox Text.png [ 22.89 KiB | Viewed 205 times ]

As you can see from the image, the starting point is the same, but the fact that the text is bigger and in italic means the end point is wrong. I could lose the italic, but the bold would be really useful.

Regards
Baron


Top
 OnlineProfile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Fri Jun 14, 2019 6:48 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 226
Location: Belgium / Brussels
If you use FontProp B & I, remplace Arial by Arial Bold :P

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Sun Jun 16, 2019 5:05 am 

Joined: Thu Aug 16, 2018 6:41 am
Posts: 28
dj phil {L_WROTE}:
If you use FontProp B & I, remplace Arial by Arial Bold :P
Cheers Phil,

I have played with settings using
{L_CODE}:
string gSTRING__font_name = "Arial Bold";
and
{L_CODE}:
string gSTRING__font_name = "Arial";
and it works with no problem. Is there a similar way to get italic or not? Or would I have to try and work out the difference between the placements, for example italic adding 3 points to the end?

Baron


Top
 OnlineProfile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Sun Jun 16, 2019 5:15 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 226
Location: Belgium / Brussels
You can cumulate 2 or 3 without problems like this:
FontProp B, I, U;

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: [Help Required]osSetDynamicTextureData
PostPosted: Sun Jun 16, 2019 5:40 am 

Joined: Thu Aug 16, 2018 6:41 am
Posts: 28
dj phil {L_WROTE}:
You can cumulate 2 or 3 without problems like this:
FontProp B, I, U;
True, but as with using bold, if you use italic, then the text is no longer centered as the osGetDrawStringSize does not seem to be able to calculate the additional length when using italics.

Example for Arial
{L_CODE}:
Arial) String Size = <219.000000, 62.000000, 0.000000>
Arial) Font Size = 41
Arial) X Position = 18
Arial) Y Position = 97
And for bold
{L_CODE}:
Arial Bold) String Size = <220.000000, 59.000000, 0.000000>
Arial Bold) Font Size = 38
Arial Bold) X Position = 18
Arial Bold) Y Position = 98
If the I is added in the font prop, the the actual text is extended by X amount, so the osGetDrawStringSize would be osGetDrawStringSize + X

If that makes sense :?:
Baron


Top
 OnlineProfile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 12 posts ]
Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net