X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffont.cpp;h=a19a94e5d13b22670e13c361689669b3d5b71db4;hb=80aac2618536baaa99b92629be6931363c49c4de;hp=2cab462c04e9eaef76b27066d327cebb15a93396;hpb=48420e9e3f950cfe1e3ced8f8ea92d89671ae8c4;p=libs%2Fgl.git diff --git a/source/font.cpp b/source/font.cpp index 2cab462c..a19a94e5 100644 --- a/source/font.cpp +++ b/source/font.cpp @@ -1,3 +1,10 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include #include "font.h" #include "texture2d.h" @@ -9,19 +16,12 @@ namespace GL { Font::Font(): tex(0), - own_tex(false), default_size(1), ascent(1), descent(0), varray((TEXCOORD2, VERTEX2)) { } -Font::~Font() -{ - if(own_tex) - delete tex; -} - void Font::set_texture(const Texture2D &t) { tex=&t; @@ -141,13 +141,24 @@ float Font::get_glyph_advance(unsigned code) const Font::Loader::Loader(Font &f): - font(f) + font(f), + coll(0) { - add("default_size", &Font::default_size); - add("ascent", &Font::ascent); - add("descent", &Font::descent); - add("texture", &Loader::texture); - add("glyph", &Loader::glyph); + init(); +} + +Font::Loader::Loader(Font &f, Collection &c): + font(f), + coll(&c) +{ + init(); +} + +DataFile::Collection &Font::Loader::get_collection() +{ + if(!coll) + throw InvalidState("No collection"); + return *coll; } Font::Loader::~Loader() @@ -155,13 +166,13 @@ Font::Loader::~Loader() font.create_glyph_vertices(); } -void Font::Loader::texture(const string &t) +void Font::Loader::init() { - Texture2D *tex=new Texture2D; - tex->parameter(GL_GENERATE_MIPMAP, 1); - font.tex=tex; - tex->image(t); - font.own_tex=true; + add("default_size", &Font::default_size); + add("ascent", &Font::ascent); + add("descent", &Font::descent); + add("texture", &Font::tex); + add("glyph", &Loader::glyph); } void Font::Loader::glyph(unsigned c) @@ -177,8 +188,8 @@ Font::Glyph::Loader::Loader(Glyph &g): glyph(g) { add("texcoords", &Loader::texcoords); - add("size", &Loader::size); - add("offset", &Loader::offset); + add("size", &Glyph::w, &Glyph::h); + add("offset", &Glyph::off_x, &Glyph::off_y); add("advance", &Glyph::advance); } @@ -190,17 +201,5 @@ void Font::Glyph::Loader::texcoords(float x1, float y1, float x2, float y2) glyph.y2=y2; } -void Font::Glyph::Loader::size(float w, float h) -{ - glyph.w=w; - glyph.h=h; -} - -void Font::Glyph::Loader::offset(float x, float y) -{ - glyph.off_x=x; - glyph.off_y=y; -} - } // namespace GL } // namespace Msp