1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Solarus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef SOLARUS_CAMERA_H
18 #define SOLARUS_CAMERA_H
19 
20 #include "solarus/core/Common.h"
21 #include "solarus/core/Rectangle.h"
22 #include "solarus/entities/Entity.h"
23 #include "solarus/entities/EntityPtr.h"
24 #include "solarus/graphics/SurfacePtr.h"
25 #include <memory>
26 
27 namespace Solarus {
28 
29 class Map;
30 class Separator;
31 class Surface;
32 class TargetMovement;
33 
34 /**
35  * \brief Manages the visible area of the map.
36  *
37  * The camera determines the visible area of the map.
38  * The camera may either be tracking an entity
39  * (usually the hero)
40  * or be controlled manually by a script.
41  */
42 class Camera : public Entity {
43 
44   public:
45 
46     static constexpr EntityType ThisType = EntityType::CAMERA;
47 
48     explicit Camera(Map& map);
49 
50     EntityType get_type() const override;
51 
52     bool can_be_drawn() const override;
53     void set_suspended(bool suspended) override;
54     void notify_movement_started() override;
55     void notify_size_changed() override;
56     bool is_separator_obstacle(Separator& separator, const Rectangle& candidate_position) override;
57 
58     const SurfacePtr& get_surface() const;
59 
60     Point get_position_on_screen() const;
61     void set_position_on_screen(const Point& position_on_screen);
62     Point get_position_to_track(const Point& tracked_xy) const;
63 
64     void start_tracking(const EntityPtr& entity);
65     void start_manual();
66 
67     EntityPtr get_tracked_entity() const;
68     void notify_tracked_entity_traversing_separator(Separator& separator);
69     bool is_traversing_separator() const;
70 
71     Rectangle apply_map_bounds(const Rectangle& area) const;
72     Rectangle apply_separators(const Rectangle& area) const;
73     Rectangle apply_separators_and_map_bounds(const Rectangle& area) const;
74 
75 private:
76 
77     void create_surface();
78 
79     SurfacePtr surface;           /**< Surface where this camera draws its entities. */
80     Point position_on_screen;     /**< Where to draw this camera on the screen. */
81 
82 };
83 
84 }
85 
86 #endif
87 
88