Fresh IDE . Check-in [6386df457c]
Not logged in

This repository is a mirror!

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

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

Overview
Comment:Work on TAsmEdit;
Timelines: family | ancestors | descendants | both | FreshLibDev
Files: files | file ages | folders
SHA1:6386df457c6362a9c57529d8ec0ab17bac7fb2a1
User & Date: johnfound 2017-04-20 05:58:16
Context
2017-05-11
08:33
Generally here are the changes made during the work on AsmBB and some work on the GUI library.

Better error check in SocketSendall. Added new function "FileTruncateTo" and implemented for Linux and Win32. Work on the TScrollable class and adapting the TTreeView and TAsmEdit for it. check-in: 3e024fbdf2 user: johnfound tags: FreshLibDev

2017-04-20
05:58
Work on TAsmEdit; check-in: 6386df457c user: johnfound tags: FreshLibDev
2017-04-18
14:11
Work on TScrollable and TAsmEdit. check-in: b15c441b4d user: johnfound tags: FreshLibDev
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/gui/TAsmEdit.asm.

388
389
390
391
392
393
394

395
396

397
398
399
400
401

402
403
404
405
406
407
408
409
410
...
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
541
542
543
...
544
545
546
547
548
549
550
551
552
553
554
555

556

557
558
559
560
561
562
563
...
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
...
833
834
835
836
837
838
839
840
841
842
843

844
845
846
847
848
849
850
...
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
...
871
872
873
874
875
876
877

878
879
880
881
882
883
884
....
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287

1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311


1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322










1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335





1336


1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
....
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
....
1387
1388
1389
1390
1391
1392
1393









1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404





1405


1406
1407
1408
1409
1410
1411
1412
....
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
....
1438
1439
1440
1441
1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
....
1495
1496
1497
1498
1499
1500
1501





1502


1503
1504
1505
1506
1507
1508
1509
....
1515
1516
1517
1518
1519
1520
1521

1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533



1534
1535
1536
1537
1538
1539
1540
....
1568
1569
1570
1571
1572
1573
1574





1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
....
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
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
1649
1650
1651
1652
1653
1654
1655
1656
....
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
        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.


        shr     eax, 2


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

        lea     edx, [.rectr]

        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
................................................................................
        test    [esi+TAsmEdit._options], aeoStripedBackground
        cmovnz  ecx, ebx
        and     ecx, 1

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

