Subversion Repositories Kolibri OS

Rev

Rev 7823 | Rev 7924 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5598 pavelyakov 1
#ifndef INCLUDE_LIST_BOX_H
2
#define INCLUDE_LIST_BOX_H
3225 leency 3
 
5598 pavelyakov 4
#ifndef INCLUDE_KOLIBRI_H
5
#include "../lib/kolibri.h"
6
#endif
7
 
3225 leency 8
struct llist
9
{
5825 leency 10
	int x, y, w, h, item_h, item_w;
11
	int count, visible, first, column_max; //visible = row_max
12
	int cur_x, cur_y;
13
	int text_y;
5781 leency 14
	byte font_w, font_h, font_type;
5779 leency 15
	byte wheel_size;
16
	byte active;
17
	byte no_selection;
5825 leency 18
	byte horisontal_selelection;
3225 leency 19
	void ClearList();
5825 leency 20
	void SetSizes(int xx, yy, ww, hh, item_hh);
21
	void SetFont(dword font_ww, font_hh, font_tt);
22
	int ProcessKey(dword key);
23
	int ProcessMouse(int xx, yy);
4077 leency 24
	int MouseOver(int xx, yy);
5825 leency 25
	int MouseScroll(dword scroll_state);
26
	int KeyDown();
27
	int KeyUp();
28
	int KeyHome();
7863 leency 29
	int KeyHomeHor();
5825 leency 30
	int KeyEnd();
7863 leency 31
	int KeyEndHor();
5825 leency 32
	int KeyPgDown();
33
	int KeyPgUp();
34
	int KeyLeft();
35
	int KeyRight();
5694 leency 36
	void CheckDoesValuesOkey();
7227 leency 37
	void debug();
5825 leency 38
};
3225 leency 39
 
