Fresh IDE . Check-in [2d85be0cb6]
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: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.
Timelines: family | ancestors | descendants | both | NoCanvasGUI
Files: files | file ages | folders
SHA1:2d85be0cb66c56eaa441e17bb35514ca958f63b9
User & Date: johnfound 2017-11-12 07:58:09
Context
2017-11-12
21:04
Correctly working SetImageWrap procedure. But suboptimal solution of the procedure ZeroOrgImage that is used in SetImageWrap. But as long as this operation is needed only on image resize, it is not so important actually. check-in: 7a45e0a480 user: johnfound tags: NoCanvasGUI
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
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

287
288
289
290
291
292
293
294
295



296
297
298
299
300
301
302

        mov     ebx, [esi+TImage.wrapW]
        mov     edx, [esi+TImage.wrapH]
        lea     ecx, [.sRect]

        lea     eax, [.maskUL]
        stdcall RectIntersect, eax, eax, ecx
        call    .DoDraw                                 ; the upper left rect is always drawn




        lea     eax, [.maskUR]
        stdcall RectIntersect, eax, eax, ecx
        jc      .upper_right_ok

        sub     [.maskUR.left], ebx
        sub     [.maskUR.right], ebx








|

>
>
>







287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

        mov     ebx, [esi+TImage.wrapW]
        mov     edx, [esi+TImage.wrapH]
        lea     ecx, [.sRect]

        lea     eax, [.maskUL]
        stdcall RectIntersect, eax, eax, ecx
        jc      .upper_left_ok

        call    .DoDraw

.upper_left_ok:
        lea     eax, [.maskUR]
        stdcall RectIntersect, eax, eax, ecx
        jc      .upper_right_ok

        sub     [.maskUR.left], ebx
        sub     [.maskUR.right], ebx

Changes to freshlib/graphics/images.asm.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
..
77
78
79
80
81
82
83




















































































































































































































































































84
85
86
87
88
89
90
...
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
...
431
432
433
434
435
436
437







438
439
440
441
442
443
444
...
459
460
461
462
463
464
465
466
467
468
469
470
471
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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
  .height    dd ?  ; height in pixels.
  .pPixels   dd ?  ; pointer to the pixel memory.

  .orgX      dd ?
  .orgY      dd ?
  .wrapW     dd ?
  .wrapH     dd ?
  .xWrapBeg   dd ?   ; byte offset relative to the line start.
  .yWrapBeg   dd ?   ; byte offset relative to the image start.
  .xWrapEnd   dd ?   ; byte offset relative to the line start.
  .yWrapEnd   dd ?   ; byte offset relative to the image start.

  .lock      TMutex
ends



; Creates memory image with parameters specified.
................................................................................
;        OutputValue "Unable to lock image. Error=", eax, 10, -1
;
;        OutputCallStack 2
;        OutputLn

;        mov     eax, [ebp+4]
;        OutputValue "Unable to lock image on: ", eax, 16, 8
        stc
        pop      eax
        return
endp


proc UnlockImg, .pImage
begin
................................................................................
        mov     eax, [.pImage]
        lea     eax, [eax+TImage.lock]
        stdcall MutexRelease, eax
        pop     eax
        return
endp























































































































































































































































































proc BlendImage, .pDstImage, .xDst, .yDst, .pSrcImage, .xSrc, .ySrc, .width, .height
.srect RECT
.drect RECT
.rect  RECT
begin
................................................................................
        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
        packssdw  mm5, mm5              ; mm5 = As, As, As, As
................................................................................
        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]

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



proc ImageSetWrap, .pImage, .x, .y, .width, .height
.srect RECT
begin
        pushad

        mov     esi, [.pImage]
        stdcall LockImg, esi
        jc      .finish

        mov     eax, [.x]
        mov     ebx, [.y]
        mov     ecx, [.width]
        mov     edx, [.height]
        add     ecx, eax
        add     edx, ebx

        mov     [esi+TImage.WrapRect.left], eax
        mov     [esi+TImage.WrapRect.top], ebx
        mov     [esi+TImage.WrapRect.right], ecx
        mov     [esi+TImage.WrapRect.bottom], edx