.background_ok:



        lea     eax, [4*ebx]

        pos2ofs eax, edi












        test    [.flags], rrfLeftMargin
        jz      .left_margin_ok

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

        xor     ecx, ecx
        dec     ecx

        test    [esi+TAsmEdit._options], aeoLineNumbers
        cmovnz  ecx, ebx

        stdcall __RenderLeftMargin, [esi+TAsmEdit._canvas], ecx, [edi+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




        stdcall __RenderOneLine, [esi+TAsmEdit._canvas], [edi+eax], [.recta.left], [.recta.right], [.rectr.left], [.rectr.top]

.text_ok:

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

        inc     ebx
        cmp     ebx, [.recta.bottom]
        jbe     .line_loop

        stdcall UnlockImg, [esi+TAsmEdit._canvas]

.end_draw:

        popad
        return
endp




proc __RenderLeftMargin, .pImage, .LineNum, .pLineIndo, .y, .xTxt, .yTxt, .width, .height
begin


        dec     [.width]
        stdcall DrawSolidRect, [.pImage], 0, [.y], [.width], [.height], [ASM.clLeftMargin]
        stdcall DrawSolidRect, [.pImage], [.width], [.y], 1, [.height], [ASM.clLeftMarginEdge]





        inc     [.LineNum]
        jz      .line_num_ok

        pushad

        stdcall NumToStr, [.LineNum], ntsDec or ntsUnsigned
        push    eax

        stdcall StrPtr, eax
        push    eax

        stdcall GetTextBounds, eax, [eax+string.len], [ASM.NumFont]
................................................................................
        sub     [.xTxt], eax

        pop     eax
        stdcall DrawString, [.pImage], eax, [eax+string.len], [.xTxt], [.yTxt], [ASM.NumFont], [ASM.clLeftMarginText]

        stdcall StrDel ; from the stack

        popad

.line_num_ok:



.finish:

        return
endp



proc __RenderOneLine, .pImage, .pLineInfo, .fromChar, .toChar, .x, .y

................................................................................
.gap_start dd ?
.gap_end   dd ?
.txt_end   dd ?

begin
        pushad

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


        mov     edi, [esi+TLineInfo.syn_array]

; search for the [.fromChar] element.

        xor     ebx, ebx                ; position inside the TTextChunk array.
        xor     ecx, ecx                ; position inside the text
        mov     edx, [.fromChar]        ; counter
................................................................................
        xor     eax, eax
        cmp     [esi+TAsmEdit._font_width], eax
        lea     eax, [eax+1]
        je      .xpage_ok

        mov     eax, [esi+TAsmEdit._width]

        OutputValue "_width: ", eax, 10, -1
        OutputValue "_left_margin: ", [esi+TAsmEdit._left_margin], 10, -1

        sub     eax, [esi+TAsmEdit._left_margin]

        cdq
        idiv    [esi+TAsmEdit._font_width]
        test    eax, eax
        jnz     .xpage_ok

        inc     eax

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

        mov     ecx, [esi+TAsmEdit._line_widths]
        mov     edx, [ecx+TArray.count]
        test    edx, edx
        jz      .xsize_ok

        mov     edx, [ecx+TArray.array+sizeof.TCounter*edx+TCounter.value - sizeof.TCounter]
        sub     edx, eax

.xsize_ok:

        OutputValue "Max X: ", edx, 10, -1

        set     esi, TScrollable:MaxX, edx

; set Y scrollers page and
................................................................................

        xor     eax, eax
        cmp     [esi+TAsmEdit._font_height], eax
        lea     eax, [eax+1]
        je      .ypage_ok

        mov     eax, [esi+TAsmEdit._height]

        cdq
        idiv    [esi+TAsmEdit._font_height]
        test    eax, eax
        jnz     .ypage_ok

        inc     eax

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


; Navigation manipulation methods.



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

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

        mov     eax, [esi+TAsmEdit._width]
        sub     eax, [esi+TAsmEdit._left_margin]

        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


        exec    esi, TAsmEdit:RestoreBackground
        stdcall CaretShow, 0

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

; scroll left

        sub     eax, [.max_col]
        jb      .finish



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

        add     eax, [.quarter_x]

.morex_ok:

        mov     edx, [esi+TAsmEdit._scrX.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 ScrollRectLeft, [esi+TAsmEdit._canvas], [esi+TAsmEdit._left_margin], 0, ecx, [esi+TAsmEdit._height], edx



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

        sub     eax, edx
        neg     eax

        OutputValue "Scroll left from: ", eax, 10, -1
        OutputValue "Scroll left to:   ", edx, 10, -1

        inc     edx
        mov     [.rect.left], eax
        mov     [.rect.right], edx

        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._height_ch]
................................................................................
        mov     [.rect.top], eax
        mov     [.rect.bottom], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:Render, eax, rrfText or rrfBackground

.changed:

        exec    esi, TAsmEdit:RectChanged, 0, FALSE

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos
        stdcall CaretShow, 1
        exec    esi, TAsmEdit:DrawScrollbars

        popad
        return


.paint_all:



        exec    esi, TAsmEdit:Paint
        jmp     .changed



.scroll_right:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollXMore
................................................................................
.morex_ok2:

        xor     ecx, ecx
        mov     edx, [esi+TAsmEdit._scrX.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]






        stdcall ScrollRectRight, [esi+TAsmEdit._canvas], [esi+TAsmEdit._left_margin], 0, ecx, [esi+TAsmEdit._height], edx



        xor     ecx, ecx
        inc     eax

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

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

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

        lea     eax, [.rect]
        exec    esi, TAsmEdit:Render, eax, rrfText or rrfBackground

;        exec    esi, TAsmEdit:RenderLines, 0, [esi+TAsmEdit._height_ch], 0, eax   ; .LineFrom, .LineTo, .CharFrom, .CharTo

        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, 1
        mov     [.half_y], eax

        shr     eax, 1
        mov     [.quarter_y], eax

        exec    esi, TAsmEdit:RestoreBackground
        stdcall CaretShow, 0

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

; scroll up

        sub     eax, [.max_line]
        jb      .finish

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

        add     eax, [.quarter_y]

.morey_ok:
................................................................................

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

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






        stdcall ScrollRectUp, [esi+TAsmEdit._canvas], 0, 0, [esi+TAsmEdit._width], ecx, edx



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

        sub     eax, edx
        neg     eax

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

        lea     eax, [.rect]
        exec    esi, TAsmEdit:Render, eax, rrfText or rrfBackground or rrfLeftMargin

.changed:

        exec    esi, TAsmEdit:RectChanged, 0, FALSE

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos
        stdcall CaretShow, 1
        exec    esi, TAsmEdit:DrawScrollbars

        popad
        return


.paint_all:



        exec    esi, TAsmEdit:Paint
        jmp     .changed



.scroll_down:

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

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

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






        stdcall ScrollRectDn, [esi+TAsmEdit._canvas], 0, 0, [esi+TAsmEdit._width], ecx, 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]
