GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2010-06-17 00:00:48

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

draw_text_ext replacement and related script

Originaly from flexaplex (wp), with minor changes to original draw script.

Expand//draw_text_ext2(x, y, str, sep, w); draws text the same as draw_text_ext except splitting up long words as well 
var str; 
str = argument2 + " "; 
if (string_width_ext(str, argument3, argument4) > argument4) 
{ 
  var i; 
  for (i = 1; i <= string_length(str); i += 1) 
  { 
    if (string_width_ext(string_copy(str, 1, i),argument3,argument4) > argument4) 
    { 
      str = string_insert(" ", str,max(1,i-1)); 
      i+=1;
    } 
  } 
} 
draw_text_ext(argument0, argument1, str, argument3, argument4);
Expand//string_width_ext2(str, sep, w); width compatible with draw_text_ext2
var str; 
str = argument0 + " "; 
if (string_width_ext(str, argument1, argument2) > argument2) 
{ 
  var i; 
  for (i = 1; i <= string_length(str); i += 1) 
  { 
    if (string_width_ext(string_copy(str, 1, i),argument1,argument2) > argument2) 
    { 
      str = string_insert(" ", str,max(1,i-1)); 
      i+=1;
    } 
  } 
} 
return string_width_ext(str,argument1,argument2);
Expand//string_height_ext2(str, sep, w); height compatible with draw_text_ext2
var str; 
str = argument0 + " "; 
if (string_width_ext(str, argument1, argument2) > argument2) 
{ 
  var i; 
  for (i = 1; i <= string_length(str); i += 1) 
  { 
    if (string_width_ext(string_copy(str, 1, i),argument1,argument2) > argument2) 
    { 
      str = string_insert(" ", str,max(1,i-1)); 
      i+=1;
    } 
  } 
} 
return string_height_ext(str,argument1,argument2);
Expand//string_draw_text_ext2_format(str, sep, w); generates the string, so you can call only once and use the 
//resulting string in the regular _ext functions (faster to format once)
var str; 
str = argument0 + " "; 
if (string_width_ext(str, argument1, argument2) > argument2) 
{ 
  var i; 
  for (i = 1; i <= string_length(str); i += 1) 
  { 
    if (string_width_ext(string_copy(str, 1, i),argument1,argument2) > argument2) 
    { 
      str = string_insert(" ", str,max(1,i-1)); 
      i+=1;
    } 
  } 
} 
return str;

Last edited by icuurd12b42 (2010-06-19 19:37:59)

Offline

#2 2010-06-17 14:34:56

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: draw_text_ext replacement and related script

Regarding the last script, is it functionally different than either of these existing scripts?

http://www.gmlscripts.com/script/string_width_wrap
http://www.gmlscripts.com/script/string_width_limit

I'm also not happy with the name because it doesn't extend built-in function string_format(), it does something completely different.


Abusing forum power since 1986.

Offline

#3 2010-06-17 14:49:35

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: draw_text_ext replacement and related script

Yes it's different. It reformats the string so you are able to use it with draw_text_ext correctly. Here is the gmc topic on it:
http://gmc.yoyogames.com/index.php?showtopic=401419

I'm not sure which (if any) scripts would fit well with gmlscripts though.

Last edited by flexaplex (2010-06-17 14:50:12)

Offline

#4 2010-06-17 21:38:22

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: draw_text_ext replacement and related script

name it string_draw_text_ext2_format

Offline

Board footer

Powered by FluxBB