cpp_photon/test/Font_test.cpp

75 lines
1.9 KiB
C++
Raw Normal View History

2005-06-29 04:30:40 +00:00
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
2005-07-20 07:30:13 +00:00
// $Id: Font_test.cpp,v 1.8 2005/07/20 07:30:13 cozman Exp $
2005-06-29 04:30:40 +00:00
#include "photon.hpp"
using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar
2005-06-29 04:30:40 +00:00
class MainTask : public Task
{
public:
MainTask() :
Task("MainTask"),
app(AppCore::getInstance()),
video(video::VideoCore::getInstance())
{
video.setOrthoView(800,600);
2005-07-20 07:30:13 +00:00
// add archive to search path
util::filesys::addToSearchPath("data/fonts.zip");
2005-07-19 18:47:28 +00:00
// show two different fonts
2005-07-20 07:30:13 +00:00
video::Font::addResource("font1","FreeMono.ttf",32);
video::Font::addResource("font2","FreeSerif.ttf",18);
2005-07-04 03:06:48 +00:00
font.open("font1");
font2.open("font2");
2005-06-29 04:30:40 +00:00
}
2005-06-29 04:30:40 +00:00
void update()
{
2005-07-19 18:47:28 +00:00
// draw the three strings to the screen
2005-07-17 07:14:09 +00:00
font.setColor(video::Color(0,128,128));
font.drawText(0, 0, "Photon");
2005-07-17 07:14:09 +00:00
font.setColor(video::Color(255,0,0));
font.drawText(font.calcStringWidth("Photon"), font.getHeight(),
"FPS: %.0f", app.getFramerate() );
2005-07-19 18:47:28 +00:00
font2.beginDraw(200, 200) << "another (plain) font" << font2.endDraw();
2005-06-29 04:30:40 +00:00
}
private:
video::Font font;
2005-07-04 03:06:48 +00:00
video::Font font2;
2005-06-29 04:30:40 +00:00
AppCore& app;
video::VideoCore& video;
};
2005-07-19 18:47:28 +00:00
// standard application, creates window, registers task and runs
2005-07-04 03:06:48 +00:00
class FontTest : public Application
2005-06-29 04:30:40 +00:00
{
public:
int main(const StrVec& args)
{
AppCore::getInstance().createDisplay(800,600,32,0,0,false);
// be sure to add FPSDisplayTask
Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
2005-06-29 04:30:40 +00:00
Kernel::getInstance().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run();
return 0;
}
};
2005-07-04 03:06:48 +00:00
ENTRYPOINT(FontTest)