-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Groß
committed
Nov 26, 2023
1 parent
8d484ac
commit bb61ee9
Showing
20 changed files
with
1,120 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
file(GLOB_RECURSE SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cxx") | ||
file(GLOB_RECURSE HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h") | ||
|
||
cgv_add_target(cg_g2d | ||
TYPE plugin NO_EXECUTABLE | ||
SOURCES ${SOURCES} | ||
HEADERS ${HEADERS} | ||
DEPENDENCIES | ||
cgv_g2d cgv_gl cgv_gui cgv_render cgv_media cgv_utils cgv_os cgv_base | ||
cgv_data cgv_type cgv_signal cgv_reflect | ||
|
||
OVERRIDE_SHARED_EXPORT_DEFINE "CG_G2D_EXPORTS;CGV_GUI_G2D_EXPORTS" | ||
OVERRIDE_FORCE_STATIC_DEFINE CGV_GUI_G2D_FORCE_STATIC | ||
) | ||
|
||
install(TARGETS cg_g2d EXPORT cgv_plugins DESTINATION ${CGV_BIN_DEST}) | ||
install(TARGETS cg_g2d_static EXPORT cgv_plugins DESTINATION ${CGV_BIN_DEST}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@= | ||
projectType="plugin"; | ||
projectName="cg_g2d"; | ||
projectGUID="D008EC3A-0C5B-46A8-A3CA-B28268E2A7C2"; | ||
addIncDirs=[CGV_DIR."/libs"]; | ||
addProjectDirs=[CGV_DIR."/libs/cgv_gl"]; | ||
addProjectDeps=["cgv_gui","cgv_render", "cgv_media", "cgv_utils", "cgv_os","cgv_base","cgv_data", "cgv_type","cgv_signal", "cgv_reflect", "cgv_gl", "cgv_g2d"]; | ||
addSharedDefines=["CGV_GUI_G2D_EXPORTS"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <cgv/gui/event.h> | ||
#include <cgv/gui/key_event.h> | ||
#include <cgv/gui/mouse_event.h> | ||
#include <cgv/render/render_types.h> | ||
#include <cgv_g2d/canvas.h> | ||
#include <cgv_g2d/rect.h> | ||
|
||
#include "styles.h" | ||
|
||
namespace cg { | ||
namespace g2d { | ||
|
||
class control_base { | ||
private: | ||
typedef std::function<void(control_base*, void*)> callback_t; | ||
callback_t _callback; | ||
void* _user_data = nullptr; | ||
|
||
protected: | ||
std::string label; | ||
cgv::g2d::irect rectangle; | ||
|
||
public: | ||
control_base(const std::string& label, cgv::g2d::irect rectangle) : label(label), rectangle(rectangle) {} | ||
|
||
virtual ~control_base() {} | ||
|
||
void set_label(const std::string& label) { | ||
this->label = label; | ||
} | ||
|
||
virtual void update() = 0; | ||
|
||
void callback(callback_t c, void* p) { | ||
_callback = c; | ||
_user_data = p; | ||
} | ||
|
||
void do_callback() { | ||
if(_callback) | ||
_callback(this, _user_data); | ||
} | ||
|
||
virtual bool handle_key_event(cgv::gui::key_event& e) { return false; } | ||
virtual bool handle_mouse_event(cgv::gui::mouse_event& e, cgv::render::ivec2 mouse_position) { return false; } | ||
|
||
virtual void draw(cgv::render::context& ctx, cgv::g2d::canvas& cnvs, const styles& style) {} | ||
}; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include "control_manager.h" | ||
|
||
//#include <cgv_g2d/utils2d.h> | ||
|
||
#include <cgv_g2d/msdf_font.h> | ||
#include <cgv_g2d/msdf_gl_canvas_font_renderer.h> | ||
|
||
using namespace cgv::render; | ||
|
||
namespace cg { | ||
namespace g2d { | ||
|
||
bool control_manager::init(context& ctx) { | ||
|
||
cgv::g2d::ref_msdf_gl_canvas_font_renderer(ctx, 1); | ||
cgv::g2d::ref_msdf_font_regular(ctx, 1); | ||
|
||
//shaders.add("rectangle", shaders::rectangle); | ||
//shaders.add("line", shaders::line, { { "MODE", "0" } }); | ||
//bool success = shaders.load_all(ctx, "control_manager::init()"); | ||
|
||
//success &= label_texts.init(ctx); | ||
//success &= value_texts.init(ctx); | ||
|
||
init_styles(); | ||
|
||
return true;// success; | ||
} | ||
|
||
void control_manager::destruct(context& ctx) { | ||
|
||
cgv::g2d::ref_msdf_gl_canvas_font_renderer(ctx, -1); | ||
cgv::g2d::ref_msdf_font_regular(ctx, -1); | ||
|
||
//shaders.clear(ctx); | ||
} | ||
|
||
void control_manager::clear() { | ||
|
||
controls.clear(); | ||
g2d_controls.clear(); | ||
} | ||
|
||
bool control_manager::handle(cgv::gui::event& e, const ivec2& viewport_size, const cgv::g2d::irect& container) { | ||
|
||
unsigned et = e.get_kind(); | ||
|
||
if(et == cgv::gui::EID_KEY) { | ||
cgv::gui::key_event& ke = dynamic_cast<cgv::gui::key_event&>(e); | ||
|
||
for(auto& control : g2d_controls) { | ||
if(control->handle_key_event(ke)) | ||
return true; | ||
} | ||
} else if(et == cgv::gui::EID_MOUSE) { | ||
cgv::gui::mouse_event& me = dynamic_cast<cgv::gui::mouse_event&>(e); | ||
ivec2 mouse_position = get_local_mouse_pos(ivec2(me.get_x(), me.get_y()), viewport_size, container); | ||
|
||
for(auto& control : g2d_controls) { | ||
if(control->handle_mouse_event(me, mouse_position)) | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void control_manager::draw(context& ctx, cgv::g2d::canvas& cnvs) { | ||
|
||
for(auto& control : g2d_controls) | ||
control->draw(ctx, cnvs, style); | ||
} | ||
|
||
void control_manager::init_styles() { | ||
|
||
auto& ti = cgv::gui::theme_info::instance(); | ||
|
||
style.control_box.use_fill_color = true; | ||
style.control_box.fill_color = ti.control(); | ||
style.control_box.feather_width = 1.0f; | ||
//style.control_box.border_radius = 5.0f; | ||
//style.control_box.use_blending = true; | ||
|
||
style.text = cgv::g2d::text2d_style::preset_default(ti.text()); | ||
style.text.font_size = 12.0f; | ||
|
||
style.colored_box = style.control_box; | ||
style.colored_box.use_fill_color = false; | ||
|
||
style.control_color = ti.control(); | ||
style.background_color = ti.background(); | ||
style.shadow_color = ti.shadow(); | ||
} | ||
|
||
void control_manager::handle_theme_change(const cgv::gui::theme_info& theme) { | ||
|
||
init_styles(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.