Exemple #1
0
static void FreeResources(void)
{
  if(g_glcontext)
  {
    SDL_GL_DeleteContext(g_glcontext);
    g_glcontext = NULL;
  }

  if(g_renderer)
  {
    SDL_DestroyRenderer(g_renderer);
    g_renderer = NULL;
  }

  if(g_texture)
  {
    SDL_DestroyTexture(g_texture);
    g_texture = NULL;
  }

  if(g_screen)
  {
    SDL_FreeSurface(g_screen);
    g_screen = NULL;
  }

  if(g_window)
  {
    SDL_GetWindowPosition(g_window, &g_lastx, &g_lasty);
    SDL_DestroyWindow(g_window);
    g_window = NULL;
  }

}
Exemple #2
0
    void InputWrapper::handleWindowEvent(const SDL_Event& evt)
    {
        switch (evt.window.event) {
            case SDL_WINDOWEVENT_ENTER:
                mMouseInWindow = true;
                updateMouseSettings();
                break;
            case SDL_WINDOWEVENT_LEAVE:
                mMouseInWindow = false;
                updateMouseSettings();
                break;
            case SDL_WINDOWEVENT_MOVED:
                // I'm not sure what OSG is using the window position for, but I don't think it's needed,
                // so we ignore window moved events (improves window movement performance)
                break;
            case SDL_WINDOWEVENT_SIZE_CHANGED:
                int w,h;
                SDL_GetWindowSize(mSDLWindow, &w, &h);
                int x,y;
                SDL_GetWindowPosition(mSDLWindow, &x,&y);
                mViewer->getCamera()->getGraphicsContext()->resized(x,y,w,h);

                mViewer->getEventQueue()->windowResize(x,y,w,h);

                if (mWindowListener)
                    mWindowListener->windowResized(w, h);

                break;

            case SDL_WINDOWEVENT_RESIZED:
                // This should also fire SIZE_CHANGED, so no need to handle
                break;

            case SDL_WINDOWEVENT_FOCUS_GAINED:
                mWindowHasFocus = true;
                updateMouseSettings();
                if (mWindowListener)
                    mWindowListener->windowFocusChange(true);

                break;
            case SDL_WINDOWEVENT_FOCUS_LOST:
                mWindowHasFocus = false;
                updateMouseSettings();
                if (mWindowListener)
                    mWindowListener->windowFocusChange(false);
                break;
            case SDL_WINDOWEVENT_CLOSE:
                break;
            case SDL_WINDOWEVENT_SHOWN:
            case SDL_WINDOWEVENT_RESTORED:
                if (mWindowListener)
                    mWindowListener->windowVisibilityChange(true);
                break;
            case SDL_WINDOWEVENT_HIDDEN:
            case SDL_WINDOWEVENT_MINIMIZED:
                if (mWindowListener)
                    mWindowListener->windowVisibilityChange(false);
                break;
        }
    }
Exemple #3
0
void Window::getPosition(int &x, int &y, int &displayindex)
{
	if (!window)
	{
		x = y =  0;
		displayindex = 0;
		return;
	}

	displayindex = std::max(SDL_GetWindowDisplayIndex(window), 0);

	SDL_GetWindowPosition(window, &x, &y);

	// In SDL <= 2.0.3, fullscreen windows are always reported as 0,0. In every
	// other case we need to convert the position from global coordinates to the
	// monitor's coordinate space.
	if (x != 0 || y != 0)
	{
		SDL_Rect displaybounds = {};
		SDL_GetDisplayBounds(displayindex, &displaybounds);

		x -= displaybounds.x;
		y -= displaybounds.y;
	}
}
Exemple #4
0
	MyGUI::IntCoord BaseManager::getWindowCoord()
	{
		int left, top, width, height;
		SDL_GetWindowPosition(mWindow, &left, &top);
		SDL_GetWindowSize(mWindow, &width, &height);
		return MyGUI::IntCoord(left, top, width, height);
	}
Exemple #5
0
    glm::uvec2 Window::getPosition() const
    {
        int x, y;
        SDL_GetWindowPosition(window_, &x, &y);

        return {x, y};
    }
Exemple #6
0
    math::vector<int, 2> window::get_mouse_position() const
    {
        int x, y;
        SDL_GetGlobalMouseState(&x, &y);

        int window_x, window_y;
        SDL_GetWindowPosition(handle.get(), &window_x, &window_y);

        x -= window_x;
        y -= window_y;

        // SDL_GetGlobalMouseState and SDL_GetWindowPosition return "screen
        // coordinates", as in scaled values. We'll need to convert these to
        // pixels before we can do anything with them.

        // TODO: is this also the case on Windows?

        // TODO: seeing as get_position/set_position and get_size/set_size
        // operate in "screen coordinates", there might also be use for a
        // variant of get_mouse_position that returns "screen coordinates".

        x *= get_backbuffer_width() / get_width();
        y *= get_backbuffer_height() / get_height();

        return { x, y };
    }
