Example #1
0
/** Special Key Press Event */
void EventMgr::OnSpecialKeyPress(unsigned char Key)
{
	if (!last_win_focused) {
		return;
	}
	Control *ctrl = NULL;

	// tab shows tooltips
	if (Key == GEM_TAB) {
		if (last_win_over != NULL) {
			Control *ctrl = last_win_over->GetOver();
			if (ctrl != NULL) {
				ctrl->DisplayTooltip();
			}
		}
	}
	//the default control will get only GEM_RETURN
	else if (Key == GEM_RETURN) {
		ctrl = last_win_focused->GetDefaultControl(0);
	}
	//the default cancel control will get only GEM_ESCAPE
	else if (Key == GEM_ESCAPE) {
		ctrl = last_win_focused->GetDefaultControl(1);
	} else if (Key >= GEM_FUNCTION1 && Key <= GEM_FUNCTION16) {
		if (function_bar) {
			ctrl = function_bar->GetFunctionControl(Key-GEM_FUNCTION1);
		} else {
			ctrl = last_win_focused->GetFunctionControl(Key-GEM_FUNCTION1);
		}
	}

	//if there was no default button set, then the current focus will get it (except function keys)
	if (!ctrl) {
		if (Key<GEM_FUNCTION1 || Key > GEM_FUNCTION16) {
			ctrl = last_win_focused->GetFocus();
		}
	}
	//if one is under focus, use the default scroll focus
	if (!ctrl) {
		if (Key == GEM_UP || Key == GEM_DOWN) {
			ctrl = last_win_focused->GetScrollControl();
		}
	}
	if (ctrl) {
		switch (ctrl->ControlType) {
			//scrollbars will receive only mousewheel events
			case IE_GUI_SCROLLBAR:
				if (Key != GEM_UP && Key != GEM_DOWN) {
					return;
				}
				break;
			//buttons will receive only GEM_RETURN
			case IE_GUI_BUTTON:
				if (Key >= GEM_FUNCTION1 && Key <= GEM_FUNCTION16) {
					//fake mouse button
					ctrl->OnMouseDown(0,0,GEM_MB_ACTION,0);
					ctrl->OnMouseUp(0,0,GEM_MB_ACTION,0);
					return;
				}
				if (Key != GEM_RETURN && Key!=GEM_ESCAPE) {
					return;
				}
				break;
			case IE_GUI_GAMECONTROL:
			case IE_GUI_WORLDMAP:
				//gamecontrols will receive all special keys
				break;
			case IE_GUI_EDIT:
			case IE_GUI_TEXTAREA:
				//editboxes and textareas will receive all special keys
				break;
			default:
				//other controls don't receive any
				return;
		}
		ctrl->OnSpecialKeyPress( Key );
	}
}
Example #2
0
File: bsgui.cpp Project: 3da/BSGUI
bool HandleSDLEvent(SDL_Event *ev)
{
    Control	*child;

    if (!Screen::screen)
        return false;

    switch (ev->type)
    {
    case SDL_MOUSEBUTTONDOWN:
        if (Control::trackControl)
        {
            Control::trackControl->OnMouseDown(ev->button.x, ev->button.y, ev->button.button);
            return true;
        }
        if (Screen::screen->exclusiveChild)
        {
            int	x1, y1, x2, y2;
            Screen::screen->exclusiveChild->GetBounds(x1, y1, x2, y2);
            if (!(ev->button.x >= x1 && ev->button.x <= x2 && ev->button.y >= y1 && ev->button.y <= y2))
                return false;
            child = Screen::screen->exclusiveChild->ChildAt(ev->button.x, ev->button.y);
        }
        else
            child = Screen::screen->ChildAt(ev->button.x, ev->button.y);
        if (child->visible)
            return child->OnMouseDown(ev->button.x, ev->button.y, ev->button.button);
        return false;
    case SDL_MOUSEBUTTONUP:
        if (Control::trackControl)
        {
            Control::trackControl->OnMouseUp(ev->button.x, ev->button.y, ev->button.button);
            return true;
        }
        if (Screen::screen->exclusiveChild)
            child = Screen::screen->exclusiveChild->ChildAt(ev->button.x, ev->button.y);
        else
            child = Screen::screen->ChildAt(ev->button.x, ev->button.y);
        if (child->visible)
            return child->OnMouseUp(ev->button.x, ev->button.y, ev->button.button);
        return false;
    case SDL_MOUSEMOTION:
        if (Control::trackControl)
        {
            Control::trackControl->OnMouseMoved(ev->button.x, ev->button.y);
            return true;
        }
        if (Screen::screen->exclusiveChild)
            child = Screen::screen->exclusiveChild->ChildAt(ev->motion.x, ev->motion.y);
        else
            child = Screen::screen->ChildAt(ev->motion.x, ev->motion.y);
        if (Control::lastChildUnderMouse != child)
        {
            if (Control::lastChildUnderMouse)
                Control::lastChildUnderMouse->OnMouseExit();
            Control::lastChildUnderMouse = child;
            child->OnMouseEnter();
        }
        if (child->visible)
            return child->OnMouseMoved(ev->motion.x, ev->motion.y);
        return false;
    case SDL_KEYDOWN:
        if (!(Control::keyboardFocusControl && Control::keyboardFocusControl->Focused()))
            return false;
        return Control::keyboardFocusControl->OnKeyDown(ev->key.keysym.sym, ev->key.keysym.unicode);
    case SDL_KEYUP:
        if (!(Control::keyboardFocusControl && Control::keyboardFocusControl->Focused()))
            return false;
        return Control::keyboardFocusControl->OnKeyUp(ev->key.keysym.sym, ev->key.keysym.unicode);
    }
    return false;
}