52 lines
No EOL
1.7 KiB
C++
Executable file
52 lines
No EOL
1.7 KiB
C++
Executable file
#include "headers/input_field.hpp"
|
|
|
|
namespace asloengine
|
|
{
|
|
|
|
InputField::InputField(sf::String _name, sf::Vector2f _size, sf::Font& _font, sf::Texture& _texture, uint _text_size, int _max_length, sf::String _default_text)
|
|
: text_vertical_offset(3.5), TextOnlyInputField(_name, _size, _font, _text_size, _max_length, _default_text), SpriteObject(_name, _texture), GameObject(_name) {}
|
|
|
|
InputField::~InputField() {}
|
|
|
|
void InputField::draw()
|
|
{
|
|
|
|
SpriteObject::draw();
|
|
//sf::FloatRect sprite_bounds = sprite.getLocalBounds();
|
|
//sf::View default_view = crop ? set_crop(position.x + (sprite_bounds.width - size.x) / 2, position.y, size.x, size.y * 1.5) : render_window->getView();
|
|
TextObject::draw();
|
|
//render_window->setView(default_view);
|
|
|
|
}
|
|
|
|
void InputField::on_main_property_update()
|
|
{
|
|
|
|
SpriteObject::on_main_property_update();
|
|
|
|
sf::FloatRect sprite_bounds = sprite.getLocalBounds();
|
|
sf::FloatRect text_bounds = text->getLocalBounds();
|
|
|
|
sf::Vector2f offset(0, -text_bounds.height / text_vertical_offset);
|
|
sf::Vector2f position_correction = calculate_child_position_centered(
|
|
sprite_bounds, text_bounds, offset, scale, rotation
|
|
);
|
|
|
|
text->setPosition(position.x + position_correction.x, position.y + position_correction.y);
|
|
text->setScale(scale);
|
|
text->setOrigin(origin);
|
|
text->setRotation(rotation);
|
|
|
|
sprite_bounds = sprite.getGlobalBounds();
|
|
update_clickable(sprite_bounds);
|
|
|
|
}
|
|
|
|
void InputField::on_start()
|
|
{
|
|
|
|
set_clickable(sprite.getGlobalBounds(), render_window);
|
|
|
|
}
|
|
|
|
} |