+//
+// Map of all known cursor names
+// This used to contain all the Glut cursors, but those are
+// not defined by other toolkits. It now supports only the cursor
+// images we actually use, in the interest of portability. Someday,
+// it would be cool to write an OpenGL cursor renderer, with the
+// cursors defined as textures referenced in the property tree. This
+// list could then be eliminated. -Andy
+//
+static struct {
+ const char * name;
+ int cursor;
+} mouse_cursor_map[] = {
+ { "none", MOUSE_CURSOR_NONE },
+ { "inherit", MOUSE_CURSOR_POINTER },
+ { "wait", MOUSE_CURSOR_WAIT },
+ { "crosshair", MOUSE_CURSOR_CROSSHAIR },
+ { "left-right", MOUSE_CURSOR_LEFTRIGHT },
+ { 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);
+ if (m.mode_node == NULL) {
+ 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 = MOUSE_CURSOR_POINTER;
+ 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,
+ KEYMOD_NONE);
+ _read_bindings(mode_node->getChild("y-axis", 0, true),
+ m.modes[j].y_bindings,
+ KEYMOD_NONE);
+ }
+ }
+}
+