source: golgotha/src/maxtool/anim_dialog.cc @ 80

Last change on this file since 80 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: 6.7 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 "window/window.hh"
10#include "window/colorwin.hh"
11#include "window/style.hh"
12#include "gui/text_input.hh"
13#include "gui/text.hh"
14#include "app/app.hh"
15#include "lisp/lisp.hh"
16#include "lisp/li_init.hh"
17
18#include "m1_info.hh"
19#include "max_object.hh"
20
21class m1_animation_dialog_class : public i4_color_window_class
22{
23protected:
24  enum
25  //{{{
26  {
27    SPEED,
28    DU,
29    DV,
30    MAXX,
31    MAXY,
32    MAXFRAMES,
33    NONE,
34    ITEMS
35  };
36  //}}}
37  i4_text_window_class *caption[ITEMS];
38  i4_text_input_class *input[ITEMS];
39public:
40  g1_texture_animation *special;
41
42  void add_item(int &h, int item)
43  //{{{
44  {
45    int dh=0;
46
47    if (caption[item])
48    {
49      add_child(10 ,h,caption[item]);
50      dh = caption[item]->height();
51    }
52    if (input[item])
53    {
54      add_child(100,h,input[item]);
55      dh = input[item]->height();
56    }
57    h += dh + 4;
58  }
59  //}}}
60
61  void clear_kids()
62  //{{{
63  {
64    for (int i=0; i<ITEMS; i++)
65    {
66      if (isa_child(caption[i]))
67        remove_child(caption[i]);
68      if (isa_child(input[i]))
69        remove_child(input[i]);
70    }   
71  }
72  //}}}
73
74  void edit_pan()
75  //{{{
76  {
77    int h=10;
78    char buf[512];
79
80    clear_kids();
81
82    sprintf(buf, "%f", special->speed);
83    input[SPEED]->change_text(buf);
84
85    sprintf(buf, "%f", special->du);
86    input[DU]->change_text(buf);
87    sprintf(buf, "%f", special->dv);
88    input[DV]->change_text(buf);
89
90    add_item(h,SPEED);
91    add_item(h,DU);
92    add_item(h,DV);
93  }
94  //}}}
95
96  void edit_animation()
97  //{{{
98  {
99    int h=10;
100    char buf[512];
101
102    clear_kids();
103
104    sprintf(buf, "%f", special->speed);
105    input[SPEED]->change_text(buf);
106
107    int frames_y = int(1.0/special->dv+0.5);
108
109    sprintf(buf, "%d", special->frames_x);
110    input[MAXX]->change_text(buf);
111    sprintf(buf, "%d", frames_y);
112    input[MAXY]->change_text(buf);
113    sprintf(buf, "%d", special->max_frames);
114    input[MAXFRAMES]->change_text(buf);
115
116    add_item(h,SPEED);
117    add_item(h,MAXX);
118    add_item(h,MAXY);
119    add_item(h,MAXFRAMES);
120  }
121  //}}}
122
123  void edit_none()
124  //{{{
125  {
126    int h=10;
127
128    clear_kids();
129
130    add_item(h,NONE);
131  }
132  //}}}
133
134  void find_special()
135  //{{{
136  {
137    m1_poly_object_class *obj = m1_info.obj;
138    int i,found=-1;
139
140    special=0;
141
142    if (!obj) return;
143
144    for (i=0; i<obj->num_quad; i++)
145      if (obj->quad[i].get_flags(g1_quad_class::SELECTED))
146        if (found==-1)
147          found = i;
148        else
149          found = -2;
150
151    if (found<0) return;
152     
153    for (i=0; i<obj->num_special; i++)
154      if (obj->special[i].quad_number == found)
155        special = &obj->special[i];
156  }
157  //}}}
158 
159  void init()
160  //{{{
161  {
162    find_special();
163    if (!special)
164      edit_none();
165    else if (special->max_frames==0)
166      edit_pan();
167    else
168      edit_animation();
169  }
170  //}}}
171
172  m1_animation_dialog_class(i4_graphical_style_class *style)
173    : i4_color_window_class(400,200,style->color_hint->neutral(),style)
174  //{{{
175  {
176    caption[SPEED]     = new i4_text_window_class(      "Frames/Tick:",style);
177    input  [SPEED]     = new i4_text_input_class(style, "<default>",200,40, this);
178    caption[DU]        = new i4_text_window_class(      "DU::",style);
179    input  [DU]        = new i4_text_input_class(style, "<default>",200,40, this);
180    caption[DV]        = new i4_text_window_class(      "DV:",style);
181    input  [DV]        = new i4_text_input_class(style, "<default>",200,40, this);
182    caption[MAXX]      = new i4_text_window_class(      "X divisions:",style);
183    input  [MAXX]      = new i4_text_input_class(style, "<default>",200,40, this);
184    caption[MAXY]      = new i4_text_window_class(      "Y divisions:",style);
185    input  [MAXY]      = new i4_text_input_class(style, "<default>",200,40, this);
186    caption[MAXFRAMES] = new i4_text_window_class(      "Frames:",style);
187    input  [MAXFRAMES] = new i4_text_input_class(style, "<default>",200,40, this);
188    caption[NONE]      = new i4_text_window_class(      "No special animation",style);
189    input  [NONE]      = 0;
190
191    init();
192  }
193  //}}}
194
195  virtual void receive_event(i4_event *ev)
196  //{{{
197  {
198    switch (ev->type())
199    {
200      case i4_event::OBJECT_MESSAGE:
201      {
202        if (!special)
203          break;
204
205        CAST_PTR(tev, i4_text_change_notify_event, ev);
206        int found=-1;
207       
208        for (int i=0; i<ITEMS; i++)
209          if (input[i]==tev->object)
210            found = i;
211
212        i4_str::iterator p = tev->new_text->begin();
213        switch (found)
214        {
215          case SPEED:     special->speed = p.read_float(); break;
216          case DU:        special->du = p.read_float(); break;
217          case DV:        special->dv = p.read_float(); break;
218          case MAXFRAMES:
219            special->max_frames = p.read_number();
220            if (special->max_frames<1) special->max_frames=1;
221            break;
222          case MAXX:
223            special->frames_x = p.read_number();
224            if (special->frames_x<1) special->frames_x=1;
225            special->du = 1.0/i4_float(special->frames_x);
226            break;
227          case MAXY:
228          {
229            int frames_y=p.read_number();
230            if (frames_y<1) frames_y=1;
231            special->dv = 1.0/i4_float(frames_y);
232          } break;
233        }
234      } break;
235
236      default:
237        i4_color_window_class::receive_event(ev);
238        break;
239    }
240  }
241  //}}}
242};
243
244static i4_event_handler_reference_class<m1_animation_dialog_class> m1_animation_dialog;
245
246li_object *m1_edit_special(li_object *o, li_environment *env)
247//{{{
248{
249  if (m1_animation_dialog.get())
250    m1_animation_dialog->init();
251  else
252  {
253    i4_graphical_style_class *style = i4_current_app->get_style();
254    m1_animation_dialog = new m1_animation_dialog_class(style);
255   
256    style->create_mp_window(-1,-1,
257                            m1_animation_dialog->width(),
258                            m1_animation_dialog->height(),
259                            "Edit Special")
260      ->add_child(0,0,m1_animation_dialog.get());
261  }
262  return 0;
263}
264//}}}
265li_automatic_add_function(m1_edit_special, "edit_special");
266
267//{{{ Emacs Locals
268// Local Variables:
269// folded-file: t
270// End:
271//}}}
Note: See TracBrowser for help on using the repository browser.