diff --git a/include/eepp/ui/doc/textdocument.hpp b/include/eepp/ui/doc/textdocument.hpp index 3e803a3fb..fd54adf29 100644 --- a/include/eepp/ui/doc/textdocument.hpp +++ b/include/eepp/ui/doc/textdocument.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -18,6 +19,8 @@ namespace EE { namespace UI { namespace Doc { class EE_API TextDocumentLine { public: + typedef std::function DocumentCommand; + TextDocumentLine( const String& text ) : mText( text ) { updateHash(); } void setText( const String& text ) { @@ -159,6 +162,8 @@ class EE_API TextDocument { TextPosition endOfLine( TextPosition position ) const; + TextPosition startOfContent( TextPosition position ); + TextPosition startOfDoc() const; TextPosition endOfDoc() const; @@ -207,6 +212,8 @@ class EE_API TextDocument { void moveToEndOfLine(); + void moveToStartOfContent(); + void deleteToPreviousChar(); void deleteToNextChar(); @@ -233,18 +240,30 @@ class EE_API TextDocument { void selectToEndOfLine(); + void selectToStartOfDoc(); + + void selectToEndOfDoc(); + void selectToPreviousPage( Int64 pageSize ); void selectToNextPage( Int64 pageSize ); + void selectToStartOfContent(); + void selectAll(); void newLine(); + void newLineAbove(); + void indent(); void unindent(); + void moveLinesUp(); + + void moveLinesDown(); + String getIndentString(); const Uint32& getTabWidth() const; @@ -311,6 +330,8 @@ class EE_API TextDocument { UndoStackContainer& undoStack, const Time& time ); TextPosition insert( TextPosition position, const String::StringBaseType& text ); + + void appendLineIfLastLine( Int64 line ); }; }}} // namespace EE::UI::Doc diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 02f3fab52..5a8ee19a6 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -108,7 +108,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { bool isDirty() const; - virtual Int64 getColFromXOffset( Int64 line, const Float& offset ) const; + virtual Int64 getColFromXOffset( Int64 line, const Float& x ) const; virtual Float getColXOffset( TextPosition position ); diff --git a/include/eepp/ui/uieventdispatcher.hpp b/include/eepp/ui/uieventdispatcher.hpp index 5e8cabc2f..00f5fcf0e 100644 --- a/include/eepp/ui/uieventdispatcher.hpp +++ b/include/eepp/ui/uieventdispatcher.hpp @@ -12,6 +12,8 @@ class UIEventDispatcher : public EventDispatcher { UIEventDispatcher( SceneNode* sceneNode ); + const bool& justGainedFocus() const; + protected: bool mJustGainedFocus; diff --git a/include/eepp/window/displaymanager.hpp b/include/eepp/window/displaymanager.hpp index 17af78061..b99d20b39 100644 --- a/include/eepp/window/displaymanager.hpp +++ b/include/eepp/window/displaymanager.hpp @@ -50,6 +50,10 @@ class EE_API DisplayManager { virtual void disableScreenSaver(); + virtual void enableMouseFocusClickThrough(); + + virtual void disableMouseFocusClickThrough(); + virtual ~DisplayManager(); protected: diff --git a/include/eepp/window/input.hpp b/include/eepp/window/input.hpp index 25ace3c0e..f818a6eca 100644 --- a/include/eepp/window/input.hpp +++ b/include/eepp/window/input.hpp @@ -188,7 +188,10 @@ class EE_API Input { /** @return A list of the input finders that were down in the last update */ std::list getFingersWasDown(); - protected: + /** @return the state of the mod keys. */ + const Uint32& getKeyMod() const; + + protected: friend class Window; Input( EE::Window::Window* window, JoystickManager* joystickmanager ); diff --git a/include/eepp/window/window.hpp b/include/eepp/window/window.hpp index e309b2871..26c8c58ba 100644 --- a/include/eepp/window/window.hpp +++ b/include/eepp/window/window.hpp @@ -425,6 +425,7 @@ class EE_API Window { ** @param fps The desired FPS ( 0 = infinite ) */ void runMainLoop( void ( *func )(), int fps = 0 ); + /** @return The current display index. */ virtual int getCurrentDisplayIndex(); Vector2f mapPixelToCoords( const Vector2i& point ); diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index ce8b3d143..559cb2f35 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -334,6 +334,13 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { {"char8_t", "keyword2"}, {"char16_t", "keyword2"}, {"char32_t", "keyword2"}, + {"size_t", "keyword2"}, + {"int16_t", "keyword2"}, + {"int32_t", "keyword2"}, + {"int64_t", "keyword2"}, + {"uint16_t", "keyword2"}, + {"uint32_t", "keyword2"}, + {"uint64_t", "keyword2"}, {"NULL", "literal"}, }, "//"} ); @@ -353,48 +360,474 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { {{"[%a_][%w_]*"}, "symbol"}, {{"%$[%a][%w_]*"}, "keyword2"}, }, + {{"return", "keyword"}, {"if", "keyword"}, + {"else", "keyword"}, {"elseif", "keyword"}, + {"endif", "keyword"}, {"declare", "keyword"}, + {"enddeclare", "keyword"}, {"switch", "keyword"}, + {"endswitch", "keyword"}, {"as", "keyword"}, + {"do", "keyword"}, {"for", "keyword"}, + {"endfor", "keyword"}, {"foreach", "keyword"}, + {"endforeach", "keyword"}, {"while", "keyword"}, + {"endwhile", "keyword"}, {"switch", "keyword"}, + {"case", "keyword"}, {"continue", "keyword"}, + {"default", "keyword"}, {"break", "keyword"}, + {"exit", "keyword"}, {"goto", "keyword"}, + + {"catch", "keyword"}, {"throw", "keyword"}, + {"try", "keyword"}, {"finally", "keyword"}, + + {"class", "keyword"}, {"trait", "keyword"}, + {"interface", "keyword"}, {"public", "keyword"}, + {"static", "keyword"}, {"protected", "keyword"}, + {"private", "keyword"}, {"abstract", "keyword"}, + {"final", "keyword"}, + + {"function", "keyword2"}, {"global", "keyword2"}, + {"var", "keyword2"}, {"const", "keyword2"}, + {"bool", "keyword2"}, {"boolean", "keyword2"}, + {"int", "keyword2"}, {"integer", "keyword2"}, + {"real", "keyword2"}, {"double", "keyword2"}, + {"float", "keyword2"}, {"string", "keyword2"}, + {"array", "keyword2"}, {"object", "keyword2"}, + {"callable", "keyword2"}, {"iterable", "keyword2"}, + + {"namespace", "keyword2"}, {"extends", "keyword2"}, + {"implements", "keyword2"}, {"instanceof", "keyword2"}, + {"require", "keyword2"}, {"require_once", "keyword2"}, + {"include", "keyword2"}, {"include_once", "keyword2"}, + {"use", "keyword2"}, {"new", "keyword2"}, + {"clone", "keyword2"}, + + {"true", "literal"}, {"false", "literal"}, + {"NULL", "literal"}, {"parent", "literal"}, + {"self", "literal"}, {"echo", "function"}}, + "//"} ); + + // Add SQL + std::vector keywords = { + "CREATE", "SELECT", "INSERT", "INTO", "UPDATE", "DELETE", + "TABLE", "DROP", "VALUES", "NOT", "NULL", "PRIMARY", + "KEY", "REFERENCES", "DEFAULT", "UNIQUE", "CONSTRAINT", "CHECK", + "ON", "EXCLUDE", "WITH", "USING", "WHERE", "GROUP", + "BY", "HAVING", "DISTINCT", "LIMIT", "OFFSET", "ONLY", + "CROSS", "JOIN", "INNER", "LEFT", "RIGHT", "FULL", + "OUTER", "NATURAL", "AND", "OR", "AS", "ORDER", + "ORDINALITY", "UNNEST", "FROM", "VIEW", "RETURNS", "SETOF", + "LANGUAGE", "SQL", "LIKE", "LATERAL", "INTERVAL", "PARTITION", + "UNION", "INTERSECT", "EXCEPT", "ALL", "ASC", "DESC", + "NULLS", "FIRST", "LAST", "IN", "RECURSIVE", "ARRAY", + "RETURNING", "SET", "ALSO", "INSTEAD", "ALTER", "SEQUENCE", + "OWNED", "AT", "ZONE", "WITHOUT", "TO", "TIMEZONE", + "TYPE", "ENUM", "DOCUMENT", "XMLPARSE", "XMLSERIALIZE", "CONTENT", + "OPTION", "INDEX", "ANY", "EXTENSION", "ISNULL", "NOTNULL", + "UNKNOWN", "CASE", "THEN", "WHEN", "ELSE", "END", + "ROWS", "BETWEEN", "UNBOUNDED", "PRECEDING", "UNBOUNDED", "FOLLOWING", + "EXISTS", "SOME", "COLLATION", "FOR", "TRIGGER", "BEFORE", + "EACH", "ROW", "EXECUTE", "PROCEDURE", "FUNCTION", "DECLARE", + "BEGIN", "LOOP", "RAISE", "NOTICE", "LOOP", "EVENT", + "OPERATOR", "DOMAIN", "VARIADIC", "FOREIGN"}; + + std::vector types = { + "BIGINT", "INT8", "BIGSERIAL", "SERIAL8", "BIT", "VARBIT", + "BOOLEAN", "BOOL", "BOX", "BYTEA", "CHARACTER", "CHAR", + "VARCHAR", "CIDR", "CIRCLE", "DATE", "DOUBLE", "PRECISION", + "FLOAT8", "INET", "INTEGER", "INT", "INT4", "INTERVAL", + "JSON", "JSONB", "LINE", "LSEG", "MACADDR", "MONEY", + "NUMERIC", "DECIMAL", "PATH", "POINT", "POLYGON", "REAL", + "FLOAT4", "INT2", "SMALLINT", "SMALLSERIAL", "SERIAL2", "SERIAL", + "SERIAL4", "TEXT", "TIME", "TIMEZ", "TIMESTAMP", "TIMESTAMPZ", + "TSQUERY", "TSVECTOR", "TXID_SNAPSHOT", "UUID", "XML", "INT4RANGE", + "INT8RANGE", "NUMRANGE", "TSRANGE", "TSTZRANGE", "DATERANGE", "PG_LSN"}; + + std::vector literals = {"FALSE", "TRUE", "CURRENT_TIMESTAMP", + "CURRENT_TIME", "CURRENT_DATE", "LOCALTIME", + "LOCALTIMESTAMP"}; + + std::unordered_map symbols; + for ( auto& keyword : keywords ) { + symbols[String::toLower( keyword )] = "keyword"; + symbols[keyword] = "keyword"; + } + + for ( auto& type : types ) { + symbols[String::toLower( type )] = "keyword2"; + symbols[type] = "keyword2"; + } + + for ( auto& literal : literals ) { + symbols[String::toLower( literal )] = "literal"; + symbols[literal] = "literal"; + } + + add( {{"%.sql$", "%.psql$"}, { - {"return", "keyword"}, {"if", "keyword"}, - {"else", "keyword"}, {"elseif", "keyword"}, - {"endif", "keyword"}, {"declare", "keyword"}, - {"enddeclare", "keyword"}, {"switch", "keyword"}, - {"endswitch", "keyword"}, {"as", "keyword"}, - {"do", "keyword"}, {"for", "keyword"}, - {"endfor", "keyword"}, {"foreach", "keyword"}, - {"endforeach", "keyword"}, {"while", "keyword"}, - {"endwhile", "keyword"}, {"switch", "keyword"}, - {"case", "keyword"}, {"continue", "keyword"}, - {"default", "keyword"}, {"break", "keyword"}, - {"exit", "keyword"}, {"goto", "keyword"}, + {{"%-%-.-\n"}, "comment"}, + {{"/%*", "%*/"}, "comment"}, + {{"'", "'", "\\"}, "string"}, + {{"-?%d+[%d%.eE]*f?"}, "number"}, + {{"-?%.?%d+f?"}, "number"}, + {{"[%+%-=/%*%%<>!~|&@%?$#]"}, "operator"}, + {{"[%a_][%w_]*%f[(]"}, "function"}, + {{"[%a_][%w_]*"}, "symbol"}, + }, + symbols, + "--"} ); - {"catch", "keyword"}, {"throw", "keyword"}, - {"try", "keyword"}, {"finally", "keyword"}, - - {"class", "keyword"}, {"trait", "keyword"}, - {"interface", "keyword"}, {"public", "keyword"}, - {"static", "keyword"}, {"protected", "keyword"}, - {"private", "keyword"}, {"abstract", "keyword"}, - {"final", "keyword"}, - - {"function", "keyword2"}, {"global", "keyword2"}, - {"var", "keyword2"}, {"const", "keyword2"}, - {"bool", "keyword2"}, {"boolean", "keyword2"}, - {"int", "keyword2"}, {"integer", "keyword2"}, - {"real", "keyword2"}, {"double", "keyword2"}, - {"float", "keyword2"}, {"string", "keyword2"}, - {"array", "keyword2"}, {"object", "keyword2"}, - {"callable", "keyword2"}, {"iterable", "keyword2"}, - - {"namespace", "keyword2"}, {"extends", "keyword2"}, - {"implements", "keyword2"}, {"instanceof", "keyword2"}, - {"require", "keyword2"}, {"require_once", "keyword2"}, - {"include", "keyword2"}, {"include_once", "keyword2"}, - {"use", "keyword2"}, {"new", "keyword2"}, - {"clone", "keyword2"}, - - {"true", "literal"}, {"false", "literal"}, - {"NULL", "literal"}, {"parent", "literal"}, - {"self", "literal"}, + // GLSL + add( {{"%.glsl$", "%.frag$", "%.vert$"}, + { + {{"//.-\n"}, "comment"}, + {{"/%*", "%*/"}, "comment"}, + {{"#", "[^\\]\n"}, "comment"}, + {{"\"", "\"", "\\"}, "string"}, + {{"'", "'", "\\"}, "string"}, + {{"-?0x%x+"}, "number"}, + {{"-?%d+[%d%.eE]*f?"}, "number"}, + {{"-?%.?%d+f?"}, "number"}, + {{"[%+%-=/%*%^%%<>!~|&]"}, "operator"}, + {{"ivec[2-4]"}, "keyword2"}, + {{"bvec[2-4]"}, "keyword2"}, + {{"uvec[2-4]"}, "keyword2"}, + {{"vec[2-4]"}, "keyword2"}, + {{"dmat[2-4]x[2-4]"}, "keyword2"}, + {{"dmat[2-4]"}, "keyword2"}, + {{"mat[2-4]x[2-4]"}, "keyword2"}, + {{"mat[2-4]"}, "keyword2"}, + {{"[%a_][%w_]*%f[(]"}, "function"}, + {{"[%a_][%w_]*"}, "symbol"}, + }, + { + {"if", "keyword"}, + {"else", "keyword"}, + {"do", "keyword"}, + {"while", "keyword"}, + {"for", "keyword"}, + {"break", "keyword"}, + {"continue", "keyword"}, + {"return", "keyword"}, + {"const", "keyword"}, + {"switch", "keyword"}, + {"case", "keyword"}, + {"default", "keyword"}, + {"const", "keyword"}, + {"void", "keyword"}, + {"bool", "keyword2"}, + {"int", "keyword2"}, + {"uint", "keyword2"}, + {"float", "keyword2"}, + {"double", "keyword2"}, + {"true", "literal"}, + {"false", "literal"}, + {"NULL", "literal"}, + {"attribute", "keyword"}, + {"varying", "keyword"}, + {"uniform", "keyword"}, + {"buffer", "keyword"}, + {"shared", "keyword"}, + {"layout", "keyword"}, + {"centroid", "keyword"}, + {"flat", "keyword"}, + {"smooth", "keyword"}, + {"noperspective", "keyword"}, + {"patch", "keyword"}, + {"sample", "keyword"}, + {"in", "keyword"}, + {"out", "keyword"}, + {"inout", "keyword"}, + {"invariant", "keyword"}, + {"precise", "keyword"}, + {"lowp", "keyword"}, + {"mediump", "keyword"}, + {"highp", "keyword"}, + {"precision", "keyword"}, + {"struct", "keyword"}, + {"subroutine", "keyword"}, + {"coherent", "keyword"}, + {"volatile", "keyword"}, + {"readonly", "keyword"}, + {"writeonly", "keyword"}, + {"sampler1D", "keyword2"}, + {"sampler2D", "keyword2"}, + {"sampler3D", "keyword2"}, + {"samplerCube", "keyword2"}, + {"sampler1DShadow", "keyword2"}, + {"sampler2DShadow", "keyword2"}, + {"samplerCubeShadow", "keyword2"}, + {"sampler1DArray", "keyword2"}, + {"sampler2DArray", "keyword2"}, + {"samplerCubeArray", "keyword2"}, + {"sampler1DArrayShadow", "keyword2"}, + {"sampler2DArrayShadow", "keyword2"}, + {"samplerCubeArrayShadow", "keyword2"}, + {"isampler1D", "keyword2"}, + {"isampler2D", "keyword2"}, + {"isampler3D", "keyword2"}, + {"isamplerCube", "keyword2"}, + {"sampler2DMS", "keyword2"}, + {"isampler2DMS", "keyword2"}, + {"usampler2DMS", "keyword2"}, + {"sampler2DMSArray", "keyword2"}, + {"isampler2DMSArray", "keyword2"}, + {"usampler2DMSArray", "keyword2"}, + {"isampler1DArray", "keyword2"}, + {"isampler2DArray", "keyword2"}, + {"usampler1D", "keyword2"}, + {"usampler2D", "keyword2"}, + {"usampler3D", "keyword2"}, + {"usamplerCube", "keyword2"}, + {"usampler1DArray", "keyword2"}, + {"usampler2DArray", "keyword2"}, + {"sampler2DRect", "keyword2"}, + {"sampler2DRectShadow", "keyword2"}, + {"isampler2DRect", "keyword2"}, + {"usampler2DRect", "keyword2"}, + {"samplerBuffer", "keyword2"}, + {"isamplerBuffer", "keyword2"}, + {"usamplerBuffer", "keyword2"}, + {"image1D", "keyword2"}, + {"iimage1D", "keyword2"}, + {"uimage1D", "keyword2"}, + {"image1DArray", "keyword2"}, + {"iimage1DArray", "keyword2"}, + {"uimage1DArray", "keyword2"}, + {"image2D", "keyword2"}, + {"iimage2D", "keyword2"}, + {"uimage2D", "keyword2"}, + {"image2DArray", "keyword2"}, + {"iimage2DArray", "keyword2"}, + {"uimage2DArray", "keyword2"}, + {"image2DRect", "keyword2"}, + {"iimage2DRect", "keyword2"}, + {"uimage2DRect", "keyword2"}, + {"image2DMS", "keyword2"}, + {"iimage2DMS", "keyword2"}, + {"uimage2DMS", "keyword2"}, + {"image2DMSArray", "keyword2"}, + {"iimage2DMSArray", "keyword2"}, + {"uimage2DMSArray", "keyword2"}, + {"image3D", "keyword2"}, + {"iimage3D", "keyword2"}, + {"uimage3D", "keyword2"}, + {"imageCube", "keyword2"}, + {"iimageCube", "keyword2"}, + {"uimageCube", "keyword2"}, + {"imageCubeArray", "keyword2"}, + {"iimageCubeArray", "keyword2"}, + {"uimageCubeArray", "keyword2"}, + {"imageBuffer", "keyword2"}, + {"iimageBuffer", "keyword2"}, + {"uimageBuffer", "keyword2"}, + {"atomic_uint", "keyword2"}, + {"radians", "keyword"}, + {"degrees", "keyword"}, + {"sin", "keyword"}, + {"cos", "keyword"}, + {"tan", "keyword"}, + {"asin", "keyword"}, + {"acos", "keyword"}, + {"atan", "keyword"}, + {"sinh", "keyword"}, + {"cosh", "keyword"}, + {"tanh", "keyword"}, + {"asinh", "keyword"}, + {"acosh", "keyword"}, + {"pow", "keyword"}, + {"exp", "keyword"}, + {"exp2", "keyword"}, + {"log2", "keyword"}, + {"sqrt", "keyword"}, + {"inversesqrt", "keyword"}, + {"abs", "keyword"}, + {"sign", "keyword"}, + {"floor", "keyword"}, + {"trunc", "keyword"}, + {"round", "keyword"}, + {"roundEven", "keyword"}, + {"ceil", "keyword"}, + {"fract", "keyword"}, + {"mod", "keyword"}, + {"modf", "keyword"}, + {"min", "keyword"}, + {"max", "keyword"}, + {"clamp", "keyword"}, + {"mix", "keyword"}, + {"step", "keyword"}, + {"smoothstep", "keyword"}, + {"isnan", "keyword"}, + {"isinf", "keyword"}, + {"floatBitsToInt", "keyword"}, + {"floatBitsToUint", "keyword"}, + {"intBitsToFloat", "keyword"}, + {"uintBitsToFloat", "keyword"}, + {"fma", "keyword"}, + {"frexp", "keyword"}, + {"ldexp", "keyword"}, + {"packUnorm2x16", "keyword"}, + {"packSnorm2x16", "keyword"}, + {"packUnorm4x8", "keyword"}, + {"packSnorm4x8", "keyword"}, + {"unpackUnorm2x16", "keyword"}, + {"unpackSnorm2x16", "keyword"}, + {"unpackUnorm4x8", "keyword"}, + {"unpackSnorm4x8", "keyword"}, + {"packHalf2x16", "keyword"}, + {"unpackHalf2x16", "keyword"}, + {"packDouble2x32", "keyword"}, + {"unpackDouble2x32", "keyword"}, + {"length", "keyword"}, + {"distance", "keyword"}, + {"dot", "keyword"}, + {"cross", "keyword"}, + {"normalize", "keyword"}, + {"ftransform", "keyword"}, + {"faceforward", "keyword"}, + {"reflect", "keyword"}, + {"refract", "keyword"}, + {"matrixCompMult", "keyword"}, + {"outerProduct", "keyword"}, + {"transpose", "keyword"}, + {"determinant", "keyword"}, + {"inverse", "keyword"}, + {"lessThan", "keyword"}, + {"lessThanEqual", "keyword"}, + {"greaterThan", "keyword"}, + {"greaterThanEqual", "keyword"}, + {"equal", "keyword"}, + {"notEqual", "keyword"}, + {"any", "keyword"}, + {"all", "keyword"}, + {"not", "keyword"}, + {"uaddCarry", "keyword"}, + {"usubBorrow", "keyword"}, + {"umulExtended", "keyword"}, + {"imulExtended", "keyword"}, + {"bitfieldExtract", "keyword"}, + {"bitfieldInsert", "keyword"}, + {"bitfieldReverse", "keyword"}, + {"bitCount", "keyword"}, + {"findLSB", "keyword"}, + {"findMSB", "keyword"}, + {"textureSize", "keyword"}, + {"textureQueryLod", "keyword"}, + {"textureQueryLevels", "keyword"}, + {"textureSamples", "keyword"}, + {"texture", "keyword"}, + {"textureProj", "keyword"}, + {"textureLod", "keyword"}, + {"textureOffset", "keyword"}, + {"texelFetch", "keyword"}, + {"texelFetchOffset", "keyword"}, + {"textureProjOffset", "keyword"}, + {"textureLodOffset", "keyword"}, + {"textureProjLod", "keyword"}, + {"textureProjLodOffset", "keyword"}, + {"textureGrad", "keyword"}, + {"textureGradOffset", "keyword"}, + {"textureProjGrad", "keyword"}, + {"textureProjGradOffset", "keyword"}, + {"textureGather", "keyword"}, + {"textureGatherOffset", "keyword"}, + {"textureGatherOffsets", "keyword"}, + {"atomicCounterIncrement", "keyword"}, + {"atomicCounterDecrement", "keyword"}, + {"atomicCounter", "keyword"}, + {"atomicCounterAdd", "keyword"}, + {"atomicCounterSubtract", "keyword"}, + {"atomicCounterMin", "keyword"}, + {"atomicCounterMax", "keyword"}, + {"atomicCounterAnd", "keyword"}, + {"atomicCounterOr", "keyword"}, + {"atomicCounterXor", "keyword"}, + {"atomicCounterExchange", "keyword"}, + {"atomicCounterCompSwap", "keyword"}, + {"atomicAdd", "keyword"}, + {"atomicMin", "keyword"}, + {"atomicMax", "keyword"}, + {"atomicAnd", "keyword"}, + {"atomicOr", "keyword"}, + {"atomicXor", "keyword"}, + {"atomicExchange", "keyword"}, + {"atomicCompSwap", "keyword"}, + {"imageSize", "keyword"}, + {"imageSamples", "keyword"}, + {"imageLoad", "keyword"}, + {"imageStore", "keyword"}, + {"imageAtomicAdd", "keyword"}, + {"imageAtomicMin", "keyword"}, + {"imageAtomicMax", "keyword"}, + {"imageAtomicAnd", "keyword"}, + {"imageAtomicOr", "keyword"}, + {"imageAtomicXor", "keyword"}, + {"imageAtomicExchange", "keyword"}, + {"imageAtomicCompSwap", "keyword"}, + {"EmitStreamVertex", "keyword"}, + {"EndStreamPrimitive", "keyword"}, + {"EmitVertex", "keyword"}, + {"EndPrimitive", "keyword"}, + {"dFdx", "keyword"}, + {"dFdy", "keyword"}, + {"dFdxFine", "keyword"}, + {"dFdyFine", "keyword"}, + {"dFdxCoarse", "keyword"}, + {"dFdyCoarse", "keyword"}, + {"fwidth", "keyword"}, + {"fwidthFine", "keyword"}, + {"fwidthCoarse", "keyword"}, + {"interpolateAtCentroid", "keyword"}, + {"interpolateAtSample", "keyword"}, + {"interpolateAtOffset", "keyword"}, + {"barrier", "keyword"}, + {"memoryBarrier", "keyword"}, + {"memoryBarrierAtomicCounter", "keyword"}, + {"memoryBarrierBuffer", "keyword"}, + {"memoryBarrierShared", "keyword"}, + {"memoryBarrierImage", "keyword"}, + {"groupMemoryBarrier", "keyword"}, + {"subpassLoad", "keyword"}, + {"anyInvocation", "keyword"}, + {"allInvocations", "keyword"}, + {"allInvocationsEqual", "keyword"}, + {"texture1D", "keyword"}, + {"texture1DArray", "keyword"}, + {"itexture1D", "keyword"}, + {"itexture1DArray", "keyword"}, + {"utexture1D", "keyword"}, + {"utexture1DArray", "keyword"}, + {"texture2D", "keyword"}, + {"texture2DArray", "keyword"}, + {"itexture2D", "keyword"}, + {"itexture2DArray", "keyword"}, + {"utexture2D", "keyword"}, + {"utexture2DArray", "keyword"}, + {"texture2DRect", "keyword"}, + {"itexture2DRect", "keyword"}, + {"utexture2DRect", "keyword"}, + {"texture2DMS", "keyword"}, + {"itexture2DMS", "keyword"}, + {"utexture2DMS", "keyword"}, + {"texture2DMSArray", "keyword"}, + {"itexture2DMSArray", "keyword"}, + {"utexture2DMSArray", "keyword"}, + {"texture3D", "keyword"}, + {"itexture3D", "keyword"}, + {"utexture3D", "keyword"}, + {"textureCube", "keyword"}, + {"itextureCube", "keyword"}, + {"utextureCube", "keyword"}, + {"textureCubeArray", "keyword"}, + {"itextureCubeArray", "keyword"}, + {"utextureCubeArray", "keyword"}, + {"textureBuffer", "keyword"}, + {"itextureBuffer", "keyword"}, + {"utextureBuffer", "keyword"}, + {"sampler", "keyword2"}, + {"samplerShadow", "keyword2"}, + {"subpassInput", "keyword2"}, + {"isubpassInput", "keyword2"}, + {"usubpassInput", "keyword2"}, + {"subpassInputMS", "keyword2"}, + {"isubpassInputMS", "keyword2"}, + {"usubpassInputMS", "keyword2"}, }, "//"} ); } diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 4e4ae5daf..2e0c8e3bd 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -41,6 +41,10 @@ void TextDocument::reset() { } void TextDocument::loadFromPath( const std::string& path ) { + if ( !FileSystem::fileExists( path ) ) { + eePRINTL( "File \"%s\" does not exists. Creating a new file.", path.c_str() ); + } + Clock clock; reset(); mLines.clear(); mFilePath = path; @@ -70,6 +74,8 @@ void TextDocument::loadFromPath( const std::string& path ) { } else if ( mLines[mLines.size() - 1][mLines[mLines.size() - 1].size() - 1] != '\n' ) { mLines[mLines.size() - 1].append( '\n' ); } + eePRINTL( "Document \"%s\" loaded in %.2fms.", path.c_str(), + clock.getElapsedTime().asMilliseconds() ); } bool TextDocument::save( const std::string& path, const bool& utf8bom ) { @@ -435,6 +441,21 @@ TextPosition TextDocument::endOfLine( TextPosition position ) const { return TextPosition( position.line(), mLines[position.line()].size() - 1 ); } +TextPosition TextDocument::startOfContent( TextPosition start ) { + start = sanitizePosition( start ); + const String& ln = line( start.line() ).getText(); + size_t to = start.column(); + int indent = 0; + for ( size_t i = 0; i < to; i++ ) { + if ( '\t' == ln[i] || ' ' == ln[i] ) { + indent++; + } else { + break; + } + } + return {start.line(), indent}; +} + TextPosition TextDocument::startOfDoc() const { return TextPosition( 0, 0 ); } @@ -498,8 +519,7 @@ void TextDocument::unregisterClient( TextDocument::Client& client ) { void TextDocument::moveToPreviousChar() { if ( hasSelection() ) { - TextRange selection = getSelection( true ); - setSelection( selection.end() ); + setSelection( getSelection( true ).start() ); } else { setSelection( positionOffset( getSelection().start(), -1 ) ); } @@ -507,8 +527,7 @@ void TextDocument::moveToPreviousChar() { void TextDocument::moveToNextChar() { if ( hasSelection() ) { - TextRange selection = getSelection( true ); - setSelection( selection.start() ); + setSelection( getSelection( true ).end() ); } else { setSelection( positionOffset( getSelection().start(), 1 ) ); } @@ -516,8 +535,7 @@ void TextDocument::moveToNextChar() { void TextDocument::moveToPreviousWord() { if ( hasSelection() ) { - TextRange selection = getSelection( true ); - setSelection( selection.end() ); + setSelection( getSelection( true ).start() ); } else { setSelection( previousWordBoundary( getSelection().start() ) ); } @@ -525,8 +543,7 @@ void TextDocument::moveToPreviousWord() { void TextDocument::moveToNextWord() { if ( hasSelection() ) { - TextRange selection = getSelection( true ); - setSelection( selection.start() ); + setSelection( getSelection( true ).end() ); } else { setSelection( nextWordBoundary( getSelection().start() ) ); } @@ -565,6 +582,20 @@ void TextDocument::moveToEndOfDoc() { setSelection( endOfDoc() ); } +void TextDocument::moveToStartOfContent() { + TextPosition start = getSelection().start(); + TextPosition indented = startOfContent( getSelection().start() ); + setSelection( indented.column() == start.column() ? TextPosition( start.line(), 0 ) + : indented ); +} + +void TextDocument::selectToStartOfContent() { + TextPosition start = getSelection().start(); + TextPosition indented = startOfContent( getSelection().start() ); + setSelection( {indented.column() == start.column() ? TextPosition( start.line(), 0 ) : indented, + getSelection().end()} ); +} + void TextDocument::moveToStartOfLine() { setSelection( startOfLine( getSelection().start() ) ); } @@ -630,6 +661,14 @@ void TextDocument::selectToEndOfLine() { selectTo( endOfLine( getSelection().start() ) ); } +void TextDocument::selectToStartOfDoc() { + selectTo( startOfDoc() ); +} + +void TextDocument::selectToEndOfDoc() { + selectTo( endOfDoc() ); +} + void TextDocument::selectToPreviousPage( Int64 pageSize ) { TextPosition pos = getSelection().start(); pos.setLine( pos.line() - pageSize ); @@ -649,24 +688,22 @@ void TextDocument::selectAll() { void TextDocument::newLine() { String input( "\n" ); TextPosition start = getSelection().start(); - if ( start.line() >= 0 && start.line() < (Int64)mLines.size() ) { - const String& ln = line( start.line() ).getText(); - size_t to = eemin( ln.size(), start.column() ); - int indent = 0; - for ( size_t i = 0; i < to; i++ ) { - if ( '\t' == ln[i] || ' ' == ln[i] ) { - indent++; - } else { - break; - } - } - if ( indent ) { - input.append( ln.substr( 0, indent ) ); - } - } + TextPosition indent = startOfContent( getSelection().start() ); + if ( indent.column() != 0 ) + input.append( line( start.line() ).getText().substr( 0, indent.column() ) ); textInput( input ); } +void TextDocument::newLineAbove() { + String input( "\n" ); + TextPosition start = getSelection().start(); + TextPosition indent = startOfContent( getSelection().start() ); + if ( indent.column() != 0 ) + input.insert( 0, line( start.line() ).getText().substr( 0, indent.column() ) ); + insert( {start.line(), 0}, input ); + setSelection( {start.line(), (Int64)input.size()} ); +} + void TextDocument::insertAtStartOfSelectedLines( const String& text, bool skipEmpty ) { TextPosition prevStart = getSelection().start(); TextRange range = getSelection( true ); @@ -709,6 +746,38 @@ void TextDocument::unindent() { removeFromStartOfSelectedLines( getIndentString(), false ); } +void TextDocument::moveLinesUp() { + TextRange range = getSelection( true ); + bool swap = getSelection( true ) != getSelection(); + appendLineIfLastLine( range.end().line() ); + if ( range.start().line() > 0 ) { + auto& text = line( range.start().line() - 1 ); + insert( {range.end().line() + 1, 0}, text.getText() ); + remove( {{range.start().line() - 1, 0}, {range.start().line(), 0}} ); + setSelection( {range.start().line() - 1, range.start().column()}, + {range.end().line() - 1, range.end().column()}, swap ); + } +} + +void TextDocument::moveLinesDown() { + TextRange range = getSelection( true ); + bool swap = getSelection( true ) != getSelection(); + appendLineIfLastLine( range.end().line() + 1 ); + if ( range.end().line() < (Int64)mLines.size() - 1 ) { + auto text = line( range.end().line() + 1 ); + remove( {{range.end().line() + 1, 0}, {range.end().line() + 2, 0}} ); + insert( {range.start().line(), 0}, text.getText() ); + setSelection( {range.start().line() + 1, range.start().column()}, + {range.end().line() + 1, range.end().column()}, swap ); + } +} + +void TextDocument::appendLineIfLastLine( Int64 line ) { + if ( line >= (Int64)mLines.size() - 1 ) { + insert( endOfDoc(), "\n" ); + } +} + String TextDocument::getIndentString() { if ( IndentSpaces == mIndentType ) { return String( std::string( mTabWidth, ' ' ) ); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 04227ec07..e31da5fc0 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -404,6 +405,10 @@ Uint32 UICodeEditor::onTextInput( const TextInputEvent& event ) { return 1; if ( !getUISceneNode()->getWindow()->getInput()->isControlPressed() ) { + if ( getUISceneNode()->getWindow()->getInput()->isAltPressed() && + !event.getText().empty() && event.getText()[0] == '\t' ) + return 1; + mDoc.textInput( event.getText() ); } return 1; @@ -425,7 +430,7 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { case KEY_BACKSPACE: { if ( event.getMod() & KEYMOD_CTRL ) { mDoc.deleteToPreviousWord(); - } else { + } else if ( event.getMod() == 0 || ( event.getMod() & KEYMOD_SHIFT ) ) { mDoc.deleteToPreviousChar(); } break; @@ -433,28 +438,36 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { case KEY_DELETE: { if ( event.getMod() & KEYMOD_CTRL ) { mDoc.deleteToNextWord(); - } else { + } else if ( event.getMod() == 0 || ( event.getMod() & KEYMOD_SHIFT ) ) { mDoc.deleteToNextChar(); } break; } case KEY_KP_ENTER: case KEY_RETURN: { - mDoc.newLine(); + if ( ( event.getMod() & KEYMOD_CTRL ) && ( event.getMod() & KEYMOD_SHIFT ) ) { + mDoc.newLineAbove(); + } else if ( !( event.getMod() & KEYMOD_ALT ) ) { + mDoc.newLine(); + } break; } case KEY_UP: { - if ( event.getMod() & KEYMOD_CTRL ) { + if ( ( event.getMod() & KEYMOD_CTRL ) && ( event.getMod() & KEYMOD_SHIFT ) ) { + mDoc.moveLinesUp(); + } else if ( event.getMod() & KEYMOD_CTRL ) { setScrollY( mScroll.y - getLineHeight() ); } else if ( event.getMod() & KEYMOD_SHIFT ) { selectToPreviousLine(); - } else { + } else if ( event.getMod() == 0 ) { moveToPreviousLine(); } break; } case KEY_DOWN: { - if ( event.getMod() & KEYMOD_CTRL ) { + if ( ( event.getMod() & KEYMOD_CTRL ) && ( event.getMod() & KEYMOD_SHIFT ) ) { + mDoc.moveLinesDown(); + } else if ( event.getMod() & KEYMOD_CTRL ) { setScrollY( mScroll.y + getLineHeight() ); } else if ( event.getMod() & KEYMOD_SHIFT ) { selectToNextLine(); @@ -488,21 +501,25 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { break; } case KEY_HOME: { - if ( event.getMod() & KEYMOD_SHIFT ) { - mDoc.selectToStartOfLine(); + if ( ( event.getMod() & KEYMOD_CTRL ) && ( event.getMod() & KEYMOD_SHIFT ) ) { + mDoc.selectToStartOfDoc(); + } else if ( event.getMod() & KEYMOD_SHIFT ) { + mDoc.selectToStartOfContent(); } else if ( event.getMod() & KEYMOD_CTRL ) { mDoc.moveToStartOfDoc(); - } else { - mDoc.moveToStartOfLine(); + } else if ( event.getMod() == 0 ) { + mDoc.moveToStartOfContent(); } break; } case KEY_END: { - if ( event.getMod() & KEYMOD_SHIFT ) { + if ( ( event.getMod() & KEYMOD_CTRL ) && ( event.getMod() & KEYMOD_SHIFT ) ) { + mDoc.selectToEndOfDoc(); + } else if ( event.getMod() & KEYMOD_SHIFT ) { mDoc.selectToEndOfLine(); } else if ( event.getMod() & KEYMOD_CTRL ) { mDoc.moveToEndOfDoc(); - } else { + } else if ( event.getMod() == 0 ) { mDoc.moveToEndOfLine(); } break; @@ -510,7 +527,7 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { case KEY_PAGEUP: { if ( event.getMod() & KEYMOD_SHIFT ) { mDoc.selectToPreviousPage( getVisibleLinesCount() ); - } else { + } else if ( event.getMod() == 0 ) { mDoc.moveToPreviousPage( getVisibleLinesCount() ); } break; @@ -518,16 +535,20 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { case KEY_PAGEDOWN: { if ( event.getMod() & KEYMOD_SHIFT ) { mDoc.selectToNextPage( getVisibleLinesCount() ); - } else { + } else if ( event.getMod() == 0 ) { mDoc.moveToNextPage( getVisibleLinesCount() ); } break; } case KEY_TAB: { - if ( event.getMod() & KEYMOD_SHIFT ) { - mDoc.unindent(); - } else if ( !event.getMod() ) { - mDoc.indent(); + UIEventDispatcher* eventDispatcher = + static_cast( getUISceneNode()->getEventDispatcher() ); + if ( !eventDispatcher->justGainedFocus() ) { + if ( event.getMod() & KEYMOD_SHIFT ) { + mDoc.unindent(); + } else if ( event.getMod() == 0 ) { + mDoc.indent(); + } } break; } @@ -644,8 +665,8 @@ Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags } Uint32 UICodeEditor::onMouseMove( const Vector2i& position, const Uint32& flags ) { - if ( !getUISceneNode()->getEventDispatcher()->isNodeDragging() && hasFocus() && NULL != mFont && - mMouseDown && ( flags & EE_BUTTON_LMASK ) ) { + if ( !getUISceneNode()->getEventDispatcher()->isNodeDragging() && NULL != mFont && mMouseDown && + ( flags & EE_BUTTON_LMASK ) ) { TextRange selection = mDoc.getSelection(); selection.setStart( resolveScreenPosition( position.asFloat() ) ); mDoc.setSelection( selection ); @@ -679,7 +700,7 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) } Uint32 UICodeEditor::onMouseDoubleClick( const Vector2i&, const Uint32& flags ) { - if ( !mLocked || NULL == mFont ) + if ( mLocked || NULL == mFont ) return 1; if ( flags & EE_BUTTON_LMASK ) { @@ -837,18 +858,18 @@ void UICodeEditor::setLocked( bool locked ) { } } -Int64 UICodeEditor::getColFromXOffset( Int64 lineNumber, const Float& offset ) const { - if ( offset <= 0 ) +Int64 UICodeEditor::getColFromXOffset( Int64 lineNumber, const Float& x ) const { + if ( x <= 0 ) return 0; TextPosition pos = mDoc.sanitizePosition( TextPosition( lineNumber, 0 ) ); const String& line = mDoc.line( pos.line() ).getText(); - size_t len = line.length(); + Int64 len = line.length(); Float glyphWidth = getGlyphWidth(); - Float x = 0; - for ( size_t i = 0; i < len; i++ ) { - x += ( line[i] == '\t' ) ? glyphWidth * mTabWidth : glyphWidth; - if ( x >= offset ) - return i; + Float xOffset = 0; + for ( int i = 0; i < len; i++ ) { + if ( xOffset >= x ) + return xOffset - x > glyphWidth * 0.5f ? eemax( 0, i - 1 ) : i; + xOffset += ( line[i] == '\t' ) ? glyphWidth * mTabWidth : glyphWidth; } return static_cast( line.size() ) - 1; } @@ -866,16 +887,14 @@ Float UICodeEditor::getGlyphWidth() const { } void UICodeEditor::resetCursor() { - if ( hasFocus() ) { - mCursorVisible = true; - mBlinkTimer.restart(); - } + mCursorVisible = true; + mBlinkTimer.restart(); } TextPosition UICodeEditor::moveToLineOffset( const TextPosition& position, int offset ) { auto& xo = mLastXOffset; if ( xo.position != position ) { - xo.offset = getColXOffset( {position.line(), position.column() + 1} ); + xo.offset = getColXOffset( position ); } xo.position.setLine( position.line() + offset ); xo.position.setColumn( getColFromXOffset( position.line() + offset, xo.offset ) ); diff --git a/src/eepp/ui/uieventdispatcher.cpp b/src/eepp/ui/uieventdispatcher.cpp index 6c490f4e5..e822dbe1c 100644 --- a/src/eepp/ui/uieventdispatcher.cpp +++ b/src/eepp/ui/uieventdispatcher.cpp @@ -13,6 +13,10 @@ UIEventDispatcher* UIEventDispatcher::New( SceneNode* sceneNode ) { UIEventDispatcher::UIEventDispatcher( SceneNode* sceneNode ) : EventDispatcher( sceneNode ), mJustGainedFocus( false ) {} +const bool& UIEventDispatcher::justGainedFocus() const { + return mJustGainedFocus; +} + void UIEventDispatcher::inputCallback( InputEvent* Event ) { EventDispatcher::inputCallback( Event ); @@ -35,8 +39,7 @@ void UIEventDispatcher::checkTabPress( const Uint32& KeyCode ) { eeASSERT( NULL != mFocusNode ); Window::Window* win = mFocusNode->getSceneNode()->getWindow(); - if ( KeyCode == KEY_TAB && mFocusNode->isUINode() && NULL != win && win->isActive() && - !mJustGainedFocus ) { + if ( KeyCode == KEY_TAB && mFocusNode->isUINode() && NULL != win && !mJustGainedFocus ) { UINode* uiNode = static_cast( mFocusNode ); if ( !uiNode->isTabStop() ) { diff --git a/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp b/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp index 5d603de4c..97295156e 100644 --- a/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp +++ b/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp @@ -115,4 +115,12 @@ void DisplayManagerSDL2::disableScreenSaver() { SDL_DisableScreenSaver(); } +void DisplayManagerSDL2::enableMouseFocusClickThrough() { + SDL_SetHint( SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1" ); +} + +void DisplayManagerSDL2::disableMouseFocusClickThrough() { + SDL_SetHint( SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "0" ); +} + }}}} // namespace EE::Window::Backend::SDL2 diff --git a/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp b/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp index f94c5bbe8..0b0849791 100644 --- a/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp +++ b/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp @@ -35,6 +35,11 @@ class EE_API DisplayManagerSDL2 : public DisplayManager { void enableScreenSaver(); void disableScreenSaver(); + + void enableMouseFocusClickThrough(); + + void disableMouseFocusClickThrough(); + }; }}}} // namespace EE::Window::Backend::SDL2 diff --git a/src/eepp/window/displaymanager.cpp b/src/eepp/window/displaymanager.cpp index 03c00c581..ea54da86a 100644 --- a/src/eepp/window/displaymanager.cpp +++ b/src/eepp/window/displaymanager.cpp @@ -26,4 +26,8 @@ void DisplayManager::enableScreenSaver() {} void DisplayManager::disableScreenSaver() {} +void DisplayManager::enableMouseFocusClickThrough() {} + +void DisplayManager::disableMouseFocusClickThrough() {} + }} // namespace EE::Window diff --git a/src/eepp/window/engine.cpp b/src/eepp/window/engine.cpp index aaa5a3fe7..fbae1e286 100644 --- a/src/eepp/window/engine.cpp +++ b/src/eepp/window/engine.cpp @@ -55,8 +55,6 @@ Engine::Engine() : mZip->open( getPlatformHelper()->getApkPath() ); FileSystem::changeWorkingDirectory( getPlatformHelper()->getExternalStoragePath() ); -#else - FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); #endif TextureAtlasManager::createSingleton(); diff --git a/src/eepp/window/input.cpp b/src/eepp/window/input.cpp index ae35a8033..d4d1e04ef 100644 --- a/src/eepp/window/input.cpp +++ b/src/eepp/window/input.cpp @@ -458,4 +458,8 @@ std::list Input::getFingersWasDown() { return fDown; } +const Uint32& Input::getKeyMod() const { + return mInputMod; +} + }} // namespace EE::Window diff --git a/src/examples/fonts/fonts.cpp b/src/examples/fonts/fonts.cpp index 1ecc19e07..ed88eaba2 100644 --- a/src/examples/fonts/fonts.cpp +++ b/src/examples/fonts/fonts.cpp @@ -52,6 +52,11 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { // Check if created if ( win->isOpen() ) { + // Change the current working directory to the binary path to ensure the assets location + // is always correct even if we load the application from other directory than the binary + // path. + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + // Create a new text string String Txt( "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod " "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, " diff --git a/src/examples/sprites/sprites.cpp b/src/examples/sprites/sprites.cpp index 0349521cd..81e31cde9 100644 --- a/src/examples/sprites/sprites.cpp +++ b/src/examples/sprites/sprites.cpp @@ -95,6 +95,11 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { // Check if created if ( win->isOpen() ) { + // Change the current working directory to the binary path to ensure the assets location + // is always correct even if we load the application from other directory than the binary + // path. + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + // Load the rock texture Uint32 PlanetId = TextureFactory::instance()->loadFromFile( "assets/sprites/7.png" ); Uint32 RockId = TextureFactory::instance()->loadFromFile( "assets/sprites/5.png" ); diff --git a/src/examples/ui_hello_world/ui_hello_world.cpp b/src/examples/ui_hello_world/ui_hello_world.cpp index 5554bad6d..63aeb2f1d 100644 --- a/src/examples/ui_hello_world/ui_hello_world.cpp +++ b/src/examples/ui_hello_world/ui_hello_world.cpp @@ -34,6 +34,11 @@ EE_MAIN_FUNC int main( int, char** ) { ContextSettings( true ) ); if ( win->isOpen() ) { + // Change the current working directory to the binary path to ensure the assets location + // is always correct even if we load the application from other directory than the binary + // path. + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + // Load a font to use as the default font in our UI. FontTrueType* font = FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" ); diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index fd08a8dd7..af2b677f3 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -112,7 +112,7 @@ void EETest::init() { mTerrainUp = true; relLay = NULL; - MyPath = "assets/"; + MyPath = Sys::getProcessPath() + "assets/"; IniFile Ini( MyPath + "ee.ini" ); diff --git a/src/tests/ui_perf_test/ui_perf_test.cpp b/src/tests/ui_perf_test/ui_perf_test.cpp index 9ac0de487..41295fdf8 100644 --- a/src/tests/ui_perf_test/ui_perf_test.cpp +++ b/src/tests/ui_perf_test/ui_perf_test.cpp @@ -34,6 +34,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { ContextSettings( true ) ); if ( win->isOpen() ) { + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); PixelDensity::setPixelDensity( Engine::instance()->getDisplayManager()->getDisplayIndex( 0 )->getPixelDensity() ); FontTrueType* font = diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index b7ba55f86..42e616e63 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -52,48 +52,45 @@ void mainLoop() { input->update(); - if ( win->isActive() ) { - if ( codeEditor->isDirty() != docDirtyState ) { - docDirtyState = codeEditor->isDirty(); - setAppTitle( docDirtyState ? curFile + "*" : curFile ); - } + if ( codeEditor->isDirty() != docDirtyState ) { + docDirtyState = codeEditor->isDirty(); + setAppTitle( docDirtyState ? curFile + "*" : curFile ); + } - if ( ( input->isControlPressed() && input->isKeyUp( KEY_O ) ) || - input->isKeyUp( KEY_F2 ) ) { - openFileDialog(); - } + if ( ( input->isControlPressed() && input->isKeyUp( KEY_O ) ) || input->isKeyUp( KEY_F2 ) ) { + openFileDialog(); + } - if ( input->isControlPressed() && input->isKeyUp( KEY_S ) ) { - codeEditor->save(); - } + if ( input->isControlPressed() && input->isKeyUp( KEY_S ) ) { + codeEditor->save(); + } - if ( input->isKeyUp( KEY_F6 ) ) { - uiSceneNode->setHighlightOver( !uiSceneNode->getHighlightOver() ); - } + if ( input->isKeyUp( KEY_F6 ) ) { + uiSceneNode->setHighlightOver( !uiSceneNode->getHighlightOver() ); + } - if ( input->isKeyUp( KEY_F7 ) ) { - uiSceneNode->setDrawBoxes( !uiSceneNode->getDrawBoxes() ); - } + if ( input->isKeyUp( KEY_F7 ) ) { + uiSceneNode->setDrawBoxes( !uiSceneNode->getDrawBoxes() ); + } - if ( input->isKeyUp( KEY_F8 ) ) { - uiSceneNode->setDrawDebugData( !uiSceneNode->getDrawDebugData() ); - } + if ( input->isKeyUp( KEY_F8 ) ) { + uiSceneNode->setDrawDebugData( !uiSceneNode->getDrawDebugData() ); + } - if ( input->isKeyUp( KEY_ESCAPE ) && NULL == MsgBox && onCloseRequestCallback( win ) ) { - win->close(); - } + if ( input->isKeyUp( KEY_ESCAPE ) && NULL == MsgBox && onCloseRequestCallback( win ) ) { + win->close(); + } - if ( input->isAltPressed() && input->isKeyUp( KEY_RETURN ) ) { - win->toggleFullscreen(); - } + if ( input->isAltPressed() && input->isKeyUp( KEY_RETURN ) ) { + win->toggleFullscreen(); + } - if ( input->isKeyUp( KEY_F3 ) ) { - console->toggle(); - } + if ( input->isKeyUp( KEY_F3 ) ) { + console->toggle(); + } - if ( input->isControlPressed() && input->isKeyUp( KEY_L ) ) { - codeEditor->setLocked( !codeEditor->isLocked() ); - } + if ( input->isControlPressed() && input->isKeyUp( KEY_L ) ) { + codeEditor->setLocked( !codeEditor->isLocked() ); } SceneManager::instance()->update(); @@ -127,12 +124,18 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { return EXIT_FAILURE; } - Display* currentDisplay = Engine::instance()->getDisplayManager()->getDisplayIndex( 0 ); + DisplayManager* displayManager = Engine::instance()->getDisplayManager(); + Display* currentDisplay = displayManager->getDisplayIndex( 0 ); Float pixelDensity = currentDisplay->getPixelDensity(); + displayManager->enableScreenSaver(); + displayManager->enableMouseFocusClickThrough(); + + std::string resPath( Sys::getProcessPath() ); + win = Engine::instance()->createWindow( WindowSettings( 1280, 720, windowTitle, WindowStyle::Default, WindowBackend::Default, 32, - "assets/icon/ee.png", pixelDensity ), + resPath + "assets/icon/ee.png", pixelDensity ), ContextSettings( true ) ); if ( win->isOpen() ) { @@ -153,15 +156,16 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { uiSceneNode = UISceneNode::New(); - uiSceneNode->getUIThemeManager()->setDefaultFont( - FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" ) ); + uiSceneNode->getUIThemeManager()->setDefaultFont( FontTrueType::New( + "NotoSans-Regular", resPath + "assets/fonts/NotoSans-Regular.ttf" ) ); - Font* fontMono = FontTrueType::New( "monospace", "assets/fonts/DejaVuSansMono.ttf" ); + Font* fontMono = + FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" ); SceneManager::instance()->add( uiSceneNode ); StyleSheetParser cssParser; - if ( cssParser.loadFromFile( "assets/ui/breeze.css" ) ) { + if ( cssParser.loadFromFile( resPath + "assets/ui/breeze.css" ) ) { uiSceneNode->setStyleSheet( cssParser.getStyleSheet() ); } diff --git a/src/tools/mapeditor/mapeditor.cpp b/src/tools/mapeditor/mapeditor.cpp index c27f05d1f..fa6f43ed8 100644 --- a/src/tools/mapeditor/mapeditor.cpp +++ b/src/tools/mapeditor/mapeditor.cpp @@ -77,9 +77,11 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { Display* currentDisplay = Engine::instance()->getDisplayManager()->getDisplayIndex( 0 ); Float pixelDensity = currentDisplay->getPixelDensity(); + std::string resPath( Sys::getProcessPath() ); + win = Engine::instance()->createWindow( WindowSettings( 1280, 720, "eepp - Map Editor", WindowStyle::Default, - WindowBackend::Default, 32, "assets/icon/ee.png", pixelDensity ), + WindowBackend::Default, 32, resPath + "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, false ) ); if ( win->isOpen() ) { @@ -98,14 +100,14 @@ 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* font = FontTrueType::New( "NotoSans-Regular", + resPath + "assets/fonts/NotoSans-Regular.ttf" ); - UITheme* theme = - UITheme::load( "uitheme" + pd, "uitheme" + pd, "assets/ui/uitheme" + pd + ".eta", - font, "assets/ui/uitheme.css" ); + UITheme* theme = UITheme::load( "uitheme" + pd, "uitheme" + pd, + resPath + "assets/ui/uitheme" + pd + ".eta", font, + resPath + "assets/ui/uitheme.css" ); /*UITheme* theme = - UITheme::load( "uitheme", "uitheme", "", font, "assets/ui/breeze.css" );*/ + UITheme::load( "uitheme", "uitheme", "", font, resPath + "assets/ui/breeze.css" );*/ uiSceneNode->combineStyleSheet( theme->getStyleSheet() ); diff --git a/src/tools/textureatlaseditor/textureatlaseditor.cpp b/src/tools/textureatlaseditor/textureatlaseditor.cpp index 7f2f4ca74..574dc6290 100644 --- a/src/tools/textureatlaseditor/textureatlaseditor.cpp +++ b/src/tools/textureatlaseditor/textureatlaseditor.cpp @@ -76,9 +76,11 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { Display* currentDisplay = Engine::instance()->getDisplayManager()->getDisplayIndex( 0 ); Float pixelDensity = currentDisplay->getPixelDensity(); + std::string resPath( Sys::getProcessPath() ); + win = Engine::instance()->createWindow( WindowSettings( 1280, 720, "eepp - Texture Atlas Editor", WindowStyle::Default, - WindowBackend::Default, 32, "assets/icon/ee.png", pixelDensity ), + WindowBackend::Default, 32, resPath + "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, true ) ); if ( win->isOpen() ) { @@ -97,15 +99,14 @@ 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* font = FontTrueType::New( "NotoSans-Regular", + resPath + "assets/fonts/NotoSans-Regular.ttf" ); - /*UITheme* theme = - UITheme::load( "uitheme" + pd, "uitheme" + pd, "assets/ui/uitheme" + pd + ".eta", - font, "assets/ui/uitheme.css" );*/ + /*UITheme* theme = UITheme::load( "uitheme" + pd, "uitheme" + pd, resPath + + * "assets/ui/uitheme" + pd + ".eta", font, resPath + "assets/ui/uitheme.css" );*/ UITheme* theme = - UITheme::load( "uitheme", "uitheme", "", font, "assets/ui/breeze.css" ); + UITheme::load( "uitheme", "uitheme", "", font, resPath + "assets/ui/breeze.css" ); uiSceneNode->combineStyleSheet( theme->getStyleSheet() ); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 3f1afaa71..ea14b976b 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -978,9 +978,11 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { Log::instance()->setLiveWrite( true ); Log::instance()->setConsoleOutput( true ); + std::string resPath( Sys::getProcessPath() ); + window = Engine::instance()->createWindow( WindowSettings( 1280, 720, "eepp - UI Editor", WindowStyle::Default, WindowBackend::Default, - 32, "assets/icon/ee.png", pixelDensity ), + 32, resPath + "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, true ) ); if ( window->isOpen() ) { @@ -995,15 +997,17 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { pd = "2x"; FontTrueType* font = - FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" ); + FontTrueType::New( "NotoSans-Regular", resPath + "assets/fonts/NotoSans-Regular.ttf" ); FontTrueType* fontMono = - FontTrueType::New( "DejaVuSansMono", "assets/fonts/DejaVuSansMono.ttf" ); + FontTrueType::New( "DejaVuSansMono", resPath + "assets/fonts/DejaVuSansMono.ttf" ); 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" ); - /*theme = UITheme::load( "uitheme", "uitheme", "", font, "assets/ui/breeze.css" );*/ + theme = UITheme::load( "uitheme" + pd, "uitheme" + pd, + resPath + "assets/ui/uitheme" + pd + ".eta", font, + resPath + "assets/ui/uitheme.css" ); + /*theme = UITheme::load( "uitheme", "uitheme", "", font, resPath + "assets/ui/breeze.css" + * );*/ uiSceneNode = UISceneNode::New(); uiSceneNode->setId( "uiSceneNode" );