PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lljoystickbutton.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 180 lines | 115 code | 30 blank | 35 comment | 0 complexity | 059c41043e46c18399e4a05c251abd97 MD5 | raw file
  1/** 
  2 * @file lljoystickbutton.h
  3 * @brief LLJoystick class definition
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLJOYSTICKBUTTON_H
 28#define LL_LLJOYSTICKBUTTON_H
 29
 30#include "llbutton.h"
 31#include "llcoord.h"
 32#include "llviewertexture.h"
 33
 34typedef enum e_joystick_quadrant
 35{
 36	JQ_ORIGIN,
 37	JQ_UP,
 38	JQ_DOWN,
 39	JQ_LEFT,
 40	JQ_RIGHT
 41} EJoystickQuadrant;
 42
 43struct QuadrantNames : public LLInitParam::TypeValuesHelper<EJoystickQuadrant, QuadrantNames>
 44{
 45	static void declareValues();
 46};
 47
 48class LLJoystick
 49:	public LLButton
 50{
 51public:
 52	struct Params 
 53	:	public LLInitParam::Block<Params, LLButton::Params>
 54	{
 55		Optional<EJoystickQuadrant, QuadrantNames> quadrant;
 56
 57		Params()
 58		:	quadrant("quadrant", JQ_ORIGIN)
 59		{
 60			changeDefault(label, "");
 61		}
 62	};
 63	LLJoystick(const Params&);
 64
 65	virtual BOOL	handleMouseDown(S32 x, S32 y, MASK mask);
 66	virtual BOOL	handleMouseUp(S32 x, S32 y, MASK mask);
 67	virtual BOOL	handleHover(S32 x, S32 y, MASK mask);
 68
 69	virtual void	onMouseUp() {}
 70	virtual void	onHeldDown() = 0;
 71	F32				getElapsedHeldDownTime();
 72
 73	static void		onBtnHeldDown(void *userdata);		// called by llbutton callback handler
 74	void            setInitialQuadrant(EJoystickQuadrant initial) { mInitialQuadrant = initial; };
 75
 76	/**
 77	 * Checks if click location is inside joystick circle.
 78	 *
 79	 * Image containing circle is square and this square has adherent points with joystick
 80	 * circle. Make sure to change method according to shape other than square. 
 81	 */
 82	bool			pointInCircle(S32 x, S32 y) const;
 83	
 84	static std::string nameFromQuadrant(const EJoystickQuadrant quadrant);
 85	static EJoystickQuadrant quadrantFromName(const std::string& name);
 86	static EJoystickQuadrant selectQuadrant(LLXMLNodePtr node);
 87
 88
 89protected:
 90	virtual void	updateSlop();					// recompute slop margins
 91
 92protected:
 93	EJoystickQuadrant	mInitialQuadrant;			// mousedown = click in this quadrant
 94	LLCoordGL			mInitialOffset;				// pretend mouse started here
 95	LLCoordGL			mLastMouse;					// where was mouse on last hover event
 96	LLCoordGL			mFirstMouse;				// when mouse clicked, where was it
 97	S32					mVertSlopNear;				// where the slop regions end
 98	S32					mVertSlopFar;				// where the slop regions end
 99	S32					mHorizSlopNear;				// where the slop regions end
100	S32					mHorizSlopFar;				// where the slop regions end
101	BOOL				mHeldDown;
102	LLFrameTimer		mHeldDownTimer;
103};
104
105
106// Turn agent left and right, move forward and back
107class LLJoystickAgentTurn
108:	public LLJoystick
109{
110public:
111	struct Params : public LLJoystick::Params {};
112	LLJoystickAgentTurn(const Params& p) : LLJoystick(p) {}
113	virtual void	onHeldDown();
114};
115
116
117// Slide left and right, move forward and back
118class LLJoystickAgentSlide
119:	public LLJoystick
120{
121public:
122	struct Params : public LLJoystick::Params {};
123	LLJoystickAgentSlide(const Params& p) : LLJoystick(p) {}
124
125	virtual void	onHeldDown();
126	virtual void	onMouseUp();
127};
128
129
130// Rotate camera around the focus point
131class LLJoystickCameraRotate
132:	public LLJoystick
133{
134public:
135	struct Params 
136	:	public LLInitParam::Block<Params, LLJoystick::Params>
137	{
138		Params()
139		{
140			changeDefault(held_down_delay.seconds, 0.0);
141		}
142	};
143
144	LLJoystickCameraRotate(const LLJoystickCameraRotate::Params&);
145
146	virtual void	setToggleState( BOOL left, BOOL top, BOOL right, BOOL bottom );
147
148	virtual BOOL	handleMouseDown(S32 x, S32 y, MASK mask);
149	virtual void	onHeldDown();
150	virtual void	draw();
151
152protected:
153	F32				getOrbitRate();
154	virtual void	updateSlop();
155	void			drawRotatedImage( LLPointer<LLUIImage> image, S32 rotations );
156
157protected:
158	BOOL			mInLeft;
159	BOOL			mInTop;
160	BOOL			mInRight;
161	BOOL			mInBottom;
162};
163
164
165// Track the camera focus point forward/backward and side to side
166class LLJoystickCameraTrack
167:	public LLJoystickCameraRotate
168{
169public:
170	struct Params 
171	:	public LLInitParam::Block<Params, LLJoystickCameraRotate::Params>
172	{
173		Params();
174	};
175
176	LLJoystickCameraTrack(const LLJoystickCameraTrack::Params&);
177	virtual void	onHeldDown();
178};
179
180#endif  // LL_LLJOYSTICKBUTTON_H