source: golgotha/src/golg/options.cc

Last change on this file was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 8.1 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "options.hh"
10#include "gui/button.hh"
11#include "gui/text.hh"
12#include "gui/butbox.hh"
13#include "loaders/load.hh"
14#include "resources.hh"
15#include "gui/image_win.hh"
16#include "mess_id.hh"
17#include "g1_render.hh"
18#include "r1_api.hh"
19#include "app/app.hh"
20#include "g1_speed.hh"
21
22i4_event_handler_reference_class<g1_option_window> g1_options_window;
23
24void g1_option_window::add_buttons()
25{
26  int i;
27  i4_button_box_class *visbox=new i4_button_box_class(this);
28  i4_button_class *vi[3];
29
30  vi[0]=create_button(i4gets("vis_low_help"),
31                      g1_resource_class::OPTIONS_VIS_LOW, 0, VIS_LOW);
32
33  vi[1]=create_button(i4gets("vis_med_help"),
34                      g1_resource_class::OPTIONS_VIS_MEDIUM, 0, VIS_MEDIUM);
35
36  vi[2]=create_button(i4gets("vis_hi_help"),
37                      g1_resource_class::OPTIONS_VIS_HIGH, 0, VIS_HIGH);
38
39  for (i=0; i<3; i++)
40    visbox->add_button(0,0, vi[i]);
41
42  visbox->push_button(vi[g1_resources.radius_mode], i4_F);   
43  visbox->arrange_down_right();
44  visbox->resize_to_fit_children();
45
46     
47  i4_button_box_class *pixelbox=0;
48  if (g1_render.r_api->expand_type_supported(R1_COPY_2x2) ||
49      g1_render.r_api->expand_type_supported(R1_COPY_1x1_SCANLINE_SKIP))
50  {     
51    pixelbox=new i4_button_box_class(this);     
52    pixelbox->add_button(0,0, create_button(i4gets("normal_pixel_help"),
53                                            g1_resource_class::OPTIONS_PIXEL_NORMAL, 0,
54                                            NORMAL_PIXEL));
55
56    if (g1_render.r_api->expand_type_supported(R1_COPY_2x2))
57      pixelbox->add_button(0,0, create_button(i4gets("double_pixel_help"),
58                                              g1_resource_class::OPTIONS_DOUBLEPIXEL, 0,
59                                              DOUBLE_PIXEL));
60
61    if (g1_render.r_api->expand_type_supported(R1_COPY_1x1_SCANLINE_SKIP))
62      pixelbox->add_button(0,0, create_button(i4gets("interlace_pixel_help"),
63                                              g1_resource_class::OPTIONS_INTERLACE, 0,
64                                              INTERLACE));
65    pixelbox->arrange_down_right();
66    pixelbox->resize_to_fit_children();
67  }
68
69
70  int x=4,y=4;
71  add_child(x,y, visbox);
72  x+=visbox->width()+5;
73
74  if (pixelbox)
75  {
76    add_child(x, y, pixelbox);
77    x+=pixelbox->width()+5;
78  }
79
80  i4_button_class *sound_but=create_button(i4gets("3d/2d_sound_help"),
81                                           g1_resource_class::OPTIONS_SOUND,
82                                           &sound_image_win, SOUND);
83  add_child(x,y, sound_but);
84  x+=sound_but->width();
85
86#if 0
87  i4_button_class *shadow_but=create_button(i4gets("shadows_help"),
88                                            g1_enable_shadows ?
89                                            g1_resource_class::OPTIONS_SHADOWS_ON :
90                                            g1_resource_class::OPTIONS_SHADOWS_OFF,
91                                            &shadow_image_win, SHADOWS);
92  shadow_but->set_popup(i4_T);
93
94  add_child(x,y, shadow_but);
95  x+=shadow_but->width();
96#endif
97
98  i4_button_class *gamespeed_but=create_button(i4gets("gamespeed_help"),
99                                               g1_resource_class::OPTIONS_GAME_SPEED, 0,
100                                               GAME_SPEED);
101  add_child(x,y, gamespeed_but);
102  x+=gamespeed_but->width();
103
104}
105
106g1_option_window::g1_option_window(i4_graphical_style_class *style)
107  : i4_parent_window_class(0,0),
108    style(style)
109{
110  options_background=i4_load_image(i4gets("options_background"));
111  if (!options_background)
112    i4_error("missing image options_background (res/g1.res)");
113
114  resize(options_background->width(), options_background->height());
115
116  mode=SLIDE_RIGHT;   
117  slide_speed=options_background->width()/2;
118  slide_correction=get_correction();
119
120  add_buttons();
121}
122
123void g1_option_window::forget_redraw()
124{
125  if (mode==SLIDE_RIGHT)
126  {
127    i4_user_message_event_class slide(SLIDE);
128    i4_kernel.send_event(this, &slide);
129  }
130  else if (mode==SLIDE_LEFT)
131  {
132    i4_user_message_event_class slide(SLIDE_AWAY);
133    i4_kernel.send_event(this, &slide);
134  }
135
136}
137
138i4_button_class *g1_option_window::create_button(const i4_const_str &help,
139                                                 int im1,
140                        i4_event_handler_reference_class<i4_image_window_class> *win_ref,
141                                                 int mess_id)
142{
143  i4_image_class *im=g1_resources.images[im1];
144  i4_image_window_class *im_win=new i4_image_window_class(im);
145  if (win_ref)
146    (*win_ref)=im_win;
147
148  i4_user_message_event_class *uev=new i4_user_message_event_class(mess_id);
149  i4_event_reaction_class *rev=new i4_event_reaction_class(this, uev);
150
151  i4_button_class *b=new i4_button_class(&help, im_win, style, rev);
152  return b;
153}
154
155void g1_option_window::parent_draw(i4_draw_context_class &context)
156{
157  forget_redraw();
158  options_background->put_image(local_image, width()-options_background->width(), 0, context);
159}
160                         
161
162int g1_option_window::get_correction()
163{
164  int sum=0, x=options_background->width();
165  while (x)
166  {
167    x/=2;
168    sum+=x;
169  }
170  return options_background->width()-sum;
171}
172
173
174void g1_option_window::receive_event(i4_event *ev)
175{
176  if (ev->type()==i4_event::USER_MESSAGE)   
177  {
178    CAST_PTR(uev, i4_user_message_event_class, ev);
179    switch (uev->sub_type)
180    {
181      case SLIDE :
182      {
183        if (mode!=SLIDE_LEFT)
184        {
185          move(slide_speed + slide_correction, 0);
186          slide_speed/=2;
187          if (slide_speed==0)
188            mode=STOPPED;
189          slide_correction=0;       
190        }
191      } break;
192
193      case SLIDE_AWAY :
194      {
195        if (g1_options_window.get() == this)
196          g1_options_window=0;
197         
198        if (mode!=SLIDE_LEFT)
199        {
200          mode=SLIDE_LEFT;   
201          slide_speed=options_background->width()/2;
202          slide_correction=get_correction();       
203        }
204
205
206        move(-(slide_speed + slide_correction), 0);
207        slide_speed/=2;
208        if (slide_speed==0)
209          i4_kernel.delete_handler(this);
210
211        slide_correction=0;
212      } break;
213     
214
215      case VIS_LOW :
216      case VIS_MEDIUM :
217      case VIS_HIGH :
218        g1_resources.radius_mode=(g1_resource_class::radius_mode_type)(uev->sub_type-VIS_LOW);
219        break;
220
221      case GAME_SPEED :
222      {
223        if (G1_HZ==10)
224          G1_HZ=20;
225        else
226          G1_HZ=10;
227      } break;
228     
229      case INTERLACE :
230      {
231        i4_user_message_event_class uev(G1_INTERLACE_PIXEL);
232        i4_kernel.send_event(i4_current_app, &uev);
233      } break;
234
235      case DOUBLE_PIXEL :
236      {
237        i4_user_message_event_class uev(G1_DOUBLE_PIXEL);
238        i4_kernel.send_event(i4_current_app, &uev);
239      } break;
240
241      case NORMAL_PIXEL :
242      {
243        i4_user_message_event_class uev(G1_NORMAL_PIXEL);
244        i4_kernel.send_event(i4_current_app, &uev);
245      } break;
246
247#if 0
248      case SHADOWS :
249        g1_enable_shadows= !g1_enable_shadows;
250        if (g1_enable_shadows && shadow_image_win.get())
251          shadow_image_win.get()->change_image(
252              g1_resources.images[g1_resource_class::OPTIONS_SHADOWS_ON]);
253        else if (!g1_enable_shadows && shadow_image_win.get())
254          shadow_image_win.get()->change_image(
255              g1_resources.images[g1_resource_class::OPTIONS_SHADOWS_OFF]);       
256        break;
257#endif
258    }
259  }
260  else i4_parent_window_class::receive_event(ev);
261}
262
263
264g1_option_window::~g1_option_window()
265{
266  delete options_background;
267}
Note: See TracBrowser for help on using the repository browser.