Fresh IDE . Check-in [fe507f8504]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work on the proper image wrapping. Now there is a problem with the repainting when the image wrapX/wrapY changes and the orgX/orgY are not 0; On such operation, some tearing in the middle of the image appears, hence need to be repainted - by copying the teared off parts where they belongs. (the _screen image wrapX/Y) changes and the orgX/Y are not 0;
Timelines: family | ancestors | descendants | both | NoCanvasGUI
Files: files | file ages | folders
SHA1:fe507f85048e71071349193258fa5ecc271046a5
User & Date: johnfound 2017-11-08 13:32:03
Context
2017-11-12
07:58
Some implementation of the SetImageWrap procedure. It has problems when the wrapW/H becomes less than orgX/Y; And the algorithm is pretty complex. Need some general algorithmic fix. check-in: 2d85be0cb6 user: johnfound tags: NoCanvasGUI
2017-11-08
13:32
Work on the proper image wrapping. Now there is a problem with the repainting when the image wrapX/wrapY changes and the orgX/orgY are not 0; On such operation, some tearing in the middle of the image appears, hence need to be repainted - by copying the teared off parts where they belongs. (the _screen image wrapX/Y) changes and the orgX/Y are not 0; check-in: fe507f8504 user: johnfound tags: NoCanvasGUI
2017-11-07
12:27
Fixed bug in random.asm (Win32 and Linux) causing resource leaks and defered crash.

Working on the 0-move scroll for TImage (by moving the image origin) - DrawImageRect funtions for Windows and Linux are adapted for the new standard.

Added test project (TestGraphics) for this feature.

Added debugging FPS display (see options.DebugMode.ShowFPS).

Work on the remaining aspects of the GUI engine. check-in: 993829fb8c user: johnfound tags: NoCanvasGUI

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/graphics/Linux/images.asm.

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
        mov     edi, [.maskUL.right]
        add     [.xDst], edi
        call    .DoDraw

.lower_right_ok:

; now, wait for the events:

        cinvoke XFlushGC, [hApplicationDisplay], [.gc]
        cinvoke XFlush, [hApplicationDisplay]

.event_wait:
        dec     [.cnt_events]
        js      .events_ok








<







332
333
334
335
336
337
338

339
340
341
342
343
344
345
        mov     edi, [.maskUL.right]
        add     [.xDst], edi
        call    .DoDraw

.lower_right_ok:

; now, wait for the events:

        cinvoke XFlushGC, [hApplicationDisplay], [.gc]
        cinvoke XFlush, [hApplicationDisplay]

.event_wait:
        dec     [.cnt_events]
        js      .events_ok

Changes to freshlib/graphics/images.asm.

268
269
270
271
272
273
274
275
276
277
278
279
280
281





282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502

503
504
505
506
507
508
509
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
...
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
  if ~ dst eq edx
        mov     dst, edx
  end if
..ok:
}


proc BlendImageTileWrap, .pDstImage, .xDst, .yDst, .wDst, .hDst, .pSrcImage, .xSrc, .ySrc, .wSrc, .hSrc

.startYSrc dd ?
.endYSrc   dd ?

.startYDst dd ?
.endYDst   dd ?






.stepYSrc dd ?
.stepYDst dd ?

.endXSrc  dd ?
.endXDst  dd ?

.imgWSrc dd ?
.imgWDst dd ?

.img0Src dd ?
.imgHSrc dd ?

.img0Dst dd ?
.imgHDst dd ?

begin
        pushad

        mov     esi, [.pSrcImage]
        mov     edi, [.pDstImage]

................................................................................
; lock the images.
        stdcall LockImg, esi
        jc      .finish

        stdcall LockImg, edi
        jc      .finish2

; ensure width and height parameters are in the bounds of the images.

        mov     eax, [.wSrc]
        mov     ebx, [.hSrc]
        mov     ecx, [.wDst]
        mov     edx, [.hDst]

        cmp     eax, [esi+TImage.width]
        cmova   eax, [esi+TImage.width]

        cmp     ebx, [esi+TImage.height]
        cmova   ebx, [esi+TImage.height]

        cmp     ecx, [edi+TImage.width]
        cmova   ecx, [edi+TImage.width]

        cmp     edx, [edi+TImage.height]
        cmova   edx, [edi+TImage.height]

        mov     [.wSrc], eax
        mov     [.hSrc], ebx
        mov     [.wDst], ecx
        mov     [.hDst], edx

; ensure the x,y coordinates are in the bounds of the images.

        scale   [.xSrc], [esi+TImage.width]
        scale   [.ySrc], [esi+TImage.height]
        scale   [.xDst], [edi+TImage.width]
        scale   [.yDst], [edi+TImage.height]

