Fresh IDE . Check-in [59f19b3b5c]
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:TAsmEdit refactored to the TText interface changes.
Timelines: family | ancestors | descendants | both | NoCanvasGUI
Files: files | file ages | folders
SHA1:59f19b3b5c116512070d0cb5e56c1c63622bdf29
User & Date: johnfound 2019-04-27 16:52:07
Context
2019-04-28
14:31
Fixed selection rectangles list creation. Fixed selection delete method. Code cleanup. check-in: b233c364d5 user: johnfound tags: NoCanvasGUI
2019-04-27
16:52
TAsmEdit refactored to the TText interface changes. check-in: 59f19b3b5c user: johnfound tags: NoCanvasGUI
2019-04-22
17:00
Merged with FreshLibDev. Some serious conflicts with the existing code are possible, especially because of TText interface has been changed! check-in: b8ab87cfc4 user: johnfound tags: NoCanvasGUI
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/data/buffergap.asm.

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
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
...
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
        pushad

        mov     esi, [.pText]
        xor     edx, edx
        mov     ebx, [.index]

.loop:
        sub     ebx, 1
        jc      .finish

        cmp     edx, [esi+TText.TextLen]
        cmova   edx, [esi+TText.TextLen]
        jae     .finish

        xor     eax, eax
        cmp     edx, [esi+TText.GapStart]
        cmovae  eax, [esi+TText.GapLen]

        add     eax, edx

        movzx   eax, byte [esi+eax]

                                ; compute the length of the UTF-8 character by its first byte (version without branches) Is it fast?
        not     al              ; utf-8 starts with one of: 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, 1111110x
        bsr     eax, eax        ; eax =                 7,  5,  4,  3,  2,  1
................................................................................

  if pos eqtype eax & text eqtype eax
    cmp    pos, [text+TText.GapBegin]
    jb     ..skip
    add    pos, [text+TText.GapEnd]
    sub    pos, [text+TText.GapBegin]
..skip:
    cmp    pos, [text+TText.Length]
    cmova  pos, [text+TText.Length]
  else
    error "Error! Arguments must be registers!"
    err
  end if
}


................................................................................
; Duplicates TText structure of any size. Returns pointer to the structure in EAX
; The returned pointer have to be freed with TextFree when not needed anymore.
;
; Arguments:
;   .pText - pointer to the source structure
;
; Returns:
;   EAX - pointer to the new TText structure.


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

;proc TextDup, .pText
;begin
;        pushad
;
;        mov     esi, [.pText]
;        test    esi, esi

;        jz      .finish
;
;        mov     ecx, [esi+TText.TextLen]
;        add     ecx, [esi+TText.GapLen]
;        add     ecx, [esi+TText.struc_size]
;
;        stdcall GetMem, ecx
;

;        mov     edi, eax
;
;        mov     edx, [esi+TText.struc_size]
;        add     eax, edx
;

;        mov     [esp+4*regEAX], eax

;        sub     esi, edx
;
;        mov     ebx, ecx
;        shr     ecx, 2
;        and     ebx, 3
;
;        rep movsd
;
;        mov     ecx, ebx
;        rep movsb

;
;.finish:
;        popad
;        return
;endp



proc TextFree, .pText
begin
        push    eax
        mov     eax, [.pText]
................................................................................
        push    eax ecx

        mov     edx, [.pText]

        stdcall TextSetGapSize, edx, 4
        jc      .finish

        mov     eax, [edx+TText.GapStart]

        pushd   [.char]
        popd    [edx+eax]

        mov     ecx, 4

.len_loop:
        cmp     byte [edx+eax], 0
        je      .len_ok
        inc     eax
        loop    .len_loop

.len_ok:
        sub     eax, [edx+TText.GapStart]

        add     [edx+TText.GapStart], eax
        add     [edx+TText.TextLen], eax
        sub     [edx+TText.GapLen], eax
        clc

.finish:
        pop     ecx eax
        return
endp








|
|

|
|


|
|
|
>







 







|
|







 







|
>
>


|
|
|
|
|
|
>
|
|
|
<
|
|
|
<
>
|
|
|
<
|
>
|
>
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|







 







|













<
<
<
<
|







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
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
...
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
        pushad

        mov     esi, [.pText]
        xor     edx, edx
        mov     ebx, [.index]

.loop:
        dec     ebx
        js      .finish

        cmp     edx, [esi+TText.Length]
        cmova   edx, [esi+TText.Length]
        jae     .finish

        mov     eax, [esi+TText.GapBegin]
        cmp     edx, eax
        cmovae  eax, [esi+TText.GapEnd]
        sub     eax, [esi+TText.GapBegin]
        add     eax, edx

        movzx   eax, byte [esi+eax]

                                ; compute the length of the UTF-8 character by its first byte (version without branches) Is it fast?
        not     al              ; utf-8 starts with one of: 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, 1111110x
        bsr     eax, eax        ; eax =                 7,  5,  4,  3,  2,  1
