Subversion Repositories Kolibri OS

Rev

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

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