1/*
2 * Copyright 2008 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 */
6
7/*
8	Copyright 1999, Be Incorporated.   All Rights Reserved.
9	This file may be used under the terms of the Be Sample Code License.
10*/
11
12#ifndef OBJECT_VIEW_H
13#define OBJECT_VIEW_H
14
15#include <GL/glu.h>
16#include <GLView.h>
17
18#define kMsgFPS			'fps '
19#define kMsgAddModel	'addm'
20#define kMsgGouraud		'gour'
21#define kMsgZBuffer		'zbuf'
22#define kMsgCulling		'cull'
23#define kMsgTextured	'txtr'
24#define kMsgFog			'fog '
25#define kMsgLighting	'lite'
26#define kMsgLights		'lits'
27#define kMsgFilled		'fill'
28#define kMsgPerspective	'prsp'
29
30enum lights {
31	lightNone = 0,
32	lightWhite,
33	lightYellow,
34	lightRed,
35	lightBlue,
36	lightGreen
37};
38
39#define HISTSIZE 10
40
41class ResScroll;
42class GLObject;
43
44struct TrackingInfo {
45	float		lastX;
46	float		lastY;
47	float		lastDx;
48	float		lastDy;
49	bool		isTracking;
50	GLObject	*pickedObject;
51	uint32		buttons;
52};
53
54class ObjectView : public BGLView {
55	public:
56						ObjectView(BRect rect, const char* name,
57							ulong resizingMode, ulong options);
58						~ObjectView();
59
60		virtual	void	MouseDown(BPoint point);
61		virtual	void	MouseUp(BPoint point);
62		virtual	void	MouseMoved(BPoint point, uint32 transit, const BMessage *msg);
63
64		virtual	void	MessageReceived(BMessage* msg);
65		virtual	void	AttachedToWindow();
66		virtual	void	DetachedFromWindow();
67		virtual	void	FrameResized(float width, float height);
68				bool	SpinIt();
69				int		ObjectAtPoint(const BPoint &point);
70		virtual	void	DrawFrame(bool noPause);
71		virtual	void	Pulse();
72				void	EnforceState();
73				bool	RepositionView();
74
75		sem_id			drawEvent;
76		sem_id			quittingSem;
77
78	private:
79		thread_id		fDrawThread;
80		ResScroll*		fResScroll;
81		BList			fObjects;
82		BLocker			fObjListLock;
83		uint64			fLastFrame;
84		int32			fHistEntries,fOldestEntry;
85		bool			fFps, fLastGouraud, fGouraud;
86		bool			fLastZbuf, fZbuf, fLastCulling, fCulling;
87		bool			fLastLighting, fLighting, fLastFilled, fFilled;
88		bool			fLastPersp, fPersp, fLastTextured, fTextured;
89		bool			fLastFog, fFog, fForceRedraw;
90		float			fLastYXRatio, fYxRatio, fFpsHistory[HISTSIZE];
91		float			fObjectDistance, fLastObjectDistance;
92		TrackingInfo	fTrackingInfo;
93};
94
95#endif // OBJECT_VIEW_H
96