Skip to content

Commit

Permalink
Rename and change some methods of rect class
Browse files Browse the repository at this point in the history
  • Loading branch information
David Groß committed Dec 8, 2023
1 parent 18c28a6 commit 8fdd398
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 158 deletions.
12 changes: 6 additions & 6 deletions libs/cgv_app/color_map_editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool color_map_editor::handle_event(cgv::gui::event& e) {
if (ma == cgv::gui::MA_PRESS) {
ivec2 mpos = get_local_mouse_pos(ivec2(me.get_x(), me.get_y()));

request_clear_selection = get_overlay_rectangle().is_inside(mpos);
request_clear_selection = get_overlay_rectangle().contains(mpos);

switch (modifiers) {
case cgv::gui::EM_CTRL:
Expand Down Expand Up @@ -401,7 +401,7 @@ void color_map_editor::draw_content(cgv::render::context& ctx) {
static_cast<ivec2>(value_labels.get_text_render_size(0, value_label_style.font_size))
);
rectangle.translate(0, 5);
rectangle.resize(10, 6);
rectangle.size += ivec2(10, 6);

content_canvas.draw_shape(ctx, rectangle);
content_canvas.disable_current_shader(ctx);
Expand Down Expand Up @@ -678,14 +678,14 @@ void color_map_editor::add_point(const vec2& pos) {
if(cmc.cm) {
ivec2 test_pos = static_cast<ivec2>(pos);

if(layout.color_editor_rect.is_inside(test_pos)) {
if(layout.color_editor_rect.contains(test_pos)) {
// color point
color_point p;
p.position = ivec2(int(pos.x()), layout.color_handles_rect.y());
p.update_val(layout);
p.col = cmc.cm->interpolate_color(p.val);
cmc.color_points.add(p);
} else if(supports_opacity && layout.opacity_editor_rect.is_inside(test_pos)) {
} else if(supports_opacity && layout.opacity_editor_rect.contains(test_pos)) {
// opacity point
opacity_point p;
p.position = pos;
Expand Down Expand Up @@ -742,13 +742,13 @@ cgv::g2d::draggable* color_map_editor::get_hit_point(const color_map_editor::vec

for(unsigned i = 0; i < cmc.color_points.size(); ++i) {
color_point& p = cmc.color_points[i];
if(p.is_inside(pos))
if(p.contains(pos))
hit = &p;
}

for(unsigned i = 0; i < cmc.opacity_points.size(); ++i) {
opacity_point& p = cmc.opacity_points[i];
if(p.is_inside(pos))
if(p.contains(pos))
hit = &p;
}

Expand Down
10 changes: 5 additions & 5 deletions libs/cgv_app/color_selector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ bool color_selector::handle_event(cgv::gui::event& e) {
int hit_index = -1;
cgv::g2d::irect hit_rect;

if(layout.color_rect.is_inside(mpos)) {
if(layout.color_rect.contains(mpos)) {
hit_index = 0;
hit_rect = layout.color_rect;
}

if(layout.hue_rect.is_inside(mpos)) {
if(layout.hue_rect.contains(mpos)) {
hit_index = 1;
hit_rect = layout.hue_rect;
}

if(layout.opacity_rect.is_inside(mpos)) {
if(layout.opacity_rect.contains(mpos)) {
hit_index = 2;
hit_rect = layout.opacity_rect;
}
Expand Down Expand Up @@ -295,7 +295,7 @@ void color_selector::update_layout(const ivec2& parent_size) {

cgv::g2d::irect content_rect = l.border_rect;
content_rect.translate(1, 1);
content_rect.resize(-2, -2);
content_rect.size -= 2;

int mult = has_opacity ? 2 : 1;

Expand All @@ -308,7 +308,7 @@ void color_selector::update_layout(const ivec2& parent_size) {
}

l.color_rect = content_rect;
l.color_rect.resize(-21 * mult, 0);
l.color_rect.w() -= 21 * mult;

l.preview_rect.position = ivec2(l.padding);
l.preview_rect.size = ivec2(20, 20);
Expand Down
4 changes: 2 additions & 2 deletions libs/cgv_app/color_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class CGV_API color_selector : public canvas_overlay {
}
}

bool is_inside(const vec2& mp) const {
bool contains(const vec2& mp) const override {
if(is_rectangular) {
return draggable::is_inside(mp);
return draggable::contains(mp);
} else {
const auto dist = length(mp - center());
return dist <= 0.5f*size.x();
Expand Down
2 changes: 1 addition & 1 deletion libs/cgv_app/overlay.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bool overlay::ensure_viewport(cgv::render::context& ctx) {
bool overlay::is_hit(const ivec2& mouse_pos) const {

ivec2 test_pos = cgv::g2d::get_transformed_mouse_pos(mouse_pos, last_viewport_size);
return container.is_inside(test_pos);
return container.contains(test_pos);
};

bool overlay::begin_overlay_gui() {
Expand Down
2 changes: 1 addition & 1 deletion libs/cgv_app/overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <cgv/render/context.h>
#include <cgv/render/drawable.h>
#include <cgv/utils/pointer_test.h>
#include <cgv_g2d/rect.h>
#include <cgv_g2d/trect.h>
#include <cgv_g2d/utils2d.h>

#include "lib_begin.h"
Expand Down
6 changes: 3 additions & 3 deletions libs/cgv_g2d/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cgv/render/render_types.h>
#include <cgv/render/shader_library.h>
#include <cgv_gl/gl/gl_context.h>
#include <cgv_g2d/rect.h>
#include <cgv_g2d/trect.h>
#include <cgv_g2d/shaders2d.h>
#include <cgv_g2d/shape2d_styles.h>
#include <cgv_g2d/utils2d.h>
Expand Down Expand Up @@ -79,7 +79,7 @@ class CGV_API canvas : public cgv::render::render_types {
void set_style(cgv::render::context& ctx, const shape2d_style& style);

template<typename T>
void draw_shape(const cgv::render::context& ctx, const rect<T>& r) {
void draw_shape(const cgv::render::context& ctx, const trect<T>& r) {
draw_shape(ctx, r.position, r.size);
}

Expand Down Expand Up @@ -107,7 +107,7 @@ class CGV_API canvas : public cgv::render::render_types {
}

template<typename T>
void draw_shape(const cgv::render::context& ctx, const rect<T>& r, const rgba& color) {
void draw_shape(const cgv::render::context& ctx, const trect<T>& r, const rgba& color) {
draw_shape(ctx, r.position, r.size, color);
}

Expand Down
5 changes: 2 additions & 3 deletions libs/cgv_g2d/draggable.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "rect.h"
#include "trect.h"
#include "shape.h"

#include "lib_begin.h"
Expand Down Expand Up @@ -42,8 +42,7 @@ struct CGV_API circle_draggable : public draggable {

circle_draggable(const cgv::render::vec2& position, const cgv::render::vec2& size);

inline bool is_inside(const cgv::render::vec2& mp) const override {

bool contains(const cgv::render::vec2& mp) const override {
float dist = length(mp - center());
return dist <= 0.5f * size.x();
}
Expand Down
6 changes: 3 additions & 3 deletions libs/cgv_g2d/draggable_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "canvas.h"
#include "draggable.h"
#include "rect.h"
#include "trect.h"
#include "utils2d.h"

#include "lib_begin.h"
Expand Down Expand Up @@ -49,7 +49,7 @@ class draggable_collection : public cgv::render::render_types {
for(unsigned i = 0; i < draggables.size(); ++i) {
ptr_type d = get_ptr(draggables[i]);

if(d && d->is_inside(pos))
if(d && d->contains(pos))
hit = d;
}
return hit;
Expand Down Expand Up @@ -167,7 +167,7 @@ class draggable_collection : public cgv::render::render_types {

if(me.get_button() == cgv::gui::MB_LEFT_BUTTON) {
if(me.get_action() == cgv::gui::MA_PRESS) {
press_inside = has_constraint && !use_individual_constraints ? constraint_area.is_inside(mouse_position) : true;
press_inside = has_constraint && !use_individual_constraints ? constraint_area.contains(mouse_position) : true;
dragged = get_hit_draggable(mouse_position);

press_inside = press_inside || dragged;
Expand Down
113 changes: 0 additions & 113 deletions libs/cgv_g2d/rect.h

This file was deleted.

17 changes: 8 additions & 9 deletions libs/cgv_g2d/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@

#include <cgv/render/render_types.h>

#include "rect.h"
#include "trect.h"

#include "lib_begin.h"

namespace cgv {
namespace g2d {

struct CGV_API shape_base : public frect {
struct CGV_API shape_base : public rect {

using frect::frect;
using rect::rect;

bool position_is_center = false;

inline cgv::render::ivec2 int_position() const { return static_cast<cgv::render::ivec2>(position); }
cgv::render::ivec2 int_position() const { return static_cast<cgv::render::ivec2>(position); }

template<typename T>
inline cgv::render::ivec2 int_size() const { return static_cast<cgv::render::ivec2>(size); }
cgv::render::ivec2 int_size() const { return static_cast<cgv::render::ivec2>(size); }

inline cgv::render::vec2 center() const { return position_is_center ? position : frect::center(); }
cgv::render::vec2 center() const { return position_is_center ? position : rect::center(); }

inline virtual bool is_inside(const cgv::render::vec2& query_pos) const {

return frect::is_inside(position_is_center ? query_pos + frect::center() - position : query_pos);
virtual bool contains(const cgv::render::vec2& query_pos) const {
return rect::contains(position_is_center ? query_pos + rect::center() - position : query_pos);
}
};

Expand Down
Loading

0 comments on commit 8fdd398

Please sign in to comment.