Deprecated (removed) EE::Graphics::Console and EE::Window::InputTextBuffer.

Fixed build.
This commit is contained in:
Martín Lucas Golini
2022-07-16 20:20:13 -03:00
parent 3cf446a467
commit 6be517ccf5
16 changed files with 47 additions and 2356 deletions

View File

@@ -5,7 +5,6 @@
#include <eepp/graphics/batchrenderer.hpp>
#include <eepp/graphics/blendmode.hpp>
#include <eepp/graphics/circledrawable.hpp>
#include <eepp/graphics/console.hpp>
#include <eepp/graphics/convexshapedrawable.hpp>
#include <eepp/graphics/drawablegroup.hpp>
#include <eepp/graphics/drawablesearcher.hpp>

View File

@@ -1,267 +0,0 @@
#ifndef EE_GRAPHICSCCONSOLE_H
#define EE_GRAPHICSCCONSOLE_H
#include <deque>
#include <eepp/graphics/base.hpp>
#include <eepp/graphics/font.hpp>
#include <eepp/graphics/primitives.hpp>
#include <eepp/graphics/text.hpp>
#include <eepp/window/inputtextbuffer.hpp>
namespace EE { namespace Window {
class Window;
class InputTextBuffer;
class InputEvent;
}} // namespace EE::Window
using namespace EE::Window;
namespace EE { namespace Graphics {
class EE_API Console : protected LogReaderInterface {
public:
//! The Console Callback return a vector of parameters ( String )
typedef std::function<void( const std::vector<String>& )> ConsoleCallback;
/** Instances the console but doesn't create it, you must call Create to initialize the console.
*/
Console( EE::Window::Window* window = NULL );
/** Creates the console */
Console( Font* Font, const bool& makeDefaultCommands = true, const bool& attachToLog = true,
const unsigned int& maxLogLines = 1024, const Uint32& textureId = 0,
EE::Window::Window* window = NULL );
virtual ~Console();
/** Set the Console Height ( percent, between 0 and 1 ) when it's not in fullscreen */
void setConsoleMinimizedHeight( const Float& MinHeight );
/** Get the Console Height when it's Minimized ( Not Maximized ) */
const Float& getConsoleMinimizedHeight() const;
/** Set the Texture Id for the Background, 0 will disable texture background */
void setBackgroundTextureId( const Uint32& TexId );
/** Get the Background Texture Id */
Uint32 getBackgroundTextureId() const;
/** Set the Console Background Color */
void setBackgroundColor( const Color& BackColor );
void setCharacterSize( const Uint32& characterSize );
/** Get the Console Background Color */
const Color& getBackgroundColor() const;
/** Set the Console Border Line Background Color */
void setBackgroundLineColor( const Color& BackColor );
/** Get the Console Border Line Background Color */
const Color& getBackgroundLineColor() const;
/** Set the Console Font Color */
void setFontColor( const Color& FntColor );
/** Get the Console Font Color */
const Color& getFontColor() const;
/** Set the Console Client Input ( Writeable Line ) Font Color */
void setFontLineColor( const Color& FntColor );
/** Get the Console Client Input ( Writeable Line ) Font Color */
const Color& getFontLineColor() const;
/** Toogle the console between visible and hided with Fade In or Fade Out effect. */
void toggle();
/** Make visible the console */
void fadeIn();
/** Hide the console */
void fadeOut();
/** @return If Console Active ( Visible ) */
bool isActive() const;
/** Maximize or Minimize the Console */
void setExpanded( const bool& Exp );
/** @return If console is maximized */
bool isExpanded() const;
/** Set the fade time */
void setFadeSpeed( const Time& fadespeed );
/** @return The fading speed in ms */
const Time& getFadeSpeed() const;
/** @brief Creates the new console
* @param Font The Font pointer to class
* @param MakeDefaultCommands Register the default commands provided by the class?
* @param AttachToLog Attach the console to the Log instance
* @param MaxLogLines Maximum number of lines stored on the console
* @param textureId Background texture id ( 0 for no texture )
*/
void create( Font* Font, const bool& makeDefaultCommands = true, const bool& attachToLog = true,
const unsigned int& maxLogLines = 1024, const Uint32& textureId = 0 );
/** Add Text to Console */
void pushText( const String& str );
/** Add formated Text to console */
void pushText( const char* format, ... );
/** Adds a new Command
* @param Command The Command Name ( raise the event )
* @param CB The Callback for the Command
*/
void addCommand( const String& Command, ConsoleCallback CB );
/** Draw the Console ( allways call it, visible or not ) */
void draw( const Time& elapsedTime = Time::Zero );
/** Set the line height ( distance between lines ) */
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 );
/** @return If the console is rendering the FPS count. */
const bool& isShowingFps() const;
/** Activate/Deactive fps rendering */
void showFps( const bool& Show );
FontStyleConfig getFontStyleConfig() const;
void setFontStyleConfig( const FontStyleConfig& fontStyleConfig );
const bool& isFading() const;
protected:
Mutex mMutex;
std::map<String, ConsoleCallback> mCallbacks;
std::deque<String> mCmdLog;
std::deque<String> mLastCommands;
EE::Window::Window* mWindow{ nullptr };
Color mConColor{ 0x201F1FEE };
Color mConLineColor{ 0x666666EE };
Color mFontLineColor{ 255, 255, 255, 230 };
Sizef mSize;
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS
Float mHeightMin{ 0.5f };
#else
Float mHeightMin{ 0.6f };
#endif
Float mCurHeight{ 0.f };
Float mY{ 0.f };
Float mA{ 0.f };
Float mMaxAlpha{ 255.f };
Float mTempY{ 0.f };
Float mFontSize{ 12.f };
Time mFadeSpeed{ Milliseconds( 250.f ) };
Uint32 mMyCallback{ 0 };
Uint32 mVidCb{ 0 };
Uint32 mEx{ 0 };
Uint32 mMaxLogLines{ 1024 };
int mLastLogPos{ 0 };
InputTextBuffer* mTBuf{ nullptr };
Primitives mPri;
Uint32 mTexId{ 0 };
struct sCon {
int ConMin{ 0 };
int ConMax{ 0 };
int ConModif{ 0 };
};
sCon mCon;
Float mCurAlpha{ 0.f };
std::vector<Text> mTextCache;
FontStyleConfig mFontStyleConfig;
bool mEnabled{ false };
bool mVisible{ false };
bool mFadeIn{ false };
bool mFadeOut{ false };
bool mExpand{ false };
bool mFading{ false };
bool mShowFps{ false };
bool mCurSide{ false };
void createDefaultCommands();
void fade( const Time& elapsedTime );
/** Internal Callback for default command ( maximize ) */
void cmdMaximize();
/** Internal Callback for default command ( minimize ) */
void cmdMinimize();
/** Internal Callback for default command ( cmdlist ) */
void cmdCmdList();
/** Internal Callback for default command ( showcursor ) */
void cmdShowCursor( const std::vector<String>& params );
/** Internal Callback for default command ( setfpslimit ) */
void cmdFrameLimit( const std::vector<String>& params );
/** Internal Callback for default command ( setgamma ) */
void cmdSetGamma( const std::vector<String>& params );
/** Internal Callback for default command ( setvolume ) */
void cmdSetVolume( const std::vector<String>& params );
/** Internal Callback for default command ( dir and ls ) */
void cmdDir( const std::vector<String>& params );
/** Internal Callback for default command ( showfps ) */
void cmdShowFps( const std::vector<String>& params );
/** Internal Callback for default command ( gettexturememory ) */
void cmdGetTextureMemory();
/** The Default Commands Callbacks for the Console ( don't call it ) */
void privInputCallback( InputEvent* Event );
/** Clear the Console */
void cmdClear();
/** Add the current log to the console */
void cmdGetLog();
/** Add the GPU Extensions supported to the console */
void cmdGetGpuExtensions();
/** Internal Callback to Process the new line ( when return pressed ) */
void processLine();
void privPushText( const String& str );
void printCommandsStartingWith( const String& start );
void privVideoResize( EE::Window::Window* );
void writeLog( const std::string& Text );
void getFilesFrom( std::string txt, const Uint32& curPos );
Int32 linesOnScreen();
Int32 maxLinesOnScreen();
String getLastCommonSubStr( std::list<String>& cmds );
};
}} // namespace EE::Graphics
#endif

View File

@@ -206,9 +206,7 @@ class EE_API Model {
Mutex mResourceLock;
};
inline ModelIndex ModelIndex::parent() const {
return mModel ? mModel->parentIndex( *this ) : ModelIndex();
}
}}} // namespace EE::UI::Models

View File

@@ -6,7 +6,6 @@
#include <eepp/window/cursormanager.hpp>
#include <eepp/window/engine.hpp>
#include <eepp/window/input.hpp>
#include <eepp/window/inputtextbuffer.hpp>
#include <eepp/window/joystick.hpp>
#include <eepp/window/joystickmanager.hpp>
#include <eepp/window/platformhelper.hpp>