................................................................................

  if pos eqtype eax & text eqtype eax
    cmp    pos, [text+TText.GapBegin]
    jb     ..skip
    add    pos, [text+TText.GapEnd]
    sub    pos, [text+TText.GapBegin]
..skip:
;    cmp    pos, [text+TText.Length]    ; ?????????
;    cmova  pos, [text+TText.Length]    ; ?????????
  else
    error "Error! Arguments must be registers!"
    err
  end if
}


................................................................................
; Duplicates TText structure of any size. Returns pointer to the structure in EAX
; The returned pointer have to be freed with TextFree when not needed anymore.
;
; Arguments:
;   .pText - pointer to the source structure
;
; Returns:
;   CF = 0 if everithing is OK. In this case EAX is a pointer to the new TText structure.
;   CF = 1 if there is an error. The TText is not duplicated and EAX contains the value
;          before the call.
;---------------------------------------------------------------------------------

proc TextDup, .pText
begin
        pushad

        mov     esi, [.pText]
        test    esi, esi
        stc
        jz      .finish

        mov     ecx, [esi+TText.Length]

        add     ecx, [esi+TText.struc_size]

        stdcall GetMem, ecx

        jc      .finish
        mov     edi, eax

        mov     edx, [esi+TText.struc_size]


        add     eax, edx
        mov     [esp+4*regEAX], eax

        sub     esi, edx

        mov     ebx, ecx
        shr     ecx, 2
        and     ebx, 3

        rep movsd

        mov     ecx, ebx
        rep movsb
        clc

.finish:
        popad
        return
endp



proc TextFree, .pText
begin
        push    eax
        mov     eax, [.pText]
................................................................................
        push    eax ecx

        mov     edx, [.pText]

        stdcall TextSetGapSize, edx, 4
        jc      .finish

        mov     eax, [edx+TText.GapBegin]

        pushd   [.char]
        popd    [edx+eax]

        mov     ecx, 4

.len_loop:
        cmp     byte [edx+eax], 0
        je      .len_ok
        inc     eax
        loop    .len_loop

.len_ok:




        mov     [edx+TText.GapBegin], eax
        clc

.finish:
        pop     ecx eax
        return
endp

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

499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
        jmp     .finish


;.........................................................................
; Window paint event

.expose:
        DebugMsg "Expose event."

        stdcall CreateArray, sizeof.RECT
        mov     edi, eax

.add_rect:
        stdcall RectListAddXY, edi, [ebx+XExposeEvent.x], [ebx+XExposeEvent.y], [ebx+XExposeEvent.width], [ebx+XExposeEvent.height]
        mov     edi, edx








<
<







499
500
501
502
503
504
505


506
507
508
509
510
511
512
        jmp     .finish


;.........................................................................
; Window paint event

.expose:


        stdcall CreateArray, sizeof.RECT
        mov     edi, eax

.add_rect:
        stdcall RectListAddXY, edi, [ebx+XExposeEvent.x], [ebx+XExposeEvent.y], [ebx+XExposeEvent.width], [ebx+XExposeEvent.height]
        mov     edi, edx

Changes to freshlib/gui/TAsmEdit.asm.

406
407
408
409
410
411
412

413


414

415
416
417
418
419
420
421
....
1261
1262
1263
1264
1265
1266
1267


1268
1269
1270
1271
1272
1273
1274
1275
....
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375


1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
....
1430
1431
1432
1433
1434
1435
1436


1437
1438


1439
1440
1441

1442
1443
1444
1445
1446
1447
1448
....
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530



1531
1532
1533
1534
1535
1536
1537
....
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553

1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
....
1985
1986
1987
1988
1989
1990
1991
1992


1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
....
2248
2249
2250
2251
2252
2253
2254
2255
2256

2257
2258
2259
2260
2261
2262
2263
....
2349
2350
2351
2352
2353
2354
2355
2356
2357


2358
2359
2360
2361
2362
2363
2364
....
2511
2512
2513
2514
2515
2516
2517
2518
2519



2520
2521
2522

2523
2524
2525
2526
2527
2528
2529
2530
....
2618
2619
2620
2621
2622
2623
2624





2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
....
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728


2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741











2742
2743
2744
2745
2746
2747
2748
....
2810
2811
2812
2813
2814
2815
2816
2817

2818


2819
2820
2821
2822
2823
2824
2825
....
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
....
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938

2939


2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
....
3235
3236
3237
3238
3239
3240
3241
3242

