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_PREF_PREFERENCES_H_INCLUDED
8 #define APP_PREF_PREFERENCES_H_INCLUDED
9 #pragma once
10 
11 #include "app/color.h"
12 #include "app/commands/filters/cels_target.h"
13 #include "app/doc_exporter.h"
14 #include "app/docs_observer.h"
15 #include "app/pref/option.h"
16 #include "app/sprite_sheet_type.h"
17 #include "app/tools/freehand_algorithm.h"
18 #include "app/tools/ink_type.h"
19 #include "app/tools/rotation_algorithm.h"
20 #include "app/ui/color_bar.h"
21 #include "doc/algorithm/resize_image.h"
22 #include "doc/anidir.h"
23 #include "doc/brush_pattern.h"
24 #include "doc/frame.h"
25 #include "doc/layer_list.h"
26 #include "filters/tiled_mode.h"
27 #include "gfx/rect.h"
28 #include "render/onionskin_position.h"
29 #include "render/zoom.h"
30 
31 #include "pref.xml.h"
32 
33 #include <map>
34 #include <string>
35 #include <vector>
36 
37 namespace app {
38   namespace tools {
39     class Tool;
40   }
41 
42   class Doc;
43 
44   typedef app::gen::ToolPref ToolPreferences;
45   typedef app::gen::DocPref DocumentPreferences;
46 
47   class Preferences : public app::gen::GlobalPref,
48                       public app::DocsObserver {
49   public:
50     static Preferences& instance();
51 
52     Preferences();
53     ~Preferences();
54 
55     void load();
56     void save();
57 
58     // Returns true if the given option was set by the user or false
59     // if it contains the default value.
60     bool isSet(OptionBase& opt) const;
61 
62     ToolPreferences& tool(tools::Tool* tool);
63     DocumentPreferences& document(const Doc* doc);
64 
65     // Remove one document explicitly (this can be used if the
66     // document used in Preferences::document() function wasn't member
67     // of UIContext.
68     void removeDocument(Doc* doc);
69 
70   protected:
71     void onRemoveDocument(Doc* doc) override;
72 
73   private:
74     std::string docConfigFileName(const Doc* doc);
75 
76     void serializeDocPref(const Doc* doc, app::DocumentPreferences* docPref, bool save);
77 
78     std::map<std::string, app::ToolPreferences*> m_tools;
79     std::map<const Doc*, DocumentPreferences*> m_docs;
80   };
81 
82 } // namespace app
83 
84 #endif
85