4
* 2007-March-17 Jason Rohrer
9
#ifndef SHADOW_IMAGE_BUTTON_GL_INCLUDED
10
#define SHADOW_IMAGE_BUTTON_GL_INCLUDED
14
#include "minorGems/graphics/Image.h"
16
#include "minorGems/graphics/openGL/SingleTextureGL.h"
22
* A textured button for GL-based GUIs that draws one image with a shadow
23
* to show pressed/unpressed status.
25
* @author Jason Rohrer
27
class ShadowImageButtonGL : public ButtonGL {
35
* Constructs a button.
37
* @param inAnchorX the x position of the upper left corner
39
* @param inAnchorY the y position of the upper left corner
41
* @param inWidth the width of this component.
42
* @param inHeight the height of this component.
43
* @param inUnpressedImage the image to display
44
* when this button is unpressed. Must have dimensions
45
* that are powers of 2.
46
* Will be destroyed when this class is destroyed.
49
double inAnchorX, double inAnchorY, double inWidth,
50
double inHeight, Image *inUnpressedImage );
54
~ShadowImageButtonGL();
57
// implements the ButtonGL interface
58
virtual void drawPressed();
59
virtual void drawUnpressed();
64
Image *mUnpressedImage;
66
SingleTextureGL *mUnpressedTexture;
70
* Draw this button with an optional z offset above it's shadow.
72
* @param inOffset true to draw the button above its shadow.
74
void drawWithOffset( char inOffset );
80
inline ShadowImageButtonGL::ShadowImageButtonGL(
81
double inAnchorX, double inAnchorY, double inWidth,
82
double inHeight, Image *inUnpressedImage )
83
: ButtonGL( inAnchorX, inAnchorY, inWidth, inHeight ),
84
mUnpressedImage( inUnpressedImage ) {
86
mUnpressedTexture = new SingleTextureGL( mUnpressedImage );
91
inline ShadowImageButtonGL::~ShadowImageButtonGL() {
92
delete mUnpressedImage;
94
delete mUnpressedTexture;
99
inline void ShadowImageButtonGL::drawPressed() {
100
drawWithOffset( false );
105
inline void ShadowImageButtonGL::drawUnpressed() {
106
drawWithOffset( true );
111
inline void ShadowImageButtonGL::drawWithOffset( char inOffset ) {
113
// calculate offset for shadow
114
double xOffset = mWidth * 0.05;
115
double yOffset = mHeight * 0.05;
118
double offset = xOffset;
119
if( yOffset < xOffset ) {
125
mUnpressedTexture->enable();
128
glColor4f( 0.0, 0.0, 0.0, 0.5 );
130
// shadow in lower left corner
131
glBegin( GL_QUADS ); {
133
glTexCoord2f( 0, 1.0f );
134
glVertex2d( mAnchorX, mAnchorY );
136
glTexCoord2f( 1.0f, 1.0f );
137
glVertex2d( mAnchorX + mWidth - offset, mAnchorY );
139
glTexCoord2f( 1.0f, 0 );
140
glVertex2d( mAnchorX + mWidth - offset, mAnchorY + mHeight - offset );
142
glTexCoord2f( 0, 0 );
143
glVertex2d( mAnchorX, mAnchorY + mHeight - offset );
148
glColor4f( 1.0, 1.0, 1.0, 10 );
150
double anchorOffset = 0;
152
// put it in upper right corner
153
anchorOffset = offset;
157
glBegin( GL_QUADS ); {
159
glTexCoord2f( 0, 1.0f );
160
glVertex2d( mAnchorX + anchorOffset,
161
mAnchorY + anchorOffset );
163
glTexCoord2f( 1.0f, 1.0f );
164
glVertex2d( mAnchorX + mWidth - offset,
165
mAnchorY + anchorOffset );
167
glTexCoord2f( 1.0f, 0 );
168
glVertex2d( mAnchorX + mWidth - offset,
169
mAnchorY + mHeight - offset );
171
glTexCoord2f( 0, 0 );
172
glVertex2d( mAnchorX + anchorOffset,
173
mAnchorY + mHeight - offset );
178
mUnpressedTexture->disable();