From 26058b69e8dfb2d2e64f91dce886f2f0d90b23b3 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 9 Jun 2019 23:02:46 +0200 Subject: Basic selection and level setting --- src/command.c | 42 +++++++++++++++++++++++++++++++++++++++++- src/nanolight.c | 18 +++++++++++++++++- src/nanolight.h | 3 +++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index c6b64e7..62c047b 100644 --- a/src/command.c +++ b/src/command.c @@ -205,16 +205,56 @@ static void show_tokens(struct token *tokens, int n, struct nanolight *nl) } +static void set_level(struct nanolight *nl, int val, enum attr_class cls) +{ + int i; + + if ( cls == ATT_INTENSITY ) { + val *= 255; + val /= 100; + } + + for ( i=0; in_sel; i++ ) { + int j; + struct fixture *fix = &nl->fixtures[nl->selection[i]]; + for ( j=0; jcls->n_attrs; j++ ) { + if ( fix->cls->attrs[j].cls == cls ) { + fix->attr_vals[j] = val; + break; + } + } + } +} + + int command_run(const char *cmd, struct nanolight *nl) { struct token tokens[1024]; - int n; + int i, n; n = find_tokens(cmd, tokens, nl); if ( n == 0 ) return 1; show_tokens(tokens, n, nl); + i = 0; + if ( tokens[i].type == TK_FIXTURE ) { + nl->n_sel = 0; + for ( i=0; iselection[nl->n_sel++] = tokens[i].fixture_index; + } else { + break; + } + } + } + + if ( tokens[i].type == TK_AT ) { + if ( tokens[i+1].type == TK_LEVEL ) { + set_level(nl, tokens[i+1].val, ATT_INTENSITY); + } + } + return 0; } diff --git a/src/nanolight.c b/src/nanolight.c index 5f76dd5..6fe379e 100644 --- a/src/nanolight.c +++ b/src/nanolight.c @@ -61,6 +61,16 @@ static double get_attr_val(struct fixture *fix, enum attr_class acls) } +static int fixture_selected(struct nanolight *nl, struct fixture *fix) +{ + int i; + for ( i=0; in_sel; i++ ) { + if ( &nl->fixtures[nl->selection[i]] == fix ) return 1; + } + return 0; +} + + static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fontdesc, struct nanolight *nl, struct fixture *fix) { @@ -69,7 +79,11 @@ static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fo char tmp[32]; cairo_rectangle(cr, 0.5, 0.5, w, 3.0/2.0*w); - cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); + if ( fixture_selected(nl, fix) ) { + cairo_set_source_rgb(cr, 0.3, 0.3, 0.9); + } else { + cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); + } cairo_fill_preserve(cr); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_set_line_width(cr, 1.0); @@ -257,6 +271,7 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct nanoligh case GDK_KEY_Escape : nl->cmdline[0] = '\0'; nl->cursor_idx = 0; + nl->n_sel = 0; redraw(nl); claim = 1; break; @@ -383,6 +398,7 @@ int main(int argc, char *argv[]) nl.max_fixtures = 0; nl.cmdline[0] = '\0'; nl.cursor_idx = 0; + nl.n_sel = 0; create_fixture(&nl, &cls, "mh1", 1); create_fixture(&nl, &cls, "mh2", 52); diff --git a/src/nanolight.h b/src/nanolight.h index 5c08cd7..124e214 100644 --- a/src/nanolight.h +++ b/src/nanolight.h @@ -76,6 +76,9 @@ struct nanolight char cmdline[1024]; int cursor_idx; PangoLayout *layout; + + int selection[1024]; + int n_sel; }; -- cgit v1.2.3