Пример #1
0
/**
 *	@brief	Called when the selection of current keys listbox is changed.
 */
void EditKeymapDlg::handleCurrentKeysListBoxSelectionChanged()
{
	UICListBox* currentKeysList = getCurrentKeysListBox();
	if (NULL != currentKeysList)
	{
		SInt32 keyIndex = currentKeysList->GetSelectedItem();
		
		// enable/disable remove button
		if (!isReadOnly)
		{
			UICButton* removeButton = getRemoveButton();
			if (NULL != removeButton)
			{
				removeButton->Enable(0 <= keyIndex);
			}
		}
		
		// set selected key to the key-input control
		if (0 <= keyIndex)
		{
			UICKeyInput* keyInput = getKeyInput();
			if (NULL != keyInput)
			{
				const KeyEventParameter* keyParam = static_cast<KeyEventParameter*>(currentKeysList->GetItemData(keyIndex));
				keyInput->StopValueChangedNotification(true);
				keyInput->SetKeyEventParameter(*keyParam);
				keyInput->StopValueChangedNotification(false);
				handleKeyInputChanged();
			}
		}
	}
}
Пример #2
0
VkBool32 UpdateThreadContext::getKey(const int32_t windowIndex, const int32_t keyIndex) const
{
    auto currentWindow = getWindow(windowIndex);

    if (currentWindow.get())
    {
        return currentWindow->getKeyInput().getKey(keyIndex);
    }

    return VK_FALSE;
}
Пример #3
0
// @author Andre Allan Ponce
// @author Computergeek01 (for the keyboard input stuff)
// @author Duoas (for more keyboard input stuff)
// url: http://www.cplusplus.com/forum/beginner/75529/
// url: http://www.cplusplus.com/forum/articles/7312/#msg33734
void Game::runGame(){
	bool running = true;
	HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
	DWORD NumInputs = 0;
	DWORD InputsRead = 0;
	INPUT_RECORD irInput;
	GetNumberOfConsoleInputEvents(hInput, &NumInputs);
	int old_state = 0;
	clock_t startTime = clock();
	while(running){
		//printGame();
		switch(state){
		case STATE_PRE_GAME:{
			createWorld();
			preGameInit();
			state = STATE_LEVEL_ONE;
			break;
		}
		case STATE_GAME_FINISH:{
			break;
		}
		case STATE_WAIT:{
			
			if(clock() - startTime > 20){ // it was too fast at one point
				state = old_state;
			}
			//*/
			//Sleep(1*1000);
			//state = old_state;
			break;
		}
		default:{
			printGame();
			do ReadConsoleInput( hInput, &irInput, 1, &InputsRead );
			while ((irInput.EventType != KEY_EVENT) || irInput.Event.KeyEvent.bKeyDown);
			//ReadConsoleInput(hInput, &irInput, 1, &InputsRead); 
			startTime = clock();
			Location* thisRoom = world[currX][currY];
			getKeyInput(irInput.Event.KeyEvent.wVirtualKeyCode, thisRoom);
			switch(state){
			case STATE_LEVEL_ONE:{
				old_state = STATE_LEVEL_ONE;
				state = STATE_WAIT;
				break;
			}
			}
			break;
		}
		}
	}
}
Пример #4
0
int main()
{
	char command[128] = { 0 };
	clock_t flag = clock(), flagNow, flagDiff;
	
	srand((unsigned int)time(NULL));

	newMatrix(&map, HEIGHT, WIDTH);
	newMatrix(&rendered, HEIGHT, WIDTH);

	sprintf(command, "mode con:cols=%d lines=%d", 2 * WIDTH + 5, 4+HEIGHT);
	system(command);
	SetConsoleOutputCP(949);

	initilize();
	eventInitilize();

	for (;;)
	{
		do {
			flagNow = clock();
			flagDiff = ((flagNow - flag) * 1000 / CLOCKS_PER_SEC) % 10000;
			if (flagDiff > timeInterval)
			{
				eventLoop();
				flag = flagNow;
			}
		} while (!kbhit());
		eventKeyPress(getKeyInput());

		switch (state)
		{
			case INIT:
				eventGameInit();
				render(&rendered, &map);
				if(autoState)
					state = GAME;
				break;
			case GAME:
				break;
			case DEAD:
				eventGameOver();
				if(autoState)
					state = INIT;
				break;
			default:
				break;
		}
	}

}
Пример #5
0
/**
 *	@brief	Called when assign button is clicked.
 */
