File: mouse.h

package info (click to toggle)
exult 1.2-15
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 8,640 kB
  • ctags: 10,524
  • sloc: cpp: 99,373; sh: 7,324; ansic: 4,659; makefile: 985; yacc: 769; lex: 313; xml: 19
file content (160 lines) | stat: -rw-r--r-- 5,055 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 *	mouse.h - Mouse pointers.
 *
 *  Copyright (C) 2000-2002  The Exult Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _MOUSE_H_
#define _MOUSE_H_

#include "rect.h"
#include "dir.h"
#include "iwin8.h"
#include "vgafile.h"
#include "glshape.h"

/*
 *	Handle custom mouse pointers.
 */
class Mouse
{
protected:
	Shape_file pointers;		// Pointers from 'pointers.shp'.
	Game_window *gwin;		// Where to draw.
	Image_window8 *iwin;		// From gwin.
	Image_buffer *backup;		// Stores image below mouse shape.
	Rectangle box;			// Area backed up.
	Rectangle dirty;		// Dirty area from mouse move.
	int mousex, mousey;		// Last place where mouse was.
	int cur_framenum;		// Frame # of current shape.
	Shape_frame *cur;		// Current shape.
	unsigned char focus;		// 1 if we have focus.
	unsigned char onscreen;		// 1 if mouse is drawn on screen.
	static short short_arrows[8];	// Frame #'s of short arrows, indexed
					//   by direction (0-7, 0=east).
	static short med_arrows[8];	// Medium arrows.
	static short long_arrows[8];	// Frame #'s of long arrows.
	static short short_combat_arrows[8];	// Short red arrows
	static short med_combat_arrows[8];	// Medium red arrows
	void set_shape0(int framenum);	// Set shape without checking first.
	void Init();

public:
	enum Mouse_shapes		// List of shapes' frame #'s.
	{
		dontchange = 1000,	// Flag to not change.
		hand = 0,
		redx = 1,
		greenselect = 2,	// For modal select.
		tooheavy = 3,
		outofrange = 4,
		outofammo = 5,
		wontfit = 6,
		hourglass = 7,
		greensquare = 23,
		blocked = 49
	};

	/* Avatar speed, relative to standard delay:
	 * avatar_speed = standard_delay * 100 / avatar_speed_factor
	 *
	 *
	 * Experimental results, Serpent Isle
	 *
	 * "short" arrow within central 0.4 of screen in each dimension
	 * "middle" arrow within central 0.8 of screen in each dimension
	 * "long" arrow (non-combat, non-threat only) outside 
	 *
	 * relative speeds:
         * (movement type           - time for a certain dist. - rel. speed)
	 *  non-combat short arrow  -          8               -   1
	 *  non-combat medium arrow -          4               -   2
	 *  non-combat long arrow   -          2               -   4
	 *  combat short arrow      -          8               -   1
	 *  combat medium arrow     -          6               -   4/3
	 */
	enum Avatar_Speed_Factors
	{
		slow_speed_factor          = 100,
		medium_combat_speed_factor = 133,
		medium_speed_factor        = 200,
		fast_speed_factor          = 400
	};
	int avatar_speed;

	static bool mouse_update;
	static Mouse* mouse;

	Mouse(Game_window *gw);
	Mouse(Game_window *gw, DataSource& shapes);
	~Mouse();
	
	void show();			// Paint it.
	void hide()			// Restore area under mouse.
		{
		if (onscreen)
			{
			onscreen = 0;
			iwin->put(backup, box.x, box.y);	
			dirty = box;	// Init. dirty to box.
			}
		}
	void set_shape(int framenum)	// Set to desired shape.
		{
		if (framenum != cur_framenum)
			set_shape0(framenum);
		}
	void set_shape(Mouse_shapes shape)
		{ set_shape(static_cast<int>(shape)); }
	Mouse_shapes get_shape()
		{ return (Mouse_shapes) cur_framenum; }
	void move(int x, int y);	// Move to new location (mouse motion).
	void blit_dirty()		// Blit dirty area.
		{ 			// But not in OpenGL.
		if (!GL_manager::get_instance())
			iwin->show(dirty.x - 1, dirty.y - 1, dirty.w + 2, 
							dirty.h + 2); 
		}
	void set_location(int x, int y);// Set to given location.
					// Flash desired shape for 1/2 sec.
	void flash_shape(Mouse_shapes flash);
					// Set to short arrow.
	int get_short_arrow(Direction dir)
		{ return (short_arrows[static_cast<int>(dir)]); }
					// Set to medium arrow.
	int get_medium_arrow(Direction dir)
		{ return (med_arrows[static_cast<int>(dir)]); }
					// Set to long arrow.
	int get_long_arrow(Direction dir)
		{ return (long_arrows[static_cast<int>(dir)]); }
					// Set to short combat mode arrow.
	int get_short_combat_arrow(Direction dir)
		{ return (short_combat_arrows[static_cast<int>(dir)]); }
					// Set to medium combat mode arrow.
	int get_medium_combat_arrow(Direction dir)
		{ return (med_combat_arrows[static_cast<int>(dir)]); }

	unsigned char is_onscreen() { return onscreen; }

	//inline const int get_mousex() const { return mousex; }
	//inline const int get_mousey() const { return mousey; }

	// Sets hand or speed cursors
	void set_speed_cursor();
};

#endif