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);
54void canvas_overlay::register_shader(
const std::string& name,
const std::string& filename) {
56 content_canvas.register_shader(
name, filename);
59void canvas_overlay::post_damage(
bool redraw) {
66 ivec2 pos = cgv::g2d::apply_origin_setting(mouse_pos,
get_viewport_size(), cgv::g2d::OriginSetting::kUpperLeft, overlay_canvas.get_origin_setting());
68 pos = cgv::g2d::apply_origin_setting(pos,
get_rectangle().size, overlay_canvas.get_origin_setting(), content_canvas.get_origin_setting());
73 ivec2 test_pos = cgv::g2d::apply_origin_setting(mouse_pos,
get_viewport_size(), cgv::g2d::OriginSetting::kUpperLeft, overlay_canvas.get_origin_setting());
77bool canvas_overlay::ensure_layout(
context& ctx) {
79 if(overlay::ensure_layout(ctx) || recreate_layout_requested_) {
80 recreate_layout_requested_ =
false;
84 frame_buffer_.ensure(ctx);
93void canvas_overlay::post_recreate_layout() {
94 recreate_layout_requested_ =
true;
97void canvas_overlay::clear_damage() {
101bool canvas_overlay::is_damaged()
const {
105void canvas_overlay::begin_content(
context& ctx,
bool clear_frame_buffer) {
107 frame_buffer_.enable(ctx);
108 if(clear_frame_buffer) {
116void canvas_overlay::end_content(
context& ctx,
bool keep_damage) {
118 frame_buffer_.disable(ctx);
119 has_damage_ = keep_damage;
122void canvas_overlay::draw_impl(
context& ctx) {
131 BF_ONE_MINUS_SRC_ALPHA,
133 BF_ONE_MINUS_SRC_ALPHA
144 overlay_canvas.enable_shader(ctx,
"rectangle");
145 overlay_canvas.set_style(ctx, blit_style_);
146 frame_buffer_.enable_attachment(ctx,
"color", 0);
148 frame_buffer_.disable_attachment(ctx,
"color");
149 overlay_canvas.disable_current_shader(ctx);
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.
void clear(cgv::render::context &ctx) override
clear all objects living in the context like textures or display lists
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(const cgv::utils::pointer_test &m) override
implement to handle member changes
void after_finish(cgv::render::context &) override
draw the content of the canvas overlay
virtual void on_set(void *member_ptr) override
default implementation of that calls handle_member_change and afterwards upates the member in the gui...
bool init(cgv::render::context &ctx) override
this method is called after creation or recreation of the context, return whether all necessary funct...
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
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
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 set_size(const ivec2 &size)
Sets the size of the framebuffer renderbuffers.
namespace for api independent GPU programming
Represents a blend state used to configure fragment blending.