1#include "canvas_overlay.h"
10 blit_style_.use_blending =
true;
11 blit_style_.use_texture =
true;
12 blit_style_.feather_width = 0.0f;
19 frame_buffer_.add_attachment(
"color",
"uint8[R,G,B,A]");
21 success &= frame_buffer_.
ensure(ctx);
23 content_canvas.set_apply_gamma(
false);
24 success &= content_canvas.init(ctx);
26 overlay_canvas.register_shader(
"rectangle", cgv::g2d::shaders::rectangle);
27 success &= overlay_canvas.init(ctx);
36 content_canvas.destruct(ctx);
37 overlay_canvas.destruct(ctx);
38 frame_buffer_.destruct(ctx);
49 draw_in_finish_frame = enable;
62void canvas_overlay::register_shader(
const std::string& name,
const std::string& filename) {
64 content_canvas.register_shader(
name, filename);
67void canvas_overlay::post_damage(
bool redraw) {
74 ivec2 pos = cgv::g2d::change_origin(mouse_pos,
get_viewport_size(), cgv::g2d::CoordinateOrigin::kUpperLeft, overlay_canvas.get_origin_setting());
76 pos = cgv::g2d::change_origin(pos,
get_rectangle().size, overlay_canvas.get_origin_setting(), content_canvas.get_origin_setting());
81 ivec2 test_pos = cgv::g2d::change_origin(mouse_pos,
get_viewport_size(), cgv::g2d::CoordinateOrigin::kUpperLeft, overlay_canvas.get_origin_setting());
89bool canvas_overlay::ensure_layout(
context& ctx) {
91 if(overlay::ensure_layout(ctx) || recreate_layout_requested_) {
92 recreate_layout_requested_ =
false;
105void canvas_overlay::post_recreate_layout() {
106 recreate_layout_requested_ =
true;
109void canvas_overlay::clear_damage() {
113bool canvas_overlay::is_damaged()
const {
117void canvas_overlay::begin_content(
context& ctx,
bool clear_frame_buffer) {
119 frame_buffer_.enable(ctx);
120 if(clear_frame_buffer) {
128void canvas_overlay::end_content(
context& ctx,
bool keep_damage) {
130 frame_buffer_.disable(ctx);
131 has_damage_ = keep_damage;
134void canvas_overlay::draw_impl(
context& ctx) {
143 BF_ONE_MINUS_SRC_ALPHA,
145 BF_ONE_MINUS_SRC_ALPHA
156 overlay_canvas.enable_shader(ctx,
"rectangle");
157 overlay_canvas.set_style(ctx, blit_style_);
158 frame_buffer_.enable_attachment(ctx,
"color", 0);
160 frame_buffer_.disable_attachment(ctx,
"color");
161 overlay_canvas.disable_current_shader(ctx);
std::string name
store the name as a string
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
bool init(cgv::render::context &ctx) override
this method is called after creation or recreation of the context, return whether all necessary funct...
ivec2 get_local_mouse_pos(ivec2 mouse_pos) const override
return the mouse position local to the container of this overlay taking the canvas origin into accoun...
virtual void handle_member_change(cgv::data::informed_ptr ptr) override
implement to handle member changes
void finish_frame(cgv::render::context &) override
draw the content of the canvas overlay either in finish_frame
bool is_hit_local(const ivec2 &local_mouse_pos) const
See is_hit.
canvas_overlay()
creates an overlay in the bottom left corner with zero size using a canvas for 2d drawing
bool is_hit(const ivec2 &mouse_pos) const override
Test if the mouse pointer is hovering over this overlay and returns true if this is the case.
virtual void on_set(void *member_ptr) override
default implementation of that calls handle_member_change and afterwards upates the member in the gui...
void after_finish(cgv::render::context &) override
or in after_finish, what is the default
virtual void draw_content(cgv::render::context &ctx)=0
draw_content is implemented by decendent classes
void set_draw_in_finish_frame(bool enable=true)
set the drawing of the content to be in finish_frame (enable = true) or after_finish (enable = false)
void clear(cgv::render::context &ctx) override
clear all objects living in the context like textures or display lists
cgv::g2d::irect get_rectangle() const
return the current rectangle area (in screen coordinates) of the overlay taking layout into account
ivec2 get_viewport_size() const
return the current viewport size
base class for all drawables, which is independent of the used rendering API.
virtual void set_blend_func(BlendFunction src_factor, BlendFunction dst_factor)
set the blend function
void pop_bg_color()
pop the top of the current background color from the stack
void push_depth_test_state()
push a copy of the current depth test state onto the stack saved attributes: depth test enablement,...
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
virtual void disable_depth_test()
disable the depth test
void pop_blend_state()
pop the top of the current culling state from the stack
virtual void clear_background(bool color_flag, bool depth_flag, bool stencil_flag=false, bool accum_flag=false)=0
clear the buffer contents of the flagged buffers to the set background colors
void pop_depth_test_state()
pop the top of the current depth test state from the stack
virtual void set_bg_color(vec4 rgba)
set a user defined background color
virtual void set_blend_state(BlendState state)
set the complete blend state
void push_bg_color()
push a copy of the current background color onto the stack
void post_redraw()
posts a redraw event to the current context if one is available
bool is_visible() const
check whether the drawable is visible
bool ensure(context &ctx)
Ensure the framebuffer is constructed with the specified size.
void set_size(const ivec2 &size)
Set the size of the framebuffer attachments.
namespace for api independent GPU programming
this header is dependency free
Represents a blend state used to configure fragment blending.