Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1004 diamond 1
use32
2
org 0x0
3
 
4
db 'MENUET01'
5
dd 0x01, START, I_END, 0x4000, 0x4000, @PARAMS, 0x0
6
 
7
;-----------------------------------------------------------------------------
8
 
9
FALSE = 0
10
TRUE  = 1
11
 
1080 diamond 12
include '../../../proc32.inc'
13
include '../../../macros.inc'
1004 diamond 14
include 'dll.inc'
15
 
16
include '../../../develop/libraries/libs-dev/libio/libio.inc'
17
include '../../../develop/libraries/libs-dev/libimg/libimg.inc'
18
 
19
;-----------------------------------------------------------------------------
20
 
21
START:
22
	mcall	68, 11
23
 
24
	stdcall dll.Load, @IMPORT
25
	or	eax, eax
26
	jnz	exit
27
 
1144 diamond 28
	invoke	sort.START, 1
1016 diamond 29
 
1004 diamond 30
	mov	ecx, 1	; for 15.4: 1 = tile
31
	cmp	word [@PARAMS], '\T'
32
	jz	set_bgr
33
	inc	ecx	; for 15.4: 2 = stretch
34
	cmp	word [@PARAMS], '\S'
35
	jz	set_bgr
36
 
1427 diamond 37
; initialize keyboard handling
38
	invoke	ini_get_shortcut, inifilename, aShortcuts, aNext, -1, next_mod
39
	mov	[next_key], eax
40
	invoke	ini_get_shortcut, inifilename, aShortcuts, aPrev, -1, prev_mod
41
	mov	[prev_key], eax
42
	mcall	66, 1, 1	; set kbd mode to scancodes
43
 
1004 diamond 44
	cmp	byte [@PARAMS], 0
45
	jnz	params_given
46
 
47
	call	opendialog
48
	jc	exit
49
	mov	esi, path
50
	mov	edi, @PARAMS
51
	mov	ecx, 512/4
52
	rep	movsd
53
	mov	byte [edi-1], 0
54
	jmp	params_given
55
 
56
set_bgr:
57
	mcall	15, 4
58
	mov	eax, @PARAMS + 4
59
	call	load_image
1016 diamond 60
	jc	exit
1004 diamond 61
 
1016 diamond 62
	call	set_as_bgr
1004 diamond 63
	jmp	exit
64
 
65
params_given:
66
 
1427 diamond 67
	mov	esi, @PARAMS
68
	push	esi
69
	call	find_last_name_component
70
 
71
	pop	eax
1004 diamond 72
	call	load_image
73
	jc	exit
1427 diamond 74
	call	generate_header
1004 diamond 75
 
76
;-----------------------------------------------------------------------------
77
 
78
red:
79
	call	draw_window
80
 
81
still:
1080 diamond 82
	mov	eax, [image]
83
	test	byte [eax + Image.Flags], Image.IsAnimated
84
	push	10
85
	pop	eax
86
	jz	@f
87
	mcall	26, 9
88
	mov	edx, [cur_frame]
89
	mov	ebx, [cur_frame_time]
90
	add	ebx, [edx + Image.Delay]
91
	sub	ebx, eax
92
	cmp	ebx, [edx + Image.Delay]
93
	ja	red_update_frame
94
	test	ebx, ebx
95
	jz	red_update_frame
96
	push	23
97
	pop	eax
98
  @@:
99
	mcall
1004 diamond 100
	dec	eax
1080 diamond 101
	js	red_update_frame
1004 diamond 102
	jz	red
103
	dec	eax
104
	jnz	button
105
 
1080 diamond 106
key:
1427 diamond 107
	xor	esi, esi
108
keyloop:
1004 diamond 109
	mcall	2
1427 diamond 110
	test	al, al
111
	jnz	keyloopdone
112
	shr	eax, 8
113
	mov	ecx, eax
114
	mcall	66, 3
115
	mov	edx, next_mod
116
	call	check_shortcut
117
	jz	.next
118
	add	edx, prev_mod - next_mod
119
	call	check_shortcut
120
	jnz	keyloop
121
.prev:
122
	dec	esi
123
	jmp	keyloop
124
.next:
125
	inc	esi
126
	jmp	keyloop
127
keyloopdone:
128
	test	esi, esi
129
	jz	still
130
next_or_prev_handler:
131
	call	next_or_prev_image
132
	jmp	red
1004 diamond 133
 
1080 diamond 134
red_update_frame:
135
	mov	eax, [cur_frame]
136
	mov	eax, [eax + Image.Next]
137
	test	eax, eax
138
	jnz	@f
139
	mov	eax, [image]
140
  @@:
141
	mov	[cur_frame], eax
142
	mcall	26, 9
143
	mov	[cur_frame_time], eax
144
	mcall	9, procinfo, -1
145
	call	draw_cur_frame
146
	jmp	still
147
 
148
button:
1004 diamond 149
	mcall	17
150
	shr	eax, 8
151
 
152
	; flip horizontally
153
	cmp	eax, 'flh'
154
	jne	@f
155
 
