Skip to content

Commit

Permalink
Merge branch 'master' into add_tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	CMakeLists.txt
#	Source/Core/DataModel.cpp
#	Source/Core/GeometryDatabase.cpp
  • Loading branch information
mikke89 committed Jul 21, 2020
2 parents 4bc9e0b + 6704977 commit fcae4ff
Show file tree
Hide file tree
Showing 158 changed files with 644 additions and 419 deletions.
1 change: 1 addition & 0 deletions CMake/FileList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ set(MASTER_Core_PUB_HDR_FILES
)

set(Core_PUB_HDR_FILES
${PROJECT_SOURCE_DIR}/Include/RmlUi/Config/Config.h
${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/Animation.h
${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/BaseXMLParser.h
${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/Box.h
Expand Down
1 change: 1 addition & 0 deletions CMake/gen_filelists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ printfiles() {
echo -e ')\n' >>$file
# Print public headers sub directory
echo ${pubhdr/lib/$1} >>$file
if [[ "$1" == "Core" ]]; then echo ' '$srcdir/Include/RmlUi/Config/Config.h >>$file; fi
find $hdrpath/$1 -maxdepth 3 -path */$luapath -prune -o -path */$fontdefaultpath -prune -o \( -iname "*.h" -o -iname "*.inl" -o -iname "*.hpp" \) -exec echo ' '$srcdir/{} \; 2>/dev/null | sort -f >>$file
echo -e ')\n' >>$file
# Print source files
Expand Down
49 changes: 48 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ endif()

option(BUILD_SAMPLES "Build samples" OFF)

option(MATRIX_ROW_MAJOR "Use row-major matrices. Column-major matrices are used by default." OFF)

if(APPLE)
if(IOS)
if(BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -191,6 +193,31 @@ if( NO_THIRDPARTY_CONTAINERS )
message("-- No third-party containers will be used: Make sure to #define RMLUI_NO_THIRDPARTY_CONTAINERS before including RmlUi in your project.")
endif()

option(CUSTOM_CONFIGURATION "Customize RmlUi configuration files for overriding the default configuration and types." OFF)

set(CUSTOM_CONFIGURATION_FILE "" CACHE STRING "Custom configuration file to be included in place of <RmlUi/Config/Config.h>.")
if( CUSTOM_CONFIGURATION AND CUSTOM_CONFIGURATION_FILE )
add_definitions(-DRMLUI_CUSTOM_CONFIGURATION_FILE="${CUSTOM_CONFIGURATION_FILE}")
message("-- Including ${CUSTOM_CONFIGURATION_FILE} instead of <RmlUi/Config/Config.h>")
endif ()

set(CUSTOM_INCLUDE_DIRS "" CACHE STRING "Extra include directories (use with CUSTOM_CONFIGURATION_FILE).")
if( CUSTOM_CONFIGURATION AND CUSTOM_INCLUDE_DIRS )
include_directories(${CUSTOM_INCLUDE_DIRS})
endif ()

set(CUSTOM_LINK_LIBRARIES "" CACHE STRING "Extra link libraries (use with CUSTOM_CONFIGURATION_FILE).")

if( CUSTOM_CONFIGURATION )
mark_as_advanced( CLEAR CUSTOM_CONFIGURATION_FILE CUSTOM_INCLUDE_DIRS CUSTOM_LINK_LIBRARIES )
else()
mark_as_advanced( FORCE CUSTOM_CONFIGURATION_FILE CUSTOM_INCLUDE_DIRS CUSTOM_LINK_LIBRARIES )

if( CUSTOM_CONFIGURATION_FILE OR CUSTOM_INCLUDE_DIRS OR CUSTOM_LINK_LIBRARIES )
message("-- CUSTOM_CONFIGURATION disabled, but custom configuration variables are set. They will have no effect.")
endif()
endif()

option(ENABLE_TRACY_PROFILING "Enable profiling with Tracy. Source files can be placed in Dependencies/tracy." OFF)
if( ENABLE_TRACY_PROFILING )
find_package(Tracy REQUIRED)
Expand Down Expand Up @@ -316,13 +343,31 @@ foreach(library ${LIBRARIES})
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)


set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${NAME})
endforeach(library)

if( CUSTOM_CONFIGURATION )
foreach(library ${CUSTOM_LINK_LIBRARIES})
install(TARGETS ${library}
EXPORT RmlUiTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${library})
endforeach(library ${CUSTOM_LINK_LIBRARIES})
endif()

target_compile_definitions(RmlCore PRIVATE RMLUI_VERSION="${RMLUI_VERSION_SHORT}")

if( MATRIX_ROW_MAJOR )
target_compile_definitions(RmlCore PUBLIC -DRMLUI_MATRIX_ROW_MAJOR)
endif ()
if( CUSTOM_CONFIGURATION AND CUSTOM_LINK_LIBRARIES )
target_link_libraries(RmlCore PUBLIC ${CUSTOM_LINK_LIBRARIES})
endif ()

if (PRECOMPILED_HEADERS_ENABLED)
target_precompile_headers(RmlCore PRIVATE ${PROJECT_SOURCE_DIR}/Source/Core/precompiled.h)
endif()
Expand Down Expand Up @@ -549,6 +594,8 @@ endif(NOT BUILD_FRAMEWORK)
target_link_libraries(shell PUBLIC shlwapi)
endif()

target_link_libraries(shell PUBLIC RmlCore)

add_common_target_options(shell)

# Build and install the basic samples
Expand Down
203 changes: 203 additions & 0 deletions Include/RmlUi/Config/Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*
* This source file is part of RmlUi, the HTML/CSS Interface Middleware
*
* For the latest information, see http://github.com/mikke89/RmlUi
*
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
* Copyright (c) 2019 The RmlUi Team, and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#ifndef RMLUI_CONFIG_CONFIG_H
#define RMLUI_CONFIG_CONFIG_H

/*
* This file provides the means to configure various types used across RmlUi. It is possible to override container
* types with your own, provided they are compatible with STL, or customize STL containers, for example by setting
* custom allocators. This file may be edited directly, or can be copied to an alternate location, modified, and
* included by setting the CMake option CUSTOM_CONFIGURATION_FILE (RMLUI_CUSTOM_CONFIGURATION_FILE preprocessor
* define) to the path of that file.
*/

#ifdef RMLUI_CUSTOM_CONFIGURATION_FILE
#include RMLUI_CUSTOM_CONFIGURATION_FILE
#else
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <list>
#include <functional>
#include <queue>
#include <array>
#include <unordered_map>
#include <memory>

#ifdef RMLUI_NO_THIRDPARTY_CONTAINERS
#include <set>
#include <unordered_set>
#else
#include "../Core/Containers/chobo/flat_map.hpp"
#include "../Core/Containers/chobo/flat_set.hpp"
#include "../Core/Containers/robin_hood.h"
#endif // RMLUI_NO_THIRDPARTY_CONTAINERS

namespace Rml {

// Default matrix type to be used. This alias may be set to ColumnMajorMatrix4f or RowMajorMatrix4f. This alias can not
// be set here because matrix types are defined after this include in Core/Types.h.
#ifdef RMLUI_MATRIX_ROW_MAJOR
#define RMLUI_MATRIX4_TYPE RowMajorMatrix4f
#else
#define RMLUI_MATRIX4_TYPE ColumnMajorMatrix4f
#endif

// A way to disable 'final' specified for Rml::Releaser class. It breaks EASTL.
#define RMLUI_RELEASER_FINAL final

// Containers types.
template<typename T>
using Vector = std::vector<T>;
template<typename T, size_t N = 1>
using Array = std::array<T, N>;
template<typename T>
using Stack = std::stack<T>;
template<typename T>
using List = std::list<T>;
template<typename T>
using Queue = std::queue<T>;
template<typename T1, typename T2>
using Pair = std::pair<T1, T2>;
template <typename Key, typename Value>
using UnorderedMultimap = std::unordered_multimap< Key, Value >;
#ifdef RMLUI_NO_THIRDPARTY_CONTAINERS
template <typename Key, typename Value>
using UnorderedMap = std::unordered_map< Key, Value >;
template <typename Key, typename Value>
using SmallUnorderedMap = UnorderedMap< Key, Value >;
template <typename T>
using UnorderedSet = std::unordered_set< T >;
template <typename T>
using SmallUnorderedSet = std::unordered_set< T >;
template <typename T>
using SmallOrderedSet = std::set< T >;
#else
template < typename Key, typename Value>
using UnorderedMap = robin_hood::unordered_flat_map< Key, Value >;
template <typename Key, typename Value>
using SmallUnorderedMap = chobo::flat_map< Key, Value >;
template <typename T>
using UnorderedSet = robin_hood::unordered_flat_set< T >;
template <typename T>
using SmallUnorderedSet = chobo::flat_set< T >;
template <typename T>
using SmallOrderedSet = chobo::flat_set< T >;
#endif // RMLUI_NO_THIRDPARTY_CONTAINERS
template<typename Iterator>
inline std::move_iterator<Iterator> MakeMoveIterator(Iterator it) { return std::make_move_iterator(it); }

// Utilities.
template <typename T>
using Hash = std::hash<T>;
template<typename T>
using Function = std::function<T>;

// Strings.
using String = std::string;
using StringList = Vector< String >;
using U16String = std::u16string;

// Smart pointer types.
template<typename T>
using UniquePtr = std::unique_ptr<T>;
template<typename T>
class Releaser;
template<typename T>
using UniqueReleaserPtr = std::unique_ptr<T, Releaser<T>>;
template<typename T>
using SharedPtr = std::shared_ptr<T>;
template<typename T>
using WeakPtr = std::weak_ptr<T>;
template<typename T, typename... Args>
inline SharedPtr<T> MakeShared(Args... args) { return std::make_shared<T, Args...>(std::forward<Args>(args)...); }
template<typename T, typename... Args>
inline UniquePtr<T> MakeUnique(Args... args) { return std::make_unique<T, Args...>(std::forward<Args>(args)...); }

}


/***
// The following defines should be used for inserting custom type cast operators for conversion of RmlUi types
// to user types. RmlUi uses template math types, therefore conversion operators to non-templated types
// should be done using SFINAE as in example below.
// Extra code to be inserted into RmlUi::Color<> class body. Note: be mindful of colorspaces used by different
// color types. RmlUi assumes that float colors are interpreted in linear colorspace while byte colors are
// interpreted as sRGB.
#define RMLUI_COLOUR_USER_EXTRA \
template<typename U = ColourType, typename std::enable_if_t<std::is_same_v<U, byte>>* = nullptr> \
operator MyColor() const { return MyColor( \
(float)red / 255.0f, (float)green / 255.0f, (float)blue / 255.0f, (float)alpha / 255.0f); } \
template<typename U = ColourType, typename std::enable_if_t<std::is_same_v<U, float>>* = nullptr> \
operator MyColor() const { return MyColor(red, green, blue, alpha); } \
// Extra code to be inserted into RmlUi::Vector2<> class body.
#define RMLUI_VECTOR2_USER_EXTRA \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, int>>* = nullptr> \
operator typename MyIntVector2() const { return MyIntVector2(x, y); } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, float>>* = nullptr> \
operator MyVector2() const { return MyVector2(x, y); } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, int>>* = nullptr> \
Vector2(MyIntVector2 value) : Vector2(value.x_, value.y_) { } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, float>>* = nullptr> \
Vector2(MyVector2 value) : Vector2(value.x_, value.y_) { } \
// Extra code to be inserted into RmlUi::Vector3<> class body.
#define RMLUI_VECTOR3_USER_EXTRA \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, int>>* = nullptr> \
operator typename MyIntVector3() const { return MyIntVector3(x, y, z); } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, float>>* = nullptr> \
operator MyVector3() const { return MyVector3(x, y, z); } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, int>>* = nullptr> \
Vector3(MyIntVector3 value) : Vector3(value.x_, value.y_, value.z_) { } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, float>>* = nullptr> \
Vector3(MyVector3 value) : Vector3(value.x_, value.y_, value.z_) { } \
// Extra code to be inserted into RmlUi::Vector4<> class body.
#define RMLUI_VECTOR4_USER_EXTRA \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, int>>* = nullptr> \
operator typename MyIntVector4() const { return MyIntVector4(x, y, z, w); } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, float>>* = nullptr> \
operator MyVector4() const { return MyVector4(x, y, z, w); } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, int>>* = nullptr> \
Vector4(MyIntVector4 value) : Vector4(value.x_, value.y_, value.z_, value.w_) { } \
template<typename U = Type, typename std::enable_if_t<std::is_same_v<U, float>>* = nullptr> \
Vector4(MyVector4 value) : Vector4(value.x_, value.y_, value.z_, value.w_) { } \
// Extra code to be inserted into RmlUi::Matrix4<> class body.
#define RMLUI_MATRIX4_USER_EXTRA operator MyMatrix4() const { return MyMatrix4(data()); }
***/


#endif // RMLUI_USER_CONFIG_FILE

#endif // RMLUI_CONFIG_CONFIG_H
4 changes: 2 additions & 2 deletions Include/RmlUi/Core/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ struct Transition {
struct TransitionList {
bool none = true;
bool all = false;
std::vector<Transition> transitions;
Vector<Transition> transitions;

TransitionList() {}
TransitionList(bool none, bool all, std::vector<Transition> transitions) :
TransitionList(bool none, bool all, Vector<Transition> transitions) :
none(none), all(all), transitions(transitions) {}
};

Expand Down
4 changes: 4 additions & 0 deletions Include/RmlUi/Core/Colour.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class Colour
inline operator ColourType*() { return &red; }

ColourType red, green, blue, alpha;

#ifdef RMLUI_COLOUR_USER_EXTRA
RMLUI_COLOUR_USER_EXTRA
#endif
};

} // namespace Rml
Expand Down
15 changes: 12 additions & 3 deletions Include/RmlUi/Core/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class RMLUICORE_API Context : public ScriptInterface
bool Render();

/// Creates a new, empty document and places it into this context.
/// @param[in] tag The document type to create.
/// @param[in] instancer_name The name of the instancer used to create the document.
/// @return The new document, or nullptr if no document could be created.
ElementDocument* CreateDocument(const String& tag = "body");
ElementDocument* CreateDocument(const String& instancer_name = "body");
/// Load a document into the context.
/// @param[in] document_path The path to the document to load.
/// @return The loaded document, or nullptr if no document was loaded.
Expand Down Expand Up @@ -239,18 +239,27 @@ class RMLUICORE_API Context : public ScriptInterface
/// @return True if succesfully removed, false if no data model was found.
bool RemoveDataModel(const String& name);

/// This will set the documents base <tag> before creation. Default = "body"
/// @param[in] tag The name of the base tag. Example: "html"
void SetDocumentsBaseTag(const String& tag);

/// Gets the name of the documents base tag.
/// @return The current documents base tag name.
const String& GetDocumentsBaseTag();

protected:
void Release() override;

private:
String name;
Vector2i dimensions;
float density_independent_pixel_ratio;
String documents_base_tag = "body";

ContextInstancer* instancer;

using ElementSet = SmallOrderedSet< Element* > ;
using ElementList = std::vector< Element* >;
using ElementList = Vector< Element* >;
// Set of elements that are currently in hover state.
ElementSet hover_chain;
// List of elements that are currently in active state.
Expand Down
3 changes: 1 addition & 2 deletions Include/RmlUi/Core/DataController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "Header.h"
#include "Types.h"
#include "Traits.h"
#include <unordered_map>

namespace Rml {

Expand Down Expand Up @@ -111,7 +110,7 @@ class RMLUICORE_API DataControllers : NonCopyMoveable {
void OnElementRemove(Element* element);

private:
using ElementControllersMap = std::unordered_multimap<Element*, DataControllerPtr>;
using ElementControllersMap = UnorderedMultimap<Element*, DataControllerPtr>;
ElementControllersMap controllers;
};

Expand Down
4 changes: 3 additions & 1 deletion Include/RmlUi/Core/DataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class RMLUICORE_API DataModelConstructor {
// Convenience wrapper around BindEventCallback for member functions.
template<typename T>
bool BindEventCallback(const String& name, DataEventMemberFunc<T> member_func, T* object_pointer) {
return BindEventCallback(name, std::bind(member_func, object_pointer, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
return BindEventCallback(name, [member_func, object_pointer](DataModelHandle handle, Event& event, const VariantList& arguments) {
(object_pointer->*member_func)(handle, event, arguments);
});
}

// Register a struct type.
Expand Down
Loading

0 comments on commit fcae4ff

Please sign in to comment.