; Wrap bounds source rect

        xor     eax, eax
        mov     ecx, [esi+TImage.width]
        mov     edx, [esi+TImage.height]

        mov     [esi+TImage.xWrapBeg], eax
        mov     [esi+TImage.yWrapBeg], eax
        mov     [esi+TImage.xWrapEnd], eax
        mov     [esi+TImage.yWrapEnd], eax
        mov     [.srect.left], eax
        mov     [.srect.top], eax
        mov     [.srect.right], ecx
        mov     [.srect.bottom], edx

        lea     eax, [.srect]
        lea     ecx, [esi+TImage.WrapRect]
        stdcall RectIntersect, ecx, eax, ecx
        jc      .unlock

        mov     eax, [esi+TImage.WrapRect.left]
        mov     ebx, [esi+TImage.WrapRect.top]
        mov     ecx, [esi+TImage.WrapRect.right]
        mov     edx, [esi+TImage.WrapRect.bottom]
        shl     eax, 2
        shl     ebx, 2
        shl     ecx, 2
        shl     edx, 2
        imul    ebx, [esi+TImage.width]
        imul    edx, [esi+TImage.width]
        add     ebx, [esi+TImage.pPixels]
        add     edx, [esi+TImage.pPixels]

        mov     [esi+TImage.xWrapBeg], eax
        mov     [esi+TImage.yWrapBeg], ebx
        mov     [esi+TImage.xWrapEnd], ecx
        mov     [esi+TImage.yWrapEnd], edx

.unlock:
        stdcall UnlockImg, esi
        clc

.finish:
        popad
        return
endp




proc BlendImageWrap, .pDstImage, .xDst, .yDst, .pSrcImage, .xSrc, .ySrc, .wSrc, .hSrc

.xDstWrap0 dd ?
.xDstWrap1 dd ?







<
<
<
<







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<







 







>
>
>
>
>
>
>







 







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







18
19
20
21
22
23
24




25
26
27
28
29
30
31
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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
...
673
674
675
676
677
678
679






680
681
682
683
684
685
686
...
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
...
732
733
734
735
736
737
738




































































739
740
741
742
743
744
745
  .height    dd ?  ; height in pixels.
  .pPixels   dd ?  ; pointer to the pixel memory.

  .orgX      dd ?
  .orgY      dd ?
  .wrapW     dd ?
  .wrapH     dd ?





  .lock      TMutex
ends



; Creates memory image with parameters specified.
................................................................................
;        OutputValue "Unable to lock image. Error=", eax, 10, -1
;
;        OutputCallStack 2
;        OutputLn

;        mov     eax, [ebp+4]
;        OutputValue "Unable to lock image on: ", eax, 16, 8
;        stc
        pop      eax
        return
endp


proc UnlockImg, .pImage
begin
................................................................................
        mov     eax, [.pImage]
        lea     eax, [eax+TImage.lock]
        stdcall MutexRelease, eax
        pop     eax
        return
endp


; Sets the wrap parameters of the image.
; Arguments:
;    .pImage - pointer to the TImage
;    .newWrapW - new wrap width
;    .newWrapH - new wrap height
;    .fPreserveImg - if TRUE, moves pixels in order to preserve the original image.
;                    if FALSE, does nothing and the image will be destroyed.

