1 // Aseprite 2 // Copyright (c) 2001-2018 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifndef APP_SITE_H_INCLUDED 8 #define APP_SITE_H_INCLUDED 9 #pragma once 10 11 #include "doc/frame.h" 12 #include "doc/selected_frames.h" 13 #include "doc/selected_layers.h" 14 15 namespace doc { 16 class Cel; 17 class Image; 18 class Layer; 19 class Palette; 20 class Sprite; 21 } // namespace doc 22 23 namespace app { 24 class Doc; 25 26 // Specifies the current location in a context. E.g. the location in 27 // the current Editor (current document, sprite, layer, frame, 28 // etc.). 29 class Site { 30 public: 31 // Were is the user focus. E.g. If this focus is in the timeline, 32 // it means that commands should applied in the context of the 33 // timeline (layers, or frames, or cels). 34 enum Focus { 35 None, 36 InEditor, 37 InLayers, 38 InFrames, 39 InCels, 40 InColorBar 41 }; 42 Site()43 Site() 44 : m_focus(None) 45 , m_document(nullptr) 46 , m_sprite(nullptr) 47 , m_layer(nullptr) 48 , m_frame(0) { } 49 focus()50 const Focus focus() const { return m_focus; } inEditor()51 bool inEditor() const { return m_focus == InEditor; } inLayers()52 bool inLayers() const { return m_focus == InLayers; } inFrames()53 bool inFrames() const { return m_focus == InFrames; } inCels()54 bool inCels() const { return m_focus == InCels; } inColorBar()55 bool inColorBar() const { return m_focus == InColorBar; } inTimeline()56 bool inTimeline() const { return (inLayers() || inFrames() || inCels()); } 57 document()58 const Doc* document() const { return m_document; } sprite()59 const doc::Sprite* sprite() const { return m_sprite; } layer()60 const doc::Layer* layer() const { return m_layer; } frame()61 doc::frame_t frame() const { return m_frame; } 62 const doc::Cel* cel() const; 63 document()64 Doc* document() { return m_document; } sprite()65 doc::Sprite* sprite() { return m_sprite; } layer()66 doc::Layer* layer() { return m_layer; } 67 doc::Cel* cel(); 68 focus(Focus focus)69 void focus(Focus focus) { m_focus = focus; } document(Doc * document)70 void document(Doc* document) { m_document = document; } sprite(doc::Sprite * sprite)71 void sprite(doc::Sprite* sprite) { m_sprite = sprite; } layer(doc::Layer * layer)72 void layer(doc::Layer* layer) { m_layer = layer; } frame(doc::frame_t frame)73 void frame(doc::frame_t frame) { m_frame = frame; } 74 selectedLayers()75 const doc::SelectedLayers& selectedLayers() const { return m_selectedLayers; } selectedLayers()76 doc::SelectedLayers& selectedLayers() { return m_selectedLayers; } selectedLayers(const doc::SelectedLayers & selectedLayers)77 void selectedLayers(const doc::SelectedLayers& selectedLayers) { 78 m_selectedLayers = selectedLayers; 79 } 80 selectedFrames()81 const doc::SelectedFrames& selectedFrames() const { return m_selectedFrames; } selectedFrames()82 doc::SelectedFrames& selectedFrames() { return m_selectedFrames; } selectedFrames(const doc::SelectedFrames & selectedFrames)83 void selectedFrames(const doc::SelectedFrames& selectedFrames) { 84 m_selectedFrames = selectedFrames; 85 } 86 87 doc::Palette* palette(); 88 doc::Image* image(int* x = nullptr, int* y = nullptr, int* opacity = nullptr) const; 89 doc::Palette* palette() const; 90 91 private: 92 Focus m_focus; 93 Doc* m_document; 94 doc::Sprite* m_sprite; 95 doc::Layer* m_layer; 96 doc::frame_t m_frame; 97 doc::SelectedLayers m_selectedLayers; 98 doc::SelectedFrames m_selectedFrames; 99 }; 100 101 } // namespace app 102 103 #endif 104