................................................................................



method TAsmEdit.CaretLeftRight
begin
        pushad

; debug only!
        stdcall GetFineTimestamp
        push    eax
; debug only end!

        mov     esi, [.self]

        xor     edx, edx                    ; minimal caret pos 0

        mov     ebx, [esi+TAsmEdit._caret_x]
        add     ebx, [.count]
        cmovs   ebx, edx













        mov     [esi+TAsmEdit._caret_x], ebx
        cmp     [.select], 0
        jne     .select_ok

        mov     [esi+TAsmEdit._selection_x], ebx

.select_ok:
        exec    esi, TAsmEdit:ScrollToCaretX

; debug only!
        stdcall GetFineTimestamp
        sub     eax, [esp]

        OutputValue "Scroll left/right time [us]:", eax, 10, -1

        add     esp, 4
; end debug only!

        popad
        return
endp





method TAsmEdit.CaretUpDown
begin
        pushad

; debug only!
        stdcall GetFineTimestamp
        push    eax
; debug only end!

        mov     esi, [.self]

        xor     edx, edx                    ; minimal caret pos 0

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

        mov     [esi+TAsmEdit._selection_y], ebx

.select_ok:

        exec    esi, TAsmEdit:ScrollToCaretY

; debug only!
        stdcall GetFineTimestamp
        sub     eax, [esp]

        OutputValue "Scroll up/down time [us]:", eax, 10, -1

        add     esp, 4
; end debug only!

        popad
        return
endp










>


>





>
|
|







 








>
>

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







<
|
<



|






>
>
>
|








|












|

>
>



>
>
>
>




<
<







 







|

|


>

>







 







|
<
<
<
<







 







<
<
<

>







 







|
|







 







>







 







|











>












<
<
<
<







|
>
>











>
>
>
>
>
>
>
>
>
>













>
>
>
>
>

>
>







|
|







 







>




<
<






>
>
>


<







 







>
>
>
>
>
>
>
>
>











>
>
>
>
>

>
>







 







<
<







 







>












<
<
<







|







 







>
>
>
>
>

>
>







 







>




<
<




<

>
>
>







 







>
>
>
>
>


|







 







|


|








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










|


<

<

|













|


|







 







|


<

<

|







388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
...
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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558


559
560
561
562
563
564
565
...
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
...
592
593
594
595
596
597
598
599




600
601
602
603
604
605
606
...
853
854
855
856
857
858
859



860
861
862
863
864
865
866
867
868
...
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
...
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
....
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319




