Question: resize and update button object area

  • #1, z sebastianWednesday, 10. May 2017, 23:02 hodinky 8 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?

    Kapitán

    2346 Posts


  • #2, z stroncisWednesday, 10. May 2017, 23:12 hodinky 8 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

    Bažant

    42 Posts

  • #3, z sebastianWednesday, 10. May 2017, 23:23 hodinky 8 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...

    Kapitán

    2346 Posts

  • #4, z stroncisWednesday, 10. May 2017, 23:44 hodinky 8 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.

    Bažant

    42 Posts

  • #5, z afrlmeThursday, 11. May 2017, 00:11 hodinky 8 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.

    Imperátor

    7285 Posts

  • #6, z sebastianThursday, 11. May 2017, 01:35 hodinky 8 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) 

    Kapitán

    2346 Posts