#include <cstdlib>
#include <cstring>
-#include "app/globals.h"
-#include "video/screen.h"
-#include "video/font.h"
-#include "video/drawing_context.h"
-#include "utils/lispreader.h"
+#include "../app/globals.h"
+#include "../video/screen.h"
+#include "../video/font.h"
+#include "../video/drawing_context.h"
+#include "../utils/lispreader.h"
+
+using namespace SuperTux;
Font::Font(const std::string& file, FontType ntype, int nw, int nh,
int nshadowsize)
}
float
-Font::get_height() const
+Font::get_text_width(const std::string& text) const
{
- return h;
+ /** Let's calculate the size of the biggest paragraph */
+ int l, hl;
+ hl = 0; l = -1;
+ while(true)
+ {
+ l = text.find("\n", l+1);
+ if(l == (int)std::string::npos)
+ break;
+ if(hl < l)
+ hl = l;
+ }
+ if(hl == 0)
+ hl = text.size();
+
+ return hl * w;
}
float
-Font::get_text_width(const std::string& text) const
+Font::get_text_height(const std::string& text) const
+{
+ /** Let's calculate height of the text */
+ int l, hh;
+ hh = h; l = -1;
+ while(true)
+ {
+ l = text.find("\n", l+1);
+ if(l == (int)std::string::npos)
+ break;
+ hh += h + 2;
+ }
+
+ return hh;
+}
+
+float
+Font::get_height() const
{
- return text.size() * w;
+ return h;
}
void
}
void
+Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_effect)
+{
+ /* Cut lines changes into seperate strings, needed to support centering text
+ with break lines.
+ Feel free to replace this hack with a more elegant solution
+ */
+ char temp[1024];
+ unsigned int i, l, y;
+ i = y = 0;
+ while(true)
+ {
+ l = text.find("\n", i);
+ if(l == std::string::npos)
+ {
+ temp[text.copy(temp, text.size() - i, i)] = '\0';
+ draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y),
+ drawing_effect);
+ break;
+ }
+ temp[text.copy(temp, l - i, i)] = '\0';
+ draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y),
+ drawing_effect);
+
+ i = l+1;
+ y += h + 2;
+ }
+}
+
+void
Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos,
Uint32 drawing_effect)
{
#define SCROLL 60
#define ITEMS_SPACE 4
-void display_text_file(const std::string& file, float scroll_speed)
+void SuperTux::display_text_file(const std::string& file, float scroll_speed, Font* heading_font, Font* normal_font, Font* small_font, Font* reference_font )
{
std::string text;
std::vector<std::string> names;
float y = 0;
for(size_t i = 0; i < names.size(); i++) {
if(names[i].size() == 0) {
- y += white_text->get_height() + ITEMS_SPACE;
+ y += normal_font->get_height() + ITEMS_SPACE;
continue;
}
Font* font = 0;
switch(names[i][0])
{
- case ' ': font = white_small_text; break;
- case '\t': font = white_text; break;
- case '-': font = white_big_text; break;
- case '*': font = blue_text; break;
- default: font = blue_text; break;
+ case ' ': font = small_font; break;
+ case '\t': font = normal_font; break;
+ case '-': font = heading_font; break;
+ case '*': font = reference_font; break;
+ default: font = reference_font; break;
}
context.draw_text_center(font,