Author Topic: Another line editor  (Read 6788 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Another line editor
« Reply #15 on: April 19, 2021, 03:24:34 am »
Basic mouse select

Code: QB64: [Select]
  1. DIM Handle AS LONG
  2. DIM curWidth AS INTEGER
  3. DIM curPosX AS INTEGER
  4. DIM curOffset AS _UNSIGNED LONG
  5. DIM newcurOffset AS _UNSIGNED LONG
  6. DIM mouseOffset AS _UNSIGNED LONG
  7. DIM newmouseOffset AS _UNSIGNED LONG
  8. DIM newSelectOffset AS _UNSIGNED LONG
  9. DIM selectOffset AS _UNSIGNED LONG
  10.  
  11.  
  12. DIM CharWidth AS INTEGER
  13. DIM printPos AS INTEGER
  14.  
  15. DIM insertKeyToggle AS _UNSIGNED _BIT
  16. DIM pixelUpDown AS INTEGER
  17.  
  18. DIM selectPosLeftX AS INTEGER
  19. DIM selectPosTopY AS INTEGER
  20. DIM selectPosRightX AS INTEGER
  21. DIM selectPosLowY AS INTEGER
  22.  
  23.  
  24. DIM lines AS INTEGER
  25. lines = 5 * 16
  26.  
  27.  
  28. Text = "Some text to edit"
  29.  
  30. Handle = _NEWIMAGE(400, 400, 32)
  31. SCREEN Handle
  32. M = _MEMIMAGE(Handle)
  33.  
  34.  
  35.  
  36. PRINT "Move cursor with left / right arrow"
  37.  
  38. PRINT "Insert / Type over, Append, Delete, Backspace"
  39.  
  40. PRINT "Move text with up / down arrow. ESC to exit"
  41. PRINT Text
  42.  
  43. curWidth = (_PRINTWIDTH(CHR$(a)) - 2)
  44.  
  45. CharHeight = _FONTHEIGHT
  46. CharWidth = _PRINTWIDTH(CHR$(a))
  47.  
  48.  
  49. curPosX = _PRINTWIDTH(Text)
  50. curOffset = _WIDTH * (15 + lines) + curPosX 'initial
  51.  
  52.  
  53. GOSUB curon
  54. F = 0
  55.  
  56.  
  57.     X = 0
  58.     T1 = TIMER
  59.     DO
  60.  
  61.         _LIMIT 1000
  62.  
  63.         IF _MOUSEINPUT = -1 THEN
  64.             X = _MOUSEX
  65.             Y = _MOUSEY
  66.             IF X < 0 THEN EXIT DO
  67.             IF Y < 0 THEN EXIT DO
  68.             GOSUB curmouseoff
  69.             IF Y + CharHeight < _HEIGHT THEN mouseOffset = Y * _WIDTH + X
  70.             GOSUB curmouseon
  71.  
  72.             IF _MOUSEBUTTON(1) = 0 AND F1 = 1 THEN F1 = 0
  73.             ' IF _MOUSEBUTTON(1) = 0 AND F1 = 3 THEN F1 = 0
  74.  
  75.             IF _MOUSEBUTTON(1) = -1 AND F1 = 1 THEN 'Left mouse button held down to select
  76.                 selectPosRightX = X
  77.                 selectPosLowY = Y
  78.                 GOSUB curSelect
  79.             END IF
  80.  
  81.             IF _MOUSEBUTTON(1) = -1 AND F1 = 0 THEN 'Initial top left position of select block
  82.                 F1 = 1
  83.                 selectOffset = mouseOffset
  84.                 selectPosLeftX = X
  85.                 selectPosTopY = Y
  86.             END IF
  87.  
  88.  
  89.         END IF
  90.  
  91.  
  92.         kh = _KEYHIT
  93.  
  94.         IF kh = 20992 AND insertKeyToggle = 0 AND LEN(Text) >= printPos THEN
  95.             insertKeyToggle = 1 'TYPEOVER mode
  96.             kh = 0
  97.             T1 = TIMER
  98.             GOSUB curoff
  99.             GOSUB cursolidon
  100.             F = 0
  101.         END IF
  102.  
  103.         IF kh = 20992 AND insertKeyToggle = 1 AND LEN(Text) >= printPos THEN
  104.             insertKeyToggle = 0 'INSERT MODE
  105.             kh = 0
  106.             T1 = TIMER
  107.             GOSUB cursolidoff
  108.             GOSUB curon
  109.             F = 0
  110.         END IF
  111.  
  112.         IF insertKeyToggle = 1 THEN
  113.             IF TIMER - T1 > .3 AND F = 1 THEN
  114.                 F = 0
  115.                 T1 = TIMER
  116.                 GOSUB cursolidon
  117.             END IF
  118.         END IF
  119.  
  120.         IF insertKeyToggle = 1 THEN
  121.             IF TIMER - T1 > .3 AND F = 0 THEN
  122.                 F = 1
  123.                 T1 = TIMER
  124.                 GOSUB cursolidoff
  125.             END IF
  126.         END IF
  127.  
  128.         IF insertKeyToggle = 0 THEN
  129.             IF TIMER - T1 > .3 AND F = 0 THEN
  130.                 F = 1
  131.                 T1 = TIMER
  132.                 GOSUB curoff
  133.             END IF
  134.             IF TIMER - T1 > .3 AND F = 1 THEN
  135.                 F = 0
  136.                 T1 = TIMER
  137.                 GOSUB curon
  138.             END IF
  139.         END IF
  140.  
  141.         IF kh > 0 AND insertKeyToggle = 1 THEN GOSUB cursolidon: EXIT DO
  142.         IF kh > 0 AND insertKeyToggle = 0 THEN GOSUB curon: EXIT DO
  143.     LOOP
  144.  
  145.  
  146.     ' PRINT kh
  147.  
  148.     IF kh = 27 THEN END
  149.  
  150.     IF kh = 8 AND curPosX > 0 THEN 'BACKSPACE
  151.         IF insertKeyToggle = 1 THEN GOSUB cursolidoff: insertKeyToggle = 0: GOTO LL3
  152.         GOSUB curoff
  153.         Text = LEFT$(Text, printPos - 2) + MID$(Text, printPos, LEN(Text) - (printPos - 1))
  154.         curPosX = curPosX - CharWidth
  155.         curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  156.         _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  157.         GOSUB curon
  158.         LL3:
  159.     END IF
  160.     '****
  161.  
  162.     '****
  163.     IF kh > 31 AND kh < 127 AND LEN(Text) < printPos AND _PRINTWIDTH(Text) + CharWidth < _WIDTH THEN 'APPEND
  164.         Text = Text + CHR$(kh)
  165.         curPosX = _PRINTWIDTH(Text)
  166.         curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  167.         _PRINTSTRING (0, lines + pixelUpDown), Text
  168.         GOSUB curon
  169.     END IF
  170.     '****
  171.  
  172.     '****
  173.     IF kh > 31 AND kh < 127 AND LEN(Text) >= printPos AND _PRINTWIDTH(Text) + CharWidth < _WIDTH THEN 'INSERT TYPE OVER
  174.         IF insertKeyToggle = 0 THEN 'INSERT MODE
  175.             Text = LEFT$(Text, printPos - 1) + CHR$(kh) + MID$(Text, printPos, LEN(Text) - printPos + 1)
  176.             curPosX = curPosX + CharWidth
  177.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  178.             _PRINTSTRING (0, lines + pixelUpDown), Text
  179.             GOSUB curon
  180.         END IF
  181.  
  182.         IF insertKeyToggle = 1 AND LEN(Text) = printPos THEN 'cursor is pointing to last character
  183.             insertKeyToggle = 0
  184.             GOSUB cursolidoff
  185.             Text = LEFT$(Text, printPos - 1) + CHR$(kh) + MID$(Text, printPos + 1, LEN(Text) - (printPos))
  186.             curPosX = curPosX + CharWidth
  187.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  188.             _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  189.             GOSUB curon
  190.         END IF
  191.  
  192.         IF insertKeyToggle = 1 AND LEN(Text) > printPos THEN 'cursor is pointing to any char except last char
  193.             GOSUB cursolidoff
  194.             Text = LEFT$(Text, printPos - 1) + CHR$(kh) + MID$(Text, printPos + 1, LEN(Text) - (printPos))
  195.             curPosX = curPosX + CharWidth
  196.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  197.             _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  198.             GOSUB cursolidon
  199.         END IF
  200.     END IF 'END INSERT OR TYPE OVER
  201.  
  202.     '****
  203.  
  204.     '****
  205.  
  206.     IF kh = 21248 AND LEN(Text) >= printPos AND _PRINTWIDTH(Text) <= _WIDTH THEN 'DELETE
  207.         IF insertKeyToggle = 1 THEN GOSUB cursolidoff: insertKeyToggle = 0: GOTO LL1
  208.  
  209.         Text = LEFT$(Text, printPos - 1) + MID$(Text, printPos + 1, LEN(Text) - printPos + 1)
  210.         curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX '
  211.         _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  212.         GOSUB curon
  213.         LL1:
  214.     END IF
  215.  
  216.     '****
  217.  
  218.     '****
  219.  
  220.     IF kh = 19200 AND curPosX > 0 THEN 'LEFT ARROW
  221.  
  222.         IF insertKeyToggle = 1 AND LEN(Text) >= printPos THEN
  223.             GOSUB cursolidoff
  224.             curPosX = curPosX - CharWidth
  225.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  226.             GOSUB cursolidon
  227.         END IF
  228.  
  229.         IF insertKeyToggle = 0 THEN
  230.             GOSUB curoff
  231.             curPosX = curPosX - CharWidth
  232.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  233.             GOSUB curon
  234.         END IF
  235.  
  236.     END IF 'END LEFT ARROW
  237.  
  238.     '****
  239.  
  240.     '****
  241.     IF kh = 19712 AND curPosX < _PRINTWIDTH(Text) AND _PRINTWIDTH(Text) < _WIDTH THEN 'RIGHT ARROW
  242.  
  243.         IF insertKeyToggle = 1 AND LEN(Text) = printPos THEN
  244.             insertKeyToggle = 0
  245.             GOSUB cursolidoff
  246.             curPosX = curPosX + CharWidth
  247.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  248.             GOSUB curon
  249.             GOTO LL2
  250.         END IF
  251.  
  252.         IF insertKeyToggle = 1 AND LEN(Text) > printPos THEN
  253.             GOSUB cursolidoff
  254.             curPosX = curPosX + CharWidth
  255.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  256.             GOSUB cursolidon
  257.         END IF
  258.  
  259.         IF insertKeyToggle = 0 THEN
  260.             GOSUB curoff
  261.             curPosX = curPosX + CharWidth
  262.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  263.             GOSUB curon
  264.         END IF
  265.         LL2:
  266.  
  267.     END IF 'END RIGHT ARROW
  268.     '****
  269.  
  270.     '****
  271.     IF kh = 20480 AND lines + pixelUpDown + CharHeight < _HEIGHT THEN 'DOWN ARROW
  272.  
  273.         IF insertKeyToggle = 1 THEN
  274.             pixelUpDown = pixelUpDown + 1
  275.             GOSUB cursolidoff
  276.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  277.             _PRINTSTRING (0, lines + pixelUpDown), Text
  278.             GOSUB cursolidon
  279.         END IF
  280.  
  281.         IF insertKeyToggle = 0 THEN
  282.             pixelUpDown = pixelUpDown + 1
  283.             GOSUB curoff
  284.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  285.             _PRINTSTRING (0, lines + pixelUpDown), Text
  286.             GOSUB curon
  287.         END IF
  288.     END IF
  289.     '**** END DOWN ARROW
  290.  
  291.     '****
  292.     IF kh = 18432 AND lines + pixelUpDown > lines THEN 'UP ARROW
  293.  
  294.         IF insertKeyToggle = 1 THEN
  295.             pixelUpDown = pixelUpDown - 1
  296.             GOSUB cursolidoff
  297.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  298.             _PRINTSTRING (0, lines + pixelUpDown), Text
  299.             GOSUB cursolidon
  300.         END IF
  301.         IF insertKeyToggle = 0 THEN
  302.             pixelUpDown = pixelUpDown - 1
  303.             GOSUB curoff
  304.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  305.             _PRINTSTRING (0, lines + pixelUpDown), Text
  306.             GOSUB curon
  307.         END IF
  308.     END IF
  309.     '**** END UP ARROW
  310.  
  311. '****
  312.  
  313. '****
  314. curmouseon:
  315. FOR Z = 0 TO CharHeight - 1
  316.     newmouseOffset = mouseOffset + Z * _WIDTH
  317.     FOR T = newmouseOffset * 4 TO newmouseOffset * 4 + curWidth * 4 STEP 4
  318.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  319.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  320.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  321.         IF b = 255 AND g = 255 AND r = 255 THEN b = 0: g = 0: r = 255
  322.         IF b = 0 AND g = 0 AND r = 0 THEN b = 255: g = 255: r = 0
  323.         ' _MEMPUT M, M.OFFSET + T + 100, b
  324.         ' _MEMPUT M, M.OFFSET + T + 1 + 100, g
  325.         ' _MEMPUT M, M.OFFSET + T + 2 + 100, r
  326.  
  327.  
  328.  
  329.         _MEMPUT M, M.OFFSET + T, b
  330.         _MEMPUT M, M.OFFSET + T + 1, g
  331.         _MEMPUT M, M.OFFSET + T + 2, r
  332.     NEXT T
  333.  
  334. '****
  335. curmouseoff:
  336. FOR Z = 0 TO CharHeight - 1
  337.     newmouseOffset = mouseOffset + Z * _WIDTH
  338.  
  339.     FOR T = newmouseOffset * 4 TO newmouseOffset * 4 + curWidth * 4 STEP 4
  340.         'locate 100,100: print t
  341.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  342.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  343.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  344.         IF b = 0 AND g = 0 AND r = 255 THEN b = 255: g = 255: r = 255
  345.         IF b = 255 AND g = 255 AND r = 0 THEN b = 0: g = 0: r = 0
  346.         _MEMPUT M, M.OFFSET + T, b
  347.         _MEMPUT M, M.OFFSET + T + 1, g
  348.         _MEMPUT M, M.OFFSET + T + 2, r
  349.     NEXT T
  350.  
  351.  
  352. '****
  353. cursolidon: 'Cursor for TYPE OVER mode  - ON
  354. FOR Z = 0 TO CharHeight - 1
  355.     newcurOffset = curOffset - Z * _WIDTH
  356.  
  357.     FOR T = newcurOffset * 4 TO newcurOffset * 4 + curWidth * 4 STEP 4
  358.  
  359.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  360.         b = b XOR 255
  361.         _MEMPUT M, M.OFFSET + T, b
  362.  
  363.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  364.         g = g XOR 255
  365.         _MEMPUT M, M.OFFSET + T + 1, g
  366.  
  367.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  368.         r = r XOR 0
  369.         _MEMPUT M, M.OFFSET + T + 2, r
  370.     NEXT T
  371.  
  372. printPos = curPosX / CharWidth + 1
  373.  
  374. '****
  375. cursolidoff: 'Cursor for TYPE OVER mode - OFF
  376. FOR Z = 0 TO CharHeight
  377.     newcurOffset = curOffset - Z * _WIDTH
  378.  
  379.     FOR T = newcurOffset * 4 TO newcurOffset * 4 + curWidth * 4 STEP 4
  380.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  381.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  382.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  383.         IF b = 255 AND g = 255 AND r = 0 THEN b = 0: g = 0: r = 0
  384.         IF b = 0 AND g = 0 AND r = 255 THEN b = 255: g = 255: r = 255
  385.         _MEMPUT M, M.OFFSET + T, b
  386.         _MEMPUT M, M.OFFSET + T + 1, g
  387.         _MEMPUT M, M.OFFSET + T + 2, r
  388.     NEXT T
  389. printPos = curPosX / CharWidth + 1
  390. '****
  391.  
  392. curon:
  393. FOR T = curOffset * 4 TO curOffset * 4 + curWidth * 4 STEP 4
  394.     b = 255
  395.     _MEMPUT M, M.OFFSET + T, b
  396.  
  397.     g = 255
  398.     _MEMPUT M, M.OFFSET + T + 1, g
  399.  
  400.     r = 0
  401.     _MEMPUT M, M.OFFSET + T + 2, r
  402. printPos = curPosX / CharWidth + 1
  403.  
  404. '****
  405. curoff:
  406.  
  407. FOR T = curOffset * 4 TO curOffset * 4 + curWidth * 4 STEP 4
  408.  
  409.     b = 0
  410.     _MEMPUT M, M.OFFSET + T, b
  411.  
  412.     g = 0
  413.     _MEMPUT M, M.OFFSET + T + 1, g
  414.  
  415.     r = 0
  416.     _MEMPUT M, M.OFFSET + T + 2, r
  417. printPos = curPosX / CharWidth + 1
  418.  
  419. curSelect:
  420.  
  421. FOR Z = 0 TO ABS(selectPosLowY - selectPosTopY) 'select block height
  422.     newSelectOffset = selectOffset + Z * _WIDTH
  423.     '*                                                            select block width
  424.     FOR T = newSelectOffset * 4 TO newSelectOffset * 4 + (ABS(selectPosRightX - selectPosLeftX) * 4) STEP 4
  425.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  426.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  427.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  428.         IF b = 255 AND g = 255 AND r = 255 THEN b = 0: g = 0: r = 255
  429.         IF b = 0 AND g = 0 AND r = 0 THEN b = 255: g = 255: r = 0
  430.         _MEMPUT M, M.OFFSET + T, b
  431.         _MEMPUT M, M.OFFSET + T + 1, g
  432.         _MEMPUT M, M.OFFSET + T + 2, r
  433.     NEXT T




« Last Edit: April 19, 2021, 04:04:34 am by NOVARSEG »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Another line editor
« Reply #16 on: May 03, 2021, 08:16:57 pm »
Basic mouse select with copy / paste feature  The moved text can not be edited yet.

The code shows some uses of MEMGET and MEMPUT. Very useful for selecting areas of the screen and making cursors of any shape or color etc.  Also the basic editing of a single line of text is shown.

FULLSCREEN has no issues with MEMGET or MEMPUT. 

The code does not use the ELSE statement and does not have any SUBS or FUNCTIONS

Lots of gosubs though :)

