Subversion Repositories Kolibri OS

Rev

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