; step Y, source, destination

        mov     ecx, [esi+TImage.width]
        mov     edx, [edi+TImage.width]
        shl     ecx, 2
        shl     edx, 2
        mov     [.stepYSrc], ecx
        mov     [.stepYDst], edx

; start, end Y source destination

        mov     ecx, [.ySrc]
        mov     edx, [.yDst]
        imul    ecx, [esi+TImage.width]
        imul    edx, [edi+TImage.width]
        shl     ecx, 2
        shl     edx, 2
        add     ecx, [esi+TImage.pPixels]
        add     edx, [edi+TImage.pPixels]
        mov     [.startYSrc], ecx
        mov     [.startYDst], edx

        mov     eax, [.ySrc]
        add     eax, [.hSrc]
        dec     eax
        scale   eax, [esi+TImage.height]
        inc     eax
        shl     eax, 2
        imul    eax, [esi+TImage.width]
        add     eax, [esi+TImage.pPixels]
        mov     [.endYSrc], eax

        mov     eax, [.yDst]
        add     eax, [.hDst]
        dec     eax
        scale   eax, [edi+TImage.height]
        inc     eax
        shl     eax, 2
        imul    eax, [edi+TImage.width]
        add     eax, [edi+TImage.pPixels]
        mov     [.endYDst], eax

; end X source destination

        mov     eax, [.xSrc]
        add     eax, [.wSrc]
        dec     eax
        scale   eax, [esi+TImage.width]
        inc     eax
        mov     [.endXSrc], eax

        mov     eax, [.xDst]
        add     eax, [.wDst]
        dec     eax
        scale   eax, [edi+TImage.width]
        inc     eax
        mov     [.endXDst], eax

; image width source destination

        mov     ecx, [esi+TImage.width]
        mov     edx, [edi+TImage.width]
        mov     [.imgWSrc], ecx
        mov     [.imgWDst], edx

; image height source, destination

        mov     ecx, [esi+TImage.pPixels]
        mov     edx, [edi+TImage.pPixels]

        mov     [.img0Src], ecx
        mov     [.img0Dst], edx

        mov     eax, [esi+TImage.height]
        shl     eax, 2
        imul    eax, [esi+TImage.width]
        add     eax, ecx
        mov     [.imgHSrc], eax

        mov     eax, [edi+TImage.height]
        shl     eax, 2
        imul    eax, [edi+TImage.width]
        add     eax, edx
        mov     [.imgHDst], eax

; pixel pointers

        mov     esi, [.startYSrc]
        mov     edi, [.startYDst]

; prepare MMX constants

        pxor    mm0, mm0        ; mm0 = 0000 0000 0000 0000
        pcmpeqw mm1, mm1                                        ; mm1 = ffff ffff ffff ffff
        psrlw   mm1, 8                                         ; mm1 = 00ff 00ff 00ff 00ff

;        psrlw   mm1, 15                                         ; mm1 = 0001 0001 0001 0001
;        psllw   mm1, 8          ; mm1 = 0100 0100 0100 0100

.loopY:
        mov     ecx, [.xSrc]
        mov     edx, [.xDst]
        mov     eax, [.wDst]

.loopX:
        dec     eax
        js      .nextY

        cmp     ecx, [.endXSrc]
        cmove   ecx, [.xSrc]

        cmp     edx, [.endXDst]
        cmove   edx, [.xDst]

        movd    mm7, [esi+4*ecx]        ; source pixel.
        movd    mm6, [edi+4*edx]        ; destination pixel.

        movq    mm5, mm7
        psrlq   mm5, 24                 ; alpha source
        punpckldq mm5, mm5
................................................................................
        paddusw mm6, mm7                ; Cd = Cs + Cd
        psrlw   mm6, 8                  ; Cd = Cd/256

        packuswb mm6, mm0               ; pack words to bytes 0A 0R 0G 0B -> 0000ARGB
        movd     [edi+4*edx], mm6

        inc     ecx
        cmp     ecx, [.imgWSrc]
        jnz     @f
        xor     ecx, ecx
@@:
        inc     edx
        cmp     edx, [.imgWDst]
        jne     .loopX
        xor     edx, edx
        jmp     .loopX

.nextY:
        add     esi, [.stepYSrc]
        cmp     esi, [.endYSrc]
        cmove   esi, [.startYSrc]
        cmp     esi, [.imgHSrc]
        cmove   esi, [.img0Src]

        add     edi, [.stepYDst]
        cmp     edi, [.imgHDst]
        cmove   edi, [.img0Dst]

        dec     [.hDst]
        jnz     .loopY


        emms

; unlock the images.
        stdcall UnlockImg, [.pDstImage]

.finish2:
        stdcall UnlockImg, [.pSrcImage]
