Fresh IDE . Check-in [26ad3176f8]
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 work on the proper resizing and partial text rendering.
Timelines: family | ancestors | descendants | both | NoCanvasGUI
Files: files | file ages | folders
SHA1:26ad3176f81489ba2df3c8214e361ba293bd499b
User & Date: johnfound 2017-11-30 09:11:45
Context
2017-12-04
12:55
Small fix in buffergap.asm: The function TextCompact only moves the gap, without reallocating the memory.

The procedures ScrollImageH and ScrollImageV has been moved to "graphics/draw.asm";

In TAsmEdit class, the aeoXXXXX options constants has been revised and extended. TAsmEdit.SetCaretXY method has been implemented. In order to handle the selection properly, the caret coordinates must be set only by calling this method.

The selection rendering was implemented in a proper way. Block and char selections are supported for now. The algorithm used allows other kind of selections to be easily added (for example line selection). check-in: a106042c55 user: johnfound tags: NoCanvasGUI

2017-11-30
09:11
TAsmEdit work on the proper resizing and partial text rendering. check-in: 26ad3176f8 user: johnfound tags: NoCanvasGUI
2017-11-29
12:06
Changed the way FreeType load flags are managed. This way, the programs can render the text the user prefered way. Different kind of rendering are possible as well. For example the transparent controls require mandatory grayscale or mono rendering, while the non-transparent can be rendered with subpixel accuracy. This rendering is implemented by the constants troXXXXXXX and the global variable TextRenderOptions.

BlendImage procedure fixed to work with the new TImage. Removed the outdated procedure BlendImageWrap.

Removed the .Operation argument of TWindow.SelfPaint method.

Not finished work on TAsmEdit control. check-in: 80856b2dcb user: johnfound tags: NoCanvasGUI

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/gui/TAsmEdit.asm.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
...
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
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
378
379
380
381
382
383
384
385
386
387
388
389









390
391
392
393
394
395
396
...
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
...
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
...
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
...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
...
581
582
583
584
585
586
587



588
589
590
591
592
593
594
595
596
...
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
...
912
913
914
915
916
917
918



919
920
921
922
923
924
925



926
927
928
929
930
931
932
...
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
....
1189
1190
1191
1192
1193
1194
1195


1196
1197

1198







1199
































































1200
1201
1202

1203
1204
1205
1206
1207
1208






















1209
1210
1211
1212
1213
1214
1215
....
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
....
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
....
1539
1540
1541
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
....
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
....
1610
1611
1612
1613
1614
1615
1616
1617
1618

1619
1620
1621
1622
1623
1624
1625
1626
1627
1628

1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
....
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
....
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711

1712

1713
1714
1715
1716
1717
1718
1719

1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736




1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
....
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777

1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789

1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
....
2560
2561
2562
2563
2564
2565
2566
2567
2568
aeoBorder             = $10
aeoStripedBackground  = $20

aeoScrollYMore = $40            ; scroll Y more than needed in order to scroll less and to scroll more readable.
aeoScrollXMore = $80            ; scroll X more than needed



rrfText = 1
rrfBackground = 2
rrfLeftMargin = 4


struct TUndoInfo
  .pNext     dd ?       ; pointer to the next TUndoInfo structure in the chain.

  .caret_x   dd ?
  .caret_y   dd ?
  .line      dd ?       ; the line number affected.
  .pText     dd ?       ; pointer to the previous TLineInfo of the affected line for chopChanged and chopDeleted
................................................................................

  ._width_ch      dd    ?       ; width and
  ._height_ch     dd    ?       ; height of the window in chars. Should be set on resizing and on font change.

  ._syntax_proc   dd    ?

; parameters



  param .Selection, .GetSelection, .SetSelection
  param .Text,      .GetText,      .SetText

  param .CaretX,    ._caret_x, NONE
  param .CaretY,    ._caret_y, NONE
  param .SelectionX, ._selection_x, NONE
  param .SelectionY, ._selection_y, NONE

  param .PosX,      ._scrollx.pos, ._scrollx.pos
  param .PosY,      ._scrolly.pos, ._scrolly.pos

; param methods



  method  .GetSelection
  method  .SetSelection, .value

  method  .GetText
  method  .SetText, .value

................................................................................
  method .UpdateScrollBar

  method .UpdateCaretPos


