source: golgotha/src/golg/editor/mode/e_mode.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 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.9 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_mode.hh"
10#include "editor/contedit.hh"
11#include "window/wmanager.hh"
12#include "window/win_evt.hh"
13#include "device/kernel.hh"
14#include "window/style.hh"
15#include "g1_render.hh"
16#include "g1_limits.hh"
17#include "r1_api.hh"
18#include "app/app.hh"
19#include "resources.hh"
20#include "editor/e_state.hh"
21#include "editor/editor.hh"
22#include "lisp/lisp.hh"
23#include "lisp/li_init.hh"
24
25sw32 g1_mode_handler::lx() { return c->last_mouse_x; }
26sw32 g1_mode_handler::ly() { return c->last_mouse_y; }
27
28sw32 g1_mode_handler::x() { return c->x(); }
29sw32 g1_mode_handler::y() { return c->y(); }
30
31
32g1_mode_creator *g1_mode_creator::first=0;
33
34void g1_mode_handler::uninit()
35{
36}
37
38i4_bool g1_mode_handler::active()
39{
40  return c->active();
41}
42
43g1_mode_creator::g1_mode_creator()
44{
45  minor_mode=0;
46  next=first;
47  first=this;
48}
49
50g1_mode_creator::~g1_mode_creator()
51{
52  if (first==this)
53    first=first->next;
54  else
55  {
56    g1_mode_creator *last=0;
57    for (g1_mode_creator *f=first; f!=this;)
58    {
59      last=f;
60      f=f->next;
61    }
62    last->next=next;
63  }
64}
65
66
67i4_graphical_style_class *g1_mode_creator::get_style()
68{
69  return i4_current_app->get_style();
70}
71
72i4_transform_class *g1_mode_handler::get_transform()
73{
74  return &c->transform;
75}
76
77g1_mode_handler::g1_mode_handler(g1_controller_edit_class *c)
78  : c(c)
79{
80  mouse_down_flag=i4_F;
81 
82  drag=i4_F;
83  drag_select=i4_F;
84  cursor_type=G1_DEFAULT_CURSOR;
85}
86
87void g1_mode_handler::update_cursor()
88{
89  float x,y,z;
90  w8 nc=G1_DEFAULT_CURSOR;
91 
92 
93
94  if (g1_map_is_loaded() && current_state()==DRAG_SELECT)
95  {
96    if (drag)
97      nc=G1_MOVE_CURSOR;
98    else if (select_object(lx(), ly(), x,y,z, FOR_CURSOR_HINT))
99      nc=G1_SELECT_CURSOR;
100  }
101
102  if (nc!=cursor_type)
103  {
104    cursor_type=nc;
105    c->set_cursor(g1_resources.big_cursors[cursor_type]);
106  }
107}
108
109
110void g1_mode_handler::mouse_move(sw32 mx, sw32 my)
111{
112  switch (current_state())
113  {
114    case DRAG_SELECT :
115    {
116      if (drag)   // are we dragging game stuff around?
117      {
118        i4_transform_class *t=&c->transform;
119
120        i4_3d_point_class control_point;   
121
122        t->transform(pos, control_point);
123
124        i4_3d_vector is(1,0,0), js(0,1,0), center, i,j;
125        t->inverse_transform(i4_3d_vector(0,0,0), center);
126        t->inverse_transform(is, i);
127        i-=center;
128        t->inverse_transform(js, j);
129        j-=center;
130
131        // i & j now for the camera plane
132
133        i4_float csx=g1_render.scale_x;
134        i4_float csy=g1_render.scale_y;
135
136
137
138        i4_float sx=(mx-lx())/(csx*g1_render.center_x) * control_point.z;
139        i4_float sy=(my-ly())/(csy*g1_render.center_y) * control_point.z;
140   
141
142        i*=sx;
143        j*=sy;
144   
145        i4_float xc=i.x+j.x, yc=i.y+j.y, zc=i.z+j.z;
146
147        pos.x+=xc; pos.y+=yc; pos.z+=zc;
148        i4_3d_point_class current_snap_pos=pos;
149        g1_edit_state.snap_point(current_snap_pos);
150
151        move_selected(current_snap_pos.x-snap_pos.x,
152                      current_snap_pos.y-snap_pos.y,
153                      current_snap_pos.z-snap_pos.z,
154                      mx-lx(), my-ly());   
155
156        snap_pos=current_snap_pos;
157      }
158      else if (mouse_down_flag && drag_select)
159      {
160        sx2=mx;
161        sy2=my;
162        c->request_redraw();
163      }
164    } break;
165   
166    case ZOOM :
167      if (mouse_down_flag)
168        if (i4_current_app->get_window_manager()->shift_pressed())
169          c->rotate((mx-lx())*0.01, (ly()-my)*0.01);
170        else
171          c->zoom((ly()-my)/50.0);
172     
173      break;
174     
175    case ROTATE :
176      if (mouse_down_flag)
177        if (i4_current_app->get_window_manager()->shift_pressed())
178          c->zoom((ly()-my)/50.0);
179        else
180          c->rotate((mx-lx())*0.01, (ly()-my)*0.01);
181          break;
182  }
183}
184
185void g1_mode_handler::mouse_up()
186{
187  if (mouse_down_flag)
188  {
189    ungrab_mouse();
190
191    if (drag)
192    {
193      update_cursor();
194      drag=i4_F;
195    }
196    else if (current_state()==DRAG_SELECT && drag_select)
197    {
198      sw32 dx1,dy1,dx2,dy2;
199      if (sx1<sx2) { dx1=sx1; dx2=sx2; } else { dx1=sx2; dx2=sx1; }
200      if (sy1<sy2) { dy1=sy1; dy2=sy2; } else { dy1=sy2; dy2=sy1; }
201
202      select_modifier mod;
203      if (i4_current_app->get_window_manager()->shift_pressed())
204        mod=ADD_TO_OLD;
205      else if (i4_current_app->get_window_manager()->alt_pressed())
206        mod=SUB_FROM_OLD;
207      else
208        mod=CLEAR_OLD_IF_NO_SELECTION;
209
210      select_objects_in_area(dx1,dy1,dx2,dy2, mod);
211      c->request_redraw();
212      drag_select=i4_F;
213      update_cursor();
214    }
215
216  }
217}
218
219void g1_mode_handler::grab_mouse()
220{
221  mouse_down_flag=i4_T;
222}
223
224void g1_mode_handler::ungrab_mouse()
225{
226  mouse_down_flag=i4_F;
227}
228
229void g1_mode_handler::do_command(i4_do_command_event_class *cmd)
230{
231  if (!strcmp(cmd->command, "edit_selected"))
232    edit_selected(); 
233}
234
235void g1_mode_handler::end_command(i4_end_command_event_class *cmd)
236{
237 
238}
239
240
241void g1_mode_handler::mouse_down()
242{
243  grab_mouse();
244
245  if (current_state()==DRAG_SELECT)
246  {
247    select_modifier mod;
248    if (i4_current_app->get_window_manager()->shift_pressed())
249      mod=ADD_TO_OLD;
250    else if (i4_current_app->get_window_manager()->alt_pressed())
251      mod=SUB_FROM_OLD;
252    else
253      mod=CLEAR_OLD_IF_NO_SELECTION;
254
255
256    if (select_object(lx(), ly(), pos.x, pos.y, pos.z, mod))
257    {
258      snap_pos=pos;
259      i4_time_class now;
260      if (now.milli_diff(last_click_time)<c->style->time_hint->double_click)
261        edit_selected();
262      else
263        drag=i4_T;
264    }
265    else
266    {
267      drag_select=i4_T;
268      sx2=sx1=lx();
269      sy2=sy1=ly();
270    }
271
272    update_cursor();
273  }
274
275  last_click_time.get();
276}
277
278void g1_mode_handler::post_draw(i4_draw_context_class &context)
279{
280  if (current_state()==DRAG_SELECT && mouse_down_flag && !drag)
281    g1_render.draw_rectangle(sx1,sy1,sx2,sy2, 0xffffff, context);
282}
283
284i4_bool g1_mode_handler::pass_through_focus_click()
285{
286  switch (current_state())
287  {
288    case ZOOM :
289    case ROTATE : return i4_T; break;
290  }
291  return i4_F;
292}
293
294
295li_object *g1_delete_selected(li_object *o, li_environment *env)
296{
297  g1_controller_edit_class *v=g1_editor_instance.get_current_view();
298  if (v)
299  {
300    v->get_mode()->delete_selected();
301    return li_true_sym;
302  }
303 
304  return 0;
305}
306
307li_automatic_add_function(g1_delete_selected, "Map/Delete Selected");
Note: See TracBrowser for help on using the repository browser.