示例#1
0
文件: CList.cpp 项目: Rektosauros/0ad
InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev)
{
	InReaction result = IN_PASS;

	if (ev->ev.type == SDL_KEYDOWN)
	{
		int szChar = ev->ev.key.keysym.sym;

		switch (szChar)
		{
		case SDLK_HOME:
			SelectFirstElement();
			UpdateAutoScroll();
			result = IN_HANDLED;
			break;

		case SDLK_END:
			SelectLastElement();
			UpdateAutoScroll();
			result = IN_HANDLED;
			break;

		case SDLK_UP:
			SelectPrevElement();
			UpdateAutoScroll();
			result = IN_HANDLED;
			break;

		case SDLK_DOWN:
			SelectNextElement();
			UpdateAutoScroll();
			result = IN_HANDLED;
			break;

		case SDLK_PAGEUP:
			GetScrollBar(0).ScrollMinusPlenty();
			result = IN_HANDLED;
			break;

		case SDLK_PAGEDOWN:
			GetScrollBar(0).ScrollPlusPlenty();
			result = IN_HANDLED;
			break;

		default: // Do nothing
			result = IN_PASS;
		}
	}

	return result;
}
示例#2
0
文件: CList.cpp 项目: Rektosauros/0ad
void CList::HandleMessage(SGUIMessage& Message)
{
	IGUIScrollBarOwner::HandleMessage(Message);
	//IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!

	m_Modified = false;
	switch (Message.type)
	{
	case GUIM_SETTINGS_UPDATED:
		if (Message.value == "list")
			SetupText();

		// If selected is changed, call "SelectionChange"
		if (Message.value == "selected")
		{
			// TODO: Check range

			// TODO only works if lower-case, shouldn't it be made case sensitive instead?
			ScriptEvent("selectionchange");
		}

		if (Message.value == "scrollbar")
			SetupText();

		// Update scrollbar
		if (Message.value == "scrollbar_style")
		{
			CStr scrollbar_style;
			GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);

			GetScrollBar(0).SetScrollBarStyle(scrollbar_style);

			SetupText();
		}

		break;

	case GUIM_MOUSE_PRESS_LEFT:
	{
		bool enabled;
		GUI<bool>::GetSetting(this, "enabled", enabled);
		if (!enabled)
		{
			CStrW soundPath;
			if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty())
				g_SoundManager->PlayAsUI(soundPath.c_str(), false);
			break;
		}

		bool scrollbar;
		CGUIList* pList;
		GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
		GUI<CGUIList>::GetSettingPointer(this, "list", pList);
		float scroll = 0.f;
		if (scrollbar)
			scroll = GetScrollBar(0).GetPos();

		CRect rect = GetListRect();
		CPos mouse = GetMousePos();
		mouse.y += scroll;
		int set = -1;
		for (int i = 0; i < (int)pList->m_Items.size(); ++i)
		{
			if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
				mouse.y < rect.top + m_ItemsYPositions[i+1] &&
				// mouse is not over scroll-bar
				!(mouse.x >= GetScrollBar(0).GetOuterRect().left &&
				mouse.x <= GetScrollBar(0).GetOuterRect().right))
			{
				set = i;
			}
		}

		if (set != -1)
		{
			GUI<int>::SetSetting(this, "selected", set);
			UpdateAutoScroll();

			CStrW soundPath;
			if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty())
				g_SoundManager->PlayAsUI(soundPath.c_str(), false);
		}
		break;
	}

	case GUIM_LOAD:
	{
		CStr scrollbar_style;
		GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
		GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
		break;
	}

	default:
		break;
	}

	IGUITextOwner::HandleMessage(Message);
}
示例#3
0
void CList::HandleMessage(SGUIMessage &Message)
{
    IGUIScrollBarOwner::HandleMessage(Message);
    //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!

    switch (Message.type)
    {
    case GUIM_SETTINGS_UPDATED:
        if (Message.value == "list")
        {
            SetupText();
        }

        // If selected is changed, call "SelectionChange"
        if (Message.value == "selected")
        {
            // TODO: Check range

            // TODO only works if lower-case, shouldn't it be made case sensitive instead?
            ScriptEvent("selectionchange");
        }

        if (Message.value == "scrollbar")
        {
            SetupText();
        }

        // Update scrollbar
        if (Message.value == "scrollbar_style")
        {
            CStr scrollbar_style;
            GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);

            GetScrollBar(0).SetScrollBarStyle( scrollbar_style );

            SetupText();
        }

        break;

    case GUIM_MOUSE_PRESS_LEFT:
    {
        bool enabled;
        GUI<bool>::GetSetting(this, "enabled", enabled);
        if (!enabled)
            break;

        bool scrollbar;
        CGUIList *pList;
        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
        GUI<CGUIList>::GetSettingPointer(this, "list", pList);
        float scroll=0.f;
        if (scrollbar)
        {
            scroll = GetScrollBar(0).GetPos();
        }

        CRect rect = GetListRect();
        CPos mouse = GetMousePos();
        mouse.y += scroll;
        int set=-1;
        for (int i=0; i<(int)pList->m_Items.size(); ++i)
        {
            if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
                    mouse.y < rect.top + m_ItemsYPositions[i+1] &&
                    // mouse is not over scroll-bar
                    !(mouse.x >= GetScrollBar(0).GetOuterRect().left &&
                      mouse.x <= GetScrollBar(0).GetOuterRect().right))
            {
                set = i;
            }
        }

        if (set != -1)
        {
            GUI<int>::SetSetting(this, "selected", set);
            UpdateAutoScroll();
        }
    }
    break;

    case GUIM_MOUSE_WHEEL_DOWN:
    {
        GetScrollBar(0).ScrollPlus();
        // Since the scroll was changed, let's simulate a mouse movement
        //  to check if scrollbar now is hovered
        SGUIMessage msg(GUIM_MOUSE_MOTION);
        HandleMessage(msg);
        break;
    }
    case GUIM_MOUSE_WHEEL_UP:
    {
        GetScrollBar(0).ScrollMinus();
        // Since the scroll was changed, let's simulate a mouse movement
        //  to check if scrollbar now is hovered
        SGUIMessage msg(GUIM_MOUSE_MOTION);
        HandleMessage(msg);
        break;
    }
    case GUIM_LOAD:
    {
        CStr scrollbar_style;
        GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
        GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
    }
    break;

    default:
        break;
    }

    IGUITextOwner::HandleMessage(Message);
}