Files
mirage/example/test_thread/main.cpp
daiqingshuang 9023922ef7 Refactor widget framework for thread safety and state management
- Updated v_stack.h to use threading::main_property for spacing management, ensuring automatic dirty marking on changes.
- Enhanced render_collector.h with threading::thread_bound for thread safety, added documentation for thread usage.
- Modified widget_state.h to include previous_aabb for dirty region calculations.
- Implemented update_previous_aabb method in widget_state_store to track previous AABB for widgets.
- Refactored viewport_cache to utilize threading::main_property for caching and visibility management.
- Updated widget_base.h to use threading::main_property for widget attributes, ensuring thread-safe access.
- Enhanced widget_context.h with threading::property for managing state changes.
- Refactored imager and scrollbar widgets to utilize new property management for state consistency.
- Added comprehensive documentation for thread safety and usage across the widget framework.
2025-12-12 14:04:40 +08:00

75 lines
2.6 KiB
C++

#include "application.h"
#include "modifier_helper.h"
#include "containers/overlay.h"
#include "containers/scroll_box/scroll_box.h"
#include "image/texture_manager.h"
#include "text/font_manager.h"
#include "widgets/imager.h"
#include "widgets/mask.h"
#include "widgets/post_process.h"
#include "widgets/text_widget.h"
using namespace mirage;
int main(int argc, char* argv[]) {
app::application app;
app::application_config config;
config.title = "Test Thread";
config.width = 800;
config.height = 600;
config.enable_multithreading = true;
config.enable_validation = true;
config.vsync = true;
if (!app.initialize(config)) {
return -1;
}
// auto texture_id = app.texture_mgr()->load_texture("D:\\G2uY1fJa8AAOucs.jpg").value();
auto texture_id = app.texture_mgr()->load_texture("D:\\screenshot-20251128-165627.png").value();
auto tex_size = app.texture_mgr()->get_texture(texture_id)->size().cast<float>();
// 加载字体
uint32_t font_id;
auto font_result = app.font_mgr()->load_font(R"(C:\Windows\Fonts\SIMYOU.TTF)");
if (font_result.has_value()) {
font_id = font_result.value();
}
auto root_widget = new_widget<scroll_box>()[
new_widget<text_widget>()->font_id(font_id).text("你好,我们在此相遇").font_size(24),
new_widget<overlay>()[
new_widget<imager>()->texture_id(texture_id).source_size(tex_size).scale(scale_mode::contain),
// 圆形遮罩
new_widget<mask>()[
// 模糊效果 (blur)
new_widget<post_process>()->blur(40.0f)
]->circle() | align(alignment::center_left)
],
new_widget<overlay>()[
new_widget<imager>()->texture_id(texture_id).source_size(tex_size).scale(scale_mode::contain),
new_widget<post_process>()->vignette()
],
new_widget<overlay>()[
new_widget<imager>()->texture_id(texture_id).source_size(tex_size).scale(scale_mode::contain),
new_widget<post_process>()->chromatic_aberration(10, 1)
],
new_widget<overlay>()[
new_widget<imager>()->texture_id(texture_id).source_size(tex_size).scale(scale_mode::contain),
new_widget<post_process>()->noise(20.0f, 1.f, true)
],
new_widget<overlay>()[
new_widget<imager>()->texture_id(texture_id).source_size(tex_size).scale(scale_mode::contain),
new_widget<post_process>()->color_adjust(0.1f, 1.5f, 1.5f, 2.2f)
],
new_widget<overlay>()[
new_widget<imager>()->texture_id(texture_id).source_size(tex_size).scale(scale_mode::contain),
new_widget<post_process>()->color_tint(color::from_rgba(255, 100, 100, 255), 0.3f, blend_mode::overlay)
]
];
app.set_root_widget(root_widget.ptr());
app.run();
}