7227 leency 40
:void llist::debug()
5616 leency 41
{
5694 leency 42
	char yi[128];
5825 leency 43
	sprintf(#yi, "%s %d %s %d %s %d %s %d %s %d %s %d", "first:", first, "visible:", visible, "count:", count, "col_max:", column_max, "cur_y:", cur_y, "cur_x:", cur_x);
5694 leency 44
	debugln(#yi);
7227 leency 45
}
4662 leency 46
 
5421 leency 47
 
7227 leency 48
:void llist::ClearList()
3225 leency 49
{
5825 leency 50
	count = visible = first = cur_y = cur_x = 0;
3225 leency 51
}
52
 
53
 
7227 leency 54
:void llist::SetSizes(int xx, yy, ww, hh, item_hh)
3225 leency 55
{
56
	x = xx;
57
	y = yy;
58
	w = ww;
59
	h = hh;
5825 leency 60
	item_h = item_hh;
61
	text_y = item_h - font_h / 2;
62
	visible = h / item_h;
5749 leency 63
	wheel_size = 3;
5784 leency 64
	CheckDoesValuesOkey();
3225 leency 65
}
66
 
7227 leency 67
 
68
:void llist::SetFont(dword font_ww, font_hh, font_tt)
5710 leency 69
{
70
	font_w = font_ww;
71
	font_h = font_hh;
72
	font_type = font_tt;
73
}
3225 leency 74
 
5710 leency 75
 
7227 leency 76
:int llist::MouseScroll(dword scroll_state)
3225 leency 77
{
4533 leency 78
	if (count<=visible) return 0;
3225 leency 79
	if (scroll_state == 65535)
80
	{
81
		if (first == 0) return 0;
5749 leency 82
		if (first > wheel_size+1) first -= wheel_size; else first=0;
7812 leency 83
		CheckDoesValuesOkey();
3225 leency 84
		return 1;
85
	}
86
	if (scroll_state == 1)
87
	{
5421 leency 88
		if (visible + first == count) return 0;
5749 leency 89
		if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
7812 leency 90
		CheckDoesValuesOkey();
3225 leency 91
		return 1;
92
	}
93
	return 0;
4059 leency 94
}
95
 
5616 leency 96
 
7227 leency 97
:int llist::MouseOver(int xx, yy)
4077 leency 98
{
99
	if (xx>x) && (xxy) && (yy
100
	return 0;
101
}
102
 
7227 leency 103
:int llist::ProcessMouse(int xx, yy)
4077 leency 104
{
5825 leency 105
	int cur_y_temp, cur_x_temp, ret=0;
4077 leency 106
	if (MouseOver(xx, yy))
107
	{
5825 leency 108
		cur_y_temp = yy - y / item_h + first;
109
		if (cur_y_temp != cur_y) && (cur_y_temp
4077 leency 110
		{
5825 leency 111
			cur_y = cur_y_temp;
112
			ret = 1;
4077 leency 113
		}
5829 leency 114
		if (horisontal_selelection)
115
		{
116
			cur_x_temp = xx - x / item_w;
117
			if (cur_x_temp != cur_x) && (cur_x_temp
118
			{
119
				cur_x = cur_x_temp;
120
				ret = 1;
121
			}
5825 leency 122
		}
4077 leency 123
	}
5825 leency 124
	return ret;
4077 leency 125
}
126
 
7227 leency 127
:int llist::ProcessKey(dword key)
4073 leency 128
{
7863 leency 129
	if (horisontal_selelection) switch(key)
130
	{
131
		case SCAN_CODE_LEFT:  return KeyLeft();
132
		case SCAN_CODE_RIGHT: return KeyRight();
133
		case SCAN_CODE_HOME:  return KeyHomeHor();
134
		case SCAN_CODE_END:   return KeyEndHor();
135
	}
4073 leency 136
	switch(key)
137
	{
5702 punk_joker 138
		case SCAN_CODE_DOWN: return KeyDown();
139
		case SCAN_CODE_UP:   return KeyUp();
140
		case SCAN_CODE_HOME: return KeyHome();
141
		case SCAN_CODE_END:  return KeyEnd();
142
		case SCAN_CODE_PGUP: return KeyPgUp();
143
		case SCAN_CODE_PGDN: return KeyPgDown();
4073 leency 144
	}
145
	return 0;
146
}
147
 
7227 leency 148
:int llist::KeyDown()
4059 leency 149
{
5781 leency 150
	if (no_selection)
4059 leency 151
	{
5781 leency 152
		if (visible + first >= count) return 0;
153
		first++;
154
		return 1;
155
	}
156
 
5825 leency 157
	if (cur_y-first+1
5781 leency 158
	{
5825 leency 159
		if (cur_y + 1 >= count) return 0;
160
		cur_y++;
4059 leency 161
	}
162
	else
163
	{
5694 leency 164
		if (visible + first >= count) return 0;
4059 leency 165
		first++;
5825 leency 166
		cur_y++;
4059 leency 167
	}
7823 leency 168
	if (cur_y < first) || (cur_y >= first + visible)
5694 leency 169
	{
5825 leency 170
		first = cur_y;
5694 leency 171
	}
7863 leency 172
	CheckDoesValuesOkey();
4059 leency 173
	return 1;
174
}
175
 
7227 leency 176
:int llist::KeyUp()
4059 leency 177
{
5781 leency 178
	if (no_selection)
4059 leency 179
	{
5781 leency 180
		if (first == 0) return 0;
181
		first--;
182
		return 1;
183
	}
184
 
5825 leency 185
	if (cur_y > first)
5781 leency 186
	{
5825 leency 187
		cur_y--;
4059 leency 188
	}
189
	else
190
	{
5694 leency 191
		if (first == 0) return 0;
4059 leency 192
		first--;
5825 leency 193
		cur_y--;
4059 leency 194
	}
5825 leency 195
	if (cur_y < first) || (cur_y > first + visible)
5694 leency 196
	{
5825 leency 197
		first = cur_y;
5694 leency 198
		CheckDoesValuesOkey();
199
	}
4059 leency 200
	return 1;
4063 leency 201
}
202
 
7863 leency 203
:int llist::KeyHomeHor()
204
{
205
	if (cur_x==0) return 0;
206
	cur_x = 0;
207
	return 1;
208
}
209
 
210
:int llist::KeyEndHor()
211
{
212
	if (cur_x==column_max) return 0;
213
	cur_x = column_max;
214
	CheckDoesValuesOkey();
215
	return 1;
216
}
217
 
7227 leency 218
:int llist::KeyHome()
4063 leency 219
{
5825 leency 220
	if (cur_y==0) && (first==0) return 0;
221
	cur_y = first = 0;
4063 leency 222
	return 1;
223
}
224
 
7227 leency 225
:int llist::KeyEnd()
4063 leency 226
{
5825 leency 227
	if (cur_y==count-1) && (first==count-visible) return 0;
228
	cur_y = count-1;
5694 leency 229
	first = count - visible;
7804 leency 230
	CheckDoesValuesOkey();
4063 leency 231
	return 1;
5598 pavelyakov 232
}
233
 
7227 leency 234
:int llist::KeyPgUp()
5694 leency 235
{
236
	if (count <= visible) return KeyHome();
237
	if (first == 0) return 0;
238
	first -= visible;
5958 leency 239
	cur_y = first;
5694 leency 240
	CheckDoesValuesOkey();
241
	return 1;
242
}
243
 
7227 leency 244
:int llist::KeyPgDown()
5694 leency 245
{
246
	if (count <= visible) return KeyEnd();
247
	if (first == count - visible) return 0;
248
	first += visible;
5958 leency 249
	cur_y = first + visible - 1;
5694 leency 250
	CheckDoesValuesOkey();
251
	return 1;
252
}
253
 
7227 leency 254
:void llist::CheckDoesValuesOkey()
5694 leency 255
{
5784 leency 256
	if (visible + first > count) first = count - visible;
5694 leency 257
	if (first < 0) first = 0;
5825 leency 258
	if (cur_y >= count) cur_y = count - 1;
7863 leency 259
	if (cur_x >= column_max) cur_x = column_max;
5825 leency 260
	if (cur_y < 0) cur_y = 0;
261
	if (cur_x < 0) cur_x = 0;
5694 leency 262
}
263
 
7227 leency 264
:int llist::KeyRight()
5825 leency 265
{
266
	if (cur_x < column_max)
267
	{
268
		cur_x++;
269
	}
270
	else
271
	{
272
		if (!KeyDown()) return 0;
273
		cur_x = 0;
274
	}
275
	return 1;
276
}
277
 
7227 leency 278
:int llist::KeyLeft()
5825 leency 279
{
280
	if (cur_x > 0)
281
	{
282
		cur_x--;
283
	}
284
	else
285
	{
286
		if (!KeyUp()) return 0;
287
		cur_x = column_max;
288
	}
289
	return 1;
290
}
291
 
292
 
7227 leency 293
:void llist_copy(dword dest, src)
5733 leency 294
{
7757 leency 295
	memmov(dest, src, sizeof(llist));
296
	/*
5733 leency 297
	EDI = dest;
298
	ESI = src;
299
	EDI.llist.x = ESI.llist.x;
300
	EDI.llist.y = ESI.llist.y;
301
	EDI.llist.w = ESI.llist.w;
302
	EDI.llist.h = ESI.llist.h;
5825 leency 303
	EDI.llist.item_h = ESI.llist.item_h;
5733 leency 304
	EDI.llist.text_y = ESI.llist.text_y;
305
	EDI.llist.font_w = ESI.llist.font_w;
306
	EDI.llist.font_h = ESI.llist.font_h;
307
	EDI.llist.font_type = ESI.llist.font_type;
308
	EDI.llist.count = ESI.llist.count;
309
	EDI.llist.visible = ESI.llist.visible;
310
	EDI.llist.first = ESI.llist.first;
5825 leency 311
	EDI.llist.cur_y = ESI.llist.cur_y;
5733 leency 312
	EDI.llist.column_max = ESI.llist.column_max;
313
	EDI.llist.active = ESI.llist.active;
7757 leency 314
	*/
5733 leency 315
}
316
 
5598 pavelyakov 317
#endif