-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcpanel.cpp
96 lines (71 loc) · 2.02 KB
/
cpanel.cpp
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
#include "cpanel.h"
void CPanel::init( int Id, float Width, float Height, float X, float Y, float Z, string textureFileName ) {
id = Id;
width = Width; height = Height;
x = X; y = Y; z = Z;
texture.makeTexture( textureFileName, PNG );
visible = false; enabled = false;
return;
}
void CPanel::addPanelObjek( CPanelObjek *panelObjek ) {
panelObjeks.push_back( (CPanelObjek *) panelObjek );
return;
}
void CPanel::removePanelObjek( CPanelObjek *panelObjek ) {
// doesn't work yet
return;
}
void CPanel::draw( ) {
if ( !enabled || !visible ) {
return;
}
glDisable( GL_LIGHTING );
glMatrixMode( GL_MODELVIEW );
glPushMatrix( );
glLoadIdentity( );
glTranslatef( x, y, z );
// draw the background image of the panel
texture.bindTexture( );
glBegin( GL_QUADS );
glTexCoord2f( 0.0, 1.0 ); glVertex3f( -width/2.0, -height/2.0, 0.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex3f( width/2.0, -height/2.0, 0.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex3f( width/2.0, height/2.0, 0.0 );
glTexCoord2f( 0.0, 0.0 ); glVertex3f( -width/2.0, height/2.0, 0.0 );
glEnd( );
texture.unbindTexture( );
// draw the panel objeks
for ( unsigned int i=0; i<panelObjeks.size( ); i++ ) {
panelObjeks[i]->draw( );
}
glMatrixMode( GL_MODELVIEW );
glPopMatrix( );
glEnable( GL_LIGHTING );
return;
}
void CPanel::enableChildren( ) { // !!!! Doesn't work yet
for ( unsigned int i=0; i<panelObjeks.size( ); i++ ) {
panelObjeks[i]->visible = true;
panelObjeks[i]->enabled = true;
}
return;
}
void CPanel::disableChildren( ) { // !!!! Doesn't work yet
for ( unsigned int i=0; i<panelObjeks.size( ); i++ ) {
panelObjeks[i]->visible = false;
panelObjeks[i]->enabled = false;
}
return;
}
bool CPanel::pointLiesWithin( float px, float py, float tolerance ){
if (px >= (x-width/2.0 -tolerance) && px <= (x+width/2.0+ tolerance) && \
py >= (y-height/2.0-tolerance) && py <= (y+height/2.0+tolerance)) {
return true;
}
return false;
}
void CPanel::clickHandler( float x, float y ) {
if ( onClick ) {
onClick( x, y );
}
return;
}