2005-07-17 06:19:08 +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-08-02 23:07:51 +00:00
|
|
|
// $Id: Input_test.cpp,v 1.6 2005/08/02 23:07:53 cozman Exp $
|
2005-07-17 06:19:08 +00:00
|
|
|
|
|
|
|
#include "photon.hpp"
|
|
|
|
using namespace photon;
|
2005-07-20 06:12:13 +00:00
|
|
|
#include "FPSDisplayTask.hpp" // used to display FPS in title bar
|
2005-07-17 06:19:08 +00:00
|
|
|
|
2005-07-19 20:32:00 +00:00
|
|
|
class MainTask : public Task, public InputListener
|
2005-07-19 05:57:43 +00:00
|
|
|
{
|
2005-07-19 20:32:00 +00:00
|
|
|
|
2005-07-19 05:57:43 +00:00
|
|
|
public:
|
2005-07-19 20:32:00 +00:00
|
|
|
MainTask() :
|
|
|
|
Task("MainTask"),
|
2005-08-02 23:07:51 +00:00
|
|
|
app(Application::getAppCore()),
|
|
|
|
video(Application::getVideoCore())
|
2005-07-19 20:32:00 +00:00
|
|
|
{
|
|
|
|
video.setOrthoView(800,600);
|
2005-07-20 07:30:13 +00:00
|
|
|
|
|
|
|
// add archives to search path
|
|
|
|
util::filesys::addToSearchPath("data/fonts.zip");
|
2005-07-19 20:32:00 +00:00
|
|
|
|
2005-07-20 07:30:13 +00:00
|
|
|
video::Font::addResource("font","FreeMono.ttf",20);
|
2005-07-19 20:32:00 +00:00
|
|
|
font.open("font");
|
|
|
|
}
|
|
|
|
|
|
|
|
// listen for events and set the last event string
|
2005-07-19 05:57:43 +00:00
|
|
|
void onKeyPress(int key)
|
|
|
|
{
|
|
|
|
lastEvent = "key " + boost::lexical_cast<std::string>(key) +
|
|
|
|
" pressed";
|
|
|
|
}
|
|
|
|
|
|
|
|
void onKeyRelease(int key)
|
|
|
|
{
|
|
|
|
lastEvent = "key " + boost::lexical_cast<std::string>(key) +
|
|
|
|
" released";
|
|
|
|
}
|
|
|
|
|
|
|
|
void onMouseButtonPress(int button)
|
|
|
|
{
|
|
|
|
lastEvent = "mouse button " + boost::lexical_cast<std::string>(button) +
|
|
|
|
" pressed";
|
|
|
|
}
|
|
|
|
|
|
|
|
void onMouseButtonRelease(int button)
|
|
|
|
{
|
|
|
|
lastEvent = "mouse button " + boost::lexical_cast<std::string>(button) +
|
|
|
|
" released";
|
|
|
|
}
|
|
|
|
|
|
|
|
void onMouseMove(const math::Vector2& pos)
|
|
|
|
{
|
|
|
|
lastEvent = "mouse moved to " + boost::lexical_cast<std::string>(pos);
|
|
|
|
}
|
2005-07-17 06:19:08 +00:00
|
|
|
|
|
|
|
void update()
|
|
|
|
{
|
2005-07-19 20:32:00 +00:00
|
|
|
// used for spacing text vertically
|
2005-07-17 06:19:08 +00:00
|
|
|
static const photon::uint fontHeight(font.getHeight());
|
|
|
|
photon::uint curHeight(0);
|
|
|
|
|
2005-07-19 20:32:00 +00:00
|
|
|
// draw input event/status notifications, increment curHeight on each
|
|
|
|
// draw so that text is properly spaced vertically
|
|
|
|
font.beginDraw(0,curHeight) << "Last event: " << lastEvent <<
|
2005-07-19 05:57:43 +00:00
|
|
|
font.endDraw();
|
|
|
|
curHeight += fontHeight;
|
|
|
|
|
2005-07-17 06:19:08 +00:00
|
|
|
font.beginDraw(0,curHeight) << "Mouse at " << app.getMouseX() << "," <<
|
|
|
|
app.getMouseY() << " wheel = " << app.getMouseWheelPos() <<
|
|
|
|
font.endDraw();
|
|
|
|
curHeight += fontHeight;
|
|
|
|
|
2005-07-19 05:57:43 +00:00
|
|
|
font.beginDraw(0,curHeight) << "#Pressed Keys = " <<
|
|
|
|
app.getPressedKeys().size() << font.endDraw();
|
|
|
|
curHeight += fontHeight;
|
|
|
|
|
2005-07-17 06:19:08 +00:00
|
|
|
if(app.keyPressed(KEY_SPACE))
|
|
|
|
{
|
|
|
|
font.drawText(0,curHeight, "Space key is pressed.");
|
|
|
|
curHeight += fontHeight;
|
|
|
|
}
|
|
|
|
if(!app.keyPressed(KEY_RETURN))
|
|
|
|
{
|
|
|
|
font.drawText(0,curHeight, "Return key is NOT pressed.");
|
|
|
|
curHeight += fontHeight;
|
|
|
|
}
|
|
|
|
if(app.mouseButtonPressed(MB_LEFT))
|
|
|
|
{
|
|
|
|
font.drawText(0,curHeight, "Left mouse button is pressed.");
|
|
|
|
curHeight += fontHeight;
|
|
|
|
}
|
|
|
|
if(app.mouseButtonPressed(MB_MIDDLE))
|
|
|
|
{
|
|
|
|
font.drawText(0,curHeight, "Center mouse button is pressed.");
|
|
|
|
curHeight += fontHeight;
|
|
|
|
}
|
|
|
|
if(app.mouseButtonPressed(MB_RIGHT))
|
|
|
|
{
|
|
|
|
font.drawText(0,curHeight, "Right mouse button is pressed.");
|
|
|
|
curHeight += fontHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
video::Font font;
|
2005-07-19 20:32:00 +00:00
|
|
|
std::string lastEvent;
|
|
|
|
|
2005-07-17 06:19:08 +00:00
|
|
|
AppCore& app;
|
|
|
|
video::VideoCore& video;
|
|
|
|
};
|
|
|
|
|
2005-07-19 20:32:00 +00:00
|
|
|
// standard application, creates window, registers task and runs
|
2005-07-17 06:19:08 +00:00
|
|
|
class InputTest : public Application
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
int main(const StrVec& args)
|
|
|
|
{
|
2005-08-02 23:07:51 +00:00
|
|
|
Application::getAppCore().createDisplay(800,600,32,0,0,false);
|
2005-07-17 06:19:08 +00:00
|
|
|
|
2005-07-20 06:12:13 +00:00
|
|
|
// be sure to add FPSDisplayTask
|
2005-08-02 23:07:51 +00:00
|
|
|
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask()));
|
|
|
|
Application::getKernel().addTask(TaskPtr(new MainTask()));
|
2005-07-17 06:19:08 +00:00
|
|
|
|
2005-08-02 23:07:51 +00:00
|
|
|
Application::getKernel().run();
|
2005-07-17 06:19:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ENTRYPOINT(InputTest)
|