From ec0a7bac9d80b4ac094e361535f1ce4a5f5c6487 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 26 May 2019 22:28:23 +0200 Subject: Dummy fixture and initial rendering --- src/nanolight.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/nanolight.h | 6 ++-- 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/src/nanolight.c b/src/nanolight.c index 94ae685..4c657df 100644 --- a/src/nanolight.c +++ b/src/nanolight.c @@ -32,6 +32,8 @@ #include #define _(x) gettext(x) +#include "nanolight.h" + static void show_help(const char *s) { printf(_("Syntax: %s [options]\n\n"), s); @@ -39,17 +41,74 @@ static void show_help(const char *s) " -h, --help Display this help message.\n")); } +#define OVERALL_BORDER (20.0) +#define OVERALL_SPLIT (0.5) + +static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fontdesc, + struct nanolight *nl, struct fixture *fx) +{ + PangoLayout *layout; + const double w = nl->fixture_width; + + cairo_rectangle(cr, 0.5, 0.5, w, 3.0/2.0*w); + 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); + cairo_stroke(cr); + + layout = pango_layout_new(pc); + pango_layout_set_text(layout, fx->label, -1); + pango_layout_set_width(layout, w*PANGO_SCALE); + pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); + pango_layout_set_font_description(layout, fontdesc); + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); + pango_cairo_show_layout(cr, layout); +} + -static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, gpointer data) +static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct nanolight *nl) { + int w, h; + int i; + PangoContext *pc; + PangoFontDescription *fontdesc; + + w = gtk_widget_get_allocated_width(widget); + h = gtk_widget_get_allocated_height(widget); + pc = gtk_widget_get_pango_context(widget); + fontdesc = pango_font_description_from_string("Comfortaa Bold 14"); + + /* Overall background */ cairo_set_source_rgb(cr, 0.0, 0.0, 0.2); cairo_paint(cr); + + /* Separator between fixture and cue areas */ + cairo_move_to(cr, w*OVERALL_SPLIT, OVERALL_BORDER); + cairo_line_to(cr, w*OVERALL_SPLIT, h - OVERALL_BORDER); + cairo_set_line_width(cr, 3.0); + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); + cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); + cairo_stroke(cr); + + /* Fixtures */ + cairo_translate(cr, OVERALL_BORDER, OVERALL_BORDER); + for ( i=0; in_fixtures; i++ ) { + draw_fixture(cr, pc, fontdesc, nl, &nl->fixtures[i]); + } + + /* Command line */ + return FALSE; } int main(int argc, char *argv[]) { + struct nanolight nl; + struct fixture fix; + struct fixture_class cls; + struct attribute attrs[3]; int c; GtkWidget *mainwindow; GtkWidget *da; @@ -85,13 +144,39 @@ int main(int argc, char *argv[]) bindtextdomain("nanolight", LOCALEDIR); textdomain("nanolight"); + cls.name = "Dummy fixture"; + cls.n_attrs = 3; + cls.attrs = attrs; + + cls.attrs[0].name = "Intensity"; + cls.attrs[0].cls = ATT_INTENSITY; + cls.attrs[0].props = 0; + cls.attrs[0].addr_offset = 50; + + cls.attrs[1].name = "Pan"; + cls.attrs[1].cls = ATT_PAN; + cls.attrs[1].props = ATTR_16BIT; + cls.attrs[1].addr_offset = 0; + + cls.attrs[2].name = "Tilt"; + cls.attrs[2].cls = ATT_TILT; + cls.attrs[2].props = ATTR_16BIT; + cls.attrs[2].addr_offset = 2; + + nl.n_fixtures = 1; + nl.fixtures = &fix; + fix.label = "mh1"; + fix.cls = &cls; + + nl.fixture_width = 80.0; + mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_fullscreen(GTK_WINDOW(mainwindow)); g_signal_connect_swapped(G_OBJECT(mainwindow), "destroy", gtk_main_quit, NULL); da = gtk_drawing_area_new(); gtk_container_add(GTK_CONTAINER(mainwindow), GTK_WIDGET(da)); - g_signal_connect(G_OBJECT(da), "draw", G_CALLBACK(draw_sig), NULL); + g_signal_connect(G_OBJECT(da), "draw", G_CALLBACK(draw_sig), &nl); gtk_widget_show_all(mainwindow); gtk_main(); diff --git a/src/nanolight.h b/src/nanolight.h index 4ab4d5a..5235666 100644 --- a/src/nanolight.h +++ b/src/nanolight.h @@ -40,8 +40,7 @@ struct attribute char *name; enum attr_class cls; int props; - int n_addrs; - int *addrs; + int addr_offset; }; @@ -56,6 +55,7 @@ struct fixture_class struct fixture { char *label; + int base_addr; struct fixture_class *cls; }; @@ -64,6 +64,8 @@ struct nanolight { int n_fixtures; struct fixture *fixtures; + + double fixture_width; }; -- cgit v1.2.3