00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include "SDL_events.h"
00024
00025 #include "Yesno_gump.h"
00026 #include "gamewin.h"
00027 #include "mouse.h"
00028 #include "game.h"
00029 #include "Gump_button.h"
00030 #include "Gump_manager.h"
00031
00032
00033
00034
00035
00036 short Yesno_gump::yesx = 63;
00037 short Yesno_gump::yesnoy = 45;
00038 short Yesno_gump::nox = 84;
00039
00040
00041
00042
00043
00044
00045 class Yesno_button : public Gump_button
00046 {
00047 int isyes;
00048 public:
00049 Yesno_button(Gump *par, int px, int py, int yes)
00050 : Gump_button(par, yes ?
00051 game->get_shape("gumps/yesbtn")
00052 : game->get_shape("gumps/nobtn"), px, py),
00053 isyes(yes)
00054 { }
00055
00056 virtual void activate();
00057 };
00058
00059
00060
00061
00062
00063
00064 void Yesno_button::activate
00065 (
00066 )
00067 {
00068 ((Yesno_gump *) parent)->set_answer(isyes);
00069 }
00070
00071
00072
00073
00074
00075
00076 Yesno_gump::Yesno_gump
00077 (
00078 const std::string &txt
00079 ) : Modal_gump(0, game->get_shape("gumps/yesnobox")), text(txt), answer(-1)
00080 {
00081 set_object_area(Rectangle(6, 6, 116, 30));
00082 yes_button = new Yesno_button(this, yesx, yesnoy, 1);
00083 no_button = new Yesno_button(this, nox, yesnoy, 0);
00084 }
00085
00086
00087
00088
00089
00090 Yesno_gump::~Yesno_gump
00091 (
00092 )
00093 {
00094 delete yes_button;
00095 delete no_button;
00096 }
00097
00098
00099
00100
00101
00102 void Yesno_gump::paint
00103 (
00104 )
00105 {
00106
00107 paint_shape(x, y);
00108
00109 yes_button->paint();
00110 no_button->paint();
00111
00112 sman->paint_text_box(2, text.c_str(), x + object_area.x,
00113 y + object_area.y, object_area.w, object_area.h, 2);
00114 gwin->set_painted();
00115 }
00116
00117
00118
00119
00120
00121 void Yesno_gump::mouse_down
00122 (
00123 int mx, int my
00124 )
00125 {
00126
00127 if (yes_button->on_button(mx, my))
00128 pushed = yes_button;
00129 else if (no_button->on_button(mx, my))
00130 pushed = no_button;
00131 else
00132 {
00133 pushed = 0;
00134 return;
00135 }
00136 pushed->push();
00137 }
00138
00139
00140
00141
00142
00143 void Yesno_gump::mouse_up
00144 (
00145 int mx, int my
00146 )
00147 {
00148 if (pushed)
00149 {
00150 pushed->unpush();
00151 if (pushed->on_button(mx, my))
00152 pushed->activate();
00153 pushed = 0;
00154 }
00155 }
00156
00157
00158
00159
00160
00161 void Yesno_gump::key_down(int chr)
00162 {
00163 if (chr == 'y' || chr == 'Y' || chr == SDLK_RETURN)
00164 set_answer(1);
00165 else if (chr == 'n' || chr == 'N' || chr == SDLK_ESCAPE)
00166 set_answer(0);
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 int Yesno_gump::ask
00176 (
00177 const char *txt
00178 )
00179 {
00180 Yesno_gump *dlg = new Yesno_gump(txt);
00181 int answer;
00182 if (!gumpman->do_modal_gump(dlg, Mouse::hand))
00183 answer = 0;
00184 else
00185 answer = dlg->get_answer();
00186 delete dlg;
00187 return (answer);
00188 }