Description:
Refactor ImGui windows.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,70 | |||
|
1 | using System.Collections.Generic; | |
|
2 | using ImGuiNET; | |
|
3 | ||
|
4 | using Num = System.Numerics; | |
|
5 | ||
|
6 | ||
|
7 | namespace isometricparkfna.UI | |
|
8 | { | |
|
9 | public class StyleSet | |
|
10 | { | |
|
11 | static Num.Vector4 grey = new Num.Vector4(0.75f, 0.75f, 0.75f, 1f); | |
|
12 | static Num.Vector4 darkgrey = new Num.Vector4(0.45f, 0.45f, 0.45f, 1f); | |
|
13 | static Num.Vector4 black = new Num.Vector4(0f, 0f, 0f, 1f); | |
|
14 | static Num.Vector4 title_bar = new Num.Vector4(0.65f, 0.65f, 0.65f, 1f); | |
|
15 | public static Dictionary<ImGuiStyleVar, float> defaultWindowVars = new Dictionary<ImGuiStyleVar, float>{ | |
|
16 | { ImGuiStyleVar.FrameRounding, 0.0f }, | |
|
17 | {ImGuiStyleVar.WindowRounding, 0.0f}, | |
|
18 | {ImGuiStyleVar.FrameBorderSize, 1.0f}, | |
|
19 | {ImGuiStyleVar.TabRounding, 0.0f}, | |
|
20 | }; | |
|
21 | public static Dictionary<ImGuiCol, Num.Vector4> defaultWindowColors = new Dictionary<ImGuiCol, Num.Vector4>{ | |
|
22 | ||
|
23 | {ImGuiCol.WindowBg, grey}, | |
|
24 | {ImGuiCol.FrameBg, grey}, | |
|
25 | {ImGuiCol.FrameBgHovered, grey}, | |
|
26 | {ImGuiCol.Header, darkgrey}, | |
|
27 | {ImGuiCol.HeaderHovered, darkgrey}, | |
|
28 | {ImGuiCol.HeaderActive, darkgrey}, | |
|
29 | {ImGuiCol.ButtonHovered, grey}, | |
|
30 | {ImGuiCol.CheckMark, black}, | |
|
31 | ||
|
32 | {ImGuiCol.TitleBg, title_bar}, | |
|
33 | {ImGuiCol.TitleBgActive, title_bar}, | |
|
34 | {ImGuiCol.TitleBgCollapsed, title_bar}, | |
|
35 | ||
|
36 | {ImGuiCol.Border, black}, | |
|
37 | {ImGuiCol.BorderShadow, black}, | |
|
38 | ||
|
39 | {ImGuiCol.Button, grey}, | |
|
40 | {ImGuiCol.Text, black} | |
|
41 | }; | |
|
42 | /* | |
|
43 | */ | |
|
44 | public static void pushStyleVarSet(Dictionary<ImGuiStyleVar, float> style_set) | |
|
45 | { | |
|
46 | foreach(var pair in style_set) | |
|
47 | { | |
|
48 | ImGui.PushStyleVar(pair.Key, pair.Value); | |
|
49 | } | |
|
50 | } | |
|
51 | ||
|
52 | public static void popStyleVarSet(Dictionary<ImGuiStyleVar, float> style_set) | |
|
53 | { | |
|
54 | ImGui.PopStyleVar(style_set.Count); | |
|
55 | } | |
|
56 | public static void pushColorSet(Dictionary<ImGuiCol, Num.Vector4> style_set) | |
|
57 | { | |
|
58 | foreach(var pair in style_set) | |
|
59 | { | |
|
60 | ImGui.PushStyleColor(pair.Key, pair.Value); | |
|
61 | } | |
|
62 | ||
|
63 | } | |
|
64 | public static void popColorSet(Dictionary<ImGuiCol, Num.Vector4> style_set) | |
|
65 | { | |
|
66 | ImGui.PopStyleColor(style_set.Count); | |
|
67 | } | |
|
68 | } | |
|
69 | ||
|
70 | } No newline at end of file |
@@ -37,40 +37,15 | |||
|
37 | 37 | bool newShow = true; |
|
38 | 38 | |
|
39 | 39 | // Entity newSelected; |
|
40 | var grey = new Num.Vector4(0.75f, 0.75f, 0.75f, 1f); | |
|
41 | var darkgrey = new Num.Vector4(0.45f, 0.45f, 0.45f, 1f); | |
|
42 | var black = new Num.Vector4(0f, 0f, 0f, 1f); | |
|
43 | var title_bar = new Num.Vector4(0.65f, 0.65f, 0.65f, 1f); | |
|
40 | ; | |
|
44 | 41 | |
|
45 | 42 | if (newShow) |
|
46 | 43 | { |
|
47 | 44 | ImGui.PushFont(font); |
|
48 | 45 | |
|
49 | 46 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; |
|
50 | ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0.0f); | |
|
51 | ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); | |
|
52 | ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1.0f); | |
|
53 | ImGui.PushStyleVar(ImGuiStyleVar.TabRounding, 0.0f); | |
|
54 | ImGui.PushStyleColor(ImGuiCol.WindowBg, grey); | |
|
55 | ImGui.PushStyleColor(ImGuiCol.FrameBg, grey); | |
|
56 | ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, grey); | |
|
57 | ImGui.PushStyleColor(ImGuiCol.Header, darkgrey); | |
|
58 | ImGui.PushStyleColor(ImGuiCol.HeaderHovered, darkgrey); | |
|
59 | ImGui.PushStyleColor(ImGuiCol.HeaderActive, darkgrey); | |
|
60 | ImGui.PushStyleColor(ImGuiCol.ButtonHovered, grey); | |
|
61 | ImGui.PushStyleColor(ImGuiCol.CheckMark, black); | |
|
62 | ||
|
63 | ImGui.PushStyleColor(ImGuiCol.TitleBg, title_bar); | |
|
64 | ImGui.PushStyleColor(ImGuiCol.TitleBgActive, title_bar); | |
|
65 | ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, title_bar); | |
|
66 | ||
|
67 | ImGui.PushStyleColor(ImGuiCol.Border, black); | |
|
68 | ImGui.PushStyleColor(ImGuiCol.BorderShadow, black); | |
|
69 | ||
|
70 | ||
|
71 | ||
|
72 | ImGui.PushStyleColor(ImGuiCol.Button, grey); | |
|
73 | ImGui.PushStyleColor(ImGuiCol.Text, black); | |
|
47 | StyleSet.pushStyleVarSet(StyleSet.defaultWindowVars); | |
|
48 | StyleSet.pushColorSet(StyleSet.defaultWindowColors); | |
|
74 | 49 | ImGui.SetNextWindowSize(new Num.Vector2(320, 360)); |
|
75 | 50 | ImGui.Begin(string.Format("Contract {0}", name), ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings); |
|
76 | 51 | |
@@ -137,8 +112,8 | |||
|
137 | 112 | |
|
138 | 113 | ImGui.End(); |
|
139 | 114 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; |
|
140 | ImGui.PopStyleVar(4); | |
|
141 | ImGui.PopStyleColor(15); | |
|
115 | StyleSet.popStyleVarSet(StyleSet.defaultWindowVars); | |
|
116 | StyleSet.popColorSet(StyleSet.defaultWindowColors); | |
|
142 | 117 | ImGui.PopFont(); |
|
143 | 118 | |
|
144 | 119 | // Logging.Trace("Finished."); |
@@ -36,30 +36,9 | |||
|
36 | 36 | ImGui.PushFont(font); |
|
37 | 37 | |
|
38 | 38 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; |
|
39 | ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0.0f); | |
|
40 | ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); | |
|
41 | ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1.0f); | |
|
42 | ImGui.PushStyleVar(ImGuiStyleVar.TabRounding, 0.0f); | |
|
43 | ImGui.PushStyleColor(ImGuiCol.WindowBg, grey); | |
|
44 | ImGui.PushStyleColor(ImGuiCol.FrameBg, grey); | |
|
45 | ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, grey); | |
|
46 | ImGui.PushStyleColor(ImGuiCol.Header, darkgrey); | |
|
47 | ImGui.PushStyleColor(ImGuiCol.HeaderHovered, darkgrey); | |
|
48 | ImGui.PushStyleColor(ImGuiCol.HeaderActive, darkgrey); | |
|
49 | ImGui.PushStyleColor(ImGuiCol.ButtonHovered, grey); | |
|
50 | ImGui.PushStyleColor(ImGuiCol.CheckMark, black); | |
|
39 | StyleSet.pushStyleVarSet(StyleSet.defaultWindowVars); | |
|
40 | StyleSet.pushColorSet(StyleSet.defaultWindowColors); | |
|
51 | 41 | |
|
52 | ImGui.PushStyleColor(ImGuiCol.TitleBg, title_bar); | |
|
53 | ImGui.PushStyleColor(ImGuiCol.TitleBgActive, title_bar); | |
|
54 | ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, title_bar); | |
|
55 | ||
|
56 | ImGui.PushStyleColor(ImGuiCol.Border, black); | |
|
57 | ImGui.PushStyleColor(ImGuiCol.BorderShadow, black); | |
|
58 | ||
|
59 | ||
|
60 | ||
|
61 | ImGui.PushStyleColor(ImGuiCol.Button, grey); | |
|
62 | ImGui.PushStyleColor(ImGuiCol.Text, black); | |
|
63 | 42 | ImGui.SetNextWindowSize(new Num.Vector2(320, 340)); |
|
64 | 43 | ImGui.Begin("Contracts", ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings); |
|
65 | 44 | ImGui.ListBoxHeader("##Contracts:", new Num.Vector2(300, 150)); |
@@ -154,8 +133,8 | |||
|
154 | 133 | |
|
155 | 134 | ImGui.End(); |
|
156 | 135 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; |
|
157 | ImGui.PopStyleVar(4); | |
|
158 | ImGui.PopStyleColor(15); | |
|
136 | StyleSet.popStyleVarSet(StyleSet.defaultWindowVars); | |
|
137 | StyleSet.popColorSet(StyleSet.defaultWindowColors); | |
|
159 | 138 | ImGui.PopFont(); |
|
160 | 139 | } |
|
161 | 140 |
@@ -18,23 +18,9 | |||
|
18 | 18 | ImGui.PushFont(font); |
|
19 | 19 | |
|
20 | 20 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; |
|
21 | ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0.0f); | |
|
22 | ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); | |
|
23 | ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1.0f); | |
|
24 | ImGui.PushStyleColor(ImGuiCol.WindowBg, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | |
|
21 | StyleSet.pushStyleVarSet(StyleSet.defaultWindowVars); | |
|
22 | StyleSet.pushColorSet(StyleSet.defaultWindowColors); | |
|
25 | 23 | |
|
26 | var title_bar = new Num.Vector4(0.65f, 0.65f, 0.65f, 1f); | |
|
27 | ImGui.PushStyleColor(ImGuiCol.TitleBg, title_bar); | |
|
28 | ImGui.PushStyleColor(ImGuiCol.TitleBgActive, title_bar); | |
|
29 | ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, title_bar); | |
|
30 | ||
|
31 | ImGui.PushStyleColor(ImGuiCol.Border, new Num.Vector4(0f, 0f, 0f, 1f)); | |
|
32 | ImGui.PushStyleColor(ImGuiCol.BorderShadow, new Num.Vector4(0f, 0f, 0f, 0.5f)); | |
|
33 | ||
|
34 | ||
|
35 | ||
|
36 | ImGui.PushStyleColor(ImGuiCol.Button, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | |
|
37 | ImGui.PushStyleColor(ImGuiCol.Text, new Num.Vector4(0f, 0f, 0f, 1f)); | |
|
38 | 24 | ImGui.Begin("Forest Policy", ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings); |
|
39 | 25 | |
|
40 | 26 | |
@@ -58,8 +44,10 | |||
|
58 | 44 | |
|
59 | 45 | ImGui.End(); |
|
60 | 46 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; |
|
61 | ImGui.PopStyleVar(3); | |
|
62 | ImGui.PopStyleColor(8); | |
|
47 | // ImGui.PopStyleVar(3); | |
|
48 | // ImGui.PopStyleColor(8); | |
|
49 | StyleSet.popStyleVarSet(StyleSet.defaultWindowVars); | |
|
50 | StyleSet.popColorSet(StyleSet.defaultWindowColors); | |
|
63 | 51 | ImGui.PopFont(); |
|
64 | 52 | } |
|
65 | 53 | if (show != newShow) |
You need to be logged in to leave comments.
Login now