コード例 #1
0
ファイル: MicroGlut.c プロジェクト: simplerr/RayTracer
static void doKeyboardEvent(WPARAM wParam, LPARAM lParam, void (*keyFunc)(unsigned char key, int x, int y), void (specialKeyFunc)(unsigned char key, int x, int y), char keyMapValue)
{
	unsigned char c;

		switch(wParam)
		{
			case VK_F1:
				c = GLUT_KEY_F1; break;
			case VK_F2:
				c = GLUT_KEY_F2; break;
			case VK_F3:
				c = GLUT_KEY_F3; break;
			case VK_F4:
				c = GLUT_KEY_F4; break;
			case VK_F5:
				c = GLUT_KEY_F5; break;
			case VK_F6:
				c = GLUT_KEY_F6; break;
			case VK_F7:
				c = GLUT_KEY_F7; break;
// F8 and up ignored since they are not possible on some keyboards - like mine

			case VK_LEFT:
				c = GLUT_KEY_LEFT; break;
			case VK_UP:
				c = GLUT_KEY_UP; break;
			case VK_RIGHT:
				c = GLUT_KEY_RIGHT; break;
			case VK_DOWN:
				c = GLUT_KEY_DOWN; break;

			case VK_ESCAPE:
				c = GLUT_KEY_ESC; break;
			case VK_PRIOR:
				c = GLUT_KEY_PAGE_UP; break;
			case VK_NEXT:
				c = GLUT_KEY_PAGE_DOWN; break;
			case VK_HOME:
				c = GLUT_KEY_HOME; break;
			case VK_END:
				c = GLUT_KEY_END; break;
			case VK_INSERT:
				c = GLUT_KEY_INSERT; break;
			default:
				c = scan2ascii(wParam,lParam);
				if (c == 0) return;
		}
		if (keyFunc != NULL)
		{
			keyFunc(c, 0, 0); // TO DO: x and y
		}
		else
		if (specialKeyFunc != NULL && c < 32)
		{
			specialKeyFunc(c, 0, 0); // TO DO: x and y
		}
		gKeymap[c] = keyMapValue;
		printf("key %i %i\n", c, keyMapValue);
}
コード例 #2
0
ファイル: btree.c プロジェクト: ahknight/hfsinspect
int btree_search_node(BTRecNum* index, const BTreePtr btree, const BTreeNodePtr node, const void* searchKey)
{
    assert(index != NULL);
    assert(node != NULL);
    assert(node->bTree->keyCompare != NULL);
    assert(searchKey != NULL);

    // Perform a binary search within the records (since they are guaranteed to be ordered).
    int low                        = 0;
    int high                       = node->nodeDescriptor->numRecords - 1;
    int result                     = 0;
    int recNum                     = 0;

    /*
       Low is 0, high is the index of the largest record.
       recNum is the record we're searching right now.

       Using a >>1 shift to divide to avoid DIV/0 errors when recNum is 0

       Key compare based on btree type.
       -1/0/1 results for k1 less/equal/greater than k2 (if k1 is gt k2, return 1, etc.)

       if result is that k1 is less than k2, remove the upper half of the search area (my key is less than the current key)
       if k1 is greater than k2, remove the lower half of the search area (my key is greater than the current key)
       if they're equal, return the index.

       if low is ever incremented over high, or high decremented over low, return the current index.
     */

    BTreeKeyPtr            testKey = NULL;
    btree_key_compare_func keyFunc = node->bTree->keyCompare;

    bool                   found   = false;

    //FIXME: When low==high but the recNum is != either, it will find the record prior to the correct one (actually, it returns the right one but tree search decrements it).
    while (low <= high) {
        recNum = (low + high) >> 1;

        btree_get_record(&testKey, NULL, node, recNum);
        result = keyFunc(searchKey, testKey);

        if (result < 0) {
            high = recNum - 1;
        } else if (result > 0) {
            low = recNum + 1;
        } else {
            found = 1;
            break;
        }
    }

    // Back up one if the last test key was greater (we need to always return the insertion point if we don't have a match).
    if (!found && (recNum != 0) && (result < 0)) recNum--;

    *index = recNum;
    return found;
}
コード例 #3
0
ファイル: events.c プロジェクト: CliffsDover/cdogs-sdl
int GetKeyboardCmd(
	keyboard_t *keyboard, const int kbIndex, const bool isPressed)
{
	int cmd = 0;
	bool (*keyFunc)(const keyboard_t *, const int) =
		isPressed ? KeyIsPressed : KeyIsDown;
	const InputKeys *keys = &keyboard->PlayerKeys[kbIndex];

	if (keyFunc(keyboard, keys->left))			cmd |= CMD_LEFT;
	else if (keyFunc(keyboard, keys->right))	cmd |= CMD_RIGHT;

	if (keyFunc(keyboard, keys->up))			cmd |= CMD_UP;
	else if (keyFunc(keyboard, keys->down))		cmd |= CMD_DOWN;

	if (keyFunc(keyboard, keys->button1))		cmd |= CMD_BUTTON1;

	if (keyFunc(keyboard, keys->button2))		cmd |= CMD_BUTTON2;

	return cmd;
}