1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
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
1387
....
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400


1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417
1418
....
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
....
1466
1467
1468
1469
1470
1471
1472


1473
1474
1475
1476
1477
1478
1479
....
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507



1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
....
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
....
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581


1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
....
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
....
1657
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
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700

1701

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
....
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751

1752

1753
1754
1755
1756
1757
1758
1759
1760
1761
        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
................................................................................
        test    [esi+TAsmEdit._options], aeoStripedBackground
        cmovnz  ecx, ebx
        and     ecx, 1

        stdcall DrawSolidRect, [esi+TAsmEdit._canvas], [.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

        cmp     eax, [edi+TText.GapStart]
        jb      .offs_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, [esi+TAsmEdit._canvas], 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, [esi+TAsmEdit._canvas], eax, [.recta.left], [.recta.right], [.rectr.left], [.rectr.top]

.text_ok:

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

        inc     ebx
        cmp     ebx, [.recta.bottom]
        jb      .line_loop

        stdcall UnlockImg, [esi+TAsmEdit._canvas]

.end_draw:

        popad
        return
endp




proc __RenderLeftMargin, .pImage, .LineNum, .pLineInfo, .y, .xTxt, .yTxt, .width, .height
begin
        pushad

        dec     [.width]
        stdcall DrawSolidRect, [.pImage], 0, [.y], [.width], [.height], [ASM.clLeftMargin]
        stdcall DrawSolidRect, [.pImage], [.width], [.y], 1, [.height], [ASM.clLeftMarginEdge]

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

        inc     [.LineNum]
        jz      .line_num_ok



        stdcall NumToStr, [.LineNum], ntsDec or ntsUnsigned
        push    eax

        stdcall StrPtr, eax
        push    eax

        stdcall GetTextBounds, eax, [eax+string.len], [ASM.NumFont]
................................................................................
        sub     [.xTxt], eax

        pop     eax
        stdcall DrawString, [.pImage], eax, [eax+string.len], [.xTxt], [.yTxt], [ASM.NumFont], [ASM.clLeftMarginText]

        stdcall StrDel ; from the stack

.line_num_ok:

; here draw the different line attributes from TLineInfo structure.



.finish:
        popad
        return
endp



proc __RenderOneLine, .pImage, .pLineInfo, .fromChar, .toChar, .x, .y

................................................................................
.gap_start dd ?
.gap_end   dd ?
.txt_end   dd ?

begin
        pushad

        mov     esi, [.pLineInfo]       ; Should not be called with invalid [.pLineInfo]




        mov     edi, [esi+TLineInfo.syn_array]

; search for the [.fromChar] element.

        xor     ebx, ebx                ; position inside the TTextChunk array.
        xor     ecx, ecx                ; position inside the text
        mov     edx, [.fromChar]        ; counter
................................................................................
        xor     eax, eax
        cmp     [esi+TAsmEdit._font_width], eax
        lea     eax, [eax+1]
        je      .xpage_ok

        mov     eax, [esi+TAsmEdit._width]




        sub     eax, [esi+TAsmEdit._left_margin]
        sub     eax, [GUI.scrollWidth]
        cdq
        idiv    [esi+TAsmEdit._font_width]
        test    eax, eax
        jnz     .xpage_ok

        inc     eax

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

        mov     ecx, [esi+TAsmEdit._line_widths]
        mov     edx, [ecx+TArray.count]
        test    edx, edx
        jz      .xsize_ok

        mov     edx, [ecx+TArray.array+sizeof.TCounter*edx+TCounter.value - sizeof.TCounter]
;        sub     edx, eax
        inc     edx
.xsize_ok:

        OutputValue "Max X: ", edx, 10, -1

        set     esi, TScrollable:MaxX, edx

; set Y scrollers page and
................................................................................

        xor     eax, eax
        cmp     [esi+TAsmEdit._font_height], eax
        lea     eax, [eax+1]
        je      .ypage_ok

        mov     eax, [esi+TAsmEdit._height]
        sub     eax, [GUI.scrollWidth]
        cdq
        idiv    [esi+TAsmEdit._font_height]
        test    eax, eax
        jnz     .ypage_ok

        inc     eax

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


; 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]

        mov     eax, [esi+TAsmEdit._width]
        sub     eax, [esi+TAsmEdit._left_margin]
        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._scrX.pos]    ; offset from the screen home.
        js      .scroll_right