3243
3244
3245
3246
3247

3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
....
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
        cmovs   eax, edx
        set     esi, TAsmEdit:PosY, eax
        jmp     .finish


.scrolldny:
        mov     edx, [esi+TAsmEdit._lines]

        mov     edx, [edx+TText.TextLen]


        shr     edx, 2


        get     eax, esi, TAsmEdit:PosY

        add     eax, [ASM.MouseWheel]
        cmp     eax, edx
        cmova   eax, edx

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

        mov     [.recta.left], eax
        mov     [.recta.top], eax

        mov     edi, [esi+TAsmEdit._lines]
        mov     ecx, [esi+TAsmEdit._line_widths]



        mov     eax, [edi+TText.TextLen]                ; the height of the document in lines x4

;        mov     edx, [ecx+TArray.count]
;        test    edx, edx
;        cmovnz  edx, [ecx + TArray.array + sizeof.TCounter * (edx-1) + TCounter.value]  ; the maximal width of the document.   ??????????????????????????
        mov     edx, $7fffffff

        shr     eax, 2
................................................................................
        xor     ecx, ecx
        test    [esi+TAsmEdit._options], aeoStripedBackground
        cmovnz  ecx, ebx
        and     ecx, 1

        stdcall DrawSolidRect, [.pImage], [.rectr.left], edx, [.rectr.right], [esi+TAsmEdit._font_height], [ASM.clBackground + 4*ecx]

        xor     ecx, ecx

        lea     eax, [4*ebx]
        cmp     eax, [edi+TText.TextLen]
        cmovae  eax, ecx
        jae     .pointer_ok

        cmp     eax, [edi+TText.GapStart]
        jb      .offs_ok

        add     eax, [edi+TText.GapLen]

.offs_ok:
        mov     eax, [edi+eax]          ; the TTextLine structure of the line!

.pointer_ok:



        test    eax, eax
        jz      .text_ok

        stdcall __RenderOneLine, [.pImage], eax, [.recta.left], [.recta.right], [.rectr.left], [.rectr.top]

.text_ok:

        mov     eax, [esi+TAsmEdit._font_height]
        add     [.rectr.top], eax

        inc     ebx
................................................................................
        get     ebx, esi, TAsmEdit:PosY
        lea     ebx, [ebx+ecx+1]                ; line numbers are from 1

        mov     eax, [esi+TAsmEdit._font_height]
        imul    ecx, eax
        imul    edx, eax



        mov     eax, [esi+TAsmEdit._lines]
        mov     eax, [eax+TText.TextLen]


        shr     eax, 2
        mov     [.last], eax



.lines_loop:
        cmp     ecx, edx
        jae     .end_lines

; background

................................................................................
        sub     [.toChar], edx          ; [.toChar] will contains the length
        jle     .finish                 ; nothing to render.

.loop_from:
        dec     edx
        js      .found

        cmp     ecx, [esi+TTextLine.TextLen]
        jae     .finish                         ; the .fromChar is bigger than the length of the text - do nothing.

        xor     eax, eax
        cmp     ecx, [esi+TTextLine.GapStart]
        cmovae  eax, [esi+TTextLine.GapLen]
        add     eax, ecx




        movzx   eax, byte [esi+eax]

                                ; compute the length of the UTF-8 character by its first byte (version without branches) Is it fast?
        not     al              ; utf-8 starts with one of: 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, 1111110x
        bsr     eax, eax        ; eax =                 7,  5,  4,  3,  2,  1
        sub     eax, 7          ; eax =                 0, -2, -3, -4, -5, -6
                                ; CF  =                 0,  1,  1,  1,  1,  1
................................................................................
        jmp     .loop_from


.found:

; here ecx contains the position in the text of [.fromChar]

        mov     eax, [esi+TTextLine.GapStart]
        lea     eax, [esi+eax]
        mov     [.gap_start], eax

        add     eax, [esi+TTextLine.GapLen]

        mov     [.gap_end], eax

        mov     eax, [esi+TTextLine.TextLen]
        cmp     eax, [esi+TTextLine.GapStart]
        jbe     .len_ok
        add     eax, [esi+TTextLine.GapLen]
.len_ok:
        lea     eax, [esi+eax]
        mov     [.txt_end], eax

        xor     eax, eax
        cmp     ecx, [esi+TTextLine.GapStart]
        cmovae  eax, [esi+TTextLine.GapLen]

        add     eax, ecx

        lea     esi, [esi+eax]          ; now esi - the start of the text that have to be drawn

; now loop to the starting TTextChunk

        mov     edx, [.fromChar]
        xor     ebx, ebx
        dec     ebx

................................................................................
        inc     eax