156
	invoke	img.flip, [image], FLIP_HORIZONTAL
157
	jmp	redraw_image
158
 
159
	; flip vertically
160
    @@: cmp	eax, 'flv'
161
	jne	@f
162
 
163
	invoke	img.flip, [image], FLIP_VERTICAL
164
	jmp	redraw_image
165
 
166
	; flip both horizontally and vertically
167
    @@: cmp	eax, 'flb'
168
	jne	@f
169
 
170
	invoke	img.flip, [image], FLIP_BOTH
171
	jmp	redraw_image
172
 
173
	; rotate left
174
    @@: cmp	eax, 'rtl'
175
	jne	@f
176
 
177
	push	ROTATE_90_CCW
178
.rotate_common:
179
	invoke	img.rotate, [image]
180
	mov	eax, [image]
181
	test	eax, eax	; clear ZF flag
182
	call	update_image_sizes
183
	jmp	redraw_image
184
 
185
	; rotate right
186
    @@: cmp	eax, 'rtr'
187
	jne	@f
188
 
189
	push	ROTATE_90_CW
190
	jmp	.rotate_common
191
 
192
	; open new file
193
    @@: cmp	eax, 'opn'
194
	jne	@f
195
 
196
	call	opendialog
197
	jc	still
198
	push	[image]
199
	mov	eax, path
200
	call	load_image
201
	jc	.restore_old
202
	mov	esi, path
203
	mov	edi, @PARAMS
204
	mov	ecx, 512/4
205
	rep	movsd
1016 diamond 206
	mov	byte [edi-1], 0
1004 diamond 207
	invoke	img.destroy
1016 diamond 208
	call	free_directory
1004 diamond 209
	jmp	red
210
    .restore_old:
211
	pop	[image]
1080 diamond 212
	call	init_frame
1004 diamond 213
	jmp	still
214
 
1016 diamond 215
	; set background
216
    @@:
217
	cmp	eax, 'bgr'
218
	jne	@f
219
 
220
	call	set_as_bgr
221
	jmp	still
222
 
223
    @@:
224
 
1427 diamond 225
	or	esi, -1
1016 diamond 226
	cmp	eax, 'bck'
1427 diamond 227
	jz	next_or_prev_handler
228
	neg	esi
1016 diamond 229
	cmp	eax, 'fwd'
1427 diamond 230
	jz	next_or_prev_handler
1016 diamond 231
 
232
	cmp	eax, 1
1004 diamond 233
	jne	still
234
 
235
  exit:
236
	mcall	-1
237
 
238
  redraw_image = red
239
 
240
load_image:
241
	and	[img_data], 0
242
	push	eax
243
	invoke	file.open, eax, O_READ
244
	or	eax, eax
245
	jz	.error_pop
246
	mov	[fh], eax
247
	invoke	file.size
248
	mov	[img_data_len], ebx
249
	stdcall mem.Alloc, ebx
250
	test	eax, eax
251
	jz	.error_close
252
	mov	[img_data], eax
253
	invoke	file.read, [fh], eax, [img_data_len]
254
	cmp	eax, -1
255
	jz	.error_close
256
	cmp	eax, [img_data_len]
257
	jnz	.error_close
258
	invoke	file.close, [fh]
259
	inc	eax
260
	jz	.error
261
 
262
; img.decode checks for img.is_img
263
;	invoke	img.is_img, [img_data], [img_data_len]
264
;	or	eax, eax
265
;	jz	exit
1102 diamond 266
	invoke	img.decode, [img_data], [img_data_len], 0
1004 diamond 267
	or	eax, eax
268
	jz	.error
269
	cmp	[image], 0
1080 diamond 270
	pushf
1004 diamond 271
	mov	[image], eax
1080 diamond 272
	call	init_frame
273
	popf
1004 diamond 274
	call	update_image_sizes
275
	call	free_img_data
276
	clc
277
	ret
278
 
279
.error_free:
280
	invoke	img.destroy, [image]
281
	jmp	.error
282
 
283
.error_pop:
284
	pop	eax
285
	jmp	.error
286
.error_close:
287
	invoke	file.close, [fh]
288
.error:
289
	call	free_img_data
290
	stc
291
	ret
292
 
293
free_img_data:
294
	mov	eax, [img_data]
295
	test	eax, eax
296
	jz	@f
297
	stdcall	mem.Free, eax
298
@@:
299
	ret
300
 
301
update_image_sizes:
302
	pushf
303
	mov	edx, [eax + Image.Width]
1040 diamond 304
	mov	[draw_width], edx
1004 diamond 305
	add	edx, 19
1016 diamond 306
	cmp	edx, 40 + 25*9
1004 diamond 307
	jae	@f
1016 diamond 308
	mov	edx, 40 + 25*9
1004 diamond 309
@@:
310
	mov	[wnd_width], edx
311
	mov	esi, [eax + Image.Height]
1040 diamond 312
	mov	[draw_height], esi
1004 diamond 313
	add	esi, 44
314
	mov	[wnd_height], esi
315
	popf
316
	jz	.no_resize
