Add switch in reverse order to schema mode
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 29 Mar 2025 21:14:40 +0000 (22:14 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 29 Mar 2025 21:14:40 +0000 (22:14 +0100)
src/schema_mode.c

index 7e4d7382e08171bfd3dc185efe616660cd7286ca..4b3f85ea026c4ca6627ba6bf9b4fb0358f77a322 100644 (file)
@@ -321,7 +321,7 @@ void        schema_user_draw_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets,
        return ;
 }
 
-void schema_switch_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+void schema_switch_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
 {
        t_node  *chosen_node;
 
@@ -338,6 +338,23 @@ void schema_switch_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_
        return ;
 }
 
+void schema_reverse_switch_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+{
+       t_node  *chosen_node;
+
+       chosen_node = find_node_at_pos(nodes, pos);
+       if (!chosen_node)
+               return ;
+       if (chosen_node->set_state == off)
+               chosen_node->set_state = unknown;
+       else
+               --chosen_node->set_state;
+       update_nodes(nodes, mosfets);
+       refresh_schema_win(schematics_win, nodes, mosfets);
+       wmove(schematics_win, pos.y, pos.x);
+       return ;
+}
+
 int    schema_next(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
 {
        if (sim_step(nodes, mosfets))
@@ -365,7 +382,9 @@ int handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfet
        else if (ch == 'c')
                schema_user_draw_node(schematics_win, nodes, mosfets, pos);
        else if (ch == 's')
-               schema_switch_mode(schematics_win, nodes, mosfets, pos);
+               schema_switch_node(schematics_win, nodes, mosfets, pos);
+       else if (ch == 'S')
+               schema_reverse_switch_node(schematics_win, nodes, mosfets, pos);
        else if (ch == 'n')
                schema_next(schematics_win, nodes, mosfets, pos);
        return (0);