.ypage_ok:

        mov     [esi+TAsmEdit._scrolly.page], eax

        mov     edx, [esi+TAsmEdit._lines]
        mov     edx, [edx+TText.TextLen]


        shr     edx, 2
        sub     edx, eax

        mov     [esi+TAsmEdit._scrolly.max], edx

        popad
        return
endp



................................................................................
        je      .finish

        mov     [esi+TAsmEdit._options], eax
        xor     eax, eax
        mov     [esi+TAsmEdit._img_txt_valid], eax
        mov     [esi+TAsmEdit._img_margin_valid], eax

        exec    ebx, TAsmEdit:ComputeLeftMarginWidth
        exec    esi, TAsmEdit:RectChanged2, eax

        exec    esi, TAsmEdit:UpdateCaretPos

.finish:
        popad
        return
endp

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

        test    [esi+TAsmEdit._options], aeoLeftMargin
        jz      .marginok

        test    [esi+TAsmEdit._options], aeoLineNumbers
        jz      .marginok1

        mov     eax, [esi+TAsmEdit._lines]
        mov     eax, [eax+TText.TextLen]


        shr     eax, 2                          ; the number of the lines.
        test    eax, eax
        jz      .marginok1

        call    .digits
        imul    ecx, [esi+TAsmEdit._numfont_width]
        add     ebx, ecx
................................................................................
        mov     esi, [ebx+TAsmEdit._lines]
        test    esi, esi
        jz      .create_new_lines

        xor     ecx, ecx

.free_loop:
        cmp     ecx, [esi+TText.TextLen]
        jae     .end_free_loop




        mov     eax, ecx
        pos2ofs eax, esi


        stdcall TextFree, [esi+eax]
        add     ecx, 4
        jmp     .free_loop

.end_free_loop:

        stdcall TextFree, esi
................................................................................

        mov     eax, [.self]
        mov     esi, [eax+TAsmEdit._lines]

        mov     eax, [.y]
        shl     eax, 2






        cmp     eax, [esi+TText.TextLen]
        jae     .error

        pos2ofs eax, esi
        mov     eax, [esi+eax]

        clc
        pop     esi
        return

.error:
................................................................................
        cmovz   edi, ecx
        cmovnz  edi, eax        ; scroll more than needed.

        get     edx, esi, TAsmEdit:PosY

        mov     eax, [esi+TAsmEdit._caretPos.y]
        sub     eax, edx                       ; offset from the screen home.
        jz      .finish                        ; no need to scroll
        js      .do_scroll

        sub     eax, ebx
        jle     .finish

        neg     edi

.do_scroll:


        sub     eax, edi
        add     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosY, edx
        exec    esi, TAsmEdit:RectChanged2, ecx

        inc     dword [esp+4*regEAX]

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos
        popad
        return











endp






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

        add     ebx, [.count]
        cmovs   ebx, edx

        add     ecx, [.count]
        cmovs   ecx, edx

        mov     eax, [esi+TAsmEdit._lines]

        mov     eax, [eax+TText.TextLen]


        shr     eax, 2

        cmp     ebx, eax
        cmova   ebx, eax

        add     eax, 2
        sub     eax, [esi+TAsmEdit._height_ch]
................................................................................
        mov     [esi+TAsmEdit._caretPos.y], ebx

        cmp     [.scroll], edx
        je      .scroll_ok

        set     esi, TAsmEdit:PosY, ecx
        exec    esi, TAsmEdit:RectChanged2, edx
        exec    esi, TAsmEdit:UpdateCaretPos

.scroll_ok:

        exec    esi, TAsmEdit:ScrollToCaretY

.finish:
        popad
................................................................................
        pop     eax
        return
endp


method TAsmEdit.CaretTxtEnd
begin
        push    esi

        mov     esi, [.self]
        mov     eax, [esi+TAsmEdit._lines]

        mov     eax, [eax+TText.TextLen]


        shr     eax, 2

        mov     [esi+TAsmEdit._caretPos.y], eax
        exec    esi, TAsmEdit:ScrollToCaretY

        pop     esi
        return
endp


; Selection control methods


................................................................................
        jc      .finish

        mov     eax, [.LineNum]
        shl     eax, 2

        stdcall TextMoveGap, edx, eax

        mov     ebx, [edx+TText.GapStart]


        stdcall TextCreate, sizeof.TTextLine
        mov     [edx+ebx], eax
        lea     ebx, [edx+ebx]


        mov     [esp+4*regEAX], ebx                     ; return value in EAX is the pointer to the new inserted TText.

        add     [edx+TText.GapStart], 4
        add     [edx+TText.TextLen],  4
        sub     [edx+TText.GapLen],   4