317
	mcall	48, 4
318
	add	esi, eax
319
	mcall	67,-1,-1
320
.no_resize:
321
	ret
322
 
1016 diamond 323
set_as_bgr:
324
	mov	esi, [image]
325
	mov	ecx, [esi + Image.Width]
326
	mov	edx, [esi + Image.Height]
327
	mcall	15, 1
328
 
329
	mcall	15, 6
330
	test	eax, eax
331
	jz	@f
332
 
333
	push	eax
334
	invoke	img.to_rgb2, esi, eax
335
	pop	ecx
336
	mcall	15, 7
337
 
338
@@:
339
	mcall	15, 3
340
	ret
341
 
1427 diamond 342
; seek to ESI image files
343
; esi>0 means next file, esi<0 - prev file
344
next_or_prev_image:
345
	push	esi
1016 diamond 346
	call	load_directory
1427 diamond 347
	pop	esi
348
	mov	ebx, [directory_ptr]
349
	test	ebx, ebx
1016 diamond 350
	jz	.ret
1427 diamond 351
	cmp	dword[ebx+4], 0
352
	jz	.ret
1016 diamond 353
	mov	eax, [cur_file_idx]
354
	cmp	eax, -1
355
	jnz	@f
1427 diamond 356
	test	esi, esi
357
	jns	@f
1016 diamond 358
	mov	eax, [ebx+4]
359
@@:
360
	push	[image]
1427 diamond 361
	add	eax, esi
362
@@:
363
	test	eax, eax
1016 diamond 364
	jns	@f
1427 diamond 365
	add	eax, [ebx+4]
366
	jmp	@b
1016 diamond 367
@@:
1427 diamond 368
	cmp	eax, [ebx+4]
369
	jb	@f
370
	sub	eax, [ebx+4]
371
	jmp	@b
372
@@:
373
	push	eax
374
.scanloop:
375
	push	eax ebx esi
1016 diamond 376
	imul	esi, eax, 304
377
	add	esi, [directory_ptr]
378
	add	esi, 32 + 40
379
	mov	edi, curdir
380
@@:
381
	inc	edi
382
	cmp	byte [edi-1], 0
383
	jnz	@b
384
	mov	byte [edi-1], '/'
385
@@:
386
	lodsb
387
	stosb
388
	test	al, al
389
	jnz	@b
390
	mov	eax, curdir
391
	call	load_image
1040 diamond 392
	pushf
1016 diamond 393
	mov	esi, curdir
1040 diamond 394
	push	esi
1016 diamond 395
	mov	edi, @PARAMS
396
	mov	ecx, 512/4
397
	rep	movsd
398
	mov	byte [edi-1], 0
1040 diamond 399
	pop	esi
400
@@:
401
	lodsb
402
	test	al, al
403
	jnz	@b
404
@@:
405
	dec	esi
406
	cmp	byte [esi], '/'
407
	jnz	@b
408
	mov	byte [esi], 0
409
	popf
1427 diamond 410
	pop	esi ebx eax
411
	jnc	.loadedok
412
	test	esi, esi
413
	js	.try_prev
414
.try_next:
1016 diamond 415
	inc	eax
416
	cmp	eax, [ebx+4]
417
	jb	@f
418
	xor	eax, eax
419
@@:
1427 diamond 420
.try_common:
421
	cmp	eax, [esp]
1016 diamond 422
	jz	.notfound
1427 diamond 423
	jmp	.scanloop
424
.try_prev:
425
	dec	eax
426
	jns	@f
427
	mov	eax, [ebx+4]
428
	dec	eax
1016 diamond 429
@@:
1427 diamond 430
	jmp	.try_common
431
.loadedok:
1040 diamond 432
	mov	[cur_file_idx], eax
1427 diamond 433
	pop	eax
1040 diamond 434
	invoke	img.destroy
1427 diamond 435
	call	generate_header
1016 diamond 436
.ret:
437
	ret
438
.notfound:
1427 diamond 439
	pop	eax
1016 diamond 440
	pop	[image]
1080 diamond 441
	call	init_frame
1016 diamond 442
	ret
443
 
444
load_directory:
445
	cmp	[directory_ptr], 0
446
	jnz	.ret
447
	mov	esi, @PARAMS
448
	mov	edi, curdir
1427 diamond 449
	mov	ecx, [last_name_component]
450
	sub	ecx, esi
451
	dec	ecx
452
	js	@f
1016 diamond 453
	rep	movsb
1427 diamond 454
@@:
1016 diamond 455
	mov	byte [edi], 0
456
	mcall	68, 12, 0x1000
457
	test	eax, eax
458
	jz	.ret
459
	mov	ebx, readdir_fileinfo
460
	mov	dword [ebx+12], (0x1000 - 32) / 304
461
	mov	dword [ebx+16], eax
462
	mcall	70
463
	cmp	eax, 6
464
	jz	.dirok
465
	test	eax, eax
466
	jnz	free_directory
467
	mov	edx, [directory_ptr]
468
	mov	ecx, [edx+8]
469
	mov	[readblocks], ecx
