Subversion Repositories Kolibri OS

Rev

Rev 9630 | Rev 9659 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9630 Rev 9648
Line 21... Line 21...
21
 
21
 
Line 22... Line 22...
22
IMPORT G := Graph, K := KolibriOS, U := Utils;
22
IMPORT G := Graph, K := KolibriOS, U := Utils;
Line 23... Line -...
23
 
-
 
24
CONST
23
 
Line 25... Line 24...
25
 
24
CONST
Line -... Line 25...
-
 
25
 
-
 
26
	DELAY = 40;
26
	ScrollIPC* = 0;
27
 
27
	DELAY = 40;
28
TYPE
28
 
29
 
29
TYPE
30
	tProcedure = PROCEDURE;
30
 
31
 
31
	tScroll* = RECORD
32
	tScroll* = RECORD
32
		vertical, Inc*, Dec*, mouse: BOOLEAN;
33
		vertical, mouse: BOOLEAN;
33
		top*, left*,
-
 
34
		width*, height*: INTEGER; (* read only *)
-
 
35
		btnSize, sliderSize: INTEGER;
-
 
36
		pos, Slider, pos0, maxVal*, value*: INTEGER;
-
 
37
		canvas*: G.tCanvas
-
 
38
	END;
-
 
39
 
34
		top*, left*,
40
	tProcedure* = PROCEDURE;
35
		width*, height*: INTEGER; (* read only *)
-
 
36
		btnSize, sliderSize: INTEGER;
-
 
37
		pos, Slider, pos0, maxVal*, value*: INTEGER;
Line 41... Line 38...
41
 
38
		canvas: G.tCanvas;
42
VAR
39
		change: tProcedure;
43
 
40
		delay: INTEGER;
44
	ScrollChange: tProcedure;
-
 
45
	delay: INTEGER;
41
		btn*: INTEGER
46
 
42
	END;
-
 
43
 
47
 
44
 
Line 48... Line 45...
48
PROCEDURE MouseUp (VAR scroll: tScroll);
45
PROCEDURE MouseUp (VAR scroll: tScroll);
49
BEGIN
46
BEGIN
50
	scroll.Slider := -1;
47
	scroll.Slider := -1;
51
	scroll.Inc := FALSE;
48
	scroll.btn := 0;
52
	scroll.Dec := FALSE;
49
	scroll.mouse := FALSE;
53
	scroll.mouse := FALSE;
50
	scroll.delay := DELAY
Line 67... Line 64...
67
	res.btnSize := btnSize;
64
	res.btnSize := btnSize;
68
	res.sliderSize := sliderSize;
65
	res.sliderSize := sliderSize;
69
	res.pos := 0;
66
	res.pos := 0;
70
	res.maxVal := 0;
67
	res.maxVal := 0;
71
	res.canvas := G.CreateCanvas(width, height);
68
	res.canvas := G.CreateCanvas(width, height);
-
 
69
	res.change := change;
72
	scroll := res
70
	scroll := res
73
END create;
71
END create;
Line 74... Line 72...
74
 
72
 
Line 109... Line 107...
109
	G.SetColor(canvas, K.colors.light);
107
	G.SetColor(canvas, K.colors.light);
110
	G.clear(canvas);
108
	G.clear(canvas);
111
	G.SetColor(canvas, K.colors.line);
109
	G.SetColor(canvas, K.colors.line);
112
	G.Rect(canvas, 0, 0, width - 1, height - 1);
110
	G.Rect(canvas, 0, 0, width - 1, height - 1);
113
	IF scroll.vertical THEN
111
	IF scroll.vertical THEN
114
		SetColor(canvas, ~scroll.Dec);
