Path: blob/master/editor/scene/2d/tiles/tile_atlas_view.h
22321 views
/**************************************************************************/1/* tile_atlas_view.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/gui/editor_zoom_widget.h"33#include "scene/gui/box_container.h"34#include "scene/gui/button.h"35#include "scene/gui/center_container.h"36#include "scene/gui/label.h"37#include "scene/gui/margin_container.h"38#include "scene/resources/2d/tile_set.h"3940class ViewPanner;4142class TileAtlasView : public Control {43GDCLASS(TileAtlasView, Control);4445private:46Ref<TileSet> tile_set;47Ref<TileSetAtlasSource> tile_set_atlas_source;48int source_id = TileSet::INVALID_SOURCE;4950float previous_zoom = 1.0;51EditorZoomWidget *zoom_widget = nullptr;52Button *button_center_view = nullptr;53CenterContainer *center_container = nullptr;54Vector2 panning;55void _update_zoom_and_panning(bool p_zoom_on_mouse_pos = false, const Vector2 &p_mouse_pos = Vector2());56void _zoom_widget_changed();57void _center_view();58virtual void gui_input(const Ref<InputEvent> &p_event) override;5960Ref<ViewPanner> panner;61void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);62void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);6364HashMap<Vector2, HashMap<int, Rect2i>> alternative_tiles_rect_cache;65void _update_alternative_tiles_rect_cache();6667MarginContainer *margin_container = nullptr;68int margin_container_paddings[4] = { 0, 0, 0, 0 };69HBoxContainer *hbox = nullptr;70Label *missing_source_label = nullptr;7172// Background73Control *background_left = nullptr;74void _draw_background_left();75Control *background_right = nullptr;76void _draw_background_right();7778// Left side.79Control *base_tiles_root_control = nullptr;80void _base_tiles_root_control_gui_input(const Ref<InputEvent> &p_event);8182Control *base_tiles_drawing_root = nullptr;8384Control *base_tiles_draw = nullptr;85HashMap<Ref<Material>, RID> material_tiles_draw;86HashMap<Ref<Material>, RID> material_alternatives_draw;87void _draw_base_tiles();88RID _get_canvas_item_to_draw(const TileData *p_for_data, const CanvasItem *p_base_item, HashMap<Ref<Material>, RID> &p_material_map);89void _clear_material_canvas_items();9091Control *base_tiles_texture_grid = nullptr;92void _draw_base_tiles_texture_grid();9394Control *base_tiles_shape_grid = nullptr;95void _draw_base_tiles_shape_grid();9697Size2i _compute_base_tiles_control_size();9899// Right side.100Control *alternative_tiles_root_control = nullptr;101void _alternative_tiles_root_control_gui_input(const Ref<InputEvent> &p_event);102103Control *alternative_tiles_drawing_root = nullptr;104105Control *alternatives_draw = nullptr;106void _draw_alternatives();107108Size2i _compute_alternative_tiles_control_size();109110struct ThemeCache {111Ref<Texture2D> center_view_icon;112Ref<Texture2D> checkerboard;113} theme_cache;114115protected:116virtual void _update_theme_item_cache() override;117118void _notification(int p_what);119static void _bind_methods();120121public:122// Global.123void set_atlas_source(TileSet *p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id);124125float get_zoom() const;126void set_transform(float p_zoom, Vector2i p_panning);127128void set_padding(Side p_side, int p_padding);129130// Left side.131void set_texture_grid_visible(bool p_visible) { base_tiles_texture_grid->set_visible(p_visible); }132void set_tile_shape_grid_visible(bool p_visible) { base_tiles_shape_grid->set_visible(p_visible); }133134Vector2i get_atlas_tile_coords_at_pos(const Vector2 p_pos, bool p_clamp = false) const;135136void add_control_over_atlas_tiles(Control *p_control, bool scaled = true) {137if (scaled) {138base_tiles_drawing_root->add_child(p_control);139} else {140base_tiles_root_control->add_child(p_control);141}142p_control->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);143p_control->set_mouse_filter(Control::MOUSE_FILTER_PASS);144}145146// Right side.147Vector3i get_alternative_tile_at_pos(const Vector2 p_pos) const;148Rect2i get_alternative_tile_rect(const Vector2i p_coords, int p_alternative_tile);149150void add_control_over_alternative_tiles(Control *p_control, bool scaled = true) {151if (scaled) {152alternative_tiles_drawing_root->add_child(p_control);153} else {154alternative_tiles_root_control->add_child(p_control);155}156p_control->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);157p_control->set_mouse_filter(Control::MOUSE_FILTER_PASS);158}159160// Redraw everything.161void queue_redraw();162163TileAtlasView();164~TileAtlasView();165};166167168