; rendering methods

  method ._RenderTxt, .pImage, .pRect, .flags    ; the rectangle contains coordinates in character positions, relative to the begining of the window.
  method ._RenderLM,  .pImage, .from, .to, .flags    ; the rectangle contains coordinates in character positions, relative to the begining of the window.

; Painting methods

  method .SelfPaint, .pDstImage, .xDst, .yDst, .xSrc, .ySrc, .width, .height    ; Paints itself on the caller provided TImage.

; Text navigarion methods

................................................................................
        jmp     .finish
endp





method TAsmEdit._RenderTxt ; .pImage, .pRect, .flags
.rectr RECT  ; relative to the upper left corner of the window
.recta RECT  ; absolute in the document coordinates.
begin
        pushad










        mov     esi, [.self]

        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._width_ch]
        mov     edx, [esi+TAsmEdit._height_ch]
        mov     [.rectr.left], eax
................................................................................
        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, $70000000

        shr     eax, 2
        add     eax, 1000

        mov     [.recta.right], edx
        mov     [.recta.bottom], eax

        lea     edx, [.rectr]
; Not needed in order to allow drawing of the empty areas! Need some code cleanup around.
;        stdcall RectIntersect, edx, edx, [.pRect]
;        jc      .end_draw                               ; nothing to draw









        get     eax, esi, TAsmEdit:PosX
        get     ecx, esi, TAsmEdit:PosY

        add     [.rectr.left], eax
        add     [.rectr.top], ecx
        add     [.rectr.right], eax
        add     [.rectr.bottom], ecx

        lea     ebx, [.recta]
        stdcall RectIntersect, ebx, edx, ebx
        jc      .end_draw                               ; nothing to draw.

        stdcall RectCopy, edx, ebx

        sub     [.rectr.left], eax
        sub     [.rectr.top], ecx
        sub     [.rectr.right], eax
................................................................................
        mov     ebx, [.recta.top]

.line_loop:

        mov     edx, [.rectr.top]
        sub     edx, [esi+TAsmEdit._font_asc]   ; needed for the background and the left margin.

        test    [.flags], rrfBackground
        jz      .background_ok

        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]

.background_ok:

        xor     ecx, ecx

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

................................................................................
        add     eax, [edi+TText.GapLen]

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

.pointer_ok:

;        test    [.flags], rrfLeftMargin
;        jz      .left_margin_ok
;
;        test    [esi+TAsmEdit._options], aeoLeftMargin
;        jz      .left_margin_ok
;
;        or       ecx, -1
;        test    [esi+TAsmEdit._options], aeoLineNumbers
;        cmovnz  ecx, ebx
;
;        stdcall __RenderLeftMargin, [.pImage], ecx, eax, edx, [esi+TAsmEdit._num_margin], [.rectr.top], [esi+TAsmEdit._left_margin], [esi+TAsmEdit._font_height]
;
;.left_margin_ok:

        test    [.flags], rrfText
        jz      .text_ok

        test    eax, eax
        jz      .text_ok

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

.text_ok:

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

        popad
        return
endp



method TAsmEdit._RenderLM ;  .pImage, .from, .to, .flags
begin
        pushad

        OutputValue "LM from:", [.from], 10, -1
        OutputValue "LM to:", [.to], 10, -1

        mov     esi, [.self]

        mov     eax, [esi+TAsmEdit._height_ch]
        mov     ecx, [.from]
        mov     edx, [.to]

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


.lines_loop:
        cmp     ecx, edx
        jae     .end_lines

; background



        stdcall DrawSolidRect, [.pImage], 0, ecx, [esi+TAsmEdit._left_margin], [esi+TAsmEdit._font_height], [ASM.clLeftMargin]
        stdcall DrawSolidRect, [.pImage], [esi+TAsmEdit._left_margin], ecx, 1, [esi+TAsmEdit._font_height], [ASM.clLeftMarginEdge]

; the number

        pushad

        add     ecx, [esi+TAsmEdit._font_asc]

................................................................................
        mov     eax, [.rect_lm.bottom]
        xor     edx, edx
        div     [esi+TAsmEdit._font_height]
        test    edx, edx
        jz      @f
        inc     eax
@@:
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], ecx, eax, 0
        inc     [esi+TAsmEdit._img_margin_valid]

.img_lm_ok:
        mov     ecx, [.rect_lm.left]
        mov     edx, [.rect_lm.top]
        sub     [.rect_lm.right], ecx
        sub     [.rect_lm.bottom], edx
