summaryrefslogtreecommitdiffstats
path: root/kue/interface.h
blob: 72565d3103499c8c7f1402b8cf50b70a7f9bb59f (plain)
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
#ifndef _INTERFACE_H
#define _INTERFACE_H

#include <tqdatetime.h>
#include <tqobject.h>
#include <tqcolor.h>
#include <tqgl.h>

#include "circle.h"
#include "vector.h"
#include "texture.h"

class table;
class rules;
class TQString;

// Handles user interface functionality
class GLUserInterface : public TQGLWidget  {
  TQ_OBJECT
  public:
	GLUserInterface(TQWidget *parent);
	~GLUserInterface();

	// Rules' functions
	void placeBilliard(double cue_line);
	void startShot(circle cue_location, TQColor player_color, bool forward_only = false);

	void update();

  signals:
  	// Called by the interface when the user has decided on a cue location
	void billiardPlaced(point &location);
	// Called by the interface when the user is deciding on a cue location
	void previewBilliardPlace(point &location);
	void shotTaken(vector &velocity);

  private:
  	void initializeGL();
	void resizeGL(int widget, int height);
	void paintGL();

	void mouseMoveEvent(TQMouseEvent *e);
	void mousePressEvent(TQMouseEvent *e);
	void mouseReleaseEvent(TQMouseEvent *e);

	double windowToInternalX(int x);
	double windowToInternalY(int y);

	void timerEvent( TQTimerEvent * );
	void updateView();
	double shotPower();

	void mouseClicked(double x, double y, int button, int state);

	double positionToAngle(double position);
	double positionToCuePlacement(double position);

	// Are we placing the cue ball?
	bool _placing_cue;
	double _cue_line;

	// Are we shooting?
	bool _shooting;
	// Can we shoot only in front of the start line?
	bool _forward_only;


	// Where is the cue? And how big is it?
	circle _cue_location;
	// Where is the mouse?
	point _mouse_location;

	// When did the user begin the 'shot' by pressing down the mouse button
	bool _shot_started;
	TQTime _shot_time;

	// Cue texture	
	KueTexture _cue_texture;

	// The current player's color
	TQColor _player_color;

	table *_table;
};

#endif