Mercurial > fife-parpg
comparison tests/core_tests/test_gui.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 | |
24 // Platform specific includes | |
25 | |
26 // 3rd party library includes | |
27 #include <boost/scoped_ptr.hpp> | |
28 #include <boost/shared_ptr.hpp> | |
29 #include <SDL.h> | |
30 #include <guichan.hpp> | |
31 | |
32 // FIFE includes | |
33 // These includes are split up in two parts, separated by one empty line | |
34 // First block: files included from the FIFE root src directory | |
35 // Second block: files included from the same folder | |
36 #include "vfs/vfs.h" | |
37 #include "util/structures/rect.h" | |
38 #include "util/time/timemanager.h" | |
39 #include "vfs/vfs.h" | |
40 #include "vfs/vfsdirectory.h" | |
41 #include "vfs/raw/rawdata.h" | |
42 #include "video/image_location.h" | |
43 #include "video/image.h" | |
44 #include "video/imagepool.h" | |
45 #include "video/sdl/renderbackendsdl.h" | |
46 #include "video/opengl/renderbackendopengl.h" | |
47 #include "loaders/native/video_loaders/image_loader.h" | |
48 #include "loaders/native/video_loaders/subimage_loader.h" | |
49 #include "util/base/exception.h" | |
50 #include "gui/base/opengl/opengl_gui_graphics.h" | |
51 #include "gui/base/sdl/sdl_gui_graphics.h" | |
52 #include "gui/base/gui_image.h" | |
53 #include "gui/base/gui_imageloader.h" | |
54 | |
55 #include "fife_unit_test.h" | |
56 | |
57 using boost::unit_test::test_suite; | |
58 using namespace FIFE; | |
59 | |
60 static const std::string IMAGE_FILE = "../data/beach_e1.png"; | |
61 static const std::string SUBIMAGE_FILE = "../data/rpg_tiles_01.png"; | |
62 | |
63 // Environment | |
64 struct environment { | |
65 boost::shared_ptr<TimeManager> timemanager; | |
66 | |
67 environment() | |
68 : timemanager(new TimeManager()) { | |
69 if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { | |
70 throw SDLException(SDL_GetError()); | |
71 } | |
72 } | |
73 }; | |
74 | |
75 void test_gui_image(RenderBackend& renderbackend, gcn::Graphics& graphics, ImagePool& pool) { | |
76 boost::scoped_ptr<VFS> vfs(new VFS()); | |
77 vfs->addSource(new VFSDirectory(vfs.get())); | |
78 | |
79 pool.addResourceLoader(new SubImageLoader()); | |
80 pool.addResourceLoader(new ImageLoader(vfs.get())); | |
81 | |
82 GuiImageLoader imageloader(pool); | |
83 gcn::Image::setImageLoader(&imageloader); | |
84 | |
85 gcn::Container* top = new gcn::Container(); | |
86 top->setDimension(gcn::Rectangle(0, 0, 200, 300)); | |
87 gcn::Gui* gui = new gcn::Gui(); | |
88 gui->setGraphics(&graphics); | |
89 gui->setTop(top); | |
90 gcn::Label* label = new gcn::Label("Label"); | |
91 ; gcn::Image* guiimage = gcn::Image::load(IMAGE_FILE); | |
92 gcn::Icon* icon = new gcn::Icon(guiimage); | |
93 | |
94 top->add(label, 10, 10); | |
95 top->add(icon, 10, 30); | |
96 | |
97 ImageLoader provider(vfs.get()); | |
98 boost::scoped_ptr<Image> img(dynamic_cast<Image*>(provider.loadResource(ImageLocation(IMAGE_FILE)))); | |
99 | |
100 int h = img->getHeight(); | |
101 int w = img->getWidth(); | |
102 for (int i = 0; i < 100; i+=2) { | |
103 renderbackend.startFrame(); | |
104 img->render(Rect(i, i, w, h)); | |
105 gui->logic(); | |
106 gui->draw(); | |
107 renderbackend.endFrame(); | |
108 } | |
109 delete label; | |
110 delete icon; | |
111 delete guiimage; | |
112 } | |
113 | |
114 #ifdef FIFE_BOOST_VERSION_103300 | |
115 void test_sdl_gui_image() { | |
116 #else | |
117 BOOST_AUTO_TEST_CASE( SDL_gui_test ) { | |
118 #endif | |
119 environment env; | |
120 RenderBackendSDL renderbackend; | |
121 renderbackend.init(); | |
122 ImagePool pool; | |
123 Image* screen = renderbackend.createMainScreen(800, 600, 0, false); | |
124 SdlGuiGraphics graphics(pool); | |
125 graphics.setTarget(screen->getSurface()); | |
126 test_gui_image(renderbackend, graphics, pool); | |
127 } | |
128 | |
129 | |
130 #ifdef FIFE_BOOST_VERSION_103300 | |
131 void test_ogl_gui_image() { | |
132 #else | |
133 BOOST_AUTO_TEST_CASE( OGL_gui_test ) { | |
134 #endif | |
135 environment env; | |
136 RenderBackendOpenGL renderbackend; | |
137 renderbackend.init(); | |
138 ImagePool pool; | |
139 renderbackend.createMainScreen(800, 600, 0, false); | |
140 OpenGLGuiGraphics graphics(pool); | |
141 test_gui_image(renderbackend, graphics, pool); | |
142 } | |
143 | |
144 #ifdef FIFE_BOOST_VERSION_103300 | |
145 test_suite* init_unit_test_suite(int argc, char** const argv) { | |
146 test_suite* test = BOOST_TEST_SUITE("Gui Tests"); | |
147 test->add( BOOST_TEST_CASE( &test_ogl_gui_image ),0 ); | |
148 test->add( BOOST_TEST_CASE( &test_sdl_gui_image ),0 ); | |
149 | |
150 return test; | |
151 } | |
152 #endif |