two node snap for triangles
This commit is contained in:
@@ -13,9 +13,7 @@ namespace VISEQ::GRAPH {
|
||||
GraphItem(const GraphItem& G) {
|
||||
newId(-1);
|
||||
graphItemType = G.graphItemType;
|
||||
neighbors = G.neighbors;
|
||||
}
|
||||
std::vector<std::shared_ptr<GraphItem>> neighbors;
|
||||
GraphItemType graphItemType;
|
||||
|
||||
int id = 0;
|
||||
|
||||
+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);
|
||||
|
||||
+22
-4
@@ -289,12 +289,30 @@ int main(){
|
||||
dragNode->position.x = round((mouse_pos.x + dragNode->drag_offset.x) / app.settings.grid) * app.settings.grid;
|
||||
dragNode->position.y = round((mouse_pos.y + dragNode->drag_offset.y) / app.settings.grid) * app.settings.grid;
|
||||
} else if(IsKeyDown(KEY_LEFT_SHIFT)){
|
||||
float steps = round((dragNode->neighbor->position.dist(mouse_pos)) / app.settings.grid) * app.settings.grid;
|
||||
float pol_r = steps;
|
||||
float pol_theta = Vector2Angle(Vec2Df{1,0},(mouse_pos - dragNode->neighbor->position));
|
||||
float steps = round((dragNode->neighbors.front()->position.dist(mouse_pos)) / app.settings.grid) * app.settings.grid;
|
||||
if(dragNode->neighbors.size() > 1){
|
||||
Vec2Df dn1 = dragNode->neighbors[0]->position;
|
||||
Vec2Df dn2 = dragNode->neighbors[1]->position;
|
||||
Vec2Df v1_orth = dn1.center(dn2);
|
||||
|
||||
if(dn1.x < dn2.x) std::swap(dn1,dn2);
|
||||
|
||||
float dist = dn1.dist(dn2);
|
||||
float dist_orth = std::sqrt(std::pow(steps,2) - std::pow(dist/2,2));
|
||||
|
||||
if(mouse_pos.y < v1_orth.y) dist_orth *= -1;
|
||||
|
||||
Vec2Df v1_orth_t = v1_orth + (dn1-dn2).norm().orth() * dist_orth;
|
||||
DrawLineV(dn1, dn2, VS_COLOR_RED);
|
||||
DrawLineV(v1_orth, v1_orth_t, VS_COLOR_RED);
|
||||
DrawCircleV(v1_orth, 3.0f, VS_COLOR_RED);
|
||||
dragNode->position = v1_orth_t;
|
||||
} else if(!dragNode->neighbors.empty()){
|
||||
float pol_r = steps;
|
||||
float pol_theta = Vector2Angle(Vec2Df{1,0},(mouse_pos - dragNode->neighbors.front()->position));
|
||||
Vec2Df polar = VISEQ::VMATH::polarToCartesian(pol_r, pol_theta);
|
||||
dragNode->position = dragNode->neighbor->position + polar;
|
||||
dragNode->position = dragNode->neighbors.front()->position + polar;
|
||||
}
|
||||
} else {
|
||||
dragNode->position = mouse_pos + dragNode->drag_offset;
|
||||
}
|
||||
|
||||
+1
-2
@@ -22,8 +22,7 @@ namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
NodeType nodeType;
|
||||
|
||||
std::shared_ptr<Node> neighbor;
|
||||
|
||||
std::vector<std::shared_ptr<Node>> neighbors;
|
||||
std::vector<std::shared_ptr<VISEQ::GRAPH::EDGES::Edge>> connections;
|
||||
|
||||
Distribution distributionMode = Distribution::GEOMETRIC;
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ namespace VISEQ::APP {
|
||||
}
|
||||
|
||||
new_node->copied = false;
|
||||
new_node->selected = false;
|
||||
new_node->selected = true;
|
||||
|
||||
for(auto c : copy_connections){
|
||||
if(c->start == old_node) {
|
||||
|
||||
Reference in New Issue
Block a user