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.
17 #include "framework/askyesnoactivity.hpp"
18 #include "framework/commands.hpp"
19 #include "gfx/fontmanager.hpp"
20 #include "gfx/screen.hpp"
21 #include "cave/helper/colors.hpp"
22 #include "misc/printf.hpp"
25 AskYesNoActivity::AskYesNoActivity(App
*app
, char const *question
, const char *yes_answer
, char const *no_answer
, SmartPtr
<Command
> command_when_yes
, SmartPtr
<Command
> command_when_no
)
29 yes_answer(yes_answer
), no_answer(no_answer
),
30 command_when_yes(command_when_yes
), command_when_no(command_when_no
)
35 void AskYesNoActivity::redraw_event() {
36 int height
=6*app
->font_manager
->get_line_height();
37 int y1
=(app
->screen
->get_height()-height
)/2; /* middle of the screen */
38 int cx
=2*app
->font_manager
->get_font_width_narrow(), cy
=y1
, cw
=app
->screen
->get_width()-2*cx
, ch
=height
;
40 app
->draw_window(cx
, cy
, cw
, ch
);
41 app
->screen
->set_clip_rect(cx
, cy
, cw
, ch
);
42 app
->set_color(GD_GDASH_WHITE
);
43 app
->blittext_n(-1, y1
+app
->font_manager
->get_line_height(), question
.c_str());
44 app
->blittext_n(-1, y1
+3*app
->font_manager
->get_line_height(), CPrintf("N: %s, Y: %s") % no_answer
.c_str() % yes_answer
.c_str());
45 app
->screen
->remove_clip_rect();
51 void AskYesNoActivity::keypress_event(KeyCode keycode
, int gfxlib_keycode
) {
55 app
->enqueue_command(new PopActivityCommand(app
));
56 app
->enqueue_command(command_when_yes
);
60 app
->enqueue_command(new PopActivityCommand(app
));
61 app
->enqueue_command(command_when_no
);