................................................................................
        jc      .text_ok

        cmp     [esi+TAsmEdit._img_txt_valid], 0
        jne     .img_txt_ok


        mov     eax, [.rect_txt.left]



        xor     edx, edx
        mov     ecx, [esi+TAsmEdit._font_width]

        div     ecx
        mov     [.rect_ch.left], eax

        mov     eax, [.rect_txt.right]



        xor     edx, edx
        div     ecx
        test    edx, edx
        jz      @f
        inc     eax
@@:
        mov     [.rect_ch.right], eax
................................................................................
        test    edx, edx
        jz      @f
        inc     eax
@@:
        mov     [.rect_ch.bottom], eax

        lea     eax, [.rect_ch]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax, rrfText or rrfBackground
        inc     [esi+TAsmEdit._img_txt_valid]

.img_txt_ok:

        mov     ecx, [.rect_txt.left]
        mov     edx, [.rect_txt.top]
        sub     [.rect_txt.right], ecx
................................................................................
        stdcall SetImageWrap, edi, ecx, edx
        retn

endp


method TAsmEdit.Resize


begin
        inherited [.newWidth], [.newHeight]









        exec    [.self], TAsmEdit:ComputeScreenInChars
































































        exec    [.self], TAsmEdit:UpdateScrollBar
        exec    [.self], TAsmEdit:RectChanged2, 0


        return
endp



; parameters get/set methods
























method TAsmEdit.GetSelection
begin

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

; Navigation manipulation methods.



method TAsmEdit.ScrollToCaretX
.max_col   dd ? ; the maximal column NOT including partial columns.
.half_x    dd ?
.quarter_x dd ?
.rect      RECT
begin
        pushad

        mov     esi, [.self]
        mov     edi, [esi+TAsmEdit._lines]
................................................................................
        sub     eax, [GUI.scrollWidth]
        xor     edx, edx
        div     [esi+TAsmEdit._font_width]

        dec     eax
        mov     [.max_col], eax

        shr     eax, 1
        mov     [.half_x], eax

        shr     eax, 1
        mov     [.quarter_x], eax

        mov     eax, [esi+TAsmEdit._caret_x]
        sub     eax, [esi+TAsmEdit._scrollx.pos]    ; offset from the screen home.
        js      .scroll_right

; scroll left
................................................................................
        test    [esi+TAsmEdit._options], aeoScrollXMore
        jz      .morex_ok

        add     eax, [.quarter_x]

.morex_ok:

        mov     edx, [esi+TAsmEdit._scrollx.pos]
        add     edx, eax
        set     esi, TAsmEdit:PosX, edx

        cmp     eax, [.half_x]
        ja      .paint_all


; now scroll the screen left

        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_width]

        mov     ecx, [esi+TAsmEdit._width_ch]
        imul    ecx, [esi+TAsmEdit._font_width]

        stdcall ScrollImageH, [esi+TAsmEdit._imgText], edx


        mov     edx, [esi+TAsmEdit._width_ch]
        dec     edx

        sub     eax, edx
        neg     eax

;        OutputValue "Scroll left from: ", eax, 10, -1
................................................................................
        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._height_ch]

        mov     [.rect.top], eax
        mov     [.rect.bottom], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax, rrfText or rrfBackground

.changed:
        exec    esi, TAsmEdit:RectChanged2, 0

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos

        popad
        return


.paint_all:
        jmp     .changed


.scroll_right:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollXMore
        jz      .morex_ok2
................................................................................
        xor     ecx, ecx
        mov     edx, [esi+TAsmEdit._scrollx.pos]
        sub     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosX, edx

        cmp     eax, [.half_x]
        ja      .paint_all


        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_width]

        mov     ecx, [esi+TAsmEdit._width_ch]
        imul    ecx, [esi+TAsmEdit._font_width]

        neg     edx
        stdcall ScrollImageH, [esi+TAsmEdit._imgText], edx


        xor     ecx, ecx
        inc     eax

        mov     [.rect.left], ecx
        mov     [.rect.right], eax

        mov     eax, [esi+TAsmEdit._height_ch]

        mov     [.rect.top], ecx
        mov     [.rect.bottom], eax

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax, rrfText or rrfBackground

        jmp     .changed

endp



