Example #1
0
/** BroadCast Mouse Move Event */
void EventMgr::MouseDown(unsigned short x, unsigned short y, unsigned short Button,
	unsigned short Mod)
{
	std::vector< int>::iterator t;
	std::vector< Window*>::iterator m;
	Control *ctrl;
	unsigned long thisTime;

	thisTime = GetTickCount();
	if (ClickMatch(x, y, thisTime)) {
		Button |= GEM_MB_DOUBLECLICK;
		dc_x = 0;
		dc_y = 0;
		dc_time = 0;
	} else {
		dc_x = x;
		dc_y = y;
		dc_time = thisTime+dc_delay;
	}
	MButtons |= Button;
	for (t = topwin.begin(); t != topwin.end(); ++t) {
		m = windows.begin();
		m += ( *t );
		if (( *m ) == NULL)
			continue;
		if (!( *m )->Visible)
			continue;
		if (( ( *m )->XPos <= x ) && ( ( *m )->YPos <= y )) {
			//Maybe we are on the window, let's check
			if (( ( *m )->XPos + ( *m )->Width >= x ) &&
				( ( *m )->YPos + ( *m )->Height >= y )) {
				//Yes, we are on the Window
				//Let's check if we have a Control under the Mouse Pointer
				ctrl = ( *m )->GetControl( x, y, true );
				if (!ctrl) {
					ctrl = ( *m )->GetControl( x, y, false);
				}
				last_win_mousefocused = *m;
				if (ctrl != NULL) {
					last_win_mousefocused->SetMouseFocused( ctrl );
					ctrl->OnMouseDown( x - last_win_mousefocused->XPos - ctrl->XPos, y - last_win_mousefocused->YPos - ctrl->YPos, Button, Mod );
					return;
				}
			}
		}
		if (( *m )->Visible == WINDOW_FRONT) //stop looking further
			break;
	}
	
	if ((Button == GEM_MB_SCRLUP || Button == GEM_MB_SCRLDOWN) && last_win_mousefocused) {
		ctrl = last_win_mousefocused->GetScrollControl();
		if (ctrl) {
			ctrl->OnMouseDown( x - last_win_mousefocused->XPos - ctrl->XPos, y - last_win_mousefocused->YPos - ctrl->YPos, Button, Mod );
		}
	}

	if (last_win_mousefocused) {
		last_win_mousefocused->SetMouseFocused(NULL);
	}
}
Example #2
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 #3
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;
}