How can I get the screen resolution using SDL2? - c++

I'm using pixel-perfect source images and SDL2 to make a program. When set to fullscreen, I'd like it to use the native resolution (the SDL_WINDOW_FULLSCREEN_DESKTOP flag) but only between a certain minimum resolution and a reasonable maximum one, after which it will stretch from the largest legal resolution. The problem is that I can only find references to the program's own window or program size on the SDL2 documentation.
Is there any function in SDL from which I could retrieve the screen width and height at least almost directly?
Or I should do something like using SDL_WINDOW_FULLCREEN_DESKTOP and then SDL_GetWindowSize() and resizing the window again? Would this even work as expected? I'd like to fins a more elegant solution than that. It feels dirty.

In the SDL 2 wiki, you have a category named Display and Window Management. It lists everything you need to know about SDL 2's management of displays (screens) and windows.
You have multiple choices, the most generic would be using SDL_GetCurrentDisplayMode or SDL_GetDesktopDisplayMode. The difference is explained in the wiki :
There's a difference between SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() when SDL runs fullscreen and has changed the resolution. In that case SDL_GetDesktopDisplayMode() will return the previous native display mode, and not the current display mode.
After setting a SDL_DisplayMode with one of these, you can retrieve its attributes w and h.
However, there is another function that might be more appropriate and straightforward : SDL_GetDisplayBounds. If I am not mistaken, it gives you the coordinates of the display relative to the whole set of displays that can be active on the computer, and also the size of the display.
Both methods need you to know the index of the display you want to know about. I have not played that much with this part of SDL 2, but I guess you can use SDL_GetNumVideoDisplays to get the number of displays (and check if there is at least one ? - I think the SDL_Window part might not work if there is no display available anyway) and choose one. Or you could pick the first one, which has index 0.
Oh, and you can look at the exemple on the page of SDL_GetCurrentDisplayMode, they effectively retreive the size of a display.

Related

Custom frame/decoration for specific X window

Is there any way to apply or have custom frames (images) around specific X windows?
For example, in xfwm4 and fvwm (window managers) it's possible to have a specific window decoration for a window with different images, one at the bottom, other at the top, etc. examples:
For xfwm4 and fvwm.
Obviously if it was that easy, I'd just use either of them, however, I do think that a singular program could handle it instead of needing to change the whole window manager.
I'm currently using dwm and there are ways to change the colour and thickness of border, and that's it. If I was better at C I could create a rule to draw images around specific X windows with specific WM_CLASS, but that's too much for me now, so any help is really appreciated.
An alternative solution would be to draw a single image (from a file) bigger than the X window behind it and make it to follow the X window position, and maybe the size as well (that's harder, so it's not really that necessary)
I started writing a C++ program to do that, but that may take too much time since C++ still a new tool to me and looking at how xfwm4 handles this.

C++ && QT Is there a way to create "warm screen" color using c++ and qt on Mac && Windows

Is there some way to change screen "saturation" ? Make screen in warm colors \ or make it in sepia using c++ && qt on win\mac ?
As a reference modern monitors have such a menu option on changing the screen color or you can also check the app for linux f.lux as a reference ...
The first thing that comes on my mind is to create some transparent " window on top " make a screenshot and play around with rgb ... but it will be not the best solution
There's no Qt API that will help you with that. On either platform you'll have to use native APIs to change the screen color reproduction curves and shift the color temperature to warmer tones. The situation on OS X would be more uniform in that the API to do that either exists on all hardware or on none. On Windows, things might be more complicated. Some undocumented vendor APIs probably exist, used by respective vendor control panels to alter the color temperature. There are also all ways you could hook yourself into the screen compositing pipeline, but this may require writing a driver. Unfortunately, I'm not too familiar with how easy it might be. It'll be probably either very simple or very complicated. There are some simple workarounds, like adding a translucent tinted window on top of everything, but those don't look good.
Neither C++ nor Qt facilitate such functionality. It seems for windows it is possible to modify brightness and contrast for the display, but that's about it, no saturation, no colorization.
The "make a screenshot and play around with rgb" will have abysmal performance and a number of other possible complications, such as event handling.
Now, if you want to apply a color filter to your Qt application, Qt has the QGraphicsEffect class, which automatically hooks up with the rendering system, caches the target to an image and applies to desired effect. I am not sure how well will that work for the "transparent window on top" idea.
It only has a few stock effects, but you can easily roll out your own. Then you can use QWidget::setGraphicsEffect(QGraphicsEffect * effect) to apply it to the desired widget or derived.

Expanding Qt interface if necessary

