cpp_photon/test/Font_test.cpp

64 lines
1.7 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-11-15 02:59:08 +00:00
// $Id: Font_test.cpp,v 1.14 2005/11/15 02:59:08 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
2005-08-08 06:37:10 +00:00
class MainState : public State
2005-06-29 04:30:40 +00:00
{
public:
2005-08-08 06:37:10 +00:00
MainState() :
app(Application::getInstance())
2005-06-29 04:30:40 +00:00
{
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-08-08 06:37:10 +00:00
void render()
{
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
2005-08-08 06:37:10 +00:00
Application& app;
2005-06-29 04:30:40 +00:00
};
2005-08-08 06:37:10 +00:00
int PhotonMain(const StrVec& args)
2005-06-29 04:30:40 +00:00
{
Application& app(Application::getInstance());
2005-11-15 02:59:08 +00:00
app.createDisplay(800,600,32,0,0,DISP_WINDOWED); // create window
2005-06-29 04:30:40 +00:00
2005-08-08 06:37:10 +00:00
// be sure to add FPSDisplayTask
2005-08-17 06:35:54 +00:00
//TaskManager::getInstance().addTask(util::TaskPtr(new FPSDisplayTask()));
2005-06-29 04:30:40 +00:00
app.setState<MainState>(); // register state and make active
app.run(); // run until finished
2005-08-08 06:37:10 +00:00
return 0;
}