1 //------------------------------------------------------------------------
2 //  BROWSER for TEXTURES / FLATS / THINGS
3 //------------------------------------------------------------------------
4 //
5 //  Eureka DOOM Editor
6 //
7 //  Copyright (C) 2007-2019 Andrew Apted
8 //
9 //  This program is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU General Public License
11 //  as published by the Free Software Foundation; either version 2
12 //  of the License, or (at your option) any later version.
13 //
14 //  This program is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 //  GNU General Public License for more details.
18 //
19 //------------------------------------------------------------------------
20 
21 #ifndef __EUREKA_UI_BROWSER_H__
22 #define __EUREKA_UI_BROWSER_H__
23 
24 #include <map>
25 #include <string>
26 
27 
28 class Browser_Button;
29 
30 
31 class Browser_Item : public Fl_Group
32 {
33 private:
34 
35 public:
36 	std::string desc;
37 	std::string real_name;	// for textures and flats only
38 
39 	int number;
40 
41 	char kind;  // generally matches browser kind: T/F/O/S/L
42 	char category;
43 
44 	int recent_idx;
45 
46 	Browser_Button * button;
47 
48 	UI_Pic *pic;
49 
50 public:
51 	// this constructor makes a simple text button
52 	Browser_Item(int X, int Y, int W, int H,
53 	             const char *_desc, const char *_realname,
54 				 int _num, char _kind, char _category);
55 
56 	// this constructor makes a picture with a text label below it
57 	Browser_Item(int X, int Y, int W, int H,
58 	             const char * _desc, const char *_realname,
59 				 int _num, char _kind, char _category,
60 	             int pic_w, int pic_h, UI_Pic *_pic);
61 
62 	virtual ~Browser_Item();
63 
64 	bool MatchName(const char *name) const;
65 
66 public:
67 	static void texture_callback(Fl_Widget *w, void *data);
68 	static void    flat_callback(Fl_Widget *w, void *data);
69 	static void   thing_callback(Fl_Widget *w, void *data);
70 	static void    line_callback(Fl_Widget *w, void *data);
71 	static void  sector_callback(Fl_Widget *w, void *data);
72 
73 private:
74 };
75 
76 
77 class UI_Browser_Box : public Fl_Group
78 {
79 private:
80 	char kind;
81 
82 	Fl_Choice *category;
83 	Fl_Input  *search;
84 
85 	Fl_Check_Button *alpha;
86 	Fl_Check_Button *pics;
87 
88 	Fl_Check_Button *do_tex;
89 	Fl_Check_Button *do_flats;
90 
91 	UI_Scroll *scroll;
92 
93 	bool pic_mode;
94 
95 	char cat_letters[64];
96 
97 public:
98 	UI_Browser_Box(int X, int Y, int W, int H, const char *label, char _kind);
99 	virtual ~UI_Browser_Box();
100 
101 	/* FLTK method */
102 	void resize(int X, int Y, int W, int H);
103 
104 public:
105 	void Populate();
106 
107 	void SetCategories(const char *cats, const char *letters);
108 
109 	void CycleCategory(int dir);
110 	void ToggleRecent(bool force_recent);
111 	void ClearSearchBox();
112 	void Scroll(int delta);
113 
GetKind()114 	char GetKind() const { return kind; }
115 
116 	// ensure the given texture or type/special is visible
117 	void JumpToTex(const char *tex_name);
118 	void JumpToValue(int value);
119 
120 	void RecentUpdate();
121 
122 	bool ParseUser(const char ** tokens, int num_tok);
123 	void WriteUser(FILE *fp);
124 
125 private:
126 	// adjust the widgets in the Fl_Scroll based on current search
127 	// parameters.  Returns true if something changed.
128 	bool Filter(bool force_update = false);
129 
130 	void Sort();
131 
132 	bool SearchMatch(Browser_Item *item) const;
133 
134 	void Populate_Images(char imkind, std::map<std::string, Img_c *> & img_list);
135 	void Populate_Sprites();
136 
137 	void Populate_ThingTypes();
138 	void Populate_LineTypes();
139 	void Populate_SectorTypes();
140 
141 	bool Recent_UpdateItem(Browser_Item *item);
142 
143 	bool CategoryByLetter(char letter);
144 
145 	static void category_callback(Fl_Widget *w, void *data);
146 	static void   search_callback(Fl_Widget *w, void *data);
147 
148 	static void   hide_callback(Fl_Widget *w, void *data);
149 	static void  repop_callback(Fl_Widget *w, void *data);
150 	static void   sort_callback(Fl_Widget *w, void *data);
151 };
152 
153 
154 class UI_Generalized_Page;
155 
156 
157 class UI_Generalized_Box : public Fl_Group
158 {
159 private:
160 	// overall kind of line (DOOR, LIFT, etc...)
161 	Fl_Choice * category;
162 
163 	// this is shown when not in Boom mode
164 	Fl_Box * no_boom;
165 
166 	enum
167 	{
168 		MAX_PAGES = 16
169 	};
170 
171 	UI_Generalized_Page * pages[MAX_PAGES];
172 
173 	int num_pages;
174 
175 	int in_update;
176 
177 public:
178 	UI_Generalized_Box(int X, int Y, int W, int H, const char *label);
179 	virtual ~UI_Generalized_Box();
180 
181 	void Populate();
182 
183 	void UpdateGenType(int line_type);
184 
185 private:
186 	void CreatePages();
187 
188 	int ComputeType() const;
189 
190 	static void hide_callback(Fl_Widget *w, void *data);
191 	static void  cat_callback(Fl_Widget *w, void *data);
192 	static void edit_callback(Fl_Widget *w, void *data);
193 };
194 
195 
196 class UI_Browser : public Fl_Group
197 {
198 	/* this widget basically just contains all the browser boxes,
199 	 * and controls which one is visible at any time.
200 	 */
201 
202 private:
203 	UI_Browser_Box *browsers[5];
204 
205 	UI_Generalized_Box *gen_box;
206 
207 	enum
208 	{
209 		ACTIVE_GENERALIZED = 5
210 	};
211 
212  	// currently active browser box (may be hidden though)
213 	int active;
214 
215 public:
216 	UI_Browser(int X, int Y, int W, int H, const char *label = NULL);
217 	virtual ~UI_Browser();
218 
219 public:
220 	void Populate();
221 
222 	void SetActive(int new_active);
223 
224 	char GetMode() const;
225 	void ChangeMode(char new_mode);
226 	void NewEditMode(obj_type_e edit_mode);
227 
228 	// ensure the given texture or type/special is visible
229 	void JumpToTex(const char *tex_name);
230 	void JumpToValue(int value);
231 
232 	// dir is +1 or -1, or 0 to set the category to "ALL"
233 	void CycleCategory(int dir);
234 	void ToggleRecent(bool force_recent = false);
235 
236 	void ClearSearchBox();
237 
238 	void Scroll(int delta);
239 
240 	// recently used textures (etc) has changed
241 	void RecentUpdate();
242 
243 	// for the generalized box
244 	void UpdateGenType(int line_type);
245 
246 	bool ParseUser(const char ** tokens, int num_tok);
247 	void WriteUser(FILE *fp);
248 
249 private:
250 //	static void mode_callback(Fl_Widget *w, void *data);
251 };
252 
253 
254 bool Browser_ParseUser(const char ** tokens, int num_tok);
255 void Browser_WriteUser(FILE *fp);
256 
257 #endif  /* __EUREKA_UI_BROWSER_H__ */
258 
259 //--- editor settings ---
260 // vi:ts=4:sw=4:noexpandtab
261