1 /*
2 * item_list.h
3 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath
4 * DIN Is Noise is released under GNU Public License 2.0
5 * For more information, please visit https://dinisnoise.org/
6 */
7 
8 #ifndef __item_list
9 #define __item_list
10 
11 #include "button.h"
12 #include <vector>
13 #include <string>
14 
15 struct tokenizer;
16 
17 struct item_list;
18 struct selection_listener {
19 	virtual void selected (item_list& il, int l) = 0;
20 };
21 
22 struct itemt {
23   std::string name;
24   int sel;
nameitemt25   itemt (const std::string& n, int sell = 0) : name(n), sel(sell) {}
26 };
27 
28 struct item_list : button, click_listener {
29 
30 	int last, hov, cur, yt;
31 
32 	int n, n_1, nsel;
33 	void calc ();
34 
35   std::vector <std::string> nums;
36   std::vector<itemt> items;
37 
38 	selection_listener *sel_lis;
39 	void select (int w);
40 	void select (int i, int j);
41 	int select_these (tokenizer& tz);
42 	void invert_select ();
43 	std::string get_selected ();
num_selecteditem_list44 	inline int num_selected () {return nsel;}
45 	int get_first ();
46 
47 	item_list ();
48   void add (const std::string& i);
49 	void insert (int i, const std::string& s);
50 	void remove (int i);
51   void clear ();
52 
53 	void clicked (button& b);
54 
55   void set_pos (int x, int y);
56   int handle_input ();
57   void draw ();
updateitem_list58   void update () {}
59 
60 };
61 #endif
62