Use scalar to scale TileMap icons

This commit is contained in:
Andreas Haas 2016-05-27 18:54:46 +02:00
parent eb7227a20b
commit 7c1594ee5a
3 changed files with 16 additions and 23 deletions

View File

@ -720,7 +720,7 @@ void ItemList::ensure_current_is_visible() {
update(); update();
} }
static Size2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size, bool p_stretch) { static Size2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) {
if (p_max_size.x<=0) if (p_max_size.x<=0)
p_max_size.x=1e20; p_max_size.x=1e20;
@ -730,10 +730,6 @@ static Size2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size, bool p_stretch)
Size2 new_size; Size2 new_size;
if (p_stretch && (p_size.x * p_size.y < p_max_size.x * p_max_size.y)) {
return p_max_size;
}
if (p_size.x > p_max_size.x) { if (p_size.x > p_max_size.x) {
new_size.width=p_max_size.x; new_size.width=p_max_size.x;
@ -835,7 +831,7 @@ void ItemList::_notification(int p_what) {
Size2 minsize; Size2 minsize;
if (items[i].icon.is_valid()) { if (items[i].icon.is_valid()) {
minsize=_adjust_to_max_size(items[i].get_icon_size(),max_icon_size, icon_stretch); minsize=_adjust_to_max_size(items[i].get_icon_size(),max_icon_size) * icon_scale;
if (items[i].text!="") { if (items[i].text!="") {
if (icon_mode==ICON_MODE_TOP) { if (icon_mode==ICON_MODE_TOP) {
@ -980,7 +976,7 @@ void ItemList::_notification(int p_what) {
Vector2 text_ofs; Vector2 text_ofs;
if (items[i].icon.is_valid()) { if (items[i].icon.is_valid()) {
Size2 icon_size = _adjust_to_max_size(items[i].get_icon_size(),max_icon_size, icon_stretch); Size2 icon_size = _adjust_to_max_size(items[i].get_icon_size(),max_icon_size) * icon_scale;
Vector2 icon_ofs; Vector2 icon_ofs;
if (min_icon_size!=Vector2()) { if (min_icon_size!=Vector2()) {
@ -1205,14 +1201,12 @@ bool ItemList::get_allow_rmb_select() const {
return allow_rmb_select; return allow_rmb_select;
} }
void ItemList::set_icon_stretch_to_max_size(bool p_stretch) { void ItemList::set_icon_scale(real_t p_scale) {
icon_scale = p_scale;
icon_stretch = p_stretch;
} }
bool ItemList::get_icon_stretch_to_max_size() const { real_t ItemList::get_icon_scale() const {
return icon_scale;
return icon_stretch;
} }
void ItemList::_bind_methods(){ void ItemList::_bind_methods(){
@ -1275,8 +1269,8 @@ void ItemList::_bind_methods(){
ObjectTypeDB::bind_method(_MD("set_max_icon_size","size"),&ItemList::set_max_icon_size); ObjectTypeDB::bind_method(_MD("set_max_icon_size","size"),&ItemList::set_max_icon_size);
ObjectTypeDB::bind_method(_MD("get_max_icon_size"),&ItemList::get_max_icon_size); ObjectTypeDB::bind_method(_MD("get_max_icon_size"),&ItemList::get_max_icon_size);
ObjectTypeDB::bind_method(_MD("set_icon_stretch_to_max_size","stretch"),&ItemList::set_icon_stretch_to_max_size); ObjectTypeDB::bind_method(_MD("set_icon_scale","scale"),&ItemList::set_icon_scale);
ObjectTypeDB::bind_method(_MD("get_icon_stretch_to_max_size"),&ItemList::get_icon_stretch_to_max_size); ObjectTypeDB::bind_method(_MD("get_icon_scale"),&ItemList::get_icon_scale);
ObjectTypeDB::bind_method(_MD("set_allow_rmb_select","allow"),&ItemList::set_allow_rmb_select); ObjectTypeDB::bind_method(_MD("set_allow_rmb_select","allow"),&ItemList::set_allow_rmb_select);
ObjectTypeDB::bind_method(_MD("get_allow_rmb_select"),&ItemList::get_allow_rmb_select); ObjectTypeDB::bind_method(_MD("get_allow_rmb_select"),&ItemList::get_allow_rmb_select);
@ -1325,8 +1319,7 @@ ItemList::ItemList() {
defer_select_single=-1; defer_select_single=-1;
allow_rmb_select=false; allow_rmb_select=false;
icon_stretch = false; icon_scale = 1.0f;
} }
ItemList::~ItemList() { ItemList::~ItemList() {

View File

@ -45,8 +45,6 @@ private:
bool ensure_selected_visible; bool ensure_selected_visible;
bool icon_stretch;
Vector<Item> items; Vector<Item> items;
Vector<int> separators; Vector<int> separators;
@ -67,6 +65,8 @@ private:
bool allow_rmb_select; bool allow_rmb_select;
real_t icon_scale;
void _scroll_changed(double); void _scroll_changed(double);
void _input_event(const InputEvent& p_event); void _input_event(const InputEvent& p_event);
protected: protected:
@ -152,8 +152,8 @@ public:
virtual String get_tooltip(const Point2& p_pos) const; virtual String get_tooltip(const Point2& p_pos) const;
int get_item_at_pos(const Point2& p_pos,bool p_exact=false) const; int get_item_at_pos(const Point2& p_pos,bool p_exact=false) const;
void set_icon_stretch_to_max_size(bool p_stretch); void set_icon_scale(real_t p_scale);
bool get_icon_stretch_to_max_size() const; real_t get_icon_scale() const;
ItemList(); ItemList();
~ItemList(); ~ItemList();

View File

@ -1212,8 +1212,8 @@ void TileMapEditor::_icon_size_changed(float p_value) {
if (node) { if (node) {
Size2 size = node->get_cell_size() * p_value; Size2 size = node->get_cell_size() * p_value;
palette->set_min_icon_size(size + Size2(4, 0)); //4px gap between tiles palette->set_min_icon_size(size + Size2(4, 0)); //4px gap between tiles
palette->set_icon_stretch_to_max_size(true); //palette->set_max_icon_size(size);
palette->set_max_icon_size(size); palette->set_icon_scale(p_value);
_update_palette(); _update_palette();
} }
} }