;        stdcall IncCount, [esi+TAsmEdit._line_widths], 0
;        mov     [esi+TAsmEdit._line_widths], edx

        clc

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

        exec    [.self], TAsmEdit:TextLine, ebx
        mov     esi, eax

        stdcall TextIndexToPos, esi, [edi+RECT.left]
        stdcall TextMoveGap, esi, eax

        OutputValue "Length before delete: ", [esi+TTextLine.length], 10, -1

        mov     eax, [esi+TTextLine.length]
        cmp     eax, [edi+RECT.right]
        cmova   eax, [edi+RECT.right]
        push    eax

        stdcall TextIndexToPos, esi, eax
        sub     eax, [esi+TTextLine.GapStart]

        add     [esi+TTextLine.GapLen], eax
        sub     [esi+TTextLine.TextLen], eax

        stdcall DecCount, edx, [esi+TTextLine.length]

        pop     eax
        sub     eax, [edi+RECT.left]

        OutputValue "Chars deleted: ", eax, 10, -1

        sub     [esi+TTextLine.length], eax
        sub     [esi+TTextLine.line_width], eax

        stdcall IncCount, edx, [esi+TTextLine.length]

        OutputValue "Length after delete: ", [esi+TTextLine.length], 10, -1
        OutputValue "Bytes after delete: ", [esi+TTextLine.TextLen], 10, -1
        jmp     .y_loop

.next_rect:
        add     edi, sizeof.RECT
        jmp     .rect_loop

.finish:







>
|
>
>
|
>







 







>
>
|







 







<
<

<
<
<
<
|
|
<
|
<
<
<
<
<
<
>
>
|
|

|







 







>
>
|
|
>
>



>







 







|
<
<
|
|
|


>
>
>







 







|
|


|
>


|
<
<
<
<
|


|
|
|
>


|







 







|
>
>
|
|

|







 







<

>







 







|
|
>
>







 







|
|
>
>
>

|
<
>








 







>
>
>
>
>
|


<







 







|



|




>
>













>
>
>
>
>
>
>
>
>
>
>







 







|
>
|
>
>







 







<







 







|


|
>
|
>
>





|







 







|
>


<
|

>


|
<
<

|







 







<
<


|



|
<
|
<


<

|
<
<





<
<
<







406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
....
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
....
1358
1359
1360
1361
1362
1363
1364


1365




1366
1367

1368






1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
....
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
....
1516
1517
1518
1519
1520
1521
1522
1523


1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
....
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558




1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
....
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
....
2249
2250
2251
2252
2253
2254
2255

2256
2257
2258
2259
2260
2261
2262
2263
2264
....
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
....
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527

2528
2529
2530
2531
2532
2533
2534
2535
2536
....
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638

2639
2640
2641
2642
2643
2644
2645
....
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
....
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
....
2857
2858
2859
2860
2861
2862
2863

2864
2865
2866
2867
2868
2869
2870
....
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
....
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273

3274
3275
3276
3277
3278
3279


3280
3281
3282
3283
3284
3285
3286
3287
3288
....
3337
3338
3339
3340
3341
3342
3343


3344
3345
3346
3347
3348
3349
3350

3351

3352
3353

3354
3355


3356
3357
3358
3359
3360



3361
3362
3363
3364
3365
3366
3367
        cmovs   eax, edx
        set     esi, TAsmEdit:PosY, eax
        jmp     .finish


.scrolldny:
        mov     edx, [esi+TAsmEdit._lines]

        mov     eax, [edx+TText.Length]
        add     eax, [edx+TText.GapBegin]
        sub     eax, [edx+TText.GapEnd]
        shr     eax, 2
        mov     edx, eax                                ; the line count in the text.

        get     eax, esi, TAsmEdit:PosY

        add     eax, [ASM.MouseWheel]
        cmp     eax, edx
        cmova   eax, edx

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

        mov     [.recta.left], eax
        mov     [.recta.top], eax

        mov     edi, [esi+TAsmEdit._lines]
        mov     ecx, [esi+TAsmEdit._line_widths]

        mov     eax, [edi+TText.Length]
        add     eax, [edi+TText.GapBegin]
        sub     eax, [edi+TText.GapEnd]         ; the height of the document in lines x4

;        mov     edx, [ecx+TArray.count]
;        test    edx, edx
;        cmovnz  edx, [ecx + TArray.array + sizeof.TCounter * (edx-1) + TCounter.value]  ; the maximal width of the document.   ??????????????????????????
        mov     edx, $7fffffff

        shr     eax, 2