void EditKeymapDlg::handleAssignButtonClicked()
{
	UICListBox* funcList = getFunctionListBox();
	UICKeyInput* keyInput = getKeyInput();
	if (NULL == funcList || NULL == keyInput)
	{
		return;
	}
	
	SInt32 funcIndex = funcList->GetSelectedItem();
	if (funcIndex < 0)
	{
		// function is not selected.
		return;
	}
	const FuncInfo* funcInfo = static_cast<FuncInfo*>(funcList->GetItemData(funcIndex));
	
	const KeyEventParameter& keyParam = keyInput->GetKeyEventParameter();
	if (!keyParam.IsValid())
	{
		// key parameter is not valid.
		return;
	}
	
	SInt32 oldFunc = keyMappingManager.GetFunction(keyParam);
	if (oldFunc == funcInfo->keyFunc)
	{
		// already assigned.
		return;
	}
	
	if (KeyFuncOperation::KeyFunc_None != oldFunc)
	{
		keyMappingManager.RemoveKey(oldFunc, keyParam);
	}
	keyMappingManager.AddKey(funcInfo->keyFunc, keyParam);
	isModified = true;
	
	keyInput->StopValueChangedNotification(true);
	handleFunctionListBoxSelectionChanged();
	keyInput->StopValueChangedNotification(false);
	handleKeyInputChanged();
}
Пример #6
0
/**
 *	@brief	Called when the value of key-input control is changed.
 */
void EditKeymapDlg::handleKeyInputChanged()
{
	// enable/disable assign button
	updateAssignButtonState();

	UICKeyInput* keyInput = getKeyInput();
	if (NULL != keyInput)
	{
		// set assigned function to text edit.
		UICTextEdit* assignedFuncEdit = getAssignedFunctionTextEdit();
		if (NULL != assignedFuncEdit)
		{
			const KeyEventParameter& keyParam = keyInput->GetKeyEventParameter();
			SInt32 func = keyMappingManager.GetFunction(keyParam);
			if (KeyFuncOperation::KeyFunc_None == func)
			{
				assignedFuncEdit->SetText(ALITERAL(""));
			}
			else
			{
				bool found = false;
				SInt32 index;
				for (index = 0; KeyFuncOperation::KeyFunc_None != funcInfo[index].keyFunc; index++)
				{
					if (funcInfo[index].keyFunc == func)
					{
						NativeStringLoader* stringLoader = CoveredCalcApp::GetInstance();
						MBCString funcName = stringLoader->LoadNativeString(funcInfo[index].funcNameId);
						assignedFuncEdit->SetText(funcName.CString());
						found = true;
						break;
					}
				}
				if (!found)
				{
					assignedFuncEdit->SetText(ALITERAL(""));
				}
			}
		}
	}
}
Пример #7
0
/**
 *	@brief	Called when remove button is clicked.
 */
void EditKeymapDlg::handleRemoveButtonClicked()
{
	UICListBox* funcList = getFunctionListBox();
	UICListBox* currentKeysList = getCurrentKeysListBox();
	if (NULL == funcList || NULL == currentKeysList)
	{
		return;
	}
	
	SInt32 funcIndex = funcList->GetSelectedItem();
	if (funcIndex < 0)
	{
		// function is not selected.
		return;
	}
	const FuncInfo* funcInfo = static_cast<FuncInfo*>(funcList->GetItemData(funcIndex));

	SInt32 keyIndex = currentKeysList->GetSelectedItem();
	if (keyIndex < 0)
	{
		// key is not selected.
		return;
	}
	const KeyEventParameter* keyParam = static_cast<KeyEventParameter*>(currentKeysList->GetItemData(keyIndex));

	keyMappingManager.RemoveKey(funcInfo->keyFunc, *keyParam);
	isModified = true;
	
	UICKeyInput* keyInput = getKeyInput();
	if (NULL != keyInput)
	{
		keyInput->StopValueChangedNotification(true);
	}
	handleFunctionListBoxSelectionChanged();
	if (NULL != keyInput)
	{
		keyInput->StopValueChangedNotification(false);
	}
	handleKeyInputChanged();
}
Пример #8
0
/**
 *	@brief	Updates enable/disable state of assign button.
 */
void EditKeymapDlg::updateAssignButtonState()
{
	if (isReadOnly)
	{
		return;
	}

	UICButton* assignButton = getAssignButton();
	if (NULL == assignButton)
	{
		return;
	}

	bool isFuncOK = false;
	bool isKeyOK = false;

	UICListBox* funcList = getFunctionListBox();
	if (NULL != funcList)
	{
		if (funcList->GetSelectedItem() >= 0)
		{
			isFuncOK = true;
		}
	}
	
	UICKeyInput* keyInput = getKeyInput();
	if (NULL != keyInput)
	{
		const KeyEventParameter& keyParam = keyInput->GetKeyEventParameter();
		if (keyParam.IsValid())
		{
			isKeyOK = true;
		}
	}
	
	assignButton->Enable(isFuncOK && isKeyOK);
}