2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include "misc/printf.hpp"
31 #include "misc/logger.hpp"
32 #include "gfx/pixbuf.hpp"
33 #include "gfx/pixbuffactory.hpp"
34 #include "gfx/screen.hpp"
35 #include "cave/colors.hpp"
36 #include "cave/cavetypes.hpp"
37 #include "cave/titleanimation.hpp"
39 std::vector
<Pixbuf
*> get_title_animation_pixbuf(const GdString
&title_screen
, const GdString
&title_screen_scroll
, bool one_frame_only
, PixbufFactory
&pixbuf_factory
) {
40 typedef std::auto_ptr
<Pixbuf
> PixbufPtr
;
42 std::vector
<Pixbuf
*> animation
;
44 PixbufPtr screen
, tile
;
46 if (title_screen
!= "")
47 screen
= PixbufPtr(pixbuf_factory
.create_from_base64(title_screen
.c_str()));
48 if (screen
.get() != NULL
&& title_screen_scroll
!= "")
49 tile
= PixbufPtr(pixbuf_factory
.create_from_base64(title_screen_scroll
.c_str()));
50 } catch (std::exception
&e
) {
51 gd_message(CPrintf("Caveset is storing an invalid title screen image: %s") % e
.what());
55 if (tile
.get() != NULL
&& tile
->get_height() > 40) {
56 gd_message("Caveset is storing an oversized tile image");
60 /* if no special title image or unable to load that one, load the built-in */
61 if (screen
.get() == NULL
) {
63 screen
= PixbufPtr(pixbuf_factory
.create_from_inline(sizeof(gdash_screen
), gdash_screen
));
64 /* the tile to be put under the screen */
65 tile
= PixbufPtr(pixbuf_factory
.create_from_inline(sizeof(gdash_tile
), gdash_tile
));
66 g_assert(screen
.get() != NULL
);
67 g_assert(tile
.get() != NULL
);
70 /* if no tile, let it be black. */
71 if (tile
.get() == NULL
) {
72 /* one-row pixbuf, so no animation; totally black. */
73 tile
= PixbufPtr(pixbuf_factory
.create(screen
->get_width(), 1));
74 tile
->fill(GdColor::from_rgb(0, 0, 0));
77 /* do not allow more than 40 frames of animation */
78 g_assert(tile
->get_height() < 40);
80 /* create a big image, which is one tile larger than the title image size */
81 Pixbuf
*bigone
= pixbuf_factory
.create(screen
->get_width(), screen
->get_height() + tile
->get_height());
82 /* and fill it with the tile. use copy(), so pixbuf data is initialized! */
83 for (int y
= 0; y
< screen
->get_height() + tile
->get_height(); y
+= tile
->get_height())
84 for (int x
= 0; x
< screen
->get_width(); x
+= tile
->get_width())
85 tile
->copy(*bigone
, x
, y
);
87 int framenum
= one_frame_only
? 1 : tile
->get_height();
88 for (int i
= 0; i
< framenum
; i
++) {
89 Pixbuf
*frame
= pixbuf_factory
.create(screen
->get_width(), screen
->get_height());
90 // copy part of the big tiled image
91 bigone
->copy(0, i
, screen
->get_width(), screen
->get_height(), *frame
, 0, 0);
92 // and composite it with the title image
93 screen
->blit(*frame
, 0, 0);
95 animation
.push_back(frame
);
102 std::vector
<Pixmap
*> get_title_animation_pixmap(const GdString
&title_screen
, const GdString
&title_screen_scroll
, bool one_frame_only
, Screen
&screen
, PixbufFactory
&pixbuf_factory
) {
103 std::vector
<Pixbuf
*> pixbufs
;
104 pixbufs
= get_title_animation_pixbuf(title_screen
, title_screen_scroll
, one_frame_only
, pixbuf_factory
);
106 pixbufs
= get_title_animation_pixbuf(GdString(), GdString(), one_frame_only
, pixbuf_factory
);
108 std::vector
<Pixmap
*> pixmaps
;
109 for (unsigned i
= 0; i
< pixbufs
.size(); ++i
) {
110 pixmaps
.push_back(screen
.create_scaled_pixmap_from_pixbuf(*pixbufs
[i
], false));