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