................................................................................
; lock the images.
        stdcall LockImg, esi
        jc      .finish

        stdcall LockImg, edi
        jc      .finish2

























        mov     ecx, [esi+TImage.WrapRect.right]
        mov     edx, [esi+TImage.WrapRect.bottom]
        sub     ecx, [esi+TImage.WrapRect.left]
        sub     edx, [esi+TImage.WrapRect.top]
        dec     ecx
        dec     edx
        mov     eax, [esi+TImage.offsX]
................................................................................
        mov     eax, [esi+TImage.ClipRect.left]
        mov     ebx, [esi+TImage.ClipRect.top]
        mov     ecx, [esi+TImage.ClipRect.
        mov     [.srect.left], eax
        mov     [.srect.top], eax


        mov     ecx, [esi+TImage.ClipRect.



; ensure width and height parameters are in the bounds of the images.

        mov     eax, [.wSrc]
        mov     ebx, [.hSrc]







|

|
|

|
|
>
>
>
>
>




|
|
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<









|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<






|
|

|
|







 







<
<
<
<

<
<
<




|
|
<
<


|
|
<
<
|

>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292









293
294
295
296
297
298
299
...
300
301
302
303
304
305
306































307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401







402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
...
430
431
432
433
434
435
436




437



438
439
440
441
442
443


444
445
446
447


448
449
450
451
452
453
454
455
456
457
...
586
587
588
589
590
591
592
























593
594
595
596
597
598
599
...
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
  if ~ dst eq edx
        mov     dst, edx
  end if
..ok:
}


proc BlendImageTileWrap, .pDstImage, .xDst, .yDst, .wDst, .hDst, .pSrcImage

.srcXOffs dd ?
.srcXwrap dd ?

.srcYoffs dd ?
.srcYwrap dd ?

.dstXbegn dd ?
.dstXwrap dd ?
.dstYoffs dd ?
.dstYwrap dd ?

.stepYSrc dd ?
.stepYDst dd ?

.srcY0    dd ?
.dstY0    dd ?










begin
        pushad

        mov     esi, [.pSrcImage]
        mov     edi, [.pDstImage]

................................................................................
; lock the images.
        stdcall LockImg, esi
        jc      .finish

        stdcall LockImg, edi
        jc      .finish2
































; step Y, source, destination

        mov     ecx, [esi+TImage.width]
        mov     edx, [edi+TImage.width]
        shl     ecx, 2
        shl     edx, 2
        mov     [.stepYSrc], ecx
        mov     [.stepYDst], edx

; Destination Y offset + wrap:

        mov     eax, [.yDst]
        mov     ebx, [edi+TImage.wrapH]

        add     eax, [edi+TImage.orgY]
        cmp     eax, ebx
        jb      @f
        sub     eax, ebx
@@:
        mov     ecx, [edi+TImage.pPixels]

        imul    eax, edx
        imul    ebx, edx
        add     eax, ecx
        add     ebx, ecx

        mov     [.dstYoffs], eax
        mov     [.dstYwrap], ebx
        mov     [.dstY0], ecx

        mov     ecx, [edi+TImage.wrapW]
        mov     [.dstXwrap], ecx

; Destination X start:

        mov     eax, [.xDst]
        add     eax, [edi+TImage.orgX]
        cmp     eax, ecx
        jb      @f
        sub     eax, ecx
@@:
        mov     [.dstXbegn], eax

; Source offset X,Y

        mov     eax, [.xDst]
        mov     ecx, [esi+TImage.wrapW]
        cdq
        div     ecx
        add     edx, [esi+TImage.orgX]
        cmp     edx, ecx
        jb      @f
        sub     edx, ecx
@@:
        mov     [.srcXOffs], edx
        mov     [.srcXwrap], ecx

        mov     eax, [.yDst]
        mov     ecx, [esi+TImage.wrapH]
        mov     ebx, [esi+TImage.pPixels]
        cdq
        div     ecx
        add     edx, [esi+TImage.orgY]
        cmp     edx, ecx
        jb      @f
        sub     edx, ecx
@@:
        imul    edx, [.stepYSrc]
        imul    ecx, [.stepYSrc]
        add     edx, ebx
        add     ecx, ebx
        mov     [.srcYoffs], edx
        mov     [.srcYwrap], ecx
        mov     [.srcY0],    ebx

; prepare MMX constants

        pxor    mm0, mm0        ; mm0 = 0000 0000 0000 0000
        pcmpeqw mm1, mm1                                        ; mm1 = ffff ffff ffff ffff
        psrlw   mm1, 8                                         ; mm1 = 00ff 00ff 00ff 00ff

;        psrlw   mm1, 15                                         ; mm1 = 0001 0001 0001 0001
;        psllw   mm1, 8                                          ; mm1 = 0100 0100 0100 0100

        xor     ebx, ebx
        mov     esi, [.srcYoffs]
        mov     edi, [.dstYoffs]


.loopY:
        dec     [.hDst]
        js      .exit

        mov     ecx, [.srcXOffs]
        mov     edx, [.dstXbegn]







        mov     eax, [.wDst]

.loopX:
        dec     eax
        js      .nextY

        cmp     ecx, [.srcXwrap]
        cmovae  ecx, ebx

        cmp     edx, [.dstXwrap]
        cmovae  edx, ebx

        movd    mm7, [esi+4*ecx]        ; source pixel.
        movd    mm6, [edi+4*edx]        ; destination pixel.

        movq    mm5, mm7
        psrlq   mm5, 24                 ; alpha source
        punpckldq mm5, mm5
................................................................................
        paddusw mm6, mm7                ; Cd = Cs + Cd
        psrlw   mm6, 8                  ; Cd = Cd/256

        packuswb mm6, mm0               ; pack words to bytes 0A 0R 0G 0B -> 0000ARGB
        movd     [edi+4*edx], mm6

        inc     ecx




        inc     edx



        jmp     .loopX

.nextY:
        add     esi, [.stepYSrc]
        cmp     esi, [.srcYwrap]
        cmovae  esi, [.srcY0]



        add     edi, [.stepYDst]
        cmp     edi, [.dstYwrap]
        cmovae  edi, [.dstY0]


        jmp     .loopY

.exit:
        emms

; unlock the images.
        stdcall UnlockImg, [.pDstImage]

.finish2:
        stdcall UnlockImg, [.pSrcImage]
................................................................................
; lock the images.
        stdcall LockImg, esi
        jc      .finish

        stdcall LockImg, edi
        jc      .finish2

























        mov     ecx, [esi+TImage.WrapRect.right]
        mov     edx, [esi+TImage.WrapRect.bottom]
        sub     ecx, [esi+TImage.WrapRect.left]
        sub     edx, [esi+TImage.WrapRect.top]
        dec     ecx
        dec     edx
        mov     eax, [esi+TImage.offsX]
................................................................................
        mov     eax, [esi+TImage.ClipRect.left]
        mov     ebx, [esi+TImage.ClipRect.top]
        mov     ecx, [esi+TImage.ClipRect.
        mov     [.srect.left], eax
        mov     [.srect.top], eax


 ;       mov     ecx, [esi+TImage.ClipRect.



; ensure width and height parameters are in the bounds of the images.

        mov     eax, [.wSrc]
        mov     ebx, [.hSrc]

Changes to freshlib/gui/Linux/Main.asm.

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384

        test    eax, eax
        jnz     .add_rect

        mov     eax, [edx+TArray.count]
        mov     [.rect_cnt], eax

        OutputValue "Expose, draw rectangles: ", eax, 10, -1

        push    edx
        lea     ebx, [edx+TArray.array]

        get     edi, esi, TWindow:Screen
        test    edi, edi
        jz      .free_rectangles








<
<







369
370
371
372
373
374
375


376
377
378
379
380
381
382

        test    eax, eax
        jnz     .add_rect

        mov     eax, [edx+TArray.count]
        mov     [.rect_cnt], eax



        push    edx
        lea     ebx, [edx+TArray.array]

        get     edi, esi, TWindow:Screen
        test    edi, edi
        jz      .free_rectangles

Changes to freshlib/gui/Main.asm.

340
341
342
343
344
345
346



347

348
349
350
351
352
353
354
355
356
357
358
359
        stdcall StrDel ; from the stack

        stdcall FileWriteString, [STDOUT], <txt ', max: '>
        stdcall NumToStr, [fpsmax], ntsDec or ntsUnsigned
        push    eax
        stdcall FileWriteString, [STDOUT], eax
        stdcall StrDel ; from the stack



        stdcall FileWriteString, [STDOUT], <txt 13>


.finish:
        popad
        return
endp




include '%TargetOS%/Main.asm'

endmodule







>
>
>
|
>












340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
        stdcall StrDel ; from the stack

        stdcall FileWriteString, [STDOUT], <txt ', max: '>
        stdcall NumToStr, [fpsmax], ntsDec or ntsUnsigned
        push    eax
        stdcall FileWriteString, [STDOUT], eax
        stdcall StrDel ; from the stack
        stdcall FileWriteString, [STDOUT], <txt "                                           ", 13>

      if defined options.DebugMode & options.DebugMode
        stdcall FileWriteString, [STDOUT], <txt 10>
      end if

.finish:
        popad
        return
endp




include '%TargetOS%/Main.asm'

endmodule

Changes to freshlib/gui/TWindow.asm.

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
...
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
...
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
....
1097
1098
1099
1100
1101
1102
1103



1104
1105
1106
1107
1108
1109
1110
....
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155

1156

1157
1158








1159
1160
1161
1162
1163
1164
1165
....
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
        stdcall RectIntersect, edx, ebx, edi
        jc      .next_rect

        mov     eax, [edx+RECT.left]
        sub     [edx+RECT.right], eax

        mov     eax, [edx+RECT.top]
        sub     [edx+RECT.top], eax

        exec    esi, TWindow:SelfPaint, spCopy, [esi+TWindow._screen], [edx+RECT.left], [edx+RECT.top], [edx+RECT.left], [edx+RECT.top], [edx+RECT.right], [edx+RECT.bottom]

.next_rect:

        add     edi, sizeof.RECT
        loop    .rect_loop
................................................................................

        mov     eax, [.pRect]
        test    eax, eax
        jz      .rect_ok

        mov     eax, edi
        lea     edi, [.rect]
        stdcall RectIntersect, edi, eax, [.pRect]   ; from the stack
        jc      .notify_parent

.rect_ok:
        cmp     [esi+TWindow._screen], 0
        je      .notify_parent

if defined options.Threads & options.Threads
................................................................................
end if

; now send some redraw events if needed.

        mov     ecx, [esi+TWindow.handle]
        jecxz   .notify_parent

        mov     eax, [.rect.right]
        mov     edx, [.rect.bottom]
        sub     eax, [.rect.left]
        sub     edx, [.rect.top]

        stdcall _RefreshWindowRect, ecx, [edi+RECT.left], [edi+RECT.top], eax, edx
        jmp     .finish  ; only root windows have handle, so no need to notify further.

; now do the same for the parent window

.notify_parent:
................................................................................
.clear:
        mov     [__FocusedWindow], 0
        exec    [.self], TWindow:EventFocusOut
        return
endp






method TWindow.__UpdateImages
begin
        pushad
        mov     esi, [.self]

        mov     ebx, [esi+TWindow._visible]
................................................................................

; check the size

        cmp     ecx, [edi+TImage.width]
        ja      .destroy

        cmp     edx, [edi+TImage.height]
        jbe     .exit


.destroy:
        stdcall DestroyImage, edi                         ; screen

        xor     eax, eax
        mov     [esi+TWindow._screen], eax

        test    ebx, ebx
        jz      .exit


.create_new:

        add     ecx, 256
        add     edx, 256

;        cmp     [esi+TWindow.__pChildren], 0
;        je      .exit

        stdcall CreateImage, ecx, edx

        mov     [esi+TWindow._screen], eax


        OutputValue "Create new screen image:", eax, 16, 8









.exit:
        popad
        return
endp


................................................................................
        return
endp



method TWindow.Resize     ;, .newWidth, .newHeight
.rect1 RECT
.rect2 RECT
.rect3 RECT
begin
        pushad
        mov     esi, [.self]

        mov     ebx, [.newWidth]
        mov     ecx, [.newHeight]

        cmp     ebx, [esi+TWindow._width]
        jne     .update

        cmp     ecx, [esi+TWindow._height]
        je      .finish

.update:
        xor     edi, edi
        mov     [.rect1.top], edi
        mov     [.rect2.left], edi

        mov     eax, [esi+TWindow._width]
        mov     [esi+TWindow._width], ebx
        cmp     eax, ebx
        jl      @f
        xchg    eax, ebx        ; eax = minX; ebx = maxX
        inc     edi
@@:
        mov     edx, [esi+TWindow._height]
        mov     [esi+TWindow._height], ecx
        cmp     ecx, edx
        jl      @f
        xchg    ecx, edx        ; ecx = minY; edx = maxY
        inc     edi
@@:
        mov     [.rect1.left], eax
        mov     [.rect1.right], ebx
        mov     [.rect1.bottom], ecx

        mov     [.rect2.top], ecx
        mov     [.rect2.right], eax
        mov     [.rect2.bottom], edx

        OutputValue "Skip RECT3 value: ", edi, 10, -1

        cmp     eax, ebx
        je      .skip1

        test    edi, 1
        jnz     .skip3

        cmp     ecx, edx
        je      .skip3

        mov     [.rect3.left], eax
        mov     [.rect3.top], ecx
        mov     [.rect3.right], ebx
        mov     [.rect3.bottom], edx

        lea     edi, [.rect3]
        exec    esi, TWindow:RectChanged2, edi

        DebugMsg "Rectangle 3 invalidated!"

.skip3:

        lea     edi, [.rect1]
        exec    esi, TWindow:RectChanged2, edi

.skip1:
        cmp     ecx, edx
        je      .skip2

        lea     edi, [.rect2]
        exec    esi, TWindow:RectChanged2, edi

.skip2:
        exec    esi, TWindow:__UpdateImages

.finish:
        popad
        return
endp











|







 







|







 







|
|
|
|







 







>
>
>







 







|
<













|
|

<
<
<
|
>
|
>

<
>
>
>
>
>
>
>
>







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
...
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
...
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
....
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
....
1130
1131
1132
1133
1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153



1154
1155
1156
1157
1158

1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
....
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315



























1316
1317
1318
1319
1320
1321
1322
        stdcall RectIntersect, edx, ebx, edi
        jc      .next_rect

        mov     eax, [edx+RECT.left]
        sub     [edx+RECT.right], eax

        mov     eax, [edx+RECT.top]
        sub     [edx+RECT.bottom], eax

        exec    esi, TWindow:SelfPaint, spCopy, [esi+TWindow._screen], [edx+RECT.left], [edx+RECT.top], [edx+RECT.left], [edx+RECT.top], [edx+RECT.right], [edx+RECT.bottom]

.next_rect:

        add     edi, sizeof.RECT
        loop    .rect_loop
................................................................................

        mov     eax, [.pRect]
        test    eax, eax
        jz      .rect_ok

        mov     eax, edi
        lea     edi, [.rect]
        stdcall RectIntersect, edi, eax, [.pRect]
        jc      .notify_parent

.rect_ok:
        cmp     [esi+TWindow._screen], 0
        je      .notify_parent

if defined options.Threads & options.Threads
................................................................................
end if

; now send some redraw events if needed.

        mov     ecx, [esi+TWindow.handle]
        jecxz   .notify_parent

        mov     eax, [edi+RECT.right]  ;[.rect.right]
        mov     edx, [edi+RECT.bottom] ;[.rect.bottom]
        sub     eax, [edi+RECT.left]   ;[.rect.left]
        sub     edx, [edi+RECT.top]    ;[.rect.top]

        stdcall _RefreshWindowRect, ecx, [edi+RECT.left], [edi+RECT.top], eax, edx
        jmp     .finish  ; only root windows have handle, so no need to notify further.

; now do the same for the parent window

.notify_parent:
................................................................................
.clear:
        mov     [__FocusedWindow], 0
        exec    [.self], TWindow:EventFocusOut
        return
endp


SCREEN_MORE_X = 256
SCREEN_MORE_Y = 256


method TWindow.__UpdateImages
begin
        pushad
        mov     esi, [.self]

        mov     ebx, [esi+TWindow._visible]
................................................................................

; check the size

        cmp     ecx, [edi+TImage.width]
        ja      .destroy

        cmp     edx, [edi+TImage.height]
        jbe     .set_wrap


.destroy:
        stdcall DestroyImage, edi                         ; screen

        xor     eax, eax
        mov     [esi+TWindow._screen], eax

        test    ebx, ebx
        jz      .exit


.create_new:

        lea     eax, [ecx + SCREEN_MORE_X]
        lea     ebx, [edx + SCREEN_MORE_Y]




        stdcall CreateImage, eax, ebx
        mov     edi, eax
        mov     [esi+TWindow._screen], edi
        exec    esi, TWindow:RectChanged2, 0


        OutputValue "New screen image has been created:", edi, 16, 8

.set_wrap:
;        xor     eax, eax
        mov     [edi+TImage.wrapW], ecx
        mov     [edi+TImage.wrapH], edx
;        mov     [edi+TImage.orgX], eax
;        mov     [edi+TImage.orgY], eax

.exit:
        popad
        return
endp


................................................................................
        return
endp



method TWindow.Resize     ;, .newWidth, .newHeight
.rect1 RECT
begin
        pushad

        mov     esi, [.self]
        lea     edi, [.rect1]

        mov     ebx, [.newWidth]
        mov     ecx, [.newHeight]
        mov     eax, ebx
        mov     edx, ecx
        xchg    ebx, [esi+TWindow._width]
        xchg    ecx, [esi+TWindow._height]

        cmp     eax, ebx        ; newW, oldW
        ja      .updateW

        cmp     edx, ecx        ; newH, oldH
        ja      .updateH

        popad
        return

.updateW:
        mov     [.rect1.top], 0                 ; 0
        mov     [.rect1.left], ebx              ; oldWidth
        mov     [.rect1.right],  eax            ; newWidth
        mov     [.rect1.bottom], edx            ; newHeight

        exec    esi, TWindow:RectChanged2, edi

        cmp     edx, ecx        ; newH, oldH
        jbe     .exit

.updateH:
        cmp     eax, ebx        ; newW, oldW
        cmova   eax, ebx        ; eax = min(oldWidth, newWidth)

        mov     [.rect1.left], 0
        mov     [.rect1.top], ecx               ; oldHeight
        mov     [.rect1.right], eax             ; min(oldWidth, newWidth)
        mov     [.rect1.bottom], edx            ; newHeight

;        DebugMsg "Update resized:"
;        OutputValue "L = ", 0, 10, -1
;        OutputValue "T = ", ecx, 10, -1
;        OutputValue "R = ", eax, 10, -1
;        OutputValue "B = ", edx, 10, -1

        exec    esi, TWindow:RectChanged2, edi

.exit:
        exec    esi, TWindow:__UpdateImages



























        popad
        return
endp




Changes to freshlib/simpledebug/Win32/debug.asm.

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
iglobal
  if used cConsoleTitle
    cConsoleTitle du 'Fresh simple debug console.', 0
  end if
endg


if (defined options.DebugMode & options.DebugMode) | used Output
initialize InitDebugConsole
begin
        invoke  AllocConsole
        invoke  GetStdHandle, STD_ERROR_HANDLE
        mov     [debug_con_handle], eax
        invoke  SetConsoleTitleW, cConsoleTitle
        return
endp
end if


if (defined options.DebugMode & options.DebugMode)
finalize FinishDebugConsole
.string rb 10
begin
        invoke  WriteFile, [STDERR], ___CloseMsg, ___CloseMsg.length, 0, 0
        lea     eax, [.string]
        invoke  ReadFile, [STDIN], eax, 1, 0, 0
        return
endp

___CloseMsg text "Press ENTER to close."

end if


maxConsoleWrite = 1024

proc Output, .ptrStr
.dummy dd ?







|











|










<







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
iglobal
  if used cConsoleTitle
    cConsoleTitle du 'Fresh simple debug console.', 0
  end if
endg


if (defined options.DebugMode & options.DebugMode) | used Output | (defined options.DebugMode.ShowFPS & options.DebugMode.ShowFPS)
initialize InitDebugConsole
begin
        invoke  AllocConsole
        invoke  GetStdHandle, STD_ERROR_HANDLE
        mov     [debug_con_handle], eax
        invoke  SetConsoleTitleW, cConsoleTitle
        return
endp
end if


if (defined options.DebugMode & options.DebugMode) | used Output | (defined options.DebugMode.ShowFPS & options.DebugMode.ShowFPS)
finalize FinishDebugConsole
.string rb 10
begin
        invoke  WriteFile, [STDERR], ___CloseMsg, ___CloseMsg.length, 0, 0
        lea     eax, [.string]
        invoke  ReadFile, [STDIN], eax, 1, 0, 0
        return
endp

___CloseMsg text "Press ENTER to close."

end if


maxConsoleWrite = 1024

proc Output, .ptrStr
.dummy dd ?

Changes to freshlib/simpledebug/debug.asm.

12
13
14
15
16
17
18


19
20
21
22
23
24
25
;  Notes: use options.DebugMode={1|0} to enable/disable debug output of this library.
;_________________________________________________________________________________________
module "Simple debug library"

SimpleDebugLoaded = 1

include "%TargetOS%/debug.asm"




match =DBG_CHAR_NEWLINE, DBG_CHAR_NEWLINE {
  DBG_CHAR_NEWLINE equ $0d, $0a
}









>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;  Notes: use options.DebugMode={1|0} to enable/disable debug output of this library.
;_________________________________________________________________________________________
module "Simple debug library"

SimpleDebugLoaded = 1

include "%TargetOS%/debug.asm"




match =DBG_CHAR_NEWLINE, DBG_CHAR_NEWLINE {
  DBG_CHAR_NEWLINE equ $0d, $0a
}


Changes to freshlib/test_code0/TestGraphics.asm.

10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
..
64
65
66
67
68
69
70
71












72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
...
112
113
114
115
116
117
118


119
120
121
122
123
124
125
...
131
132
133
134
135
136
137





138
139
140
141
142
143
144
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
;  Dependencies: FreshLib
;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

options.DebugMode = 0
options.DebugMode.NoTimers = 0
options.DebugMode.ShowFPS = 1


@BinaryType GUI, compact

include "%lib%/freshlib.asm"

iglobal
  tplMainForm:
................................................................................
        FinalizeAll
        stdcall TerminateAll, 0



proc DemoPaint as TWindow.OnSelfPaint
begin
        stdcall CopyImageRect, [.pDstImage], [.xDst], [.yDst], [imgBackground], [.xSrc], [.ySrc], [.width], [.height]












        return
endp




proc Scroll, .application
.wx dd ?
.wy dd ?
begin
        pushad

        mov     edi, [imgBackground]

        mov     esi, [frmMain]
        test    esi, esi
        jz      .finish

        mov     eax, [esi+TWindow._screen]
        test    eax, eax
        jz      .finish

        mov     ecx, [edi+TImage.width]
        mov     edx, [edi+TImage.height]

        mov     [eax+TImage.wrapW], ecx
        mov     [eax+TImage.wrapH], edx

        dec     ecx
        dec     edx
        mov     [.wx], ecx
        mov     [.wy], edx

        xor     edx, edx

................................................................................

        mov     ecx, [eax+TImage.orgY]
        add     ecx, [incY]
        cmovs   ecx, [.wy]
        cmp     ecx, [.wy]
        cmovg   ecx, edx
        mov     [eax+TImage.orgY], ecx



        stdcall _RefreshWindowRect, [esi+TWindow.handle], 0, 0, [esi+TWindow._width], [esi+TWindow._height]
        stdcall Randomize

.finish:
        popad
        return
................................................................................

uglobal
  incX dd ?
  incY dd ?
  dist dd ?
endg







proc Randomize
.random dd ?
begin
        dec     [dist]
        jns     .finish

................................................................................
;        jne     .finish
;
;        mov     [incX], -1

        stdcall GetRandomBytes, 12
        mov     esi, eax

        mov     ecx, 500

        mov     eax, [esi]
        xor     edx, edx
        div     ecx

        add     edx, 100
        mov     [dist], edx

        mov     ecx, 3

        mov     eax, [esi+4]
        xor     edx, edx
        div     ecx
        dec     edx

        mov     [incX], edx

        mov     eax, [esi+8]
        xor     edx, edx
        div     ecx
        dec     edx

        mov     [incY], edx

        or      edx, [incX]
        jnz     @f
        mov     [dist], edx
@@:
        stdcall FreeMem, esi

.finish:
        return
endp







|


>







 







|
>
>
>
>
>
>
>
>
>
>
>
>












<
<








|
|
>
|
|
<







 







>
>







 







>
>
>
>
>







 







|





|


|




|
>





|
>











10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96


97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
;  Dependencies: FreshLib
;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

options.DebugMode = 1
options.DebugMode.NoTimers = 0
options.DebugMode.ShowFPS = 1
options.DebugMode.DisableSHM = 0

@BinaryType GUI, compact

include "%lib%/freshlib.asm"

iglobal
  tplMainForm:
................................................................................
        FinalizeAll
        stdcall TerminateAll, 0



proc DemoPaint as TWindow.OnSelfPaint
begin
        pushad
        mov     edi, [.pDstImage]
        mov     esi, [imgBackground]

        DebugMsg "Form self paint:"
        OutputValue "X = ", [.xDst],10, -1
        OutputValue "Y = ", [.yDst],10, -1
        OutputValue "W = ", [.width], 10, -1
        OutputValue "H = ", [.height], 10, -1

        stdcall BlendImageTileWrap, edi, [.xDst], [.yDst], [.width], [.height], esi

        popad
        return
endp




proc Scroll, .application
.wx dd ?
.wy dd ?
begin
        pushad



        mov     esi, [frmMain]
        test    esi, esi
        jz      .finish

        mov     eax, [esi+TWindow._screen]
        test    eax, eax
        jz      .finish

        stdcall LockImg, eax
        jc      .finish

        mov     ecx, [eax+TImage.wrapW]
        mov     edx, [eax+TImage.wrapH]

        dec     ecx
        dec     edx
        mov     [.wx], ecx
        mov     [.wy], edx

        xor     edx, edx

................................................................................

        mov     ecx, [eax+TImage.orgY]
        add     ecx, [incY]
        cmovs   ecx, [.wy]
        cmp     ecx, [.wy]
        cmovg   ecx, edx
        mov     [eax+TImage.orgY], ecx

        stdcall UnlockImg, eax

        stdcall _RefreshWindowRect, [esi+TWindow.handle], 0, 0, [esi+TWindow._width], [esi+TWindow._height]
        stdcall Randomize

.finish:
        popad
        return
................................................................................

uglobal
  incX dd ?
  incY dd ?
  dist dd ?
endg

rndMaxStep = 2
rndStepMul = 0

rndMaxCnt  = 100
rndMinCnt  = 5

proc Randomize
.random dd ?
begin
        dec     [dist]
        jns     .finish

................................................................................
;        jne     .finish
;
;        mov     [incX], -1

        stdcall GetRandomBytes, 12
        mov     esi, eax

        mov     ecx, rndMaxCnt - rndMinCnt

        mov     eax, [esi]
        xor     edx, edx
        div     ecx

        add     edx, rndMinCnt
        mov     [dist], edx

        mov     ecx, 2*rndMaxStep+1

        mov     eax, [esi+4]
        xor     edx, edx
        div     ecx
        sub     edx, rndMaxStep
        shl     edx, rndStepMul
        mov     [incX], edx

        mov     eax, [esi+8]
        xor     edx, edx
        div     ecx
        sub     edx, rndMaxStep
        shl     edx, rndStepMul
        mov     [incY], edx

        or      edx, [incX]
        jnz     @f
        mov     [dist], edx
@@:
        stdcall FreeMem, esi

.finish:
        return
endp

Changes to freshlib/test_code0/TestGraphics.fpr.

cannot compute difference between binary files