summaryrefslogtreecommitdiff
path: root/src/display.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-06-26 09:18:22 +0200
committerThomas White <taw@physics.org>2019-06-27 23:02:59 +0200
commite07e0540e7b599e09fa009a4e2c165b01a7a34e3 (patch)
treeb1d2f1e3d4ce812a4eac4493f051eae09c16a465 /src/display.c
parentc269b1fa9eaa247ef2b863367c249b996b4a01be (diff)
New way of doing attributes
The program now has its own view of what it wants ("this position", "this gobo" etc), and the fixture class contains instructions on how to turn that view into DMX values.
Diffstat (limited to 'src/display.c')
-rw-r--r--src/display.c208
1 files changed, 57 insertions, 151 deletions
diff --git a/src/display.c b/src/display.c
index ed10330..cd1f0f4 100644
--- a/src/display.c
+++ b/src/display.c
@@ -39,35 +39,22 @@
#define OVERALL_SPLIT (0.5)
#define FIXTURE_BORDER (5.0)
-enum attr_class key_attrs[] = {
+int key_attrs[] = {
0,
- ATT_INTENSITY, /* F1 */
- ATT_TILT, /* F2 */
- ATT_STROBE, /* F3 */
- ATT_CYAN, /* F4 */
- ATT_MAGENTA, /* F5 */
- ATT_YELLOW, /* F6 */
- ATT_GOBO, /* F7 */
- ATT_RGOBO, /* F8 */
- ATT_PRISM, /* F9 */
- ATT_FOCUS, /* F10 */
- ATT_ZOOM, /* F11 */
- ATT_ZOOM, /* F12 */
+ INTENSITY, /* F1 */
+ PANTILT, /* F2 */
+ COL_CMY, /* F3 */
+ GOBO, /* F4 */
+ PRISM, /* F5 */
+ FOCUS, /* F6 */
+ ZOOM, /* F7 */
+ IRIS, /* F8 */
+ FROST, /* F9 */
+ GOBO_ROTATE, /* F10 */
+ PRISM_ROTATE, /* F11 */
+ IRIS, /* F12 */
};
-static double get_attr_val(struct fixture *fix, enum attr_class acls)
-{
- int i;
- for ( i=0; i<fix->cls->n_attrs; i++ ) {
- if ( fix->cls->attrs[i].cls == acls ) {
- int max = 255;
- if ( fix->cls->attrs[i].props & ATTR_16BIT ) max = 65535;
- return (double)fix->attr_vals[i] / max;
- }
- }
- return 0.0;
-}
-
static int fixture_selected(struct nanolight *nl, struct fixture *fix)
{
@@ -79,19 +66,6 @@ static int fixture_selected(struct nanolight *nl, struct fixture *fix)
}
-static int find_attribute(struct fixture *fix, enum attr_class cls, int *n)
-{
- int j;
- for ( j=0; j<fix->cls->n_attrs; j++ ) {
- if ( fix->cls->attrs[j].cls == cls ) {
- *n = j;
- return 1;
- }
- }
- return 0;
-}
-
-
static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fontdesc,
struct nanolight *nl, struct fixture *fix)
{
@@ -99,24 +73,25 @@ static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fo
const double w = 40.0;
const double h = 3.0/2.0*w;
char tmp[32];
- int n;
/* Pan/tilt (underneath rectangle) */
- if ( find_attribute(fix, ATT_PAN, &n) ) {
- double x = w*fix->attr_vals[n] / 65535;
+ if ( fix->cls->attributes & PANTILT ) {
+
+ double x = w*(1.0 + fix->pan)/2.0;
+ double y = h*(1.0 + fix->tilt)/2.0;
+
cairo_move_to(cr, x, -1.0);
cairo_line_to(cr, x, h+1.0);
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_set_line_width(cr, 1.0);
cairo_stroke(cr);
- }
- if ( find_attribute(fix, ATT_TILT, &n) ) {
- double y = h*(1.0 - (double)fix->attr_vals[n] / 65535);
+
cairo_move_to(cr, -1.0, y);
cairo_line_to(cr, w+1.0, y);
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_set_line_width(cr, 1.0);
cairo_stroke(cr);
+
}
cairo_rectangle(cr, 0.0, 0.0, w, h);
@@ -142,7 +117,7 @@ static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fo
g_object_unref(layout);
/* Intensity */
- snprintf(tmp, 32, "%.0f %%", get_attr_val(fix, ATT_INTENSITY)*100.0);
+ snprintf(tmp, 32, "%.0f %%", fix->intensity*100.0);
layout = pango_layout_new(pc);
pango_layout_set_text(layout, tmp, -1);
pango_layout_set_width(layout, (w*PANGO_SCALE)-4.0);
@@ -155,21 +130,19 @@ static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fo
}
-static const char *attr_text(enum attr_class cls)
+static const char *attr_text(int cls)
{
switch ( cls ) {
- case ATT_INTENSITY : return "Intensity";
- case ATT_PAN : return "(pan)";
- case ATT_TILT : return "Pan/tilt";
- case ATT_STROBE : return "Strobe";
- case ATT_CYAN : return "Cyan";
- case ATT_MAGENTA : return "Magenta";
- case ATT_YELLOW : return "Yellow";
- case ATT_RGOBO : return "RGobo";
- case ATT_GOBO : return "Gobo";
- case ATT_PRISM : return "Prism";
- case ATT_FOCUS : return "Focus";
- case ATT_ZOOM : return "Zoom";
+ case INTENSITY : return "Intensity";
+ case PANTILT : return "Pan/tilt";
+ case COL_CMY : return "CMY colour";
+ case COL_RGB : return "RGB colour";
+ case GOBO : return "Gobo";
+ case PRISM : return "Prism";
+ case FOCUS : return "Focus";
+ case ZOOM : return "Zoom";
+ case IRIS : return "Iris";
+ case FROST : return "Frost";
}
return "(unknown)";
}
@@ -285,31 +258,13 @@ static size_t delete_char(char *str)
}
-static void cap_value(struct fixture *fix, int n, signed int *v)
-{
- if ( *v < 0 ) *v = 0;
- if ( fix->cls->attrs[n].props & ATTR_16BIT ) {
- if ( *v > 65535 ) *v = 65535;
- } else {
- if ( *v > 255 ) *v = 255;
- }
-}
-
-
-static void set_start_attrs(struct nanolight *nl, enum attr_class cls)
+static void set_start_pantilt(struct nanolight *nl)
{
int i;
for ( i=0; i<nl->n_sel; i++ ) {
- int n;
struct fixture *fix = &nl->fixtures[nl->selection[i]];
- if ( find_attribute(fix, cls, &n) ) {
- fix->attr_vals_start[n] = fix->attr_vals[n];
- }
- }
-
- /* If altering tilt, also change pan */
- if ( cls == ATT_TILT ) {
- set_start_attrs(nl, ATT_PAN);
+ fix->pan_start = fix->pan;
+ fix->tilt_start = fix->tilt;
}
}
@@ -324,8 +279,7 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, struct na
nl->pointer = gdk_seat_get_pointer(seat);
#endif
- set_start_attrs(nl, nl->sel_attr);
-
+ set_start_pantilt(nl);
nl->x_orig = event->x;
nl->y_orig = event->y;
nl->dragging = 1;
@@ -341,105 +295,55 @@ static gboolean button_release_sig(GtkWidget *da, GdkEventButton *event, struct
}
-static double maybe_fine(struct fixture *fix, int n, double inc, int shift)
-{
- if ( !(fix->cls->attrs[n].props & ATTR_16BIT) ) return inc;
- if ( shift ) return inc;
- return inc * 100.0;
-}
-
-
static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, struct nanolight *nl)
{
int i;
double x_inc, y_inc;
int shift;
+ double speed;
if ( !nl->dragging ) return FALSE;
+ if ( nl->sel_attr != PANTILT ) return FALSE;
- x_inc = (event->x - nl->x_orig)/3;
- y_inc = (nl->y_orig - event->y)/3; /* Mouse up means increase */
+ x_inc = event->x - nl->x_orig;
+ y_inc = nl->y_orig - event->y; /* Mouse up means increase */
shift = event->state & GDK_SHIFT_MASK;
if ( shift != nl->fine ) {
nl->fine = shift;
- set_start_attrs(nl, nl->sel_attr);
+ set_start_pantilt(nl);
nl->x_orig = event->x;
nl->y_orig = event->y;
return FALSE;
}
- if ( nl->sel_attr == ATT_TILT ) {
- for ( i=0; i<nl->n_sel; i++ ) {
- int n;
- struct fixture *fix = &nl->fixtures[nl->selection[i]];
- if ( find_attribute(fix, ATT_PAN, &n) ) {
- double inc = maybe_fine(fix, n, x_inc,
- event->state & GDK_SHIFT_MASK);
- signed int nv = fix->attr_vals_start[n] + inc;
- cap_value(fix, n, &nv);
- fix->attr_vals[n] = nv;
- }
- if ( find_attribute(fix, ATT_TILT, &n) ) {
- double inc = maybe_fine(fix, n, y_inc,
- event->state & GDK_SHIFT_MASK);
- signed int nv = fix->attr_vals_start[n] + inc;
- cap_value(fix, n, &nv);
- fix->attr_vals[n] = nv;
- }
- }
- } else {
- for ( i=0; i<nl->n_sel; i++ ) {
- int n;
- struct fixture *fix = &nl->fixtures[nl->selection[i]];
- if ( find_attribute(fix, nl->sel_attr, &n) ) {
- double inc = maybe_fine(fix, n, y_inc,
- event->state & GDK_SHIFT_MASK);
- signed int nv = fix->attr_vals_start[n] + inc;
- cap_value(fix, n, &nv);
- if ( !(fix->cls->attrs[n].props & ATTR_STOP) ) {
- fix->attr_vals[n] = nv;
- } else {
- printf("Can't change step attr with mouse\n");
- }
- }
- }
- }
-
- redraw(nl);
- return FALSE;
-}
-
+ speed = shift ? (1.0/(256.0*500.0)) : (1.0/500.0);
-static void change_stop_attr(struct nanolight *nl, signed int inc)
-{
- int i;
for ( i=0; i<nl->n_sel; i++ ) {
struct fixture *fix = &nl->fixtures[nl->selection[i]];
- int n;
+ if ( !(fix->cls->attributes & PANTILT) ) continue;
- if ( find_attribute(fix, nl->sel_attr, &n) ) {
- signed int nv;
- if ( !(fix->cls->attrs[n].props & ATTR_STOP) ) {
- printf("Can't change continuous attr with keys\n");
- continue;
- }
- nv = fix->attr_vals[n] + inc;
- if ( (nv>=0) && (nv<fix->cls->attrs[n].n_stops) ) {
- fix->attr_vals[n] = nv;
- }
- }
+ fix->pan = fix->pan_start + x_inc*speed;
+ fix->tilt = fix->tilt_start + y_inc*speed;
+ if ( fix->pan > 1.0 ) fix->pan = 1.0;
+ if ( fix->pan < -1.0 ) fix->pan = -1.0;
+ if ( fix->tilt > 1.0 ) fix->tilt = 1.0;
+ if ( fix->tilt < -1.0 ) fix->tilt = -1.0;
}
+
redraw(nl);
+ return FALSE;
}
+
static void home_value(struct nanolight *nl)
{
int i;
for ( i=0; i<nl->n_sel; i++ ) {
+#if 0
struct fixture *fix = &nl->fixtures[nl->selection[i]];
int n;
@@ -456,6 +360,8 @@ static void home_value(struct nanolight *nl)
fix->attr_vals[n] = fix->cls->attrs[n].home;
}
}
+#endif
+
}
redraw(nl);
@@ -503,11 +409,11 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct nanoligh
break;
case GDK_KEY_Up :
- change_stop_attr(nl, +1);
+ //change_stop_attr(nl, +1);
break;
case GDK_KEY_Down :
- change_stop_attr(nl, -1);
+ //change_stop_attr(nl, -1);
break;
case GDK_KEY_Return :