[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 | |
---|
[2] | 11 | #ifndef _SCROLLER_HPP_ |
---|
| 12 | #define _SCROLLER_HPP_ |
---|
| 13 | |
---|
[481] | 14 | #include "input.h" |
---|
[2] | 15 | |
---|
| 16 | class scroller : public ifield |
---|
| 17 | { |
---|
| 18 | protected : |
---|
| 19 | int l,h,drag,vert,last_click; |
---|
| 20 | |
---|
| 21 | int bh(); |
---|
| 22 | int bw(); |
---|
| 23 | void drag_area(int &x1, int &y1, int &x2, int &y2); |
---|
| 24 | void dragger_area(int &x1, int &y1, int &x2, int &y2); |
---|
| 25 | int b1x() { if (vert) return x+l; else return x; } |
---|
| 26 | int b1y() { if (vert) return y; else return y+h; } |
---|
| 27 | int b2x() { if (vert) return x+l; else return x+l-bw(); } |
---|
| 28 | int b2y() { if (vert) return y+h-bh(); else return y+h; } |
---|
| 29 | unsigned char *b1(); |
---|
| 30 | unsigned char *b2(); |
---|
| 31 | void wig_area(int &x1, int &y1, int &x2, int &y2); |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | int wig_x(); |
---|
| 35 | int darea() { return (l-bw()-2)-bw()-bw(); } |
---|
[112] | 36 | void draw_widget(image *screen, int erase); |
---|
[2] | 37 | int mouse_to_drag(int mx,int my); |
---|
| 38 | public : |
---|
| 39 | int t,sx; |
---|
| 40 | scroller(int X, int Y, int ID, int L, int H, int Vert, int Total_items, ifield *Next); |
---|
[106] | 41 | virtual void area(int &x1, int &y1, int &x2, int &y2); |
---|
| 42 | virtual void draw_first(image *screen); |
---|
| 43 | virtual void draw(int active, image *screen); |
---|
[120] | 44 | virtual void handle_event(event &ev, image *screen, InputManager *im); |
---|
[2] | 45 | virtual char *read() { return (char *)&sx; } |
---|
| 46 | |
---|
| 47 | virtual int activate_on_mouse_move() { return 1; } |
---|
[494] | 48 | virtual void handle_inside_event(event &ev, image *screen, InputManager *inm) { ; } |
---|
[106] | 49 | virtual void scroll_event(int newx, image *screen); |
---|
[120] | 50 | virtual void handle_up(image *screen, InputManager *inm); |
---|
| 51 | virtual void handle_down(image *screen, InputManager *inm); |
---|
| 52 | virtual void handle_left(image *screen, InputManager *inm); |
---|
| 53 | virtual void handle_right(image *screen, InputManager *inm); |
---|
[106] | 54 | virtual void area_config() { ; } |
---|
[2] | 55 | void set_size(int width, int height) { l=width; h=height; } |
---|
[106] | 56 | virtual void set_x(int x, image *screen); |
---|
[2] | 57 | } ; |
---|
| 58 | |
---|
| 59 | class spicker : public scroller |
---|
| 60 | { |
---|
| 61 | protected : |
---|
| 62 | int r,c,m,last_sel,cur_sel; |
---|
[17] | 63 | uint8_t *select; |
---|
[2] | 64 | public : |
---|
| 65 | spicker(int X, int Y, int ID, int Rows, int Cols, int Vert, int MultiSelect, ifield *Next); |
---|
| 66 | int vis() { if (vert) return r; else return c; } |
---|
[106] | 67 | virtual void area_config(); |
---|
[2] | 68 | void set_select(int x, int on); |
---|
| 69 | int get_select(int x); |
---|
| 70 | int first_selected(); |
---|
[106] | 71 | virtual void scroll_event(int newx, image *screen); |
---|
[120] | 72 | virtual void handle_inside_event(event &ev, image *screen, InputManager *inm); |
---|
[2] | 73 | |
---|
| 74 | // you should define \/ |
---|
[106] | 75 | virtual void draw_background(image *screen); |
---|
| 76 | virtual void draw_item(image *screen, int x, int y, int num, int active) = 0; |
---|
[2] | 77 | virtual int total() = 0; |
---|
[106] | 78 | virtual int item_width() = 0; |
---|
| 79 | virtual int item_height() = 0; |
---|
[120] | 80 | virtual void note_selection(image *screen, InputManager *inm, int x) { ; } |
---|
| 81 | virtual void note_new_current(image *screen, InputManager *inm, int x) { ; } |
---|
[2] | 82 | virtual int ok_to_select(int num) { return 1; } |
---|
[120] | 83 | virtual void handle_up(image *screen, InputManager *inm); |
---|
| 84 | virtual void handle_down(image *screen, InputManager *inm); |
---|
| 85 | virtual void handle_left(image *screen, InputManager *inm); |
---|
| 86 | virtual void handle_right(image *screen, InputManager *inm); |
---|
[106] | 87 | virtual void set_x(int x, image *screen); |
---|
[2] | 88 | void reconfigure(); // should be called by constructor after class is ready to take virtual calls |
---|
[129] | 89 | ~spicker() { if (select) free(select); } |
---|
[124] | 90 | } ; |
---|
[2] | 91 | |
---|
| 92 | struct pick_list_item |
---|
| 93 | { |
---|
| 94 | char *name; |
---|
| 95 | int number; |
---|
| 96 | } ; |
---|
| 97 | |
---|
| 98 | class pick_list : public scroller |
---|
| 99 | { |
---|
| 100 | int last_sel,cur_sel,th,wid; |
---|
| 101 | pick_list_item *lis; |
---|
| 102 | char key_hist[20],key_hist_total; |
---|
| 103 | image *tex; |
---|
| 104 | public : |
---|
| 105 | pick_list(int X, int Y, int ID, int height, |
---|
[124] | 106 | char **List, int num_entries, int start_yoffset, ifield *Next, image *texture=NULL); |
---|
[120] | 107 | virtual void handle_inside_event(event &ev, image *screen, InputManager *inm); |
---|
[106] | 108 | virtual void scroll_event(int newx, image *screen); |
---|
[2] | 109 | virtual char *read() { return (char *)this; } |
---|
[106] | 110 | virtual void area_config(); |
---|
[120] | 111 | virtual void handle_up(image *screen, InputManager *inm); |
---|
| 112 | virtual void handle_down(image *screen, InputManager *inm); |
---|
[2] | 113 | int get_selection() { return lis[cur_sel].number; } |
---|
[129] | 114 | ~pick_list() { free(lis); } |
---|
[2] | 115 | } ; |
---|
| 116 | |
---|
| 117 | #endif |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | |
---|