SDL mouse range on resize - linux

I am developing a SDL OpenGL application on Ubuntu and have noticed a problem with the mouse range when a new window size is set. The initiale size of my application is 600x400 and the mouse range (x,y) reflects this. However, when a user changes the screen to any other size (using given predefined sizes), the mouse range still only reflects a 600x400 screen size and causes issues with mouse location functionality.
To set the new resolution, I call:
SDL_SetVideoMode(Width, Height, 32, SDL_OPENGL); which to my understanding should handle the mouse range resizing but doesn't seem to do so in Linux. Can anyone give me a solution to this problem?
Note: Possible hack seem to be to exit SDL and re-initialize using SDL_Init(SDL_INIT_EVERYTHING);

After some digging, I found the problem was that I was calling SDL_GetMouseState(0,0) later after the size change was made which apparently was interfering with the recalculation of the mouse range. However, I've gone through the SDL source but I can't really determine how this would effect it so. There seems to be some mouse state switching that may be causing it.

Anytime i resize the window, I execute the following to refresh my viewport:
m_ParentWindow = SDL_SetVideoMode( m_width, m_height, m_depth, m_SDL_Vid_Flags );
glViewport(0,0,m_width,m_height);
Clear();
Where Clear calls:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

Related

How to change FlxG width and height, ResizeGame doesn't work

how do i change FlxG width and height in runtime as resizeGame doesn't do anything
i have the project by default set to 1600 x 900 and i have a state for settings where i can change the resolution and have managed to make it so that i can change what the width and height will be on startup however i want to be able to resize it during runtime so it will be higher/lower res.
the problem is since FlxG width and height aren't modifiable directly so resizeGame is the only option but it doesn't do anything, even after calling it and tracing FlxG width and height there is no difference nor is there any visual difference asside from the game being offset to the very top left corner of the window and messing up detecting where the mouse is until i maximise and restore down where it goes back to normal
does anyone have any idea why this isn't working and how i should go about fixing it
i'm compiling to c++ (windows)
edit: it has been a couple of months and i have started mostly rewriting the program and yet this issue is still a thing on a fresh start and i am in serious need of an answer

Splash Screen Shared Element Transition On Bigger Screens

I want to make a splash screen that appears when i open the app and disappears after 3 seconds, with the image being shared with the next activity.
On smaller screens(for example Pixel 2) the animation works without problems, but when i try it on my OnePlus 6 or Pixel 3 XL, the image always clips to like 50dp below it's position right before the transition.
What could be the problem?
For anyone having the same problem.
The issue was that i was setting a color on the splash screen's frame background. If i didn't set any color, it would work fine.
I found a way around it by adding a view that expanded the whole screen and setting the color to the view instead.
I hope this will help someone eventually.

Phaser - Change width and height Camera

In normal i have canvas size 500x500 and it will create camera size (500,500)
But when i change
game.camera.width=5;
game.camera.height=5;
then visible area it the same? what will happen when change width and height camera, how to understand that thanks
Based upon the documentation and an older post from the creator of Phaser on the HTML5 Game Dev Forum where he said:
You're not doing anything wrong, you just can't change the camera dimensions - they match the game size at the moment.
and then in 2015 on the same thread:
So you can tell if something is within the camera bounds or not. Which is impossible if the camera doesn't have a size.
suggesting that things haven't changed since 2013, and the camera doesn't resize as you're expecting.
Testing as well suggests that things haven't changed either.

How to take screenshot of obscured window in C++ on Linux

I'm trying to figure out how to take a screenshot of a window that is currently not focused, so there is a good chance that the window will be partially or fully obscured by other windows.
I've found an example here on this link Get a screenshot of a window that is cover or not visible or minimized with Xcomposite extension for X11 but I can't make it work, any time I take a screenshot I get only strange output, mostly black, like I'm accessing the wrong buffer or something.
XID xid = windowID; // Checked and confirmed that the window ID is correct
XGetWindowAttributes( display, windowID, &attrributes );
XCompositeRedirectWindow (display, xid, CompositeRedirectAutomatic);
Pixmap pixmap = XCompositeNameWindowPixmap (display, xid);
// Extract the data
XRenderPictFormat *format = XRenderFindVisualFormat (display, attrributes.visual);
XRenderPictureAttributes pa;
pa.subwindow_mode = IncludeInferiors;
Picture picture = XRenderCreatePicture (display, xid, format, CPSubwindowMode, &pa);
QPixmap finalPix (attrributes.width, attrributes.height);
XRenderComposite (display, PictOpSrc, picture, None, finalPix.x11PictureHandle(), 0,0, 0,0, 0,0, attrributes.width, attrributes.height);
XFreePixmap (display, pixmap);
XCompositeUnredirectWindow (display, xid, CompositeRedirectAutomatic);
return finalPix;
(Edit: This screenshot was taken from a fully visible window, not an obscured window, so I guess currently the issue is not even that X11 doesn't draw it but my implementation seems to be not working and I can't figure out why.)
And this is how a screenshot of my konsole window looks:
First of all Qt has this feature. You can use: QScreen::grabWindow.
Problem is that documentation says:
Note on X11 that if the given window doesn't have the same depth as
the root window, and another window partially or entirely obscures the
one you grab, you will not get pixels from the overlying window. The
contents of the obscured areas in the pixmap will be undefined and
uninitialized.
So this will simplify your code, but obscured parts of window will still remains as a problem. Looks like functionality of x11 won't let to resolve this issue.
There is a good example how to use this feature.

Paint red lines on rulers indicating the mouse position (MFC/Direct2D)

I would like to implement red lines moving oh H/V rulers similar to what I see in windows paint brush (8.1) indicating current mouse position. See the example (red line at 560):
What would be the best way to do it. Direct2D Animation? layers? any other simple trick? The thing here is of cause doing it efficiently without repainting the whole area on mouse move.
I currently using MFC/direct2d so I paint myself the area with field and rulers inside the view, so I have full control on graphics here.
There are many ways to attack this problem. The simplest is to rely on your OnPaint function to paint the line in a location based on a member variable. In your OnMouseMove handler, call InvalidateRect on the current location of the line based on the saved variable, update the variable, and call InvalidateRect a second time for the new line position.
The BeginPaint call that is generated in the CPaintDC constructor will set a clipping region based on the invalidation rectangles you provided. Even if your OnPaint tries to paint the entire window, only those parts that have been invalidated will be redrawn. If this is too inefficient, you can cache the ruler in a bitmap and use GetClipBox to determine which part of the bitmap to blit to the screen.

Resources