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.Pushes is 
  12.  
  13.     -- A Push_Button is a variation of a button that is on when it's being 
  14.     -- pressed with the mouse or keyboard, and immediately returns to off when 
  15.     -- the mouse or keyboard is released. It does not stay on until clicked 
  16.     -- again. 
  17.     type Push_Button is new Button with private; 
  18.     type A_Push_Button is access all Push_Button'Class; 
  19.  
  20.     -- Creates a new push button within 'view' with id 'id'. 'text' is the 
  21.     -- button's text and 'icon' is the filename of the icon to use. Both are 
  22.     -- optional but at least one should be specified or the button will be 
  23.     -- blank. 
  24.     function Create_Push_Button( view : not null access Game_Views.Game_View'Class; 
  25.                                  id   : String; 
  26.                                  text : String := ""; 
  27.                                  icon : String := "" ) return A_Button; 
  28.     pragma Precondition( id'Length > 0 ); 
  29.     pragma Postcondition( Create_Push_Button'Result /= null ); 
  30.  
  31. private 
  32.  
  33.     type Push_Button is new Button with null record; 
  34.  
  35.     -- If the button is pressed and it loses input focus, it will release. 
  36.     procedure Handle_Blur( this : access Push_Button ); 
  37.  
  38.     -- Handles Space, Enter and Keypad-Enter keys to turn the button on. 
  39.     function Handle_Key_Press( this : access Push_Button; 
  40.                                evt  : not null A_Key_Event ) return Boolean; 
  41.  
  42.     -- Handles Space, Enter and Keypad-Enter keys to turn the button off. 
  43.     function Handle_Key_Release( this : access Push_Button; 
  44.                                  evt  : not null A_Key_Event ) return Boolean; 
  45.  
  46.     -- Handles the left mouse button to dispatch a Held action. 
  47.     procedure Handle_Mouse_Held( this : access Push_Button; 
  48.                                  evt  : not null A_Mouse_Button_Event ); 
  49.  
  50.     -- Handles the left mouse button to press the button. 
  51.     procedure Handle_Mouse_Press( this : access Push_Button; 
  52.                                   evt  : not null A_Mouse_Button_Event ); 
  53.  
  54.     -- Handles the left mouse button to release the button. A Click action 
  55.     -- occurs only if the mouse is released while hovering on the button. 
  56.     -- Otherwise the click is considered aborted. The state still changes to 
  57.     -- False and a Release action still occurs. 
  58.     procedure Handle_Mouse_Release( this : access Push_Button; 
  59.                                     evt  : not null A_Mouse_Button_Event ); 
  60.  
  61.     -- Toggles the state of the button and then toggles it back again. (Push 
  62.     -- buttons don't stay on!) Both Press and Release actions will occur. 
  63.     procedure Toggle_State( this : access Push_Button ); 
  64.  
  65. end Widgets.Buttons.Pushes;