source: golgotha/src/golg/editor/mode/e_light.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: 4.6 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_light.hh"
10#include "editor/e_state.hh"
11#include "error/error.hh"
12#include "gui/butbox.hh"
13#include "editor/contedit.hh"
14#include "light.hh"
15#include "map_light.hh"
16#include "cwin_man.hh"
17#include "editor/editor.hh"
18#include "lisp/lisp.hh"
19
20g1_light_params g1_e_light;
21
22g1_mode_handler::state g1_light_mode::current_state()
23{
24  w8 remap[]={ ROTATE, ZOOM, DRAG_SELECT, DRAG_SELECT, OTHER, OTHER };
25  I4_ASSERT(g1_e_light.minor_mode<=sizeof(remap), "state too big");
26  return (g1_mode_handler::state)remap[g1_e_light.get_minor_mode()];
27}
28
29void g1_light_params::create_buttons(i4_parent_window_class *container)
30{
31  i4_button_box_class *box=new i4_button_box_class(&g1_edit_state);
32  char *rn[]={"lROTATE", "lZOOM", 0 }, **a;
33  w32 i=ROTATE;
34
35  for (a=rn; *a; i++, a++)
36    g1_edit_state.add_but(box, *a, 0, (i4_bool) i==minor_mode,
37                          new g1_set_minor_mode_event("LIGHT",i));
38
39  box->arrange_right_down();
40  box->resize_to_fit_children();
41
42
43  container->add_child(0,0,box);
44
45
46  char *indiv_buts[]={"lGDARKEN", "lGBRIGHTEN", "lDDARKEN", "lDBRIGHTEN", "lAMBIENT", 0};
47  int but_ids[]={ GDARKEN, GBRIGHTEN, DDARKEN, DBRIGHTEN, AMBIENT };
48  int rep_ids[]={ GDARKEN_REP, GBRIGHTEN_REP, DDARKEN_REP, DBRIGHTEN_REP, 0 };
49
50
51  int y=box->height()+5;
52
53 
54  for (i=0, a=indiv_buts; *a; i++, a++)
55  {
56    i4_button_class *b=g1_edit_state.create_button(*a, but_ids[i], i4_T, this);
57    if (rep_ids[i])
58      b->set_repeat_down(i4_T, new i4_event_reaction_class(this, rep_ids[i]));
59
60    container->add_child(0, y, b);
61    y+=b->height();
62  }
63}
64
65
66void g1_light_params::receive_event(i4_event *ev)
67{
68  int sub_type=-1;
69  if (ev->type()==i4_event::OBJECT_MESSAGE)
70  {
71    CAST_PTR(oev,i4_object_message_event_class,ev);
72    if (oev->object==this)
73      sub_type=oev->sub_type;
74  }
75  else if (ev->type()==i4_event::USER_MESSAGE)
76    sub_type=((i4_user_message_event_class *)ev)->sub_type;
77
78  if (sub_type!=-1)
79  {
80    int recalc=0;
81    float increment=1/32.0;
82
83    switch (sub_type)
84    {
85      case GDARKEN :
86        li_call("add_undo", li_make_list(new li_int(G1_MAP_VERTS | G1_MAP_LIGHTS), 0));
87       
88      case GDARKEN_REP :
89      {
90        if (g1_lights.ambient_intensity - increment>=0)
91        {
92          recalc=1;
93          g1_lights.set_ambient_intensity(g1_lights.ambient_intensity-increment);
94        }
95      } break;
96
97      case GBRIGHTEN :
98        li_call("add_undo", li_make_list(new li_int(G1_MAP_VERTS | G1_MAP_LIGHTS), 0));
99
100      case GBRIGHTEN_REP :
101      {
102        if (g1_lights.ambient_intensity+increment <= 1.0)
103        {
104          recalc=1;
105          g1_lights.set_ambient_intensity(g1_lights.ambient_intensity+increment);
106        }
107      } break;
108
109      case DDARKEN :
110        li_call("add_undo", li_make_list(new li_int(G1_MAP_VERTS | G1_MAP_LIGHTS), 0));
111
112      case DDARKEN_REP :
113      {
114        if (g1_lights.directional_intensity - increment>=0)
115        {
116          recalc=1;
117          g1_lights.set_directional_intensity(g1_lights.directional_intensity-increment);
118        }
119      } break;
120
121      case DBRIGHTEN :
122        li_call("add_undo", li_make_list(new li_int(G1_MAP_VERTS | G1_MAP_LIGHTS), 0));
123      case DBRIGHTEN_REP :
124      {
125        if (g1_lights.directional_intensity+increment <= 1.0)
126        {
127          recalc=1;
128          g1_lights.set_directional_intensity(g1_lights.directional_intensity+increment);
129        }
130      } break;
131
132     
133      case AMBIENT :
134      {
135        if (g1_current_controller.get())
136        {
137          recalc=1;
138          li_call("add_undo", li_make_list(new li_int(G1_MAP_VERTS | G1_MAP_LIGHTS), 0));
139
140          i4_transform_class *t=&g1_current_controller->transform;
141          i4_3d_vector cam1, cam2;
142          t->inverse_transform(i4_3d_vector(0,0,0), cam1);
143          t->inverse_transform(i4_3d_vector(0,0,1), cam2);
144          cam2-=cam1;
145
146          g1_lights.direction=cam2;
147        }
148      } break;
149
150    }
151   
152    if (recalc)
153    {
154      g1_calc_static_lighting();
155      g1_editor_instance.changed();
156
157      li_call("redraw");
158    }
159  }
160}
161
Note: See TracBrowser for help on using the repository browser.