View File

@@ -1,214 +0,0 @@
#ifndef EE_WINDOWCINPUTTEXTBUFFER_H
#define EE_WINDOWCINPUTTEXTBUFFER_H
#include <climits>
#include <eepp/window/base.hpp>
#include <eepp/window/input.hpp>
#include <eepp/window/window.hpp>
namespace EE { namespace Window {
/** @brief A class to keep a buffer of the user writed text */
class EE_API InputTextBuffer {
public:
typedef std::function<void()> EnterCallback;
typedef std::function<void()> CursorPositionChangeCallback;
typedef std::function<void()> BufferChangeCallback;
typedef std::function<void()> SelectionChangeCallback;
static InputTextBuffer* New( const bool& active, const bool& newLineEnabled,
const bool& freeEditing, EE::Window::Window* window = NULL,
const Uint32& maxLength = UINT32_MAX );
static InputTextBuffer* New( EE::Window::Window* window = NULL );
InputTextBuffer( const bool& active, const bool& newLineEnabled, const bool& freeEditing,
EE::Window::Window* window = NULL, const Uint32& maxLength = UINT32_MAX );
InputTextBuffer( EE::Window::Window* window = NULL );
~InputTextBuffer();
/** @return The current buffer */
String getBuffer() const;
/** Set a new current buffer */
void setBuffer( const String& str );
/** @return If input buffer is active */
bool isActive() const;
/** Set the state of the input buffer */
void setActive( const bool& active );
/** @return If new line is supported */
bool setSupportNewLine();
/** Support new line consist of allowing to add a new line when key return is pressed. */
void isNewLineEnabled( const bool& enabled );
/** @return If Free Editing is enabled */
bool isFreeEditingEnabled() const;
/** Free editing consist on the capability of moving the cursor position over the buffer, to
* write over the buffer, and not only after the last character. */
void setFreeEditing( const bool& enabled );
/** Block all the inserts, allow only numeric characters. */
void setAllowOnlyNumbers( const bool& onlynums, const bool& allowdots = false );
/** @return If is only allowing numbers */
bool onlyNumbersAllowed();
/** @return If is only allowing numbers, it allow floating point numbers? */
bool dotsInNumbersAllowed();
/** @return If text selection feature is enabled */
bool isTextSelectionEnabled();
/** Enable text selection */
void setTextSelectionEnabled( const bool& enabled );
/** Start the input buffer */
void start();
/** Clear the buffer */
void clear();
/** Internal callback, don't call it */
void update( InputEvent* Event );
/** A callback for the key return */
void setReturnCallback( EnterCallback EC );
/** @return If something changed since last update */
bool changedSinceLastUpdate();
/** Set if changed since last update */
void setChangedSinceLastUpdate( const bool& Changed );
/** @return The Cursor Position (where is the cursor editing) */
int getCursorPosition() const;
/** Set the cursor position */
void setCursorPosition( const Uint32& pos );
/** This function locates the cursor line position for the correct rendering of it.
* @param LastNewLinePos This will return the position of the closest "\n" to the current Cursor
* Pos
* @return On which line is the cursor
*/
Uint32 getCurPosLinePos( Uint32& LastNewLinePos );
/** Push the char you want to ignore */
void pushIgnoredChar( const Uint32& ch );
/** Set the new max length */
void setMaxLength( const Uint32& Max );
/** @return The Max Length */
const Uint32& getMaxLength() const;
/** Support copy paste */
void supportCopyPaste( const bool& support );
/** @return Support copy paste */
bool supportCopyPaste();
/** Set the cursor to the last character of the buffer. */
void cursorToEnd();
/** Set the selection cursor initial position */
void selCurInit( const Int32& init );
/** Set the selection cursor final position */
void selCurEnd( const Int32& end );
/** @return The selection cursor initial position */
const Int32& selCurInit() const;
/** @return The selection cursor final position */
const Int32& selCurEnd() const;
/** Event callback when the cursor position changes. */
void setCursorPositionChangeCallback(
const CursorPositionChangeCallback& cursorPositionChangeCallback );
/** Event callback when the text buffer changes. */
void setBufferChangeCallback( const BufferChangeCallback& bufferChangeCallback );
/** Event callback when the selection changes. */
void setSelectionChangeCallback( const SelectionChangeCallback& selectionChangeCallback );
void selectAll();
protected:
enum Flags {
SUPPORT_NEW_LINE = 0,
ALLOW_ONLY_NUMBERS = 1,
ALLOW_DOT_IN_NUMBERS = 2,
ACTIVE = 3,
CHANGE_SINCE_LAST_UPDATE = 4,
FREE_EDITING = 5,
PROMPT_AUTO_POS = 6,
SUPPORT_COPY_PASTE = 7,
TEXT_SELECTION_ENABLED = 8
};
EE::Window::Window* mWindow;
String mText;
Uint32 mFlags;
Uint32 mCallback;
int mPromptPos;
EnterCallback mEnterCall;
CursorPositionChangeCallback mCursorPositionChangeCallback;
BufferChangeCallback mBufferChangeCallback;
SelectionChangeCallback mSelectionChangeCallback;
Uint32 mMaxLength;
std::vector<Uint32> mIgnoredChars;
Int32 mSelCurInit;
Int32 mSelCurEnd;
void autoPrompt( const bool& set );
bool autoPrompt();
bool canAdd();
void movePromptRowDown( const bool& breakit );
void movePromptRowUp( const bool& breakit );
void promptToLeftFirstNoChar();
void promptToRightFirstNoChar();
void eraseToPrevNoChar();
void eraseToNextNoChar();
bool isIgnoredChar( const String::StringBaseType& c );
bool validChar( const String::StringBaseType& c );
void tryAddChar( const String::StringBaseType& c );
void shiftSelection( const int& lastPromtpPos );
void removeSelection();
void resetSelection();
void onCursorPositionChange();
void onSelectionChange();
void onBufferChange();
/** Set the cursor position */
void setCursorPos( const Uint32& pos );
};
}} // namespace EE::Window
#endif

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 7.0.2, 2022-07-16T02:30:18. -->
<!-- Written by QtCreator 7.0.2, 2022-07-16T20:03:16. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@@ -109,7 +109,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{388e5431-b31b-42b3-b9ad-9002d279d75d}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">10</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">16</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">19</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">../../make/linux</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">

View File

@@ -51,7 +51,6 @@
../../include/eepp/graphics/batchrenderer.hpp
../../include/eepp/graphics/blendmode.hpp
../../include/eepp/graphics/circledrawable.hpp
../../include/eepp/graphics/console.hpp
../../include/eepp/graphics/convexshapedrawable.hpp
../../include/eepp/graphics/drawablegroup.hpp
../../include/eepp/graphics/drawable.hpp
@@ -443,7 +442,6 @@
../../include/eepp/window/inputfinger.hpp
../../include/eepp/window/inputhelper.hpp
../../include/eepp/window/input.hpp
../../include/eepp/window/inputtextbuffer.hpp
../../include/eepp/window/joycodes.hpp
../../include/eepp/window/joystick.hpp
../../include/eepp/window/joystickmanager.hpp
@@ -527,7 +525,6 @@
../../src/eepp/graphics/batchrenderer.cpp
../../src/eepp/graphics/blendmode.cpp
../../src/eepp/graphics/circledrawable.cpp
../../src/eepp/graphics/console.cpp
../../src/eepp/graphics/convexshapedrawable.cpp
../../src/eepp/graphics/drawable.cpp
../../src/eepp/graphics/drawablegroup.cpp
@@ -987,7 +984,6 @@
../../src/eepp/window/input.cpp
../../src/eepp/window/inputfinger.cpp
../../src/eepp/window/inputhelper.cpp
../../src/eepp/window/inputtextbuffer.cpp
../../src/eepp/window/joystick.cpp
../../src/eepp/window/joystickmanager.cpp
../../src/eepp/window/keycodes.cpp

View File