................................................................................
begin
        pushad

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

        mov     eax, [esi+TAsmEdit._height]
        sub     eax, [GUI.scrollWidth]
        xor     edx, edx
        div     [esi+TAsmEdit._font_height]

        dec     eax
        mov     [.max_line], eax

        shr     eax, 1
        mov     [.half_y], eax

        shr     eax, 1
        mov     [.quarter_y], eax

        mov     eax, [esi+TAsmEdit._caret_y]
        sub     eax, [esi+TAsmEdit._scrolly.pos]    ; offset from the screen home.
        js      .scroll_down

; scroll up
................................................................................
.even_scroll_up_ok:

        get     edx, esi, TAsmEdit:PosY
        add     edx, eax

        set     esi, TAsmEdit:PosY, edx

        cmp     eax, [.half_y]
        ja      .paint_all


; now scroll the screen up


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

        stdcall ScrollImageV, [esi+TAsmEdit._imgText], edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgMargin], edx


        mov     edx, [esi+TAsmEdit._height_ch]
        sub     eax, edx
        neg     eax

        dec     eax

        mov     [.rect.top], eax
        mov     [.rect.bottom], edx
        mov     [.rect.left], 0
        mov     eax, [esi+TAsmEdit._width_ch]
        mov     [.rect.right], eax

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax, rrfText or rrfBackground
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom], 0

.changed:




        exec    esi, TAsmEdit:RectChanged2, 0

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos

        popad
        return

.paint_all:
        jmp     .changed



.scroll_down:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollYMore
................................................................................

; scroll always even count lines in Zebra mode.
        bt      eax, ecx
        adc     eax, ecx

.even_scroll_dn_ok:

        mov     edx, [esi+TAsmEdit._scrolly.pos]
        sub     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosY, edx

        cmp     eax, [.half_y]

        ja      .paint_all

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

        mov     ecx, [esi+TAsmEdit._height_ch]
        imul    ecx, [esi+TAsmEdit._font_height]

        neg     edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgText], edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgMargin], edx


        mov     [.rect.bottom], eax
        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._width_ch]
        mov     [.rect.top], eax
        mov     [.rect.left], eax
        mov     [.rect.right], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax, rrfText or rrfBackground
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom], 0

        jmp     .changed

endp



................................................................................
endmodule





include "themes/asmedit.asm"

include "syntax/SyntaxFASM.asm"







<
<
<
<
<
<







 







>
>













>
>







 







|
|







 







|




>
>
>
>
>
>
>
>
>







 







<

>
|
|
|









|
|
>
>
>
>
>
>
>
>










|







 







<
<
<







<
<







 







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







 







|



|
|







 







>
>
>
|
|







 







|







 







>
>
>







>
>
>







 







|







 







>
>

<
>

>
>
>
>
>
>
>

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

|

>






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







 







<







 







|
<
<
<







 







|



|
|
>











>







 







|










<
<
<
<







 







|
|
>










>












|







 







<






|
<
<
<







 







|
<

>
|
>







>













|
|


>
>
>
>







<
<
<
<







 







|


<


|
>
|











>








|
|







 







<

23
24
25
26
27
28
29






30
31
32
33
34
35
36
...
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
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
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
...
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
...
491
492
493
494
495
496
497



498
499
500
501
502
503
504


505
506
507
508
509
510
511
...
515
516
517
518
519
520
521

















522
523
524
525
526
527
528
...
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
...
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
...
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
...
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
...
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
....
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
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
....
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604
1605
1606
1607
1608
....
1612
1613
1614
1615
1616
1617
1618
1619



1620
1621
1622
1623
1624
1625
1626
....
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
....
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689




1690
1691
1692
1693
1694
1695
1696
....
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
....
1752
1753
1754
1755
1756
1757
1758

1759
1760
1761
1762
1763
1764
1765



1766
1767
1768
1769
1770
1771
1772
....
1792
1793
1794
1795
1796
1797
1798
1799

1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839




1840
1841
1842
1843
1844
1845
1846
....
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865

1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
....
2653
2654
2655
2656
2657
2658
2659

2660
aeoBorder             = $10
aeoStripedBackground  = $20

aeoScrollYMore = $40            ; scroll Y more than needed in order to scroll less and to scroll more readable.
aeoScrollXMore = $80            ; scroll X more than needed








struct TUndoInfo
  .pNext     dd ?       ; pointer to the next TUndoInfo structure in the chain.

  .caret_x   dd ?
  .caret_y   dd ?
  .line      dd ?       ; the line number affected.
  .pText     dd ?       ; pointer to the previous TLineInfo of the affected line for chopChanged and chopDeleted
