summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-06-11 21:04:49 +0200
committerThomas White <taw@physics.org>2019-06-11 23:21:03 +0200
commitcf59fc712b696c7d790e7da42d566b3b57f7dfce (patch)
treee0c8719af45081df591f35451f5a5cb3193a5b34
parent26058b69e8dfb2d2e64f91dce886f2f0d90b23b3 (diff)
Set pan and tilt with mouse
-rw-r--r--src/nanolight.c103
-rw-r--r--src/nanolight.h6
2 files changed, 109 insertions, 0 deletions
diff --git a/src/nanolight.c b/src/nanolight.c
index 6fe379e..cffa48c 100644
--- a/src/nanolight.c
+++ b/src/nanolight.c
@@ -202,6 +202,11 @@ static struct fixture *create_fixture(struct nanolight *nl, struct fixture_class
nl->n_fixtures--;
return NULL;
}
+ fix->attr_vals_start = calloc(cls->n_attrs, sizeof(int));
+ if ( fix->attr_vals_start == NULL ) {
+ nl->n_fixtures--;
+ return NULL;
+ }
return fix;
}
@@ -248,6 +253,97 @@ static size_t delete_char(char *str)
}
+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 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)
+{
+ 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];
+ }
+ }
+}
+
+
+static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, struct nanolight *nl)
+{
+ gdouble x, y;
+ int i;
+ signed int pan_inc, tilt_inc;
+ GdkWindow *win = gtk_widget_get_window(nl->da);
+
+ gdk_window_get_device_position_double(win, nl->pointer, &x, &y, NULL);
+
+ pan_inc = 9*(x - nl->x_orig);
+ tilt_inc = 9*(y - nl->y_orig);
+ 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) ) {
+ signed int nv = fix->attr_vals_start[n] + pan_inc;
+ cap_value(fix, n, &nv);
+ fix->attr_vals[n] = nv;
+ }
+ if ( find_attribute(fix, ATT_TILT, &n) ) {
+ signed int nv = fix->attr_vals_start[n] + tilt_inc;
+ cap_value(fix, n, &nv);
+ fix->attr_vals[n] = nv;
+ }
+ }
+
+ return FALSE;
+}
+
+
+static void update_mouse_orientation(struct nanolight *nl)
+{
+ if ( (nl->n_sel > 0) && (nl->mouse_orientation == 0) ) {
+
+ GdkSeat *seat;
+ GdkWindow *win = gtk_widget_get_window(nl->da);
+
+ seat = gdk_display_get_default_seat(gdk_display_get_default());
+ nl->pointer = gdk_seat_get_pointer(seat);
+ gdk_window_get_device_position_double(win, nl->pointer,
+ &nl->x_orig, &nl->y_orig, NULL);
+ set_start_attrs(nl, ATT_PAN);
+ set_start_attrs(nl, ATT_TILT);
+
+ nl->mouse_orientation = g_signal_connect(G_OBJECT(nl->da), "motion-notify-event",
+ G_CALLBACK(motion_sig), nl);
+
+ } else if ( nl->mouse_orientation != 0 ) {
+ g_signal_handler_disconnect(nl->da, nl->mouse_orientation);
+ nl->mouse_orientation = 0;
+ }
+}
+
+
static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct nanolight *nl)
{
gboolean r;
@@ -272,6 +368,7 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct nanoligh
nl->cmdline[0] = '\0';
nl->cursor_idx = 0;
nl->n_sel = 0;
+ update_mouse_orientation(nl);
redraw(nl);
claim = 1;
break;
@@ -292,6 +389,11 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct nanoligh
claim = 1;
break;
+ case GDK_KEY_F1 :
+ update_mouse_orientation(nl);
+ claim = 1;
+ break;
+
}
if ( !claim ) {
@@ -399,6 +501,7 @@ int main(int argc, char *argv[])
nl.cmdline[0] = '\0';
nl.cursor_idx = 0;
nl.n_sel = 0;
+ nl.mouse_orientation = 0;
create_fixture(&nl, &cls, "mh1", 1);
create_fixture(&nl, &cls, "mh2", 52);
diff --git a/src/nanolight.h b/src/nanolight.h
index 124e214..a7f7136 100644
--- a/src/nanolight.h
+++ b/src/nanolight.h
@@ -59,6 +59,7 @@ struct fixture
int base_addr;
struct fixture_class *cls;
int *attr_vals;
+ int *attr_vals_start;
};
@@ -79,6 +80,11 @@ struct nanolight
int selection[1024];
int n_sel;
+
+ GdkDevice *pointer;
+ gulong mouse_orientation;
+ gdouble x_orig;
+ gdouble y_orig;
};