@@ -1,975 +0,0 @@
#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/system/lock.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 ) :
mWindow( window ), mTBuf( InputTextBuffer::New() ) {
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 ) :
mWindow( window ), mTBuf( InputTextBuffer::New() ) {
mFontStyleConfig.FontColor = Color( 0xCFCFCFFF );
if ( NULL == mWindow )
mWindow = Engine::instance()->getCurrentWindow();
create( font, makeDefaultCommands, attachToLog, maxLogLines, textureId );
}
Console::~Console() {
if ( mMyCallback && NULL != Engine::existsSingleton() &&
Engine::instance()->existsWindow( mWindow ) ) {
mWindow->getInput()->popCallback( mMyCallback );
mWindow->popResizeCallback( mVidCb );
}
eeSAFE_DELETE( mTBuf );
if ( Log::existsSingleton() )
Log::instance()->removeLogReader( this );
}
void Console::setConsoleMinimizedHeight( const EE::Float& MinHeight ) {
mHeightMin = eemax( 0.f, eemin( MinHeight, 1.f ) );
if ( mVisible && !mExpand )
mCurHeight = eefloor( mHeightMin * mWindow->getHeight() );
}
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 ) ) );
}
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 ) ) );
if ( textureId > 0 )
mTexId = textureId;
mMaxLogLines = maxLogLines;
mMaxAlpha = (Float)mConColor.a;
mEnabled = true;
if ( makeDefaultCommands )
createDefaultCommands();
mSize.x = (Float)mWindow->getWidth();
mSize.y = (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 ) );
}
mTBuf->setReturnCallback( cb::Make0( this, &Console::processLine ) );
mTBuf->start();
mTBuf->isNewLineEnabled( false );
mTBuf->setActive( false );
ignoreCharOnPrompt( KEY_TAB );
mCon.ConModif = 0;
cmdGetLog();
if ( attachToLog )
Log::instance()->addLogReader( this );
}
void Console::addCommand( const String& Command, ConsoleCallback CB ) {
if ( !( mCallbacks.count( Command ) > 0 ) )
mCallbacks[Command] = CB;
}
void Console::draw( const Time& elapsedTime ) {
Lock l( mMutex );
if ( mEnabled && NULL != mFontStyleConfig.Font ) {
fade( elapsedTime == Time::Zero ? mWindow->getElapsed() : elapsedTime );
if ( mY > 0.0f ) {
if ( mTexId == 0 ) {
mPri.setColor(
Color( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>( mA ) ) );
mPri.drawRectangle( Rectf( Vector2f( 0.0f, 0.0f ), Sizef( mSize.x, mY ) ) );
} else {
Color C( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>( mA ) );
Texture* Tex = TextureFactory::instance()->getTexture( mTexId );
if ( NULL != Tex )
Tex->drawEx( 0.0f, 0.0f, mSize.x, 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( mSize.x, PixelDensity::dpToPx( 2.0f ) ) ) );
Int32 linesInScreen = this->linesOnScreen();
if ( static_cast<Int32>( mCmdLog.size() ) > linesInScreen )
mEx = (Uint32)( mCmdLog.size() - linesInScreen );
else
mEx = 0;
mTempY = -mCurHeight;
Uint16 Pos = 0;
Float CurY;
mCon.ConMin = mEx;
mCon.ConMax = (int)mCmdLog.size() - 1;
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;
Text& text = mTextCache[Pos];
text.setFont( mFontStyleConfig.Font );
text.setFontSize( mFontStyleConfig.CharacterSize );
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.setString( mCmdLog[i] );
text.draw( mFontSize, CurY );
Pos++;
}
}
CurY = mTempY + mY + mCurHeight - mFontSize - 1;
Text& text = mTextCache[mTextCache.size() - 1];
text.setFont( mFontStyleConfig.Font );
text.setFontSize( 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.setString( "> " + mTBuf->getBuffer() );
text.draw( mFontSize, CurY );
Text& text2 = mTextCache[mTextCache.size() - 2];
text2.setFont( mFontStyleConfig.Font );
text2.setFontSize( 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 ) ) );
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() ) );
Uint32 width = mFontSize + text2.getTextWidth();
text2.setString( "_" );
text2.draw( width, CurY );
}
}
}
if ( mShowFps && NULL != mFontStyleConfig.Font ) {
Text& text = mTextCache[mTextCache.size() - 3];
Color OldColor1( text.getColor() );
text.setStyleConfig( mFontStyleConfig );
text.setFillColor( Color::White );
text.setString( "FPS: " + String::toString( mWindow->getFPS() ) );
text.draw( mWindow->getWidth() - text.getTextWidth() - 15, 6 );
text.setFillColor( OldColor1 );
}
}
void Console::setLineHeight( const Float& LineHeight ) {
mFontSize = LineHeight;
}
void Console::fadeIn() {
if ( !mFading ) {
mFading = true;
mFadeIn = true;
mVisible = true;
mY = 0.0f;
mTBuf->setActive( true );
}
}
void Console::fadeOut() {
if ( !mFading ) {
mFading = true;
mFadeOut = true;
mVisible = false;
mTBuf->setActive( false );
}
}
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++ ) {
String tparam = params[i];
if ( !tparam.empty() ) {
if ( '"' == tparam[0] ) {
tstr += tparam;
} else if ( '"' == tparam[tparam.size() - 1] ) {
tstr += " " + tparam;
rparams.push_back( String::trim( tstr, '"' ) );
tstr = "";
} else if ( !tstr.empty() ) {
tstr += " " + tparam;
} else {
rparams.push_back( tparam );
}
}
}
if ( !tstr.empty() ) {
rparams.push_back( String::trim( tstr, '"' ) );
}
return rparams;
}
void Console::processLine() {
String str = mTBuf->getBuffer();
std::vector<String> params = splitCommandParams( str );
mLastCommands.push_back( str );
mLastLogPos = (int)mLastCommands.size();
if ( mLastCommands.size() > 20 )
mLastCommands.pop_front();
if ( str.size() > 0 ) {
privPushText( "> " + str );
if ( mCallbacks.find( params[0] ) != mCallbacks.end() ) {
mCallbacks[params[0]]( params );
} else {
privPushText( "Unknown Command: '" + params[0] + "'" );
}
}
mTBuf->clear();
}
void Console::privPushText( const String& str ) {
Lock l( mMutex );
mCmdLog.push_back( str );
if ( mCmdLog.size() >= mMaxLogLines )
mCmdLog.pop_front();
}
void Console::pushText( const String& str ) {
if ( std::string::npos != str.find_first_of( '\n' ) ) {
std::vector<String> Strings = String::split( String( str ) );
for ( Uint32 i = 0; i < Strings.size(); i++ ) {
privPushText( Strings[i] );
}
} else {
privPushText( str );
}
}
void Console::pushText( const char* format, ... ) {
int n, size = 256;
std::string tstr( size, '\0' );
va_list args;
while ( 1 ) {
va_start( args, format );
n = vsnprintf( &tstr[0], size, format, args );
if ( n > -1 && n < size ) {
tstr.resize( n );
pushText( tstr );
va_end( args );
return;
}
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 );
}
}
void Console::toggle() {
if ( mVisible )
fadeOut();
else
fadeIn();
}
void Console::fade( const Time& elapsedTime ) {
if ( mCurSide ) {
mCurAlpha -= 255.f * elapsedTime.asMilliseconds() / mFadeSpeed.asMilliseconds();
if ( mCurAlpha <= 0.0f ) {
mCurAlpha = 0.0f;
mCurSide = !mCurSide;
}
} else {
mCurAlpha += 255.f * elapsedTime.asMilliseconds() / mFadeSpeed.asMilliseconds();
if ( mCurAlpha >= 255.f ) {
mCurAlpha = 255.f;
mCurSide = !mCurSide;
}
}
if ( mExpand )
mCurHeight = mSize.y;
else
mCurHeight = eefloor( mHeightMin * mSize.y );
if ( mFadeIn ) {
mFadeOut = false;
mY += mCurHeight * elapsedTime.asMilliseconds() / mFadeSpeed.asMilliseconds();
mA = ( mY * mMaxAlpha / mCurHeight );
if ( mY > mCurHeight ) {
mY = mCurHeight;
mFadeIn = false;
mFading = false;
}
}
if ( mFadeOut ) {
mFadeIn = false;
mY -= mCurHeight * elapsedTime.asMilliseconds() / mFadeSpeed.asMilliseconds();
mA = ( mY * mMaxAlpha / mCurHeight );
if ( mY <= 0.0f ) {
mY = 0.0f;
mFadeOut = false;
mFading = false;
}
}
if ( mA > 255.0f )
mA = 255.0f;
if ( mA < 0.0f )
mA = 0.0f;
}
String Console::getLastCommonSubStr( std::list<String>& cmds ) {
String lastCommon( mTBuf->getBuffer() );
String strTry( lastCommon );
std::list<String>::iterator ite;
bool found = false;
do {
found = false;
bool allEqual = true;
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 );
if ( !( strTry.size() <= strCur.size() &&
strTry == strCur.substr( 0, strTry.size() ) ) ) {
allEqual = false;
}
}
if ( allEqual ) {
lastCommon = strTry;
found = true;
}
}
} while ( found );
return lastCommon;
}
void Console::printCommandsStartingWith( const String& start ) {
std::list<String> cmds;
std::map<String, ConsoleCallback>::iterator it;
for ( it = mCallbacks.begin(); it != mCallbacks.end(); ++it ) {
if ( String::startsWith( it->first, start ) ) {
cmds.push_back( it->first );
}
}
if ( cmds.size() > 1 ) {
privPushText( "> " + mTBuf->getBuffer() );
std::list<String>::iterator ite;
for ( ite = cmds.begin(); ite != cmds.end(); ++ite )
privPushText( ( *ite ) );
String newStr( getLastCommonSubStr( cmds ) );
if ( newStr != mTBuf->getBuffer() ) {
mTBuf->setBuffer( newStr );
mTBuf->cursorToEnd();
}
} else if ( cmds.size() ) {
mTBuf->setBuffer( cmds.front() );
mTBuf->cursorToEnd();
}
}
void Console::privVideoResize( EE::Window::Window* ) {
mSize.x = (Float)mWindow->getWidth();
mSize.y = (Float)mWindow->getHeight();
mTextCache.resize( maxLinesOnScreen() );
if ( mVisible ) {
if ( mExpand )
mCurHeight = mSize.y;
else
mCurHeight = eefloor( mHeightMin * mSize.y );
mY = mCurHeight;
}
}
void Console::getFilesFrom( std::string txt, const Uint32& curPos ) {
static char OSSlash = FileSystem::getOSSlash().at( 0 );
size_t pos;
if ( std::string::npos != ( pos = txt.find_last_of( OSSlash ) ) && pos <= curPos ) {
size_t fpos = txt.find_first_of( OSSlash );
std::string dir( txt.substr( fpos, pos - fpos + 1 ) );
std::string file( txt.substr( pos + 1 ) );
if ( FileSystem::isDirectory( dir ) ) {
size_t count = 0, lasti = 0;
std::vector<std::string> files = FileSystem::filesGetInPath( dir, true, true );
String res;
bool again = false;
do {
std::vector<std::string> foundFiles;
res = "";
count = 0;
again = false;
for ( size_t i = 0; i < files.size(); i++ ) {
if ( !file.size() || String::startsWith( files[i], file ) ) {
res += "\t" + files[i] + "\n";
count++;
lasti = i;
foundFiles.push_back( files[i] );
}
}
if ( count > 1 ) {
bool allBigger = true;
bool allStartsWith = true;
do {
allBigger = true;
for ( size_t i = 0; i < foundFiles.size(); i++ ) {
if ( foundFiles[i].size() < file.size() + 1 ) {
allBigger = false;
break;
}
}
if ( allBigger ) {
std::string tfile = foundFiles[0].substr( 0, file.size() + 1 );
allStartsWith = true;
for ( size_t i = 0; i < foundFiles.size(); i++ ) {
if ( !String::startsWith( foundFiles[i], tfile ) ) {
allStartsWith = false;
break;
}
}
if ( allStartsWith ) {
file = tfile;
again = true;
}
}
} while ( allBigger && allStartsWith );
}
} while ( again );
if ( count == 1 ) {
std::string slash = "";
if ( FileSystem::isDirectory( dir + files[lasti] ) ) {
slash = FileSystem::getOSSlash();
}
mTBuf->setBuffer( mTBuf->getBuffer().substr( 0, pos + 1 ) + files[lasti] + slash );
mTBuf->cursorToEnd();
} else if ( count > 1 ) {
privPushText( "Directory file list:" );
pushText( res );
mTBuf->setBuffer( mTBuf->getBuffer().substr( 0, pos + 1 ) + file );
mTBuf->cursorToEnd();
}
}
}
}
Int32 Console::linesOnScreen() {
return static_cast<Int32>( ( mCurHeight / mFontSize ) - 1 );
}
Int32 Console::maxLinesOnScreen() {
return static_cast<Int32>( ( mSize.y / mFontSize ) + 3 );
}
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;
if ( InputEvent::KeyDown == etype ) {
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 ( mCon.ConMin - mCon.ConModif > 0 )
mCon.ConModif++;
}
if ( KeyCode == KEY_DOWN ) {
if ( mCon.ConModif > 0 )
mCon.ConModif--;
}
if ( KeyCode == KEY_HOME ) {
size_t size;
{
Lock l( mMutex );
size = mCmdLog.size();
}
if ( static_cast<Int32>( size ) > linesOnScreen() )
mCon.ConModif = mCon.ConMin;
}
if ( KeyCode == KEY_END ) {
mCon.ConModif = 0;
}
if ( KeyCode == KEY_PAGEUP ) {
if ( mCon.ConMin - mCon.ConModif - linesOnScreen() / 2 > 0 )
mCon.ConModif += linesOnScreen() / 2;
else
mCon.ConModif = mCon.ConMin;
}
if ( KeyCode == KEY_PAGEDOWN ) {
if ( mCon.ConModif - linesOnScreen() / 2 > 0 )
mCon.ConModif -= linesOnScreen() / 2;
else
mCon.ConModif = 0;
}
} else {
if ( mLastCommands.size() > 0 ) {
if ( KeyCode == KEY_UP && mLastLogPos > 0 ) {
mLastLogPos--;
}
if ( KeyCode == KEY_DOWN &&
mLastLogPos < static_cast<int>( mLastCommands.size() ) ) {
mLastLogPos++;
}
if ( KeyCode == KEY_UP || KeyCode == KEY_DOWN ) {
if ( mLastLogPos == static_cast<int>( mLastCommands.size() ) ) {
mTBuf->setBuffer( "" );
} else {
mTBuf->setBuffer( mLastCommands[mLastLogPos] );
mTBuf->cursorToEnd();
}
}
}
}
} else if ( InputEvent::MouseButtonUp == etype ) {
if ( Button == EE_BUTTON_WHEELUP ) {
if ( mCon.ConMin - mCon.ConModif - 6 > 0 ) {
mCon.ConModif += 6;
} else {
mCon.ConModif = mCon.ConMin;
}
}
if ( Button == EE_BUTTON_WHEELDOWN ) {
if ( mCon.ConModif - 6 > 0 ) {
mCon.ConModif -= 6;
} else {
mCon.ConModif = 0;
}
}
}
}
}
void Console::createDefaultCommands() {
addCommand( "clear", [&]( const auto& ) { cmdClear(); } );
addCommand( "quit", [&]( const auto& ) { mWindow->close(); } );
addCommand( "maximize", [&]( const auto& ) { cmdMaximize(); } );
addCommand( "minimize", [&]( const auto& ) { cmdMinimize(); } );
addCommand( "cmdlist", [&]( const auto& ) { cmdCmdList(); } );
addCommand( "help", [&]( const auto& ) { cmdCmdList(); } );
addCommand( "showcursor", [&]( const auto& params ) { cmdShowCursor( params ); } );
addCommand( "setfpslimit", [&]( const auto& params ) { cmdFrameLimit( params ); } );
addCommand( "getlog", [&]( const auto& ) { cmdGetLog(); } );
addCommand( "setgamma", [&]( const auto& params ) { cmdSetGamma( params ); } );
addCommand( "setvolume", [&]( const auto& params ) { cmdSetVolume( params ); } );
addCommand( "getgpuextensions", [&]( const auto& ) { cmdGetGpuExtensions(); } );
addCommand( "dir", [&]( const auto& params ) { cmdDir( params ); } );
addCommand( "ls", [&]( const auto& params ) { cmdDir( params ); } );
addCommand( "showfps", [&]( const auto& params ) { cmdShowFps( params ); } );
addCommand( "gettexturememory", [&]( const auto& ) { cmdGetTextureMemory(); } );
addCommand( "hide", [&]( const auto& ) { fadeOut(); } );
}
void Console::cmdClear() {
Uint16 CutLines;
if ( mExpand ) {
CutLines = (Uint16)( mSize.y / mFontSize );
} else {
CutLines = (Uint16)( ( mHeightMin * mSize.y ) / mFontSize );
}
for ( Uint16 i = 0; i < CutLines; i++ )
privPushText( "" );
}
void Console::cmdMaximize() {
mExpand = true;
mY = mSize.y;
privPushText( "Console Maximized" );
}
void Console::cmdMinimize() {
mExpand = false;
mY = eefloor( mHeightMin * mSize.y );
privPushText( "Console Minimized" );
}
void Console::cmdGetTextureMemory() {
privPushText( "Total texture memory used: " +
FileSystem::sizeToString( TextureFactory::instance()->getTextureMemorySize() ) );
}
void Console::cmdCmdList() {
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 ) {
if ( params.size() >= 2 ) {
Int32 tInt = 0;
bool Res = String::fromString<Int32>( tInt, params[1] );
if ( Res && ( tInt == 0 || tInt == 1 ) ) {
mWindow->getCursorManager()->setVisible( 0 != tInt );
} else
privPushText( "Valid parameters are 0 or 1." );
} else {
privPushText( "No parameters. Valid parameters are 0 ( hide ) or 1 ( show )." );
}
}
void Console::cmdFrameLimit( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Int32 tInt = 0;
bool Res = String::fromString<Int32>( tInt, params[1] );
if ( Res && ( tInt >= 0 && tInt <= 10000 ) ) {
mWindow->setFrameRateLimit( tInt );
return;
}
}
privPushText( "Valid parameters are between 0 and 10000 (0 = no limit)." );
}
void Console::cmdGetLog() {
std::vector<String> tvec =
String::split( String( String::toString( Log::instance()->getBuffer() ) ) );
if ( tvec.size() > 0 ) {
for ( unsigned int i = 0; i < tvec.size(); i++ )
privPushText( tvec[i] );
}
}
void Console::cmdGetGpuExtensions() {
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::cmdSetGamma( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Float tFloat = 0.f;
bool Res = String::fromString<Float>( tFloat, params[1] );
if ( Res && ( tFloat > 0.1f && tFloat <= 10.0f ) ) {
mWindow->setGamma( tFloat, tFloat, tFloat );
return;
}
}
privPushText( "Valid parameters are between 0.1 and 10." );
}
void Console::cmdSetVolume( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Float tFloat = 0.f;
bool Res = String::fromString<Float>( tFloat, params[1] );
if ( Res && ( tFloat >= 0.0f && tFloat <= 100.0f ) ) {
EE::Audio::Listener::setGlobalVolume( tFloat );
return;
}
}
privPushText( "Valid parameters are between 0 and 100." );
}
void Console::cmdDir( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
String Slash( FileSystem::getOSSlash() );
String myPath = params[1];
String myOrder;
if ( params.size() > 2 ) {
myOrder = params[2];
}
if ( FileSystem::isDirectory( myPath ) ) {
unsigned int i;
std::vector<String> mFiles = FileSystem::filesGetInPath( myPath );
std::sort( mFiles.begin(), mFiles.end() );
privPushText( "Directory: " + myPath );
if ( myOrder == "ff" ) {
std::vector<String> mFolders;
std::vector<String> mFile;
for ( i = 0; i < mFiles.size(); i++ ) {
if ( FileSystem::isDirectory( myPath + Slash + mFiles[i] ) ) {
mFolders.push_back( mFiles[i] );
} else {
mFile.push_back( mFiles[i] );
}
}
if ( mFolders.size() )
privPushText( "Folders: " );
for ( i = 0; i < mFolders.size(); i++ )
privPushText( " " + mFolders[i] );
if ( mFolders.size() )
privPushText( "Files: " );
for ( i = 0; i < mFile.size(); i++ )
privPushText( " " + mFile[i] );
} else {
for ( i = 0; i < mFiles.size(); i++ )
privPushText( " " + mFiles[i] );
}
} else {
if ( myPath == "help" )
privPushText(
"You can use a third parameter to show folders first, the parameter is ff." );
else
privPushText( "Path \"" + myPath + "\" is not a directory." );
}
} else {
privPushText( "Expected a path to list. Example of usage: ls /home" );
}
}
void Console::cmdShowFps( const std::vector<String>& params ) {
if ( params.size() >= 2 ) {
Int32 tInt = 0;
bool Res = String::fromString<Int32>( tInt, params[1] );
if ( Res && ( tInt == 0 || tInt == 1 ) ) {
mShowFps = 0 != tInt;
return;
}
}
privPushText( "Valid parameters are 0 ( hide ) or 1 ( show )." );
}
void Console::ignoreCharOnPrompt( const Uint32& ch ) {
mTBuf->pushIgnoredChar( ch );
}
const bool& Console::isShowingFps() const {
return mShowFps;
}
void Console::showFps( const bool& Show ) {
mShowFps = Show;
}
FontStyleConfig Console::getFontStyleConfig() const {
return mFontStyleConfig;
}
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 ) );
for ( Uint32 i = 0; i < Strings.size(); i++ ) {
privPushText( Strings[i] );
}
}
}} // namespace EE::Graphics

