source: golgotha/src/golg/editor/mode/e_camera.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: 6.3 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 "editor/mode/e_camera.hh"
10#include "editor/contedit.hh"
11#include "m_flow.hh"
12#include "image/color.hh"
13#include "device/keys.hh"
14#include "editor/dialogs/d_time.hh"
15#include "g1_render.hh"
16#include "editor/editor.hh"
17#include "gui/butbox.hh"
18#include "editor/e_res.hh"
19
20g1_camera_params g1_e_camera;
21
22void g1_camera_mode::edit_selected()
23{
24  i4_spline_class *s[g1_controller_edit_class::MAX_SPLINE_EDIT];
25  int t=c->get_current_splines(s,g1_controller_edit_class::MAX_SPLINE_EDIT);
26
27  w32 cur_frame=0;
28
29  for (int i=0; i<t; i++)
30  {
31    i4_spline_class::point *sp=s[i]->begin();
32    for (;sp;sp=sp->next)
33    {
34      if (sp->selected)
35        cur_frame=sp->frame;
36    }
37  }
38
39  i4_parent_window_class *p=g1_create_time_edit_window(c->style, cur_frame);
40  g1_e_camera.set_edit_window(c->parent->root_window(), lx() + c->x(), ly() + c->y());
41}
42
43g1_mode_handler::state g1_camera_mode::current_state()
44{
45  w8 remap[]={ ROTATE, ZOOM, OTHER, OTHER, DRAG_SELECT, DRAG_SELECT };
46
47  I4_ASSERT(g1_e_camera.get_minor_mode()<=sizeof(remap), "state too big");
48  return (g1_mode_handler::state)remap[g1_e_camera.get_minor_mode()];
49}
50
51void g1_camera_mode::mouse_down()
52{
53  if (g1_e_camera.get_minor_mode()==g1_camera_params::ADD_CAMERA)
54    c->add_movie_control_point(0);
55  else if (g1_e_camera.get_minor_mode()==g1_camera_params::ADD_TARGET)
56    c->add_movie_control_point(1);
57  else if (g1_e_camera.get_minor_mode()==g1_camera_params::ADD_OBJECT)
58    c->add_movie_control_point(2);
59
60  g1_mode_handler::mouse_down();
61}
62
63
64i4_bool g1_camera_mode::select_object(sw32 mx, sw32 my,
65                                      i4_float &ox, i4_float &oy, i4_float &oz,
66                                      select_modifier mod)
67{
68  i4_spline_class::point *sp=c->find_spline_point(mx, my, 0);
69
70  if (sp)
71  {
72   
73    if ((sp->selected && mod==SUB_FROM_OLD) ||
74        (!sp->selected && (mod==ADD_TO_OLD || mod==CLEAR_OLD_IF_NO_SELECTION)))
75    {
76      g1_editor_instance.add_undo(G1_MAP_MOVIE);
77
78      if (mod == CLEAR_OLD_IF_NO_SELECTION)
79        c->clear_selected_points();
80      sp->selected = !sp->selected;
81
82      c->changed();
83      c->refresh();
84    }
85         
86    ox=sp->x;    oy=sp->y;    oz=sp->z;
87    return i4_T;
88  }
89  else if (mod == CLEAR_OLD_IF_NO_SELECTION)
90  {
91    g1_editor_instance.add_undo(G1_MAP_MOVIE);
92   
93    c->clear_selected_points();
94  }
95
96  return i4_F;
97}
98
99void g1_camera_mode::move_selected(i4_float xc, i4_float yc, i4_float zc,
100                                   sw32 mouse_x, sw32 mouse_y)
101{
102  if (g1_e_camera.get_minor_mode()==g1_camera_params::MOVE)
103    c->move_selected_points(xc,yc,zc);
104}
105
106void g1_camera_mode::post_draw(i4_draw_context_class &context)
107{
108  i4_spline_class *s[g1_controller_edit_class::MAX_SPLINE_EDIT];
109  int t=c->get_current_splines(s,g1_controller_edit_class::MAX_SPLINE_EDIT);
110
111  i4_color pas_colors[3]={0x7f0000, 0x007f00, 0x00007f };
112  i4_color act_colors[3]={0xff0000, 0x00ff00, 0x0000ff };
113                         
114
115  for (int i=0; i<t; i++)
116  {
117    w32 cf=c->get_map()->get_current_movie()->get_frame();
118   
119    c->draw_spline(c->local_image, &c->g1_context, 0xffffff,
120                   pas_colors[i], act_colors[i], s[i], cf);
121  }
122
123  g1_mode_handler::post_draw(context);
124}
125
126void g1_camera_mode::select_objects_in_area(sw32 x1, sw32 y1, sw32 x2, sw32 y2,
127                                            select_modifier add_modifier)
128{
129  if (!c->get_map()->current_movie)
130    return ;
131
132  g1_editor_instance.add_undo(G1_MAP_MOVIE);
133
134  if (!add_modifier)
135    c->clear_selected_points();
136
137  g1_movie_flow_class *flow=c->get_map()->current_movie;
138
139  i4_bool change=i4_F;
140
141  r1_vert rv;
142  i4_spline_class::point *first=0, *last=0;
143 
144  i4_spline_class *s[g1_controller_edit_class::MAX_SPLINE_EDIT];
145  int t=c->get_current_splines(s,g1_controller_edit_class::MAX_SPLINE_EDIT);
146
147
148  for (w32 i=0; i<t; i++)
149  {
150    i4_spline_class::point *sp=s[i]->begin();
151
152    for (;sp;sp=sp->next)
153    {
154      if (g1_render.project_point(i4_3d_point_class(sp->x, sp->y, sp->z),
155                           rv,
156                           c->g1_context.transform))
157      {
158        if (rv.px>=x1 && rv.py>=y1 && rv.px<=x2 && rv.py<=y2)
159        {
160          if (add_modifier==CLEAR_OLD_IF_NO_SELECTION || add_modifier==ADD_TO_OLD)
161          {
162            if (!sp->selected)
163            {
164              sp->selected=i4_T;
165              change=i4_T;
166            }
167          } else if (add_modifier==SUB_FROM_OLD)
168          {
169            sp->selected=i4_F;
170            change=i4_T;
171          }         
172        }
173      }     
174    }
175  }
176 
177  if (change)
178  {
179    c->refresh(); 
180    c->changed();
181  }
182}
183
184void g1_camera_mode::delete_selected()
185{
186  c->delete_selected_points();
187}
188
189
190
191g1_camera_params::g1_camera_params()
192{
193  edit_win=0;
194  minor_mode=MOVE;
195}
196
197
198
199void g1_camera_params::create_buttons(i4_parent_window_class *container)
200{
201  i4_button_box_class *box=new i4_button_box_class(&g1_edit_state);
202  char *rn[]={"cROTATE", "cZOOM",
203              "cADD_CAMERA", "cADD_TARGET", "cADD_OBJECT",
204              "cMODIFY", "cSELECT", 0};
205  w32 i=ROTATE;
206  for (char **a=rn; *a; a++, i++)
207    g1_edit_state.add_but(box, *a, 0, (i4_bool) i==minor_mode,
208                          new g1_set_minor_mode_event("CAMERA",i));
209
210  box->arrange_right_down();
211  container->add_child(0,0, box);
212}
213
214
215
216void g1_camera_params::cleanup()
217{
218  if (edit_win.get())
219  {
220    get_style()->close_mp_window(edit_win.get());
221    edit_win=0;
222  }
223}
224
225void g1_camera_params::set_edit_window(i4_parent_window_class *p, sw32 x, sw32 y)
226{
227  cleanup();
228  edit_win=get_style()->create_mp_window(x,y,
229                                   p->width(), p->height(),
230                                   g1_ges("edit_time"), 0);
231  edit_win->add_child(0,0,p);
232}
233
Note: See TracBrowser for help on using the repository browser.