diff --git a/include/uui/container_interface.hpp b/include/uui/container_interface.hpp index 287e918..e43f496 100644 --- a/include/uui/container_interface.hpp +++ b/include/uui/container_interface.hpp @@ -12,6 +12,7 @@ class ContainerInterface { public: virtual std::tuple get_child_position(const std::size_t child_index [[maybe_unused]]) const = 0; + protected: virtual std::size_t push_child(std::shared_ptr child) = 0; virtual std::shared_ptr get_child(std::size_t index) const = 0; diff --git a/include/uui/label.hpp b/include/uui/label.hpp index 6b4f42a..2de7c22 100644 --- a/include/uui/label.hpp +++ b/include/uui/label.hpp @@ -20,4 +20,3 @@ protected: }; } // namespace uui - diff --git a/include/uui/opengl/button.hpp b/include/uui/opengl/button.hpp index dfe5854..0df1ff2 100644 --- a/include/uui/opengl/button.hpp +++ b/include/uui/opengl/button.hpp @@ -1,4 +1,3 @@ - #pragma once #include @@ -19,8 +18,7 @@ protected: std::size_t parent_index, const position_t x, const position_t y, const Direction direction); GlButton( std::shared_ptr window, std::size_t window_index, const position_t x, const position_t y, - const Direction direction): - GlButton(window, window_index, window, window_index, x, y, direction) + const Direction direction): GlButton(window, window_index, window, window_index, x, y, direction) {} virtual std::tuple get_child_position(const std::size_t child_index) const; diff --git a/include/uui/opengl/graphic_context.hpp b/include/uui/opengl/graphic_context.hpp index 62635a7..037f696 100644 --- a/include/uui/opengl/graphic_context.hpp +++ b/include/uui/opengl/graphic_context.hpp @@ -1,8 +1,9 @@ #pragma once // clang-format off +#define GLAD_GL_IMPLEMENTATION #include "glad/glad.h" -#define GLFW_INCLUDE_VULKAN +#define GLFW_INCLUDE_NONE #include #define GLM_FORCE_RADIANS diff --git a/make.py b/make.py index cd796e9..b3b24ce 100644 --- a/make.py +++ b/make.py @@ -1,50 +1,38 @@ #! python3 -import os from pathlib import Path import shutil -from umake import get_hash, make - - -class Config: - CC = 'g++' - APPS = ['test/example_gl', 'test/benchmark_text', 'test/sample'] - IGNORE_APPS = [] - JOB_COUNT = int(os.cpu_count() * 0.8) - - BIN_DIR = Path('bin') - INCLUDE_DIR = Path('include') - OBJECT_DIR = Path('obj') - SOURCE_DIR = Path('src') - - COMMON_FLAGS = '-std=c++20 -fno-semantic-interposition' - COMMON_DEBUG_FLAGS = '-g -Og -DDEBUG' - COMMON_RELEASE_FLAGS = '-O2 -flto=auto' - COMPILE_FLAGS = f'-Wall -Wextra -Wpedantic -Wconversion -I{INCLUDE_DIR} `pkg-config --cflags glfw3 vulkan gl x11 freetype2`' - LINK_FLAGS = '-lpthread -ldl `pkg-config --libs glfw3 vulkan gl x11 freetype2`' - - PRE_COMPILE_FUNCTION = None - - CPP_SOURCES = [filepath for filepath in SOURCE_DIR.rglob('*.cpp') if not filepath.name.startswith('.')] +from umake.umake import get_hash, make, Config def main(): + config = Config() + def pre_compile(): # Copying OpenGL shaders - src_opengl_shader_path = Config.SOURCE_DIR / 'uui' / 'opengl' / 'shaders' + src_opengl_shader_path = config.source_dir / 'uui' / 'opengl' / 'shaders' for shader_path in ( list(src_opengl_shader_path.rglob('*.vert')) + list(src_opengl_shader_path.rglob('*.frag'))): - out_path = Config.BIN_DIR / shader_path.relative_to(Config.SOURCE_DIR) + out_path = config.bin_dir / shader_path.relative_to(config.source_dir) if out_path.exists() and get_hash(shader_path) == get_hash(out_path): continue if not out_path.parent.exists(): out_path.parent.mkdir(parents=True) shutil.copy(shader_path, out_path) - Config.PRE_COMPILE_FUNCTION = pre_compile - make(Config) + + config.apps = [str(p.relative_to(Path('src')))[:-4] for p in (config.source_dir / 'test').rglob('*.cpp')] + config.watch = True + + config.common_flags = '-std=c++20 -fno-semantic-interposition' + config.common_debug_flags = '-g -Og -DDEBUG' + config.common_release_flags = '-O2 -flto=auto' + config.compile_flags = f'-Wall -Wextra -Wpedantic -Wconversion -I{config.include_dir} `pkg-config --cflags glfw3 gl x11 freetype2`' + config.link_flags = '-lpthread -ldl `pkg-config --libs glfw3 gl freetype2`' + config.pre_compile_function = pre_compile + make(config) if __name__ == '__main__': diff --git a/makefile b/makefile index 5c9f40d..dde7e0f 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ MAKE_PATH="." UMAKE_PATH="umake" -.PHONY: all clean +.PHONY: all watch debug debug_watch clean lint all: @PYTHONPATH=$(UMAKE_PATH) python $(MAKE_PATH)/make.py diff --git a/src/uui/opengl/application.cpp b/src/uui/opengl/application.cpp index ab964f2..81ceb36 100644 --- a/src/uui/opengl/application.cpp +++ b/src/uui/opengl/application.cpp @@ -30,6 +30,8 @@ void uui::GlApplication::init() std::cout << "Initialize the GlApplication" << std::endl; // Init GLFW + // Avoiding libdecor would be better + // glfwInitHint(GLFW_WAYLAND_LIBDECOR, GLFW_WAYLAND_DISABLE_LIBDECOR); glfwInit(); // Set all the required options for GLFW glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); @@ -69,7 +71,7 @@ void uui::GlApplication::run() if constexpr(debug_mode) { end_time = std::chrono::high_resolution_clock::now(); - render_duration = std::chrono::duration_cast(end_time - start_time).count(); + render_duration = std::chrono::duration(end_time - start_time).count(); // std::cout << "Frame " << frame_count << ", duration: " << render_duration << std::endl; if(frame_count > 0.0f && render_duration > 500.0f) { diff --git a/src/uui/opengl/label.cpp b/src/uui/opengl/label.cpp index 46aee62..fd16e89 100644 --- a/src/uui/opengl/label.cpp +++ b/src/uui/opengl/label.cpp @@ -8,8 +8,8 @@ uui::GlLabel::GlLabel( std::shared_ptr window, std::size_t window_index, std::shared_ptr parent, std::size_t parent_index, const LabelParams& params): - GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}), - text(params.text), text_color(params.text_color) + GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}), text(params.text), + text_color(params.text_color) { if constexpr(uui::Application::debug_mode) std::cout << "Creating GlLabel " << parent_index << std::endl; @@ -27,9 +27,9 @@ uui::GlLabel::GlLabel( void uui::GlLabel::render() { float text_x = _position_x.index() == 1 ? std::get<1>(_position_x) * static_cast(_window->width()) - : static_cast(std::get<0>(_position_x)); + : static_cast(std::get<0>(_position_x)); float text_y = _position_y.index() == 1 ? std::get<1>(_position_y) * static_cast(_window->height()) - : static_cast(std::get<0>(_position_y)); + : static_cast(std::get<0>(_position_y)); text_y += static_cast(text_height) - 1; glBindVertexArray(gl_vao); diff --git a/src/uui/opengl/stack.cpp b/src/uui/opengl/stack.cpp index a6e1eed..5fa8862 100644 --- a/src/uui/opengl/stack.cpp +++ b/src/uui/opengl/stack.cpp @@ -58,10 +58,12 @@ void uui::GlStack::create_label(const StackLabelParams& params, uui::InitFunctio std::tuple uui::GlStack::get_child_position(const std::size_t child_index) const { - int x = _position_x.index() == 0 ? std::get<0>(_position_x) - : static_cast(std::get<1>(_position_x) * static_cast(_window->width())); - int y = _position_y.index() == 0 ? std::get<0>(_position_y) - : static_cast(std::get<1>(_position_y) * static_cast(_window->height())); + int x = _position_x.index() == 0 + ? std::get<0>(_position_x) + : static_cast(std::get<1>(_position_x) * static_cast(_window->width())); + int y = _position_y.index() == 0 + ? std::get<0>(_position_y) + : static_cast(std::get<1>(_position_y) * static_cast(_window->height())); if(child_index == 0) return {x, y}; diff --git a/umake b/umake index 797d6ac..933dea2 160000 --- a/umake +++ b/umake @@ -1 +1 @@ -Subproject commit 797d6accd2fd4fd1faa742a6ec8039b6aad8d861 +Subproject commit 933dea2b9e9da0b03489ea9dca3cd597fdd2d09e