View File

@@ -1,5 +1,6 @@
#include <eepp/ui/models/model.hpp>
#include <eepp/ui/models/modelindex.hpp>
namespace EE { namespace UI { namespace Models {
ModelIndex ModelIndex::sibling( int row, int column ) const {
@@ -22,4 +23,8 @@ Variant ModelIndex::data( ModelRole role ) const {
return model()->data( *this, role );
}
ModelIndex ModelIndex::parent() const {
return mModel ? mModel->parentIndex( *this ) : ModelIndex();
}
}}} // namespace EE::UI::Models

View File

@@ -27,7 +27,7 @@ using namespace EE::Scene;
namespace EE { namespace UI {
UIConsole* UIConsole::New() {
return eeNew( UIConsole, ( nullptr, true, false, 8192 ) );
return eeNew( UIConsole, ( nullptr, true, true, 8192 ) );
}
UIConsole* UIConsole::NewOpt( Font* font, const bool& makeDefaultCommands, const bool& attachToLog,
@@ -263,6 +263,26 @@ const Color& UIConsole::getFontSelectionBackColor() const {
return mFontStyleConfig.getFontSelectionBackColor();
}
UIConsole* UIConsole::setFontShadowColor( const Color& color ) {
if ( color != mFontStyleConfig.getFontShadowColor() ) {
mFontStyleConfig.ShadowColor = color;
onFontStyleChanged();
}
return this;
}
const Color& UIConsole::getFontShadowColor() const {
return mFontStyleConfig.ShadowColor;
}
UIConsole* UIConsole::setFontStyle( const Uint32& fontStyle ) {
if ( mFontStyleConfig.Style != fontStyle ) {
mFontStyleConfig.Style = fontStyle;
onFontStyleChanged();
}
return this;
}
UIConsole* UIConsole::setFontOutlineThickness( const Float& outlineThickness ) {
if ( mFontStyleConfig.OutlineThickness != outlineThickness ) {
mFontStyleConfig.OutlineThickness = outlineThickness;

View File

@@ -1,859 +0,0 @@
#include <eepp/window/clipboard.hpp>
#include <eepp/window/engine.hpp>
#include <eepp/window/inputtextbuffer.hpp>
namespace EE { namespace Window {
// TODO: Deprecate this. It's horrendous. Use TextDocument instead.
InputTextBuffer* InputTextBuffer::New( const bool& active, const bool& newLineEnabled,
const bool& freeEditing, EE::Window::Window* window,
const Uint32& maxLength ) {
return eeNew( InputTextBuffer, ( active, newLineEnabled, freeEditing, window, maxLength ) );
}
InputTextBuffer* InputTextBuffer::New( EE::Window::Window* window ) {
return eeNew( InputTextBuffer, ( window ) );
}
InputTextBuffer::InputTextBuffer( const bool& active, const bool& newLineEnabled,
const bool& freeEditing, EE::Window::Window* window,
const Uint32& maxLength ) :
mWindow( window ),
mFlags( 0 ),
mCallback( 0 ),
mPromptPos( 0 ),
mMaxLength( UINT32_MAX ),
mSelCurInit( -1 ),
mSelCurEnd( -1 ) {
if ( NULL == mWindow ) {
mWindow = Engine::instance()->getCurrentWindow();
}
this->setActive( active );
this->setFreeEditing( freeEditing );
this->isNewLineEnabled( newLineEnabled );
autoPrompt( true );
supportCopyPaste( true );
mMaxLength = maxLength;
}
InputTextBuffer::InputTextBuffer( EE::Window::Window* window ) :
mWindow( window ),
mFlags( 0 ),
mCallback( 0 ),
mPromptPos( 0 ),
mMaxLength( UINT32_MAX ),
mSelCurInit( -1 ),
mSelCurEnd( -1 ) {
if ( NULL == mWindow ) {
mWindow = Engine::instance()->getCurrentWindow();
}
setActive( true );
setFreeEditing( true );
isNewLineEnabled( false );
autoPrompt( true );
setTextSelectionEnabled( false );
supportCopyPaste( true );
}
InputTextBuffer::~InputTextBuffer() {
if ( 0 != mCallback && Engine::existsSingleton() &&
Engine::instance()->existsWindow( mWindow ) ) {
mWindow->getInput()->popCallback( mCallback );
}
mText.clear();
}
void InputTextBuffer::start() {
if ( NULL == mWindow ) {
mWindow = Engine::instance()->getCurrentWindow();
}
if ( Engine::instance()->existsWindow( mWindow ) ) {
mCallback =
mWindow->getInput()->pushCallback( cb::Make1( this, &InputTextBuffer::update ) );
}
}
void InputTextBuffer::promptToLeftFirstNoChar() {
if ( !mText.size() )
return;
if ( mPromptPos - 2 > 0 ) {
for ( Int32 i = mPromptPos - 2; i > 0; i-- ) {
if ( !String::isLetter( mText[i] ) && !String::isNumber( mText[i] ) &&
'\n' != mText[i] ) {
setCursorPos( i + 1 );
break;
} else if ( i - 1 == 0 ) {
setCursorPos( 0 );
break;
}
}
} else {
setCursorPos( 0 );
}
resetSelection();
}
void InputTextBuffer::promptToRightFirstNoChar() {
Int32 s = static_cast<Int32>( mText.size() );
if ( 0 == s )
return;
for ( Int32 i = mPromptPos; i < s; i++ ) {
if ( !String::isLetter( mText[i] ) && !String::isNumber( mText[i] ) && '\n' != mText[i] ) {
setCursorPos( i + 1 );
break;
} else if ( i + 1 == s ) {
setCursorPos( s );
}
}
resetSelection();
}
void InputTextBuffer::resetSelection() {
if ( isTextSelectionEnabled() ) {
selCurInit( -1 );
selCurEnd( -1 );
onSelectionChange();
}
}
void InputTextBuffer::eraseToPrevNoChar() {
if ( !mText.size() || !mPromptPos )
return;
String::StringBaseType c;
do {
if ( mPromptPos < (int)mText.size() ) {
mText.erase( mPromptPos - 1, 1 );
setCursorPos( mPromptPos - 1 );
} else {
mText.resize( mText.size() - 1 );
setCursorPos( mText.size() );
}
if ( mPromptPos <= 0 ) {
setCursorPos( 0 );
break;
}
c = mText[mPromptPos - 1];
} while ( String::isLetter( c ) || String::isNumber( c ) );
resetSelection();
setChangedSinceLastUpdate( true );
onBufferChange();
}
void InputTextBuffer::eraseToNextNoChar() {
if ( !mText.size() )
return;
Int32 tPromptPos = mPromptPos;
Int32 c;
Int32 size = (Int32)mText.size();
do {
tPromptPos++;
if ( tPromptPos < size ) {
c = mText[tPromptPos];
} else {
break;
}
} while ( String::isLetter( c ) || String::isNumber( c ) );
if ( tPromptPos <= size ) {
String iniStr( mText.substr( 0, mPromptPos ) );
String endStr( mText.substr( tPromptPos ) );
setBuffer( iniStr + endStr );
resetSelection();
onBufferChange();
}
}
bool InputTextBuffer::isIgnoredChar( const String::StringBaseType& c ) {
if ( mIgnoredChars.size() ) {
for ( std::size_t i = 0; i < mIgnoredChars.size(); i++ ) {
if ( mIgnoredChars[i] == c )
return true;
}
}
return false;
}
bool InputTextBuffer::validChar( const String::StringBaseType& c ) {
if ( canAdd() && String::isCharacter( c ) ) {
bool Ignored = false;
if ( onlyNumbersAllowed() && !String::isNumber( c, dotsInNumbersAllowed() ) ) {
Ignored = true;
}
if ( isIgnoredChar( c ) ) {
Ignored = true;
}
if ( !Ignored ) {
return true;
}
}
return false;
}
void InputTextBuffer::tryAddChar( const String::StringBaseType& c ) {
if ( isFreeEditingEnabled() ) {
if ( validChar( c ) ) {
removeSelection();
if ( autoPrompt() ) {
mText += c;
setCursorPos( (int)mText.size() );
} else {
String::insertChar( mText, mPromptPos, c );
setCursorPos( mPromptPos + 1 );
}
setChangedSinceLastUpdate( true );
onBufferChange();
}
} else {
if ( canAdd() && String::isCharacter( c ) ) {
Input* Input = mWindow->getInput();
if ( !Input->isMetaPressed() && !Input->isAltPressed() && !Input->isControlPressed() ) {
if ( !( onlyNumbersAllowed() && !String::isNumber( c, dotsInNumbersAllowed() ) ) ) {
mText += c;
}
}
}
}
}
void InputTextBuffer::removeSelection() {
if ( isTextSelectionEnabled() && -1 != mSelCurInit && -1 != mSelCurEnd ) {
Int32 size = (Int32)mText.size();
if ( mSelCurInit <= size && mSelCurInit <= size ) {
Int32 init = eemin( mSelCurInit, mSelCurEnd );
Int32 end = eemax( mSelCurInit, mSelCurEnd );
String iniStr( mText.substr( 0, init ) );
String endStr( mText.substr( end ) );
setBuffer( iniStr + endStr );
setCursorPos( init );
resetSelection();
onBufferChange();
} else {
resetSelection();
}
}
}
void InputTextBuffer::update( InputEvent* Event ) {
if ( isActive() ) {
Input* Input = mWindow->getInput();
Uint32 keyChar = 0;
if ( Event->Type == InputEvent::TextInput || Event->Type == InputEvent::KeyDown ||
Event->Type == InputEvent::KeyUp ) {
keyChar = InputHelper::convertKeyCharacter( Event->key.keysym.sym,
Event->key.keysym.unicode );
}
if ( isFreeEditingEnabled() ) {
switch ( Event->Type ) {
case InputEvent::TextInput: {
tryAddChar( Event->text.text );
break;
}
case InputEvent::KeyDown: {
if ( isTextSelectionEnabled() ) {
if ( mSelCurInit >= 0 && mSelCurInit != mSelCurEnd ) {
if ( ( Event->key.keysym.mod & KEYMOD_CTRL ) &&
( Event->key.keysym.sym == KEY_C ||
Event->key.keysym.sym == KEY_X ) ) {
Int32 init = eemin( mSelCurInit, mSelCurEnd );
Int32 end = eemax( mSelCurInit, mSelCurEnd );
std::string clipStr( mText.substr( init, end - init ).toUtf8() );
mWindow->getClipboard()->setText( clipStr );
} else if ( Event->key.keysym.sym == KEY_UP ||
Event->key.keysym.sym == KEY_DOWN ||
Event->key.keysym.sym == KEY_LEFT ||
Event->key.keysym.sym == KEY_RIGHT ||
Event->key.keysym.sym == KEY_HOME ||
Event->key.keysym.sym == KEY_END ) {
if ( !( Input->isShiftPressed() &&
( Event->key.keysym.sym == KEY_UP ||
Event->key.keysym.sym == KEY_DOWN ||
Event->key.keysym.sym == KEY_LEFT ||
Event->key.keysym.sym == KEY_RIGHT ||
Event->key.keysym.sym == KEY_HOME ||
Event->key.keysym.sym == KEY_END ) ) ) {
resetSelection();
}
}
if ( ( ( ( Event->key.keysym.sym & KEYMOD_LCTRL ) &&
( Event->key.keysym.sym == KEY_X ||
Event->key.keysym.sym == KEY_V ) ) ||
Event->key.keysym.sym == KEY_DELETE ) ||
keyChar == KEY_BACKSPACE ) {
removeSelection();
}
}
if ( ( Event->key.keysym.mod & KEYMOD_CTRL ) &&
Event->key.keysym.sym == KEY_A ) {
selectAll();
}
}
if ( Input->isShiftPressed() || Input->isControlPressed() ) {
if ( !onlyNumbersAllowed() &&
( ( ( Event->key.keysym.mod & KEYMOD_SHIFT ) &&
keyChar == KEY_INSERT ) ||
( ( Event->key.keysym.mod & KEYMOD_CTRL ) &&
Event->key.keysym.sym == KEY_V ) ) ) {
String txt = mWindow->getClipboard()->getWideText();
if ( !setSupportNewLine() ) {
size_t pos = txt.find_first_of( '\n' );
if ( pos != std::string::npos )
txt = txt.substr( 0, pos );
}
if ( txt.size() ) {
if ( mText.size() + txt.size() < mMaxLength ) {
if ( autoPrompt() ) {
mText += txt;
setCursorPos( (int)mText.size() );
} else {
mText.insert( mPromptPos, txt );
mPromptPos += txt.size();
}
autoPrompt( false );
}
setChangedSinceLastUpdate( true );
onBufferChange();
}
}
if ( Input->isControlPressed() ) {
if ( keyChar == KEY_LEFT ) {
promptToLeftFirstNoChar();
break;
} else if ( keyChar == KEY_RIGHT ) {
promptToRightFirstNoChar();
break;
} else if ( keyChar == KEY_BACKSPACE ) {
eraseToPrevNoChar();
break;
} else if ( keyChar == KEY_DELETE ) {
eraseToNextNoChar();
break;
}
}
}
if ( ( keyChar == KEY_BACKSPACE || keyChar == KEY_DELETE ) ) {
if ( mText.size() ) {
if ( mPromptPos < (int)mText.size() ) {
if ( keyChar == KEY_BACKSPACE ) {
if ( mPromptPos > 0 ) {
mText.erase( mPromptPos - 1, 1 );
setCursorPos( mPromptPos - 1 );
}
} else {
mText.erase( mPromptPos, 1 );
}
} else if ( keyChar == KEY_BACKSPACE ) {
mText.resize( mText.size() - 1 );
autoPrompt( true );
}
resetSelection();
setChangedSinceLastUpdate( true );
onBufferChange();
}
} else if ( ( keyChar == KEY_RETURN || keyChar == KEY_KP_ENTER ) ) {
if ( setSupportNewLine() && canAdd() ) {
String::insertChar( mText, mPromptPos, '\n' );
setCursorPos( mPromptPos + 1 );
resetSelection();
setChangedSinceLastUpdate( true );
onBufferChange();
}
if ( mEnterCall )
mEnterCall();
} else if ( keyChar == KEY_LEFT ) {
if ( ( mPromptPos - 1 ) >= 0 ) {
setCursorPos( mPromptPos - 1 );
autoPrompt( false );
shiftSelection( mPromptPos + 1 );
}
} else if ( keyChar == KEY_RIGHT ) {
if ( ( mPromptPos + 1 ) < (int)mText.size() ) {
setCursorPos( mPromptPos + 1 );
autoPrompt( false );
shiftSelection( mPromptPos - 1 );
} else if ( ( mPromptPos + 1 ) == (int)mText.size() ) {
autoPrompt( true );
}
} else if ( keyChar == KEY_UP ) {
movePromptRowUp( false );
} else if ( keyChar == KEY_DOWN ) {
movePromptRowDown( true );
} else if ( keyChar == KEY_PAGEUP ) {
movePromptRowUp( true );
} else if ( keyChar == KEY_PAGEDOWN ) {
movePromptRowDown( false );
} else if ( keyChar == KEY_TAB ) {
tryAddChar( keyChar );
}
if ( setSupportNewLine() ) {
int lPromtpPos = mPromptPos;
if ( keyChar == KEY_END ) {
for ( Uint32 i = mPromptPos; i < mText.size(); i++ ) {
if ( mText[i] == '\n' ) {
setCursorPos( i );
autoPrompt( false );
break;
}
if ( i == ( mText.size() - 1 ) ) {
setCursorPos( mText.size() );
autoPrompt( false );
}
}
shiftSelection( lPromtpPos );
}
if ( keyChar == KEY_HOME ) {
if ( 0 != mPromptPos ) {
for ( Int32 i = (Int32)mPromptPos - 1; i >= 0; i-- ) {
if ( mText[i] == '\n' ) {
setCursorPos( i + 1 );
autoPrompt( false );
break;
}
if ( i == 0 ) {
setCursorPos( 0 );
autoPrompt( false );
}
}
}
shiftSelection( lPromtpPos );
}
} else {
int lPromtpPos = mPromptPos;
if ( keyChar == KEY_END ) {
autoPrompt( true );
shiftSelection( lPromtpPos );
}
if ( keyChar == KEY_HOME ) {
setCursorPos( 0 );
autoPrompt( false );
shiftSelection( lPromtpPos );
}
}
break;
}
}
} else {
if ( Event->Type == InputEvent::TextInput ) {
tryAddChar( Event->text.text );
} else if ( Event->Type == InputEvent::KeyDown ) {
if ( keyChar == KEY_BACKSPACE && mText.size() > 0 ) {
mText.resize( mText.size() - 1 );
} else if ( ( keyChar == KEY_RETURN || keyChar == KEY_KP_ENTER ) &&
!Input->isMetaPressed() && !Input->isAltPressed() &&
!Input->isControlPressed() ) {
if ( setSupportNewLine() && canAdd() )
mText += '\n';
if ( mEnterCall )
mEnterCall();
}
setChangedSinceLastUpdate( true );
onBufferChange();
}
}
}
}
void InputTextBuffer::shiftSelection( const int& lastPromtpPos ) {
if ( !isTextSelectionEnabled() )
return;
Input* Input = mWindow->getInput();
if ( Input->isShiftPressed() && !Input->isControlPressed() ) {
if ( selCurInit() != getCursorPosition() ) {
selCurEnd( getCursorPosition() );
onSelectionChange();
} else {
if ( selCurInit() != getCursorPosition() ) {
selCurInit( getCursorPosition() );
onSelectionChange();
} else {
resetSelection();
return;
}
}
if ( -1 == selCurInit() ) {
selCurInit( lastPromtpPos );
onSelectionChange();
}
if ( -1 == selCurEnd() ) {
selCurEnd( lastPromtpPos );
onSelectionChange();
}
}
}
void InputTextBuffer::movePromptRowDown( const bool& breakit ) {
if ( isFreeEditingEnabled() && setSupportNewLine() ) {
int lPromtpPos = mPromptPos;
Uint32 dNLPos = 0;
getCurPosLinePos( dNLPos );
Uint32 dCharsTo = mPromptPos - dNLPos;
Uint32 dLastLinePos = 0;
Uint32 dCharLineCount = 0;
for ( Uint32 i = mPromptPos; i < mText.size(); i++ ) {
if ( mText[i] == '\n' ) {
if ( breakit ) {
if ( 0 == dLastLinePos ) {
dLastLinePos = i + 1;
dCharLineCount = 0;
} else {
break;
}
} else {
dLastLinePos = i + 1;
dCharLineCount = 0;
}
} else {
dCharLineCount++;
}
}
if ( 0 != dLastLinePos ) {
if ( dCharLineCount < dCharsTo ) {
setCursorPos( dLastLinePos + dCharLineCount );
} else {
setCursorPos( dLastLinePos + dCharsTo );
}
autoPrompt( false );
}
shiftSelection( lPromtpPos );
}
}
void InputTextBuffer::movePromptRowUp( const bool& breakit ) {
if ( isFreeEditingEnabled() && setSupportNewLine() ) {
int lPromtpPos = mPromptPos;
Uint32 uNLPos = 0;
Uint32 uLineNum = getCurPosLinePos( uNLPos );
Uint32 uCharsTo = mPromptPos - uNLPos;
if ( uLineNum >= 1 ) {
Uint32 uLastLinePos = 0;
Uint32 uCharLineCount = 0;
uNLPos = ( uNLPos - 1 );
for ( Uint32 i = 0; i < uNLPos; i++ ) {
if ( mText[i] == '\n' ) {
if ( !breakit ) {
uLastLinePos = i + 1;
uCharLineCount = 0;
} else {
break;
}
} else {
uCharLineCount++;
}
}
if ( uCharLineCount < uCharsTo ) {
setCursorPos( uLastLinePos + uCharLineCount );
} else {
setCursorPos( uLastLinePos + uCharsTo );
}
autoPrompt( false );
}
shiftSelection( lPromtpPos );
}
}
void InputTextBuffer::clear() {
mText.clear();
autoPrompt( true );
}
void InputTextBuffer::setReturnCallback( EnterCallback EC ) {
mEnterCall = EC;
}
void InputTextBuffer::setBuffer( const String& str ) {
if ( mText != str ) {
mText = str;
setChangedSinceLastUpdate( true );
}
}
int InputTextBuffer::getCursorPosition() const {
return mPromptPos;
}
void InputTextBuffer::setCursorPosition( const Uint32& pos ) {
if ( isFreeEditingEnabled() ) {
if ( pos < mText.size() ) {
autoPrompt( false );
}
mPromptPos = pos;
}
}
void InputTextBuffer::setCursorPos( const Uint32& pos ) {
if ( isFreeEditingEnabled() && mPromptPos != (Int32)pos ) {
setCursorPosition( pos );
onCursorPositionChange();
}
}
Uint32 InputTextBuffer::getCurPosLinePos( Uint32& LastNewLinePos ) {
if ( isFreeEditingEnabled() ) {
Uint32 nl = 0;
LastNewLinePos = 0;
for ( int i = 0; i < mPromptPos; i++ ) {
if ( mText[i] == '\n' ) {
nl++;
LastNewLinePos = i + 1;
}
}
return nl;
}
return 0;
}
void InputTextBuffer::pushIgnoredChar( const Uint32& ch ) {
mIgnoredChars.push_back( ch );
}
bool InputTextBuffer::canAdd() {
return mText.size() < mMaxLength;
}
void InputTextBuffer::setMaxLength( const Uint32& Max ) {
mMaxLength = Max;
if ( mText.size() > mMaxLength )
mText.resize( mMaxLength );
}
const Uint32& InputTextBuffer::getMaxLength() const {
return mMaxLength;
}
String InputTextBuffer::getBuffer() const {
return mText;
}
bool InputTextBuffer::changedSinceLastUpdate() {
return 0 != ( mFlags & ( 1 << CHANGE_SINCE_LAST_UPDATE ) );
}
void InputTextBuffer::setChangedSinceLastUpdate( const bool& Changed ) {
BitOp::writeBitKey( &mFlags, CHANGE_SINCE_LAST_UPDATE, Changed == true );
}
void InputTextBuffer::autoPrompt( const bool& set ) {
BitOp::writeBitKey( &mFlags, PROMPT_AUTO_POS, set == true );
if ( set ) {
mPromptPos = (int)mText.size();
onCursorPositionChange();
}
}
bool InputTextBuffer::autoPrompt() {
return 0 != ( mFlags & ( 1 << PROMPT_AUTO_POS ) );
}
bool InputTextBuffer::isActive() const {
return 0 != ( mFlags & ( 1 << ACTIVE ) );
}
void InputTextBuffer::setActive( const bool& active ) {
BitOp::writeBitKey( &mFlags, ACTIVE, active == true );
}
bool InputTextBuffer::setSupportNewLine() {
return 0 != ( mFlags & ( 1 << SUPPORT_NEW_LINE ) );
}
void InputTextBuffer::isNewLineEnabled( const bool& enabled ) {
BitOp::writeBitKey( &mFlags, SUPPORT_NEW_LINE, enabled == true );
}
void InputTextBuffer::setAllowOnlyNumbers( const bool& onlynums, const bool& allowdots ) {
BitOp::writeBitKey( &mFlags, ALLOW_ONLY_NUMBERS, onlynums == true );
BitOp::writeBitKey( &mFlags, ALLOW_DOT_IN_NUMBERS, allowdots == true );
}
bool InputTextBuffer::onlyNumbersAllowed() {
return 0 != ( mFlags & ( 1 << ALLOW_ONLY_NUMBERS ) );
}
bool InputTextBuffer::dotsInNumbersAllowed() {
return 0 != ( mFlags & ( 1 << ALLOW_DOT_IN_NUMBERS ) );
}
bool InputTextBuffer::isFreeEditingEnabled() const {
return 0 != ( mFlags & ( 1 << FREE_EDITING ) );
}
void InputTextBuffer::setFreeEditing( const bool& enabled ) {
BitOp::writeBitKey( &mFlags, FREE_EDITING, enabled == true );
}
void InputTextBuffer::supportCopyPaste( const bool& support ) {
BitOp::writeBitKey( &mFlags, SUPPORT_COPY_PASTE, support == true );
}
bool InputTextBuffer::supportCopyPaste() {
return 0 != ( mFlags & ( 1 << SUPPORT_COPY_PASTE ) );
}
bool InputTextBuffer::isTextSelectionEnabled() {
return 0 != ( mFlags & ( 1 << TEXT_SELECTION_ENABLED ) );
}
void InputTextBuffer::setTextSelectionEnabled( const bool& enabled ) {
BitOp::writeBitKey( &mFlags, TEXT_SELECTION_ENABLED, enabled == true );
}
void InputTextBuffer::cursorToEnd() {
setCursorPos( mText.size() );
}
void InputTextBuffer::selCurInit( const Int32& init ) {
mSelCurInit = init;
}
void InputTextBuffer::selCurEnd( const Int32& end ) {
mSelCurEnd = end;
}
const Int32& InputTextBuffer::selCurInit() const {
return mSelCurInit;
}
const Int32& InputTextBuffer::selCurEnd() const {
return mSelCurEnd;
}
void InputTextBuffer::setCursorPositionChangeCallback(
const CursorPositionChangeCallback& cursorPositionChangeCallback ) {
mCursorPositionChangeCallback = cursorPositionChangeCallback;
}
void InputTextBuffer::setBufferChangeCallback( const BufferChangeCallback& bufferChangeCallback ) {
mBufferChangeCallback = bufferChangeCallback;
}
void InputTextBuffer::setSelectionChangeCallback(
const SelectionChangeCallback& selectionChangeCallback ) {
mSelectionChangeCallback = selectionChangeCallback;
}
void InputTextBuffer::selectAll() {
selCurInit( 0 );
selCurEnd( mText.size() );
setCursorPos( mSelCurEnd );
onSelectionChange();
}
void InputTextBuffer::onCursorPositionChange() {
if ( mCursorPositionChangeCallback ) {
mCursorPositionChangeCallback();
}
}
void InputTextBuffer::onSelectionChange() {
if ( mSelectionChangeCallback ) {
mSelectionChangeCallback();
}
}
void InputTextBuffer::onBufferChange() {
if ( mBufferChangeCallback ) {
mBufferChangeCallback();
}
}
}} // namespace EE::Window

View File

@@ -106,7 +106,6 @@ const std::vector<Color>& TerminalColorScheme::getPalette() const {
}
const Color& TerminalColorScheme::getPaletteIndex( const size_t& index ) const {
eeASSERT( index < mPalette.size() );
return mPalette[index];
}

View File

@@ -9,6 +9,7 @@
#include <eterm/system/processfactory.hpp>
#include <eterm/terminal/boxdrawdata.hpp>
#include <eterm/terminal/terminaldisplay.hpp>
#include <limits.h>
namespace eterm { namespace Terminal {

View File

@@ -262,9 +262,6 @@ void EETest::onFontLoaded() {
eeASSERT( TTF != NULL );
eeASSERT( monospace != NULL );
Con.create( monospace, true );
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á "
@@ -273,6 +270,10 @@ void EETest::onFontLoaded() {
"el mar en tu cabeza, que es un balde." );
createUI();
Con = UIConsole::NewOpt( monospace, true, true, 8191 );
Con->setQuakeMode( true );
Con->setVisible( false );
Con->addCommand( "setparticlesnum", cb::Make1( this, &EETest::cmdSetPartsNum ) );
mEEText.create( TTF, "Entropia Engine++\nCTRL + Number to change Demo Screen\nRight click to "
"see the PopUp Menu" );
@@ -1196,13 +1197,7 @@ void EETest::onItemClick( const Event* event ) {
} else if ( "Show Screen 6" == txt ) {
setScreen( 5 );
} else if ( "Show Console" == txt ) {
Con.toggle();
if ( Con.isActive() ) {
mWindow->startTextInput();
} else {
mWindow->stopTextInput();
}
Con->toggle();
} else if ( "Show Window" == txt ) {
UIMenuCheckBox* Chk = event->getNode()->asType<UIMenuCheckBox>();
@@ -1335,9 +1330,9 @@ void EETest::cmdSetPartsNum( const std::vector<String>& params ) {
PS[2].create( ParticleEffect::WormHole, tInt, TN[5],
Vector2f( mWindow->getWidth() * 0.5f, mWindow->getHeight() * 0.5f ), 32,
true );
Con.pushText( "Wormhole Particles Number Changed to: " + String::toString( tInt ) );
Con->pushText( "Wormhole Particles Number Changed to: " + String::toString( tInt ) );
} else
Con.pushText( "Valid parameters are between 0 and 100000 (0 = no limit)." );
Con->pushText( "Valid parameters are between 0 and 100000 (0 = no limit)." );
}
}
@@ -1434,8 +1429,6 @@ void EETest::loadTextures() {
PS[3].create( ParticleEffect::Fire, 350, TN[5], Vector2f( -50.f, -50.f ), 32, true );
PS[4].create( ParticleEffect::Fire, 350, TN[5], Vector2f( -50.f, -50.f ), 32, true );
Con.addCommand( "setparticlesnum", cb::Make1( this, &EETest::cmdSetPartsNum ) );
Texture* Tex = TNP[2];
if ( NULL != Tex && Tex->lock() ) {
@@ -1914,7 +1907,6 @@ void EETest::render() {
mInfoText.draw( 6.f, 6.f );
SceneManager::instance()->draw();
Con.draw();
}
void EETest::input() {
@@ -1976,7 +1968,7 @@ void EETest::input() {
if ( KM->isAltPressed() && KM->isKeyUp( KEY_C ) )
mWindow->centerToDisplay();
if ( KM->isAltPressed() && KM->isKeyUp( KEY_M ) && !Con.isActive() ) {
if ( KM->isAltPressed() && KM->isKeyUp( KEY_M ) && !Con->isActive() ) {
if ( !mWindow->isMaximized() )
mWindow->maximize();
}
@@ -2001,7 +1993,7 @@ void EETest::input() {
KM->grabInput( !KM->grabInput() );
if ( KM->isKeyUp( KEY_F3 ) || KM->isKeyUp( KEY_BACKSLASH ) ) {
Con.toggle();
Con->toggle();
}
if ( KM->isKeyUp( KEY_1 ) && KM->isControlPressed() )

View File

@@ -69,7 +69,7 @@ class EETest : private Thread {
bool DrawBack;
Console Con;
UIConsole* Con;
virtual void run();
Vector2f Point;

View File

@@ -64,7 +64,7 @@ std::string basePath;
Vector2i mousePos;
Clock mouseClock;
Console* console = NULL;
UIConsole* console = NULL;
std::map<std::string, std::string> layouts;
std::vector<std::string> recentProjects;
@@ -789,17 +789,13 @@ void mainLoop() {
refreshStyleSheet();
}
Time elapsed = SceneManager::instance()->getElapsed();
SceneManager::instance()->update();
if ( appUiSceneNode->invalidated() || uiSceneNode->invalidated() || console->isActive() ||
console->isFading() ) {
if ( appUiSceneNode->invalidated() || uiSceneNode->invalidated() ) {
window->clear();
SceneManager::instance()->draw();
console->draw( elapsed );
window->display();
} else {
Sys::sleep( Milliseconds( 8 ) );
@@ -919,6 +915,10 @@ void createAppMenu() {
uiMenuBar->addMenuButton( "Resources", uiResourceMenu );
uiResourceMenu->addEventListener( Event::OnItemClicked, cb::Make1( fileMenuClick ) );
console = UIConsole::New();
console->setQuakeMode( true );
console->setVisible( false );
SceneManager::instance()->setCurrentUISceneNode( uiSceneNode );
}
@@ -1027,10 +1027,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
FontTrueType* font =
FontTrueType::New( "NotoSans-Regular", resPath + "assets/fonts/NotoSans-Regular.ttf" );
FontTrueType* fontMono =
FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" );
console = eeNew( Console, ( fontMono, true, true, 1024 * 1000, 0, window ) );
FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" );
theme = UITheme::load( "uitheme" + pd, "uitheme" + pd,
resPath + "assets/ui/uitheme" + pd + ".eta", font,