Beispiel #1
0
void XxWindow::HandleEvent (const XEvent &WinEvent)
{
    switch (WinEvent.type) {
    case ClientMessage:
        if (WinEvent.xclient.format == 32) {
            const long *l = WinEvent.xclient.data.l;
            if (*l == (long)GetWmDeleteWindow ()) OnDelete ();
        };
        break;
    case Expose:
        OnExpose
            ( WinEvent.xexpose.x
            , WinEvent.xexpose.y
            , WinEvent.xexpose.width
            , WinEvent.xexpose.height
            );
        break;
    case ButtonPress:
        OnButtonPress
            ( WinEvent.xbutton.button
            , WinEvent.xbutton.x
            , WinEvent.xbutton.y
            );
        break;
    case ButtonRelease:
        OnButtonRelease
            ( WinEvent.xbutton.button
            , WinEvent.xbutton.x
            , WinEvent.xbutton.y
            );
        break;
    case EnterNotify:
        OnEnterWindow
            ( WinEvent.xcrossing.x
            , WinEvent.xcrossing.y
            );
        break;
    case LeaveNotify:
        OnLeaveWindow
            ( WinEvent.xcrossing.x
            , WinEvent.xcrossing.y
            );
        break;
    case ResizeRequest:
        OnResize
            ( WinEvent.xresizerequest.width
            , WinEvent.xresizerequest.height
            );
        break;
    default:
        break;
    };
};
Beispiel #2
0
    void Module::OnEvent(const SDL_Event& event)
    {
        switch (event.type)
        {
            case SDL_WINDOWEVENT:
            {
                switch (event.window.event)
                {
                    case SDL_WINDOWEVENT_ENTER: OnMouseFocus(); break;
                    case SDL_WINDOWEVENT_LEAVE: OnMouseBlur(); break;
                    case SDL_WINDOWEVENT_FOCUS_GAINED: OnInputFocus(); break;
                    case SDL_WINDOWEVENT_FOCUS_LOST: OnInputBlur(); break;
                    case SDL_WINDOWEVENT_RESTORED: OnRestore(); break;
                    case SDL_WINDOWEVENT_MINIMIZED: OnMinimize(); break;
                    case SDL_WINDOWEVENT_MAXIMIZED: OnMaximize(); break;
                    case SDL_WINDOWEVENT_EXPOSED: OnExpose(); break;

                    case SDL_WINDOWEVENT_SIZE_CHANGED:
                        OnResize(event.window.data1, event.window.data2);
                        break;

                    default: break;
                }

                break;
            }

            case SDL_KEYDOWN:
                if (event.key.repeat)
                    OnKeyRepeat(event.key.keysym);
                else
                    OnKeyDown(event.key.keysym);
                break;

            case SDL_KEYUP: OnKeyUp(event.key.keysym); break;
            case SDL_MOUSEMOTION: OnMouseMove(event.motion); break;
            case SDL_MOUSEWHEEL: OnMouseWheel(event.wheel); break;
            case SDL_MOUSEBUTTONDOWN: OnMouseButtonDown(event.button); break;
            case SDL_MOUSEBUTTONUP: OnMouseButtonUp(event.button); break;

            case SDL_JOYAXISMOTION: OnJoyAxis(event.jaxis); break;
            case SDL_JOYBALLMOTION: OnJoyBall(event.jball); break;
            case SDL_JOYHATMOTION: OnJoyHat(event.jhat); break;
            case SDL_JOYBUTTONDOWN: OnJoyButtonDown(event.jbutton); break;
            case SDL_JOYBUTTONUP: OnJoyButtonUp(event.jbutton); break;
            case SDL_QUIT: OnExit(); break;
            case SDL_SYSWMEVENT: break;

            default: OnUser(event.user);break;
        }
    }
