Mercurial > fife-parpg
comparison ext/guichan-0.8.2/examples/openlayer.hpp @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 /* | |
2 * Code that sets up an OpenLayer application with Guichan using the | |
3 * Guichan OpenLayer back end. | |
4 */ | |
5 | |
6 #include <guichan.hpp> | |
7 #include <guichan/openlayer.hpp> | |
8 | |
9 namespace openlayer | |
10 { | |
11 // All back ends contain objects to make Guichan work on a | |
12 // specific target - in this case OpenLayer - and they are a Graphics | |
13 // object to make Guichan able to draw itself using OpenLayer, an | |
14 // input objec to make Guichan able to get user input using OpenLayer | |
15 // and an ImageLoader object to make Guichan able to load images | |
16 // using OpenLayer. | |
17 gcn::OpenLayerGraphics* graphics; | |
18 gcn::OpenLayerInput* input; | |
19 gcn::OpenLayerImageLoader* imageLoader; | |
20 | |
21 /** | |
22 * Initialises the OpenLayer application. This function creates the global | |
23 * Gui object that can be populated by various examples. | |
24 */ | |
25 void init() | |
26 { | |
27 // We simply initialise OpenLayer as we would do with any OpenLayer application. | |
28 ol::Setup::SetupProgram(true, true, true); | |
29 ol::Setup::SetupScreen(640, 480, WINDOWED); | |
30 | |
31 // Now it's time to initialise the Guichan OpenLayer back end. | |
32 | |
33 imageLoader = new gcn::OpenLayerImageLoader(); | |
34 // The ImageLoader Guichan should use needs to be passed to the Image object | |
35 // using a static function. | |
36 gcn::Image::setImageLoader(imageLoader); | |
37 graphics = new gcn::OpenLayerGraphics(); | |
38 // We need to tell the OpenLayer Graphics object how big the screen is. | |
39 graphics->setTargetPlane(640, 480); | |
40 input = new gcn::OpenLayerInput(); | |
41 | |
42 // Now we create the Gui object to be used with this OpenLayer application. | |
43 globals::gui = new gcn::Gui(); | |
44 // The Gui object needs a Graphics to be able to draw itself and an Input | |
45 // object to be able to check for user input. In this case we provide the | |
46 // Gui object with OpenLayer implementations of these objects hence making Guichan | |
47 // able to utilise OpenLayer. | |
48 globals::gui->setGraphics(graphics); | |
49 globals::gui->setInput(input); | |
50 } | |
51 | |
52 /** | |
53 * Halts the OpenLayer application. | |
54 */ | |
55 void halt() | |
56 { | |
57 delete globals::gui; | |
58 | |
59 delete imageLoader; | |
60 delete input; | |
61 delete graphics; | |
62 } | |
63 | |
64 /** | |
65 * Runs the OpenLayer application. | |
66 */ | |
67 void run() | |
68 { | |
69 ol::Bitmap mouse_bmp; | |
70 mouse_bmp.Load(mouse_sprite, ol::CONVERT_MAGIC_PINK); | |
71 | |
72 if (!mouse_bmp ) | |
73 { | |
74 ol::OlError("Pointer not loaded."); | |
75 } | |
76 | |
77 while(!key[KEY_ESC]) | |
78 { | |
79 // Now we let the Gui object perform its logic. | |
80 globals::gui->logic(); | |
81 // Now we let the Gui object draw itself. | |
82 globals::gui->draw(); | |
83 | |
84 // We draw the mouse pointer manually. | |
85 mouse_bmp.Blit(mouse_x, mouse_y); | |
86 // Finally we update the screen. | |
87 ol::GfxRend::RefreshScreen(); | |
88 } | |
89 } | |
90 } |