+//
+// Map of all known GLUT cursor names
+//
+struct {
+ const char * name;
+ int cursor;
+} mouse_cursor_map[] = {
+ { "right-arrow", GLUT_CURSOR_RIGHT_ARROW },
+ { "left-arrow", GLUT_CURSOR_LEFT_ARROW },
+ { "info", GLUT_CURSOR_INFO },
+ { "destroy", GLUT_CURSOR_DESTROY },
+ { "help", GLUT_CURSOR_HELP },
+ { "cycle", GLUT_CURSOR_CYCLE },
+ { "spray", GLUT_CURSOR_SPRAY },
+ { "wait", GLUT_CURSOR_WAIT },
+ { "text", GLUT_CURSOR_TEXT },
+ { "crosshair", GLUT_CURSOR_CROSSHAIR },
+ { "up-down", GLUT_CURSOR_UP_DOWN },
+ { "left-right", GLUT_CURSOR_LEFT_RIGHT },
+ { "top-side", GLUT_CURSOR_TOP_SIDE },
+ { "bottom-side", GLUT_CURSOR_BOTTOM_SIDE },
+ { "left-side", GLUT_CURSOR_LEFT_SIDE },
+ { "right-side", GLUT_CURSOR_RIGHT_SIDE },
+ { "top-left-corner", GLUT_CURSOR_TOP_LEFT_CORNER },
+ { "top-right-corner", GLUT_CURSOR_TOP_RIGHT_CORNER },
+ { "bottom-right-corner", GLUT_CURSOR_BOTTOM_RIGHT_CORNER },
+ { "bottom-left-corner", GLUT_CURSOR_BOTTOM_LEFT_CORNER },
+ { "inherit", GLUT_CURSOR_INHERIT },
+ { "none", GLUT_CURSOR_NONE },
+ { "full-crosshair", GLUT_CURSOR_FULL_CROSSHAIR },
+ { 0, 0 }
+};
+
+
+
+void
+FGInput::_init_mouse ()
+{
+ SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
+
+ SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
+ if (mouse_nodes == 0) {
+ SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
+ mouse_nodes = fgGetNode("/input/mice", true);
+ }
+
+ int j;
+ for (int i = 0; i < MAX_MICE; i++) {
+ SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i, true);
+ mouse &m = _mouse_bindings[i];
+
+ // Grab node pointers
+ char buf[64];
+ sprintf(buf, "/devices/status/mice/mouse[%d]/mode", i);
+ m.mode_node = fgGetNode(buf, true);
+ m.mode_node->setIntValue(0);
+ for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
+ sprintf(buf, "/devices/status/mice/mouse[%d]/button[%d]", i, j);
+ m.mouse_button_nodes[j] = fgGetNode(buf, true);
+ m.mouse_button_nodes[j]->setBoolValue(false);
+ }
+
+ // Read all the modes
+ m.nModes = mouse_node->getIntValue("mode-count", 1);
+ m.modes = new mouse_mode[m.nModes];
+
+ for (int j = 0; j < m.nModes; j++) {
+ int k;
+
+ // Read the mouse cursor for this mode
+ SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
+ const char * cursor_name =
+ mode_node->getStringValue("cursor", "inherit");
+ m.modes[j].cursor = GLUT_CURSOR_INHERIT;
+ for (k = 0; mouse_cursor_map[k].name != 0; k++) {
+ if (!strcmp(mouse_cursor_map[k].name, cursor_name)) {
+ m.modes[j].cursor = mouse_cursor_map[k].cursor;
+ break;
+ }
+ }
+
+ // Read other properties for this mode
+ m.modes[j].constrained = mode_node->getBoolValue("constrained", false);
+ m.modes[j].pass_through = mode_node->getBoolValue("pass-through", false);
+
+ // Read the button bindings for this mode
+ m.modes[j].buttons = new button[MAX_MOUSE_BUTTONS];
+ char buf[32];
+ for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
+ sprintf(buf, "mouse button %d", k);
+ SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << k);
+ _init_button(mode_node->getChild("button", k),
+ m.modes[j].buttons[k],
+ buf);
+ }
+
+ // Read the axis bindings for this mode
+ _read_bindings(mode_node->getChild("x-axis", 0, true),
+ m.modes[j].x_bindings,
+ FG_MOD_NONE);
+ _read_bindings(mode_node->getChild("y-axis", 0, true),
+ m.modes[j].y_bindings,
+ FG_MOD_NONE);
+ }
+ }
+}
+
+
+void
+FGInput::_init_button (const SGPropertyNode * node,
+ button &b,
+ const string name)
+{
+ if (node == 0) {
+ SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for button " << name);
+ } else {
+ b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
+
+ // Get the bindings for the button
+ _read_bindings(node, b.bindings, FG_MOD_NONE);
+ }
+}
+