source: golgotha/src/golg/editor/dialogs/scroll_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.2 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/e_state.hh"
10#include "gui/scroll_bar.hh"
11#include "editor/dialogs/scroll_picker.hh"
12#include "window/style.hh"
13#include "gui/button.hh"
14#include "tmanage.hh"
15#include "r1_api.hh"
16#include "tile.hh"
17#include "g1_render.hh"
18
19
20
21void g1_scroll_picker_class::create_windows()
22{
23  for (int i=0; i<windows.size(); i++)
24    delete render_windows[i];
25   
26  windows.clear();
27  render_windows.clear();
28
29  int y=start_y;
30  int obj_size=info->object_size;
31
32  int on=info->scroll_offset;
33
34  int tb=0;
35
36  int objs_per_line=info->max_object_size/obj_size;
37  int done=0;
38
39  while (y+obj_size<=height() && !done)
40  {
41    int x=0;
42    while (x+obj_size<=info->max_object_size && !done)
43    {
44
45      i4_window_class *w=create_window(obj_size, obj_size, on);
46      if (!w)
47        done=1;
48      else
49      {
50        r1_render_window_class *rwin;
51        rwin=g1_render.r_api->create_render_window(obj_size, obj_size, R1_COPY_1x1);
52
53        windows.add(w);
54        render_windows.add(rwin);
55
56        rwin->add_child(0,0, w);
57
58        add_child(x, y, rwin);
59        on++;
60        tb++;
61        x+=obj_size;     
62      }
63    }
64
65    y+=obj_size;
66  }
67
68  if (scroll_bar)
69    scroll_bar->set_new_total((total_objects()+objs_per_line-1)/objs_per_line); 
70}
71
72g1_scroll_picker_class::g1_scroll_picker_class(i4_graphical_style_class *style,
73                                               w32 option_flags,
74                                               g1_scroll_picker_info *info,
75                                               int total_objects)
76
77  : i4_color_window_class(0,0, style->color_hint->neutral(), style),
78    info(info),
79    windows(16,16),
80    render_windows(16,16)
81{
82  if (option_flags & (1<<ROTATE))
83    add_child(0,0, g1_edit_state.create_button("tp_rotate", ROTATE, i4_T, this));
84
85  if (option_flags & (1<<MIRROR))
86    add_child(0,0, g1_edit_state.create_button("tp_mirror", MIRROR, i4_T, this));
87
88  if (option_flags & (1<<GROW))
89    add_child(0,0, g1_edit_state.create_button("tp_grow",   GROW, i4_T,  this));
90
91  if (option_flags & (1<<SHRINK))
92    add_child(0,0, g1_edit_state.create_button("tp_shrink", SHRINK, i4_T, this));
93 
94  arrange_down_right();
95 
96  resize_to_fit_children();
97
98  int scroll_area_height=info->max_object_size * info->max_objects_down,
99    scroll_area_width=info->max_object_size;
100
101  start_y=height();
102  int tb=0;
103
104  if (option_flags & (1<<SCROLL))
105  {
106    scroll_bar = new i4_scroll_bar(i4_T, scroll_area_height,
107                                   scroll_area_height/info->object_size,
108                                   total_objects,
109                                   SCROLL, this, style);
110
111    scroll_area_width += scroll_bar->width();
112  }
113  else
114    scroll_bar = 0;
115 
116
117
118  resize(scroll_area_width > width() ? scroll_area_width : width(), 
119         scroll_area_height + height());
120
121  if (scroll_bar)
122    add_child(width()-scroll_bar->width(), start_y, scroll_bar);
123
124}
125
126void g1_scroll_picker_class::parent_draw(i4_draw_context_class &context)
127{
128  i4_color_window_class::parent_draw(context);
129
130  r1_texture_manager_class *tman=g1_render.r_api->get_tmanager();
131
132  tman->next_frame();
133}
134
135void g1_scroll_picker_class::receive_event(i4_event *ev)
136{
137  if (ev->type()==i4_event::USER_MESSAGE)
138  {   
139    CAST_PTR(sm, i4_scroll_message, ev);
140    if (sm->sub_type==SCROLL)
141    {
142      int obj_size=info->object_size;
143      int objs_per_line=info->max_object_size/obj_size;
144
145      int off=sm->amount * objs_per_line;
146
147      if (off>=total_objects())
148        off-=objs_per_line;
149
150      info->scroll_offset=off;
151
152      for (int i=0; i<windows.size(); i++)
153        change_window_object_num(windows[i], off+i);
154                                   
155    }
156  }
157  else if (ev->type()==i4_event::OBJECT_MESSAGE)
158  {
159    CAST_PTR(om, i4_object_message_event_class, ev);
160    switch (om->sub_type)
161    {
162      case GROW :
163      {
164        if (info->object_size*2<=info->max_object_size)
165        {
166          info->scroll_offset=0;
167          info->object_size*=2;
168          create_windows();
169        }
170      } break;
171
172      case SHRINK :
173      {
174        if (info->object_size/2>=info->min_object_size)
175        {
176          info->scroll_offset=0;
177          info->object_size/=2;
178          create_windows();
179        }
180
181      } break;
182
183      case MIRROR :
184      {
185        mirror();
186        refresh();
187      } break;
188
189      case ROTATE :
190      {
191        rotate();
192        refresh();
193      } break;
194    }
195   
196  }
197  else
198    i4_parent_window_class::receive_event(ev);
199}
200
201void g1_scroll_picker_class::refresh()
202{
203  for (int i=0; i<windows.size(); i++)
204    windows[i]->request_redraw(i4_F);
205}
Note: See TracBrowser for help on using the repository browser.