................................................................................
        xor     ecx, ecx
        test    [esi+TAsmEdit._options], aeoStripedBackground
        cmovnz  ecx, ebx
        and     ecx, 1

        stdcall DrawSolidRect, [.pImage], [.rectr.left], edx, [.rectr.right], [esi+TAsmEdit._font_height], [ASM.clBackground + 4*ecx]



        lea     eax, [4*ebx]




        cmp     eax, [edi+TText.GapBegin]
        jb      @f

        add     eax, [edi+TText.GapEnd]






        sub     eax, [edi+TText.GapBegin]
@@:
        cmp     eax, [edi+TText.Length]
        jae     .text_ok

        stdcall __RenderOneLine, [.pImage], [edi+eax], [.recta.left], [.recta.right], [.rectr.left], [.rectr.top]

.text_ok:

        mov     eax, [esi+TAsmEdit._font_height]
        add     [.rectr.top], eax

        inc     ebx
................................................................................
        get     ebx, esi, TAsmEdit:PosY
        lea     ebx, [ebx+ecx+1]                ; line numbers are from 1

        mov     eax, [esi+TAsmEdit._font_height]
        imul    ecx, eax
        imul    edx, eax

        push    edx

        mov     edx, [esi+TAsmEdit._lines]
        mov     eax, [edx+TText.Length]
        add     eax, [edx+TText.GapBegin]
        sub     eax, [edx+TText.GapEnd]
        shr     eax, 2
        mov     [.last], eax

        pop     edx

.lines_loop:
        cmp     ecx, edx
        jae     .end_lines

; background

................................................................................
        sub     [.toChar], edx          ; [.toChar] will contains the length
        jle     .finish                 ; nothing to render.

.loop_from:
        dec     edx
        js      .found

        mov     eax, [esi+TTextLine.GapBegin]


        cmp     ecx, eax
        cmovae  eax, [esi+TTextLine.GapEnd]
        sub     eax, [esi+TTextLine.GapBegin]
        add     eax, ecx

        cmp     eax, [esi+TTextLine.Length]
        jae     .finish                         ; the .fromChar is bigger than the length of the text - do nothing.

        movzx   eax, byte [esi+eax]

                                ; compute the length of the UTF-8 character by its first byte (version without branches) Is it fast?
        not     al              ; utf-8 starts with one of: 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, 1111110x
        bsr     eax, eax        ; eax =                 7,  5,  4,  3,  2,  1
        sub     eax, 7          ; eax =                 0, -2, -3, -4, -5, -6
                                ; CF  =                 0,  1,  1,  1,  1,  1
................................................................................
        jmp     .loop_from


.found:

; here ecx contains the position in the text of [.fromChar]

        mov     eax, [esi+TTextLine.GapBegin]
        add     eax, esi
        mov     [.gap_start], eax

        mov     eax, [esi+TTextLine.GapEnd]
        add     eax, esi
        mov     [.gap_end], eax

        mov     eax, [esi+TTextLine.Length]




        add     eax, esi
        mov     [.txt_end], eax

        mov     eax, [esi+TTextLine.GapBegin]
        cmp     ecx, eax
        cmovae  eax, [esi+TTextLine.GapEnd]
        sub     eax, [esi+TTextLine.GapBegin]
        add     eax, ecx

        add     esi, eax         ; now esi - the start of the text that have to be drawn

; now loop to the starting TTextChunk

        mov     edx, [.fromChar]
        xor     ebx, ebx
        dec     ebx

................................................................................
        inc     eax

.ypage_ok:

        mov     [esi+TAsmEdit._scrolly.page], eax

        mov     edx, [esi+TAsmEdit._lines]
        mov     ecx, [edx+TText.Length]
        add     ecx, [edx+TText.GapBegin]
        sub     ecx, [edx+TText.GapEnd]
        shr     ecx, 2
        sub     ecx, eax

        mov     [esi+TAsmEdit._scrolly.max], ecx

        popad
        return
endp



................................................................................
        je      .finish

        mov     [esi+TAsmEdit._options], eax
        xor     eax, eax
        mov     [esi+TAsmEdit._img_txt_valid], eax
        mov     [esi+TAsmEdit._img_margin_valid], eax


        exec    esi, TAsmEdit:RectChanged2, eax
        exec    esi, TAsmEdit:ComputeLeftMarginWidth
        exec    esi, TAsmEdit:UpdateCaretPos

.finish:
        popad
        return
endp

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

        test    [esi+TAsmEdit._options], aeoLeftMargin
        jz      .marginok

        test    [esi+TAsmEdit._options], aeoLineNumbers
        jz      .marginok1

        mov     ecx, [esi+TAsmEdit._lines]
        mov     eax, [ecx+TText.Length]
        add     eax, [ecx+TText.GapBegin]
        sub     eax, [ecx+TText.GapEnd]
        shr     eax, 2                          ; the number of the lines.
        test    eax, eax
        jz      .marginok1

        call    .digits
        imul    ecx, [esi+TAsmEdit._numfont_width]
        add     ebx, ecx
