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. with Widgets.Menu_Items;                use Widgets.Menu_Items; 
  10.  
  11. limited with Game_Views; 
  12.  
  13. private with Directions; 
  14. private with Widgets.Containers.Panels.Dialogs; 
  15. private with Widgets.Containers.Panels.Popups; 
  16.  
  17. package Widgets.Sprites.Ked is 
  18.  
  19.     type Ked_Sprite is new Sprite and Menu_Listener and  Visibility_Listener with private; 
  20.     type A_Ked_Sprite is access all Ked_Sprite'Class; 
  21.  
  22.     function Create_Ked_Sprite( view       : not null access Game_Views.Game_View'Class; 
  23.                                 eid        : Entity_Id; 
  24.                                 class      : String; 
  25.                                 x, y       : Float; 
  26.                                 width, 
  27.                                 height     : Natural; 
  28.                                 resizeable : Boolean; 
  29.                                 physical   : Boolean; 
  30.                                 libName    : String; 
  31.                                 frame      : Natural ) return A_Ked_Sprite; 
  32.     pragma Precondition( class'Length > 0 ); 
  33.     pragma Precondition( libName'Length > 0 ); 
  34.     pragma Postcondition( Create_Ked_Sprite'Result /= null ); 
  35.  
  36.     -- Consumes the attributes association. 
  37.     procedure Set_Attributes( this       : not null access Ked_Sprite'Class; 
  38.                               attributes : Assoc_Ptr ); 
  39.     pragma Precondition( attributes /= Associations.Nul ); 
  40.  
  41. private 
  42.  
  43.     use Directions; 
  44.     use Widgets.Containers.Panels.Dialogs; 
  45.     use Widgets.Containers.Panels.Popups; 
  46.  
  47.     type Drag_Action is (Drag_None, Drag_Move, Drag_Resize); 
  48.  
  49.     type Ked_Sprite is new Sprite and Menu_Listener and Visibility_Listener with 
  50.         record 
  51.             resizeable  : Boolean := False;    -- user can resize the sprite 
  52.             dragStartX,                        -- coordinates where the mouse is 
  53.             dragStartY  : Integer := -1;       --   attached to drag 
  54.             dragAction  : Drag_Action := Drag_None; 
  55.             resizeDir   : Direction_Type; 
  56.             dragged     : Boolean := False;    -- location has changed by a drag 
  57.             snapCenter  : Boolean := False;    -- snaps the center of the object to the grid 
  58.             popupMenu   : A_Popup := null;     -- right-click popup menu (belongs to this) 
  59.             dialog      : A_Dialog := null;    -- edit attributes dialog (belongs to Window) 
  60.         end record; 
  61.  
  62.     procedure Construct( this       : access Ked_Sprite; 
  63.                          view       : not null access Game_Views.Game_View'Class; 
  64.                          eid        : Entity_Id; 
  65.                          class      : String; 
  66.                          x, y       : Float; 
  67.                          width, 
  68.                          height     : Natural; 
  69.                          resizeable : Boolean; 
  70.                          physical   : Boolean; 
  71.                          libName    : String; 
  72.                          frame      : Natural ); 
  73.     pragma Precondition( class'Length > 0 ); 
  74.     pragma Precondition( libName'Length > 0 ); 
  75.  
  76.     procedure Delete( this : in out Ked_Sprite ); 
  77.  
  78.     procedure Handle_Action( this   : access Ked_Sprite; 
  79.                              action : A_Menu_Action ); 
  80.  
  81.     procedure Handle_Action( this   : access Ked_Sprite; 
  82.                              action : A_Visibility_Action ); 
  83.  
  84.     procedure On_Focus( this : access Ked_Sprite ); 
  85.  
  86.     procedure On_Key_Typed( this    : access Ked_Sprite; 
  87.                             evt     : not null A_Key_Typed_Event; 
  88.                             handled : in out Boolean ); 
  89.  
  90.     procedure On_Mouse_Move( this : access Ked_Sprite; 
  91.                              evt  : not null A_Mouse_Event ); 
  92.  
  93.     procedure On_Mouse_Press( this : access Ked_Sprite; 
  94.                               evt  : not null A_Mouse_Button_Event ); 
  95.  
  96.     procedure On_Mouse_Release( this : access Ked_Sprite; 
  97.                                 evt  : not null A_Mouse_Button_Event ); 
  98.  
  99. end Widgets.Sprites.Ked;