Subversion Repositories Kolibri OS

Rev

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