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