Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed the built-in default font

  • Loading branch information...
commit a0ebf6aba385d4ab341a0ead8d0e07ef7779ddc4 1 parent faf471d
@LaurentGomila LaurentGomila authored
View
2  examples/opengl/OpenGL.cs
@@ -26,7 +26,7 @@ static void Main()
Sprite background = new Sprite(new Texture("resources/background.jpg"));
// Create a text to display
- Text text = new Text("SFML / OpenGL demo");
+ Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf"));
text.Position = new Vector2f(250.0F, 450.0F);
text.Color = new Color(255, 255, 255, 170);
View
BIN  examples/opengl/resources/sansation.ttf
Binary file not shown
View
58 examples/shader/Shader.cs
@@ -33,17 +33,28 @@ public void Draw(RenderTarget target, RenderStates states)
}
else
{
- Text error = new Text("Shader not\nsupported");
+ Text error = new Text("Shader not\nsupported", GetFont());
error.Position = new Vector2f(320, 200);
error.CharacterSize = 36;
target.Draw(error, states);
}
}
+ public static void SetFont(Font font)
+ {
+ ourFont = font;
+ }
+
protected abstract void OnUpdate(float time, float x, float y);
protected abstract void OnDraw(RenderTarget target, RenderStates states);
+ protected Font GetFont()
+ {
+ return ourFont;
+ }
+
private string myName;
+ private static Font ourFont = null;
}
/// <summary>"Pixelate" fragment shader</summary>
@@ -83,24 +94,26 @@ class WaveBlur : Effect
public WaveBlur() : base("wave + blur")
{
// Create the text
- myText = new Text("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" +
- "Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" +
- "Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n" +
- "Donec fringilla scelerisque mauris et viverra.\n" +
- "Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n" +
- "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n" +
- "Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n" +
- "Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n" +
- "Fusce vel libero sed neque scelerisque venenatis.\n" +
- "Integer mattis tincidunt quam vitae iaculis.\n" +
- "Vivamus fringilla sem non velit venenatis fermentum.\n" +
- "Vivamus varius tincidunt nisi id vehicula.\n" +
- "Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n" +
- "vestibulum sodales sem ante in massa.\n" +
- "Vestibulum in augue non felis convallis viverra.\n" +
- "Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" +
- "Duis erat eros, porta in accumsan in, blandit quis sem.\n" +
- "In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n");
+ myText = new Text();
+ myText.DisplayedString = "Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" +
+ "Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" +
+ "Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n" +
+ "Donec fringilla scelerisque mauris et viverra.\n" +
+ "Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n" +
+ "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n" +
+ "Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n" +
+ "Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n" +
+ "Fusce vel libero sed neque scelerisque venenatis.\n" +
+ "Integer mattis tincidunt quam vitae iaculis.\n" +
+ "Vivamus fringilla sem non velit venenatis fermentum.\n" +
+ "Vivamus varius tincidunt nisi id vehicula.\n" +
+ "Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n" +
+ "vestibulum sodales sem ante in massa.\n" +
+ "Vestibulum in augue non felis convallis viverra.\n" +
+ "Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" +
+ "Duis erat eros, porta in accumsan in, blandit quis sem.\n" +
+ "In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n";
+ myText.Font = GetFont();
myText.CharacterSize = 22;
myText.Position = new Vector2f(30, 20);
@@ -254,6 +267,10 @@ static void Main()
window.Closed += new EventHandler(OnClosed);
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
+ // Load the application font and pass it to the Effect class
+ Font font = new Font("resources/sansation.ttf");
+ Effect.SetFont(font);
+
// Create the effects
effects = new Effect[]
{
@@ -270,9 +287,6 @@ static void Main()
textBackground.Position = new Vector2f(0, 520);
textBackground.Color = new Color(255, 255, 255, 200);
- // Load the messages font
- Font font = new Font("resources/sansation.ttf");
-
// Create the description text
description = new Text("Current effect: " + effects[current].Name, font, 20);
description.Position = new Vector2f(10, 530);
View
BIN  extlibs/x64/csfml-audio-2.dll
Binary file not shown
View
BIN  extlibs/x64/csfml-graphics-2.dll
Binary file not shown
View
BIN  extlibs/x64/csfml-window-2.dll
Binary file not shown
View
BIN  extlibs/x86/csfml-audio-2.dll
Binary file not shown
View
BIN  extlibs/x86/csfml-graphics-2.dll
Binary file not shown
View
BIN  extlibs/x86/csfml-window-2.dll
Binary file not shown
View
47 src/Graphics/Font.cs
@@ -115,22 +115,6 @@ public Texture GetTexture(uint characterSize)
////////////////////////////////////////////////////////////
/// <summary>
- /// Default built-in font
- /// </summary>
- ////////////////////////////////////////////////////////////
- public static Font DefaultFont
- {
- get
- {
- if (ourDefaultFont == null)
- ourDefaultFont = new Font(sfFont_getDefaultFont());
-
- return ourDefaultFont;
- }
- }
-
- ////////////////////////////////////////////////////////////
- /// <summary>
/// Provide a string describing the object
/// </summary>
/// <returns>String description of the object</returns>
@@ -148,25 +132,22 @@ public override string ToString()
////////////////////////////////////////////////////////////
protected override void Destroy(bool disposing)
{
- if (this != ourDefaultFont)
- {
- if (!disposing)
- Context.Global.SetActive(true);
-
- sfFont_destroy(CPointer);
+ if (!disposing)
+ Context.Global.SetActive(true);
- if (disposing)
- {
- foreach (Texture texture in myTextures.Values)
- texture.Dispose();
+ sfFont_destroy(CPointer);
- if (myStream != null)
- myStream.Dispose();
- }
+ if (disposing)
+ {
+ foreach (Texture texture in myTextures.Values)
+ texture.Dispose();
- if (!disposing)
- Context.Global.SetActive(false);
+ if (myStream != null)
+ myStream.Dispose();
}
+
+ if (!disposing)
+ Context.Global.SetActive(false);
}
////////////////////////////////////////////////////////////
@@ -182,7 +163,6 @@ protected override void Destroy(bool disposing)
private Dictionary<uint, Texture> myTextures = new Dictionary<uint, Texture>();
private StreamAdaptor myStream = null;
- private static Font ourDefaultFont = null;
#region Imports
[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -208,9 +188,6 @@ protected override void Destroy(bool disposing)
[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfFont_getTexture(IntPtr CPointer, uint characterSize);
-
- [DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
- static extern IntPtr sfFont_getDefaultFont();
#endregion
}
}
View
15 src/Graphics/Text.cs
@@ -41,18 +41,7 @@ public enum Styles
/// </summary>
////////////////////////////////////////////////////////////
public Text() :
- this("")
- {
- }
-
- ////////////////////////////////////////////////////////////
- /// <summary>
- /// Construct the text from a string
- /// </summary>
- /// <param name="str">String to display</param>
- ////////////////////////////////////////////////////////////
- public Text(string str) :
- this(str, Font.DefaultFont)
+ this("", null)
{
}
@@ -283,7 +272,7 @@ protected override void Destroy(bool disposing)
sfText_destroy(CPointer);
}
- private Font myFont = Font.DefaultFont;
+ private Font myFont = null;
#region Imports
Please sign in to comment.
Something went wrong with that request. Please try again.