................................................................................
        mov     esi, [ebx+TAsmEdit._lines]
        test    esi, esi
        jz      .create_new_lines

        xor     ecx, ecx

.free_loop:
        mov     eax, [esi+TText.GapBegin]
        cmp     ecx, eax
        cmovae  eax, [esi+TText.GapEnd]
        sub     eax, [esi+TText.GapBegin]
        add     eax, ecx

        cmp     eax, [esi+TText.Length]

        jae     .end_free_loop

        stdcall TextFree, [esi+eax]
        add     ecx, 4
        jmp     .free_loop

.end_free_loop:

        stdcall TextFree, esi
................................................................................

        mov     eax, [.self]
        mov     esi, [eax+TAsmEdit._lines]

        mov     eax, [.y]
        shl     eax, 2

        cmp     eax, [esi+TText.GapBegin]
        jb      @f
        add     eax, [esi+TText.GapEnd]
        sub     eax, [esi+TText.GapBegin]
@@:
        cmp     eax, [esi+TText.Length]
        jae     .error


        mov     eax, [esi+eax]

        clc
        pop     esi
        return

.error:
................................................................................
        cmovz   edi, ecx
        cmovnz  edi, eax        ; scroll more than needed.

        get     edx, esi, TAsmEdit:PosY

        mov     eax, [esi+TAsmEdit._caretPos.y]
        sub     eax, edx                       ; offset from the screen home.
        jz      .finish1                        ; no need to scroll
        js      .do_scroll

        sub     eax, ebx
        jle     .finish2

        neg     edi

.do_scroll:
        DebugMsg "Do scroll."

        sub     eax, edi
        add     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosY, edx
        exec    esi, TAsmEdit:RectChanged2, ecx

        inc     dword [esp+4*regEAX]

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos
        popad
        return

.finish1:
        DebugMsg "Finish 1"
        jmp      .finish

.finish2:
        OutputValue "Finish 2 = ", eax, 10, -1
        OutputValue "Height = ", [esi+TAsmEdit._height], 10, -1

        jmp      .finish

endp






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

        add     ebx, [.count]
        cmovs   ebx, edx

        add     ecx, [.count]
        cmovs   ecx, edx

        mov     edi, [esi+TAsmEdit._lines]

        mov     eax, [edi+TText.Length]
        add     eax, [edi+TText.GapBegin]
        sub     eax, [edi+TText.GapEnd]
        shr     eax, 2

        cmp     ebx, eax
        cmova   ebx, eax

        add     eax, 2
        sub     eax, [esi+TAsmEdit._height_ch]
................................................................................
        mov     [esi+TAsmEdit._caretPos.y], ebx

        cmp     [.scroll], edx
        je      .scroll_ok

        set     esi, TAsmEdit:PosY, ecx
        exec    esi, TAsmEdit:RectChanged2, edx


.scroll_ok:

        exec    esi, TAsmEdit:ScrollToCaretY

.finish:
        popad
................................................................................
        pop     eax
        return
endp


method TAsmEdit.CaretTxtEnd
begin
        push    esi edx

        mov     esi, [.self]
        mov     edx, [esi+TAsmEdit._lines]

        mov     eax, [edx+TText.Length]
        add     eax, [edx+TText.GapBegin]
        sub     eax, [edx+TText.GapEnd]
        shr     eax, 2

        mov     [esi+TAsmEdit._caretPos.y], eax
        exec    esi, TAsmEdit:ScrollToCaretY

        pop     edx esi
        return
endp


; Selection control methods


................................................................................
        jc      .finish

        mov     eax, [.LineNum]
        shl     eax, 2

        stdcall TextMoveGap, edx, eax

        mov     ebx, [edx+TText.GapBegin]
        add     ebx, edx

        stdcall TextCreate, sizeof.TTextLine

        jc      .finish

        mov     [ebx], eax
        mov     [esp+4*regEAX], ebx                     ; return value in EAX is the pointer to the new inserted TText.

        add     [edx+TText.GapBegin], 4



;        stdcall IncCount, [esi+TAsmEdit._line_widths], 0       ; ???????????
;        mov     [esi+TAsmEdit._line_widths], edx

        clc

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

        exec    [.self], TAsmEdit:TextLine, ebx
        mov     esi, eax

        stdcall TextIndexToPos, esi, [edi+RECT.left]
        stdcall TextMoveGap, esi, eax



        mov     eax, [esi+TTextLine.length]
        cmp     eax, [edi+RECT.right]
        cmova   eax, [edi+RECT.right]                   ; delete up to the min(length, RECT.right) utf-8 character position!
        push    eax

        stdcall TextIndexToPos, esi, eax
        sub     eax, [esi+TTextLine.GapBegin]

        add     [esi+TTextLine.GapEnd], eax             ; delete eax bytes!


        stdcall DecCount, edx, [esi+TTextLine.length]

        pop     eax
        sub     eax, [edi+RECT.left]    ; deleted characters!



        sub     [esi+TTextLine.length], eax
        sub     [esi+TTextLine.line_width], eax

        stdcall IncCount, edx, [esi+TTextLine.length]



        jmp     .y_loop

