source: golgotha/src/golg/editor/dialogs/pick_win.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: 5.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 "editor/dialogs/pick_win.hh"
10#include "image/image.hh"
11#include "math/pi.hh"
12#include "math/transform.hh"
13#include "draw_context.hh"
14#include "image/image.hh"
15#include "image/color.hh"
16#include "window/win_evt.hh"
17#include "r1_api.hh"
18#include "tmanage.hh"
19#include "g1_render.hh"
20#include "r1_win.hh"
21#include "r1_clip.hh"
22#include "resources.hh"
23
24void g1_3d_pick_window::parent_draw(i4_draw_context_class &context)
25{   
26  i4_transform_class  tmp;
27  i4_transform_class  transform;
28
29  transform.identity();
30
31  tmp.translate(0,0,camera.view_dist);  transform.multiply(tmp);   
32
33  tmp.rotate_y(camera.theta);           transform.multiply(tmp);
34  tmp.rotate_x(i4_pi()-camera.phi);   transform.multiply(tmp);
35
36
37  tmp.translate(-camera.center_x,
38                -camera.center_y,
39                -camera.center_z);     
40  transform.multiply(tmp);
41
42
43
44
45  //  context.add_both_dirty(0,0,local_image->width()-1,local_image->height()-1);
46
47  g1_draw_context_class gc;
48  gc.window_setup(0,0, width(), height(),
49                  g1_render.center_x, g1_render.center_y,
50                  g1_render.scale_x, g1_render.scale_y,
51                  g1_render.ooscale_x, g1_render.ooscale_y);
52
53  r1_render_api_class *render_api=g1_render.r_api;
54
55
56  render_api->default_state();
57
58  render_api->set_shading_mode(R1_SHADE_DISABLED);
59
60  render_api->clear_area(0,0, width()-1, height()-1,
61                         active ? 0xffffff : 0x9f9f9f, r1_far_clip_z);
62
63
64  gc.transform=&transform;
65  gc.screen=local_image;
66  gc.context=&context;
67  gc.draw_editor_stuff=i4_T;
68  g1_render.frame_ratio=1;
69 
70  r1_far_clip_z=5000;
71
72
73  if (active && !camera.stopped)
74  {
75    i4_time_class now;
76    camera.zrot+=now.milli_diff(start)/2000.0;
77    start.get();
78
79   
80    i4_float d=fabs(cos(camera.zrot)*4)-i4_pi();
81    camera.theta=d;
82
83    if (camera.theta>2*i4_pi())
84      camera.theta-=2*i4_pi();
85    if (camera.theta<0)
86      camera.theta+=2*i4_pi();
87  }
88  else
89    start.get();
90
91
92  r1_far_clip_z=5000;
93       
94  render_api->disable_texture();
95  render_api->clear_area(0,0,width()-1,height()-1,0,r1_far_clip_z);   
96
97  draw_object(&gc);
98
99  r1_texture_manager_class *tman=render_api->get_tmanager();
100
101}
102
103
104void g1_3d_pick_window::receive_event(i4_event *ev)
105{
106  if (ev->type()==i4_event::MOUSE_BUTTON_DOWN)
107  {
108    request_redraw(i4_T);
109
110    do_press();
111    i4_kernel.send(reaction);
112    camera.stopped=i4_T;
113
114    CAST_PTR(mev, i4_mouse_button_down_event_class, ev);
115    if (!grabr && mev->but==i4_mouse_button_down_event_class::RIGHT)
116    {
117      grabr=i4_T;
118
119      if (!grabl)
120      {
121        i4_window_request_mouse_grab_class grab(this);
122        i4_kernel.send_event(parent, &grab);
123      }
124    }
125    else if (!grabl && mev->but==i4_mouse_button_down_event_class::LEFT)
126    {
127      grabl=i4_T;
128
129      if (!grabr)
130      {
131        i4_window_request_mouse_grab_class grab(this);
132        i4_kernel.send_event(parent, &grab);
133      }
134      do_press();
135
136    }
137
138  }
139  else if (ev->type()==i4_event::MOUSE_BUTTON_UP)
140  {
141    CAST_PTR(mev, i4_mouse_button_up_event_class, ev);
142    if (grabr && mev->but==i4_mouse_button_up_event_class::RIGHT)
143    {
144      grabr=i4_F;
145
146      if (!grabl)
147      {
148        i4_window_request_mouse_ungrab_class ungrab(this);
149        i4_kernel.send_event(parent, &ungrab);
150      }
151    }
152    else if (grabl && mev->but==i4_mouse_button_up_event_class::LEFT)
153    {
154      grabl=i4_F;
155
156      if (!grabr)
157      {
158        i4_window_request_mouse_ungrab_class ungrab(this);
159        i4_kernel.send_event(parent, &ungrab);
160      }
161
162    }
163   
164  } else if (ev->type()==i4_event::MOUSE_MOVE)
165  {
166    CAST_PTR(mev, i4_mouse_move_event_class, ev);
167    if (grabl)
168    {
169      camera.theta -= 0.01*(mev->x - last_mx);
170      camera.phi -= 0.01*(mev->y - last_my);
171
172      if (camera.theta<0.0)
173        camera.theta += i4_pi()*2;
174      else if (camera.theta>i4_pi()*2)
175        camera.theta -= i4_pi()*2;
176
177      if (camera.phi<0.0)
178        camera.phi = 0.0;
179      else if (camera.phi>i4_pi())
180        camera.phi = i4_pi();
181
182      request_redraw(i4_F);
183    }
184    if (grabr)
185    {
186      camera.view_dist += (mev->y - last_my)*0.1;
187      request_redraw(i4_F);
188    }
189
190    last_mx=mev->x;
191    last_my=mev->y;
192  }
193  else if (ev->type()==i4_event::KEY_PRESS)
194  {
195    CAST_PTR(kev, i4_key_press_event_class, ev);
196    if (kev->key=='x')
197      camera.theta+=0.2;
198    else if (kev->key=='X')
199      camera.theta-=0.2;
200    if (kev->key=='y')
201      camera.phi+=0.2;
202    else if (kev->key=='Y')
203      camera.phi-=0.2;   
204  }
205
206  i4_menu_item_class::receive_event(ev);
207}
Note: See TracBrowser for help on using the repository browser.