proc SetImageWrap, .pImage, .newWrapW, .newWrapH, .fPreserveImg
.StepY dd ?
.EndY  dd ?
begin
        pushad
        mov     ebx, [.pImage]
        stdcall LockImg, ebx
        jc      .finish

        mov     ecx, [.newWrapW]
        cmp     ecx, [ebx+TImage.width]
        cmova   ecx, [ebx+TImage.width]

        xchg    ecx, [ebx+TImage.wrapW]         ; now ecx= old(TImage.wrapW)

        cmp     [.fPreserveImg], 0
        je      .width_ok

        cmp     ecx, [ebx+TImage.wrapW]
        je      .width_ok

        ;---------------------------------------> This block
        mov     esi, [ebx+TImage.pPixels]       ;
        mov     eax, [ebx+TImage.width]         ; must not change the flags!
        mov     edx, [ebx+TImage.wrapH]         ;
        lea     eax, [4*eax]                    ;
        mov     [.StepY], eax                   ;
        mov     [.EndY], edx     ;--------------> !!! important !!!

        jb      .expandW                        ; the new width is bigger than the old.

; shrink image horizontally.

        mov     edi, [ebx+TImage.orgX]
        sub     edi, ecx
        add     edi, [ebx+TImage.wrapW]
        jns     .loopY1
        add     edi, [ebx+TImage.wrapW]

.loopY1:
        dec     [.EndY]
        js      .width_ok

        mov     edx, [ebx+TImage.orgX]
        mov     ecx, edi

.loopX1:
        dec     edx
        js      .nextY1

        dec     ecx
        jns     @f
        mov     ecx, [ebx+TImage.wrapW]
        add     ecx, edx
@@:

        mov     eax, [esi+4*ecx]
        mov     [esi+4*edx], eax
        jmp     .loopX1

.nextY1:
        add     esi, [.StepY]
        jmp     .loopY1


; expand image horizontally...

.expandW:
        xor     eax, eax

        cmp     [ebx+TImage.orgX], eax
        je      .width_ok
        cmp     [.EndY], eax
        je      .width_ok

        mov     edi, ecx        ; the old wrapW.

.loopY2:
        xor     ecx, ecx
        mov     edx, edi

.loopX2:
        mov     eax, [esi+4*ecx]
        mov     [esi+4*edx], eax

        inc     edx
        cmp     edx, [ebx+TImage.wrapW]         ; the new wrapW
        jne     @f
        xor     edx, edx
@@:
        inc     ecx
        cmp     ecx, [ebx+TImage.orgX]
        jne     .loopX2

        mov     eax, $ff00ff00
.loopX3:
        mov     [esi+4*edx], eax

        inc     edx
        cmp     edx, [ebx+TImage.wrapW]         ; the new wrapW
        jne     @f
        xor     edx, edx
@@:
        cmp     edx, [ebx+TImage.orgX]
        jne     .loopX3

        add     esi, [.StepY]
        dec     [.EndY]
        jnz     .loopY2

;-----------------------------------------------

.width_ok:

        mov     ecx, [.newWrapH]
        cmp     ecx, [ebx+TImage.height]
        cmova   ecx, [ebx+TImage.height]

        xchg    ecx, [ebx+TImage.wrapH]         ; now ecx= old(TImage.wrapH)

        cmp     [.fPreserveImg], 0
        je      .height_ok

        cmp     ecx, [ebx+TImage.wrapH]
        je      .height_ok

        mov     esi, [ebx+TImage.pPixels]

        jb      .expandH                        ; the new height is bigger than the old.

; shrink the image vertically

        lea     eax, [ecx-1]
        imul    eax, [ebx+TImage.width]
        lea     eax, [esi+4*eax]
        mov     [.EndY], eax

        mov     eax, [ebx+TImage.orgY]
        mov     edx, [ebx+TImage.orgY]
        sub     edx, ecx
        add     edx, [ebx+TImage.wrapH]         ; the source
        jns     @f
        add     edx, [ebx+TImage.wrapH]
@@:

        imul    eax, [ebx+TImage.width]
        imul    edx, [ebx+TImage.width]

        lea     edi, [esi+4*eax]
        lea     esi, [esi+4*edx]

        mov     eax, [ebx+TImage.wrapW]
        mov     edx, [ebx+TImage.width]

        lea     edi, [edi+4*eax]
        lea     esi, [esi+4*eax]
        add     edx, eax
        shl     edx, 2

