Question: resize and update button object area

  • #1, by sebastianWednesday, 10. May 2017, 23:02 7 years ago
    Heyho,

    Simon recently posted a draw text Script in another topic where a function was shown which calculates the width of a string:

    graphics.fontDimension("some text").x

    two questions here:

    1. how do i determine in which font the script calculates the width for. Bigger fonts are wider, so the returned number also has to be bigger.

    2. is it possible to resize a button area with the above given function in mind and update it (by showing the interface again)?
    My aim is my lately created custom dialog system where the clickable areas for the text are as wide as the screen -even if the text inside is maybe not screen filling.

    The ButtonPolygon is not scriptable. That means in my eyes that it doesnt get saved to the savegames but maybe it is possible to rewrite that value, reshow the interface and you are good to go. The polygon size gets calculated at the beginning of every showing of the dialog interface so i dont neccessarily need to save its state...

    Any ideas how to achieve this?

    Thread Captain

    2346 Posts


  • #2, by stroncisWednesday, 10. May 2017, 23:12 7 years ago
    Set font, then use fontDimension. As in description "get the dimension of the text with the current font", it becomes current font that way.
    graphics.font = Fonts.FontName

    Newbie

    42 Posts

  • #3, by sebastianWednesday, 10. May 2017, 23:23 7 years ago
    thanks , mate =) i guess this is written down anywhere in the luadocs, right?

    That would solve question 1, but im still trying to get this combined with resizing the button polygon which seems to be implossible right now...

    Thread Captain

    2346 Posts

  • #4, by stroncisWednesday, 10. May 2017, 23:44 7 years ago
    Yes, it is there. After you raised the question, i went to look at luadocs, as somehow i missed this graphics method, and it seems i need exactly that. I made this as testing environment:
    function thisFont()
    
      graphics.font = Fonts.Montserrat
    
      Fonts.Montserrat.Size = 20
    
      Fonts.Montserrat.VerticalLetterSpacing = 7
    
      Fonts.Montserrat.Color = colorRGB(250, 125, 25)
    
    
    
      print(graphics.fontLineHeight())
    
      print(graphics.fontColor())
    
      print(graphics.fontDimension("aa").x .. " and " .. graphics.fontDimension("aa").y)
    
    end
    
    thisFont()

    As you can see, lineheight (Size + VerticalLetterSpacing) is correct, color is in floatings - correct to, and text dimensions are in X 30 and Y 27 (Size + VerticalLetterSpacing). It's not stated in API reference, that it returns X and Y coordinates.

    P.S.: don't set font size color etc in loops, i wanted to create some rainbow text that way, but it just crashes VS Player.

    Newbie

    42 Posts

  • #5, by afrlmeThursday, 11. May 2017, 00:11 7 years ago
    Quick note: not read majority of posts, but it's not technically possible as far as I'm aware to resize the polygons. It would be complicated to say the least as hardly anyone creates a simple rect polygon with 4 nodes - they mostly consist of many nodes that form random shapes.

    Having said that, you don't technically have to use the object polygons. You could use a mouseEvent listener/handler to check if interface open & if so then if mouse inside x or y area to trigger x action. I used mouseEvent handler in ALLD demo to slide in/out the mini menu at the top of the screen. It worked quite well. You could create a Lua table containing various values (x, y, width, height) then check if cursor is inside of a specific rect on left click or something.

    Imperator

    7278 Posts

  • #6, by sebastianThursday, 11. May 2017, 01:35 7 years ago
    Yeah i could try the mouse position checking via lua. I bet i habe to do some math, too because my interface is moving and by that line1 of this interface is not always at the same spot) 

    Thread Captain

    2346 Posts