; scroll left

        sub     eax, [.max_col]
        jbe     .finish         ; no need to scroll.

        OutputValue "Scroll distance: ", eax, 10, -1

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

        add     eax, [.quarter_x]

.morex_ok:

        mov     edx, [esi+TAsmEdit._scrX.pos]
        add     edx, eax

        mov     ecx, [esi+TAsmEdit._line_widths]
        mov     ebx, [ecx+TArray.count]
        test    ebx, ebx
        cmovnz  ebx, [ecx+TArray.array+sizeof.TCounter*ebx+TCounter.value - sizeof.TCounter]
        sub     ebx, [esi+TAsmEdit._scrX.page]

        cmp     ebx, edx
        cmovb   ebx, edx

        set     esi, TAsmEdit:MaxX, ebx
        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]

        push    eax

        stdcall CaretShow, 0
        exec    esi, TAsmEdit:RestoreBackground

        stdcall ScrollRectLeft, [esi+TAsmEdit._canvas], [esi+TAsmEdit._left_margin], 0, ecx, [esi+TAsmEdit._height], edx

        pop     eax

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

        sub     eax, edx
        neg     eax

;        OutputValue "Scroll left from: ", eax, 10, -1
;        OutputValue "Scroll left to:   ", edx, 10, -1

        inc     edx
        mov     [.rect.left], eax
        mov     [.rect.right], edx

        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._height_ch]
................................................................................
        mov     [.rect.top], eax
        mov     [.rect.bottom], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:Render, eax, rrfText or rrfBackground

.changed:
        exec    esi, TAsmEdit:DrawScrollbars
        exec    esi, TAsmEdit:RectChanged, 0, FALSE

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos



        popad
        return


.paint_all:
        stdcall CaretShow, 0
        exec    esi, TAsmEdit:RestoreBackground

        exec    esi, TAsmEdit:Paint
        jmp     .changed



.scroll_right:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollXMore
................................................................................
.morex_ok2:

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

        mov     ecx, [esi+TAsmEdit._line_widths]
        mov     ebx, [ecx+TArray.count]
        test    ebx, ebx
        cmovnz  ebx, [ecx+TArray.array+sizeof.TCounter*ebx+TCounter.value - sizeof.TCounter]

        cmp     ebx, edx
        cmovb   ebx, edx

        set     esi, TAsmEdit:MaxX, ebx
        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]

        push    eax

        stdcall CaretShow, 0
        exec    esi, TAsmEdit:RestoreBackground

        stdcall ScrollRectRight, [esi+TAsmEdit._canvas], [esi+TAsmEdit._left_margin], 0, ecx, [esi+TAsmEdit._height], edx

        pop     eax

        xor     ecx, ecx
        inc     eax

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

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

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

        lea     eax, [.rect]
        exec    esi, TAsmEdit:Render, 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._scrY.pos]    ; offset from the screen home.
        js      .scroll_down

; scroll up

        sub     eax, [.max_line]
        jbe     .finish

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

        add     eax, [.quarter_y]

.morey_ok:
................................................................................

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

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

        push    eax

        stdcall CaretShow, 0
        exec    esi, TAsmEdit:RestoreBackground

        stdcall ScrollRectUp, [esi+TAsmEdit._canvas], 0, 0, [esi+TAsmEdit._width], ecx, edx

        pop     eax

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

        sub     eax, edx
        neg     eax

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

        lea     eax, [.rect]
        exec    esi, TAsmEdit:Render, eax, rrfText or rrfBackground or rrfLeftMargin

