Description:
Initial version of font selection working.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r314:d497a83db168 -

1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,13
1
2
3
4 using Microsoft.Xna.Framework;
5 using Encompass;
6
7 namespace isometricparkfna.Messages {
8 public struct SetFontMessage : IMessage
9 {
10 public string fontName;
11 public int fontSize;
12 }
13 }
@@ -137,8 +137,15
137 Accessibility:
137 Accessibility:
138 - Verify contrast
138 - Verify contrast
139 - Option to Increase display size
139 - Option to Increase display size
140 - Add message for font changes @done(2021-06-26)
141 - Relocate fonts to central place @done(2021-06-26)
142 - Remove fonts from DebugWindow?
143 - Adjust window dimensions when font changes
140 - Option to Turn off bad outcomes or disasters @maybe
144 - Option to Turn off bad outcomes or disasters @maybe
141 - Dyslexic-friendly font @maybe
145 - Dyslexic-friendly font @maybe @done(2021-06-26)
146 Cursory research indicates open sans-serif fonts are best,
147 although fonts only help so much. (Monospaced fonts are also cited as good options so Iosevka might already be good enough. Still, I added Roboto.)
148
142 - Screen reader support @maybe
149 - Screen reader support @maybe
143 Would probably be a big undertaking (sort of opposite to the web, where things tend to be accessible unless you start reimplenting things or going more advanced)
150 Would probably be a big undertaking (sort of opposite to the web, where things tend to be accessible unless you start reimplenting things or going more advanced)
144 - Investigate .NET support for screen readers
151 - Investigate .NET support for screen readers
@@ -2,8 +2,11
2 using Encompass;
2 using Encompass;
3 using System.Linq;
3 using System.Linq;
4
4
5 using ImGuiNET;
6
5 using isometricparkfna.Messages;
7 using isometricparkfna.Messages;
6 using isometricparkfna.Components;
8 using isometricparkfna.Components;
9 using isometricparkfna.UI;
7
10
8 namespace isometricparkfna.Engines {
11 namespace isometricparkfna.Engines {
9
12
@@ -14,13 +17,14
14 typeof(JumpCameraMessage),
17 typeof(JumpCameraMessage),
15 typeof(GameStateMessage),
18 typeof(GameStateMessage),
16 typeof(GameStateMessage),
19 typeof(GameStateMessage),
17 typeof(SetResolutionMessage))]
20 typeof(SetResolutionMessage),
21 typeof(SetFontMessage))]
18 [Reads(typeof(VisibilityComponent),
22 [Reads(typeof(VisibilityComponent),
19 typeof(WindowTypeComponent)
23 typeof(WindowTypeComponent)
20 //, typeof(SelectedComponent)
24 //, typeof(SelectedComponent)
21 )]
25 )]
22 // [Writes(typeof(SelectedComponent))]
26 // [Writes(typeof(SelectedComponent))]
23 public class ImGuiWindowBridgeEngine : Engine
27 public class ImGuiWindowBridgeEngine : Engine
24 {
28 {
25
29
26 public List<ToggleWindowMessage> messages;
30 public List<ToggleWindowMessage> messages;
@@ -30,6 +34,7
30 public List<JumpCameraMessage> jumpCameraMessages;
34 public List<JumpCameraMessage> jumpCameraMessages;
31 public List<GameStateMessage> gameStateMessages;
35 public List<GameStateMessage> gameStateMessages;
32 public List<SetResolutionMessage> resolutionMessages;
36 public List<SetResolutionMessage> resolutionMessages;
37 public List<SetFontMessage> fontMessages;
33
38
34 bool showBudget {get;}
39 bool showBudget {get;}
35 bool showForest {get;}
40 bool showForest {get;}
@@ -39,8 +44,13
39
44
40 public Dictionary<Window, bool> windowStatuses {get;}
45 public Dictionary<Window, bool> windowStatuses {get;}
41
46
47 public ImFontPtr font;
48 public ImFontPtr italicFont;
49 private DebugWindow debugWindow;
42
50
43 public ImGuiWindowBridgeEngine()
51
52 public ImGuiWindowBridgeEngine(DebugWindow debugWindow,
53 ImFontPtr font)
44 {
54 {
45 this.messages = new List<ToggleWindowMessage>();
55 this.messages = new List<ToggleWindowMessage>();
46 this.typeMessages = new List<ToggleWindowTypeMessage>();
56 this.typeMessages = new List<ToggleWindowTypeMessage>();
@@ -49,7 +59,14
49 this.jumpCameraMessages = new List<JumpCameraMessage>();
59 this.jumpCameraMessages = new List<JumpCameraMessage>();
50 this.gameStateMessages = new List<GameStateMessage>();
60 this.gameStateMessages = new List<GameStateMessage>();
51 this.resolutionMessages = new List<SetResolutionMessage>();
61 this.resolutionMessages = new List<SetResolutionMessage>();
62 this.fontMessages = new List<SetFontMessage>();
52 this.windowStatuses = new Dictionary<Window, bool>();
63 this.windowStatuses = new Dictionary<Window, bool>();
64
65
66 this.font = font;
67 this.debugWindow = debugWindow;
68
69
53 //Prepopulate:
70 //Prepopulate:
54 foreach(var type in System.Enum.GetValues(typeof(Window)))
71 foreach(var type in System.Enum.GetValues(typeof(Window)))
55 {
72 {
@@ -57,7 +74,7
57 }
74 }
58 }
75 }
59
76
60 public override void Update(double dt)
77 public override void Update(double dt)
61 {
78 {
62 foreach(var message in this.messages)
79 foreach(var message in this.messages)
63 {
80 {
@@ -89,14 +106,21
89 {
106 {
90 SendMessage(message);
107 SendMessage(message);
91 }
108 }
109 foreach(var message in this.fontMessages)
110 {
111 this.font = debugWindow.addFont(message.fontName,
112 message.fontSize);
113
114 debugWindow.setMonoFont(this.font);
115 }
92
116
93
117
94
118
95 foreach(var entity in ReadEntities<WindowTypeComponent>())
119 foreach(var entity in ReadEntities<WindowTypeComponent>())
96 {
120 {
97 var type = GetComponent<WindowTypeComponent>(entity).type;
121 var type = GetComponent<WindowTypeComponent>(entity).type;
98 var visibility = GetComponent<VisibilityComponent>(entity).visible;
122 var visibility = GetComponent<VisibilityComponent>(entity).visible;
99 windowStatuses[type] = visibility;
123 windowStatuses[type] = visibility;
100 }
124 }
101
125
102 this.messages.Clear();
126 this.messages.Clear();
@@ -106,6 +130,7
106 this.jumpCameraMessages.Clear();
130 this.jumpCameraMessages.Clear();
107 this.gameStateMessages.Clear();
131 this.gameStateMessages.Clear();
108 this.resolutionMessages.Clear();
132 this.resolutionMessages.Clear();
133 this.fontMessages.Clear();
109 }
134 }
110 }
135 }
111 }
136 }
@@ -63,6 +63,11
63 new SelectedComponent { selected = true});
63 new SelectedComponent { selected = true});
64 }
64 }
65
65
66 // foreach (ref readonly var fontMessage in ReadMessages<SetFontMessage>())
67 // {
68 //
69 // }
70
66 }
71 }
67 }
72 }
68 }
73 }
@@ -232,7 +232,7
232 WorldBuilder.AddEngine(new GameStateEngine());
232 WorldBuilder.AddEngine(new GameStateEngine());
233 WorldBuilder.AddEngine(this.simulation.BridgeEngine);
233 WorldBuilder.AddEngine(this.simulation.BridgeEngine);
234 WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera));
234 WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera));
235 this.imGuiWindowBridgeEngine = new ImGuiWindowBridgeEngine();
235 this.imGuiWindowBridgeEngine = new ImGuiWindowBridgeEngine(this.debugWindow, debugWindow.monoFont);
236 WorldBuilder.AddEngine(this.imGuiWindowBridgeEngine);
236 WorldBuilder.AddEngine(this.imGuiWindowBridgeEngine);
237 WorldBuilder.AddEngine(new ContractStatusEngine(this.simulation));
237 WorldBuilder.AddEngine(new ContractStatusEngine(this.simulation));
238
238
@@ -490,6 +490,11
490 {
490 {
491 sound.Play(volume, pitch, pan);
491 sound.Play(volume, pitch, pan);
492 }
492 }
493 if (keyboardCur.IsKeyDown(Keys.V) && keyboardPrev.IsKeyUp(Keys.V))
494 {
495 // debugWindow.swap();
496 debugWindow.setMonoFont(debugWindow.addFont("Roboto", 25));
497 }
493 #endregion misc_keys
498 #endregion misc_keys
494 #endregion input
499 #endregion input
495
500
@@ -19,7 +19,7
19 {
19 {
20 class ImGuiWindowRenderer : GeneralRenderer
20 class ImGuiWindowRenderer : GeneralRenderer
21 {
21 {
22 private ImFontPtr font;
22 // private ImFontPtr font;
23 private ImFontPtr italicFont;
23 private ImFontPtr italicFont;
24 private ImGuiWindowBridgeEngine BridgeEngine;
24 private ImGuiWindowBridgeEngine BridgeEngine;
25 private FNAGame game;
25 private FNAGame game;
@@ -28,7 +28,7
28
28
29 public ImGuiWindowRenderer(FNAGame game, ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, GraphicsDeviceManager gdm)
29 public ImGuiWindowRenderer(FNAGame game, ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, GraphicsDeviceManager gdm)
30 {
30 {
31 this.font = font;
31 // this.font = font;
32 this.italicFont = italicFont;
32 this.italicFont = italicFont;
33 this.BridgeEngine = engine;
33 this.BridgeEngine = engine;
34 this.game = game;
34 this.game = game;
@@ -85,7 +85,7
85 contract_data.Add(getContractDetails(e));
85 contract_data.Add(getContractDetails(e));
86 }
86 }
87
87
88 ContractsWindow.Render(this.font, this.BridgeEngine, contract_data);
88 ContractsWindow.Render(this.BridgeEngine.font, this.BridgeEngine, contract_data);
89 break;
89 break;
90 case Window.Contract:
90 case Window.Contract:
91
91
@@ -95,17 +95,17
95 var area = GetComponent<AreaComponent>(entity).squares;
95 var area = GetComponent<AreaComponent>(entity).squares;
96 var area_size = GetComponent<AreaComponent>(entity).squares.Length;
96 var area_size = GetComponent<AreaComponent>(entity).squares.Length;
97
97
98 ContractWindow.Render(this.font, this.italicFont, this.BridgeEngine, entity, data.name, data.description, data.status, data.amount, data.delta_trees, area_size, data.image_index, data.square);
98 ContractWindow.Render(this.BridgeEngine.font, this.italicFont, this.BridgeEngine, entity, data.name, data.description, data.status, data.amount, data.delta_trees, area_size, data.image_index, data.square);
99
99
100 break;
100 break;
101 case Window.MainMenu:
101 case Window.MainMenu:
102 MainMenu.Render(this.font, this.BridgeEngine);
102 MainMenu.Render(this.BridgeEngine.font, this.BridgeEngine);
103 break;
103 break;
104 case Window.InGameMenu:
104 case Window.InGameMenu:
105 InGameMenu.Render(this.font, this.BridgeEngine, width);
105 InGameMenu.Render(this.BridgeEngine.font, this.BridgeEngine, width);
106 break;
106 break;
107 case Window.Options:
107 case Window.Options:
108 OptionsWindow.Render(this.font, this.italicFont, this.BridgeEngine, width);
108 OptionsWindow.Render(this.BridgeEngine.font, this.italicFont, this.BridgeEngine, width);
109 break;
109 break;
110 default:
110 default:
111 break;
111 break;
@@ -116,5 +116,11
116
116
117 }
117 }
118
118
119 public void setFont(ImFontPtr font)
120 {
121 this.BridgeEngine.font = font;
122 }
123
124
119 }
125 }
120 }
126 }
@@ -36,9 +36,17
36
36
37 public ImageMap map;
37 public ImageMap map;
38
38
39 private ImGuiRenderer renderer;
40
41 public static Dictionary<string, string> fonts = new Dictionary<String, string>{{"Roboto" , @"Content/Roboto-Regular.ttf"},
42 {"RobotoMedium" , @"Content/Roboto-Medium.ttf"},
43 {"Iosevka", @"Content/iosevka-term-extendedmedium.ttf"}};
44
39
45
40 public DebugWindow(ImGuiRenderer _imGuiRenderer, GraphicsDevice graphicsDevice, ImageMap map)
46 public DebugWindow(ImGuiRenderer _imGuiRenderer, GraphicsDevice graphicsDevice, ImageMap map)
41 {
47 {
48
49 this.renderer = _imGuiRenderer;
42 ImGuiIOPtr io = ImGui.GetIO();
50 ImGuiIOPtr io = ImGui.GetIO();
43 //io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-medium.ttf", 15);
51 //io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-medium.ttf", 15);
44
52
@@ -49,6 +57,10
49 io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 20);
57 io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 20);
50 io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 25);
58 io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 25);
51 io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 30);
59 io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 30);
60 io.Fonts.AddFontFromFileTTF(@"Content/Roboto-Regular.ttf", 15);
61 io.Fonts.AddFontFromFileTTF(@"Content/Roboto-Regular.ttf", 30);
62 io.Fonts.AddFontFromFileTTF(@"Content/Roboto-Medium.ttf", 15);
63 io.Fonts.AddFontFromFileTTF(@"Content/Roboto-Medium.ttf", 30);
52 #endif
64 #endif
53
65
54 this.monoFont = io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 15);
66 this.monoFont = io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 15);
@@ -81,6 +93,52
81 _imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
93 _imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
82 }
94 }
83
95
96 public void swap()
97 {
98 ImGuiIOPtr io = ImGui.GetIO();
99
100 this.monoFont = io.Fonts.AddFontFromFileTTF(@"Content/Roboto-Regular.ttf", 15);
101 unsafe //god this sucks
102 {
103 ImFontConfigPtr config = ImGuiNative.ImFontConfig_ImFontConfig();
104 config.MergeMode = true;
105 var builder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder());
106 // builder.AddText("\ue125\ue126");
107 var icon_ranges = new ushort[] { 0xe000, 0xe1f4, 0 };
108 GCHandle rangeHandle = GCHandle.Alloc(icon_ranges, GCHandleType.Pinned);
109 io.Fonts.AddFontFromFileTTF(@"Content/typicons.ttf", 15, config, rangeHandle.AddrOfPinnedObject());
110
111
112 }
113 this.renderer.RebuildFontAtlas(); // Required so fonts are available for rendering
114 }
115
116 public ImFontPtr addFont(String name, int size)
117 {
118 ImGuiIOPtr io = ImGui.GetIO();
119
120 ImFontPtr font = io.Fonts.AddFontFromFileTTF(fonts[name], size);
121 unsafe //god this sucks
122 {
123 ImFontConfigPtr config = ImGuiNative.ImFontConfig_ImFontConfig();
124 config.MergeMode = true;
125 var builder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder());
126 // builder.AddText("\ue125\ue126");
127 var icon_ranges = new ushort[] { 0xe000, 0xe1f4, 0 };
128 GCHandle rangeHandle = GCHandle.Alloc(icon_ranges, GCHandleType.Pinned);
129 io.Fonts.AddFontFromFileTTF(@"Content/typicons.ttf", size, config, rangeHandle.AddrOfPinnedObject());
130
131
132 }
133 this.renderer.RebuildFontAtlas(); // Required so fonts are available for rendering
134 return font;
135 }
136
137 public void setMonoFont(ImFontPtr font)
138 {
139 this.monoFont = font;
140 }
141
84 public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Func<int, Color> paint)
142 public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Func<int, Color> paint)
85 {
143 {
86 //initialize a texture
144 //initialize a texture
@@ -198,8 +256,6
198 ImGui.End();
256 ImGui.End();
199 }
257 }
200
258
201
202
203 if (this.show_test_window)
259 if (this.show_test_window)
204 {
260 {
205 ImGui.SetNextWindowPos(new Num.Vector2(650, 20), ImGuiCond.FirstUseEver);
261 ImGui.SetNextWindowPos(new Num.Vector2(650, 20), ImGuiCond.FirstUseEver);
@@ -19,6 +19,9
19 public static bool newFullscreen;
19 public static bool newFullscreen;
20 public static Vector2 newResolution;
20 public static Vector2 newResolution;
21
21
22 private static string fontName = "Iosevka";
23 private static int fontSize = 15;
24
22 public static void Initialize(Vector2 resolution, bool fullscreen)
25 public static void Initialize(Vector2 resolution, bool fullscreen)
23 {
26 {
24
27
@@ -68,8 +71,7
68 {
71 {
69
72
70 foreach(var (width_option, height_option) in new[]{(1280, 640), (640, 320), (960, 480), (1600, 800),
73 foreach(var (width_option, height_option) in new[]{(1280, 640), (640, 320), (960, 480), (1600, 800),
71 (2560, 1440), (1280, 720), (1920, 1080)
74 (2560, 1440), (1280, 720), (1920, 1080)})
72 })
73 {
75 {
74 if (ImGui.Selectable(string.Format("{0}x{1}", width_option, height_option)))
76 if (ImGui.Selectable(string.Format("{0}x{1}", width_option, height_option)))
75 {
77 {
@@ -80,6 +82,38
80
82
81 ImGui.EndCombo();
83 ImGui.EndCombo();
82 }
84 }
85 ImGui.Text("Font:");
86
87 ImGui.SameLine();
88
89 if (ImGui.BeginCombo("##Font", fontName))
90 {
91
92 foreach(var font_name in new[]{"Iosevka", "Roboto"})
93 {
94 if(ImGui.Selectable(font_name))
95 {
96 OptionsWindow.fontName = font_name;
97 }
98 }
99
100 ImGui.EndCombo();
101 }
102 ImGui.Text("Size:");
103 ImGui.SameLine();
104 if (ImGui.BeginCombo("##FontSize", fontSize.ToString()))
105 {
106
107 foreach(var size in new[]{9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20})
108 {
109 if(ImGui.Selectable(size.ToString()))
110 {
111 OptionsWindow.fontSize = size;
112 }
113 }
114
115 ImGui.EndCombo();
116 }
83
117
84 ImGuiIOPtr io = ImGui.GetIO();
118 ImGuiIOPtr io = ImGui.GetIO();
85 ImGui.DragFloat("Scale", ref io.FontGlobalScale, 0.005f, 0.2f, 5.0f, "%.2f");
119 ImGui.DragFloat("Scale", ref io.FontGlobalScale, 0.005f, 0.2f, 5.0f, "%.2f");
@@ -96,6 +130,10
96 resolution = newResolution,
130 resolution = newResolution,
97 fullscreen = newFullscreen
131 fullscreen = newFullscreen
98 });
132 });
133 bridgeEngine.fontMessages.Add(new SetFontMessage{
134 fontSize = OptionsWindow.fontSize,
135 fontName = OptionsWindow.fontName});
136
99 }
137 }
100
138
101 ImGui.End();
139 ImGui.End();
@@ -54,6 +54,8
54 {ImGuiCol.Button, grey},
54 {ImGuiCol.Button, grey},
55 {ImGuiCol.Text, black}
55 {ImGuiCol.Text, black}
56 };
56 };
57
58 // public static IMFont
57 /*
59 /*
58 */
60 */
59 public static void pushStyleVarSet(Dictionary<ImGuiStyleVar, float> style_set)
61 public static void pushStyleVarSet(Dictionary<ImGuiStyleVar, float> style_set)
@@ -92,9 +92,6
92 <None Include="Content\FNASound.wav">
92 <None Include="Content\FNASound.wav">
93 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
93 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
94 </None>
94 </None>
95 <None Include="Content\DroidSans.ttf">
96 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
97 </None>
98 <None Include="packages.config" />
95 <None Include="packages.config" />
99 <None Include="Content\part4_tileset.png">
96 <None Include="Content\part4_tileset.png">
100 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
97 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -157,6 +154,12
157 <None Include="Content\photos_converted3.png">
154 <None Include="Content\photos_converted3.png">
158 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
155 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
159 </None>
156 </None>
157 <None Include="Content\Roboto-Medium.ttf">
158 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
159 </None>
160 <None Include="Content\Roboto-Regular.ttf">
161 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
162 </None>
160 </ItemGroup>
163 </ItemGroup>
161 <ItemGroup>
164 <ItemGroup>
162 <Reference Include="System" />
165 <Reference Include="System" />
You need to be logged in to leave comments. Login now