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 On_Blur( this : access Push_Button ); 
  37.  
  38.     -- Handles Space, Enter and Keypad-Enter keys to turn the button on. 
  39.     procedure On_Key_Press( this    : access Push_Button; 
  40.                             evt     : not null A_Key_Event; 
  41.                             handled : in out Boolean ); 
  42.  
  43.     -- Handles Space, Enter and Keypad-Enter keys to turn the button off. 
  44.     procedure On_Key_Release( this    : access Push_Button; 
  45.                               evt     : not null A_Key_Event; 
  46.                               handled : in out Boolean ); 
  47.  
  48.     -- Handles the left mouse button to dispatch a Held action. 
  49.     procedure On_Mouse_Held( this : access Push_Button; 
  50.                              evt  : not null A_Mouse_Button_Event ); 
  51.  
  52.     -- Handles the left mouse button to press the button. 
  53.     procedure On_Mouse_Press( this : access Push_Button; 
  54.                               evt  : not null A_Mouse_Button_Event ); 
  55.  
  56.     -- Handles the left mouse button to release the button. A Click action 
  57.     -- occurs only if the mouse is released while hovering on the button. 
  58.     -- Otherwise the click is considered aborted. The state still changes to 
  59.     -- False and a Release action still occurs. 
  60.     procedure On_Mouse_Release( this : access Push_Button; 
  61.                                 evt  : not null A_Mouse_Button_Event ); 
  62.  
  63.     -- Toggles the state of the button and then toggles it back again. (Push 
  64.     -- buttons don't stay on!) Both Press and Release actions will occur. 
  65.     procedure Toggle_State( this : access Push_Button ); 
  66.  
  67. end Widgets.Buttons.Pushes;