source: abuse/tags/pd/macabuse/src/devsel.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1#include "devsel.hpp"
2#include "scroller.hpp"
3#include "cache.hpp"
4#include "game.hpp"
5
6void scale_put(image *im, image *screen, int x, int y, short new_width, short new_height);
7void scale_put_trans(image *im, image *screen, int x, int y, short new_width, short new_height);
8int cur_bg=0,cur_fg=0,cur_char=0;
9
10void tile_picker::recenter(image *screen, window_manager *wm)
11{
12  set_x(get_current(),screen,wm);
13}
14
15int tile_picker::picw()
16{
17  switch (type)
18  {
19    case SPEC_FORETILE :
20    {
21      return cash.foret(foretiles[0])->im->width()/scale;
22    } break;
23    case SPEC_BACKTILE :
24    {
25      return cash.backt(backtiles[0])->im->width()/scale;
26    } break;
27    default :
28      return 30/scale;
29  }
30}
31
32int tile_picker::pich()
33{
34  switch (type)
35  {
36    case SPEC_FORETILE :
37    {
38      return cash.foret(foretiles[0])->im->height()/scale;
39    } break;
40    case SPEC_BACKTILE :
41    {
42      return cash.backt(backtiles[0])->im->height()/scale;
43    } break;
44    default :
45      return 40/scale;
46  }
47}
48
49int tile_picker::total()
50{
51  switch (type)
52  {
53    case SPEC_FORETILE :
54    { return nforetiles; } break;
55    case SPEC_BACKTILE :
56    { return nbacktiles; } break;   
57    case SPEC_CHARACTER :
58    { return total_objects; } break;   
59  }
60  return 1;
61}
62
63tile_picker::tile_picker(int X, int Y, int ID, int spec_type, window_manager *wm,
64                         int Scale, int scroll_h, int Wid, ifield *Next)
65     : scroller(X,Y,ID,2,2,1,0,Next)
66{
67  wid=Wid;
68  type=spec_type;
69  th=scroll_h;
70  scale=Scale;
71  set_size(picw()*wid,pich()*th);
72  sx=get_current();
73  t=total();
74}
75
76
77void tile_picker::scroll_event(int newx, image *screen, window_manager *wm)
78{
79  int yo=y,ya=pich(),xw=picw(),c=get_current(),xo;
80  image im(xw,ya);
81  last_sel=newx;
82  int pi=newx;
83  screen->bar(x,y,x+l-1,y+h-1,eh->black());
84  for (int i=newx;i<newx+th*wid;i++)
85  {
86    xo=x+((i-newx)%wid)*xw;
87    yo=y+((i-newx)/wid)*ya;
88
89      int blank=0;
90      if (i<t)
91      {
92        switch (type)
93        {
94          case SPEC_FORETILE :
95          {
96            if (foretiles[i]<0) blank=1;
97            else
98            {
99              im.clear();
100              the_game->get_fg(i)->im->put_image(&im,0,0);
101
102              if (rev)
103              {
104                screen->bar(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color());
105                scale_put_trans(&im,screen,xo,yo,xw,ya);
106              }
107              else scale_put(&im,screen,xo,yo,xw,ya);
108            }
109          } break;
110          case SPEC_BACKTILE :
111          {
112            if (backtiles[i]<0) blank=1;
113            else
114              scale_put(the_game->get_bg(i)->im,screen,xo,yo,xw,ya);
115           
116          } break;
117          case SPEC_CHARACTER :
118          {
119            figures[i]->get_sequence(stopped)->get_figure(0)->forward->put_image(&im,0,0);
120            scale_put(&im,screen,xo,yo,xw,ya);
121          } break;
122        }
123      } else blank=1;
124
125      if (i==c)
126        screen->rectangle(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color());
127
128
129  }
130}
131
132
133void tile_picker::handle_inside_event(event &ev, image *screen, window_manager *wm, input_manager *inm)
134{
135  if (ev.type==EV_MOUSE_BUTTON)
136  {
137    int sel=((ev.mouse_move.y-y)/pich()*wid)+(ev.mouse_move.x-x)/picw()+last_sel;
138    if (sel<t && sel>=0 && sel!=get_current())
139    {
140      set_current(sel);
141      scroll_event(last_sel,screen,wm);
142    }
143  }
144}
145
146
147
148
149int tile_picker::get_current()
150{
151  switch (type)
152  {
153    case SPEC_FORETILE :
154    {return cur_fg;} break;
155    case SPEC_BACKTILE :
156    {return cur_bg;} break;
157    case SPEC_CHARACTER :
158    {return cur_char;} break;
159  }
160  return 0;
161}
162
163void tile_picker::set_current(int x)
164{
165  switch (type)
166  {
167    case SPEC_FORETILE :
168    {cur_fg=x;} break;
169    case SPEC_BACKTILE :
170    {cur_bg=x;} break;
171    case SPEC_CHARACTER :
172    {cur_char=x;} break;
173  }
174}
175
176
177
178
179
Note: See TracBrowser for help on using the repository browser.