................................................................................

  ._width_ch      dd    ?       ; width and
  ._height_ch     dd    ?       ; height of the window in chars. Should be set on resizing and on font change.

  ._syntax_proc   dd    ?

; parameters

  param .Options, ._options, .SetOptions

  param .Selection, .GetSelection, .SetSelection
  param .Text,      .GetText,      .SetText

  param .CaretX,    ._caret_x, NONE
  param .CaretY,    ._caret_y, NONE
  param .SelectionX, ._selection_x, NONE
  param .SelectionY, ._selection_y, NONE

  param .PosX,      ._scrollx.pos, ._scrollx.pos
  param .PosY,      ._scrolly.pos, ._scrolly.pos

; param methods

  method  .SetOptions, .value

  method  .GetSelection
  method  .SetSelection, .value

  method  .GetText
  method  .SetText, .value

................................................................................
  method .UpdateScrollBar

  method .UpdateCaretPos


; rendering methods

  method ._RenderTxt, .pImage, .pRect           ; the rectangle contains coordinates in character positions, relative to the begining of the window.
  method ._RenderLM,  .pImage, .from, .to       ; .from, .to in character positions, relative to the begining of the window.

; Painting methods

  method .SelfPaint, .pDstImage, .xDst, .yDst, .xSrc, .ySrc, .width, .height    ; Paints itself on the caller provided TImage.

; Text navigarion methods

................................................................................
        jmp     .finish
endp





method TAsmEdit._RenderTxt ; .pImage, .pRect
.rectr RECT  ; relative to the upper left corner of the window
.recta RECT  ; absolute in the document coordinates.
begin
        pushad

;if defined options.DebugMode & options.DebugMode
;        mov     eax, [.pRect]
;        mov     ecx, [eax+RECT.right]
;        mov     edx, [eax+RECT.bottom]
;        sub     ecx, [eax+RECT.left]
;        sub     edx, [eax+RECT.top]
;        OutputRect [eax+RECT.left], [eax+RECT.top], ecx, edx
;end if

        mov     esi, [.self]

        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._width_ch]
        mov     edx, [esi+TAsmEdit._height_ch]
        mov     [.rectr.left], eax
................................................................................
        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
        add     eax, 1000

        mov     [.recta.right], edx
        mov     [.recta.bottom], eax

        lea     edx, [.rectr]
; Not needed in order to allow drawing of the empty areas! Need some code cleanup around.
        stdcall RectIntersect2, edx, [.pRect]
        jc      .end_draw                               ; nothing to draw

;if defined options.DebugMode & options.DebugMode
;        mov     eax, [edx+RECT.right]
;        mov     ecx, [edx+RECT.bottom]
;        sub     eax, [edx+RECT.left]
;        sub     ecx, [edx+RECT.top]
;        OutputRect [edx+RECT.left], [edx+RECT.top], eax, ecx
;end if

        get     eax, esi, TAsmEdit:PosX
        get     ecx, esi, TAsmEdit:PosY

        add     [.rectr.left], eax
        add     [.rectr.top], ecx
        add     [.rectr.right], eax
        add     [.rectr.bottom], ecx

        lea     ebx, [.recta]
        stdcall RectIntersect2, ebx, edx
        jc      .end_draw                               ; nothing to draw.

        stdcall RectCopy, edx, ebx

        sub     [.rectr.left], eax
        sub     [.rectr.top], ecx
        sub     [.rectr.right], eax
................................................................................
        mov     ebx, [.recta.top]

.line_loop:

        mov     edx, [.rectr.top]
        sub     edx, [esi+TAsmEdit._font_asc]   ; needed for the background and the left margin.




        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

................................................................................
        add     eax, [edi+TText.GapLen]

.offs_ok:
        mov     eax, [edi+eax]          ; the TLineInfo 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:

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

        popad
        return
endp



method TAsmEdit._RenderLM ;  .pImage, .from, .to
begin
        pushad

;        OutputValue "LM from:", [.from], 10, -1
;        OutputValue "LM to:", [.to], 10, -1

        mov     esi, [.self]

        mov     eax, [esi+TAsmEdit._height_ch]
        mov     ecx, [.from]
        mov     edx, [.to]

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


.lines_loop:
        cmp     ecx, edx
        jae     .end_lines

