示例#1
0
文件: Widget.cpp 项目: biddyweb/ewol
bool ewol::Widget::rmFocus() {
	if (m_canFocus == true) {
		if (m_hasFocus == true) {
			m_hasFocus = false;
			onLostFocus();
		}
		return true;
	}
	return false;
}
bool EventStageScene::Listener::init()
{
	auto callback = [this](EventCustom* event)
			{
				EventStageScene *event_ = static_cast<EventStageScene*>(event);
				if (event_->isGainFocus())
				{
					if (onGainFocus)
					{
						onGainFocus(event_->getScene(), event_);
					}
				}
				else
				{
					if (onLostFocus)
					{
						onLostFocus(event_->getScene(), event_);
					}
				}
			};

	return EventListenerCustom::init(EventStageScene::kEventId, callback);
}
示例#3
0
void EditWidget::update(float)
{
	LabelWidget::onMouseClick();

	if(hasFocus())
	{
		size_t key=0;

		// Get keyboard input
		if(g_Keys.getKey(key, shift))
		{
			if(debounce == false || lastKey!=key)
			{
				debounce = true;

				string label = getLabel();

				switch(key)
				{
				case SDLK_BACKSPACE:
					label = label.substr(0, label.size()-1);
					break;
				case SDLK_SPACE:
					label = label + " ";
					break;
				case SDLK_SLASH: // '/?' key
					if(shift)
					{
						label = label + "?";
					}
					else
					{
						label = label + "/";
					}
					break;
				case SDLK_COLON:
					label = label + ":";
					break;
				case SDLK_SEMICOLON:
					label = label + ";";
					break;
				case SDLK_QUESTION:
					label = label + "?";
					break;
				case SDLK_BACKSLASH: // '|\' key
					if(shift)
					{
						label = label + "|";
					}
					else
					{
						label = label + "\\";
					}
					break;
				case SDLK_KP_DIVIDE:
					label = label + "/";
					break;
				case SDLK_MINUS:
					if(shift)
					{
						label = label + "_";
					}
					else
					{
						label = label + "-";
					}
					break;
				case SDLK_KP_MINUS:
					label = label + "-";
					break;
				case SDLK_KP_PERIOD:
				case SDLK_PERIOD:
					label = label + ".";
					break;
				case SDLK_COMMA:
					label = label + ",";
					break;
				default:
					{
						if(key >= SDLK_a && key <= SDLK_z)
						{
							char keyName[2] =
							{
								(char)(  shift ? toupper((int)key) : tolower((int)key)  ),
								0
							};

							label = label + keyName;
						}
						else
						{
							if(key==SDLK_1) label += shift ? "!" : "1";
							if(key==SDLK_2) label += shift ? "@" : "2";
							if(key==SDLK_3) label += shift ? "#" : "3";
							if(key==SDLK_4) label += shift ? "$" : "4";
							if(key==SDLK_5) label += shift ? "%" : "5";
							if(key==SDLK_6) label += shift ? "^" : "6";
							if(key==SDLK_7) label += shift ? "&" : "7";
							if(key==SDLK_8) label += shift ? "*" : "8";
							if(key==SDLK_9) label += shift ? "(" : "9";
							if(key==SDLK_0) label += shift ? ")" : "0";
						}
					}
					break;
				};

				setLabel(label);
				lastKey = key;
			}
		}
		else
		{
			debounce = false;
		}
	}
	else if(hadFocusLastTick) // Have we lost focus?
	{
		onLostFocus();
	}

	// House keeping
	hadFocusLastTick = hasFocus();
}