112
		SetColor(canvas, scroll.btn # -1);
115
		Rect(canvas, 0, 0, width - 1, btn - 1);
113
		Rect(canvas, 0, 0, width - 1, btn - 1);
116
		SetColor(canvas, ~scroll.Inc);
114
		SetColor(canvas, scroll.btn # 1);
117
		Rect(canvas, 0, height - btn, width - 1, height - 1);
115
		Rect(canvas, 0, height - btn, width - 1, height - 1);
118
		G.SetColor(canvas, K.colors.button);
116
		G.SetColor(canvas, K.colors.button);
119
		Rect(canvas, 0, btn + scroll.pos - 1, width - 1, btn + scroll.pos + scroll.sliderSize - 1);
117
		Rect(canvas, 0, btn + scroll.pos - 1, width - 1, btn + scroll.pos + scroll.sliderSize - 1);
Line 120... Line 118...
120
 
118
 
Line 127... Line 125...
127
 
125
 
128
		d := 4*width DIV 10;
126
		d := 4*width DIV 10;
129
		x1 := (width - d) DIV 2;
127
		x1 := (width - d) DIV 2;
Line 130... Line 128...
130
		x2 := x1 + d;
128
		x2 := x1 + d;
131
 
129
 
132
		SetColor(canvas, scroll.Dec);
130
		SetColor(canvas, scroll.btn = -1);
Line 133... Line 131...
133
		y := (btn - d DIV 2) DIV 2 + d DIV 2 - 1;
131
		y := (btn - d DIV 2) DIV 2 + d DIV 2 - 1;
134
		G.Triangle(canvas, x1 - 1, y, x2, y, G.triUp);
132
		G.Triangle(canvas, x1 - 1, y, x2, y, G.triUp);
135
 
133
 
136
		SetColor(canvas, scroll.Inc);
134
		SetColor(canvas, scroll.btn = 1);
137
		y := y + height - btn - d DIV 2 + 1;
135
		y := y + height - btn - d DIV 2 + 1;
138
		G.Triangle(canvas, x1 - 1, y, x2, y, G.triDown);
136
		G.Triangle(canvas, x1 - 1, y, x2, y, G.triDown);
139
	ELSE
137
	ELSE
140
		SetColor(canvas, ~scroll.Dec);
138
		SetColor(canvas, scroll.btn # -1);
141
		Rect(canvas, 0, 0, btn - 1, height - 1);
139
		Rect(canvas, 0, 0, btn - 1, height - 1);
142
		SetColor(canvas, ~scroll.Inc);
140
		SetColor(canvas, scroll.btn # 1);
Line 143... Line 141...
143
		Rect(canvas, width - btn, 0, width - 1, height - 1);
141
		Rect(canvas, width - btn, 0, width - 1, height - 1);
Line 153... Line 151...
153
 
151
 
154
		d := 4*height DIV 10;
152
		d := 4*height DIV 10;
155
		y1 := (height - d) DIV 2;
153
		y1 := (height - d) DIV 2;
Line 156... Line 154...
156
		y2 := y1 + d;
154
		y2 := y1 + d;
157
 
155
 
158
		SetColor(canvas, scroll.Dec);
156
		SetColor(canvas, scroll.btn = -1);
Line 159... Line 157...
159
		x := (btn - d DIV 2) DIV 2 + d DIV 2 - 1;
157
		x := (btn - d DIV 2) DIV 2 + d DIV 2 - 1;
160
		G.Triangle(canvas, x, y1 - 1, x, y2, G.triLeft);
158
		G.Triangle(canvas, x, y1 - 1, x, y2, G.triLeft);
161
 
159
 
162
		SetColor(canvas, scroll.Inc);
160
		SetColor(canvas, scroll.btn = 1);
163
		x := x + width - btn - d DIV 2 + 1;
161
		x := x + width - btn - d DIV 2 + 1;
164
		G.Triangle(canvas, x, y1 - 1, x, y2, G.triRight);
162
		G.Triangle(canvas, x, y1 - 1, x, y2, G.triRight);
Line 217... Line 215...
217
	scroll.pos := pos;
215
	scroll.pos := pos;
218
	scroll.value := value
216
	scroll.value := value
219
END setValue;
217
END setValue;
Line 220... Line -...
220
 
-
 
221
 
-
 
222
PROCEDURE change* (VAR scroll: tScroll);
-
 
223
BEGIN
-
 
224
	IF scroll.Inc THEN
-
 
225
		setValue(scroll, scroll.value + 1)
-
 
226
	ELSIF scroll.Dec THEN
-
 
227
		setValue(scroll, scroll.value - 1)
-
 
228
	END;
-
 
229
	draw(scroll)
-
 
230
END change;
-
 
231
 
218
 
232
 
219
 
233
PROCEDURE ceil (p, q: INTEGER): INTEGER;
220
PROCEDURE ceil (p, q: INTEGER): INTEGER;
Line 304... Line 291...
304
	setPos(scroll, scroll.pos0 + c - scroll.Slider);
291
	setPos(scroll, scroll.pos0 + c - scroll.Slider);
305
	draw(scroll)
292
	draw(scroll)
306
END MouseMove;
293
END MouseMove;
Line 307... Line 294...
307
 
294
 
308
 
295
 
309
PROCEDURE SendIPC;
296
PROCEDURE button (VAR scroll: tScroll);
310
VAR
-
 
311
	msg: ARRAY 2 OF INTEGER;
-
 
312
BEGIN
-
 
313
	msg[0] := ScrollIPC;
-
 
314
	msg[1] := 8;
-
 
315
	K.SendIPC(K.ThreadID(), msg)
-
 
316
END SendIPC;
-
 
317
 
-
 
318
 
297
VAR
-
 
298
	btn: INTEGER;
-
 
299
BEGIN
-
 
300
	WHILE scroll.btn # 0 DO
-
 
301
		btn := scroll.btn;
319
PROCEDURE receiveIPC* (VAR IPC: ARRAY OF INTEGER; VAR scrollIPC: BOOLEAN);
302
		setValue(scroll, scroll.value + btn);
320
BEGIN
303
		draw(scroll);
-
 
304
		IF scroll.change # NIL THEN
-
 
305
			scroll.change
321
	scrollIPC := FALSE;
306
		END;
322
	ScrollChange;
307
		scroll.btn := 0;
323
	IF 0 IN K.MouseState() THEN
308
		IF 0 IN K.MouseState() THEN
324
		WHILE (0 IN K.MouseState()) & (delay > 0) DO
309
			WHILE (0 IN K.MouseState()) & (scroll.delay > 0) DO
325
			K.Pause(1);
310
				K.Pause(1);
326
    		DEC(delay)
311
				DEC(scroll.delay)
327
		END;
-
 
328
		IF delay = 0 THEN
-
 
329
			IPC[0] := 0;
312
			END;
330
			IPC[1] := 0;
-
 
331
			scrollIPC := TRUE;
313
			IF scroll.delay = 0 THEN
332
    		SendIPC;
314
				scroll.btn := btn;
333
    		delay := 4
315
				scroll.delay := 3
334
		ELSE
316
			ELSE
335
			delay := DELAY
317
				scroll.delay := DELAY
336
		END
318
			END
-
 
319
		ELSE
337
	ELSE
320
			scroll.delay := DELAY
338
		delay := DELAY
321
		END
Line 339... Line 322...
339
	END
322
	END
340
END receiveIPC;
323
END button;
341
 
324
 
Line 357... Line 340...
357
		END;
340
		END;
358
		IF U.between(scroll.btnSize + scroll.pos - 1, c, scroll.btnSize + scroll.pos + scroll.sliderSize - 1) THEN
341
		IF U.between(scroll.btnSize + scroll.pos - 1, c, scroll.btnSize + scroll.pos + scroll.sliderSize - 1) THEN
359
			scroll.pos0 := scroll.pos;
342
			scroll.pos0 := scroll.pos;
360
			scroll.Slider := c
343
			scroll.Slider := c
361
		ELSIF U.between(0, c, scroll.btnSize - 1) THEN
344
		ELSIF U.between(0, c, scroll.btnSize - 1) THEN
362
			scroll.Dec := TRUE;
345
			scroll.btn := -1
363
			SendIPC
-
 
364
		ELSIF U.between(size - scroll.btnSize, c, size - 1) THEN
346
		ELSIF U.between(size - scroll.btnSize, c, size - 1) THEN
365
			scroll.Inc := TRUE;
347
			scroll.btn := 1
366
			SendIPC
-
 
367
		ELSE
348
		ELSE
368
			setPos(scroll, c - scroll.btnSize - scroll.sliderSize DIV 2);
349
			setPos(scroll, c - scroll.btnSize - scroll.sliderSize DIV 2);
369
			scroll.pos0 := scroll.pos;
350
			scroll.pos0 := scroll.pos;
370
			scroll.Slider := c;
351
			scroll.Slider := c;
371
			draw(scroll)
352
			draw(scroll)
Line 387... Line 368...
387
			MouseMove(scroll, x, y)
368
			MouseMove(scroll, x, y)
388
		END
369
		END
389
	ELSIF scroll.mouse THEN
370
	ELSIF scroll.mouse THEN
390
		MouseUp(scroll);
371
		MouseUp(scroll);
391
		draw(scroll)
372
		draw(scroll)
392
	END
373
	END;
-
 
374
	button(scroll)
393
END mouse;
375
END mouse;
Line 394... Line -...
394
 
-
 
395
 
-
 
396
PROCEDURE init* (_ScrollChange: tProcedure);
-
 
397
BEGIN
-
 
398
	delay := DELAY;
-
 
399
	ScrollChange := _ScrollChange
-
 
400
END init;
-
 
401
 
376
 
402
 
377