two node snap for triangles
This commit is contained in:
+10
-9
@@ -246,20 +246,21 @@ namespace VISEQ::GRAPH {
|
||||
}
|
||||
|
||||
void drawNodes(Vec2Df mouse_pos, Camera2D camera){
|
||||
auto neighbors = nodes | RANGE_FILTER([](SPTR_Node n){ return !n->dragging && !n->selected;}) | std::ranges::to<VEC_SPTR_Node>();
|
||||
float min_d = 480;
|
||||
for(auto n : nodes){
|
||||
if(n->dragging){
|
||||
std::sort(neighbors.begin(), neighbors.end(), [n, mouse_pos](SPTR_Node na, SPTR_Node nb){ return na->position.dist(mouse_pos) < nb->position.dist(mouse_pos);});
|
||||
if(neighbors.size() > 1){
|
||||
min_d = neighbors.front()->position.dist(mouse_pos);
|
||||
n->neighbor = neighbors.front();
|
||||
DrawCircleLinesV(n->neighbor->position, 20.0f, VS_COLOR_PINK);
|
||||
for(auto nb : neighbors){
|
||||
auto neighbors_local = nodes | RANGE_FILTER([mouse_pos](SPTR_Node n){ return !n->dragging && !n->selected && n->position.dist(mouse_pos) < 960;}) | std::ranges::to<VEC_SPTR_Node>();
|
||||
std::sort(neighbors_local.begin(), neighbors_local.end(), [n, mouse_pos](SPTR_Node na, SPTR_Node nb){ return na->position.dist(mouse_pos) < nb->position.dist(mouse_pos);});
|
||||
if(!neighbors_local.empty()){
|
||||
min_d = neighbors_local.front()->position.dist(mouse_pos);
|
||||
DrawCircleLinesV(neighbors_local.front()->position, 22.0f, VS_COLOR_PINK);
|
||||
n->neighbors = neighbors_local | std::ranges::views::filter([mouse_pos, min_d](SPTR_Node n){return abs(n->position.dist(mouse_pos) - min_d) < 5;}) | std::ranges::to<VEC_SPTR_Node>();
|
||||
for(auto nb : n->neighbors){
|
||||
DrawCircleLinesV(nb->position, 20.0f, VS_COLOR_RED);
|
||||
float d = nb->position.dist(mouse_pos);
|
||||
float dn = nb->position.dist(n->position);
|
||||
if(d > 0 && d < min_d*1.5 && d < 960) {
|
||||
std::string frac = MIDI::Fractions.at((int)Clamp(round(dn/60) - 1, 0, 31));
|
||||
std::string frac = MIDI::Fractions.at(std::clamp<int>(round(dn/60) - 1, 0, 31));
|
||||
Vector2 text_length = MeasureTextEx(GetFontDefault(), std::format("{:.1f}",dn).c_str(), 10.0f, 2.0f);
|
||||
Vector2 text_length_frac = MeasureTextEx(GetFontDefault(), frac.c_str(), 10.0f, 2.0f);
|
||||
|
||||
@@ -270,7 +271,7 @@ namespace VISEQ::GRAPH {
|
||||
|
||||
float rotation = Vector2Angle((Vector2){1,0}, (n->position - nb->position)) * RAD2DEG;
|
||||
DrawTextPro(GetFontDefault(), std::format("{:.1f}",dn).c_str(), text_position, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK);
|
||||
if(nb == neighbors.front() && IsKeyDown(KEY_LEFT_SHIFT)) DrawTextPro(GetFontDefault(), frac.c_str(), text_position_frac, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK);
|
||||
if(IsKeyDown(KEY_LEFT_SHIFT)) DrawTextPro(GetFontDefault(), frac.c_str(), text_position_frac, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK);
|
||||
Vec2Df n_position = n->position - ((n->position - nb->position)).norm() * 20.0f;
|
||||
Vec2Df nb_position = nb->position - ((nb->position - n->position)).norm() * 20.0f;
|
||||
DrawLineV(n_position, nb_position, VS_COLOR_PINK);
|
||||
|
||||
Reference in New Issue
Block a user