source: golgotha/src/golg/editor/dialogs/sky_picker.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: 5.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/editor.hh"
10#include "gui/create_dialog.hh"
11#include "gui/text_input.hh"
12#include "window/colorwin.hh"
13#include "sky.hh"
14#include "r1_api.hh"
15#include "g1_render.hh"
16#include "window/win_evt.hh"
17#include "app/app.hh"
18#include "r1_win.hh"
19#include "gui/scroll_bar.hh"
20#include "tmanage.hh"
21#include "editor/editor.hh"
22#include "lisp/lisp.hh"
23#include "string/string.hh"
24
25static int  sky_scroll_offset=0;
26
27class g1_sky_view : public i4_window_class
28{
29  int offset;
30  i4_bool active;
31public:
32  g1_sky_view(w16 w, w16 h, int offset)
33    : i4_window_class(w,h),
34      offset(offset)
35  {
36    active=i4_F;
37   
38  }
39
40  int off() { return offset+sky_scroll_offset;}
41
42  void setup_vert(float x, float y, r1_vert &v)
43  {
44    v.px=x*(width());  v.py=y*(height());  v.v.z=50;  v.w=1.0/v.v.z;
45    v.s=x; v.t=y;
46    v.r=v.g=v.b=1.0;
47    v.a=1;                                               
48  }
49
50  void draw(i4_draw_context_class &context)
51  {
52    i4_bool valid=i4_F;
53
54    if (off()>=0 && off()<g1_sky_list.size())
55      valid=i4_T;
56
57    r1_render_api_class *api=g1_render.r_api;
58
59    r1_texture_handle han;
60    if (valid)
61    {
62      char tname[256], tname1[256];
63      i4_os_string(*g1_sky_list[off()], tname, 256);
64      sprintf(tname1, "%s1", tname);
65     
66      i4_bool loaded;
67      han=api->get_tmanager()->register_texture(tname1, "sky texture not found", &loaded);
68      if (!loaded)
69        han=api->get_tmanager()->register_texture(tname, "sky texture not found");
70       
71
72    }
73    else
74      han=0;
75
76
77
78    api->default_state();
79    api->set_shading_mode(R1_WHITE_SHADING);
80
81    if (active)
82      api->set_constant_color(0xffffff);
83    else               
84      api->set_constant_color(0x9f9f9f);
85
86    if (han)     
87      api->use_texture(han, width(), 0);
88
89    r1_vert v[3];
90    setup_vert(0,0, v[0]);  setup_vert(0,1, v[1]);  setup_vert(1,1, v[2]);
91    api->render_poly(3, v);
92
93    setup_vert(0,0, v[0]);  setup_vert(1,1, v[1]);  setup_vert(1,0, v[2]);
94    api->render_poly(3, v);
95
96  }
97
98  void receive_event(i4_event *ev)
99  {
100    if (ev->type()==i4_event::WINDOW_MESSAGE)
101    {
102      CAST_PTR(wev, i4_window_message_class, ev);
103      if (wev->sub_type==i4_window_message_class::GOT_MOUSE_FOCUS)
104      {
105        active=i4_T;
106        request_redraw(i4_F);
107      }
108      else if (wev->sub_type==i4_window_message_class::LOST_MOUSE_FOCUS)
109      {
110        active=i4_F;
111        request_redraw(i4_F);
112      }
113    }
114    else if (ev->type()==i4_event::MOUSE_BUTTON_DOWN)
115    {
116      CAST_PTR(bev, i4_mouse_button_down_event_class, ev);
117
118      if (bev->left() && off()>=0 && off()<g1_sky_list.size())
119      {
120        g1_editor_instance.add_undo(G1_MAP_SKY);
121       
122        if (g1_get_map()->sky_name)
123          delete g1_get_map()->sky_name;
124
125        g1_get_map()->sky_name=new i4_str(*g1_sky_list[off()]);
126
127        li_call("redraw");
128      }
129
130
131    }
132   
133
134  }
135
136
137  char *name() { return "sky_view"; }
138};
139
140class g1_sky_picker_class : public i4_color_window_class
141{
142  i4_graphical_style_class *style;
143    i4_array<r1_render_window_class *> render_windows;
144
145
146public:
147  g1_sky_picker_class(i4_graphical_style_class *style)
148    : i4_color_window_class(0,0, style->color_hint->neutral(), style),
149      render_windows(0,32)
150  {
151    int t_vis=5, t_obj=g1_sky_list.size(), obj_w=64, obj_h=64, i,x=0, y=0, x1=0;
152   
153    for (i=0; i<t_vis; i++)
154    {
155      render_windows.add(g1_render.r_api->create_render_window(obj_w, obj_h, R1_COPY_1x1));
156      render_windows[i]->add_child(0,0, new g1_sky_view(obj_w, obj_h, i));     
157      add_child(x1,y, render_windows[i]);
158      x1+=render_windows[i]->width();
159    }
160    y+=obj_h;
161   
162    i4_scroll_bar *sb=new i4_scroll_bar(i4_F, t_vis * obj_w, t_vis, t_obj, 0, this, style);
163    add_child(x,y, sb);
164
165    resize_to_fit_children();
166  }
167
168  void receive_event(i4_event *ev)
169  {
170    i4_color_window_class::receive_event(ev);
171    if (ev->type()==i4_event::USER_MESSAGE)
172    {
173      CAST_PTR(sev, i4_scroll_message, ev);
174      sky_scroll_offset=sev->amount;
175      for (int i=0; i<render_windows.size(); i++)
176        render_windows[i]->request_redraw(i4_F);
177    }
178  }
179
180  char *name() { return "sky picker"; }
181};
182
183
184
185void g1_editor_class::create_sky_window()
186{
187  if (get_map())
188  {
189    sky_scroll_offset=0;
190    g1_sky_picker_class *sp=new g1_sky_picker_class(i4_current_app->get_style());
191
192    create_modal(sp->width(), sp->height(), "set_sky_title");
193    modal_window.get()->add_child(0,0,sp);
194  }
195}
196
197void g1_editor_class::set_sky()
198
199//   i4_os_string(*sky_dialog.name->get_edit_string(),
200//                get_map()->sky_name,
201//                sizeof(get_map()->sky_name));
202
203//   char *name=get_map()->sky_name;
204//   get_map()->sky_model=g1_model_list_man.get_model(g1_model_list_man.find_handle(name));
205//   close_modal();
206}
Note: See TracBrowser for help on using the repository browser.