source: abuse/branches/lol/src/devsel.cpp @ 732

Last change on this file since 732 was 732, checked in by Sam Hocevar, 8 years ago

build: SDL2 compilation fixes.

File size: 4.0 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2013 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "common.h"
16
17#include "imlib/scroller.h"
18
19#include "devsel.h"
20#include "cache.h"
21#include "game.h"
22
23void scale_put(AImage *im, AImage *screen, int x, int y, short new_width, short new_height);
24void scale_put_trans(AImage *im, AImage *screen, int x, int y, short new_width, short new_height);
25int cur_bg=0,cur_fg=0,cur_char=0;
26
27void ATilePicker::recenter(AImage *screen)
28{
29  set_x(get_current(), screen);
30}
31
32int ATilePicker::picw()
33{
34  switch (type)
35  {
36    case SPEC_FORETILE :
37    {
38      return cache.foret(foretiles[0])->im->Size().x/scale;
39    } break;
40    case SPEC_BACKTILE :
41    {
42      return cache.backt(backtiles[0])->im->Size().x/scale;
43    } break;
44    default :
45      return 30/scale;
46  }
47}
48
49int ATilePicker::pich()
50{
51  switch (type)
52  {
53    case SPEC_FORETILE :
54    {
55      return cache.foret(foretiles[0])->im->Size().y/scale;
56    } break;
57    case SPEC_BACKTILE :
58    {
59      return cache.backt(backtiles[0])->im->Size().y/scale;
60    } break;
61    default :
62      return 40/scale;
63  }
64}
65
66int ATilePicker::total()
67{
68  switch (type)
69  {
70    case SPEC_FORETILE :
71    { return nforetiles; } break;
72    case SPEC_BACKTILE :
73    { return nbacktiles; } break;
74    case SPEC_CHARACTER :
75    { return total_objects; } break;
76  }
77  return 1;
78}
79
80ATilePicker::ATilePicker(ivec2 pos, int id, int spec_type,
81             int Scale, int scroll_h, int Wid)
82  : AScroller(pos, id, ivec2(2, 2), 1, 0)
83{
84  wid=Wid;
85  type=spec_type;
86  th=scroll_h;
87  scale=Scale;
88  SetSize(ivec2(picw() * wid, pich() * th));
89  sx=get_current();
90  t=total();
91}
92
93
94void ATilePicker::scroll_event(int newx, AImage *screen)
95{
96  int ya = pich(), xw = picw(), c = get_current();
97  AImage im(ivec2(xw, ya));
98  last_sel=newx;
99
100  screen->Bar(m_pos, m_pos + m_size - ivec2(1, 1), wm->black());
101  for (int i=newx; i<newx+th*wid; i++)
102  {
103    ivec2 xyo = m_pos + ivec2(((i - newx) % wid) * xw, ((i - newx) / wid) * ya);
104
105      int blank=0;
106      if (i<t)
107      {
108    switch (type)
109    {
110      case SPEC_FORETILE :
111      {
112        if (foretiles[i]<0) blank=1;
113        else
114        {
115          im.clear();
116          the_game->get_fg(i)->im->PutImage(&im,ivec2(0,0));
117
118          if (rev)
119          {
120        screen->Bar(xyo, xyo + ivec2(xw - 1, ya - 1), wm->bright_color());
121        scale_put_trans(&im,screen,xyo.x,xyo.y,xw,ya);
122          }
123          else scale_put(&im,screen,xyo.x,xyo.y,xw,ya);
124        }
125      } break;
126      case SPEC_BACKTILE :
127      {
128        if (backtiles[i]<0) blank=1;
129        else
130          scale_put(the_game->get_bg(i)->im,screen,m_pos.x,m_pos.y,xw,ya);
131
132      } break;
133      case SPEC_CHARACTER :
134      {
135        figures[i]->get_sequence(stopped)->get_figure(0)->forward->PutImage(&im,ivec2(0,0));
136        scale_put(&im,screen,m_pos.x,m_pos.y,xw,ya);
137      } break;
138    }
139      } else blank=1;
140
141      if (i==c)
142        screen->Rectangle(m_pos, m_pos + ivec2(xw - 1, ya - 1),
143                          wm->bright_color());
144
145
146  }
147}
148
149
150void ATilePicker::handle_inside_event(Event &ev, AImage *screen, InputManager *inm)
151{
152  if (ev.type==EV_MOUSE_BUTTON)
153  {
154    int sel=((ev.mouse_move.y-m_pos.y)/pich()*wid)+(ev.mouse_move.x-m_pos.x)/picw()+last_sel;
155    if (sel<t && sel>=0 && sel!=get_current())
156    {
157      set_current(sel);
158      scroll_event(last_sel, screen);
159    }
160  }
161}
162
163
164
165
166int ATilePicker::get_current()
167{
168  switch (type)
169  {
170    case SPEC_FORETILE :
171    { return cur_fg; } break;
172    case SPEC_BACKTILE :
173    { return cur_bg; } break;
174    case SPEC_CHARACTER :
175    { return cur_char; } break;
176  }
177  return 0;
178}
179
180void ATilePicker::set_current(int x)
181{
182  switch (type)
183  {
184    case SPEC_FORETILE :
185    { cur_fg=x; } break;
186    case SPEC_BACKTILE :
187    { cur_bg=x; } break;
188    case SPEC_CHARACTER :
189    { cur_char=x; } break;
190  }
191}
192
193
194
195
196
Note: See TracBrowser for help on using the repository browser.