1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 text border issues

Discussion in 'Programming' started by Daniel Mallett, Nov 10, 2019.

  1. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    165
    x = 500;
    y = 500;

    string_val = "string";
    draw_text(x, y, string_val);

    width = string_width(string_val);
    height = string_height(string_val);

    draw_rectangle(x, y, x + width, y + height, 1);

    I am trying to implement a dialogue with form controls, text, etc.

    I have been having problems centering text. The ended up stripping everything down to basics which is the code you see above.

    I have printed some text and drawn a box around it to figure out the boundary lines. Horizontally it's pixel perfect. Vertically there are gaps between the top and bottom of where the text meets the border.

    The code above should work perfectly, but it doesn't.
     
  2. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,661
    The font you are using probably has the spacing / padding in it, I just tried with Arial 12 and it's much tighter - just 1-2 pixels space at the top and bottom between the font and border rectangle.

    The default font has a larger gap, so it seems dependent on the font you are using - test a few out and see what results you get.
     
  3. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    165
    OK, I tested it with the same font but larger and the gap is no bigger. However is there a uvs get font size type functions.
     
  4. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,661
    There is - font_get_uvs()
    "This function returns an array with the UV coordinates for the font texture on the texture page, filling in the array with the following values: [0] = left, [1] = top, [2] = right and [3] = bottom. This value can then be used in other draw functions, particularly in general drawing when using primitives as well as the Shader functions."

    You could have found this by typing "font" into the IDE and looking through the list of autocomplete suggestions, or by typing "font" into the search bar in the manual. ;)
     
  5. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    165
    Thanks, yes I should have seen that. :)
     
  6. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,881
    The docs are also available online, which is handy if you don't have GM running and just wanna look something up real quickly (e.g. when answering a forum question, or slacking off planning your dream game at work / school).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice