home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / input / mouse.h < prev   
Encoding:
C/C++ Source or Header  |  2008-07-01  |  6.4 KB  |  234 lines

  1. /***************************************************************************
  2.  * mouse.h  -  header for the corresponding cpp file
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #ifndef SMC_MOUSE_H
  17. #define SMC_MOUSE_H
  18.  
  19. #include "../core/globals.h"
  20. #include "../objects/movingsprite.h"
  21. #include "../core/math/rect.h"
  22. #include "../core/math/vector.h"
  23.  
  24. /* *** *** *** *** *** *** cSelectedObject *** *** *** *** *** *** *** *** *** *** *** */
  25.  
  26. class cSelectedObject
  27. {
  28. public:
  29.     cSelectedObject( void );
  30.     ~cSelectedObject( void );
  31.     
  32.     // base object
  33.     cSprite *obj;
  34.     // additional selection mouse position
  35.     int mouse_w, mouse_h;
  36.  
  37.     // if user controlled
  38.     bool user;
  39. };
  40.  
  41. typedef vector<cSelectedObject *> SelectedObjectList;
  42.  
  43. /* *** *** *** *** *** *** cCopyObject *** *** *** *** *** *** *** *** *** *** *** */
  44.  
  45. class cCopyObject
  46. {
  47. public:
  48.     cCopyObject( void );
  49.     ~cCopyObject( void );
  50.     
  51.     // base object
  52.     cSprite *obj;
  53. };
  54.  
  55. typedef vector<cCopyObject *> CopyObjectList;
  56.  
  57. /* *** *** *** *** *** *** cMouseCursor *** *** *** *** *** *** *** *** *** *** *** */
  58.  
  59. class cMouseCursor : public cMovingSprite
  60. {
  61. public:
  62.     cMouseCursor( void );
  63.     virtual ~cMouseCursor( void );
  64.  
  65.     // resets leveleditor features
  66.     void Reset( bool clear_copy_buffer = 1 );
  67.     // only reset buttons
  68.     void Reset_Keys( void );
  69.  
  70.     // Handles the Mouse events
  71.     bool Handle_Event( SDL_Event *ev );
  72.     /* Function: Gui_handle_Mouse_down
  73.      * GUI handle mouse down function
  74.      * Returns true if GUI handled the event
  75.     */
  76.     bool Handle_Mouse_Down( Uint8 button );
  77.     /* Function: Gui_handle_Mouse_up
  78.      * GUI handle mouse up function
  79.      * Returns true if GUI handled the event
  80.     */
  81.     bool Handle_Mouse_Up( Uint8 button );
  82.  
  83.     // Checks if the Mousecursor is in the given rect
  84.     bool Collsion_Check ( GL_rect *crect );
  85.  
  86.     // Checks for a collision for the editor
  87.     bool Editor_Collsion_Check( float px = 0, float py = 0 );
  88.     /* Get the Level/World Object Collision if available
  89.      * returns 1 if collision found else 0
  90.     */
  91.     bool Get_Collision( GL_rect *mouse_rect );
  92.  
  93.     // Update
  94.     virtual void Update( void );
  95.     // Draw
  96.     virtual void Draw( void );
  97.     // Render
  98.     void Render( void );
  99.  
  100.     // Update the Mouse Position
  101.     void Update_Position( void );
  102.     // Update the Double Click event
  103.     void Update_Doubleclick( void );
  104.  
  105.  
  106.     // Editor default click
  107.     void Click( void );
  108.     // Editor default float click
  109.     void Double_Click( bool activate = 1 );
  110.  
  111.     // ## Mouse Object
  112.     // Set new mouse object
  113.     void Set_Mouse_Object( cSprite *sprite );
  114.     // update the mouse object position
  115.     void Update_Mouse_Object( void );
  116.     // clear mouse object
  117.     void Clear_Mouse_Object( void );
  118.  
  119.     // ## Copy Objects
  120.     // Add new copy object
  121.     void Add_Copy_Object( cSprite *sprite );
  122.     void Add_Copy_Objects( SpriteList spritelist );
  123.     /* Remove a copy_object
  124.      * returns true if removed
  125.     */
  126.     bool Remove_Copy_Object( cSprite *sprite );
  127.     // clear copy object list
  128.     void Clear_Copy_Objects( void );
  129.     /* returns the position of the first top left copy object
  130.      * if no copy_objects returns 0, 0
  131.     */
  132.     GL_Vector Get_Copy_Object_Base( float px, float py );
  133.     // paste copy object list
  134.     void Paste_Copy_Objects( float px, float py );
  135.  
  136.     // ## Selected Objects
  137.     /* Add new selected_object
  138.      * Returns true if object got added or changed to user object
  139.     */
  140.     bool Add_Selected_Object( cSprite *sprite, bool from_user = 0 );
  141.     void Add_Selected_Objects( SpriteList spritelist, bool from_user = 0 );
  142.     /* Remove a selected_object
  143.      * returns true if found and removed
  144.     */
  145.     bool Remove_Selected_Object( cSprite *sprite, bool no_user = 0 );
  146.     // Returns all selected objects
  147.     SpriteList Get_Selected_Objects( void );
  148.     // clear selected object list
  149.     void Clear_Selected_Objects( void );
  150.     // updates the selected objects positions
  151.     void Update_Selected_Objects( void );
  152.     /* returns true if the given object is a selected_object
  153.      * if only_user is given only check user objects
  154.     */
  155.     bool Is_Selected_Object( cSprite *sprite, bool only_user = 0 );
  156.     // deletes the selected objects
  157.     void Delete_Selected_Objects( void );
  158.     // returns the selected objects size
  159.     unsigned int Get_Selected_Object_Size( void );
  160.  
  161.     // ## Active Object
  162.     // Set new active object
  163.     void Set_Active_Object( cSprite *sprite );
  164.     // clear active object
  165.     void Clear_Active_Object( void );
  166.  
  167.     /* Copies the given object to the given position
  168.      * object is automatically added to the object manager
  169.      * returns the new object
  170.     */
  171.     cSprite *Copy( cSprite *ncopy_object, float px, float py );
  172.     // Deletes the given Object
  173.     void Delete( cSprite *sprite );
  174.  
  175.     // Draws a rect around the mouse_object and selected objects
  176.     void Draw_Object_Rects( void );
  177.  
  178.     // Start selection mode
  179.     void Start_Selection( void );
  180.     // End selection mode
  181.     void End_Selection( void );
  182.     // update selection mode
  183.     void Update_Selection( void );
  184.  
  185.     // Toggle Mover mode
  186.     void Toggle_Mover_Mode( void );
  187.     // Updates the Mover Mode
  188.     void Mover_Update( Sint16 move_x, Sint16 move_y );
  189.     // Updates the Leveleditor Mouse
  190.     void Editor_Update( void );
  191.     
  192.     // current internal mouse position
  193.     int x, y;
  194.     
  195.     // selection mode
  196.     bool mode_selection;
  197.     // Selection rect
  198.     GL_rect selection_rect;
  199.  
  200.     // if activated the mouse cursor movement moves the screen    
  201.     bool mover_mode;
  202.     // fastcopy mode
  203.     bool mode_fastcopy;
  204.  
  205.     /* selected objects
  206.      * the mouse object is also always a selected object
  207.     */
  208.     SelectedObjectList selected_objects;
  209.     // currently colliding object with the mouse
  210.     cSelectedObject *mouse_object;
  211.     // objects selected for copying
  212.     CopyObjectList copy_objects;
  213.     // settings activated object
  214.     cSprite *active_object;
  215.  
  216.     // pressed Buttons
  217.     bool left, right, middle;
  218.  
  219.     // last clicked object
  220.     cSprite *click_temp;
  221.  
  222.     // counter for catching float-clicks
  223.     float clickcounter;
  224. };
  225.  
  226. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  227.  
  228. // The Mouse
  229. extern cMouseCursor *pMouseCursor;
  230.  
  231. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  232.  
  233. #endif
  234.