QSDK 1.1 Documentation
Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

ptut04.cpp File Reference

Go to the source code of this file.

Compounds

struct  MyListener

Functions

int main (int argc, char *argv[])


Function Documentation

int main int  argc,
char *  argv[]
 

Definition at line 175 of file ptut04.cpp.

References Layer::addListener(), Application::addListener(), Application::app(), StatsLayer::create(), TextLayer::create(), ImageLayer::create(), Screen::create(), Shader::create(), StatsLayer::Draw, Font::find(), Texture::find(), StatsLayer::Fps, Application::init(), StatsLayer::Memory, Database::open(), StatsLayer::setCategories(), Screen::setKeyboardFocus(), Application::start(), and StatsLayer::Times.

00176 {
00177     const char descrText[] = "This tutorial introduces\nthe use of 2D\n"
00178         "layers for building\nuser intefaces";
00179 
00180     const char helpText[] = "Press <escape> or <q> to Quit";
00181 
00182     /**
00183      * Initialise the application.
00184      */
00185     Q::Application app = Q::Application::app();
00186     app.init(argc, argv);
00187 
00188     /**
00189      * Open the database that contains the logo image and the font.
00190      */
00191     Q::Database db = Q::Database::open("root:/data/ptut04.q");
00192 
00193     /**
00194      * Find the logo image in the database.
00195      */
00196     Q::Texture t = Q::Texture::find("POWEREDBYQ");
00197 
00198     /**
00199      * Create a shader for the image.
00200      */
00201     Q::Shader shader = Q::Shader::create(0, t);
00202 
00203     /**
00204      * Find the font in the database.
00205      */
00206     Q::Font font = Q::Font::find("A010015L");
00207 
00208     /**
00209      * Create a screen
00210      */
00211     Q::Screen screen = Q::Screen::create("ptut04", 0, 0,
00212                                          Maths::Vec2f(640, 480),
00213                                          Maths::Vec2f(1280, 1024),
00214                                          16, false);
00215 
00216     /**
00217      * Create a plain color ImageLayer, the size of the screen, to work as a
00218      * background color.
00219      */
00220     Q::ImageLayer::create(screen, Q::Shader(),
00221                           Maths::Vec2f(0, 0),
00222                           Maths::Vec2f(1280, 1024),
00223                           Maths::Vec2f(0, 0),
00224                           Maths::Color4b(51, 102, 153),
00225                           false);
00226 
00227     /**
00228      * Create an ImageLayer to display a Texture from a Database.
00229      */
00230     Q::ImageLayer logo = Q::ImageLayer::create(screen, shader,
00231                                                Maths::Vec2f(0, 0),
00232                                                Maths::Vec2f(100, 100),
00233                                                Maths::Vec2f(0.5, 0.5),
00234                                                Maths::Color4b(255, 255, 255));
00235 
00236     /**
00237      * Create a TextLayer to show the text describing what the application
00238      * does, using a Font from the Database
00239      */
00240     Q::TextLayer::create(screen, descrText,
00241                          font, 50, 0,
00242                          Q::Font::rightJustified,
00243                          Maths::Vec2f(1180, 700),
00244                          Maths::Vec2f(1, 1),
00245                          Maths::Color4b(192, 192, 192));
00246 
00247     /**
00248      * Create a TextLayer to show the text describing what the application
00249      * does, using a Font from the Database
00250      */
00251     Q::TextLayer::create(screen, helpText,
00252                          font, 50, 0,
00253                          Q::Font::leftJustified,
00254                          Maths::Vec2f(100, 100),
00255                          Maths::Vec2f(0, 0),
00256                          Maths::Color4b(192, 192, 192));
00257 
00258     /**
00259      * Create a StatsLayer to see how the application is performing.
00260      */
00261     Q::StatsLayer stats = Q::StatsLayer::create(screen, font, 50, 0,
00262                                                 Maths::Vec2f(100, 924),
00263                                                 Maths::Vec2f(0, 1),
00264                                                 Maths::Color4b(192, 192, 192),
00265                                                 Maths::Color4b(0, 0, 0, 0),
00266                                                 true);
00267     /**
00268      * Set the categories that we are interested in seeing in the stats.
00269      */
00270     stats.setCategories(Q::StatsLayer::Fps |
00271                         Q::StatsLayer::Memory |
00272                         Q::StatsLayer::Draw |
00273                         Q::StatsLayer::Times);
00274 
00275     /**
00276      * Create an object to manipulate the logo imagelayer and handle
00277      * keypresses for quitting the application.
00278      */
00279     MyListener l(logo);
00280 
00281     /**
00282      * Connect the object to the Application to activate its function as an
00283      * ApplicationListener.
00284      */
00285     app.addListener(l);
00286 
00287     /**
00288      * Connect the object to a Layer to activcate its function as a
00289      * KeyboardListener
00290      */
00291     logo.addListener((Q::KeyboardListener&) l);
00292 
00293     /**
00294      * Set the keyboard focus to the Layer that the listener is connected to
00295      * otherwise the keyboard activity will come through.
00296      */
00297     screen.setKeyboardFocus(logo);
00298 
00299     /**
00300      * Start the application. MyListener::onTick will be called once per frame
00301      * until shutdown, at which point this function will return.
00302      */
00303     app.start();
00304 
00305     return 0;
00306 }

Return to QSDK documentation Contents page. Contact details for support, information and fault-reporting.
Qube Software Limited © 2000-2004