470
	imul	ecx, 304
471
	add	ecx, 32
472
	mcall	68, 20
473
	test	eax, eax
474
	jz	free_directory
475
	mov	[directory_ptr], eax
476
	mcall	70, readdir_fileinfo
477
.dirok:
478
	cmp	ebx, 0
479
	jle	free_directory
480
	mov	eax, [directory_ptr]
481
	add	eax, 32
482
	mov	edi, eax
483
	push	0
484
.dirskip:
485
	push	eax
486
	test	byte [eax], 18h
487
	jnz	.nocopy
488
	lea	esi, [eax+40]
489
	mov	ecx, esi
490
@@:
491
	lodsb
492
	test	al, al
493
	jnz	@b
494
@@:
495
	dec	esi
496
	cmp	esi, ecx
497
	jb	.noext
498
	cmp	byte [esi], '.'
499
	jnz	@b
500
	inc	esi
501
	mov	ecx, [esi]
502
	or	ecx, 0x202020
503
	cmp	ecx, 'jpg'
504
	jz	.copy
505
	cmp	ecx, 'bmp'
506
	jz	.copy
507
	cmp	ecx, 'gif'
508
	jz	.copy
509
	cmp	ecx, 'png'
510
	jz	.copy
511
	cmp	ecx, 'jpe'
512
	jz	.copy
1102 diamond 513
	cmp	ecx, 'ico'
514
	jz	.copy
515
	cmp	ecx, 'cur'
516
	jz	.copy
1016 diamond 517
	cmp	ecx, 'jpeg'
518
	jz	@f
519
	cmp	ecx, 'jpeG'
520
	jnz	.nocopy
521
@@:
522
	cmp	byte [esi+4], 0
523
	jnz	.nocopy
524
.copy:
525
	mov	esi, [esp]
526
	mov	ecx, 304 / 4
527
	rep	movsd
528
	inc	dword [esp+4]
529
.nocopy:
530
.noext:
531
	pop	eax
532
	add	eax, 304
533
	dec	ebx
534
	jnz	.dirskip
535
	mov	eax, [directory_ptr]
536
	pop	ebx
537
	mov	[eax+4], ebx
538
	test	ebx, ebx
539
	jz	free_directory
1144 diamond 540
	push	0	; sort mode
541
	push	ebx
542
	add	eax, 32
543
	push	eax
544
	call	[SortDir]
1016 diamond 545
	xor	eax, eax
546
	mov	edi, [directory_ptr]
547
	add	edi, 32 + 40
548
.scan:
549
	mov	esi, [last_name_component]
1144 diamond 550
	push	edi
551
	invoke	strcmpi
552
	pop	edi
1016 diamond 553
	jz	.found
554
	inc	eax
555
	add	edi, 304
556
	dec	ebx
557
	jnz	.scan
558
	or	eax, -1
559
.found:
560
	mov	[cur_file_idx], eax
561
.ret:
562
	ret
563
 
564
free_directory:
565
	mcall	68, 13, [directory_ptr]
566
	and	[directory_ptr], 0
567
	ret
568
 
1427 diamond 569
; in: esi->full name (e.g. /path/to/file.png)
570
; out: [last_name_component]->last component (e.g. file.png)
571
find_last_name_component:
572
	mov	ecx, esi
573
@@:
574
	lodsb
575
	test	al, al
576
	jnz	@b
577
@@:
578
	dec	esi
579
	cmp	esi, ecx
580
	jb	@f
581
	cmp	byte [esi], '/'
582
	jnz	@b
583
@@:
584
	inc	esi
585
	mov	[last_name_component], esi
586
	ret
587
 
1080 diamond 588
init_frame:
589
	push	eax
590
	mov	eax, [image]
591
	mov	[cur_frame], eax
592
	test	byte [eax + Image.Flags], Image.IsAnimated
593
	jz	@f
594
	push	ebx
595
	mcall	26, 9
596
	pop	ebx
597
	mov	[cur_frame_time], eax
598
@@:
599
	pop	eax
600
	ret
601
 
1004 diamond 602
draw_window:
1040 diamond 603
	cmp	[bFirstDraw], 0
604
	jz	.posok
605
	or	ecx, -1
606
	mcall	9, procinfo
607
 
608
	cmp	dword [ebx + 66], 0
1087 diamond 609
	jle	.posok
1040 diamond 610
 
611
	mov	edx, ecx
612
	mov	esi, ecx
613
	cmp	dword [ebx + 42], 40 + 25 * 9
614
	jae	@f
615
	mov	edx, 40 + 25 * 9
616
@@:
617
	cmp	dword [ebx + 46], 70
618
	jae	@f
619
	mov	esi, 70
620
@@:
621
	mov	eax, edx
622
	and	eax, esi
623
	cmp	eax, -1
624
	jz	@f
625
	mov	ebx, ecx
626
	mcall	67
627
@@:
628
 
629
.posok:
630
	mcall	12, 1
1004 diamond 631
	mcall	48, 4
632
	mov	ebp, eax	; save skin height
633
	add	eax, [wnd_height]
