scale groups of nodes is so cool!
This commit is contained in:
+52
-2
@@ -154,12 +154,15 @@ int main(){
|
||||
|
||||
app.sm.startSignalThread();
|
||||
|
||||
enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES};
|
||||
enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, SCALE_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES};
|
||||
InteractionState istate = HOVER_CANVAS;
|
||||
|
||||
Vec2Df select_start;
|
||||
Rectangle selection;
|
||||
|
||||
Vec2Df scale_start;
|
||||
Vec2Df scale_rectangle;
|
||||
|
||||
VEC_SPTR_Node copied_nodes;
|
||||
|
||||
|
||||
@@ -198,7 +201,7 @@ int main(){
|
||||
}
|
||||
|
||||
if(!mouse_down && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty()) istate = InteractionState::HOVER_CANVAS;
|
||||
if((mouse_clicked || mouse_down || mouse_released) && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty()) istate = InteractionState::DRAW_SELECTION;
|
||||
if((mouse_clicked || mouse_down || mouse_released) && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty() && istate != InteractionState::SCALE_SELECTION) istate = InteractionState::DRAW_SELECTION;
|
||||
|
||||
if(!hovering_nodes.empty() && !mouse_down && !mouse_right_down) istate = InteractionState::HOVER_NODE;
|
||||
if(!dragging_nodes.empty()) istate = InteractionState::DRAG_NODE;
|
||||
@@ -215,7 +218,54 @@ int main(){
|
||||
app.gm.setNodeMode(app.settings.mode);
|
||||
}
|
||||
|
||||
if(!selected_nodes.empty()){
|
||||
float offset = 30;
|
||||
Vec2Df corner_tl = {50000, 50000};
|
||||
Vec2Df corner_br = {-50000, -50000};
|
||||
std::shared_ptr<Node> node_tl;
|
||||
std::shared_ptr<Node> node_br;
|
||||
|
||||
for(auto n : selected_nodes){
|
||||
float x = n->position.x;
|
||||
float y = n->position.y;
|
||||
|
||||
if(x < corner_tl.x && y < corner_tl.y) node_tl = n;
|
||||
if(x > corner_br.x && y > corner_br.y) node_br = n;
|
||||
|
||||
if(x < corner_tl.x) corner_tl.x = x;
|
||||
if(x > corner_br.x) corner_br.x = x;
|
||||
if(y < corner_tl.y) corner_tl.y = y;
|
||||
if(y > corner_br.y) corner_br.y = y;
|
||||
}
|
||||
corner_tl -= Vec2Df(offset, offset);
|
||||
corner_br += Vec2Df(offset, offset);
|
||||
|
||||
DrawRectangleLines(corner_tl.x, corner_tl.y, (corner_br.x - corner_tl.x), (corner_br.y - corner_tl.y), VS_COLOR_LIGHTGREY);
|
||||
DrawCircleV(corner_br, 5, YELLOW);
|
||||
|
||||
if(istate == InteractionState::SCALE_SELECTION && mouse_released){
|
||||
istate = InteractionState::HOVER_CANVAS;
|
||||
}
|
||||
if(mouse_clicked && corner_br.dist(mouse_pos) < 10){
|
||||
scale_start = (corner_br - corner_tl);
|
||||
for(auto n : selected_nodes){
|
||||
n->drag_offset = n->position - node_tl->position;
|
||||
}
|
||||
istate = InteractionState::SCALE_SELECTION;
|
||||
}
|
||||
if(istate == InteractionState::SCALE_SELECTION && mouse_down){
|
||||
Vec2Df scale = (mouse_pos - corner_tl) / scale_start;
|
||||
if(IsKeyDown(KEY_LEFT_SHIFT)) scale.y = scale.x;
|
||||
DrawText(std::format("{:.2f} {:.2f}", scale.x, scale.y).c_str(), corner_br.x+5, corner_br.y+5, 10, RED);
|
||||
for(auto n : selected_nodes){
|
||||
n->position = node_tl->position + (n->drag_offset * scale);
|
||||
}
|
||||
istate = InteractionState::SCALE_SELECTION;
|
||||
}
|
||||
}
|
||||
|
||||
switch(istate){
|
||||
case InteractionState::SCALE_SELECTION:
|
||||
case InteractionState::HOVER_CANVAS:
|
||||
{
|
||||
for(auto &n : app.gm.nodes){
|
||||
|
||||
Reference in New Issue
Block a user