1 /*
2     Copyright © 2020, Inochi2D Project
3     Distributed under the 2-Clause BSD License, see LICENSE file.
4     
5     Authors: Luna Nielsen
6 */
7 module creator.windows.settings;
8 import creator.windows;
9 import creator.widgets;
10 import creator.core;
11 import creator.core.i18n;
12 import std.string;
13 import creator.utils.link;
14 import i18n;
15 
16 bool incIsSettingsOpen;
17 
18 /**
19     Settings window
20 */
21 class SettingsWindow : Window {
22 private:
23     bool generalTabOpen = true;
24     bool otherTabOpen = true;
25     bool useOpenDyslexic;
26 
27 protected:
28     override
29     void onBeginUpdate() {
30         flags |= ImGuiWindowFlags.NoResize;
31         flags |= ImGuiWindowFlags.NoSavedSettings;
32         incIsSettingsOpen = true;
33         super.onBeginUpdate();
34     }
35 
36     override
37     void onUpdate() {
38         igPushStyleVar(ImGuiStyleVar.ItemSpacing, ImVec2(4, 4));
39             igBeginChild("SettingsWindowChild", ImVec2(512*incGetUIScale(), 512*incGetUIScale()));
40                 if (igBeginTabBar("SettingsWindowTabs", ImGuiTabBarFlags.NoCloseWithMiddleMouseButton)) {
41                     if(igBeginTabItem(__("General"), &generalTabOpen, ImGuiTabItemFlagsI.NoCloseButton | ImGuiTabItemFlags.NoCloseWithMiddleMouseButton)) {
42                         igBeginChild("#GeneralTabItems", ImVec2(0, -26));
43                             igText(__("Look and Feel"));
44                             igSeparator();
45                             if(igBeginCombo(__("Color Theme"), incGetDarkMode() ? __("Dark") : __("Light"))) {
46                                 if (igSelectable(__("Dark"), incGetDarkMode())) incSetDarkMode(true);
47                                 if (igSelectable(__("Light"), !incGetDarkMode())) incSetDarkMode(false);
48 
49                                 igEndCombo();
50                             }
51                             
52                             import std.string : toStringz;
53                             if(igBeginCombo(__("Language"), incLocaleCurrentName().toStringz)) {
54                                 if (igSelectable("English")) incLocaleSet(null);
55                                 foreach(entry; incLocaleGetEntries()) {
56                                     if (igSelectable(entry.humanNameC)) incLocaleSet(entry.code);
57                                 }
58                                 igEndCombo();
59                             }
60 
61                             if(igBeginCombo(__("UI Scale (EXPERIMENTAL)"), incGetUIScaleText().toStringz)) {
62                                 if (igSelectable("100%")) incSetUIScale(1.0);
63                                 if (igSelectable("150%")) incSetUIScale(1.5);
64                                 if (igSelectable("200%")) incSetUIScale(2.0);
65 
66                                 igEndCombo();
67                             }
68 
69                             if (incCanUseAppTitlebar) {
70                                 bool useNative = incGetUseNativeTitlebar();
71                                 if (igCheckbox(__("Use Native Titlebar"), &useNative)) {
72                                     incSettingsSet("UseNativeTitleBar", useNative);
73                                     incSetUseNativeTitlebar(useNative);
74                                 }
75                             }
76 
77                             version(linux) {
78                                 bool disableCompositor = incSettingsGet!bool("DisableCompositor");
79                                 if (igCheckbox(__("Disable Compositor"), &disableCompositor)) {
80                                     incSettingsSet("DisableCompositor", disableCompositor);
81                                 }
82                             }
83 
84                             version(InGallium) {
85                                 bool useSWRender = incSettingsGet!bool("SoftwareRenderer");
86                                 if (igCheckbox(__("Use software rendering"), &useSWRender)) {
87                                     incSettingsSet("SoftwareRenderer", useSWRender);
88                                 }
89                             }
90 
91 
92                             igSpacing();
93                             igSpacing();
94 
95                             igText(__("Undo/Redo History"));
96                             igSeparator();
97                             
98                             int maxHistory = cast(int)incActionGetUndoHistoryLength();
99                             if (igSliderInt(__("Max Undo History"), &maxHistory, 0, 1000, "%d")) {
100                                 incActionSetUndoHistoryLength(maxHistory);
101                             }
102 
103                         igEndChild();
104 
105                         igEndTabItem();
106                     }
107 
108                     if(igBeginTabItem(__("Accessibility"), &generalTabOpen, ImGuiTabItemFlagsI.NoCloseButton | ImGuiTabItemFlags.NoCloseWithMiddleMouseButton)) {
109                         
110                         igBeginChild("#GeneralTabItems", ImVec2(0, -26));
111 
112                         igEndChild();
113                         igEndTabItem();
114                     }
115 
116                     if(igBeginTabItem(__("Other"), &otherTabOpen, ImGuiTabItemFlagsI.NoCloseButton | ImGuiTabItemFlags.NoCloseWithMiddleMouseButton)) {
117 
118                         igBeginChild("#OtherTabItems", ImVec2(0, -26));
119 
120                         igEndChild();
121                         igEndTabItem();
122                     }
123 
124                     igEndTabBar();
125                 }
126 
127                 // Save button
128                 if (igButton(__("Save"), ImVec2(0, 0))) {
129                     this.close();
130                 }
131 
132             igEndChild();
133         igPopStyleVar();
134     }
135 
136     override
137     void onClose() {
138         incSettingsSave();
139         incIsSettingsOpen = false;
140     }
141 
142 public:
143     this() {
144         super(_("Settings"));
145     }
146 }