S32 VideoSystem::getWindowPositionCoord(bool getX)
{
   S32 x, y;
   SDL_GetWindowPosition(DisplayManager::getScreenInfo()->sdlWindow, &x, &y);

   return getX ? x : y;
}
Exemple #8
0
static inline bool _gut_savebnds(GutCore *core) {
	if (gut.core->window.mode != GUT_MODE_WINDOWED) {
		// bounds undefined, use desktop bounds
		SDL_Rect bounds;
		if (!_gut_getbnds(&bounds))
			return false;
		int x, y;
		x = (bounds.w - gut.window.width) / 2;
		if (x < 0) x = 0;
		y = (bounds.h - gut.window.height) / 2;
		if (y < 0) y = 0;
		core->window.windowbounds.x = x;
		core->window.windowbounds.y = y;
		core->window.windowbounds.w = gut.window.width;
		core->window.windowbounds.h = gut.window.height;
		return true;
	}
	// recycle old bounds
	SDL_GetWindowPosition(
		core->window.handle,
		&core->window.windowbounds.x, &core->window.windowbounds.y
	);
	SDL_GetWindowSize(
		core->window.handle,
		&core->window.windowbounds.w, &core->window.windowbounds.h
	);
	return true;
}
/** Returns the size and location of the window when it is restored */
bool FLinuxWindow::GetRestoredDimensions(int32& X, int32& Y, int32& Width, int32& Height)
{
	SDL_GetWindowPosition(HWnd, &X, &Y);
	SDL_GetWindowSize(HWnd, &Width, &Height);

	return true;
}
Exemple #10
0
void Window::updatePosition()
{
	int x, y;
	SDL_GetWindowPosition(pointer, &x, &y);

	position.set(x, y);
}
Exemple #11
0
const struct point *video_get_position( )
{
	static struct point point;

	SDL_GetWindowPosition( video_window, &point.x, &point.y );
	return &point;
}
Exemple #12
0
    math::vector<int, 2> window::get_position() const
    {
        int x = 0, y = 0;

        SDL_GetWindowPosition(handle.get(), &x, &y);

        return { x, y };
    }
Exemple #13
0
    int window::get_y() const
    {
        int y = 0;

        SDL_GetWindowPosition(handle.get(), nullptr, &y);

        return y;
    }
Exemple #14
0
	point sdl_window::mouse_position() const
	{
		int x, y;
		SDL_Window* mouseFocus = SDL_GetMouseFocus();
		SDL_GetMouseState(&x, &y);
		if (mouseFocus != 0)
		{
			int mfx, mfy;
			SDL_GetWindowPosition(mouseFocus, &mfx, &mfy);
			x += mfx;
			y += mfy;
			SDL_GetWindowPosition(iHandle, &mfx, &mfy);
			x -= mfx;
			y -= mfy;
		}
		return point(static_cast<coordinate>(x), static_cast<coordinate>(y));
	}
Exemple #15
0
    int window::get_x() const
    {
        int x = 0;

        SDL_GetWindowPosition(handle.get(), &x, nullptr);

        return x;
    }
Exemple #16
0
void FLinuxCursor::SetPosition( const int32 X, const int32 Y )
{
	int WndX, WndY;

	SDL_HWindow WndFocus = SDL_GetMouseFocus();

	SDL_GetWindowPosition( WndFocus, &WndX, &WndY );	//	get top left
	SDL_WarpMouseInWindow( NULL, X - WndX, Y - WndY );
}
Exemple #17
0
GHOST_TSuccess GHOST_SystemSDL::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y)
{
  int x_win, y_win;
  SDL_Window *win = SDL_GetMouseFocus();
  SDL_GetWindowPosition(win, &x_win, &y_win);

  SDL_WarpMouseInWindow(win, x - x_win, y - y_win);
  return GHOST_kSuccess;
}
Exemple #18
0
	int Window::getWindowPosition(State & state, SDL_Window  * window){
		int x, y;
		SDL_GetWindowPosition(window, &x, &y);
		Stack * stack = state.stack;
		stack->newTable();
		stack->setField<int>("x", x, -2);
		stack->setField<int>("y", y, -2);
		return 1;
	}
Exemple #19
0
	int SDLWindow::GetY () {
		
		int x;
		int y;
		
		SDL_GetWindowPosition (sdlWindow, &x, &y);
		
		return y;
		
	}