.changed:
        exec    esi, TAsmEdit:DrawScrollbars
        exec    esi, TAsmEdit:RectChanged, 0, FALSE

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos



        popad
        return


.paint_all:
        stdcall CaretShow, 0
        exec    esi, TAsmEdit:RestoreBackground

        exec    esi, TAsmEdit:Paint
        jmp     .changed



.scroll_down:

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

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

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

        push    eax

        stdcall CaretShow, 0
        exec    esi, TAsmEdit:RestoreBackground

        stdcall ScrollRectDn, [esi+TAsmEdit._canvas], 0, 0, [esi+TAsmEdit._width], ecx, edx

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

        lea     eax, [.rect]
................................................................................



method TAsmEdit.CaretLeftRight
begin
        pushad

if defined options.DebugMode & options.DebugMode
        stdcall GetFineTimestamp
        push    eax
end if

        mov     esi, [.self]

        xor     edx, edx                    ; minimal caret pos 0

        mov     ebx, [esi+TAsmEdit._caret_x]
        add     ebx, [.count]
        cmovs   ebx, edx

;        mov     ecx, [esi+TAsmEdit._line_widths]
;        mov     edx, [ecx+TArray.count]
;        test    edx, edx
;        jz      .xmaxok
;        mov     edx, [ecx+TArray.array+sizeof.TCounter*edx+TCounter.value - sizeof.TCounter]
;;        dec     edx
;.xmaxok:
;        cmp     ebx, edx
;        cmova   ebx, edx

        OutputValue "Caret X = ", ebx, 10, -1

        mov     [esi+TAsmEdit._caret_x], ebx
        cmp     [.select], 0
        jne     .select_ok

        mov     [esi+TAsmEdit._selection_x], ebx

.select_ok:
        exec    esi, TAsmEdit:ScrollToCaretX

if defined options.DebugMode & options.DebugMode
        stdcall GetFineTimestamp
        sub     eax, [esp]

        OutputValue "Scroll left/right time [us]:", eax, 10, -1

        add     esp, 4
end if

        popad
        return
endp





method TAsmEdit.CaretUpDown
begin
        pushad

if defined options.DebugMode & options.DebugMode
        stdcall GetFineTimestamp
        push    eax
end if

        mov     esi, [.self]

        xor     edx, edx                    ; minimal caret pos 0

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

        mov     [esi+TAsmEdit._selection_y], ebx

.select_ok:

        exec    esi, TAsmEdit:ScrollToCaretY

if defined options.DebugMode & options.DebugMode
        stdcall GetFineTimestamp
        sub     eax, [esp]

        OutputValue "Scroll up/down time [us]:", eax, 10, -1

        add     esp, 4
end if

        popad
        return
endp



Changes to freshlib/gui/TScrollable.asm.

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

        mov     edx, TScrollable._scrX
        mov     ecx, TScrollable._scrY
        cmp     [.param], TScrollable.PosX
        cmovne  edx, ecx

        mov     ecx, [esi+edx+TScroller.max]
        sub     ecx, [esi+edx+TScroller.page]

        cmp     eax, ecx
        cmovg   eax, ecx

        cmp     eax, [esi+edx+TScroller.pos]
        je      .finish

        mov     [esi+edx+TScroller.pos], eax
;        exec    esi, TScrollable:RestoreBackground
;        exec    esi, TScrollable:DrawScrollbars

.finish:
        popad
        return
endp

;_________________________________________________________________________________________









<
<



<
<
<

<
<

<







102
103
104
105
106
107
108


109
110
111



112


113

114
115
116
117
118
119
120

        mov     edx, TScrollable._scrX
        mov     ecx, TScrollable._scrY
        cmp     [.param], TScrollable.PosX
        cmovne  edx, ecx

        mov     ecx, [esi+edx+TScroller.max]


        cmp     eax, ecx
        cmovg   eax, ecx




        mov     [esi+edx+TScroller.pos], eax




        popad
        return
endp

;_________________________________________________________________________________________