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/showtextactivity.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 ShowTextActivity::ShowTextActivity(App
*app
, char const *title_line
, std::string
const &text
, SmartPtr
<Command
> command_after_exit
)
33 command_after_exit(command_after_exit
),
34 title_line(title_line
)
36 wrapped_text
= gd_wrap_text(text
.c_str(), app
->screen
->get_width() / app
->font_manager
->get_font_width_narrow()-4);
37 linesavailable
= app
->screen
->get_height() / app
->font_manager
->get_line_height()-4;
38 if ((int)wrapped_text
.size() < linesavailable
)
41 scroll_max_y
= wrapped_text
.size()-linesavailable
;
46 void ShowTextActivity::redraw_event() {
49 app
->title_line(title_line
.c_str());
50 // TRANSLATORS: 40 chars max
51 app
->status_line(_("Crsr: move Esc: exit"));
54 app
->set_color(GD_GDASH_GRAY2
);
55 if (scroll_y
<scroll_max_y
)
56 app
->blittext_n(app
->screen
->get_width() - app
->font_manager
->get_font_width_narrow(),
57 app
->screen
->get_height()-3*app
->font_manager
->get_line_height(), CPrintf("%c") % GD_DOWN_CHAR
);
59 app
->blittext_n(app
->screen
->get_width() - app
->font_manager
->get_font_width_narrow(),
60 app
->font_manager
->get_line_height()*2, CPrintf("%c") % GD_UP_CHAR
);
62 app
->set_color(GD_GDASH_LIGHTBLUE
);
63 for (int l
=0; l
<linesavailable
&& scroll_y
+ l
<(int)wrapped_text
.size(); ++l
)
64 app
->blittext_n(app
->font_manager
->get_font_width_narrow()*2,
65 l
*app
->font_manager
->get_line_height()+app
->font_manager
->get_line_height()*2, wrapped_text
[scroll_y
+l
].c_str());
71 ShowTextActivity::~ShowTextActivity() {
72 app
->enqueue_command(command_after_exit
);
76 void ShowTextActivity::keypress_event(KeyCode keycode
, int gfxlib_keycode
) {
79 scroll_y
-= linesavailable
-1;
91 scroll_y
+= linesavailable
-1;
92 if (scroll_y
> scroll_max_y
)
93 scroll_y
= scroll_max_y
;
97 if (scroll_y
< scroll_max_y
) {
103 app
->enqueue_command(new PopActivityCommand(app
));
106 /* unknown key or modifier - do nothing */