void
GHOST_WindowSDL::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
{
	/* XXXSDL_WEAK_ABS_COORDS */
	int x_win, y_win;
	SDL_GetWindowPosition(m_sdl_win, &x_win, &y_win);

	outX = inX + x_win;
	outY = inY + y_win;
}
Exemple #21
0
//
// save the window position
//
void saveSettings(const char *configName, SDL_Window *window, int fontScale) {
  FILE *fp = openConfig(configName, "w");
  if (fp) {
    int x, y, w, h;
    SDL_GetWindowPosition(window, &x, &y);
    SDL_GetWindowSize(window, &w, &h);
    fprintf(fp, "%d,%d,%d,%d,%d,%d\n", x, y, w, h, fontScale, opt_mute_audio);
    fclose(fp);
  }
}
    Vec2I SDL2WindowBackend::getPosition() const
    {
        Vec2I s;
        s.x = 0;
        s.y = 0;

        if(isOpen())
            SDL_GetWindowPosition(mWindow, &s.x, &s.y);

        return s;
    }
void
GHOST_WindowSDL::getClientBounds(GHOST_Rect& bounds) const
{
	int x, y, w, h;
	SDL_GetWindowSize(m_sdl_win, &w, &h);
	SDL_GetWindowPosition(m_sdl_win, &x, &y);

	bounds.m_l = x;
	bounds.m_r = x + w;
	bounds.m_t = y;
	bounds.m_b = y + h;
}
Exemple #24
0
	const Rect &SDLWindow::GetPosition()
	{
		int x, y, w, h;
		SDL_GetWindowPosition(window, &x, &y);
		SDL_GetWindowSize(window, &w, &h);

		position.x = (double)x;
		position.y = (double)y;
		position.w = (double)w;
		position.h = (double)h;
		return this->start_location;
	}
SDL_Rect Window::getWindowDimensions()
{
    auto w = 0;
    auto h = 0;
    auto x = 0;
    auto y = 0;

    SDL_GetWindowSize(window, &w, &h);
    SDL_GetWindowPosition(window, &x, &y);

    return { x, y, w, h};
}
/*
 * Shuffles the window around in a circle
 * PARAMS:
 *		iters: number of times to move in a full circle
 *		offset: pixel distance moved at each step
 *		delay: time between steps (not full circles)
 */
void CycleAround(int iters, int offset, int delay) {
	int x, y;
	SDL_GetWindowPosition(window, &x, &y);

	int cnt;
	for(cnt=0; cnt < iters; cnt++) {
		SDL_SetWindowPosition(window, x+offset, y); 	   SDL_Delay(delay);
		SDL_SetWindowPosition(window, x+offset, y+offset); SDL_Delay(delay);
		SDL_SetWindowPosition(window, x,        y+offset); SDL_Delay(delay);
		SDL_SetWindowPosition(window, x,        y);        SDL_Delay(delay);
	}
	EndDemo();
}
Exemple #27
0
GHOST_TSuccess GHOST_SystemSDL::getCursorPosition(GHOST_TInt32 &x, GHOST_TInt32 &y) const
{
  int x_win, y_win;
  SDL_Window *win = SDL_GetMouseFocus();
  SDL_GetWindowPosition(win, &x_win, &y_win);

  int xi, yi;
  SDL_GetMouseState(&xi, &yi);
  x = xi + x_win;
  y = yi + x_win;

  return GHOST_kSuccess;
}
Exemple #28
0
bool gutGetWindowPosition(unsigned *x, unsigned *y) {
	chkwin;
	int xp, yp;
	SDL_GetWindowPosition(
		gut.core->window.handle,
		&xp, &yp
	);
	if (xp < 0 || yp < 0)
		return false;
	if (x) *x = xp;
	if (y) *y = yp;
	return true;
}
	const Rect SDLGameWindow::VGetClientBounds()
	{
	    if(m_fullscreen) {
            SDL_GetWindowPosition(m_windowHandle, &m_clientRect.x, &m_clientRect.y);
            SDL_GetWindowSize(m_windowHandle, &m_clientRect.w, &m_clientRect.h);
	    }
		else {
            //we will take the requested size from config
            m_clientRect.w = m_parent->GetConfig()->WindowArgs().width;
            m_clientRect.h = m_parent->GetConfig()->WindowArgs().height;
        }

		return m_clientRect;
	}
Exemple #30
0
void Window::getInfo( WindowInfo& info ) const noexcept
{
    info.id = getID();
    info.title = SDL_GetWindowTitle( m_wimpl->window );
    info.wflags = fromSDL2Flags_( SDL_GetWindowFlags( m_wimpl->window ) );

    SDL_GetWindowPosition( m_wimpl->window, &info.x, &info.y );
    SDL_GetWindowSize( m_wimpl->window, &info.w, &info.h );
    info.lw = getLogicalWidth();
    info.lh = getLogicalHeight();

    SDL_RendererInfo rinfo;
    SDL_GetRendererInfo( m_wimpl->renderer, &rinfo );
    info.accel = ( ( rinfo.flags & SDL_RENDERER_ACCELERATED ) != 0 );
}