source: abuse/trunk/src/gui.cpp @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

File size: 3.6 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]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 or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
[481]13#include "cache.h"
14#include "gui.h"
15#include "dev.h"
16#include "loader2.h"
[2]17
18void ico_button::set_act_id(int id)
19{
20  activate_id=id;
21}
22
23ico_switch_button::ico_switch_button(int X, int Y, int ID, int start_on, ifield *butts, ifield *Next)
24{
25  x=X; y=Y; id=ID;
[124]26  next=Next;
[2]27  blist=cur_but=butts;
28  act=0;
[494]29  for (ifield *b=blist; b; b=b->next) { b->x=x; b->y=y; }
[2]30  while (cur_but && start_on--) cur_but=cur_but->next;
31  if (!cur_but) cur_but=blist;
32}
33
[106]34void ico_switch_button::area(int &x1, int &y1, int &x2, int &y2)
[2]35{
36  x1=10000;
37  y1=10000;
38  x2=-10000;
39  y2=-10000;
40  int X1,Y1,X2,Y2;
[494]41  for (ifield *b=blist; b; b=b->next)
[124]42  {
[106]43    b->area(X1,Y1,X2,Y2);
[2]44    if (X1<x1) x1=X1;
45    if (Y1<y1) y1=Y1;
46    if (X2>x2) x2=X2;
47    if (Y2>y2) y2=Y2;
48  }
49  if (!blist) { x1=x2=x; y1=y2=y; }
50}
51
52ifield *ico_switch_button::unlink(int id)
53{
54  ifield *last=NULL;
[494]55  for (ifield *b=blist; b; b=b->next)
[2]56  {
57    if (b->id==id)
58    {
59      if (last) last->next=b->next;
60      else blist=b->next;
61      if (cur_but==b) cur_but=blist;
62      return b;
[124]63    }
[2]64    ifield *x=b->unlink(id);
65    if (x) return x;
66    last=b;
67  }
68  return NULL;
69}
70
[120]71void ico_switch_button::handle_event(event &ev, image *screen, InputManager *im)
[2]72{
73  if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON &&
74                                         ev.mouse_button))
75  {
76    cur_but=cur_but->next;
77    if (!cur_but) cur_but=blist;
[106]78    cur_but->draw(act,screen);
79    cur_but->handle_event(ev,screen,im);
[2]80  }
81
82}
83
[106]84void ico_button::draw(int active, image *screen)
[2]85{
86  int x1,y1,x2,y2;
[124]87  area(x1,y1,x2,y2);
88
[2]89  if (active!=act  && activate_id!=-1 && active)
90    wm->push_event(new event(activate_id,NULL));
[124]91
[2]92  if (up && !active)
[123]93    cache.img(u)->put_image(screen,x1,y1);
[2]94  else if (up && active)
[123]95    cache.img(ua)->put_image(screen,x1,y1);
[2]96  else if (!up && !active)
[123]97    cache.img(d)->put_image(screen,x1,y1);
98  else cache.img(da)->put_image(screen,x1,y1);
[2]99
100  if (act!=active && active && activate_id!=-1)
101    wm->push_event(new event(activate_id,NULL));
102  act=active;
[124]103
[2]104  if (active && key[0])
105  {
106    int g=80;
107    screen->bar(0,0,144,20,0);
108    wm->font()->put_string(screen,0,0,symbol_str(key),color_table->lookup_color(g>>3,g>>3,g>>3));
109  } else if (!active && key[0])
110  {
111    screen->bar(0,0,144,20,0);
112  }
113
114}
115
116extern long S_BUTTON_PRESS_SND;
117extern int sfx_volume;
118
[120]119void ico_button::handle_event(event &ev, image *screen, InputManager *im)
[2]120{
121  if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON &&
122                                         ev.mouse_button))
123  {
124    int  x1,y1,x2,y2;
[106]125    area(x1,y1,x2,y2);
[2]126    up=!up;
[106]127    draw(act,screen);
[2]128    wm->push_event(new event(id,(char *)this));
129    if (S_BUTTON_PRESS_SND)
[123]130      cache.sfx(S_BUTTON_PRESS_SND)->play(sfx_volume);
[2]131  }
132}
133
[106]134void ico_button::area(int &x1, int &y1, int &x2, int &y2)
[2]135{
136  x1=x; y1=y;
[123]137  x2=x+cache.img(u)->width()-1;
138  y2=y+cache.img(u)->height()-1;
[2]139}
140
[39]141ico_button::ico_button(int X, int Y, int ID, int Up, int down, int upa, int downa, ifield *Next, int act_id, char const *help_key)
[2]142{
143  if (help_key)
144  {
145    strncpy(key,help_key,15);
146    key[15]=0;
147  }
148  else key[0]=0;
149
150  up=1;
151  x=X; y=Y; id=ID;
152  u=Up; d=down;
153  ua=upa; da=downa;
154  next=Next;
155  activate_id=act_id;
[67]156  act = 0;
[2]157}
158
159ico_switch_button::~ico_switch_button()
160{
161  while (blist)
162  {
163    ifield *i=blist;
164    blist=blist->next;
165    delete i;
166  }
167}
Note: See TracBrowser for help on using the repository browser.