Reading the Mouse

For V6, Windows Frotz 2002 implements the read_mouse opcode, which provides information on the current mouse position and which mouse buttons are pressed. This differs from the mouse co-ordinates which are written into the game's header, as those co-ordinates are only updated on a mouse click.

In order to read the mouse, an array of four numbers is passed to read_mouse. This array is populated with the y and x co-ordinates of the mouse, a bit mask of which mouse buttons are pressed (with the most important button being represented by the lowest bit), and the last menu selected (which is discussed below). For example:

  Array mouse_table --> 0 0 0 0;

  [ PrintMouse;

     @read_mouse mouse_table;
     print "The mouse is at (";
     print mouse_table-->1, ",", mouse_table-->0, ").^";
     PrintButton("left", mouse_table-->2 & 1);
     PrintButton("right", mouse_table-->2 & 2);
     PrintButton("middle", mouse_table-->2 & 4);
     print "The last menu item selected is (";
     print mouse_table-->3 / 256, ",";
     print mouse_table-->3 & 255, ").^";
   ];

  [ PrintButton button down;

     print "The ", (string) button, " mouse button is ";
     if (down == 0)
       print "not ";
     print "pressed.^";
   ];
The last element in the array populated by read_mouse indicates the last menu selected by the user, if any, with the menu number in the upper byte and the menu item number in the lower byte. Menus are set up with the make_menu opcode. For example:
  Array menu_title string "Testing";
  Array menu_item_1 string "Menu Item 1";
  Array menu_item_2 string "Menu Item 2";
  Array menu_table table 3;

  [ SetMenu;

    menu_table-->1 = menu_title;
    menu_table-->2 = menu_item_1;
    menu_table-->3 = menu_item_2;

    @make_menu 3 menu_table ?menus;
    print "Menus not available^";
  .menus; ;
   ];
The first argument to make_menu is the menu number, which must be 3 or greater. The menu items are numbered in order from 1.

When the user selects a menu item the read_char opcode will return a value of 252. If 252 is declared as a terminating character, then the read opcode will return when a menu is selected.