Subversion Repositories Kolibri OS

Rev

Rev 7757 | Rev 7812 | 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;
3225 leency 81
		return 1;
82
	}
83
	if (scroll_state == 1)
84
	{
5421 leency 85
		if (visible + first == count) return 0;
5749 leency 86
		if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
3225 leency 87
		return 1;
88
	}
89
	return 0;
4059 leency 90
}
91
 
5616 leency 92
 
7227 leency 93
:int llist::MouseOver(int xx, yy)
4077 leency 94
{
95
	if (xx>x) && (xxy) && (yy
96
	return 0;
97
}
98
 
7227 leency 99
:int llist::ProcessMouse(int xx, yy)
4077 leency 100
{
5825 leency 101
	int cur_y_temp, cur_x_temp, ret=0;
4077 leency 102
	if (MouseOver(xx, yy))
103
	{
5825 leency 104
		cur_y_temp = yy - y / item_h + first;
105
		if (cur_y_temp != cur_y) && (cur_y_temp
4077 leency 106
		{
5825 leency 107
			cur_y = cur_y_temp;
108
			ret = 1;
4077 leency 109
		}
5829 leency 110
		if (horisontal_selelection)
111
		{
112
			cur_x_temp = xx - x / item_w;
113
			if (cur_x_temp != cur_x) && (cur_x_temp
114
			{
115
				cur_x = cur_x_temp;
116
				ret = 1;
117
			}
5825 leency 118
		}
4077 leency 119
	}
5825 leency 120
	return ret;
4077 leency 121
}
122
 
7227 leency 123
:int llist::ProcessKey(dword key)
4073 leency 124
{
125
	switch(key)
126
	{
5702 punk_joker 127
		case SCAN_CODE_DOWN: return KeyDown();
128
		case SCAN_CODE_UP:   return KeyUp();
129
		case SCAN_CODE_HOME: return KeyHome();
130
		case SCAN_CODE_END:  return KeyEnd();
131
		case SCAN_CODE_PGUP: return KeyPgUp();
132
		case SCAN_CODE_PGDN: return KeyPgDown();
4073 leency 133
	}
5825 leency 134
	if (horisontal_selelection) switch(key)
135
	{
136
		case SCAN_CODE_LEFT:  return KeyLeft();
137
		case SCAN_CODE_RIGHT: return KeyRight();
138
	}
4073 leency 139
	return 0;
140
}
141
 
7227 leency 142
:int llist::KeyDown()
4059 leency 143
{
5781 leency 144
	if (no_selection)
4059 leency 145
	{
5781 leency 146
		if (visible + first >= count) return 0;
147
		first++;
148
		return 1;
149
	}
150
 
5825 leency 151
	if (cur_y-first+1
5781 leency 152
	{
5825 leency 153
		if (cur_y + 1 >= count) return 0;
154
		cur_y++;
4059 leency 155
	}
156
	else
157
	{
5694 leency 158
		if (visible + first >= count) return 0;
4059 leency 159
		first++;
5825 leency 160
		cur_y++;
4059 leency 161
	}
5825 leency 162
	if (cur_y < first) || (cur_y > first + visible)
5694 leency 163
	{
5825 leency 164
		first = cur_y;
5694 leency 165
		CheckDoesValuesOkey();
166
	}
4059 leency 167
	return 1;
168
}
169
 
7227 leency 170
:int llist::KeyUp()
4059 leency 171
{
5781 leency 172
	if (no_selection)
4059 leency 173
	{
5781 leency 174
		if (first == 0) return 0;
175
		first--;
176
		return 1;
177
	}
178
 
5825 leency 179
	if (cur_y > first)
5781 leency 180
	{
5825 leency 181
		cur_y--;
4059 leency 182
	}
183
	else
184
	{
5694 leency 185
		if (first == 0) return 0;
4059 leency 186
		first--;
5825 leency 187
		cur_y--;
4059 leency 188
	}
5825 leency 189
	if (cur_y < first) || (cur_y > first + visible)
5694 leency 190
	{
5825 leency 191
		first = cur_y;
5694 leency 192
		CheckDoesValuesOkey();
193
	}
4059 leency 194
	return 1;
4063 leency 195
}
196
 
7227 leency 197
:int llist::KeyHome()
4063 leency 198
{
5825 leency 199
	if (cur_y==0) && (first==0) return 0;
200
	cur_y = first = 0;
4063 leency 201
	return 1;
202
}
203
 
7227 leency 204
:int llist::KeyEnd()
4063 leency 205
{
5825 leency 206
	if (cur_y==count-1) && (first==count-visible) return 0;
207
	cur_y = count-1;
5694 leency 208
	first = count - visible;
7804 leency 209
	CheckDoesValuesOkey();
4063 leency 210
	return 1;
5598 pavelyakov 211
}
212
 
7227 leency 213
:int llist::KeyPgUp()
5694 leency 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
 
7227 leency 223
:int llist::KeyPgDown()
5694 leency 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
 
7227 leency 233
:void llist::CheckDoesValuesOkey()
5694 leency 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
 
7227 leency 242
:int llist::KeyRight()
5825 leency 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
 
7227 leency 256
:int llist::KeyLeft()
5825 leency 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
 
7227 leency 271
:void llist_copy(dword dest, src)
5733 leency 272
{
7757 leency 273
	memmov(dest, src, sizeof(llist));
274
	/*
5733 leency 275
	EDI = dest;
276
	ESI = src;
277
	EDI.llist.x = ESI.llist.x;
278
	EDI.llist.y = ESI.llist.y;
279
	EDI.llist.w = ESI.llist.w;
280
	EDI.llist.h = ESI.llist.h;
5825 leency 281
	EDI.llist.item_h = ESI.llist.item_h;
5733 leency 282
	EDI.llist.text_y = ESI.llist.text_y;
283
	EDI.llist.font_w = ESI.llist.font_w;
284
	EDI.llist.font_h = ESI.llist.font_h;
285
	EDI.llist.font_type = ESI.llist.font_type;
286
	EDI.llist.count = ESI.llist.count;
287
	EDI.llist.visible = ESI.llist.visible;
288
	EDI.llist.first = ESI.llist.first;
5825 leency 289
	EDI.llist.cur_y = ESI.llist.cur_y;
5733 leency 290
	EDI.llist.column_max = ESI.llist.column_max;
291
	EDI.llist.active = ESI.llist.active;
7757 leency 292
	*/
5733 leency 293
}
294
 
5598 pavelyakov 295
#endif