Description:
Initial version of font selection working.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | 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 | 137 | Accessibility: |
|
138 | 138 | - Verify contrast |
|
139 | 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 | 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 | 149 | - Screen reader support @maybe |
|
143 | 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 | 151 | - Investigate .NET support for screen readers |
@@ -2,8 +2,11 | |||
|
2 | 2 | using Encompass; |
|
3 | 3 | using System.Linq; |
|
4 | 4 | |
|
5 | using ImGuiNET; | |
|
6 | ||
|
5 | 7 | using isometricparkfna.Messages; |
|
6 | 8 | using isometricparkfna.Components; |
|
9 | using isometricparkfna.UI; | |
|
7 | 10 | |
|
8 | 11 | namespace isometricparkfna.Engines { |
|
9 | 12 | |
@@ -14,13 +17,14 | |||
|
14 | 17 | typeof(JumpCameraMessage), |
|
15 | 18 | typeof(GameStateMessage), |
|
16 | 19 | typeof(GameStateMessage), |
|
17 |
typeof(SetResolutionMessage) |
|
|
20 | typeof(SetResolutionMessage), | |
|
21 | typeof(SetFontMessage))] | |
|
18 | 22 | [Reads(typeof(VisibilityComponent), |
|
19 | 23 | typeof(WindowTypeComponent) |
|
20 | 24 | //, typeof(SelectedComponent) |
|
21 | 25 | )] |
|
22 | 26 | // [Writes(typeof(SelectedComponent))] |
|
23 |
public class ImGuiWindowBridgeEngine : Engine |
|
|
27 | public class ImGuiWindowBridgeEngine : Engine | |
|
24 | 28 | { |
|
25 | 29 | |
|
26 | 30 | public List<ToggleWindowMessage> messages; |
@@ -30,6 +34,7 | |||
|
30 | 34 | public List<JumpCameraMessage> jumpCameraMessages; |
|
31 | 35 | public List<GameStateMessage> gameStateMessages; |
|
32 | 36 | public List<SetResolutionMessage> resolutionMessages; |
|
37 | public List<SetFontMessage> fontMessages; | |
|
33 | 38 | |
|
34 | 39 | bool showBudget {get;} |
|
35 | 40 | bool showForest {get;} |
@@ -39,8 +44,13 | |||
|
39 | 44 | |
|
40 | 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 | 55 | this.messages = new List<ToggleWindowMessage>(); |
|
46 | 56 | this.typeMessages = new List<ToggleWindowTypeMessage>(); |
@@ -49,7 +59,14 | |||
|
49 | 59 | this.jumpCameraMessages = new List<JumpCameraMessage>(); |
|
50 | 60 | this.gameStateMessages = new List<GameStateMessage>(); |
|
51 | 61 | this.resolutionMessages = new List<SetResolutionMessage>(); |
|
62 | this.fontMessages = new List<SetFontMessage>(); | |
|
52 | 63 | this.windowStatuses = new Dictionary<Window, bool>(); |
|
64 | ||
|
65 | ||
|
66 | this.font = font; | |
|
67 | this.debugWindow = debugWindow; | |
|
68 | ||
|
69 | ||
|
53 | 70 | //Prepopulate: |
|
54 | 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 | 79 | foreach(var message in this.messages) |
|
63 | 80 | { |
@@ -89,14 +106,21 | |||
|
89 | 106 | { |
|
90 | 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 | 119 | foreach(var entity in ReadEntities<WindowTypeComponent>()) |
|
96 | 120 | { |
|
97 | 121 | var type = GetComponent<WindowTypeComponent>(entity).type; |
|
98 | 122 | var visibility = GetComponent<VisibilityComponent>(entity).visible; |
|
99 |
|
|
|
123 | windowStatuses[type] = visibility; | |
|
100 | 124 | } |
|
101 | 125 | |
|
102 | 126 | this.messages.Clear(); |
@@ -106,6 +130,7 | |||
|
106 | 130 | this.jumpCameraMessages.Clear(); |
|
107 | 131 | this.gameStateMessages.Clear(); |
|
108 | 132 | this.resolutionMessages.Clear(); |
|
133 | this.fontMessages.Clear(); | |
|
109 | 134 | } |
|
110 | 135 | } |
|
111 | 136 | } |
@@ -63,6 +63,11 | |||
|
63 | 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 | 232 | WorldBuilder.AddEngine(new GameStateEngine()); |
|
233 | 233 | WorldBuilder.AddEngine(this.simulation.BridgeEngine); |
|
234 | 234 | WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera)); |
|
235 | this.imGuiWindowBridgeEngine = new ImGuiWindowBridgeEngine(); | |
|
235 | this.imGuiWindowBridgeEngine = new ImGuiWindowBridgeEngine(this.debugWindow, debugWindow.monoFont); | |
|
236 | 236 | WorldBuilder.AddEngine(this.imGuiWindowBridgeEngine); |
|
237 | 237 | WorldBuilder.AddEngine(new ContractStatusEngine(this.simulation)); |
|
238 | 238 | |
@@ -490,6 +490,11 | |||
|
490 | 490 | { |
|
491 | 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 | 498 | #endregion misc_keys |
|
494 | 499 | #endregion input |
|
495 | 500 |
@@ -19,7 +19,7 | |||
|
19 | 19 | { |
|
20 | 20 | class ImGuiWindowRenderer : GeneralRenderer |
|
21 | 21 | { |
|
22 | private ImFontPtr font; | |
|
22 | // private ImFontPtr font; | |
|
23 | 23 | private ImFontPtr italicFont; |
|
24 | 24 | private ImGuiWindowBridgeEngine BridgeEngine; |
|
25 | 25 | private FNAGame game; |
@@ -28,7 +28,7 | |||
|
28 | 28 | |
|
29 | 29 | public ImGuiWindowRenderer(FNAGame game, ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, GraphicsDeviceManager gdm) |
|
30 | 30 | { |
|
31 | this.font = font; | |
|
31 | // this.font = font; | |
|
32 | 32 | this.italicFont = italicFont; |
|
33 | 33 | this.BridgeEngine = engine; |
|
34 | 34 | this.game = game; |
@@ -85,7 +85,7 | |||
|
85 | 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 | 89 | break; |
|
90 | 90 | case Window.Contract: |
|
91 | 91 | |
@@ -95,17 +95,17 | |||
|
95 | 95 | var area = GetComponent<AreaComponent>(entity).squares; |
|
96 | 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 | 100 | break; |
|
101 | 101 | case Window.MainMenu: |
|
102 | MainMenu.Render(this.font, this.BridgeEngine); | |
|
102 | MainMenu.Render(this.BridgeEngine.font, this.BridgeEngine); | |
|
103 | 103 | break; |
|
104 | 104 | case Window.InGameMenu: |
|
105 | InGameMenu.Render(this.font, this.BridgeEngine, width); | |
|
105 | InGameMenu.Render(this.BridgeEngine.font, this.BridgeEngine, width); | |
|
106 | 106 | break; |
|
107 | 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 | 109 | break; |
|
110 | 110 | default: |
|
111 | 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 | 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 | 46 | public DebugWindow(ImGuiRenderer _imGuiRenderer, GraphicsDevice graphicsDevice, ImageMap map) |
|
41 | 47 | { |
|
48 | ||
|
49 | this.renderer = _imGuiRenderer; | |
|
42 | 50 | ImGuiIOPtr io = ImGui.GetIO(); |
|
43 | 51 | //io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-medium.ttf", 15); |
|
44 | 52 | |
@@ -49,6 +57,10 | |||
|
49 | 57 | io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 20); |
|
50 | 58 | io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 25); |
|
51 | 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 | 64 | #endif |
|
53 | 65 | |
|
54 | 66 | this.monoFont = io.Fonts.AddFontFromFileTTF(@"Content/iosevka-term-extendedmedium.ttf", 15); |
@@ -81,6 +93,52 | |||
|
81 | 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 | 142 | public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Func<int, Color> paint) |
|
85 | 143 | { |
|
86 | 144 | //initialize a texture |
@@ -198,8 +256,6 | |||
|
198 | 256 | ImGui.End(); |
|
199 | 257 | } |
|
200 | 258 | |
|
201 | ||
|
202 | ||
|
203 | 259 | if (this.show_test_window) |
|
204 | 260 | { |
|
205 | 261 | ImGui.SetNextWindowPos(new Num.Vector2(650, 20), ImGuiCond.FirstUseEver); |
@@ -19,6 +19,9 | |||
|
19 | 19 | public static bool newFullscreen; |
|
20 | 20 | public static Vector2 newResolution; |
|
21 | 21 | |
|
22 | private static string fontName = "Iosevka"; | |
|
23 | private static int fontSize = 15; | |
|
24 | ||
|
22 | 25 | public static void Initialize(Vector2 resolution, bool fullscreen) |
|
23 | 26 | { |
|
24 | 27 | |
@@ -68,8 +71,7 | |||
|
68 | 71 | { |
|
69 | 72 | |
|
70 | 73 | foreach(var (width_option, height_option) in new[]{(1280, 640), (640, 320), (960, 480), (1600, 800), |
|
71 | (2560, 1440), (1280, 720), (1920, 1080) | |
|
72 | }) | |
|
74 | (2560, 1440), (1280, 720), (1920, 1080)}) | |
|
73 | 75 | { |
|
74 | 76 | if (ImGui.Selectable(string.Format("{0}x{1}", width_option, height_option))) |
|
75 | 77 | { |
@@ -80,6 +82,38 | |||
|
80 | 82 | |
|
81 | 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 | 118 | ImGuiIOPtr io = ImGui.GetIO(); |
|
85 | 119 | ImGui.DragFloat("Scale", ref io.FontGlobalScale, 0.005f, 0.2f, 5.0f, "%.2f"); |
@@ -96,6 +130,10 | |||
|
96 | 130 | resolution = newResolution, |
|
97 | 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 | 139 | ImGui.End(); |
@@ -54,6 +54,8 | |||
|
54 | 54 | {ImGuiCol.Button, grey}, |
|
55 | 55 | {ImGuiCol.Text, black} |
|
56 | 56 | }; |
|
57 | ||
|
58 | // public static IMFont | |
|
57 | 59 | /* |
|
58 | 60 | */ |
|
59 | 61 | public static void pushStyleVarSet(Dictionary<ImGuiStyleVar, float> style_set) |
@@ -92,9 +92,6 | |||
|
92 | 92 | <None Include="Content\FNASound.wav"> |
|
93 | 93 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|
94 | 94 | </None> |
|
95 | <None Include="Content\DroidSans.ttf"> | |
|
96 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |
|
97 | </None> | |
|
98 | 95 | <None Include="packages.config" /> |
|
99 | 96 | <None Include="Content\part4_tileset.png"> |
|
100 | 97 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
@@ -157,6 +154,12 | |||
|
157 | 154 | <None Include="Content\photos_converted3.png"> |
|
158 | 155 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|
159 | 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 | 163 | </ItemGroup> |
|
161 | 164 | <ItemGroup> |
|
162 | 165 | <Reference Include="System" /> |
You need to be logged in to leave comments.
Login now