634
	__mov	ebx, 100, 0
635
	add	ebx, [wnd_width]
636
	lea	ecx, [100*65536 + eax]
1427 diamond 637
	mcall	0, , , 0x73FFFFFF, 0, real_header
1004 diamond 638
 
639
	mcall	9, procinfo, -1
1040 diamond 640
	mov	[bFirstDraw], 1
1087 diamond 641
	cmp	dword [ebx + 66], 0
642
	jle	.nodraw
643
	mov	ebx, [ebx + 62]
1016 diamond 644
	inc	ebx
1004 diamond 645
	mcall	13, , <0, 35>, 0xFFFFFF
1016 diamond 646
	mov	ecx, [procinfo + 66]
1040 diamond 647
	inc	ecx
648
	mov	esi, [draw_height]
649
	add	esi, 35
650
	sub	ecx, esi
651
	jbe	@f
652
	push	esi
653
	shl	esi, 16
654
	add	ecx, esi
655
	pop	esi
1004 diamond 656
	mcall
1040 diamond 657
	xor	ecx, ecx
658
@@:
659
	add	ecx, esi
660
	add	ecx, 35*10000h - 35
661
	__mov	ebx, 0, 5
1004 diamond 662
	mcall
1040 diamond 663
	mov	esi, [draw_width]
664
	add	esi, ebx
665
	mov	ebx, [procinfo+62]
666
	inc	ebx
1004 diamond 667
	sub	ebx, esi
1040 diamond 668
	jbe	@f
669
	shl	esi, 16
1004 diamond 670
	add	ebx, esi
671
	mcall
1040 diamond 672
@@:
1004 diamond 673
 
1016 diamond 674
	mov	ebx, [procinfo + 62]
675
	push	ebx
676
	mcall	38, , <30, 30>, 0x007F7F7F
677
	mcall	, <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
678
	mcall	, <10 + 25 * 3, 10 + 25 * 3>
679
	mcall	, <15 + 25 * 4, 15 + 25 * 4>
680
	pop	ebx
681
	sub	ebx, 25 * 5 + 10
682
	push	ebx
683
	imul	ebx, 10001h
684
	mcall
1004 diamond 685
 
686
	mcall	8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
1016 diamond 687
	mcall	, <10 + 25 * 1, 20>, , 'bck'+40000000h
688
	mcall	, <10 + 25 * 2, 20>, , 'fwd'+40000000h
689
	mcall	, <15 + 25 * 3, 20>, , 'bgr'+40000000h
690
	pop	ebx
691
	add	ebx, 5
692
	shl	ebx, 16
693
	mov	bl, 20
694
	mcall	, , , 'flh'+40000000h
695
	add	ebx, 25 * 65536
696
	mcall	, , , 'flv'+40000000h
697
	add	ebx, 30 * 65536
698
	mcall	, , , 'rtr'+40000000h
699
	add	ebx, 25 * 65536
700
	mcall	, , , 'rtl'+40000000h
701
	add	ebx, 25 * 65536
702
	mcall	, , , 'flb'+40000000h
1004 diamond 703
 
1016 diamond 704
	mov	ebp, (numimages-1)*20
1004 diamond 705
 
1016 diamond 706
	mcall	65, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
707
	mcall	, buttons+backbtn*20, , <10 + 25 * 1, 5>
708
	mcall	, buttons+forwardbtn*20, , <10 + 25 * 2, 5>
709
	mcall	, buttons+bgrbtn*20, , <15 + 25 * 3, 5>
710
	mov	edx, [procinfo + 62]
711
	sub	edx, 25 * 5 + 4
712
	shl	edx, 16
713
	mov	dl, 5
714
	mcall	, buttons+fliphorzbtn*20
715
	add	edx, 25 * 65536
716
	mcall	, buttons+flipvertbtn*20
717
	add	edx, 30 * 65536
718
	mcall	, buttons+rotcwbtn*20
719
	add	edx, 25 * 65536
720
	mcall	, buttons+rotccwbtn*20
721
	add	edx, 25 * 65536
722
	mcall	, buttons+rot180btn*20
1004 diamond 723
 
1080 diamond 724
	call	draw_cur_frame
1004 diamond 725
 
1087 diamond 726
.nodraw:
1040 diamond 727
	mcall	12, 2
728
 
1004 diamond 729
	ret
730
 
1080 diamond 731
draw_cur_frame:
732
	push	0	; ypos
733
	push	0	; xpos
734
	mov	eax, [procinfo+66]
735
	sub	eax, 34
736
	push	eax	; max height
737
	mov	eax, [procinfo+62]
738
	sub	eax, 4
739
	push	eax	; max width
740
	push	35	; y
741
	push	5	; x
742
	push	[cur_frame]
743
	call	[img.draw]
1102 diamond 744
	mov	eax, [image]
745
	test	[eax + Image.Flags], Image.IsAnimated
746
	jnz	.done
747
	cmp	[eax + Image.Next], 0
748
	jnz	.additional_frames
749
.done:
1080 diamond 750
	ret
