Commit ab3b8876 authored by David Quiroga's avatar David Quiroga
Browse files

Initial commit

parent e02e3fad
# Install fonts
install_data(
[
'fonts/JetMono-EB.ttf',
'fonts/antar.ttf',
],
install_dir: join_paths(get_option('datadir'), meson.project_name(), 'fonts')
......
......@@ -4,9 +4,7 @@ public class GSDL.GameLoop : Object {
private GSDL.Input input;
private RBackGround rb_space;
private SDLTTF.Font jetmono20;
private SDLTTF.Font antar90;
private RFont current_fps;
private RFont msg_solid;
private RFont msg_shaded;
private RFont msg_blended;
......@@ -22,14 +20,11 @@ public class GSDL.GameLoop : Object {
}
private void load_resources () {
jetmono20 = RFont.load_font_file ("JetMono-EB.ttf");
antar90 = RFont.load_font_file ("antar.ttf", 90);
rb_space = new RBackGround (wsdl, "1024x1024GreenNebula4.png");
}
private void create_messages () {
current_fps = new RFont (wsdl, jetmono20);
msg_solid = new RFont (wsdl, antar90);
msg_solid.color = {255, 255, 255, 255};
......@@ -38,6 +33,8 @@ public class GSDL.GameLoop : Object {
msg_blended = new RFont (wsdl, antar90);
msg_blended.color = {255, 255, 255, 255};
msg_solid.print_metric ('g');
}
public void run () {
......@@ -45,7 +42,6 @@ public class GSDL.GameLoop : Object {
double lag = 0.0f;
while (!input.done) {
wsdl.start_performance_counter ();
uint32 current = wsdl.get_time ();
uint32 elapsed = current - previous;
previous = current;
......@@ -59,7 +55,6 @@ public class GSDL.GameLoop : Object {
draw ();
wsdl.present_scene ();
wsdl.wait (1);
wsdl.end_performance_counter ();
}
}
......@@ -68,7 +63,6 @@ public class GSDL.GameLoop : Object {
msg_solid.set_text_solid ("Render Solid");
msg_shaded.set_text_shaded ("Render Shaded");
msg_blended.set_text_blended ("Render Blended", 680);
current_fps.set_text_blended (wsdl.get_FPS_string (), 200);
}
private void draw () {
......@@ -76,7 +70,6 @@ public class GSDL.GameLoop : Object {
msg_solid.write (220, 120);
msg_shaded.write (200, 320);
msg_blended.write (180, 520);
current_fps.write (10, wsdl.height () - 30);
}
}
......@@ -59,4 +59,28 @@ public class GSDL.RFont
wsdl.renderer.copy (texture_info_s, {0, 0, info_s.w, info_s.h},
{position_x, position_y, info_s.w, info_s.h });
}
public void print_metric (uchar letter) {
int minx, maxx, miny, maxy, advance, res;
res = this.font.get_metrics (letter, out minx, out maxx, out miny,
out maxy, out advance);
if (res == -1) {
warning ("Error in get_metrics: %s\n", SDL.get_error ());
} else {
int fontheight = this.font.get_height ();
int fontascent = this.font.get_ascent ();
int fontdescent = this.font.get_descent ();
int fontlineskip = this.font.get_lineskip ();
print ("minx\t\t:%d\n", minx);
print ("maxx\t\t:%d\n", maxx);
print ("miny\t\t:%d\n", miny);
print ("maxy\t\t:%d\n", maxy);
print ("advance\t\t:%d\n", advance);
print ("font height\t:%d\n", fontheight);
print ("font ascent\t:%d\n", fontascent);
print ("font descent\t:%d\n", fontdescent);
print ("font line skip\t:%d\n", fontlineskip);
}
}
}
......@@ -15,10 +15,6 @@ public class GSDL.Wsdl : Object {
private Video.Window window;
public Video.Renderer? renderer;
private uint64 start_perf_counter = 0;
private uint64 end_perf_counter = 0;
private float elap = 0;
public Wsdl () {
if (SDL.init (SDL.InitFlag.VIDEO) != 0) {
critical ("Couldn't initialize SDL: %s\n", SDL.get_error());
......@@ -79,24 +75,5 @@ public class GSDL.Wsdl : Object {
public void wait (uint32 ms) {
SDL.Timer.delay (ms);
}
public void start_performance_counter () {
start_perf_counter = SDL.Timer.get_performance_counter ();
}
public void end_performance_counter () {
end_perf_counter = SDL.Timer.get_performance_counter ();
elap = (end_perf_counter - start_perf_counter) /
(float) SDL.Timer.get_performance_frequency ();
}
public float get_FPS () {
return (1.0f / elap);
}
public string get_FPS_string () {
string current_fps = "Curren FPS: %0.0f".printf (get_FPS ());
return current_fps;
}
}
......@@ -143,7 +143,7 @@ namespace SDLTTF {
[CCode (cname = "TTF_GlyphMetrics")]
public int get_metrics_16 (unichar2 utf16_ch, out int minx, out int maxx, out int miny, out int maxy, out int advance);
[CCode (cname = "TTF_GlyphMetrics32")]
[CCode (cname = "TTF_GlyphMetrics")]
public int get_metrics (unichar ch, out int minx, out int maxx, out int miny, out int maxy, out int advance);
[CCode (cname = "TTF_SizeUTF8")]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment