source: abuse/trunk/src/devsel.cpp

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

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

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