1102 diamond 751
.additional_frames:
752
	mov	ebx, [procinfo+62]
753
	sub	ebx, 4
754
	jbe	.done
755
	push	5
756
	pop	esi
757
.afloop:
758
	sub	ebx, [eax + Image.Width]
759
	jbe	.done
760
	dec	ebx
761
	jz	.done
762
	add	esi, [eax + Image.Width]
763
	mov	eax, [eax + Image.Next]
764
	push	eax
765
	inc	esi
766
	push	0	; ypos
767
	push	0	; xpos
768
	mov	ecx, [procinfo+66]
769
	sub	ecx, 34
770
	push	ecx	; max height
771
	push	ebx	; max width
772
	push	35	; y
773
	push	esi	; x
774
	push	eax	; image
775
	call	[img.draw]
776
	pop	eax
777
	cmp	[eax + Image.Next], 0
778
	jnz	.afloop
779
	ret
1080 diamond 780
 
1004 diamond 781
; void* __stdcall mem.Alloc(unsigned size);
782
mem.Alloc:
783
	push	ebx ecx
784
	mov	ecx, [esp+12]
785
	mcall	68, 12
786
	pop	ecx ebx
787
	ret	4
788
 
789
; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
790
mem.ReAlloc:
791
	push	ebx ecx edx
792
	mov	edx, [esp+16]
793
	mov	ecx, [esp+20]
794
	mcall	68, 20
795
	pop	edx ecx ebx
796
	ret	8
797
 
798
; void __stdcall mem.Free(void* mptr);
799
mem.Free:
800
	push	ebx ecx
801
	mov	ecx, [esp+12]
802
	mcall	68, 13
803
	pop	ecx ebx
804
	ret	4
805
 
1427 diamond 806
check_shortcut:
807
; in:	cl = scancode (from sysfn 2),
808
;	eax = state of modifiers (from sysfn 66.3),
809
;	edx -> shortcut descriptor
810
; out:	ZF set <=> fail
811
	cmp	cl, [edx+4]
812
	jnz	.not
813
	push	eax
814
	mov	esi, [edx]
815
	and	esi, 0xF
816
	and	al, 3
817
	call	dword [check_modifier_table+esi*4]
818
	test	al, al
819
	pop	eax
820
	jnz	.not
821
	push	eax
822
	mov	esi, [edx]
823
	shr	esi, 4
824
	and	esi, 0xF
825
	shr	al, 2
826
	and	al, 3
827
	call	dword [check_modifier_table+esi*4]
828
	test	al, al
829
	pop	eax
830
	jnz	.not
831
	push	eax
832
	mov	esi, [edx]
833
	shr	esi, 8
834
	and	esi, 0xF
835
	shr	al, 4
836
	and	al, 3
837
	call	dword [check_modifier_table+esi*4]
838
	test	al, al
839
	pop	eax
840
;	jnz	.not
841
.not:
842
	ret
843
 
844
check_modifier_0:
845
	setnz	al
846
	ret
847
check_modifier_1:
848
	setp	al
849
	ret
850
check_modifier_2:
851
	cmp	al, 3
852
	setnz	al
853
	ret
854
check_modifier_3:
855
	cmp	al, 1
856
	setnz	al
857
	ret
858
check_modifier_4:
859
	cmp	al, 2
860
	setnz	al
861
	ret
862
 
863
; fills real_header with window title
864
; window title is generated as ' - Kolibri Image Viewer'
865
generate_header:
866
	push	eax
867
	mov	esi, [last_name_component]
868
	mov	edi, real_header
869
@@:
870
	lodsb
871
	test	al, al
872
	jz	@f
873
	stosb
874
	cmp	edi, real_header+256
875
	jb	@b
876
.overflow:
877
	mov	dword [edi-4], '...'
878
.ret:
879
	pop	eax
880
	ret
881
@@:
882
	mov	esi, s_header
883
@@:
884
	lodsb
885
	stosb
886
	test	al, al
887
	jz	.ret
888
	cmp	edi, real_header+256
889
	jb	@b
890
	jmp	.overflow
891
 
1004 diamond 892
;-----------------------------------------------------------------------------
893
 
1427 diamond 894
s_header db ' - Kolibri Image Viewer', 0
1004 diamond 895
 
896
;-----------------------------------------------------------------------------
897
 
898
opendialog:
899
;
900
; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
901
; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
902
;
903
 
904
;;    mov esi,path
905
    mov edi,path
906
    xor eax,eax
907
    mov ecx,(1024+16)/4
908
    rep stosd
909
 
910
;mov [get_loops],0
911
mov [dlg_pid_get],0
912
 
913
; Get my PID in dec format 4 bytes
914
    mov eax,9
915
    mov ebx,procinfo
916
    or  ecx,-1
917
    mcall
918
 
919
; convert eax bin to param dec
920
    mov eax,dword [procinfo+30]  ;offset of myPID
921
    mov edi,param+4-1		 ;offset to 4 bytes
922
    mov ecx,4
923
    mov ebx,10
924
new_d:
925
    xor edx,edx
926
    div ebx
927
    add dl,'0'