Beispiel #3
0
void Viewport::Expose( CullingTarget& target ) const {
	if( IsVisible() ) {
		if( GetChild() ) {
			unsigned int target_width = target.GetWidth();
			unsigned int target_height = target.GetHeight();

			sf::View view(
				sf::FloatRect(
					std::floor( m_horizontal_adjustment->GetValue() + .5f ),
					std::floor( m_vertical_adjustment->GetValue() + .5f ),
					GetAllocation().Width,
					GetAllocation().Height
				)
			);

			float viewport_left = std::floor( Widget::GetAbsolutePosition().x + .5f ) / static_cast<float>( target_width );
			float viewport_top = std::floor( Widget::GetAbsolutePosition().y + .5f ) / static_cast<float>( target_height );
			float viewport_width = GetAllocation().Width / static_cast<float>( target_width );
			float viewport_height = GetAllocation().Height / static_cast<float>( target_height );

			// Make sure float to int rounding errors can't lead to streching effects.
			if( static_cast<int>( viewport_width * static_cast<float>( target_width ) ) < static_cast<int>( GetAllocation().Width ) ) {
				viewport_width += 1.f / static_cast<float>( target_width );
			}

			if( static_cast<int>( viewport_height * static_cast<float>( target_height ) ) < static_cast<int>( GetAllocation().Height ) ) {
				viewport_height += 1.f / static_cast<float>( target_height );
			}

			view.SetViewport(
				sf::FloatRect(
					viewport_left,
					viewport_top,
					viewport_width,
					viewport_height
				)
			);

			sf::View original_view = target.GetView();

			target.SetView( view );

			GetChild()->Expose( target );

			target.SetView( original_view );
		}

		OnExpose();
	}
}
Beispiel #4
0
void Widget::Expose( CullingTarget& target ) const {
	if( m_invalidated ) {
		m_invalidated = false;

		m_drawable.reset( InvalidateImpl() );

		if( m_drawable ) {
			m_drawable->SetPosition( GetAbsolutePosition() );
		}
	}

	if( IsVisible() ) {
		if( m_drawable ) {
			target.Draw( *m_drawable );
		}

		HandleExpose( target );
		OnExpose();
	}
}
Beispiel #5
0
static void MsgLoop(Display* dpy, Window win, GC gc, XFontStruct* font)
{
    int running = 1;
    XEvent evt;
    Atom wm_quit = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
    XSelectInput(dpy, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | PointerMotionMask);
    XSetWMProtocols(dpy, win, &wm_quit, 1);
    while(running)
    {
        XNextEvent(dpy, &evt);
        switch(evt.type)
        {
            case Expose:
                if(evt.xexpose.count)
                    break;
                OnExpose(&evt.xexpose, gc, font);
                break;
                //    case ConfigureNotify:
                //      Resize(wnd, evt.xconfigure.width, evt.xconfigure.height);
                //      break;
            case KeyPress:
                OnKeyPress(&evt.xkey);
                break;
            case ButtonPress:
                OnButtonPress(&evt.xbutton);
                break;
            case MotionNotify:
                OnMotionNotify(&evt.xmotion);
                break;
            case ClientMessage:
                if(evt.xclient.data.l[0] != wm_quit)
                    continue;
                running = 0;
                break;
        }
    }
    //Stop receiving events
    XSelectInput(dpy, win, NoEventMask);
}
Beispiel #6
0
void CEvent::OnEvent(SDL_Event* Event) {
	switch(Event->type) {

		case SDL_ACTIVEEVENT: {
			switch(Event->active.state) {
				case SDL_APPMOUSEFOCUS: {
					if ( Event->active.gain )	OnMouseFocus();
					else				OnMouseBlur();

					break;
				}
				case SDL_APPINPUTFOCUS: {
					if ( Event->active.gain )	OnInputFocus();
					else				OnInputBlur();

					break;
				}
				case SDL_APPACTIVE:	{
					if ( Event->active.gain )	OnRestore();
					else				OnMinimize();

					break;
				}
			}
			break;
		}

		case SDL_KEYDOWN: {
			OnKeyDown(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
			break;
		}

		case SDL_KEYUP: {
			OnKeyUp(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
			break;
		}

		case SDL_MOUSEMOTION: {
			OnMouseMove(Event->motion.x,Event->motion.y,Event->motion.xrel,Event->motion.yrel,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0);
			break;
		}

		case SDL_MOUSEBUTTONDOWN: {
			switch(Event->button.button) {
				case SDL_BUTTON_LEFT: {
					OnLButtonDown(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_RIGHT: {
					OnRButtonDown(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_MIDDLE: {
					OnMButtonDown(Event->button.x,Event->button.y);
					break;
				}
			}
			break;
		}

		case SDL_MOUSEBUTTONUP:	{
			switch(Event->button.button) {
				case SDL_BUTTON_LEFT: {
					OnLButtonUp(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_RIGHT: {
					OnRButtonUp(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_MIDDLE: {
					OnMButtonUp(Event->button.x,Event->button.y);
					break;
				}
			}
			break;
		}

		case SDL_JOYAXISMOTION: {
			OnJoyAxis(Event->jaxis.which,Event->jaxis.axis,Event->jaxis.value);
			break;
		}

		case SDL_JOYBALLMOTION: {
			OnJoyBall(Event->jball.which,Event->jball.ball,Event->jball.xrel,Event->jball.yrel);
			break;
		}

		case SDL_JOYHATMOTION: {
			OnJoyHat(Event->jhat.which,Event->jhat.hat,Event->jhat.value);
			break;
		}
		case SDL_JOYBUTTONDOWN: {
			OnJoyButtonDown(Event->jbutton.which,Event->jbutton.button);
			break;
		}

		case SDL_JOYBUTTONUP: {
			OnJoyButtonUp(Event->jbutton.which,Event->jbutton.button);
			break;
		}

		case SDL_QUIT: {
			OnExit();
			break;
		}

		case SDL_SYSWMEVENT: {
			//Ignore
			break;
		}

		case SDL_VIDEORESIZE: {
			OnResize(Event->resize.w,Event->resize.h);
			break;
		}

		case SDL_VIDEOEXPOSE: {
			OnExpose();
			break;
		}

		default: {
			OnUser(Event->user.type,Event->user.code,Event->user.data1,Event->user.data2);
			break;
		}
	}
}
Beispiel #7
0
void CEvent::OnEvent(SDL_Event* Event) {
	switch (Event->type) {
	case SDL_WINDOWEVENT: {
		switch (Event->window.event) {
		case SDL_WINDOWEVENT_ENTER:			{ OnMouseFocus();	break; }
		case SDL_WINDOWEVENT_LEAVE:			{ OnMouseBlur();	break; }
		case SDL_WINDOWEVENT_FOCUS_GAINED:	{ OnInputFocus();	break; }				//keyboard focus. What is keyboard focus?
		case SDL_WINDOWEVENT_FOCUS_LOST:	{ OnInputBlur();	break; }
		case SDL_WINDOWEVENT_RESTORED:		{ OnRestore();		break; }
		case SDL_WINDOWEVENT_MINIMIZED:		{ OnMinimize();		break; }

		case SDL_WINDOWEVENT_RESIZED:		{ OnResize(Event->window.data1, Event->window.data2); break; }
		case SDL_WINDOWEVENT_EXPOSED:		{ OnExpose();		break; }
		case SDL_WINDOWEVENT_CLOSE:			{ OnExit();			break; }
		}
		break;
	}

	case SDL_KEYDOWN:					{ OnKeyDown(Event->key.keysym.sym, Event->key.keysym.mod);	break; }
	case SDL_KEYUP:						{ OnKeyUp(Event->key.keysym.sym, Event->key.keysym.mod);	break; }

	case SDL_MOUSEMOTION: {
		OnMouseMove(Event->motion.x, Event->motion.y, Event->motion.xrel, Event->motion.yrel, (Event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT)) != 0, (Event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0, (Event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0);
		break;
	}

	case SDL_MOUSEBUTTONDOWN: {
								  switch (Event->button.button) {
								  case SDL_BUTTON_LEFT: {
															OnLButtonDown(Event->button.x, Event->button.y);
															break;
								  }
								  case SDL_BUTTON_RIGHT: {
															 OnRButtonDown(Event->button.x, Event->button.y);
															 break;
								  }
								  case SDL_BUTTON_MIDDLE: {
															  OnMButtonDown(Event->button.x, Event->button.y);
															  break;
								  }
								  }
								  break;
	}

	case SDL_MOUSEBUTTONUP:    {
								   switch (Event->button.button) {
								   case SDL_BUTTON_LEFT: {
															 OnLButtonUp(Event->button.x, Event->button.y);
															 break;
								   }
								   case SDL_BUTTON_RIGHT: {
															  OnRButtonUp(Event->button.x, Event->button.y);
															  break;
								   }
								   case SDL_BUTTON_MIDDLE: {
															   OnMButtonUp(Event->button.x, Event->button.y);
															   break;
								   }
								   }
								   break;
	}

	case SDL_JOYAXISMOTION: {
								OnJoyAxis(Event->jaxis.which, Event->jaxis.axis, Event->jaxis.value);
								break;
	}

	case SDL_JOYBALLMOTION: {
								OnJoyBall(Event->jball.which, Event->jball.ball, Event->jball.xrel, Event->jball.yrel);
								break;
	}

	case SDL_JOYHATMOTION: {
							   OnJoyHat(Event->jhat.which, Event->jhat.hat, Event->jhat.value);
							   break;
	}
	case SDL_JOYBUTTONDOWN: {
								OnJoyButtonDown(Event->jbutton.which, Event->jbutton.button);
								break;
	}

	case SDL_JOYBUTTONUP: {
							  OnJoyButtonUp(Event->jbutton.which, Event->jbutton.button);
							  break;
	}

	case SDL_QUIT: {
					   OnExit();
					   break;
	}

	case SDL_SYSWMEVENT: {
							 //Ignore
							 break;
	}

	default: {
				 OnUser(Event->user.type, Event->user.code, Event->user.data1, Event->user.data2);
				 break;
	}
	}
}
Beispiel #8
0
void Event::OnEvent(SDL_Event * e)
{
    switch(e->type) {
        case SDL_ACTIVEEVENT: {
            switch(e->active.state) {
                case SDL_APPMOUSEFOCUS: {
                    if ( e->active.gain )    OnMouseFocus();
                    else OnMouseBlur();
					
                    break;
                }
                case SDL_APPINPUTFOCUS: {
                    if ( e->active.gain )    OnInputFocus();
                    else OnInputBlur();
					
                    break;
                }
                case SDL_APPACTIVE:    {
                    if ( e->active.gain )    OnRestore();
                    else OnMinimize();
					
                    break;
                }
            }
            break;
        }
			
        case SDL_KEYDOWN: {
            OnKeyDown(e->key.keysym.sym,e->key.keysym.mod,e->key.keysym.unicode);
            break;
        }
			
        case SDL_KEYUP: {
            OnKeyUp(e->key.keysym.sym,e->key.keysym.mod,e->key.keysym.unicode);
            break;
        }
			
        case SDL_MOUSEMOTION: {
            OnMouseMove(e->motion.x,e->motion.y,e->motion.xrel,e->motion.yrel,(e->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(e->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(e->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0);
            break;
        }
			
        case SDL_MOUSEBUTTONDOWN: {
            switch(e->button.button) {
                case SDL_BUTTON_LEFT: {
                    OnLButtonDown(e->button.x,e->button.y);
                    break;
                }
                case SDL_BUTTON_RIGHT: {
                    OnRButtonDown(e->button.x,e->button.y);
                    break;
                }
                case SDL_BUTTON_MIDDLE: {
                    OnMButtonDown(e->button.x,e->button.y);
                    break;
                }
            }
            break;
        }
			
        case SDL_MOUSEBUTTONUP:    {
            switch(e->button.button) {
                case SDL_BUTTON_LEFT: {
                    OnLButtonUp(e->button.x,e->button.y);
                    break;
                }
                case SDL_BUTTON_RIGHT: {
                    OnRButtonUp(e->button.x,e->button.y);
                    break;
                }
                case SDL_BUTTON_MIDDLE: {
                    OnMButtonUp(e->button.x,e->button.y);
                    break;
                }
            }
            break;
        }
					
        case SDL_QUIT: {
            OnExit();
            break;
        }
			
        case SDL_SYSWMEVENT: {
            //Ignore
            break;
        }
			
        case SDL_VIDEORESIZE: {
            OnResize(e->resize.w,e->resize.h);
            break;
        }
			
        case SDL_VIDEOEXPOSE: {
            OnExpose();
            break;
        }
			
        default: {
            OnUser(e->user.type,e->user.code,e->user.data1,e->user.data2);
            break;
        }
    }
}
Beispiel #9
0
//==============================================================================
void CEvent::OnEvent(SDL_Event* Event) {
	switch(Event->type) {
		case SDL_ACTIVEEVENT: {
			switch(Event->active.state) {//check to see what event has occured
				case SDL_APPMOUSEFOCUS: {
					if ( Event->active.gain )	OnMouseFocus();
					else				OnMouseBlur();

					break;
				}
				case SDL_APPINPUTFOCUS: {
					if ( Event->active.gain )	OnInputFocus();
					else				OnInputBlur();

					break;
				}
				case SDL_APPACTIVE:	{
					if ( Event->active.gain )	OnRestore();
					else				OnMinimize();

					break;
				}
			}
			break;
		}

		case SDL_KEYDOWN: {//on key down pass in what was pressed
			OnKeyDown(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
			break;
		}

		case SDL_KEYUP: {//on key up pass in what was depressed
			OnKeyUp(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
			break;
		}

		case SDL_MOUSEMOTION: {//
			OnMouseMove(Event->motion.x,Event->motion.y,Event->motion.xrel,Event->motion.yrel,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0);
			break;
		}

		case SDL_MOUSEBUTTONDOWN: {//if the button on the mouse is pressed pass in its x and y
			switch(Event->button.button) {
				case SDL_BUTTON_LEFT: {
					OnLButtonDown(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_RIGHT: {
					OnRButtonDown(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_MIDDLE: {
					OnMButtonDown(Event->button.x,Event->button.y);
					break;
				}
			}
			break;
		}

		case SDL_MOUSEBUTTONUP:	{
			switch(Event->button.button) {
				case SDL_BUTTON_LEFT: {
					OnLButtonUp(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_RIGHT: {
					OnRButtonUp(Event->button.x,Event->button.y);
					break;
				}
				case SDL_BUTTON_MIDDLE: {
					OnMButtonUp(Event->button.x,Event->button.y);
					break;
				}
			}
			break;
		}

		case SDL_JOYAXISMOTION: {//stuff we dont use
			OnJoyAxis(Event->jaxis.which,Event->jaxis.axis,Event->jaxis.value);
			break;
		}

		case SDL_JOYBALLMOTION: {
			OnJoyBall(Event->jball.which,Event->jball.ball,Event->jball.xrel,Event->jball.yrel);
			break;
		}

		case SDL_JOYHATMOTION: {
			OnJoyHat(Event->jhat.which,Event->jhat.hat,Event->jhat.value);
			break;
		}
		case SDL_JOYBUTTONDOWN: {
			OnJoyButtonDown(Event->jbutton.which,Event->jbutton.button);
			break;
		}

		case SDL_JOYBUTTONUP: {
			OnJoyButtonUp(Event->jbutton.which,Event->jbutton.button);
			break;
		}

		case SDL_QUIT: {//if SDL is quit then run the exit function
			OnExit();
			break;
		}
		//more stufff we dont use

		case SDL_SYSWMEVENT: {
			//Ignore
			break;
		}

		case SDL_VIDEORESIZE: {
			OnResize(Event->resize.w,Event->resize.h);
			break;
		}

		case SDL_VIDEOEXPOSE: {
			OnExpose();
			break;
		}

		default: {
			OnUser(Event->user.type,Event->user.code,Event->user.data1,Event->user.data2);
			break;
		}
	}
}