Опубликовано: 2018-07-22 18:55:00
Рисование мышкой
Этот пример демонстрирует работу с курсором мышки и позволяет рисовать на экране.
- ' Written 1999 by: Daryl R. Dubbs '
- '''''''''''''''''''''''''''''''' Initialize '''''''''''''''''''''''''''''''''
- DECLARE SUB Mouse (Funk) ' Declare Mouse sub-program.
- SCREEN 12 ' Graphics mode 12 (640 x 480 pixels, 16 colors)
- Mouse 1 ' Show mouse cursor.
- '''''''''''''''''''''''''''''''' Main Program '''''''''''''''''''''''''''''''
- DO ' Start Main loop.
- Mouse 3 ' Read mouse buttons & coordinates.
- LOCATE 1, 1: PRINT "Buttons:"; B; "Horizontal:"; H; "Vertical:"; V
- SELECT CASE B ' Which button is pressed?
- CASE 1 ' Left button pressed.
- Mouse 2 ' Hide mouse cursor.
- Mouse 3 ' Read buttons & coordinates.
- LINE STEP(0, 0)-(H, V), 14 ' Draw a yellow line.
- Mouse 1 ' Show mouse cursor.
- CASE 2 ' Right button pressed.
- Mouse 2 ' Hide mouse cursor.
- CLS ' Clear screen.
- Mouse 1 ' Show mouse cursor.
- CASE 3 ' Both buttons pressed.
- EXIT DO ' Drop out of Main loop.
- END SELECT ' End select block.
- LOOP ' End Main loop.
- '''''''''''''''''''''''''''''''' Exit Program '''''''''''''''''''''''''''''''
- Mouse 2 ' Hide mouse cursor.
- CLS ' Clear screen.
- SYSTEM ' End program.
- '''''''''''''''''''''''''''''''' Mouse Sub-program '''''''''''''''''''''''''
- ' This sub-program provides mouse support to QBasic programs. '
- ' It is called with one parameter, and performs as follows: '
- ' Mouse 1 Shows mouse cursor '
- ' Mouse 2 Hides mouse cursor '
- ' Mouse 3 Reads button status & co-ordinates '
- ' Notes: '
- ' This sub-program requires Microsoft's mouse driver '
- ' or an equivalent Dos-based mouse driver, which must be loaded and '
- ' running before use. '
- ' Variables B, H and V are global, so be certain not to create any '
- ' other variables of the same name, or you must re-name these. '
- ' Be sure to hide the mouse cursor before performing any graphics '
- ' function, or else any graphics under the cursor will be garbled. '
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- SUB Mouse (Funk) 'Define sub and parameter passed.
- SHARED B, H, V 'Share variables with main sub.
- STATIC Crsr 'Track whether Cursor is shown.
- IF Funk = 1 THEN Crsr = 1 'Show Cursor.
- IF Funk = 2 AND Crsr = 0 THEN EXIT SUB 'Don't hide Cursor more than once.
- IF Funk = 2 AND Crsr = 1 THEN: Crsr = 0 'Hide Cursor.
- POKE 100, 184: POKE 101, Funk: POKE 102, 0 'Poke machine code necessary for
- POKE 103, 205: POKE 104, 51: POKE 105, 137 'using the mouse into memory
- POKE 106, 30: POKE 107, 170: POKE 108, 10 'starting at offset 100 in the
- POKE 109, 137: POKE 110, 14: POKE 111, 187 'current segment. This code is
- POKE 112, 11: POKE 113, 137: POKE 114, 22 'then executed as a unit, via the
- POKE 115, 204: POKE 116, 12: POKE 117, 203 'statement " Call Absolute ".
- CALL ABSOLUTE(100) 'Call machine code.
- B = PEEK(&HAAA) 'Get values for: Buttons
- H = PEEK(&HBBB) + PEEK(&HBBC) * 256 'Horizontal position 2 bytes
- V = PEEK(&HCCC) + PEEK(&HCCD) * 256 'Vertical position 2 bytes
- END SUB 'End of sub-program.
Рисунок 1 – Исходный текст программы
Рисунок 2 – Выполнение программы
Спасибо за прочтение этой статьи.
Прикрепленные файлы: