Minor clean up.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2019-12-13 01:31:02 -03:00
parent c7f9ed0383
commit 9c9d3edddf
9 changed files with 341 additions and 257 deletions

View File

@@ -31,39 +31,39 @@ class EE_API Console : protected LogReaderInterface {
void setConsoleMinimizedHeight( const Float& MinHeight );
/** Get the Console Height when it's Minimized ( Not Maximized ) */
Float getConsoleMinimizedHeight() const { return mHeightMin; }
const Float& getConsoleMinimizedHeight() const;
/** Set the Texture Id for the Background, 0 will disable texture background */
void setBackgroundTextureId( const Uint32& TexId ) { mTexId = TexId; }
void setBackgroundTextureId( const Uint32& TexId );
/** Get the Background Texture Id */
Uint32 getBackgroundTextureId() const { return mTexId; }
Uint32 getBackgroundTextureId() const;
/** Set the Console Background Color */
void setBackgroundColor( const Color& BackColor ) { mConColor = BackColor; mMaxAlpha = mConColor.a; }
void setBackgroundColor( const Color& BackColor );
void setCharacterSize( const Uint32& characterSize );
/** Get the Console Background Color */
const Color& getBackgroundColor() const { return mConColor; }
const Color& getBackgroundColor() const;
/** Set the Console Border Line Background Color */
void setBackgroundLineColor( const Color& BackColor ) { mConLineColor = BackColor; }
void setBackgroundLineColor( const Color& BackColor );
/** Get the Console Border Line Background Color */
const Color& getBackgroundLineColor() const { return mConLineColor; }
const Color& getBackgroundLineColor() const;
/** Set the Console Font Color */
void setFontColor( const Color& FntColor ) { mFontStyleConfig.FontColor = FntColor; }
void setFontColor( const Color& FntColor );
/** Get the Console Font Color */
const Color& getFontColor() const { return mFontStyleConfig.FontColor; }
const Color& getFontColor() const;
/** Set the Console Client Input ( Writeable Line ) Font Color */
void setFontLineColor( const Color& FntColor ) { mFontLineColor = FntColor; }
void setFontLineColor( const Color& FntColor );
/** Get the Console Client Input ( Writeable Line ) Font Color */
const Color& getFontLineColor() const { return mFontLineColor; }
const Color& getFontLineColor() const;
/** Toogle the console between visible and hided with Fade In or Fade Out effect. */
void toggle();
@@ -75,19 +75,19 @@ class EE_API Console : protected LogReaderInterface {
void fadeOut();
/** @return If Console Active ( Visible ) */
bool isActive() const { return mVisible; }
bool isActive() const;
/** Maximize or Minimize the Console */
void setExpanded(const bool& Exp) { mExpand = Exp; }
void setExpanded(const bool& Exp);
/** @return If console is maximized */
bool isExpanded() const { return mExpand; }
bool isExpanded() const;
/** Set the fade time */
void setFadeSpeed( const Time& fadespeed ) { mFadeSpeed = fadespeed; }
void setFadeSpeed( const Time& fadespeed );
/** @return The fading speed in ms */
const Time& getFadeSpeed() const { return mFadeSpeed; }
const Time& getFadeSpeed() const;
/** @brief Creates the new console
* @param Font The Font pointer to class
@@ -114,7 +114,7 @@ class EE_API Console : protected LogReaderInterface {
void draw();
/** Set the line height ( distance between lines ) */
void setLineHeight( const Float& LineHeight ) { mFontSize = LineHeight; }
void setLineHeight( const Float& LineHeight );
/** Use this if you need to ignore some char to activate the console, for example '~'. A common char to activate a console. */
void ignoreCharOnPrompt( const Uint32& ch );
@@ -129,7 +129,7 @@ class EE_API Console : protected LogReaderInterface {
void setFontStyleConfig(const FontStyleConfig & fontStyleConfig);
const bool& isFading() const { return mFading; }
const bool& isFading() const;
protected:
std::map < String, ConsoleCallback > mCallbacks;
std::deque < String > mCmdLog;

View File

@@ -54,6 +54,7 @@ class EE_API Event {
OnDragStop,
OnPaddingChange,
OnBufferChange,
OnUpdateScreenPosition,
UserEvent,
NoEvent = eeINDEX_NOT_FOUND
};

View File

@@ -152,23 +152,23 @@ class EE_API Node : public Transformable {
/** Use it at your own risk */
void setNodeFlags( const Uint32& flags );
Uint32 isSceneNode() const;
bool isSceneNode() const;
Uint32 isUISceneNode() const;
bool isUISceneNode() const;
Uint32 isUINode() const;
bool isUINode() const;
Uint32 isWidget() const;
bool isWidget() const;
Uint32 isWindow() const;
bool isWindow() const;
Uint32 isClipped() const;
bool isClipped() const;
Uint32 isRotated() const;
bool isRotated() const;
Uint32 isScaled() const;
bool isScaled() const;
Uint32 isFrameBuffer() const;
bool isFrameBuffer() const;
bool isMouseOver() const;
@@ -393,7 +393,7 @@ class EE_API Node : public Transformable {
virtual Uint32 onCalculateDrag( const Vector2f& position, const Uint32& flags );
virtual void onClose();
void onClose();
virtual void onVisibilityChange();
@@ -407,9 +407,9 @@ class EE_API Node : public Transformable {
virtual void onParentChange();
virtual void updateWorldPolygon();
void updateWorldPolygon();
virtual void updateCenter();
void updateCenter();
virtual void matrixSet();
@@ -429,7 +429,7 @@ class EE_API Node : public Transformable {
virtual void onSceneChange();
virtual void clipStart();
void clipStart();
virtual Uint32 onFocus();
@@ -437,9 +437,9 @@ class EE_API Node : public Transformable {
virtual void internalDraw();
virtual void clipEnd();
void clipEnd();
virtual void updateScreenPos();
void updateScreenPos();
virtual void setInternalSize(const Sizef& size );

View File

@@ -1,89 +1,89 @@
#include <eepp/graphics/console.hpp>
#include <eepp/window/engine.hpp>
#include <eepp/graphics/renderer/renderer.hpp>
#include <eepp/graphics/pixeldensity.hpp>
#include <eepp/audio/listener.hpp>
#include <eepp/window/input.hpp>
#include <eepp/window/cursormanager.hpp>
#include <eepp/window/window.hpp>
#include <eepp/system/filesystem.hpp>
#include <algorithm>
#include <cstdarg>
#include <eepp/audio/listener.hpp>
#include <eepp/graphics/console.hpp>
#include <eepp/graphics/pixeldensity.hpp>
#include <eepp/graphics/renderer/renderer.hpp>
#include <eepp/system/filesystem.hpp>
#include <eepp/window/cursormanager.hpp>
#include <eepp/window/engine.hpp>
#include <eepp/window/input.hpp>
#include <eepp/window/window.hpp>
using namespace EE::Window;
namespace EE { namespace Graphics {
Console::Console( EE::Window::Window * window ) :
Console::Console( EE::Window::Window* window ) :
mWindow( window ),
mConColor(35, 47, 73, 230),
mConLineColor(55, 67, 93, 230),
mFontLineColor(255, 255, 255, 230),
mWidth(0),
mHeight(0),
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS
mHeightMin(0.5f),
#else
mHeightMin(0.6f),
#endif
mY(0.0f),
mA(0.0f),
mConColor( 0x201F1FEE ),
mConLineColor( 0x666666EE ),
mFontLineColor( 255, 255, 255, 230 ),
mWidth( 0 ),
mHeight( 0 ),
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS
mHeightMin( 0.5f ),
#else
mHeightMin( 0.6f ),
#endif
mY( 0.0f ),
mA( 0.0f ),
mFadeSpeed( Milliseconds( 250.f ) ),
mMyCallback(0),
mVidCb(0),
mMaxLogLines(1024),
mLastLogPos(0),
mMyCallback( 0 ),
mVidCb( 0 ),
mMaxLogLines( 1024 ),
mLastLogPos( 0 ),
mTBuf( InputTextBuffer::New() ),
mTexId(0),
mCurAlpha(0),
mEnabled(false),
mVisible(false),
mFadeIn(false),
mFadeOut(false),
mExpand(false),
mFading(false),
mShowFps(false),
mCurSide(false)
{
mFontStyleConfig.FontColor = Color(153, 153, 179, 230);
mTexId( 0 ),
mCurAlpha( 0 ),
mEnabled( false ),
mVisible( false ),
mFadeIn( false ),
mFadeOut( false ),
mExpand( false ),
mFading( false ),
mShowFps( false ),
mCurSide( false ) {
mFontStyleConfig.FontColor = Color( 0xCFCFCFFF );
if ( NULL == mWindow ) {
mWindow = Engine::instance()->getCurrentWindow();
}
}
Console::Console( Font * font, const bool& MakeDefaultCommands, const bool& AttachToLog, const unsigned int& MaxLogLines, const Uint32& TextureId, EE::Window::Window * window ) :
Console::Console( Font* font, const bool& MakeDefaultCommands, const bool& AttachToLog,
const unsigned int& MaxLogLines, const Uint32& TextureId,
EE::Window::Window* window ) :
mWindow( window ),
mConColor(35, 47, 73, 230),
mConLineColor(55, 67, 93, 230),
mFontLineColor(255, 255, 255, 230),
mWidth(0),
mHeight(0),
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS
mHeightMin(0.5f),
#else
mHeightMin(0.6f),
#endif
mY(0.0f),
mA(0.0f),
mFadeSpeed( Milliseconds( 250.f) ),
mMyCallback(0),
mVidCb(0),
mMaxLogLines(1024),
mLastLogPos(0),
mConColor( 0x201F1FEE ),
mConLineColor( 0x666666EE ),
mFontLineColor( 255, 255, 255, 230 ),
mWidth( 0 ),
mHeight( 0 ),
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS
mHeightMin( 0.5f ),
#else
mHeightMin( 0.6f ),
#endif
mY( 0.0f ),
mA( 0.0f ),
mFadeSpeed( Milliseconds( 250.f ) ),
mMyCallback( 0 ),
mVidCb( 0 ),
mMaxLogLines( 1024 ),
mLastLogPos( 0 ),
mTBuf( InputTextBuffer::New() ),
mTexId(0),
mCurAlpha(0),
mEnabled(false),
mVisible(false),
mFadeIn(false),
mFadeOut(false),
mExpand(false),
mFading(false),
mShowFps(false),
mCurSide(false)
{
mFontStyleConfig.FontColor = Color(153, 153, 179, 230);
mTexId( 0 ),
mCurAlpha( 0 ),
mEnabled( false ),
mVisible( false ),
mFadeIn( false ),
mFadeOut( false ),
mExpand( false ),
mFading( false ),
mShowFps( false ),
mCurSide( false ) {
mFontStyleConfig.FontColor = Color( 0xCFCFCFFF );
if ( NULL == mWindow ) {
mWindow = Engine::instance()->getCurrentWindow();
@@ -93,11 +93,8 @@ Console::Console( Font * font, const bool& MakeDefaultCommands, const bool& Atta
}
Console::~Console() {
if ( mMyCallback &&
NULL != Engine::existsSingleton() &&
Engine::instance()->existsWindow( mWindow )
)
{
if ( mMyCallback && NULL != Engine::existsSingleton() &&
Engine::instance()->existsWindow( mWindow ) ) {
mWindow->getInput()->popCallback( mMyCallback );
mWindow->popResizeCallback( mVidCb );
}
@@ -109,25 +106,73 @@ Console::~Console() {
}
}
void Console::setConsoleMinimizedHeight(const EE::Float & MinHeight) {
mHeightMin = eemax( 0.f, eemin( MinHeight, 1.f ) );
void Console::setConsoleMinimizedHeight( const EE::Float& MinHeight ) {
mHeightMin = eemax( 0.f, eemin( MinHeight, 1.f ) );
if (mVisible && !mExpand)
mCurHeight = eefloor( mHeightMin * mWindow->getHeight() );
if ( mVisible && !mExpand )
mCurHeight = eefloor( mHeightMin * mWindow->getHeight() );
}
void Console::setCharacterSize(const EE::Uint32 & characterSize) {
const Float& Console::getConsoleMinimizedHeight() const {
return mHeightMin;
}
void Console::setBackgroundTextureId( const Uint32& TexId ) {
mTexId = TexId;
}
Uint32 Console::getBackgroundTextureId() const {
return mTexId;
}
void Console::setBackgroundColor( const Color& BackColor ) {
mConColor = BackColor;
mMaxAlpha = mConColor.a;
}
void Console::setCharacterSize( const EE::Uint32& characterSize ) {
mFontStyleConfig.CharacterSize = characterSize;
mFontSize = (Float)( mFontStyleConfig.Font->getFontHeight( PixelDensity::dpToPxI( mFontStyleConfig.CharacterSize ) ) );
mFontSize = ( Float )( mFontStyleConfig.Font->getFontHeight(
PixelDensity::dpToPxI( mFontStyleConfig.CharacterSize ) ) );
}
void Console::create( Font * Font, const bool& MakeDefaultCommands, const bool& AttachToLog, const unsigned int& MaxLogLines, const Uint32& TextureId ) {
const Color& Console::getBackgroundColor() const {
return mConColor;
}
void Console::setBackgroundLineColor( const Color& BackColor ) {
mConLineColor = BackColor;
}
const Color& Console::getBackgroundLineColor() const {
return mConLineColor;
}
void Console::setFontColor( const Color& FntColor ) {
mFontStyleConfig.FontColor = FntColor;
}
const Color& Console::getFontColor() const {
return mFontStyleConfig.FontColor;
}
void Console::setFontLineColor( const Color& FntColor ) {
mFontLineColor = FntColor;
}
const Color& Console::getFontLineColor() const {
return mFontLineColor;
}
void Console::create( Font* Font, const bool& MakeDefaultCommands, const bool& AttachToLog,
const unsigned int& MaxLogLines, const Uint32& TextureId ) {
if ( NULL == mWindow ) {
mWindow = Engine::instance()->getCurrentWindow();
}
mFontStyleConfig.Font = Font;
mFontSize = (Float)( mFontStyleConfig.Font->getFontHeight( PixelDensity::dpToPxI( mFontStyleConfig.CharacterSize ) ) );
mFontSize = ( Float )( mFontStyleConfig.Font->getFontHeight(
PixelDensity::dpToPxI( mFontStyleConfig.CharacterSize ) ) );
if ( TextureId > 0 )
mTexId = TextureId;
@@ -140,16 +185,15 @@ void Console::create( Font * Font, const bool& MakeDefaultCommands, const bool&
if ( MakeDefaultCommands )
createDefaultCommands();
mWidth = (Float) mWindow->getWidth();
mHeight = (Float) mWindow->getHeight();
mWidth = (Float)mWindow->getWidth();
mHeight = (Float)mWindow->getHeight();
mTextCache.resize( maxLinesOnScreen() );
if ( NULL != Engine::existsSingleton() &&
Engine::instance()->existsWindow( mWindow ) )
{
mMyCallback = mWindow->getInput()->pushCallback( cb::Make1( this, &Console::privInputCallback ) );
mVidCb = mWindow->pushResizeCallback( cb::Make1( this, &Console::privVideoResize ) );
if ( NULL != Engine::existsSingleton() && Engine::instance()->existsWindow( mWindow ) ) {
mMyCallback =
mWindow->getInput()->pushCallback( cb::Make1( this, &Console::privInputCallback ) );
mVidCb = mWindow->pushResizeCallback( cb::Make1( this, &Console::privVideoResize ) );
}
mTBuf->setReturnCallback( cb::Make0( this, &Console::processLine ) );
@@ -168,7 +212,7 @@ void Console::create( Font * Font, const bool& MakeDefaultCommands, const bool&
}
void Console::addCommand( const String& Command, ConsoleCallback CB ) {
if ( !(mCallbacks.count( Command ) > 0) )
if ( !( mCallbacks.count( Command ) > 0 ) )
mCallbacks[Command] = CB;
}
@@ -178,23 +222,26 @@ void Console::draw() {
if ( mY > 0.0f ) {
if ( mTexId == 0 ) {
mPri.setColor( Color( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>(mA) ) );
mPri.setColor(
Color( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>( mA ) ) );
mPri.drawRectangle( Rectf( Vector2f( 0.0f, 0.0f ), Sizef( mWidth, mY ) ) );
} else {
Color C( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>(mA) );
Color C( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>( mA ) );
Texture * Tex = TextureFactory::instance()->getTexture( mTexId );
Texture* Tex = TextureFactory::instance()->getTexture( mTexId );
if ( NULL != Tex )
Tex->drawEx( 0.0f, 0.0f, mWidth, mY, 0.0f, Vector2f::One, C, C, C, C );
}
mPri.setColor( Color( mConLineColor.r, mConLineColor.g, mConLineColor.b, static_cast<Uint8>(mA) ) );
mPri.drawRectangle( Rectf( Vector2f( 0.0f, mY ), Sizef( mWidth, PixelDensity::dpToPx( 2.0f ) ) ) );
mPri.setColor( Color( mConLineColor.r, mConLineColor.g, mConLineColor.b,
static_cast<Uint8>( mA ) ) );
mPri.drawRectangle(
Rectf( Vector2f( 0.0f, mY ), Sizef( mWidth, PixelDensity::dpToPx( 2.0f ) ) ) );
Int32 linesInScreen = this->linesOnScreen();
if ( static_cast<Int32>( mCmdLog.size() ) > linesInScreen )
mEx = (Uint32) ( mCmdLog.size() - linesInScreen );
mEx = ( Uint32 )( mCmdLog.size() - linesInScreen );
else
mEx = 0;
mTempY = -mCurHeight;
@@ -205,7 +252,7 @@ void Console::draw() {
mCon.ConMin = mEx;
mCon.ConMax = (int)mCmdLog.size() - 1;
for (int i = mCon.ConMax - mCon.ConModif; i >= mCon.ConMin - mCon.ConModif; i-- ) {
for ( int i = mCon.ConMax - mCon.ConModif; i >= mCon.ConMin - mCon.ConModif; i-- ) {
if ( i < static_cast<Int16>( mCmdLog.size() ) && i >= 0 ) {
CurY = mTempY + mY + mCurHeight - Pos * mFontSize - mFontSize * 2;
@@ -216,7 +263,9 @@ void Console::draw() {
text.setStyle( mFontStyleConfig.Style );
text.setOutlineThickness( mFontStyleConfig.OutlineThickness );
text.setOutlineColor( mFontStyleConfig.OutlineColor );
text.setFillColor( Color( mFontStyleConfig.FontColor.r, mFontStyleConfig.FontColor.g, mFontStyleConfig.FontColor.b, static_cast<Uint8>(mA) ) );
text.setFillColor(
Color( mFontStyleConfig.FontColor.r, mFontStyleConfig.FontColor.g,
mFontStyleConfig.FontColor.b, static_cast<Uint8>( mA ) ) );
text.setString( mCmdLog[i] );
text.draw( mFontSize, CurY );
@@ -226,30 +275,33 @@ void Console::draw() {
CurY = mTempY + mY + mCurHeight - mFontSize - 1;
Text& text = mTextCache[ mTextCache.size() - 1 ];
Text& text = mTextCache[mTextCache.size() - 1];
text.setFont( mFontStyleConfig.Font );
text.setCharacterSize( mFontStyleConfig.CharacterSize );
text.setStyle( mFontStyleConfig.Style );
text.setOutlineThickness( mFontStyleConfig.OutlineThickness );
text.setOutlineColor( mFontStyleConfig.OutlineColor );
text.setFillColor( Color( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b, static_cast<Uint8>(mA) ) );
text.setFillColor( Color( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b,
static_cast<Uint8>( mA ) ) );
text.setString( "> " + mTBuf->getBuffer() );
text.draw( mFontSize, CurY );
Text& text2 = mTextCache[ mTextCache.size() - 2 ];
Text& text2 = mTextCache[mTextCache.size() - 2];
text2.setFont( mFontStyleConfig.Font );
text2.setCharacterSize( mFontStyleConfig.CharacterSize );
text2.setStyle( mFontStyleConfig.Style );
text2.setOutlineThickness( mFontStyleConfig.OutlineThickness );
text2.setOutlineColor( mFontStyleConfig.OutlineColor );
text2.setFillColor( Color( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b, static_cast<Uint8>(mCurAlpha) ) );
text2.setFillColor( Color( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b,
static_cast<Uint8>( mCurAlpha ) ) );
if ( (unsigned int)mTBuf->getCursorPosition() == mTBuf->getBuffer().size() ) {
Uint32 width = text.getTextWidth();
text2.setString( "_" );
text2.draw( mFontSize + width, CurY );
} else {
text2.setString( "> " + mTBuf->getBuffer().substr( 0, mTBuf->getCursorPosition() ) );
text2.setString( "> " +
mTBuf->getBuffer().substr( 0, mTBuf->getCursorPosition() ) );
Uint32 width = mFontSize + text2.getTextWidth();
text2.setString( "_" );
text2.draw( width, CurY );
@@ -258,7 +310,7 @@ void Console::draw() {
}
if ( mShowFps && NULL != mFontStyleConfig.Font ) {
Text& text = mTextCache[ mTextCache.size() - 3 ];
Text& text = mTextCache[mTextCache.size() - 3];
Color OldColor1( text.getColor() );
text.setStyleConfig( mFontStyleConfig );
text.setFillColor( Color::White );
@@ -268,8 +320,12 @@ void Console::draw() {
}
}
void Console::setLineHeight( const Float& LineHeight ) {
mFontSize = LineHeight;
}
void Console::fadeIn() {
if (!mFading) {
if ( !mFading ) {
mFading = true;
mFadeIn = true;
mVisible = true;
@@ -279,7 +335,7 @@ void Console::fadeIn() {
}
void Console::fadeOut() {
if (!mFading) {
if ( !mFading ) {
mFading = true;
mFadeOut = true;
mVisible = false;
@@ -287,9 +343,29 @@ void Console::fadeOut() {
}
}
static std::vector< String > SplitCommandParams( String str ) {
std::vector < String > params = String::split( str, ' ' );
std::vector < String > rparams;
bool Console::isActive() const {
return mVisible;
}
void Console::setExpanded( const bool& Exp ) {
mExpand = Exp;
}
bool Console::isExpanded() const {
return mExpand;
}
void Console::setFadeSpeed( const Time& fadespeed ) {
mFadeSpeed = fadespeed;
}
const Time& Console::getFadeSpeed() const {
return mFadeSpeed;
}
static std::vector<String> SplitCommandParams( String str ) {
std::vector<String> params = String::split( str, ' ' );
std::vector<String> rparams;
String tstr;
for ( size_t i = 0; i < params.size(); i++ ) {
@@ -298,7 +374,7 @@ static std::vector< String > SplitCommandParams( String str ) {
if ( !tparam.empty() ) {
if ( '"' == tparam[0] ) {
tstr += tparam;
} else if ( '"' == tparam[ tparam.size() - 1 ] ) {
} else if ( '"' == tparam[tparam.size() - 1] ) {
tstr += " " + tparam;
rparams.push_back( String::trim( tstr, '"' ) );
@@ -321,7 +397,7 @@ static std::vector< String > SplitCommandParams( String str ) {
void Console::processLine() {
String str = mTBuf->getBuffer();
std::vector < String > params = SplitCommandParams( str );
std::vector<String> params = SplitCommandParams( str );
mLastCommands.push_back( str );
mLastLogPos = (int)mLastCommands.size();
@@ -333,7 +409,7 @@ void Console::processLine() {
privPushText( "> " + str );
if ( mCallbacks.find( params[0] ) != mCallbacks.end() ) {
mCallbacks[ params[0] ]( params );
mCallbacks[params[0]]( params );
} else {
privPushText( "Unknown Command: '" + params[0] + "'" );
}
@@ -360,13 +436,13 @@ void Console::pushText( const String& str ) {
}
}
void Console::pushText( const char * format, ... ) {
void Console::pushText( const char* format, ... ) {
int n, size = 256;
std::string tstr( size, '\0' );
va_list args;
while (1) {
while ( 1 ) {
va_start( args, format );
n = vsnprintf( &tstr[0], size, format, args );
@@ -381,10 +457,10 @@ void Console::pushText( const char * format, ... ) {
return;
}
if ( n > -1 ) // glibc 2.1
size = n+1; // precisely what is needed
else // glibc 2.0
size *= 2; // twice the old size
if ( n > -1 ) // glibc 2.1
size = n + 1; // precisely what is needed
else // glibc 2.0
size *= 2; // twice the old size
tstr.resize( size );
}
@@ -398,7 +474,7 @@ void Console::toggle() {
}
void Console::fade() {
if (mCurSide) {
if ( mCurSide ) {
mCurAlpha -= 255.f * mWindow->getElapsed().asMilliseconds() / mFadeSpeed.asMilliseconds();
if ( mCurAlpha <= 0.0f ) {
mCurAlpha = 0.0f;
@@ -421,7 +497,7 @@ void Console::fade() {
mFadeOut = false;
mY += mCurHeight * mWindow->getElapsed().asMilliseconds() / mFadeSpeed.asMilliseconds();
mA = ( mY * mMaxAlpha / mCurHeight ) ;
mA = ( mY * mMaxAlpha / mCurHeight );
if ( mY > mCurHeight ) {
mY = mCurHeight;
mFadeIn = false;
@@ -433,7 +509,7 @@ void Console::fade() {
mFadeIn = false;
mY -= mCurHeight * mWindow->getElapsed().asMilliseconds() / mFadeSpeed.asMilliseconds();
mA = ( mY * mMaxAlpha / mCurHeight ) ;
mA = ( mY * mMaxAlpha / mCurHeight );
if ( mY <= 0.0f ) {
mY = 0.0f;
mFadeOut = false;
@@ -441,8 +517,10 @@ void Console::fade() {
}
}
if ( mA > 255.0f ) mA = 255.0f;
if ( mA < 0.0f ) mA = 0.0f;
if ( mA > 255.0f )
mA = 255.0f;
if ( mA < 0.0f )
mA = 0.0f;
}
String Console::getLastCommonSubStr( std::list<String>& cmds ) {
@@ -458,15 +536,16 @@ String Console::getLastCommonSubStr( std::list<String>& cmds ) {
bool allEqual = true;
String strBeg( (*cmds.begin()) );
String strBeg( ( *cmds.begin() ) );
if ( strTry.size() + 1 <= strBeg.size() ) {
strTry = String( strBeg.substr( 0, strTry.size() + 1 ) );
for ( ite = ++cmds.begin(); ite != cmds.end(); ++ite ) {
String& strCur = (*ite);
String& strCur = ( *ite );
if ( !( strTry.size() <= strCur.size() && strTry == strCur.substr( 0, strTry.size() ) ) ) {
if ( !( strTry.size() <= strCur.size() &&
strTry == strCur.substr( 0, strTry.size() ) ) ) {
allEqual = false;
}
}
@@ -484,7 +563,7 @@ String Console::getLastCommonSubStr( std::list<String>& cmds ) {
void Console::printCommandsStartingWith( const String& start ) {
std::list<String> cmds;
std::map < String, ConsoleCallback >::iterator it;
std::map<String, ConsoleCallback>::iterator it;
for ( it = mCallbacks.begin(); it != mCallbacks.end(); ++it ) {
if ( String::startsWith( it->first, start ) ) {
@@ -498,7 +577,7 @@ void Console::printCommandsStartingWith( const String& start ) {
std::list<String>::iterator ite;
for ( ite = cmds.begin(); ite != cmds.end(); ++ite )
privPushText( (*ite) );
privPushText( ( *ite ) );
String newStr( getLastCommonSubStr( cmds ) );
@@ -512,9 +591,9 @@ void Console::printCommandsStartingWith( const String& start ) {
}
}
void Console::privVideoResize( EE::Window::Window * win ) {
mWidth = (Float) mWindow->getWidth();
mHeight = (Float) mWindow->getHeight();
void Console::privVideoResize( EE::Window::Window* win ) {
mWidth = (Float)mWindow->getWidth();
mHeight = (Float)mWindow->getHeight();
mTextCache.resize( maxLinesOnScreen() );
if ( mVisible ) {
@@ -528,7 +607,7 @@ void Console::privVideoResize( EE::Window::Window * win ) {
}
void Console::getFilesFrom( std::string txt, const Uint32& curPos ) {
static char OSSlash = FileSystem::getOSSlash().at(0);
static char OSSlash = FileSystem::getOSSlash().at( 0 );
size_t pos;
if ( std::string::npos != ( pos = txt.find_last_of( OSSlash ) ) && pos <= curPos ) {
@@ -544,7 +623,7 @@ void Console::getFilesFrom( std::string txt, const Uint32& curPos ) {
bool again = false;
do {
std::vector <std::string> foundFiles;
std::vector<std::string> foundFiles;
res = "";
count = 0;
again = false;
@@ -613,29 +692,30 @@ void Console::getFilesFrom( std::string txt, const Uint32& curPos ) {
}
Int32 Console::linesOnScreen() {
return static_cast<Int32> ( ( mCurHeight / mFontSize ) - 1 );
return static_cast<Int32>( ( mCurHeight / mFontSize ) - 1 );
}
Int32 Console::maxLinesOnScreen() {
return static_cast<Int32> ( ( mHeight / mFontSize ) + 3 );
return static_cast<Int32>( ( mHeight / mFontSize ) + 3 );
}
void Console::privInputCallback( InputEvent * Event ) {
void Console::privInputCallback( InputEvent* Event ) {
Uint8 etype = Event->Type;
if ( mVisible ) {
Uint32 KeyCode = (Uint32)Event->key.keysym.sym;
Uint32 KeyMod = (Uint32)Event->key.keysym.mod;
Uint32 Button = Event->button.button;
Uint32 KeyCode = (Uint32)Event->key.keysym.sym;
Uint32 KeyMod = (Uint32)Event->key.keysym.mod;
Uint32 Button = Event->button.button;
if ( InputEvent::KeyDown == etype ) {
if ( ( KeyCode == KEY_TAB ) && (unsigned int)mTBuf->getCursorPosition() == mTBuf->getBuffer().size() ) {
if ( ( KeyCode == KEY_TAB ) &&
(unsigned int)mTBuf->getCursorPosition() == mTBuf->getBuffer().size() ) {
printCommandsStartingWith( mTBuf->getBuffer() );
getFilesFrom( mTBuf->getBuffer().toUtf8(), mTBuf->getCursorPosition() );
}
if ( KeyMod & KEYMOD_SHIFT ) {
if ( KeyCode == KEY_UP ) {
if ( KeyCode == KEY_UP ) {
if ( mCon.ConMin - mCon.ConModif > 0 )
mCon.ConModif++;
}
@@ -656,14 +736,14 @@ void Console::privInputCallback( InputEvent * Event ) {
if ( KeyCode == KEY_PAGEUP ) {
if ( mCon.ConMin - mCon.ConModif - linesOnScreen() / 2 > 0 )
mCon.ConModif+=linesOnScreen() / 2;
mCon.ConModif += linesOnScreen() / 2;
else
mCon.ConModif = mCon.ConMin;
}
if ( KeyCode == KEY_PAGEDOWN ) {
if ( mCon.ConModif - linesOnScreen() / 2 > 0 )
mCon.ConModif-=linesOnScreen() / 2;
mCon.ConModif -= linesOnScreen() / 2;
else
mCon.ConModif = 0;
}
@@ -673,7 +753,8 @@ void Console::privInputCallback( InputEvent * Event ) {
mLastLogPos--;
}
if ( KeyCode == KEY_DOWN && mLastLogPos < static_cast<int>( mLastCommands.size() ) ) {
if ( KeyCode == KEY_DOWN &&
mLastLogPos < static_cast<int>( mLastCommands.size() ) ) {
mLastLogPos++;
}
@@ -686,7 +767,6 @@ void Console::privInputCallback( InputEvent * Event ) {
}
}
}
}
} else if ( InputEvent::MouseButtonUp == etype ) {
if ( Button == EE_BUTTON_WHEELUP ) {
@@ -709,69 +789,70 @@ void Console::privInputCallback( InputEvent * Event ) {
}
void Console::createDefaultCommands() {
addCommand( "clear", cb::Make1( this, &Console::cmdClear) );
addCommand( "quit", cb::Make1( this, &Console::cmdQuit) );
addCommand( "maximize", cb::Make1( this, &Console::cmdMaximize) );
addCommand( "minimize", cb::Make1( this, &Console::cmdMinimize) );
addCommand( "cmdlist", cb::Make1( this, &Console::cmdCmdList) );
addCommand( "help", cb::Make1( this, &Console::cmdCmdList) );
addCommand( "showcursor", cb::Make1( this, &Console::cmdShowCursor) );
addCommand( "setfpslimit", cb::Make1( this, &Console::cmdFrameLimit) );
addCommand( "getlog", cb::Make1( this, &Console::cmdGetLog) );
addCommand( "setgamma", cb::Make1( this, &Console::cmdSetGamma) );
addCommand( "setvolume", cb::Make1( this, &Console::cmdSetVolume) );
addCommand( "getgpuextensions", cb::Make1( this, &Console::cmdGetGpuExtensions) );
addCommand( "dir", cb::Make1( this, &Console::cmdDir) );
addCommand( "ls", cb::Make1( this, &Console::cmdDir) );
addCommand( "showfps", cb::Make1( this, &Console::cmdShowFps) );
addCommand( "gettexturememory", cb::Make1( this, &Console::cmdGetTextureMemory) );
addCommand( "clear", cb::Make1( this, &Console::cmdClear ) );
addCommand( "quit", cb::Make1( this, &Console::cmdQuit ) );
addCommand( "maximize", cb::Make1( this, &Console::cmdMaximize ) );
addCommand( "minimize", cb::Make1( this, &Console::cmdMinimize ) );
addCommand( "cmdlist", cb::Make1( this, &Console::cmdCmdList ) );
addCommand( "help", cb::Make1( this, &Console::cmdCmdList ) );
addCommand( "showcursor", cb::Make1( this, &Console::cmdShowCursor ) );
addCommand( "setfpslimit", cb::Make1( this, &Console::cmdFrameLimit ) );
addCommand( "getlog", cb::Make1( this, &Console::cmdGetLog ) );
addCommand( "setgamma", cb::Make1( this, &Console::cmdSetGamma ) );
addCommand( "setvolume", cb::Make1( this, &Console::cmdSetVolume ) );
addCommand( "getgpuextensions", cb::Make1( this, &Console::cmdGetGpuExtensions ) );
addCommand( "dir", cb::Make1( this, &Console::cmdDir ) );
addCommand( "ls", cb::Make1( this, &Console::cmdDir ) );
addCommand( "showfps", cb::Make1( this, &Console::cmdShowFps ) );
addCommand( "gettexturememory", cb::Make1( this, &Console::cmdGetTextureMemory ) );
addCommand( "hide", cb::Make1( this, &Console::cmdHideConsole ) );
}
void Console::cmdClear () {
void Console::cmdClear() {
Uint16 CutLines;
if ( mExpand ) {
CutLines = (Uint16)( mHeight / mFontSize );
CutLines = ( Uint16 )( mHeight / mFontSize );
} else {
CutLines = (Uint16)( ( mHeightMin * mHeight ) / mFontSize );
CutLines = ( Uint16 )( ( mHeightMin * mHeight ) / mFontSize );
}
for (Uint16 i = 0; i < CutLines; i++ )
for ( Uint16 i = 0; i < CutLines; i++ )
privPushText( "" );
}
void Console::cmdClear ( const std::vector < String >& params ) {
void Console::cmdClear( const std::vector<String>& params ) {
cmdClear();
}
void Console::cmdMaximize ( const std::vector < String >& params ) {
void Console::cmdMaximize( const std::vector<String>& params ) {
mExpand = true;
mY = mHeight;
privPushText( "Console Maximized" );
}
void Console::cmdMinimize ( const std::vector < String >& params ) {
void Console::cmdMinimize( const std::vector<String>& params ) {
mExpand = false;
mY = eefloor( mHeightMin * mHeight );
privPushText( "Console Minimized" );
}
void Console::cmdQuit ( const std::vector < String >& params ) {
void Console::cmdQuit( const std::vector<String>& params ) {
mWindow->close();
}
void Console::cmdGetTextureMemory ( const std::vector < String >& params ) {
privPushText( "Total texture memory used: " + FileSystem::sizeToString( TextureFactory::instance()->getTextureMemorySize() ) );
void Console::cmdGetTextureMemory( const std::vector<String>& params ) {
privPushText( "Total texture memory used: " +
FileSystem::sizeToString( TextureFactory::instance()->getTextureMemorySize() ) );
}
void Console::cmdCmdList ( const std::vector < String >& params ) {
std::map < String, ConsoleCallback >::iterator itr;
for (itr = mCallbacks.begin(); itr != mCallbacks.end(); ++itr) {
void Console::cmdCmdList( const std::vector<String>& params ) {
std::map<String, ConsoleCallback>::iterator itr;
for ( itr = mCallbacks.begin(); itr != mCallbacks.end(); ++itr ) {
privPushText( "\t" + itr->first );
}
}
void Console::cmdShowCursor ( const std::vector < String >& params ) {
void Console::cmdShowCursor( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Int32 tInt = 0;
@@ -786,7 +867,7 @@ void Console::cmdShowCursor ( const std::vector < String >& params ) {
}
}
void Console::cmdFrameLimit ( const std::vector < String >& params ) {
void Console::cmdFrameLimit( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Int32 tInt = 0;
@@ -802,30 +883,31 @@ void Console::cmdFrameLimit ( const std::vector < String >& params ) {
}
void Console::cmdGetLog() {
std::vector < String > tvec = String::split( String( String::toStr( Log::instance()->getBuffer() ) ) );
std::vector<String> tvec =
String::split( String( String::toStr( Log::instance()->getBuffer() ) ) );
if ( tvec.size() > 0 ) {
for ( unsigned int i = 0; i < tvec.size(); i++ )
privPushText( tvec[i] );
}
}
void Console::cmdGetLog( const std::vector < String >& params ) {
void Console::cmdGetLog( const std::vector<String>& params ) {
cmdGetLog();
}
void Console::cmdGetGpuExtensions() {
std::vector < String > tvec = String::split( String( GLi->getExtensions() ), ' ' );
std::vector<String> tvec = String::split( String( GLi->getExtensions() ), ' ' );
if ( tvec.size() > 0 ) {
for ( unsigned int i = 0; i < tvec.size(); i++ )
privPushText( tvec[i] );
}
}
void Console::cmdGetGpuExtensions( const std::vector < String >& params ) {
void Console::cmdGetGpuExtensions( const std::vector<String>& params ) {
cmdGetGpuExtensions();
}
void Console::cmdSetGamma( const std::vector < String >& params ) {
void Console::cmdSetGamma( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Float tFloat = 0.f;
@@ -840,7 +922,7 @@ void Console::cmdSetGamma( const std::vector < String >& params ) {
privPushText( "Valid parameters are between 0.1 and 10." );
}
void Console::cmdSetVolume( const std::vector < String >& params ) {
void Console::cmdSetVolume( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Float tFloat = 0.f;
@@ -855,7 +937,7 @@ void Console::cmdSetVolume( const std::vector < String >& params ) {
privPushText( "Valid parameters are between 0 and 100." );
}
void Console::cmdDir( const std::vector < String >& params ) {
void Console::cmdDir( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
String Slash( FileSystem::getOSSlash() );
String myPath = params[1];
@@ -903,7 +985,8 @@ void Console::cmdDir( const std::vector < String >& params ) {
}
} else {
if ( myPath == "help" )
privPushText( "You can use a third parameter to show folders first, the parameter is ff." );
privPushText(
"You can use a third parameter to show folders first, the parameter is ff." );
else
privPushText( "Path \"" + myPath + "\" is not a directory." );
}
@@ -912,7 +995,7 @@ void Console::cmdDir( const std::vector < String >& params ) {
}
}
void Console::cmdShowFps( const std::vector < String >& params ) {
void Console::cmdShowFps( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Int32 tInt = 0;
@@ -927,7 +1010,7 @@ void Console::cmdShowFps( const std::vector < String >& params ) {
privPushText( "Valid parameters are 0 ( hide ) or 1 ( show )." );
}
void Console::cmdHideConsole( const std::vector < String >& params ) {
void Console::cmdHideConsole( const std::vector<String>& params ) {
fadeOut();
}
@@ -943,16 +1026,18 @@ void Console::showFps( const bool& Show ) {
mShowFps = Show;
}
FontStyleConfig Console::getFontStyleConfig() const
{
FontStyleConfig Console::getFontStyleConfig() const {
return mFontStyleConfig;
}
void Console::setFontStyleConfig(const FontStyleConfig & fontStyleConfig)
{
void Console::setFontStyleConfig( const FontStyleConfig& fontStyleConfig ) {
mFontStyleConfig = fontStyleConfig;
}
const bool& Console::isFading() const {
return mFading;
}
void Console::writeLog( const std::string& Text ) {
std::vector<String> Strings = String::split( String( Text ) );
@@ -961,4 +1046,4 @@ void Console::writeLog( const std::string& Text ) {
}
}
}}
}} // namespace EE::Graphics

View File

@@ -46,7 +46,11 @@ UIMap::UIMap( UITheme * Theme, TileMap * Map ) :
mDragButton = EE_BUTTON_MMASK;
setDragEnabled( true );
updateScreenPos();
onUpdateScreenPos();
addEventListener( Event::OnUpdateScreenPosition, [&] (const Event*) {
onUpdateScreenPos();
} );
}
UIMap::~UIMap() {
@@ -93,9 +97,7 @@ void UIMap::draw() {
}
}
void UIMap::updateScreenPos() {
UIWindow::updateScreenPos();
void UIMap::onUpdateScreenPos() {
if ( NULL != mMap ) {
mMap->setPosition( Vector2i( mScreenPos.x, mScreenPos.y ) );
}

View File

@@ -88,7 +88,7 @@ class EE_API UIMap : public UIWindow {
void setTileBox( UITextView * tilebox );
void replaceMap( TileMap * newMap );
protected:
protected:
enum EDITING_MODE {
EDITING_LIGHT = 1,
EDITING_OBJECT
@@ -139,7 +139,7 @@ class EE_API UIMap : public UIWindow {
virtual void onSizeChange();
virtual void updateScreenPos();
void onUpdateScreenPos();
virtual void onAlphaChange();

View File

@@ -831,40 +831,40 @@ void Node::onSceneChange() {
}
}
Uint32 Node::isWidget() const {
return mNodeFlags & NODE_FLAG_WIDGET;
bool Node::isWidget() const {
return 0 != ( mNodeFlags & NODE_FLAG_WIDGET );
}
Uint32 Node::isWindow() const {
return mNodeFlags & NODE_FLAG_WINDOW;
bool Node::isWindow() const {
return 0 != ( mNodeFlags & NODE_FLAG_WINDOW );
}
Uint32 Node::isClipped() const {
return mNodeFlags & NODE_FLAG_CLIP_ENABLE;
bool Node::isClipped() const {
return 0 != ( mNodeFlags & NODE_FLAG_CLIP_ENABLE );
}
Uint32 Node::isRotated() const {
return mNodeFlags & NODE_FLAG_ROTATED;
bool Node::isRotated() const {
return 0 != ( mNodeFlags & NODE_FLAG_ROTATED );
}
Uint32 Node::isScaled() const {
return mNodeFlags & NODE_FLAG_SCALED;
bool Node::isScaled() const {
return 0 != ( mNodeFlags & NODE_FLAG_SCALED );
}
Uint32 Node::isFrameBuffer() const {
return mNodeFlags & NODE_FLAG_FRAME_BUFFER;
bool Node::isFrameBuffer() const {
return 0 != ( mNodeFlags & NODE_FLAG_FRAME_BUFFER );
}
Uint32 Node::isSceneNode() const {
return mNodeFlags & NODE_FLAG_SCENENODE;
bool Node::isSceneNode() const {
return 0 != ( mNodeFlags & NODE_FLAG_SCENENODE );
}
Uint32 Node::isUISceneNode() const {
return mNodeFlags & NODE_FLAG_UISCENENODE;
bool Node::isUISceneNode() const {
return 0 != ( mNodeFlags & NODE_FLAG_UISCENENODE );
}
Uint32 Node::isUINode() const {
return mNodeFlags & NODE_FLAG_UINODE;
bool Node::isUINode() const {
return 0 != ( mNodeFlags & NODE_FLAG_UINODE );
}
bool Node::isMeOrParentTreeVisible() const {
@@ -1025,6 +1025,8 @@ void Node::updateScreenPos() {
updateCenter();
mNodeFlags &= ~NODE_FLAG_POSITION_DIRTY;
sendCommonEvent( Event::OnUpdateScreenPosition );
}
void Node::writeNodeFlag( const Uint32& Flag, const Uint32& Val ) {

View File

@@ -270,9 +270,6 @@ void EETest::onFontLoaded() {
eeASSERT( DBSM != NULL );
Con.create( DBSM, true );
Con.setBackgroundColor( 0x201F1FEE );
Con.setBackgroundLineColor( 0x666666EE );
Con.setFontColor( 0xCFCFCFFF );
Con.ignoreCharOnPrompt( 186 ); // 'º'
mBuda = String::fromUtf8( "El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde." );

View File

@@ -753,14 +753,10 @@ void mainLoop() {
refreshStyleSheet();
}
if ( console->isActive() || console->isFading() ) {
appUiSceneNode->invalidate();
uiSceneNode->invalidate();
}
SceneManager::instance()->update();
if ( appUiSceneNode->invalidated() || uiSceneNode->invalidated() ) {
if ( appUiSceneNode->invalidated() || uiSceneNode->invalidated() || console->isActive() ||
console->isFading() ) {
window->clear();
SceneManager::instance()->draw();
@@ -933,8 +929,9 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
else if ( PixelDensity::getPixelDensity() >= 2.f ) pd = "2x";
FontTrueType * font = FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" );
FontTrueType * fontMono = FontTrueType::New( "DejaVuSansMono", "assets/fonts/DejaVuSansMono.ttf" );
console = eeNew( Console, ( font, true, true, 1024 * 1000, 0, window ) );
console = eeNew( Console, ( fontMono, true, true, 1024 * 1000, 0, window ) );
theme = UITheme::load( "uitheme" + pd, "uitheme" + pd, "assets/ui/uitheme" + pd + ".eta", font, "assets/ui/uitheme.css" );