mouse.h

Go to the documentation of this file.
00001 /*
00002  *  mouse.h - Mouse pointers.
00003  *
00004  *  Copyright (C) 2000-2002  The Exult Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef _MOUSE_H_
00022 #define _MOUSE_H_
00023 
00024 #include "rect.h"
00025 #include "dir.h"
00026 #include "iwin8.h"
00027 #include "vgafile.h"
00028 #include "glshape.h"
00029 
00030 class Game_window;
00031 
00032 /*
00033  *  Handle custom mouse pointers.
00034  */
00035 class Mouse
00036 {
00037 protected:
00038   Shape_file pointers;    // Pointers from 'pointers.shp'.
00039   Game_window *gwin;    // Where to draw.
00040   Image_window8 *iwin;    // From gwin.
00041   Image_buffer *backup;   // Stores image below mouse shape.
00042   Rectangle box;      // Area backed up.
00043   Rectangle dirty;    // Dirty area from mouse move.
00044   int mousex, mousey;   // Last place where mouse was.
00045   int cur_framenum;   // Frame # of current shape.
00046   Shape_frame *cur;   // Current shape.
00047   unsigned char focus;    // 1 if we have focus.
00048   unsigned char onscreen;   // 1 if mouse is drawn on screen.
00049   static short short_arrows[8]; // Frame #'s of short arrows, indexed
00050           //   by direction (0-7, 0=east).
00051   static short med_arrows[8]; // Medium arrows.
00052   static short long_arrows[8];  // Frame #'s of long arrows.
00053   static short short_combat_arrows[8];  // Short red arrows
00054   static short med_combat_arrows[8];  // Medium red arrows
00055   void set_shape0(int framenum);  // Set shape without checking first.
00056   void Init();
00057 
00058 public:
00059   enum Mouse_shapes   // List of shapes' frame #'s.
00060   {
00061     dontchange = 1000,  // Flag to not change.
00062     hand = 0,
00063     redx = 1,
00064     greenselect = 2,  // For modal select.
00065     tooheavy = 3,
00066     outofrange = 4,
00067     outofammo = 5,
00068     wontfit = 6,
00069     hourglass = 7,
00070     greensquare = 23,
00071     blocked = 49
00072   };
00073 
00074   /* Avatar speed, relative to standard delay:
00075    * avatar_speed = standard_delay * 100 / avatar_speed_factor
00076    *
00077    *
00078    * Experimental results, Serpent Isle
00079    *
00080    * "short" arrow within central 0.4 of screen in each dimension
00081    * "middle" arrow within central 0.8 of screen in each dimension
00082    * "long" arrow (non-combat, non-threat only) outside 
00083    *
00084    * relative speeds:
00085          * (movement type           - time for a certain dist. - rel. speed)
00086    *  non-combat short arrow  -          8               -   1
00087    *  non-combat medium arrow -          4               -   2
00088    *  non-combat long arrow   -          2               -   4
00089    *  combat short arrow      -          8               -   1
00090    *  combat medium arrow     -          6               -   4/3
00091    */
00092   enum Avatar_Speed_Factors
00093   {
00094     slow_speed_factor          = 100,
00095     medium_combat_speed_factor = 133,
00096     medium_speed_factor        = 200,
00097     fast_speed_factor          = 400
00098   };
00099   int avatar_speed;
00100 
00101   static bool mouse_update;
00102   static Mouse* mouse;
00103 
00104   Mouse(Game_window *gw);
00105   Mouse(Game_window *gw, DataSource& shapes);
00106   ~Mouse();
00107   
00108   void show();      // Paint it.
00109   void hide()     // Restore area under mouse.
00110     {
00111     if (onscreen)
00112       {
00113       onscreen = 0;
00114       iwin->put(backup, box.x, box.y);  
00115       dirty = box;  // Init. dirty to box.
00116       }
00117     }
00118   void set_shape(int framenum)  // Set to desired shape.
00119     {
00120     if (framenum != cur_framenum)
00121       set_shape0(framenum);
00122     }
00123   void set_shape(Mouse_shapes shape)
00124     { set_shape(static_cast<int>(shape)); }
00125   Mouse_shapes get_shape()
00126     { return (Mouse_shapes) cur_framenum; }
00127   void move(int x, int y);  // Move to new location (mouse motion).
00128   void blit_dirty()   // Blit dirty area.
00129     {       // But not in OpenGL.
00130     if (!GL_manager::get_instance())
00131       iwin->show(dirty.x - 1, dirty.y - 1, dirty.w + 2, 
00132               dirty.h + 2); 
00133     }
00134   void set_location(int x, int y);// Set to given location.
00135           // Flash desired shape for 1/2 sec.
00136   void flash_shape(Mouse_shapes flash);
00137           // Set to short arrow.
00138   int get_short_arrow(Direction dir)
00139     { return (short_arrows[static_cast<int>(dir)]); }
00140           // Set to medium arrow.
00141   int get_medium_arrow(Direction dir)
00142     { return (med_arrows[static_cast<int>(dir)]); }
00143           // Set to long arrow.
00144   int get_long_arrow(Direction dir)
00145     { return (long_arrows[static_cast<int>(dir)]); }
00146           // Set to short combat mode arrow.
00147   int get_short_combat_arrow(Direction dir)
00148     { return (short_combat_arrows[static_cast<int>(dir)]); }
00149           // Set to medium combat mode arrow.
00150   int get_medium_combat_arrow(Direction dir)
00151     { return (med_combat_arrows[static_cast<int>(dir)]); }
00152 
00153   unsigned char is_onscreen() { return onscreen; }
00154 
00155   //inline const int get_mousex() const { return mousex; }
00156   //inline const int get_mousey() const { return mousey; }
00157 
00158   // Sets hand or speed cursors
00159   void set_speed_cursor();
00160 };
00161 
00162 #endif

Generated on Mon Jul 9 14:42:48 2007 for ExultEngine by  doxygen 1.5.1