.loopY3:
        sub     edi, edx
        cmp     edi, [ebx+TImage.pPixels]
        jb      .height_ok

        sub     esi, edx
        cmp     esi, [ebx+TImage.pPixels]
        cmovb   esi, [.EndY]

        mov     ecx, [ebx+TImage.wrapW]
        rep movsd
        jmp .loopY3

; expand the image vertically

.expandH:
        mov     edx, [ebx+TImage.width]
        sub     edx, [ebx+TImage.wrapW]
        shl     edx, 2

        imul    ecx, [ebx+TImage.width]
        lea     edi, [esi+4*ecx]                ; the oldWrapH

        mov     eax, [ebx+TImage.wrapH]         ; the newWrapH
        imul    eax, [ebx+TImage.width]
        lea     eax, [esi+4*eax]
        mov     [.EndY], eax

        mov     eax, [ebx+TImage.orgY]

.loopY4:
        dec     eax
        js      .height_ok

        mov     ecx, [ebx+TImage.wrapW]
        rep movsd

        add     esi, edx
        add     edi, edx
        cmp     edi, [.EndY]
        cmovae  edi, [ebx+TImage.pPixels]
        jmp     .loopY4


.height_ok:

        stdcall UnlockImg, ebx
        clc

.finish:
        popad
        return
endp



proc ZeroOrg, .pImage
.rows dd ?
begin
        pushad

        mov     ebx, [.pImage]

        mov     edx, [ebx+TImage.orgX]
        mov     esi, [ebx+TImage.pPixels]
        mov     ecx, [ebx+TImage.wrapW]

        mov     eax, [ebx+TImage.wrapH]
        mov     [.rows], eax

.loopY:
        dec     [.rows]
        js      .finishX

.loop_outer:

        mov     eax, [esi+4*edx]
        mov     edi, edx

.loop_inner:
        dec     ecx
        js      .end_loop

        sub     edx, [ebx+TImage.orgX]
        jns     @f
        add     edx, [ebx+TImage.wrapW]
@@:
        xchg    eax, [esi+4*edx]
        cmp     edx, edi
        jne     .loop_inner
        inc     edx
        jmp     .loop_outer

.end_loop:

        mov     eax, [ebx+TImage.width]
        lea     esi, [esi+4*eax]
        jmp     .loopY

.finishX:

        mov     [ebx+TImage.orgX], 0


        popad
        return
endp



proc BlendImage, .pDstImage, .xDst, .yDst, .pSrcImage, .xSrc, .ySrc, .width, .height
.srect RECT
.drect RECT
.rect  RECT
begin
................................................................................
        mov     edx, [.dstXbegn]
        mov     eax, [.wDst]

.loopX:
        dec     eax
        js      .nextY







        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
        packssdw  mm5, mm5              ; mm5 = As, As, As, As
................................................................................
        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

        cmp     ecx, [.srcXwrap]
        cmovae  ecx, ebx

        cmp     edx, [.dstXwrap]
        cmovae  edx, ebx

        jmp     .loopX

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

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










































































proc BlendImageWrap, .pDstImage, .xDst, .yDst, .pSrcImage, .xSrc, .ySrc, .wSrc, .hSrc

.xDstWrap0 dd ?
.xDstWrap1 dd ?

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

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
        cmp     eax, [ebx+XConfigureEvent.width]
        jne     .resize

        cmp     edx, [ebx+XConfigureEvent.height]
        je      .is_move

.resize:
;        DebugMsg "Resize event!"
        exec    esi, TWindow:Resize, [ebx+XConfigureEvent.width], [ebx+XConfigureEvent.height]
;        jmp     .finish

; move event...
.is_move:
        mov     eax, [esi+TWindow._x]
        mov     edx, [esi+TWindow._y]







<







144
145
146
147
148
149
150

151
152
153
154
155
156
157
        cmp     eax, [ebx+XConfigureEvent.width]
        jne     .resize

        cmp     edx, [ebx+XConfigureEvent.height]
        je      .is_move

