1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. limited with Game_Views; 
  10.  
  11. package Widgets.Buttons.Toggles is 
  12.  
  13.     -- A Toggle_Button is a variation of a button that toggles its state when 
  14.     -- pressed with a mouse or activated with the keyboard. It's state remains 
  15.     -- until the mouse presses on it again to toggle the state back again. 
  16.     type Toggle_Button is new Button with private; 
  17.     type A_Toggle_Button is access all Toggle_Button'Class; 
  18.  
  19.     -- Creates a new toggle button within 'view' with id 'id'. 'text' is the 
  20.     -- button's text and 'icon' is the filename of the icon to use. Both are 
  21.     -- optional but at least one should be specified or the button will be 
  22.     -- blank. The default state of the new button is False. 
  23.     function Create_Toggle_Button( view : not null access Game_Views.Game_View'Class; 
  24.                                    id   : String; 
  25.                                    text : String := ""; 
  26.                                    icon : String := "" ) return A_Button; 
  27.     pragma Precondition( id'Length > 0 ); 
  28.     pragma Postcondition( Create_Toggle_Button'Result /= null ); 
  29.  
  30. private 
  31.  
  32.     type Toggle_Button is new Button with null record; 
  33.  
  34.     -- Handles Space, Enter and Keypad-Enter keys to toggle the state of the 
  35.     -- button. 
  36.     procedure On_Key_Press( this    : access Toggle_Button; 
  37.                             evt     : not null A_Key_Event; 
  38.                             handled : in out Boolean ); 
  39.  
  40.     -- Handles a left mouse button press to toggle the state of the button. The 
  41.     -- other mouse buttons are not used. 
  42.     procedure On_Mouse_Press( this : access Toggle_Button; 
  43.                               evt  : not null A_Mouse_Button_Event ); 
  44.  
  45. end Widgets.Buttons.Toggles;