928
    mov [edi],dl
929
    dec edi
930
    loop new_d
931
 
932
; wirite 1 byte space to param
933
    mov [param+4],byte 32    ;Space for next parametr
934
; and 1 byte type of dialog to param
935
    mov [param+5],byte 'O'   ;Get Open dialog (Use 'S' for Save dialog)
936
 
937
;
938
; STEP2 prepare IPC area for get messages
939
;
940
 
941
; prepare IPC area
942
    mov [path],dword 0
943
    mov [path+4],dword 8
944
 
945
; define IPC memory
946
    mov eax,60
947
    mov ebx,1	     ; define IPC
948
    mov ecx,path     ; offset of area
949
    mov edx,1024+16  ; size
950
    mcall
951
 
952
; change wanted events list 7-bit IPC event
953
    mov eax,40
954
    mov ebx,01000111b
955
	cmp	[image], 0
956
	jnz	@f
957
	mov	bl, 01000110b
958
@@:
959
    mcall
960
 
961
;
962
; STEP 3 run SYSTEM XTREE with parameters
963
;
964
 
965
    mov eax,70
966
    mov ebx,run_fileinfo
967
    mcall
968
 
969
    mov [get_loops],0
970
getmesloop:
971
    mov eax,23
972
    mov ebx,50	   ;0.5 sec
973
    mcall
974
        dec     eax
975
        jz      mred
976
        dec     eax
977
        jz      mkey
978
        dec     eax
979
        jz      mbutton
980
        cmp     al, 7-3
981
        jz      mgetmes
982
 
983
; Get number of procces
984
    mov ebx,procinfo
985
    mov ecx,-1
986
    mov eax,9
987
    mcall
988
    mov ebp,eax
989
 
990
loox:
991
    mov eax,9
992
    mov ebx,procinfo
993
    mov ecx,ebp
994
    mcall
995
    mov eax,[DLGPID]
996
    cmp [procinfo+30],eax    ;IF Dialog find
997
    je	dlg_is_work	     ;jmp to dlg_is_work
998
    dec ebp
999
    jnz loox
1000
 
1001
    jmp erroff
1002
 
1003
dlg_is_work:
1004
    cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
1005
    je	erroff		       ;TESTODP2 terminated too
1006
 
1007
    cmp [dlg_pid_get],dword 1
1008
    je	getmesloop
1009
    inc [get_loops]
1010
    cmp [get_loops],4  ;2 sec if DLG_PID not get, TESTOP2  terminated
1011
    jae erroff
1012
    jmp getmesloop
1013
 
1014
mred:
1015
	cmp	[image], 0
1016
	jz	getmesloop
1017
    call draw_window
1018
    jmp  getmesloop
1019
mkey:
1020
    mov  eax,2
1021
    mcall			; read (eax=2)
1022
    jmp  getmesloop
1023
mbutton:
1024
    mov  eax,17 		; get id
1025
    mcall
1026
    cmp  ah,1			; button id=1 ?
1027
    jne  getmesloop
1028
    mov  eax,-1 		; close this program
1029
    mcall
1030
mgetmes:
1031
 
1032
; If dlg_pid_get then second message get jmp to still
1033
    cmp  [dlg_pid_get],dword 1
1034
    je	 ready
1035
 
1036
; First message is number of PID SYSXTREE dialog
1037
 
1038
; convert PID dec to PID bin
1039
    movzx eax,byte [path+16]
1040
    sub eax,48
1041
    imul eax,10
1042
    movzx ebx,byte [path+16+1]
1043
    add eax,ebx
1044
    sub eax,48
1045
    imul eax,10
1046
    movzx ebx,byte [path+16+2]
1047
    add eax,ebx
1048
    sub eax,48
1049
    imul eax,10
1050
    movzx ebx,byte [path+16+3]
1051
    add eax,ebx
1052
    sub eax,48
1053
    mov [DLGPID],eax
1054
 
1055
; Claear and prepare IPC area for next message
1056
    mov [path],dword 0
1057
    mov [path+4],dword 8
1058
    mov [path+8],dword 0
1059
    mov [path+12],dword 0
1060
    mov [path+16],dword 0
1061
 
1062
; Set dlg_pid_get for get next message
1063
    mov [dlg_pid_get],dword 1
1064
	cmp	[image], 0
1065
	jz	getmesloop
1066
    call draw_window
1067
    jmp  getmesloop
1068
 
1069
ready:
1070
;
1071
; The second message get
1072
; Second message is 100 bytes path to SAVE/OPEN file
1073
; shl path string on 16 bytes
1074
;
1075
    mov esi,path+16
1076
    mov edi,path
1077
    mov ecx,1024/4
1078
    rep movsd
1079
    mov [edi],byte 0
1080
 
1081
openoff:
1082
	mcall	40, 7
1083
	clc
1084
	ret
1085
 
1086
erroff:
1087
	mcall	40, 7
1088
	stc
1089
	ret
1090
 
1091
;-----------------------------------------------------------------------------
1092
 
1093
align 4
1094
@IMPORT:
1095
 