; background

        mov     eax, [esi+TAsmEdit._left_margin]
        dec     eax
        stdcall DrawSolidRect, [.pImage], 0, ecx, eax, [esi+TAsmEdit._font_height], [ASM.clLeftMargin]
        stdcall DrawSolidRect, [.pImage], eax, ecx, 1, [esi+TAsmEdit._font_height], [ASM.clLeftMarginEdge]

; the number

        pushad

        add     ecx, [esi+TAsmEdit._font_asc]

................................................................................
        mov     eax, [.rect_lm.bottom]
        xor     edx, edx
        div     [esi+TAsmEdit._font_height]
        test    edx, edx
        jz      @f
        inc     eax
@@:
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], ecx, eax
        inc     [esi+TAsmEdit._img_margin_valid]

.img_lm_ok:
        mov     ecx, [.rect_lm.left]
        mov     edx, [.rect_lm.top]
        sub     [.rect_lm.right], ecx
        sub     [.rect_lm.bottom], edx
................................................................................
        jc      .text_ok

        cmp     [esi+TAsmEdit._img_txt_valid], 0
        jne     .img_txt_ok


        mov     eax, [.rect_txt.left]
        sub     eax, [esi+TAsmEdit._left_margin]
        jl      .img_txt_ok

        xor     edx, edx
        mov     ecx, [esi+TAsmEdit._font_width]

        div     ecx
        mov     [.rect_ch.left], eax

        mov     eax, [.rect_txt.right]
        sub     eax, [esi+TAsmEdit._left_margin]
        jl      .img_txt_ok

        xor     edx, edx
        div     ecx
        test    edx, edx
        jz      @f
        inc     eax
@@:
        mov     [.rect_ch.right], eax
................................................................................
        test    edx, edx
        jz      @f
        inc     eax
@@:
        mov     [.rect_ch.bottom], eax

        lea     eax, [.rect_ch]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        inc     [esi+TAsmEdit._img_txt_valid]

.img_txt_ok:

        mov     ecx, [.rect_txt.left]
        mov     edx, [.rect_txt.top]
        sub     [.rect_txt.right], ecx
................................................................................
        stdcall SetImageWrap, edi, ecx, edx
        retn

endp


method TAsmEdit.Resize
.rect     RECT
.rect_ch  RECT
begin

        pushad

        mov     esi, [.self]
        mov     ebx, [esi+TAsmEdit._width]      ; the old values
        mov     ecx, [esi+TAsmEdit._height]     ; of the height and width
        mov     edi, [esi+TAsmEdit._width_ch]   ;
        mov     edx, [esi+TAsmEdit._height_ch]

        inherited [.newWidth], [.newHeight]
        exec    [.self], TAsmEdit:ComputeScreenInChars

        cmp     [esi+TAsmEdit._width], ebx
        jbe     .render_right_ok

        dec     edi
        js      .render_right_ok

        mov     [.rect.left], ebx
        mov     [.rect_ch.left], edi

        mov     ebx, [esi+TAsmEdit._width]
        mov     edi, [esi+TAsmEdit._width_ch]
        mov     [.rect.right], ebx
        mov     [.rect_ch.right], edi

        xor     eax, eax
        mov     [.rect.top], eax
        mov     [.rect_ch.top], eax

        mov     eax, [esi+TAsmEdit._height]
        mov     ebx, [esi+TAsmEdit._height_ch]
        mov     [.rect.bottom], eax
        mov     [.rect_ch.bottom], edx

        lea     eax, [.rect_ch]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax

        lea     eax, [.rect]
        exec    esi, TAsmEdit:RectChanged2, eax

.render_right_ok:

        cmp     [esi+TAsmEdit._height], ecx
        jbe     .render_bottom_ok

        dec     edx
        js      .render_bottom_ok

        mov     [.rect.top], ecx
        mov     [.rect_ch.top], edx

        mov     ecx, [esi+TAsmEdit._height]
        mov     edx, [esi+TAsmEdit._height_ch]
        mov     [.rect.bottom], ecx
        mov     [.rect_ch.bottom], edx

        xor     eax, eax
        mov     [.rect.left], eax
        mov     [.rect_ch.left], eax

        mov     eax, [esi+TAsmEdit._width]
        mov     edx, [esi+TAsmEdit._width_ch]
        mov     [.rect.right], eax
        mov     [.rect_ch.right], edx

        lea     eax, [.rect_ch]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect_ch.top], [.rect_ch.bottom]

        lea     eax, [.rect]
        exec    esi, TAsmEdit:RectChanged2, eax