.next_rect:
        add     edi, sizeof.RECT
        jmp     .rect_loop

.finish:

Changes to freshlib/gui/syntax/SyntaxFASM.asm.

59
60
61
62
63
64
65
66
67
68
69



70
71



72
73
74
75
76
77
78
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

        mov     [.Quo], bl
        mov     [edi+TArray.count], ebx
        mov     [.start], ebx

.loop:
        add     ebx, edx
        cmp     ebx, [esi+TTextLine.TextLen]
        jae     .end_of_line

        mov     eax, ebx



        pos2ofs eax, esi




        stdcall DecodeUtf8, [esi+eax]

        cmp     [.SynContext], ciComment
        je      .endif

        cmp     [.SynContext], ciString
        jne     .ifnotstr
................................................................................
                  db 9,0Ah,0Dh,1Ah,20h,'+-/*=<>()[]{}:,|&~#`;\'

endp




call SyntaxFASM2

proc SyntaxFASM2, .pTextLine, .SynContext
.Quo     rb 4
.start   dd ?
.current TTextChunk
begin
        pushad








<
<

|
>
>
>
|

>
>
>







 







<
<







59
60
61
62
63
64
65


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
...
218
219
220
221
222
223
224


225
226
227
228
229
230
231

        mov     [.Quo], bl
        mov     [edi+TArray.count], ebx
        mov     [.start], ebx

.loop:
        add     ebx, edx



        mov     eax, [esi+TTextLine.GapBegin]
        cmp     ebx, eax
        cmovae  eax, [esi+TTextLine.GapEnd]
        sub     eax, [esi+TTextLine.GapBegin]
        add     eax, ebx

        cmp     eax, [esi+TTextLine.Length]
        jae     .end_of_line

        stdcall DecodeUtf8, [esi+eax]

        cmp     [.SynContext], ciComment
        je      .endif

        cmp     [.SynContext], ciString
        jne     .ifnotstr
................................................................................
                  db 9,0Ah,0Dh,1Ah,20h,'+-/*=<>()[]{}:,|&~#`;\'

endp






proc SyntaxFASM2, .pTextLine, .SynContext
.Quo     rb 4
.start   dd ?
.current TTextChunk
begin
        pushad

Changes to freshlib/test_code0/TestAsmEdit.asm.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
128
129
130
131
132
133
134

135

136
137
138
139
140
141
142
@BinaryType GUI, compact

options.DebugMode = 1
  options.DebugMode.NoTimers = 0
  options.DebugMode.XSync = 0
  options.DebugMode.XErrors =0

  options.DebugMode.ComputeFPS = 1
  options.DebugMode.ShowFPS = 1

options.ShowSizes = 1
options.SkipZeroSizes = 1

ThemeGUI equ flat_gui
;ThemeGUI equ win_gui

................................................................................
            Split stHoriz or stJustGap, 2, 32, 0, 100
              Cell cellRedo
              Split stHoriz or stJustGap, 2, 64, 0, 100
                Cell cellCaretWrap
                  Split stHoriz or stJustGap, 2, 64, 0, 100
                    Cell cellConsoleCaret
                    Cell cellEmpty

    Cell cellAsmEdit


SplitEnd




uglobal







|
|







 







>
|
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@BinaryType GUI, compact

options.DebugMode = 1
  options.DebugMode.NoTimers = 0
  options.DebugMode.XSync = 0
  options.DebugMode.XErrors =0

  options.DebugMode.ComputeFPS = 0
  options.DebugMode.ShowFPS = 0

options.ShowSizes = 1
options.SkipZeroSizes = 1

ThemeGUI equ flat_gui
;ThemeGUI equ win_gui

................................................................................
            Split stHoriz or stJustGap, 2, 32, 0, 100
              Cell cellRedo
              Split stHoriz or stJustGap, 2, 64, 0, 100
                Cell cellCaretWrap
                  Split stHoriz or stJustGap, 2, 64, 0, 100
                    Cell cellConsoleCaret
                    Cell cellEmpty
    Split stVert or stJustGap or stOriginBR, 0, 16, 16, 16
      Cell cellAsmEdit
      Cell cellStatusBar

SplitEnd




uglobal