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 | 38232a42ff8d |
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 #include "fife_unittest++.h" | |
26 | |
27 // 3rd party library includes | |
28 #include <boost/scoped_ptr.hpp> | |
29 #include <boost/shared_ptr.hpp> | |
30 #include <SDL.h> | |
31 #include <guichan.hpp> | |
32 #include "../../ext/UnitTest++/src/UnitTest++.h" | |
33 | |
34 #include "vfs/vfs.h" | |
35 #include "util/structures/rect.h" | |
36 #include "util/time/timemanager.h" | |
37 #include "vfs/vfs.h" | |
38 #include "vfs/vfsdirectory.h" | |
39 #include "vfs/raw/rawdata.h" | |
40 #include "video/image_location.h" | |
41 #include "video/image.h" | |
42 #include "video/imagepool.h" | |
43 #include "video/sdl/renderbackendsdl.h" | |
44 #include "video/opengl/renderbackendopengl.h" | |
45 #include "loaders/native/video_loaders/image_loader.h" | |
46 #include "loaders/native/video_loaders/subimage_loader.h" | |
47 #include "util/base/exception.h" | |
48 #include "gui/base/opengl/opengl_gui_graphics.h" | |
49 #include "gui/base/sdl/sdl_gui_graphics.h" | |
50 #include "gui/base/gui_image.h" | |
51 #include "gui/base/gui_imageloader.h" | |
52 | |
53 using namespace FIFE; | |
54 | |
55 static const std::string IMAGE_FILE = "../../tests/data/beach_e1.png"; | |
56 static const std::string SUBIMAGE_FILE = "../../tests/data/rpg_tiles_01.png"; | |
57 struct environment { | |
58 boost::shared_ptr<TimeManager> timemanager; | |
59 | |
60 environment() | |
61 : timemanager(new TimeManager()) { | |
62 if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { | |
63 throw SDLException(SDL_GetError()); | |
64 } | |
65 } | |
66 }; | |
67 | |
68 void test_gui_image(RenderBackend& renderbackend, gcn::Graphics& graphics, ImagePool& pool) { | |
69 boost::scoped_ptr<VFS> vfs(new VFS()); | |
70 vfs->addSource(new VFSDirectory(vfs.get())); | |
71 | |
72 pool.addResourceLoader(new SubImageLoader()); | |
73 pool.addResourceLoader(new ImageLoader(vfs.get())); | |
74 | |
75 GuiImageLoader imageloader(pool); | |
76 gcn::Image::setImageLoader(&imageloader); | |
77 | |
78 | |
79 gcn::Container* top = new gcn::Container(); | |
80 top->setDimension(gcn::Rectangle(0, 0, 200, 300)); | |
81 gcn::Gui* gui = new gcn::Gui(); | |
82 gui->setGraphics(&graphics); | |
83 gui->setTop(top); | |
84 gcn::Label* label = new gcn::Label("Label"); | |
85 | |
86 gcn::Image* guiimage = gcn::Image::load(IMAGE_FILE); | |
87 gcn::Icon* icon = new gcn::Icon(guiimage); | |
88 | |
89 top->add(label, 10, 10); | |
90 top->add(icon, 10, 30); | |
91 | |
92 ImageLoader provider(vfs.get()); | |
93 boost::scoped_ptr<Image> img(provider.load(ImageLocation(IMAGE_FILE))); | |
94 | |
95 int h = img->getHeight(); | |
96 int w = img->getWidth(); | |
97 for (int i = 0; i < 100; i+=2) { | |
98 renderbackend.startFrame(); | |
99 img->render(Rect(i, i, w, h)); | |
100 gui->logic(); | |
101 gui->draw(); | |
102 renderbackend.endFrame(); | |
103 } | |
104 delete label; | |
105 delete icon; | |
106 delete guiimage; | |
107 } | |
108 | |
109 | |
110 TEST(test_sdl_gui_image) | |
111 { | |
112 environment env; | |
113 RenderBackendSDL renderbackend; | |
114 renderbackend.init(); | |
115 ImagePool pool; | |
116 Image* screen = renderbackend.createMainScreen(800, 600, 0, false); | |
117 SdlGuiGraphics graphics(pool); | |
118 graphics.setTarget(screen->getSurface()); | |
119 test_gui_image(renderbackend, graphics, pool); | |
120 } | |
121 | |
122 TEST(test_ogl_gui_image) | |
123 { | |
124 environment env; | |
125 RenderBackendOpenGL renderbackend; | |
126 renderbackend.init(); | |
127 ImagePool pool; | |
128 renderbackend.createMainScreen(800, 600, 0, false); | |
129 OpenGLGuiGraphics graphics(pool); | |
130 test_gui_image(renderbackend, graphics, pool); | |
131 } |