Code: QB64: [Select]
  1. DIM Handle AS LONG
  2. DIM curWidth AS INTEGER
  3. DIM curPosX AS INTEGER
  4. DIM curOffset AS _UNSIGNED LONG
  5. DIM newcurOffset AS _UNSIGNED LONG
  6. DIM mouseOffset AS _UNSIGNED LONG
  7. DIM newmouseOffset AS _UNSIGNED LONG
  8. DIM newSelectOffset AS _UNSIGNED LONG
  9. DIM selectOffset AS _UNSIGNED LONG
  10. DIM MoveSelectOffset AS _UNSIGNED LONG
  11.  
  12. DIM CharWidth AS INTEGER
  13. DIM printPos AS INTEGER
  14.  
  15. DIM insertKeyToggle AS _UNSIGNED _BIT
  16. DIM pixelUpDown AS INTEGER
  17.  
  18. DIM selectPosLeftX AS INTEGER
  19. DIM selectPosTopY AS INTEGER
  20. DIM selectPosRightX AS INTEGER
  21. DIM selectPosLowY AS INTEGER
  22.  
  23.  
  24. DIM lines AS INTEGER
  25. lines = 5 * 16
  26.  
  27.  
  28. Text = "Some text to edit"
  29.  
  30. Handle = _NEWIMAGE(400, 400, 32)
  31. SCREEN Handle
  32. M = _MEMIMAGE(Handle)
  33.  
  34.  
  35.  
  36. PRINT "Move cursor with left / right arrow"
  37.  
  38. PRINT "Insert / Type over, Append, Delete, Backspace"
  39.  
  40. PRINT "Move text with up / down arrow. ESC to exit"
  41. PRINT Text
  42.  
  43. curWidth = (_PRINTWIDTH(CHR$(a)) - 2)
  44.  
  45. CharHeight = _FONTHEIGHT
  46. CharWidth = _PRINTWIDTH(CHR$(a))
  47.  
  48.  
  49. curPosX = _PRINTWIDTH(Text)
  50. curOffset = _WIDTH * (15 + lines) + curPosX 'initial
  51.  
  52.  
  53. GOSUB curon
  54. F1 = 0
  55. F = 0
  56.  
  57.     X = 0
  58.     T1 = TIMER
  59.     DO
  60.  
  61.         _LIMIT 1000
  62.  
  63.         IF _MOUSEINPUT = -1 THEN
  64.             X = _MOUSEX
  65.             Y = _MOUSEY
  66.             IF X < 0 THEN EXIT DO
  67.             IF Y < 0 THEN EXIT DO
  68.             GOSUB curmouseoff
  69.             IF Y + CharHeight < _HEIGHT THEN mouseOffset = Y * _WIDTH + X
  70.             GOSUB curmouseon
  71.  
  72.  
  73.             IF _MOUSEBUTTON(1) = 0 AND F1 = 3 THEN F1 = 0 'reset back to zero after paste
  74.  
  75.             IF _MOUSEBUTTON(1) = -1 AND F1 = 2 THEN 'Left mouse button down, pastes image / text
  76.                 F1 = 3
  77.                 MoveSelectOffset = Y * _WIDTH + X
  78.                 GOSUB DropBlock
  79.             END IF
  80.  
  81.             IF _MOUSEBUTTON(1) = 0 AND F1 = 1 THEN F1 = 2 'release left mouse button to get ready for paste
  82.  
  83.  
  84.             IF _MOUSEBUTTON(1) = -1 AND F1 = 1 THEN 'Left mouse button held down to select area
  85.                 selectPosRightX = X
  86.                 selectPosLowY = Y
  87.                 GOSUB curSelect
  88.             END IF
  89.  
  90.             IF _MOUSEBUTTON(1) = -1 AND F1 = 0 THEN 'Initial top left position of select block
  91.                 F1 = 1
  92.                 selectOffset = Y * _WIDTH + X
  93.                 selectPosLeftX = X
  94.                 selectPosTopY = Y
  95.             END IF
  96.  
  97.  
  98.         END IF
  99.  
  100.  
  101.         kh = _KEYHIT
  102.  
  103.         IF kh = 20992 AND insertKeyToggle = 0 AND LEN(Text) >= printPos THEN
  104.             insertKeyToggle = 1 'TYPEOVER mode
  105.             kh = 0
  106.             T1 = TIMER
  107.             GOSUB curoff
  108.             GOSUB cursolidon
  109.             F = 0
  110.         END IF
  111.  
  112.         IF kh = 20992 AND insertKeyToggle = 1 AND LEN(Text) >= printPos THEN
  113.             insertKeyToggle = 0 'INSERT MODE
  114.             kh = 0
  115.             T1 = TIMER
  116.             GOSUB cursolidoff
  117.             GOSUB curon
  118.             F = 0
  119.         END IF
  120.  
  121.         IF insertKeyToggle = 1 THEN
  122.             IF TIMER - T1 > .3 AND F = 1 THEN
  123.                 F = 0
  124.                 T1 = TIMER
  125.                 GOSUB cursolidon
  126.             END IF
  127.         END IF
  128.  
  129.         IF insertKeyToggle = 1 THEN
  130.             IF TIMER - T1 > .3 AND F = 0 THEN
  131.                 F = 1
  132.                 T1 = TIMER
  133.                 GOSUB cursolidoff
  134.             END IF
  135.         END IF
  136.  
  137.         IF insertKeyToggle = 0 THEN
  138.             IF TIMER - T1 > .3 AND F = 0 THEN
  139.                 F = 1
  140.                 T1 = TIMER
  141.                 GOSUB curoff
  142.             END IF
  143.             IF TIMER - T1 > .3 AND F = 1 THEN
  144.                 F = 0
  145.                 T1 = TIMER
  146.                 GOSUB curon
  147.             END IF
  148.         END IF
  149.  
  150.         IF kh > 0 AND insertKeyToggle = 1 THEN GOSUB cursolidon: EXIT DO
  151.         IF kh > 0 AND insertKeyToggle = 0 THEN GOSUB curon: EXIT DO
  152.     LOOP
  153.  
  154.  
  155.     ' PRINT kh
  156.  
  157.     IF kh = 27 THEN END
  158.  
  159.     IF kh = 8 AND curPosX > 0 THEN 'BACKSPACE
  160.         IF insertKeyToggle = 1 THEN GOSUB cursolidoff: insertKeyToggle = 0: GOTO LL3
  161.         GOSUB curoff
  162.         Text = LEFT$(Text, printPos - 2) + MID$(Text, printPos, LEN(Text) - (printPos - 1))
  163.         curPosX = curPosX - CharWidth
  164.         curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  165.         _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  166.         GOSUB curon
  167.         LL3:
  168.     END IF
  169.     '****
  170.  
  171.     '****
  172.     IF kh > 31 AND kh < 127 AND LEN(Text) < printPos AND _PRINTWIDTH(Text) + CharWidth < _WIDTH THEN 'APPEND
  173.         Text = Text + CHR$(kh)
  174.         curPosX = _PRINTWIDTH(Text)
  175.         curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  176.         _PRINTSTRING (0, lines + pixelUpDown), Text
  177.         GOSUB curon
  178.     END IF
  179.     '****
  180.  
  181.     '****
  182.     IF kh > 31 AND kh < 127 AND LEN(Text) >= printPos AND _PRINTWIDTH(Text) + CharWidth < _WIDTH THEN 'INSERT TYPE OVER
  183.         IF insertKeyToggle = 0 THEN 'INSERT MODE
  184.             Text = LEFT$(Text, printPos - 1) + CHR$(kh) + MID$(Text, printPos, LEN(Text) - printPos + 1)
  185.             curPosX = curPosX + CharWidth
  186.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  187.             _PRINTSTRING (0, lines + pixelUpDown), Text
  188.             GOSUB curon
  189.         END IF
  190.  
  191.         IF insertKeyToggle = 1 AND LEN(Text) = printPos THEN 'cursor is pointing to last character
  192.             insertKeyToggle = 0
  193.             GOSUB cursolidoff
  194.             Text = LEFT$(Text, printPos - 1) + CHR$(kh) + MID$(Text, printPos + 1, LEN(Text) - (printPos))
  195.             curPosX = curPosX + CharWidth
  196.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  197.             _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  198.             GOSUB curon
  199.         END IF
  200.  
  201.         IF insertKeyToggle = 1 AND LEN(Text) > printPos THEN 'cursor is pointing to any char except last char
  202.             GOSUB cursolidoff
  203.             Text = LEFT$(Text, printPos - 1) + CHR$(kh) + MID$(Text, printPos + 1, LEN(Text) - (printPos))
  204.             curPosX = curPosX + CharWidth
  205.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  206.             _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  207.             GOSUB cursolidon
  208.         END IF
  209.     END IF 'END INSERT OR TYPE OVER
  210.  
  211.     '****
  212.  
  213.     '****
  214.  
  215.     IF kh = 21248 AND LEN(Text) >= printPos AND _PRINTWIDTH(Text) <= _WIDTH THEN 'DELETE
  216.         IF insertKeyToggle = 1 THEN GOSUB cursolidoff: insertKeyToggle = 0: GOTO LL1
  217.  
  218.         Text = LEFT$(Text, printPos - 1) + MID$(Text, printPos + 1, LEN(Text) - printPos + 1)
  219.         curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX '
  220.         _PRINTSTRING (0, lines + pixelUpDown), Text + " "
  221.         GOSUB curon
  222.         LL1:
  223.     END IF
  224.  
  225.     '****
  226.  
  227.     '****
  228.  
  229.     IF kh = 19200 AND curPosX > 0 THEN 'LEFT ARROW
  230.  
  231.         IF insertKeyToggle = 1 AND LEN(Text) >= printPos THEN
  232.             GOSUB cursolidoff
  233.             curPosX = curPosX - CharWidth
  234.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  235.             GOSUB cursolidon
  236.         END IF
  237.  
  238.         IF insertKeyToggle = 0 THEN
  239.             GOSUB curoff
  240.             curPosX = curPosX - CharWidth
  241.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  242.             GOSUB curon
  243.         END IF
  244.  
  245.     END IF 'END LEFT ARROW
  246.  
  247.     '****
  248.  
  249.     '****
  250.     IF kh = 19712 AND curPosX < _PRINTWIDTH(Text) AND _PRINTWIDTH(Text) < _WIDTH THEN 'RIGHT ARROW
  251.  
  252.         IF insertKeyToggle = 1 AND LEN(Text) = printPos THEN
  253.             insertKeyToggle = 0
  254.             GOSUB cursolidoff
  255.             curPosX = curPosX + CharWidth
  256.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  257.             GOSUB curon
  258.             GOTO LL2
  259.         END IF
  260.  
  261.         IF insertKeyToggle = 1 AND LEN(Text) > printPos THEN
  262.             GOSUB cursolidoff
  263.             curPosX = curPosX + CharWidth
  264.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  265.             GOSUB cursolidon
  266.         END IF
  267.  
  268.         IF insertKeyToggle = 0 THEN
  269.             GOSUB curoff
  270.             curPosX = curPosX + CharWidth
  271.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  272.             GOSUB curon
  273.         END IF
  274.         LL2:
  275.  
  276.     END IF 'END RIGHT ARROW
  277.     '****
  278.  
  279.     '****
  280.     IF kh = 20480 AND lines + pixelUpDown + CharHeight < _HEIGHT THEN 'DOWN ARROW
  281.  
  282.         IF insertKeyToggle = 1 THEN
  283.             pixelUpDown = pixelUpDown + 1
  284.             GOSUB cursolidoff
  285.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  286.             _PRINTSTRING (0, lines + pixelUpDown), Text
  287.             GOSUB cursolidon
  288.         END IF
  289.  
  290.         IF insertKeyToggle = 0 THEN
  291.             pixelUpDown = pixelUpDown + 1
  292.             GOSUB curoff
  293.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  294.             _PRINTSTRING (0, lines + pixelUpDown), Text
  295.             GOSUB curon
  296.         END IF
  297.     END IF
  298.     '**** END DOWN ARROW
  299.  
  300.     '****
  301.     IF kh = 18432 AND lines + pixelUpDown > lines THEN 'UP ARROW
  302.  
  303.         IF insertKeyToggle = 1 THEN
  304.             pixelUpDown = pixelUpDown - 1
  305.             GOSUB cursolidoff
  306.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  307.             _PRINTSTRING (0, lines + pixelUpDown), Text
  308.             GOSUB cursolidon
  309.         END IF
  310.         IF insertKeyToggle = 0 THEN
  311.             pixelUpDown = pixelUpDown - 1
  312.             GOSUB curoff
  313.             curOffset = _WIDTH * (15 + lines + pixelUpDown) + curPosX
  314.             _PRINTSTRING (0, lines + pixelUpDown), Text
  315.             GOSUB curon
  316.         END IF
  317.     END IF
  318.     '**** END UP ARROW
  319.  
  320. '****
  321.  
  322. '****
  323. curmouseon:
  324. FOR Z = 0 TO CharHeight - 1
  325.     newmouseOffset = mouseOffset + Z * _WIDTH
  326.     FOR T = newmouseOffset * 4 TO newmouseOffset * 4 + curWidth * 4 STEP 4
  327.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  328.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  329.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  330.         IF b = 255 AND g = 255 AND r = 255 THEN b = 0: g = 0: r = 255
  331.         IF b = 0 AND g = 0 AND r = 0 THEN b = 255: g = 255: r = 0
  332.         ' _MEMPUT M, M.OFFSET + T + 100, b
  333.         ' _MEMPUT M, M.OFFSET + T + 1 + 100, g
  334.         ' _MEMPUT M, M.OFFSET + T + 2 + 100, r
  335.  
  336.  
  337.  
  338.         _MEMPUT M, M.OFFSET + T, b
  339.         _MEMPUT M, M.OFFSET + T + 1, g
  340.         _MEMPUT M, M.OFFSET + T + 2, r
  341.     NEXT T
  342.  
  343. '****
  344. curmouseoff:
  345. FOR Z = 0 TO CharHeight - 1
  346.     newmouseOffset = mouseOffset + Z * _WIDTH
  347.  
  348.     FOR T = newmouseOffset * 4 TO newmouseOffset * 4 + curWidth * 4 STEP 4
  349.         'locate 100,100: print t
  350.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  351.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  352.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  353.         IF b = 0 AND g = 0 AND r = 255 THEN b = 255: g = 255: r = 255
  354.         IF b = 255 AND g = 255 AND r = 0 THEN b = 0: g = 0: r = 0
  355.         _MEMPUT M, M.OFFSET + T, b
  356.         _MEMPUT M, M.OFFSET + T + 1, g
  357.         _MEMPUT M, M.OFFSET + T + 2, r
  358.     NEXT T
  359.  
  360.  
  361. '****
  362. cursolidon: 'Cursor for TYPE OVER mode  - ON
  363. FOR Z = 0 TO CharHeight - 1
  364.     newcurOffset = curOffset - Z * _WIDTH
  365.  
  366.     FOR T = newcurOffset * 4 TO newcurOffset * 4 + curWidth * 4 STEP 4
  367.  
  368.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  369.         b = b XOR 255
  370.         _MEMPUT M, M.OFFSET + T, b
  371.  
  372.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  373.         g = g XOR 255
  374.         _MEMPUT M, M.OFFSET + T + 1, g
  375.  
  376.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  377.         r = r XOR 0
  378.         _MEMPUT M, M.OFFSET + T + 2, r
  379.     NEXT T
  380.  
  381. printPos = curPosX / CharWidth + 1
  382.  
  383. '****
  384. cursolidoff: 'Cursor for TYPE OVER mode - OFF
  385. FOR Z = 0 TO CharHeight - 1
  386.     newcurOffset = curOffset - Z * _WIDTH
  387.  
  388.     FOR T = newcurOffset * 4 TO newcurOffset * 4 + curWidth * 4 STEP 4
  389.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  390.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  391.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  392.         IF b = 255 AND g = 255 AND r = 0 THEN b = 0: g = 0: r = 0
  393.         IF b = 0 AND g = 0 AND r = 255 THEN b = 255: g = 255: r = 255
  394.         _MEMPUT M, M.OFFSET + T, b
  395.         _MEMPUT M, M.OFFSET + T + 1, g
  396.         _MEMPUT M, M.OFFSET + T + 2, r
  397.     NEXT T
  398. printPos = curPosX / CharWidth + 1
  399. '****
  400.  
  401. curon:
  402. FOR T = curOffset * 4 TO curOffset * 4 + curWidth * 4 STEP 4
  403.     b = 255
  404.     _MEMPUT M, M.OFFSET + T, b
  405.  
  406.     g = 255
  407.     _MEMPUT M, M.OFFSET + T + 1, g
  408.  
  409.     r = 0
  410.     _MEMPUT M, M.OFFSET + T + 2, r
  411. printPos = curPosX / CharWidth + 1
  412.  
  413. '****
  414. curoff:
  415.  
  416. FOR T = curOffset * 4 TO curOffset * 4 + curWidth * 4 STEP 4
  417.  
  418.     b = 0
  419.     _MEMPUT M, M.OFFSET + T, b
  420.  
  421.     g = 0
  422.     _MEMPUT M, M.OFFSET + T + 1, g
  423.  
  424.     r = 0
  425.     _MEMPUT M, M.OFFSET + T + 2, r
  426. printPos = curPosX / CharWidth + 1
  427. '****
  428.  
  429. '*****
  430. curSelect:
  431. FOR Z = 0 TO ABS(selectPosLowY - selectPosTopY) 'select block height
  432.     newSelectOffset = selectOffset + Z * _WIDTH
  433.     '*                                                            select block width
  434.     FOR T = newSelectOffset * 4 TO newSelectOffset * 4 + (ABS(selectPosRightX - selectPosLeftX) * 4) STEP 4
  435.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  436.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  437.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  438.         IF b = 255 AND g = 255 AND r = 255 THEN b = 0: g = 0: r = 255
  439.         IF b = 0 AND g = 0 AND r = 0 THEN b = 255: g = 255: r = 0
  440.         _MEMPUT M, M.OFFSET + T, b
  441.         _MEMPUT M, M.OFFSET + T + 1, g
  442.         _MEMPUT M, M.OFFSET + T + 2, r
  443.     NEXT T
  444. '****
  445.  
  446. '*****
  447. DropBlock:
  448. FOR Z = 0 TO ABS(selectPosLowY - selectPosTopY) 'select block height
  449.     newSelectOffset = selectOffset + Z * _WIDTH
  450.     '*                                                            select block width
  451.     FOR T = newSelectOffset * 4 TO newSelectOffset * 4 + (ABS(selectPosRightX - selectPosLeftX) * 4) STEP 4
  452.         b = _MEMGET(M, M.OFFSET + T, _UNSIGNED _BYTE)
  453.         g = _MEMGET(M, M.OFFSET + T + 1, _UNSIGNED _BYTE)
  454.         r = _MEMGET(M, M.OFFSET + T + 2, _UNSIGNED _BYTE)
  455.         IF b = 255 AND g = 255 AND r = 0 THEN b = 0: g = 0: r = 0
  456.         IF b = 0 AND g = 0 AND r = 255 THEN b = 255: g = 255: r = 255
  457.         T2 = T + ((MoveSelectOffset + Z * _WIDTH) - (selectOffset + Z * _WIDTH)) * 4
  458.  
  459.         _MEMPUT M, M.OFFSET + T2, b
  460.         _MEMPUT M, M.OFFSET + T2 + 1, g
  461.         _MEMPUT M, M.OFFSET + T2 + 2, r
  462.  
  463.     NEXT T
  464.  
  465.  




« Last Edit: May 03, 2021, 08:25:11 pm by NOVARSEG »

Offline LM

  • Newbie
  • Posts: 28
    • View Profile
Re: Another line editor
« Reply #17 on: May 08, 2021, 08:09:18 pm »
@NOVARSEG
Great work.  I can think of uses for this.  I like it!

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Another line editor
« Reply #18 on: May 09, 2021, 08:46:26 am »
Very big armada for a single input...
Why not yes ?