diff options
author | crupest <crupest@outlook.com> | 2021-03-24 22:58:07 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-03-24 22:58:07 +0800 |
commit | ba43736c55ad510942e9e83ca0c8bea7265cf055 (patch) | |
tree | a27a804ea3b95dbe33dde47568fe23b7f98439f6 | |
parent | 7f15a1ff9a2007e119798053083a0a87d042990a (diff) | |
download | cru-ba43736c55ad510942e9e83ca0c8bea7265cf055.tar.gz cru-ba43736c55ad510942e9e83ca0c8bea7265cf055.tar.bz2 cru-ba43736c55ad510942e9e83ca0c8bea7265cf055.zip |
...
-rw-r--r-- | .vscode/c_cpp_properties.json | 2 | ||||
-rw-r--r-- | demos/CMakeLists.txt | 10 | ||||
-rw-r--r-- | demos/xcb/CMakeLists.txt | 7 | ||||
-rw-r--r-- | demos/xcb/cairo-start/CMakeLists.txt | 4 | ||||
-rw-r--r-- | demos/xcb/cairo-start/main.cpp | 98 | ||||
-rw-r--r-- | demos/xcb/start/CMakeLists.txt | 2 | ||||
-rw-r--r-- | demos/xcb/start/main.cpp | 23 | ||||
-rw-r--r-- | include/cru/common/Format.hpp | 7 | ||||
-rw-r--r-- | include/cru/ui/style/StyleRuleSet.hpp | 8 | ||||
m--------- | vcpkg | 0 |
10 files changed, 144 insertions, 17 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index f5500679..897dbc57 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,7 +1,7 @@ { "configurations": [ { - "name": "Win32", + "name": "cpp", "configurationProvider": "ms-vscode.cmake-tools" } ], diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 16159d08..cf27d408 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -4,5 +4,11 @@ if(WIN32) target_link_libraries(cru_demo_base INTERFACE cru_win_gui) endif() -add_subdirectory(main) -add_subdirectory(input_method) +if(WIN32) # Currently only enable tests on Windows. + add_subdirectory(main) + add_subdirectory(input_method) +endif() + +if(UNIX) + add_subdirectory(xcb) +endif() diff --git a/demos/xcb/CMakeLists.txt b/demos/xcb/CMakeLists.txt new file mode 100644 index 00000000..97292467 --- /dev/null +++ b/demos/xcb/CMakeLists.txt @@ -0,0 +1,7 @@ +find_library(LIBRARY_XCB xcb REQUIRED) + +add_library(demo-xcb-base INTERFACE) +target_link_libraries(demo-xcb-base INTERFACE ${LIBRARY_XCB}) + +add_subdirectory(start) +add_subdirectory(cairo-start) diff --git a/demos/xcb/cairo-start/CMakeLists.txt b/demos/xcb/cairo-start/CMakeLists.txt new file mode 100644 index 00000000..d08f2c96 --- /dev/null +++ b/demos/xcb/cairo-start/CMakeLists.txt @@ -0,0 +1,4 @@ +find_library(LIBRARY_CAIRO cairo REQUIRED) + +add_executable(demo-xcb-cairo-start main.cpp) +target_link_libraries(demo-xcb-cairo-start PUBLIC demo-xcb-base ${LIBRARY_CAIRO}) diff --git a/demos/xcb/cairo-start/main.cpp b/demos/xcb/cairo-start/main.cpp new file mode 100644 index 00000000..331f90d7 --- /dev/null +++ b/demos/xcb/cairo-start/main.cpp @@ -0,0 +1,98 @@ +#include <cairo/cairo-xcb.h> +#include <cairo/cairo.h> +#include <unistd.h> +#include <xcb/xcb.h> +#include <cstdlib> +#include <iostream> + +int main() { + int screen_num; + xcb_connection_t *connection = xcb_connect(NULL, &screen_num); + const xcb_setup_t *setup = xcb_get_setup(connection); + xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); + xcb_screen_t *screen = iter.data; + + uint32_t mask = XCB_CW_EVENT_MASK; + uint32_t data[] = {XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY}; + + int width = 500; + int height = 500; + + xcb_window_t window = xcb_generate_id(connection); + xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, + 0, width, height, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, + screen->root_visual, mask, data); + xcb_map_window(connection, window); + xcb_flush(connection); + + xcb_visualtype_t *visual_type; + + for (xcb_depth_iterator_t depth_iter = + xcb_screen_allowed_depths_iterator(screen); + depth_iter.rem; xcb_depth_next(&depth_iter)) { + for (xcb_visualtype_iterator_t visual_iter = + xcb_depth_visuals_iterator(depth_iter.data); + visual_iter.rem; xcb_visualtype_next(&visual_iter)) { + if (screen->root_visual == visual_iter.data->visual_id) { + visual_type = visual_iter.data; + break; + } + } + } + + cairo_surface_t *surface = + cairo_xcb_surface_create(connection, window, visual_type, width, height); + + cairo_t *cairo = cairo_create(surface); + + xcb_generic_event_t *e; + + auto paint = [](cairo_t *cairo, int width, int height) { + cairo_set_source_rgb(cairo, 1, 1, 1); + cairo_paint(cairo); + cairo_set_source_rgb(cairo, 1, 1, 0); + cairo_set_line_width(cairo, 5); + cairo_move_to(cairo, width / 2.0, 0); + cairo_curve_to(cairo, width, 0, width, 0, width, height / 2.0); + cairo_curve_to(cairo, width, height, width, height, width / 2.0, height); + cairo_curve_to(cairo, 0, height, 0, height, 0, height / 2.0); + cairo_curve_to(cairo, 0, 0, 0, 0, width / 2.0, 0); + cairo_stroke(cairo); + }; + + while ((e = xcb_wait_for_event(connection))) { + switch (e->response_type & ~0x80) { + case XCB_EXPOSE: { + paint(cairo, width, height); + break; + } + case XCB_CONFIGURE_NOTIFY: { + xcb_configure_notify_event_t *event = + reinterpret_cast<xcb_configure_notify_event_t *>(e); + + width = event->width; + height = event->height; + + cairo_xcb_surface_set_size(surface, width, height); + + paint(cairo, width, height); + + break; + } + default: { + /* Unknown event type, ignore it */ + break; + } + } + /* Free the Generic Event */ + free(e); + } + + pause(); + + cairo_destroy(cairo); + cairo_surface_destroy(surface); + xcb_disconnect(connection); + + return 0; +} diff --git a/demos/xcb/start/CMakeLists.txt b/demos/xcb/start/CMakeLists.txt new file mode 100644 index 00000000..25e37be9 --- /dev/null +++ b/demos/xcb/start/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(demo-xcb-start main.cpp) +target_link_libraries(demo-xcb-start PUBLIC demo-xcb-base) diff --git a/demos/xcb/start/main.cpp b/demos/xcb/start/main.cpp new file mode 100644 index 00000000..c4e3761e --- /dev/null +++ b/demos/xcb/start/main.cpp @@ -0,0 +1,23 @@ +#include <unistd.h> +#include <xcb/xcb.h> + +int main() { + int screen_num; + xcb_connection_t* connection = xcb_connect(NULL, &screen_num); + const xcb_setup_t* setup = xcb_get_setup(connection); + xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); + xcb_screen_t* screen = iter.data; + + xcb_window_t window = xcb_generate_id(connection); + xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, + 0, 150, 150, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, + screen->root_visual, 0, NULL); + xcb_map_window(connection, window); + xcb_flush(connection); + + pause(); + + xcb_disconnect(connection); + + return 0; +} diff --git a/include/cru/common/Format.hpp b/include/cru/common/Format.hpp index 59f34036..d4da2208 100644 --- a/include/cru/common/Format.hpp +++ b/include/cru/common/Format.hpp @@ -13,11 +13,6 @@ namespace cru { template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> std::u16string ToUtf16String(T number) { - std::array<char, 40> buffer; - auto result = - std::to_chars(buffer.data(), buffer.data() + buffer.size(), number); - Ensures(result.ec == std::errc()); - std::string_view utf8_result(buffer.data(), result.ptr - buffer.data()); - return ToUtf16(utf8_result); + return ToUtf16(std::to_string(number)); } } // namespace cru diff --git a/include/cru/ui/style/StyleRuleSet.hpp b/include/cru/ui/style/StyleRuleSet.hpp index e62dd2de..b3c4f683 100644 --- a/include/cru/ui/style/StyleRuleSet.hpp +++ b/include/cru/ui/style/StyleRuleSet.hpp @@ -29,14 +29,6 @@ class StyleRuleSet : public Object { void AddStyleRule(StyleRule rule, gsl::index index); - template <typename Iter> - void AddStyleRuleRange(Iter start, Iter end, gsl::index index) { - Expects(index >= 0 && index <= GetSize()); - rules_.insert(rules_.cbegin() + index, std::move(start), std::move(end)); - UpdateChangeListener(); - UpdateStyle(); - } - void RemoveStyleRule(gsl::index index, gsl::index count = 1); void Clear() { RemoveStyleRule(0, GetSize()); } diff --git a/vcpkg b/vcpkg -Subproject acb6b10e7fdf5e8519c18398d0b069e1d58ca02 +Subproject 3166bcc15b156b57667d9e573fba9775ceef3eb |