.render_bottom_ok:

        exec    [.self], TAsmEdit:UpdateScrollBar
;        exec    [.self], TAsmEdit:RectChanged2, 0

        popad
        return
endp



; parameters get/set methods

method TAsmEdit.SetOptions
begin
        pushad

        mov     esi, [.self]
        mov     eax, [.value]

        cmp     eax, [esi+TAsmEdit._options]
        je      .finish

        mov     [esi+TAsmEdit._options], eax
        xor     eax, eax
        mov     [esi+TAsmEdit._img_txt_valid], eax
        exec    esi, TAsmEdit:RectChanged2, eax

.finish:
        popad
        return
endp




method TAsmEdit.GetSelection
begin

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

; Navigation manipulation methods.



method TAsmEdit.ScrollToCaretX
.max_col   dd ? ; the maximal column NOT including partial columns.

.quarter_x dd ?
.rect      RECT
begin
        pushad

        mov     esi, [.self]
        mov     edi, [esi+TAsmEdit._lines]
................................................................................
        sub     eax, [GUI.scrollWidth]
        xor     edx, edx
        div     [esi+TAsmEdit._font_width]

        dec     eax
        mov     [.max_col], eax

        shr     eax, 2



        mov     [.quarter_x], eax

        mov     eax, [esi+TAsmEdit._caret_x]
        sub     eax, [esi+TAsmEdit._scrollx.pos]    ; offset from the screen home.
        js      .scroll_right

; scroll left
................................................................................
        test    [esi+TAsmEdit._options], aeoScrollXMore
        jz      .morex_ok

        add     eax, [.quarter_x]

.morex_ok:

        get     edx, esi, TAsmEdit:PosX
        add     edx, eax
        set     esi, TAsmEdit:PosX, edx

        cmp     eax, [esi+TAsmEdit._width_ch]
        cmova   eax, [esi+TAsmEdit._width_ch]
        jae     .scroll_left_ok

; now scroll the screen left

        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_width]

        mov     ecx, [esi+TAsmEdit._width_ch]
        imul    ecx, [esi+TAsmEdit._font_width]

        stdcall ScrollImageH, [esi+TAsmEdit._imgText], edx

.scroll_left_ok:
        mov     edx, [esi+TAsmEdit._width_ch]
        dec     edx

        sub     eax, edx
        neg     eax

;        OutputValue "Scroll left from: ", eax, 10, -1
................................................................................
        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._height_ch]

        mov     [.rect.top], eax
        mov     [.rect.bottom], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax

.changed:
        exec    esi, TAsmEdit:RectChanged2, 0

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos

        popad
        return






.scroll_right:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollXMore
        jz      .morex_ok2
................................................................................
        xor     ecx, ecx
        mov     edx, [esi+TAsmEdit._scrollx.pos]
        sub     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosX, edx

        cmp     eax, [esi+TAsmEdit._width_ch]
        cmova   eax, [esi+TAsmEdit._width_ch]
        jae     .scroll_right_ok

        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_width]

        mov     ecx, [esi+TAsmEdit._width_ch]
        imul    ecx, [esi+TAsmEdit._font_width]

        neg     edx
        stdcall ScrollImageH, [esi+TAsmEdit._imgText], edx

.scroll_right_ok:
        xor     ecx, ecx
        inc     eax

        mov     [.rect.left], ecx
        mov     [.rect.right], eax

        mov     eax, [esi+TAsmEdit._height_ch]

        mov     [.rect.top], ecx
        mov     [.rect.bottom], eax

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax

        jmp     .changed

endp



................................................................................
begin
        pushad

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

        mov     eax, [esi+TAsmEdit._height]

        xor     edx, edx
        div     [esi+TAsmEdit._font_height]

        dec     eax
        mov     [.max_line], eax

        shr     eax, 2



        mov     [.quarter_y], eax

        mov     eax, [esi+TAsmEdit._caret_y]
        sub     eax, [esi+TAsmEdit._scrolly.pos]    ; offset from the screen home.
        js      .scroll_down

; scroll up
................................................................................
.even_scroll_up_ok:

        get     edx, esi, TAsmEdit:PosY
        add     edx, eax

        set     esi, TAsmEdit:PosY, edx

; now scroll the screen up


        cmp     eax, [esi+TAsmEdit._height_ch]
        cmova   eax, [esi+TAsmEdit._height_ch]
        jae     .scroll_up_ok

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

        stdcall ScrollImageV, [esi+TAsmEdit._imgText], edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgMargin], edx

