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 | #ifndef _SCROLLER_HPP_ |
---|
12 | #define _SCROLLER_HPP_ |
---|
13 | |
---|
14 | #include "input.h" |
---|
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(); } |
---|
36 | void draw_widget(image *screen, int erase); |
---|
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); |
---|
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); |
---|
44 | virtual void handle_event(event &ev, image *screen, InputManager *im); |
---|
45 | virtual char *read() { return (char *)&sx; } |
---|
46 | |
---|
47 | virtual int activate_on_mouse_move() { return 1; } |
---|
48 | virtual void handle_inside_event(event &ev, image *screen, InputManager *inm) { ; } |
---|
49 | virtual void scroll_event(int newx, image *screen); |
---|
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); |
---|
54 | virtual void area_config() { ; } |
---|
55 | void set_size(int width, int height) { l=width; h=height; } |
---|
56 | virtual void set_x(int x, image *screen); |
---|
57 | } ; |
---|
58 | |
---|
59 | class spicker : public scroller |
---|
60 | { |
---|
61 | protected : |
---|
62 | int r,c,m,last_sel,cur_sel; |
---|
63 | uint8_t *select; |
---|
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; } |
---|
67 | virtual void area_config(); |
---|
68 | void set_select(int x, int on); |
---|
69 | int get_select(int x); |
---|
70 | int first_selected(); |
---|
71 | virtual void scroll_event(int newx, image *screen); |
---|
72 | virtual void handle_inside_event(event &ev, image *screen, InputManager *inm); |
---|
73 | |
---|
74 | // you should define \/ |
---|
75 | virtual void draw_background(image *screen); |
---|
76 | virtual void draw_item(image *screen, int x, int y, int num, int active) = 0; |
---|
77 | virtual int total() = 0; |
---|
78 | virtual int item_width() = 0; |
---|
79 | virtual int item_height() = 0; |
---|
80 | virtual void note_selection(image *screen, InputManager *inm, int x) { ; } |
---|
81 | virtual void note_new_current(image *screen, InputManager *inm, int x) { ; } |
---|
82 | virtual int ok_to_select(int num) { return 1; } |
---|
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); |
---|
87 | virtual void set_x(int x, image *screen); |
---|
88 | void reconfigure(); // should be called by constructor after class is ready to take virtual calls |
---|
89 | ~spicker() { if (select) free(select); } |
---|
90 | } ; |
---|
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, |
---|
106 | char **List, int num_entries, int start_yoffset, ifield *Next, image *texture=NULL); |
---|
107 | virtual void handle_inside_event(event &ev, image *screen, InputManager *inm); |
---|
108 | virtual void scroll_event(int newx, image *screen); |
---|
109 | virtual char *read() { return (char *)this; } |
---|
110 | virtual void area_config(); |
---|
111 | virtual void handle_up(image *screen, InputManager *inm); |
---|
112 | virtual void handle_down(image *screen, InputManager *inm); |
---|
113 | int get_selection() { return lis[cur_sel].number; } |
---|
114 | ~pick_list() { free(lis); } |
---|
115 | } ; |
---|
116 | |
---|
117 | #endif |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|