2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <glib/gi18n.h>
21 #include "framework/messageactivity.hpp"
22 #include "framework/commands.hpp"
23 #include "cave/helper/colors.hpp"
24 #include "gfx/screen.hpp"
25 #include "gfx/fontmanager.hpp"
26 #include "misc/util.hpp"
27 #include "misc/printf.hpp"
30 MessageActivity::MessageActivity(App
*app
, std::string
const &primary
, std::string
const &secondary
, SmartPtr
<Command
> command_after_exit
)
33 command_after_exit(command_after_exit
)
37 text
= SPrintf("%c%s\n\n%c%s") % GD_COLOR_INDEX_WHITE
% primary
% GD_COLOR_INDEX_GRAY3
% secondary
;
39 text
= SPrintf("%c%s") % GD_COLOR_INDEX_WHITE
% primary
;
40 wrapped_text
= gd_wrap_text(text
.c_str(), app
->screen
->get_width() / app
->font_manager
->get_font_width_narrow()-6);
44 void MessageActivity::redraw_event() {
45 int height
= (wrapped_text
.size() + 2) * app
->font_manager
->get_line_height(); /* +2 empty lines */
46 int y1
=(app
->screen
->get_height()-height
)/2; /* middle of the screen */
47 int cx
=2*app
->font_manager
->get_font_width_narrow(), cy
=y1
, cw
=app
->screen
->get_width()-2*cx
, ch
=height
;
49 app
->draw_window(cx
, cy
, cw
, ch
);
50 app
->screen
->set_clip_rect(cx
, cy
, cw
, ch
);
52 app
->set_color(GD_GDASH_WHITE
);
53 for (size_t i
= 0; i
< wrapped_text
.size(); ++i
)
54 app
->blittext_n(-1, y1
+(i
+1)*app
->font_manager
->get_line_height(), wrapped_text
[i
].c_str());
56 app
->screen
->remove_clip_rect();
62 MessageActivity::~MessageActivity() {
63 app
->enqueue_command(command_after_exit
);
67 void MessageActivity::keypress_event(KeyCode keycode
, int gfxlib_keycode
) {
70 app
->enqueue_command(new PopActivityCommand(app
));
73 /* unknown key or modifier - do nothing */