#include "StateObjectDisplay.h"
#include "common.h"
#include "SpriteResource.h"
#include "TilePicker.h"
#include "minorGems/graphics/openGL/gui/TextGL.h"
#include "minorGems/util/stringUtils.h"
extern TilePicker *mainTilePicker;
static clickMask blankMask;
StateObjectDisplay::StateObjectDisplay( int inAnchorX, int inAnchorY )
: GUIComponentGL( inAnchorX, inAnchorY,
G * P, G * P ),
mLastPixelClickX( 0 ), mLastPixelClickY( 0 ),
mLastGridClickX( 0 ), mLastGridClickY( 0 ),
mLastActionRelease( false ),
mLastActionPress( false ),
mMouseHover( false ),
mLastHoverX( 0 ), mLastHoverY( 0 ),
mShowSelected( true ),
mShowGrid( true ),
mUseTrans( true ),
mLastSelected( -2 ),
mBlinkCycle( 0 ) {
for( int y=0; y
getBackgroundTile() );
Sprite *tileSprite = tile.getSprite();
for( int y=0; ydraw( 0, 0, &pos, mZoomFactor );
}
}
delete tileSprite;
}
// now draw all sprites
int numSprites = mObjectSprites.size();
//printf( "Drawing %d sprites, %d selected\n", numSprites, selected );
for( int s=0; s mAnchorX + mWidth
||
pos.mY < mAnchorY || pos.mY > mAnchorY + mHeight ) {
drawIt = false;
}
if( drawIt ) {
char glow = *( mObjectSpriteGlows.getElement( s ) );
if( glow ) {
// brighten only
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
}
sprite->draw( 0, 0, &pos, mZoomFactor, fadeFactor, &c );
if( glow ) {
// back to normal blend
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
}
if( ! isAnchor &&
mShowGrid &&
mShowSelected &&
s == selected ) {
// blinking highlight on top
double blinkFadeFactor =
0.25 * cos( mBlinkCycle / 3.0 ) + 0.25;
Sprite *highlight =
*( mObjectSpriteHighlights.getElement( s ) );
highlight->draw( 0, 0, &pos,
mZoomFactor,
blinkFadeFactor, &c );
}
}
}
if( mShowGrid ) {
//grid lines
glColor4f( 1, 1, 1, 0.25f );
glBegin( GL_LINES ); {
for( int x=0; x=0; i-- ) {
intPair pos = *( mObjectSpritePositions.getElement( i ) );
int posX = pos.x - centerScreenPosX;
int posY = pos.y - centerScreenPosY;
//printf( " Layer %d at (%d,%d)\n", i, posX, posY );
// first, do bounding box
if( inPixelClickX >= posX && inPixelClickX < posX + P
&&
inPixelClickY >= posY && inPixelClickY < posY + P ) {
clickMask *mask = mObjectMasks.getElement( i );
int offsetY = P - ( inPixelClickY - posY ) - 1;
int offsetX = inPixelClickX - posX;
if( mask->opaque[ offsetY ][ offsetX ] ) {
// hit!
*outClickOffsetX = offsetX - P/2;
*outClickOffsetY = offsetY - P/2;
return i;
}
}
}
return -1;
}