/*********************************************************\
         __      __           __  __
        / /     / / _____    / / / / ______   __     __
       / /     / / /___  \  / / / / / ___  | / /    / /
      / /_____/ / _____| / / / / / / /__/ / / /    / /
     / ______  / / ___  / / / / / / _____/ / /    / /
    / /     / / / /__/ / / / / / / |____  / |____/ /
   /_/     /_/ |______/ /_/ /_/  \_____/  \_____  /
                                         ______/ /
            High Level Game Framework   /_______/

  ------------------------------------------------------

  Copyright (c) 2009 - Rodrigo Braz Monteiro.
  This file is subject to the terms of license.txt.

\*********************************************************/

#include "input_keyboard.h"
using namespace Halley;

InputKeyboard::InputKeyboard()
	: InputButtonBase(SDLK_LAST)
{
}

void InputKeyboard::processEvent(const SDL_Event &_event)
{
	const SDL_KeyboardEvent& event = _event.key;
	switch (event.type) {
		case SDL_KEYUP:
			onButtonReleased(event.keysym.sym);
			break;
		case SDL_KEYDOWN:
			onButtonPressed(event.keysym.sym);
			letterEntered(event.keysym.unicode);
			break;
	}
}


void InputKeyboard::letterEntered(int code)
{
	letters.push_back(code);
}

int InputKeyboard::getNextLetter()
{
	if (letters.size()) {
		int letter = letters.front();
		letters.pop_front();
		return letter;
	} else {
		return 0;
	}
}