.resize:

        exec    esi, TWindow:Resize, [ebx+XConfigureEvent.width], [ebx+XConfigureEvent.height]
;        jmp     .finish

; move event...
.is_move:
        mov     eax, [esi+TWindow._x]
        mov     edx, [esi+TWindow._y]

Changes to freshlib/gui/TWindow.asm.

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
....
1102
1103
1104
1105
1106
1107
1108



1109
1110






1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
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
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
....
1276
1277
1278
1279
1280
1281
1282


1283
1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
....
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

  method .Autosize      ; Returns in EAX the prefered width and in EDX the prefered height of the Window
                        ; By default (in TWindow) returns the width and height of the window
                        ; Called by the splitgrid layout library.

; System event methods

  abstract .EventFocusIn
  abstract .EventFocusOut

  method .EventMouseEnter
  method .EventMouseLeave

  method .EventMouseMove, .x, .y, .kbdState

  method .EventButtonPress, .button, .kbdState, .x, .y
................................................................................


SCREEN_MORE_X = 256
SCREEN_MORE_Y = 256


method TWindow.__UpdateImages



begin
        pushad






        mov     esi, [.self]

        mov     ebx, [esi+TWindow._visible]
        mov     edi, [esi+TWindow._screen]
        get     eax, esi, TWindow:Parent

        mov     ecx, [esi+TWindow._width]
        mov     edx, [esi+TWindow._height]

        test    eax, eax
        jz      @f
        xor     ebx, ebx        ; if the window has parent, it should not have screen image == (visible == false)
        jmp     .destroy
@@:
        test    ebx, ebx
        jz      .destroy

        test    edi, edi
        jz      .create_new

; 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






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

        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

................................................................................
        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









method TWindow.EventMouseEnter
begin
        push    esi edx

        mov     esi, [.self]







|
|







 







>
>
>


>
>
>
>
>
>









|
|
|
|
|
|
|
|
|
|







>
>
>
>
|

>
>
>
>
>
>
>

>
>
>
>
>
>





>
>

|










<

>
|

>
|
<
<
<
<
<

<
<
<







 







>
>




>







 







|
<
>
|
|
<

>
|
>

<
<
<




>
>
>
>
>







236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
....
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
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
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184

1185
1186
1187
1188
1189
1190





1191



1192
1193
1194
1195
1196
1197
1198
....
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
....
1323
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333

1334
1335
1336
1337
1338



1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354

  method .Autosize      ; Returns in EAX the prefered width and in EDX the prefered height of the Window
                        ; By default (in TWindow) returns the width and height of the window
                        ; Called by the splitgrid layout library.

; System event methods

  method .EventFocusIn
  method .EventFocusOut

  method .EventMouseEnter
  method .EventMouseLeave

  method .EventMouseMove, .x, .y, .kbdState

  method .EventButtonPress, .button, .kbdState, .x, .y
................................................................................


SCREEN_MORE_X = 256
SCREEN_MORE_Y = 256


method TWindow.__UpdateImages
.prevOrgX dd ?
.prevOrgY dd ?
.fPrImg   dd ?
begin
        pushad

        xor     eax, eax
        mov     [.prevOrgX], eax
        mov     [.prevOrgY], eax
        mov     [.fPrImg], eax

        mov     esi, [.self]

        mov     ebx, [esi+TWindow._visible]
        mov     edi, [esi+TWindow._screen]
        get     eax, esi, TWindow:Parent

        mov     ecx, [esi+TWindow._width]
        mov     edx, [esi+TWindow._height]

        xor     ebx, 1          ; ebx = FALSE, if the window is visible

        test    eax, eax
        cmovnz  ebx, eax        ; if the window has parent, it should have no screen image!

        test    edi, edi
        jz      .check_hidden

        test    ebx, ebx
        jnz     .destroy

; check the size

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

        cmp     edx, [edi+TImage.height]
        ja      .destroy

        inc     [.fPrImg]

