+
+ if(bn == 0) {
+ ExSelection sel;
+ Ray ray = calc_pick_ray(x, y);
+ sel = exman->select(ray);
+
+ if(pressed) {
+ if(sel && (app_get_modifiers() & MOD_CTRL)) {
+ exsel_grab_mouse = sel;
+ Vec3 pos = sel.ex->node->get_position();
+ debug_log("grabbing... (%g %g %g)\n", pos.x, pos.y, pos.z);
+ exslot_mouse.node.set_position(pos);
+ exslot_mouse.node.set_rotation(sel.ex->node->get_rotation());
+ exslot_mouse.attach_exhibit(sel.ex, EXSLOT_ATTACH_TRANSIENT);
+ if(exsel_active) {
+ exsel_active = ExSelection::null; // cancel active on grab
+ }
+ }
+ press_x = x;
+ press_y = y;
+
+ } else {
+ if(exsel_grab_mouse) {
+ // cancel grab on mouse release
+ Exhibit *ex = exsel_grab_mouse.ex;
+ Vec3 pos = exslot_mouse.node.get_position();
+
+ debug_log("releasing at %g %g %g ...\n", pos.x, pos.y, pos.z);
+
+ exslot_mouse.detach_exhibit();
+
+ ExhibitSlot *slot = exman->nearest_empty_slot(pos, 100);
+ if(!slot) {
+ debug_log("no empty slot nearby\n");
+ if(ex->prev_slot && ex->prev_slot->empty()) {
+ slot = ex->prev_slot;
+ debug_log("using previous slot");
+ }
+ }
+
+ if(slot) {
+ slot->attach_exhibit(ex);
+ } else {
+ // nowhere to put it, so stash it for later
+ exslot_mouse.detach_exhibit();
+ exman->stash_exhibit(ex);
+ debug_log("no slots available, stashing\n");
+ }
+
+ exsel_grab_mouse = ExSelection::null;
+ }
+
+ if(abs(press_x - x) < 5 && abs(press_y - y) < 5) {
+ exsel_active = sel; // select or deselect active exhibit
+ if(sel) {
+ debug_log("selecting...\n");
+ } else {
+ debug_log("deselecting...\n");
+ }
+ }
+
+ press_x = press_y = INT_MIN;
+ }
+ }