Hi!!
i try to add an image to a button without text, but the PGButton is flat and the image has a wrong ratio. i’d like to not set the nodepath’s scale manually.
is there a way to workaround my problem?
My code is this
The PGButton object contains no code to scale an image automatically, but you can write that code yourself, for instance by using NodePath::calc_tight_bounds().
Oh, I’m sorry, I misunderstood your original question. You’re trying to scale the button to match the aspect ratio of the original image file, not trying to scale the button to fit some pre-loaded geometry object.
Use Texture::get_orig_file_x_size() and Texture::get_orig_file_y_size() to determine the appropriate aspect ratio for your button.
PGButton::setup(string) will try to shape the button to fit the given string.
Instead of that, use the PGButton::setup() method that receives a NodePath, and pass it a NodePath that you know is square. For instance, use CardMaker to generate a square. In fact, you could then apply the texture to that square and not have to use PGFrameStyle::set_texture(). (This depends on precisely what look you want to achieve.)
Or, instead of using PGButton::setup(), just use PGButton::set_frame() to specify a square button directly.