Hello guys! One thing that is a bit strange in GMS is when you use draw_text_ext and you want to wrap a word it doesn’t work properly if one word is longer ( in pixels) than the width of the text field. Fortunately, I got some help from one user and it works almost perfectly now with one exception: I want to add one thing to the code I have now. I would like to ‘clip’ the text at the bottom of the text field if it is too long. So I would like to enter not only width but also height of the text field, and if the text is too long I wish it didn't show the remaining words/letters. So now I have the code below for wrapping :
And in the draw event I use this:
How can I clip a text from the bottom of the text field? I would be grateful for help.
Kind regards,
Dawid
Code:
/// scr_wrap_string(string,w)
var text = argument0, len = argument1;
var strlen = string_length(text);
var i = 1, c = '', w = '', word = '', line = '', result = '';
while (i <= strlen) {
c = string_char_at(text, i++);
w = string_char_at(word, 1);
// text breaking
if (c == '#') {
result += line + word + '#';
line = '';
word = '';
w = '';
continue;
}
// line breaking
if (line != '' && string_width(line + word) > len) {
result += line + '#';
line = '';
}
// word breaking
if (string_width(word + c) > len) {
line += word + '#';
word = '';
w = '';
}
// building a word
// sequence of space buttons is treated as a word
if ((c == ' ' && (w == '' || w == ' ')) || (c != ' ' && w != ' ')) {
word += c;
}
else {
line += word;
word = c;
// the line cannot be started with the space button
if (string_char_at(line, 1) == ' ') {
line = '';
}
}
}
result += line;
result += word;
return result;
Code:
var text = scr_wrap_string("Lorem ipsum dolor sit amet, andverylongwordthatmustbesplitted", 100);
draw_set_color(c_black);
draw_rectangle(10, 10, 110, 210, false); // drawing text box
draw_set_color(c_white);
draw_text(10, 10, text);
Kind regards,
Dawid