1// Aseprite
2// Copyright (C) 2018-2020 Igara Studio S.A.
3// Copyright (C) 2001-2018 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_PREF_PREFERENCES_H_INCLUDED
9#define APP_PREF_PREFERENCES_H_INCLUDED
10#pragma once
11
12#include "app/color.h"
13#include "app/commands/filters/cels_target.h"
14#include "app/docs_observer.h"
15#include "app/pref/option.h"
16#include "app/sprite_sheet_data_format.h"
17#include "app/sprite_sheet_type.h"
18#include "app/tools/freehand_algorithm.h"
19#include "app/tools/ink_type.h"
20#include "app/tools/rotation_algorithm.h"
21#include "app/ui/color_bar.h"
22#include "doc/algorithm/resize_image.h"
23#include "doc/anidir.h"
24#include "doc/brush_pattern.h"
25#include "doc/color_mode.h"
26#include "doc/frame.h"
27#include "doc/layer_list.h"
28#include "doc/rgbmap_algorithm.h"
29#include "doc/sprite.h"
30#include "filters/hue_saturation_filter.h"
31#include "filters/tiled_mode.h"
32#include "gfx/rect.h"
33#include "render/onionskin_position.h"
34#include "render/zoom.h"
35
36#include "pref.xml.h"
37
38#include <map>
39#include <string>
40#include <vector>
41
42namespace app {
43 namespace tools {
44 class Tool;
45 }
46
47 class Doc;
48
49 typedef app::gen::ToolPref ToolPreferences;
50 typedef app::gen::DocPref DocumentPreferences;
51
52 class Preferences : public app::gen::GlobalPref,
53 public app::DocsObserver {
54 public:
55 static Preferences& instance();
56
57 Preferences();
58 ~Preferences();
59
60 void save();
61
62 // Returns true if the given option was set by the user or false
63 // if it contains the default value.
64 bool isSet(OptionBase& opt) const;
65
66 ToolPreferences& tool(tools::Tool* tool);
67 DocumentPreferences& document(const Doc* doc);
68
69 // Used to reset the tool preferences in scripting mode when the
70 // UI is not available (so scripts have a common default
71 // preferences and a reproducible behavior for automation).
72 void resetToolPreferences(tools::Tool* tool);
73
74 // Remove one document explicitly (this can be used if the
75 // document used in Preferences::document() function wasn't member
76 // of UIContext.
77 void removeDocument(Doc* doc);
78
79 protected:
80 // DocsObserver impl
81 void onRemoveDocument(Doc* doc) override;
82
83 private:
84 void load();
85 std::string docConfigFileName(const Doc* doc);
86
87 void serializeDocPref(const Doc* doc, app::DocumentPreferences* docPref, bool save);
88
89 std::map<std::string, app::ToolPreferences*> m_tools;
90 std::map<const Doc*, DocumentPreferences*> m_docs;
91 };
92
93} // namespace app
94
95#endif
96