zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Fonts.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <zeni_graphics.h>
19 
20 #include <iostream>
21 #include <fstream>
22 
23 #if defined(_DEBUG) && defined(_WINDOWS)
24 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
25 #define new DEBUG_NEW
26 #endif
27 
28 #include <Zeni/Database.hxx>
29 #include <Zeni/Singleton.hxx>
30 
31 namespace Zeni {
32 
33  template class Singleton<Fonts>;
34  template class Database<Font>;
35 
36  Fonts * Fonts::create() {
37  return new Fonts;
38  }
39 
40  Fonts::Lose Fonts::g_lose;
41  Fonts::Unlose Fonts::g_unlose;
42 
43  Fonts::Fonts()
44  : Database<Font>("config/fonts.xml", "Fonts")
45  {
46  Video &vr = get_Video();
47 
49 
50  vr.lend_pre_uninit(&g_lose);
51  vr.lend_post_reinit(&g_unlose);
52  }
53 
54  Fonts::~Fonts() {
55  Video::remove_pre_uninit(&g_lose);
56 
58  }
59 
61  return Singleton<Fonts>::get();
62  }
63 
64  Font * Fonts::load(XML_Element_c &xml_element, const String &/*name*/, const String &/*filename*/) {
65  const String filepath = xml_element["filepath"].to_string();
66  const float height = xml_element["height"].to_float();
67 
68  const float screen_height = float(get_Window().get_height());
69  float virtual_screen_height = screen_height;
70  XML_Element_c virtual_screen = xml_element["virtual_screen"];
71  if(virtual_screen.good()) {
72  XML_Element_c vsw = virtual_screen["width"];
73  XML_Element_c vsh = virtual_screen["height"];
74 
75  if(vsw.good()) {
76  const float vsw_ratio = vsw.to_float() / get_Window().get_width();
77 
78  if(vsh.good()) {
79  virtual_screen_height = vsh.to_float();
80 
81  if(vsw_ratio > virtual_screen_height / screen_height)
82  virtual_screen_height = vsw_ratio * screen_height;
83  }
84  else
85  virtual_screen_height = vsw_ratio * screen_height;
86  }
87  else if(vsh.good())
88  virtual_screen_height = vsh.to_float();
89  }
90 
91  return get_Video().create_Font(filepath, height, virtual_screen_height);
92  }
93 
94 }
static const int & get_width()
Get the size of the window.
Definition: Window.hxx:33
A Font database read in from a file.
Definition: Fonts.h:51
EGLSurface EGLint EGLint EGLint EGLint height
Definition: eglext.h:293
virtual Font * create_Font(const String &filename, const float &glyph_height, const float &virtual_screen_height)=0
Function for creating a Font; used internally by Fonts.
static void remove_pre_uninit(Event::Handler *const &handler)
static TYPE & get()
Definition: Singleton.hxx:31
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
Fonts & get_Fonts()
Get access to the singleton.
Definition: Fonts.cpp:60
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149