1096
library 			\
1097
	libio  , 'libio.obj'  , \
1098
	libgfx , 'libgfx.obj' , \
1144 diamond 1099
	libimg , 'libimg.obj' , \
1427 diamond 1100
	libini , 'libini.obj' , \
1144 diamond 1101
	sort   , 'sort.obj'
1004 diamond 1102
 
1103
import	libio			  , \
1104
	libio.init , 'lib_init'   , \
1102 diamond 1105
	file.size  , 'file_size'  , \
1106
	file.open  , 'file_open'  , \
1107
	file.read  , 'file_read'  , \
1108
	file.close , 'file_close'
1004 diamond 1109
 
1110
import	libgfx				, \
1111
	libgfx.init   , 'lib_init'	, \
1102 diamond 1112
	gfx.open      , 'gfx_open'	, \
1113
	gfx.close     , 'gfx_close'	, \
1114
	gfx.pen.color , 'gfx_pen_color' , \
1115
	gfx.line      , 'gfx_line'
1004 diamond 1116
 
1117
import	libimg			   , \
1118
	libimg.init , 'lib_init'   , \
1102 diamond 1119
	img.is_img  , 'img_is_img' , \
1120
	img.to_rgb2 , 'img_to_rgb2', \
1121
	img.decode  , 'img_decode' , \
1122
	img.flip    , 'img_flip'   , \
1123
	img.rotate  , 'img_rotate' , \
1124
	img.destroy , 'img_destroy', \
1125
	img.draw    , 'img_draw'
1004 diamond 1126
 
1427 diamond 1127
import	libini, \
1128
	ini_get_shortcut, 'ini_get_shortcut'
1129
 
1144 diamond 1130
import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
1016 diamond 1131
 
1040 diamond 1132
bFirstDraw	db	0
1004 diamond 1133
;-----------------------------------------------------------------------------
1134
 
1016 diamond 1135
virtual at 0
1136
file 'kivicons.bmp':0xA,4
1137
load offbits dword from 0
1138
end virtual
1139
numimages = 9
1140
openbtn = 0
1141
backbtn = 1
1142
forwardbtn = 2
1143
bgrbtn = 3
1144
fliphorzbtn = 4
1145
flipvertbtn = 5
1146
rotcwbtn = 6
1147
rotccwbtn = 7
1148
rot180btn = 8
1149
 
1004 diamond 1150
palette:
1016 diamond 1151
	file 'kivicons.bmp':0x36,offbits-0x36
1152
buttons:
1153
	file 'kivicons.bmp':offbits
1004 diamond 1154
repeat 10
1155
y = % - 1
1156
z = 20 - %
1016 diamond 1157
repeat numimages*5
1158
load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
1159
load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
1160
store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
1161
store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
1004 diamond 1162
end repeat
1163
end repeat
1164
 
1427 diamond 1165
inifilename	db	'/sys/media/kiv.ini',0
1166
aShortcuts	db	'Shortcuts',0
1167
aNext		db	'Next',0
1168
aPrev		db	'Prev',0
1169
 
1170
align 4
1171
check_modifier_table:
1172
	dd	check_modifier_0
1173
	dd	check_modifier_1
1174
	dd	check_modifier_2
1175
	dd	check_modifier_3
1176
	dd	check_modifier_4
1177
 
1004 diamond 1178
; DATA AREA
1179
get_loops   dd 0
1180
dlg_pid_get dd 0
1181
DLGPID	    dd 0
1182
 
1183
param:
1184
   dd 0    ; My dec PID
1185
   dd 0,0  ; Type of dialog
1186
 
1187
run_fileinfo:
1188
 dd 7
1189
 dd 0
1190
 dd param
1191
 dd 0
1192
 dd 0
1193
;run_filepath
1194
 db '/sys/SYSXTREE',0
1195
 
1016 diamond 1196
readdir_fileinfo:
1197
	dd	1
1198
	dd	0
1199
	dd	0
1200
readblocks dd	0
1201
directory_ptr	dd	0
1202
 
1004 diamond 1203
;-----------------------------------------------------------------------------
1204
 
1205
I_END:
1206
 
1016 diamond 1207
curdir		rb	1024
1208
 
1209
align 4
1004 diamond 1210
img_data     dd ?
1211
img_data_len dd ?
1212
fh	     dd ?
1213
image	     dd ?
1214
wnd_width	dd	?
1215
wnd_height	dd	?
1040 diamond 1216
draw_width	dd	?
1217
draw_height	dd	?
1016 diamond 1218
last_name_component	dd	?
1219
cur_file_idx	dd	?
1080 diamond 1220
cur_frame_time	dd	?
1221
cur_frame	dd	?
1004 diamond 1222
 
1427 diamond 1223
next_mod	dd	?
1224
next_key	dd	?
1225
prev_mod	dd	?
1226
prev_key	dd	?
1004 diamond 1227
 
1228
procinfo:	rb	1024
1229
path:		rb	1024+16
1427 diamond 1230
real_header	rb	256
1004 diamond 1231
 
1232
@PARAMS rb 512