.set_wrap:

        stdcall SetImageWrap, edi, ecx, edx, [.fPrImg]

.exit:
        popad
        return


.destroy:
        mov     eax, [edi+TImage.orgX]
        mov     [.prevOrgX], eax

        mov     eax, [edi+TImage.orgY]
        mov     [.prevOrgY], eax

        stdcall DestroyImage, edi                         ; screen

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

.check_hidden:

        test    ebx, ebx
        jnz     .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


        push    [.prevOrgX] [.prevOrgY]
        pop     [edi+TImage.orgY] [edi+TImage.orgX]

        exec    esi, TWindow:RectChanged2, 0
        jmp     .set_wrap









endp






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

        cmp     eax, ebx        ; newW, oldW
        ja      .updateW

        cmp     edx, ecx        ; newH, oldH
        ja      .updateH

.exit:
        exec    esi, TWindow:__UpdateImages
        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

................................................................................
        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

        exec    esi, TWindow:RectChanged2, edi


        jmp     .exit
endp



method TWindow.EventFocusIn
begin




        return
endp


method TWindow.EventFocusOut
begin

        return
endp


method TWindow.EventMouseEnter
begin
        push    esi edx

        mov     esi, [.self]

Changes to freshlib/test_code0/TestGraphics.asm.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
..
54
55
56
57
58
59
60
61




62
63
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
106
107














108
















109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
























133
134
135
136
137
138
139
140
...
144
145
146
147
148
149
150
151
152
153
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
...
204
205
206
207
208
209
210


211
212
iglobal
  tplMainForm:
        ObjTemplate  tfEnd, TForm, frmMain,     \
                     OnSelfPaint = DemoPaint,   \
                     border = borderFull,       \
                     Caption = 'FreshLib graphics and GUI library test .'

 pngBackground file "_test_images/background.png"
  .size = $ - pngBackground

endg


uglobal
  imgBackground dd ?

endg


start:
        InitializeAll

        create  [pApplication], TApplication
................................................................................
        stdcall CreateImagePNG, pngBackground, pngBackground.size
        mov     [imgBackground], eax

        set     [frmMain], TForm:width, [eax+TImage.width]
        set     [frmMain], TForm:height, [eax+TImage.height]
        set     [frmMain], TForm:Visible, TRUE

        set     [pApplication], TApplication:OnIdle, Scroll





        stdcall Run

        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.orgX]
        add     ecx, [incX]
        cmovs   ecx, [.wx]
        cmp     ecx, [.wx]
        cmovg   ecx, edx
        mov     [eax+TImage.orgX], ecx

        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
endp

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

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

;        mov     [dist], 1000
;
;        add     [incY], 1
;        cmp     [incY], 2
;        jne     .finish
;
;        mov     [incY], -1
;        add     [incX], 1
;        cmp     [incX], 2
;        jne     .finish
;
;        mov     [incX], -1

        stdcall GetRandomBytes, 12
        mov     esi, eax

        mov     ecx, rndMaxCnt - rndMinCnt

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

.finish:


        return
endp







|







>







 







|
>
>
>
>







 







|
|
<
>
>
>
|
|



>
>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>







>
>
>
|
|


|


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







|




|

|




|

|
>

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







 







|











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







 







>
>


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
55
56
57
58
59
60
61
62
63
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252













253
254
255
256
257
258
259
...
281
282
283
284
285
286
287
288
289
290
291
iglobal
  tplMainForm:
        ObjTemplate  tfEnd, TForm, frmMain,     \
                     OnSelfPaint = DemoPaint,   \
                     border = borderFull,       \
                     Caption = 'FreshLib graphics and GUI library test .'

 pngBackground file "_test_images/background2.png"
  .size = $ - pngBackground

endg


uglobal
  imgBackground dd ?
  paint         dd ?
endg


start:
        InitializeAll

        create  [pApplication], TApplication
