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.about;
8 import creator.widgets.dummy;
9 import creator.widgets.tooltip;
10 import creator.widgets.label;
11 import creator.widgets.markdown;
12 import creator.windows;
13 import creator.core;
14 import creator;
15 import std.string;
16 import creator.utils.link;
17 import inochi2d;
18 import i18n;
19 import std.stdio;
20 
21 class AboutWindow : Window {
22 private:
23     version (InBranding) {
24         enum ADA_SIZE = 332;
25         enum ADA_SIZE_PARTIAL = ADA_SIZE/6;
26         vec2 ada_float;
27     }
28     MarkdownConfig cfg;
29 
30 protected:
31     override
32     void onBeginUpdate() {
33         igSetNextWindowSize(ImVec2(640, 512), ImGuiCond.Appearing);
34         igSetNextWindowSizeConstraints(ImVec2(640, 512), ImVec2(float.max, float.max));
35         super.onBeginUpdate();
36     }
37 
38     override
39     void onUpdate() {
40 
41         // Draw Ada
42         ImVec2 sPos;
43         igGetCursorScreenPos(&sPos);
44 
45         version (InBranding) {
46             ImVec2 avail = incAvailableSpace();
47             igSetCursorScreenPos(ImVec2(
48                 sPos.x+(avail.x-(ADA_SIZE-ADA_SIZE_PARTIAL)), 
49                 sPos.y+(avail.y-(ADA_SIZE+28))+(sin(currentTime())*4)
50             ));
51 
52             igImage(
53                 cast(void*)incGetAda().getTextureId(),
54                 ImVec2(ADA_SIZE, ADA_SIZE),
55                 ImVec2(0, 0),
56                 ImVec2(1, 1), 
57                 ImVec4(1, 1, 1, 0.4), ImVec4(0, 0, 0, 0)
58             );
59         }
60 
61         // Draw the actual about dialog
62         igSetCursorScreenPos(sPos);
63         if (igBeginChild("##LogoArea", ImVec2(0, 92))) {
64 
65             version (InBranding) {
66                 igImage(
67                     cast(void*)incGetLogo().getTextureId(), 
68                     ImVec2(64, 64), 
69                     ImVec2(0, 0), 
70                     ImVec2(1, 1), 
71                     ImVec4(1, 1, 1, 1), 
72                     ImVec4(0, 0, 0, 0)
73                 );
74             }
75             
76             igSameLine(0, 8);
77             igSeparatorEx(ImGuiSeparatorFlags.Vertical);
78             igSameLine(0, 8);
79             if (igBeginChild("##LogoTextArea", ImVec2(0, -24))) {
80 
81                 incText("Inochi Creator");
82                 incText(INC_VERSION);
83                 igSeparator();
84                 igTextColored(ImVec4(0.5, 0.5, 0.5, 1), "I2D v. %s", (IN_VERSION~"\0").ptr);
85                 igTextColored(ImVec4(0.5, 0.5, 0.5, 1), "imgui v. %s", igGetVersion());
86             }
87             igEndChild();
88             
89             igSpacing();
90             incText("Credits");
91             igSeparator();
92         }
93         igEndChild();
94 
95         igPushStyleColor(ImGuiCol.Button, ImVec4(0.176, 0.447, 0.698, 1));
96         igPushStyleColor(ImGuiCol.ButtonHovered, ImVec4(0.313, 0.521, 0.737, 1));
97             if (igBeginChild("##CreditsArea", ImVec2(0, -28))) {
98                 incMarkdown(import("CONTRIBUTORS.md"), cfg);
99             }
100         igPopStyleColor();
101         igPopStyleColor();
102         igEndChild();
103 
104         if (igBeginChild("##ButtonArea", ImVec2(0, 0))) {
105             ImVec2 space = incAvailableSpace();
106             incDummy(ImVec2(space.x/2, space.y));
107             igSameLine(0, 0);
108 
109             space = incAvailableSpace();
110             float spacing = (space.x/3)-8;
111 
112             if (igButton("GitHub", ImVec2(8+spacing, 0))) {
113                 incOpenLink("https://github.com/Inochi2D/inochi-creator");
114             }
115 
116             igSameLine(0, 8);
117 
118             if (igButton("Twitter", ImVec2(spacing, 0))) {
119                 incOpenLink("https://twitter.com/Inochi2D");
120             }
121 
122             igSameLine(0, 8);
123 
124             if (igButton(__("Donate"), ImVec2(spacing, 0))) {
125                 incOpenLink("https://www.patreon.com/clipsey");
126             }
127         }
128         igEndChild();
129     }
130 
131 public:
132     this() {
133         super(_("About"));
134         this.onlyOne = true;
135 
136         cfg.headingFormats[0] = MarkdownHeadingFormat(2, true);
137         cfg.headingFormats[1] = MarkdownHeadingFormat(1.5, false);
138         cfg.headingFormats[2] = MarkdownHeadingFormat(1.2, false);
139         cfg.linkCallback = (MarkdownLinkCallbackData data) {
140             incOpenLink(data.link);
141         };
142 
143         // Only load Ada in official builds
144         version(InBranding) ada_float = vec2(0);
145     }
146 }