I'm working on a Qt project and I've noticed a persistent problem with some GUI forms. The form looks fine on KDE (bottom picture) and Windows , but when the app runs on anything GNOME3-based (like Unity or GNOME3 itself) some parts of the form are hidden from view. (Top picture, everything below the Sort Ascending radio button is cut off)
The problem seems to be with how Qt layouts handle large font sizes. If the user is using normal-sized system font (<= 10pt) everything works fine. If they are using larger fonts, the form is not large enough to accommodate everything. Other forms affected by this bug are merely crowded, but that isn't as serious as having vital controls out of bounds. The layout doesn't want to resize itself to take advantage of new space if I enlarge the dialog. Is there an easy way to make it do this or do I need to hard-code it? Originally the code prevented dialog resizing during runtime, but restoring that functionality didn't fix the bug. Even if the dialog can expand, the problem is the layout won't expand with it.
Up until now, I've made all affected forms oversized to compensate for this bug, but it looks strange to have the dialogs much bigger than they need to be on Windows and KDE systems where the font is the proper size. Is there a way to cause an affected dialog/layout to resize itself so everything fits properly at runtime? If so, how would the program detect it when parts of the GUI are out of bounds? I would prefer not to force a certain font size (some people may prefer large fonts due to vision problems).
Thanks in advance for help.
The fix for this is using a different approach when displaying forms. A more dynamic way as I'll describe. I've successfully used this approach on Windows with 96 and very high DPI modes (over 120).
1.
Query the OS and get the user's chosen font for a particular system item; say the font used for the window caption or system dialog boxes. Also you could allow the user to choose their font later if they desired. Use True Type fonts when doing this if possible.
2.
Using that font, construct a string object that you'll use for a label or edit control (I don't know what this is for QT, for Windows it is GetTextExtentPoint32) and pass it to a system function to determine the width and height of the string for your environment.
3.
Given the above value, place the control and dynamically resize the form with the padding all around the control as you like. For buttons you might always add a certain percentage of pixels above and below the button to taste.
4.
For graphical elements like Bitmaps and jpegs, again query the OS for the current DPI settings of the monitor and use larger, pre-made resources. Naturally, all text around theses elements will be dynamically placed on the fly.
Note that on Windows you'll need to mark your exe as high dpi aware using a manifest.

GetwindowoffsetEx in windows XP and up

I have an visaul object up and running
GetwindowoffsetEx moved the canvas around
But I cannot change the size of the canvas to my needs
Like should I not beable to change the canvas size for a A4-A3 printer or to a picture size
can this be done using the windows API
I do not seem to get the instructions to do this.
I take it that if I want a Zoom, I strech draw from another cavuas
am I asking the obvious in all this.
Lex Dean
I'm struggling to understand exactly what I need but you seem to want to map between two coordinate spaces in GDI.
Whilst you can use the fully general SetWorldTransform(), I suspect you are better off with the following functions:
SetWindowOrgEx(), SetWindowExtEx()
SetViewportOrgEx(), SetViewportExtEx()
The MSDN documentation also includes a full list of functions related to coordinate space transformations.

Supporting different monitor resolutions

I have a MFC application with some bitmaps, dialog boxes and menus. Currently it supports only one monitor resolution (1280x1024). I am planning to add different monitor resolution support to it. To do that I guess I have to load different resolution bitmaps, change the font size etc. My question is, how these are handled in a typical windows application? Do they use a single bitmap and stretch/shrink it according to monitor resolution or actually have different set of bitmaps in the resource and load them dynamically depending on the resolution? Is there any standard solution to this?
In the past I have used one large image and scaled accordingly.
Making sure that the menus and dialogs resize is tricky but there are helper codes on CodeProject that could help.
I would say to use multiple resources with different resolutions. While you can scale the icons dynamically, they'll probably look better if you resize them in a proper image-editing program.
Menu and toolbar icons are normally displayed with the same number of pixels regardless of screen resolution. Thus menus and toolbars take up a smaller proportion of the screen as the resolution increases.
I don't think there's any standard way of handling different resolutions where bitmaps are concerned.
I would also make sure your application works with Windows DPI scaling. That might be a better alternative when running on higher resolution displays rather than having to redesign the application to meet a specific resolution.
Scaling bitmaps will look bad (making them bigger will always look bad, making them smaller kind of depends on the source). If possible, see if you can compose your big bitmap of several smaller bitmaps that can scale nicely. Lots of times it is fairly easy to make a bitmap that can scale in one direction nicely. For example, if you want to make a frame around something, instead of using one bitmap, cut it up like a tic-tac-toe board into 9 pieces. the four corner pieces stay their original size, the top and bottom pieces stretch horizontally, the left and right vertically, and the center goes both directions (if it is used at all).