................................................................................
        stdcall CreateImagePNG, pngBackground, pngBackground.size
        mov     [imgBackground], eax

        set     [frmMain], TForm:width, [eax+TImage.width]
        set     [frmMain], TForm:height, [eax+TImage.height]
        set     [frmMain], TForm:Visible, TRUE

;        set     [pApplication], TApplication:OnIdle, Scroll

        set     [frmMain], TForm:OnKeyPressed, OnKeyPress
        mov     eax, [frmMain]
        mov     [eax+TForm.__want_focus], TRUE

        stdcall Run

        FinalizeAll
        stdcall TerminateAll, 0


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

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

        stdcall LockImg, edi
        stdcall LockImg, esi


;        OutputValue "draw X=", [.xDst], 10, -1
;        OutputValue "draw Y=", [.yDst], 10, -1
;        OutputValue "draw W=", [.width], 10, -1
;        OutputValue "draw H=", [.height], 10, -1

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

        stdcall UnlockImg, esi
        stdcall UnlockImg, edi
        popad
        return
endp


proc OnKeyPress as TWindow.OnKeyPressed
begin
        cmp     [.utf8], 's'
        je      .scroll

        cmp     [.utf8], 'r'
        je      .refresh

        return

.scroll:
        stdcall Scroll, 0
        return

.refresh:
        exec    [.self], TWindow:RectChanged2, 0
        return



endp



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

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

        cmp     [esi+TWindow._rect_list], 0
        jne     .finish

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

        stdcall LockImg, ebx
        jc      .finish

        mov     edi, [imgBackground]
        stdcall LockImg, edi

; scroll the destination image.

        mov     ecx, [ebx+TImage.wrapW]
        mov     edx, [ebx+TImage.wrapH]
        dec     ecx
        dec     edx
        mov     [.wx], ecx
        mov     [.wy], edx

        xor     edx, edx

        mov     ecx, [ebx+TImage.orgX]
        add     ecx, [incX]
        cmovs   ecx, [.wx]
        cmp     ecx, [.wx]
        cmovg   ecx, edx
        mov     [ebx+TImage.orgX], ecx

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

; scroll the source image

        mov     ecx, [edi+TImage.wrapW]
        mov     edx, [edi+TImage.wrapH]
        dec     ecx
        dec     edx
        mov     [.wx], ecx
        mov     [.wy], edx

        xor     edx, edx

        mov     ecx, [edi+TImage.orgX]
        add     ecx, [incX]
        cmovs   ecx, [.wx]
        cmp     ecx, [.wx]
        cmovg   ecx, edx
        mov     [edi+TImage.orgX], ecx

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

        stdcall UnlockImg, edi
        stdcall UnlockImg, ebx

        mov     eax, [incX]
        mov     ecx, [ebx+TImage.wrapW]
        sub     ecx, eax
        test    eax, eax
        jz      .x_ok
        jns     .ix_ok
        neg     eax
        xor     ecx, ecx
.ix_ok:
        exec    esi, TWindow:RectChangedXY2, ecx, 0, eax, [ebx+TImage.wrapH]

.x_ok:
        mov     eax, [incY]
        mov     ecx, [ebx+TImage.wrapH]
        sub     ecx, eax
        test    eax, eax
        jc      .y_ok
        jns     .iy_ok
        neg     eax
        xor     ecx, ecx
.iy_ok:
        exec    esi, TWindow:RectChangedXY2, 0, ecx, [ebx+TImage.wrapW], eax
.y_ok:

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

.finish:
        popad
        return
endp

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

uglobal
  incX dd ?
  incY dd ?
  dist dd ?
endg

rndMaxStep = 1
rndStepMul = 0

rndMaxCnt  = 100
rndMinCnt  = 5

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














        stdcall GetRandomBytes, 12
        mov     esi, eax

        mov     ecx, rndMaxCnt - rndMinCnt

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

.finish:
;        mov     [incX], 1
;        mov     [incY], 1
        return
endp

Changes to freshlib/test_code0/TestGraphics.fpr.

cannot compute difference between binary files