t_arg argv[MAX_ARGS];
} t_input;
+typedef struct s_schematics_window
+{
+ WINDOW *win;
+ t_position view_pos;
+} t_schem_win;
+
typedef struct s_windows
{
- WINDOW *command_win;
- WINDOW *schematics_win;
- WINDOW *border_win;
+ WINDOW *command_win;
+ t_schem_win schematics_win;
+ WINDOW *border_win;
} t_windows;
t_node *add_node(t_vec *nodes, t_state set_state);
const char *state_color_escape(t_state state);
void draw_single(WINDOW *command_win, t_vec *nodes, const t_mosfet *mosfet);
-void schema_draw_mosfet(WINDOW *schematics_win, t_vec *nodes, const t_mosfet *mosfet);
-void schema_draw_node(WINDOW *schematics_win, const t_node *node);
-void schema_draw_segment(WINDOW *schematics_win, const t_node_segment *segment);
+void schema_draw_mosfet(t_schem_win schematics_win, t_vec *nodes, const t_mosfet *mosfet);
+void schema_draw_node(t_schem_win schematics_win, const t_node *node);
+void schema_draw_segment(t_schem_win schematics_win, const t_node_segment *segment);
void update_nodes(t_vec *nodes, t_vec *mosfets);
int should_open(t_vec *nodes, const t_mosfet *mosfet);
int c_help(WINDOW *command_win, t_input input);
int c_next(t_input input, t_vec *nodes, t_vec *mosfets);
int c_setnode(WINDOW *command_win, t_input input, t_vec *nodes);
-int refresh_schema_win(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets);
-int schema_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets);
+int refresh_schema_win(t_schem_win schematics_win, t_vec *nodes, t_vec *mosfets);
+int schema_mode(t_schem_win *schematics_win, t_vec *nodes, t_vec *mosfets);
int str_is_num(const char *str);
return ;
}
-void schema_draw_mosfet(WINDOW *schematics_win, t_vec *nodes, const t_mosfet *mosfet)
+void schema_draw_mosfet(t_schem_win schematics_win, t_vec *nodes, const t_mosfet *mosfet)
{
t_position old_pos;
t_position work_pos;
- getyx(schematics_win, old_pos.y, old_pos.x);
+ getyx(schematics_win.win, old_pos.y, old_pos.x);
work_pos = mosfet->position;
- mvwaddch(schematics_win, work_pos.y, work_pos.x, mosfet->type);
+ mvwaddch(schematics_win.win, work_pos.y, work_pos.x, mosfet->type);
if (mosfet->orientation == UP)
++work_pos.y;
else if (mosfet->orientation == DOWN)
++work_pos.x;
else if (mosfet->orientation == RIGHT)
--work_pos.x;
- wmove(schematics_win, work_pos.y, work_pos.x);
- draw_switch(schematics_win, nodes, mosfet, mosfet->orientation);
- wmove(schematics_win, old_pos.y, old_pos.x);
+ wmove(schematics_win.win, work_pos.y, work_pos.x);
+ draw_switch(schematics_win.win, nodes, mosfet, mosfet->orientation);
+ wmove(schematics_win.win, old_pos.y, old_pos.x);
return ;
}
}
}
-void schema_draw_segment(WINDOW *schematics_win, const t_node_segment *segment)
+void schema_draw_segment(t_schem_win schematics_win, const t_node_segment *segment)
{
t_symbol symbol;
symbol = seg_connects_to_symbol(segment->connects);
if (symbol != '\0')
- mvwaddch(schematics_win, segment->position.y, segment->position.x, symbol);
+ mvwaddch(schematics_win.win, segment->position.y, segment->position.x, symbol);
return ;
}
-void schema_draw_node(WINDOW *schematics_win, const t_node *node)
+void schema_draw_node(t_schem_win schematics_win, const t_node *node)
{
const t_node_segment *seg;
size_t i;
- wattron(schematics_win, COLOR_PAIR(get_state_color(node->state)));
+ wattron(schematics_win.win, COLOR_PAIR(get_state_color(node->state)));
i = 0;
while (i < node->segments.size)
{
schema_draw_segment(schematics_win, seg);
++i;
}
- wattroff(schematics_win, COLOR_PAIR(get_state_color(node->state)));
+ wattroff(schematics_win.win, COLOR_PAIR(get_state_color(node->state)));
return ;
}
return ;
}
-int refresh_schema_win(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets)
+int refresh_schema_win(t_schem_win schematics_win, t_vec *nodes, t_vec *mosfets)
{
size_t i;
const t_mosfet *mosfet;
const t_node *node;
- werase(schematics_win);
+ werase(schematics_win.win);
i = 0;
while (i < mosfets->size)
{
schema_draw_node(schematics_win, node);
++i;
}
- wrefresh(schematics_win);
+ wrefresh(schematics_win.win);
return (1);
}
}
-void add_terminal_node(WINDOW *schematics_win, t_vec *nodes, t_mosfet *mosfet, t_terminal terminal)
+void add_terminal_node(t_schem_win schematics_win, t_vec *nodes, t_mosfet *mosfet, t_terminal terminal)
{
t_node *node;
return ;
}
-void schema_add_mosfet(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+void schema_add_mosfet(t_schem_win schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
{
t_mosfet *mosfet;
size_t i;
while (1)
{
schema_draw_mosfet(schematics_win, nodes, mosfet);
- ch = wgetch(schematics_win);
+ ch = wgetch(schematics_win.win);
if (ch == 'r' || ch == 'R')
{
gate_pos = pos_add(mosfet->position, mosfet_channel_rel_pos(mosfet));
- mvwaddch(schematics_win, gate_pos.y, gate_pos.x, ' ');
- wmove(schematics_win, mosfet->position.y, mosfet->position.x);
+ mvwaddch(schematics_win.win, gate_pos.y, gate_pos.x, ' ');
+ wmove(schematics_win.win, mosfet->position.y, mosfet->position.x);
}
if (ch == 't' && mosfet->type == p)
mosfet->type = n;
add_terminal_node(schematics_win, nodes, mosfet, source);
add_terminal_node(schematics_win, nodes, mosfet, gate);
add_terminal_node(schematics_win, nodes, mosfet, drain);
- wmove(schematics_win, mosfet->position.y, mosfet->position.x);
+ wmove(schematics_win.win, mosfet->position.y, mosfet->position.x);
ungetch(ch);
return ;
}
return (connects1 | connects2);
}
-int place_segment(WINDOW *schematics_win, t_node *node, t_node_segment *prediction)
+int place_segment(t_schem_win *schematics_win, t_node *node, t_node_segment *prediction)
{
char ch;
t_node_segment tmp;
- wmove(schematics_win, prediction->position.y, prediction->position.x);
- ch = wgetch(schematics_win);
+ wmove(schematics_win->win, prediction->position.y, prediction->position.x);
+ ch = wgetch(schematics_win->win);
tmp = *prediction;
if (ch == 'l')
{
else
return (1); // The choice not to ungetch is deliberate, because it felt weird using it
ft_vec_append(&node->segments, prediction);
- schema_draw_segment(schematics_win, prediction);
+ schema_draw_segment(*schematics_win, prediction);
*prediction = tmp;
return (0);
}
return ;
}
-void schema_user_draw_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+void schema_user_draw_node(t_schem_win *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
{
t_node *chosen_node;
t_node *end_node;
merge_nodes(nodes, mosfets, chosen_node, end_node);
chosen_node = get_node_by_id(nodes, index);
}
- schema_draw_segment(schematics_win, merge_seg);
+ schema_draw_segment(*schematics_win, merge_seg);
}
else
{
ft_vec_append(&chosen_node->segments, &seg);
- schema_draw_segment(schematics_win, &seg);
+ schema_draw_segment(*schematics_win, &seg);
}
merge_overlapping_segments(chosen_node);
- schema_draw_node(schematics_win, chosen_node);
- wmove(schematics_win, seg.position.y, seg.position.x);
+ schema_draw_node(*schematics_win, chosen_node);
+ wmove(schematics_win->win, seg.position.y, seg.position.x);
return ;
}
-void schema_switch_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+void schema_switch_node(t_schem_win schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
{
t_node *chosen_node;
++chosen_node->set_state;
update_nodes(nodes, mosfets);
refresh_schema_win(schematics_win, nodes, mosfets);
- wmove(schematics_win, pos.y, pos.x);
+ wmove(schematics_win.win, pos.y, pos.x);
return ;
}
-void schema_reverse_switch_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+void schema_reverse_switch_node(t_schem_win schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
{
t_node *chosen_node;
--chosen_node->set_state;
update_nodes(nodes, mosfets);
refresh_schema_win(schematics_win, nodes, mosfets);
- wmove(schematics_win, pos.y, pos.x);
+ wmove(schematics_win.win, pos.y, pos.x);
return ;
}
-int schema_next(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+int schema_next(t_schem_win schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
{
if (sim_step(nodes, mosfets))
return (1);
refresh_schema_win(schematics_win, nodes, mosfets);
- wmove(schematics_win, pos.y, pos.x);
+ wmove(schematics_win.win, pos.y, pos.x);
return (0);
}
-int handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets)
+int handle_key_press(int ch, t_schem_win *schematics_win, t_vec *nodes, t_vec *mosfets)
{
t_position pos;
- getyx(schematics_win, pos.y, pos.x);
+ getyx(schematics_win->win, pos.y, pos.x);
if (ch == 'h')
- wmove(schematics_win, pos.y, --pos.x);
+ wmove(schematics_win->win, pos.y, --pos.x);
else if (ch == 'l')
- wmove(schematics_win, pos.y, ++pos.x);
+ wmove(schematics_win->win, pos.y, ++pos.x);
else if (ch == 'j')
- wmove(schematics_win, ++pos.y, pos.x);
+ wmove(schematics_win->win, ++pos.y, pos.x);
else if (ch == 'k')
- wmove(schematics_win, --pos.y, pos.x);
+ wmove(schematics_win->win, --pos.y, pos.x);
else if (ch == 't')
- schema_add_mosfet(schematics_win, nodes, mosfets, pos);
+ schema_add_mosfet(*schematics_win, nodes, mosfets, pos);
else if (ch == 'c')
schema_user_draw_node(schematics_win, nodes, mosfets, pos);
else if (ch == 's')
- schema_switch_node(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);
+ schema_reverse_switch_node(*schematics_win, nodes, mosfets, pos);
else if (ch == 'n')
- schema_next(schematics_win, nodes, mosfets, pos);
+ schema_next(*schematics_win, nodes, mosfets, pos);
return (0);
}
// 27 == '\e' but compiler flags '\e' as not an ISO escape sequence
-int schema_loop(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets)
+int schema_loop(t_schem_win *schematics_win, t_vec *nodes, t_vec *mosfets)
{
int res;
int ch;
- wrefresh(schematics_win);
- ch = wgetch(schematics_win);
+ wrefresh(schematics_win->win);
+ ch = wgetch(schematics_win->win);
while (ch != 27)
{
res = handle_key_press(ch, schematics_win, nodes, mosfets);
if (res)
return (res);
- ch = wgetch(schematics_win);
+ ch = wgetch(schematics_win->win);
}
return (1);
}
-int schema_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets)
+int schema_mode(t_schem_win *schematics_win, t_vec *nodes, t_vec *mosfets)
{
int res;