.scroll_up_ok:
        mov     edx, [esi+TAsmEdit._height_ch]
        sub     eax, edx
        neg     eax

        dec     eax

        mov     [.rect.top], eax
        mov     [.rect.bottom], edx
        mov     [.rect.left], 0
        mov     eax, [esi+TAsmEdit._width_ch]
        mov     [.rect.right], eax

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom]

.changed:

; In the best case, only the changed part of the window should be refreshed. Especially on the
; relatively narrow assembly source text, the proper updated rectangle can increase the performance
; on big resolutions.
        exec    esi, TAsmEdit:RectChanged2, 0

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos

        popad
        return






.scroll_down:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollYMore
................................................................................

; scroll always even count lines in Zebra mode.
        bt      eax, ecx
        adc     eax, ecx

.even_scroll_dn_ok:

        get     edx, esi, TAsmEdit:PosY
        sub     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosY, edx

        cmp     eax, [esi+TAsmEdit._height_ch]
        cmova   eax, [esi+TAsmEdit._height_ch]
        jae     .scroll_down_ok

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

        mov     ecx, [esi+TAsmEdit._height_ch]
        imul    ecx, [esi+TAsmEdit._font_height]

        neg     edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgText], edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgMargin], edx

.scroll_down_ok:
        mov     [.rect.bottom], eax
        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._width_ch]
        mov     [.rect.top], eax
        mov     [.rect.left], eax
        mov     [.rect.right], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom]

        jmp     .changed

endp



................................................................................
endmodule





include "themes/asmedit.asm"

include "syntax/SyntaxFASM.asm"

Changes to freshlib/gui/TWindow.asm.

1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
....
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287


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

        DebugMsg "TWindow.Resize"

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

        mov     ebx, [.newWidth]
        mov     ecx, [.newHeight]
        mov     eax, ebx
        mov     edx, ecx
................................................................................
        cmp     eax, ebx        ; newW, oldW
        ja      .updateW

        cmp     edx, ecx        ; newH, oldH
        ja      .updateH

.exit:
        DebugMsg "Call TWindow:__UpdateImages"

        exec    esi, TWindow:__UpdateImages
        popad
        return

.updateW:

        mov     [.rect1.top], 0                 ; 0







<
<







 







<
<







1253
1254
1255
1256
1257
1258
1259


1260
1261
1262
1263
1264
1265
1266
....
1270
1271
1272
1273
1274
1275
1276


1277
1278
1279
1280
1281
1282
1283


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

Changes to freshlib/test_code0/TestAsmEdit.asm.

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
endp




proc ToggleZebra as TButton.OnClick
begin
        pushad

        mov     esi, [AsmEdit]
        xor     [esi+TAsmEdit._options], aeoStripedBackground

;        exec    esi, TAsmEdit:Refresh

        popad

        return
endp


proc ToggleScrollX as TButton.OnClick
begin
        pushad

        mov     esi, [AsmEdit]
        xor     [esi+TAsmEdit._options], aeoScrollXMore

;        exec    esi, TAsmEdit:Refresh

        popad

        return
endp


proc ToggleScrollY as TButton.OnClick
begin
        pushad

        mov     esi, [AsmEdit]
        xor     [esi+TAsmEdit._options], aeoScrollYMore

;        exec    esi, TAsmEdit:Refresh

        popad

        return
endp


proc DoUndo as TButton.OnClick
begin
        pushad







|
<
<
|
<
<
<
<
>






|
<
<
|
<
<
<
<
>






|
<
<
|
<
<
<
<
>







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
endp




proc ToggleZebra as TButton.OnClick
begin
        get     eax, [AsmEdit], TAsmEdit:Options


        xor     eax, aeoStripedBackground




        set     [AsmEdit], TAsmEdit:Options, eax
        return
endp


proc ToggleScrollX as TButton.OnClick
begin
        get     eax, [AsmEdit], TAsmEdit:Options


        xor     eax, aeoScrollXMore




        set     [AsmEdit], TAsmEdit:Options, eax
        return
endp


proc ToggleScrollY as TButton.OnClick
begin
        get     eax, [AsmEdit], TAsmEdit:Options


        xor     eax, aeoScrollYMore




        set     [AsmEdit], TAsmEdit:Options, eax
        return
endp


proc DoUndo as TButton.OnClick
begin
        pushad