Subversion Repositories Kolibri OS

Rev

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