| @@ -2133,13 +2133,13 @@ void flipFrame(void) · 2132 unmodified lines |
| 2133 | void updateSpectrumAnalyzer(int8_t vol, int16_t period) | 2133 | void updateSpectrumAnalyzer(int8_t vol, int16_t period) |
| 2134 | { | 2134 | { |
| 2135 | const uint8_t maxHeight = SPECTRUM_BAR_HEIGHT + 1; // +1 because of audio latency - allows full height to be seen | 2135 | const uint8_t maxHeight = SPECTRUM_BAR_HEIGHT + 1; // +1 because of audio latency - allows full height to be seen |
| 2136 | uint8_t scaledVol; | 2136 | uint16_t scaledVol; |
| 2137 | uint32_t scaledNote; | 2137 | uint32_t scaledNote; |
| 2138 | | 2138 | |
| 2139 | if (ui.visualizerMode != VISUAL_SPECTRUM || vol <= 0) | 2139 | if (ui.visualizerMode != VISUAL_SPECTRUM || vol <= 0) |
| 2140 | return; | 2140 | return; |
| 2141 | | 2141 | |
| 2142 | scaledVol = (vol * 24600L) >> 16; // scaledVol = (vol * 256) / 682 = (x / 2.66) | 2142 | scaledVol = ((uint16_t)vol * 24576) >> 16; // scaledVol = vol / 2.66667 (0..64 -> 0..24) |
| 2143 | | 2143 | |
| 2144 | period = CLAMP(period, 113, 856); | 2144 | period = CLAMP(period, 113, 856); |
| 2145 | period -= 113; | 2145 | period -= 113; |
| @@ -2149,14 +2149,14 @@ void updateSpectrumAnalyzer(int8_t vol, int16_t period) · 3 unmodified lines |
| 2149 | scaledNote /= 25093; // scaledNote now ranges 0..22, no need to clamp | 2149 | scaledNote /= 25093; // scaledNote now ranges 0..22, no need to clamp |
| 2150 | | 2150 | |
| 2151 | // increment main spectrum bar | 2151 | // increment main spectrum bar |
| 2152 | editor.spectrumVolumes[scaledNote] += scaledVol; | 2152 | editor.spectrumVolumes[scaledNote] += (uint8_t)scaledVol; |
| 2153 | if (editor.spectrumVolumes[scaledNote] > maxHeight) | 2153 | if (editor.spectrumVolumes[scaledNote] > maxHeight) |
| 2154 | editor.spectrumVolumes[scaledNote] = maxHeight; | 2154 | editor.spectrumVolumes[scaledNote] = maxHeight; |
| 2155 | | 2155 | |
| 2156 | // increment left side of spectrum bar with half volume | 2156 | // increment left side of spectrum bar with half volume |
| 2157 | if (scaledNote > 0) | 2157 | if (scaledNote > 0) |
| 2158 | { | 2158 | { |
| 2159 | editor.spectrumVolumes[scaledNote-1] += scaledVol >> 1; | 2159 | editor.spectrumVolumes[scaledNote-1] += (uint8_t)(scaledVol >> 1); |
| 2160 | if (editor.spectrumVolumes[scaledNote-1] > maxHeight) | 2160 | if (editor.spectrumVolumes[scaledNote-1] > maxHeight) |
| 2161 | editor.spectrumVolumes[scaledNote-1] = maxHeight; | 2161 | editor.spectrumVolumes[scaledNote-1] = maxHeight; |
| 2162 | } | 2162 | } |
| @@ -2164,7 +2164,7 @@ void updateSpectrumAnalyzer(int8_t vol, int16_t period) · 1 unmodified line |
| 2164 | // increment right side of spectrum bar with half volume | 2164 | // increment right side of spectrum bar with half volume |
| 2165 | if (scaledNote < SPECTRUM_BAR_NUM-1) | 2165 | if (scaledNote < SPECTRUM_BAR_NUM-1) |
| 2166 | { | 2166 | { |
| 2167 | editor.spectrumVolumes[scaledNote+1] += scaledVol >> 1; | 2167 | editor.spectrumVolumes[scaledNote+1] += (uint8_t)(scaledVol >> 1); |
| 2168 | if (editor.spectrumVolumes[scaledNote+1] > maxHeight) | 2168 | if (editor.spectrumVolumes[scaledNote+1] > maxHeight) |
| 2169 | editor.spectrumVolumes[scaledNote+1] = maxHeight; | 2169 | editor.spectrumVolumes[scaledNote+1] = maxHeight; |
| 2170 | } | 2170 | } |
| @@ -2202,21 +2202,24 @@ void sinkVisualizerBars(void) · 31 unmodified lines |
| 2202 | | 2202 | |
| 2203 | void updateRenderSizeVars(void) | 2203 | void updateRenderSizeVars(void) |
| 2204 | { | 2204 | { |
| 2205 | int32_t di; | | |
| 2206 | #ifdef __APPLE__ | | |
| 2207 | int32_t actualScreenW, actualScreenH; | | |
| 2208 | double dXUpscale, dYUpscale; | | |
| 2209 | #endif | | |
| 2210 | float fXScale, fYScale; | 2205 | float fXScale, fYScale; |
| 2211 | SDL_DisplayMode dm; | | |
| 2212 | | 2206 | |
| 2213 | di = SDL_GetWindowDisplayIndex(video.window); | 2207 | if (video.useDesktopMouseCoords) |
| 2214 | if (di < 0) | 2208 | { |
| 2215 | di = 0; // return display index 0 (default) on error | 2209 | SDL_DisplayMode dm; |
| 2216 | | 2210 | |
| 2217 | SDL_GetDesktopDisplayMode(di, &dm); | 2211 | int32_t di = SDL_GetWindowDisplayIndex(video.window); |
| 2218 | video.displayW = dm.w; | 2212 | if (di < 0) |
| 2219 | video.displayH = dm.h; | 2213 | di = 0; // return display index 0 (default) on error |
| | 2214 | |
| | 2215 | SDL_GetDesktopDisplayMode(di, &dm); |
| | 2216 | video.displayW = dm.w; |
| | 2217 | video.displayH = dm.h; |
| | 2218 | } |
| | 2219 | else |
| | 2220 | { |
| | 2221 | SDL_GetWindowSize(video.window, &video.displayW, &video.displayH); |
| | 2222 | } |
| 2220 | | 2223 | |
| 2221 | if (video.fullscreen) | 2224 | if (video.fullscreen) |
| 2222 | { | 2225 | { |
| @@ -2234,20 +2237,25 @@ void updateRenderSizeVars(void) · 11 unmodified lines |
| 2234 | video.renderW = (int32_t)(SCREEN_W * fXScale); | 2237 | video.renderW = (int32_t)(SCREEN_W * fXScale); |
| 2235 | video.renderH = (int32_t)(SCREEN_H * fYScale); | 2238 | video.renderH = (int32_t)(SCREEN_H * fYScale); |
| 2236 | | 2239 | |
| 2237 | #ifdef __APPLE__ | 2240 | // high-DPI hackery: |
| 2238 | // retina high-DPI hackery (SDL2 is bad at reporting actual rendering sizes on macOS w/ high-DPI) | 2241 | // On high-DPI systems, the display w/h are given in logical pixels, |
| | 2242 | // but the renderer size is given in physical pixels. Since our internal |
| | 2243 | // render{X,Y,W,H} variables need to be in logical coordinates, as that's |
| | 2244 | // what mouse input uses, scale them by the screen's DPI scale factor, |
| | 2245 | // which is the physical (renderer) size / the logical (window) size. |
| | 2246 | // On non high-DPI systems, this is effectively a no-op. |
| | 2247 | int32_t actualScreenW, actualScreenH; |
| 2239 | SDL_GL_GetDrawableSize(video.window, &actualScreenW, &actualScreenH); | 2248 | SDL_GL_GetDrawableSize(video.window, &actualScreenW, &actualScreenH); |
| 2240 | SDL_GetDesktopDisplayMode(0, &dm); | | |
| 2241 | | 2249 | |
| 2242 | dXUpscale = (double)actualScreenW / video.displayW; | 2250 | const double dXUpscale = (const double)actualScreenW / video.displayW; |
| 2243 | dYUpscale = (double)actualScreenH / video.displayH; | 2251 | const double dYUpscale = (const double)actualScreenH / video.displayH; |
| 2244 | | 2252 | |
| 2245 | // downscale back to correct sizes | 2253 | // downscale back to correct sizes |
| 2246 | if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale); | 2254 | if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale); |
| 2247 | if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale); | 2255 | if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale); |
| 2248 | #endif | 2256 | |
| 2249 | video.renderX = (video.displayW - video.renderW) >> 1; | 2257 | video.renderX = (video.displayW - video.renderW) / 2; |
| 2250 | video.renderY = (video.displayH - video.renderH) >> 1; | 2258 | video.renderY = (video.displayH - video.renderH) / 2; |
| 2251 | } | 2259 | } |
| 2252 | } | 2260 | } |
| 2253 | else | 2261 | else |
| @@ -2259,21 +2267,29 @@ void updateRenderSizeVars(void) · 5 unmodified lines |
| 2259 | } | 2267 | } |
| 2260 | | 2268 | |
| 2261 | // for mouse cursor creation | 2269 | // for mouse cursor creation |
| 2262 | video.xScale = (int32_t)((video.renderW * (1.0 / SCREEN_W)) + 0.5); | 2270 | video.xScale = (int32_t)round(video.renderW / (double)SCREEN_W); |
| 2263 | video.yScale = (int32_t)((video.renderH * (1.0 / SCREEN_H)) + 0.5); | 2271 | video.yScale = (int32_t)round(video.renderH / (double)SCREEN_H); |
| | 2272 | |
| 2264 | createMouseCursors(); | 2273 | createMouseCursors(); |
| 2265 | } | 2274 | } |
| 2266 | | 2275 | |
| 2267 | void toggleFullScreen(void) | 2276 | void toggleFullscreen(void) |
| 2268 | { | 2277 | { |
| 2269 | SDL_DisplayMode dm; | | |
| 2270 | | | |
| 2271 | video.fullscreen ^= 1; | 2278 | video.fullscreen ^= 1; |
| 2272 | if (video.fullscreen) | 2279 | if (video.fullscreen) |
| 2273 | { | 2280 | { |
| | 2281 | SDL_SetWindowFullscreen(video.window, SDL_WINDOW_FULLSCREEN_DESKTOP); |
| | 2282 | |
| 2274 | if (config.fullScreenStretch) | 2283 | if (config.fullScreenStretch) |
| 2275 | { | 2284 | { |
| 2276 | SDL_GetDesktopDisplayMode(0, &dm); | 2285 | SDL_DisplayMode dm; |
| | 2286 | |
| | 2287 | int32_t di = SDL_GetWindowDisplayIndex(video.window); |
| | 2288 | if (di < 0) |
| | 2289 | di = 0; // return display index 0 (default) on error |
| | 2290 | |
| | 2291 | SDL_GetDesktopDisplayMode(di, &dm); |
| | 2292 | |
| 2277 | SDL_RenderSetLogicalSize(video.renderer, dm.w, dm.h); | 2293 | SDL_RenderSetLogicalSize(video.renderer, dm.w, dm.h); |
| 2278 | } | 2294 | } |
| 2279 | else | 2295 | else |
| @@ -2282,8 +2298,10 @@ void toggleFullScreen(void) · 2 unmodified lines |
| 2282 | } | 2298 | } |
| 2283 | | 2299 | |
| 2284 | SDL_SetWindowSize(video.window, SCREEN_W, SCREEN_H); | 2300 | SDL_SetWindowSize(video.window, SCREEN_W, SCREEN_H); |
| 2285 | SDL_SetWindowFullscreen(video.window, SDL_WINDOW_FULLSCREEN_DESKTOP); | 2301 | |
| | 2302 | #ifndef __unix__ // can be severely buggy on Linux... (at least when used like this) |
| 2286 | SDL_SetWindowGrab(video.window, SDL_TRUE); | 2303 | SDL_SetWindowGrab(video.window, SDL_TRUE); |
| | 2304 | #endif |
| 2287 | } | 2305 | } |
| 2288 | else | 2306 | else |
| 2289 | { | 2307 | { |
| @@ -2291,10 +2309,13 @@ void toggleFullScreen(void) · 1 unmodified line |
| 2291 | SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H); | 2309 | SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H); |
| 2292 | SDL_SetWindowSize(video.window, SCREEN_W * config.videoScaleFactor, SCREEN_H * config.videoScaleFactor); | 2310 | SDL_SetWindowSize(video.window, SCREEN_W * config.videoScaleFactor, SCREEN_H * config.videoScaleFactor); |
| 2293 | | 2311 | |
| 2294 | // this is not sensible on a multi-monitor setup | 2312 | #ifdef __unix__ // can be required on Linux... (or else the window keeps moving down every time you leave fullscreen) |
| 2295 | //SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); | 2313 | SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); |
| | 2314 | #endif |
| 2296 | | 2315 | |
| | 2316 | #ifndef __unix__ |
| 2297 | SDL_SetWindowGrab(video.window, SDL_FALSE); | 2317 | SDL_SetWindowGrab(video.window, SDL_FALSE); |
| | 2318 | #endif |
| 2298 | } | 2319 | } |
| 2299 | | 2320 | |
| 2300 | updateRenderSizeVars(); | 2321 | updateRenderSizeVars(); |
| @@ -2302,13 +2323,13 @@ void toggleFullScreen(void) · 1 unmodified line |
| 2302 | | 2323 | |
| 2303 | if (video.fullscreen) | 2324 | if (video.fullscreen) |
| 2304 | { | 2325 | { |
| 2305 | mouse.setPosX = video.displayW >> 1; | 2326 | mouse.setPosX = video.displayW / 2; |
| 2306 | mouse.setPosY = video.displayH >> 1; | 2327 | mouse.setPosY = video.displayH / 2; |
| 2307 | } | 2328 | } |
| 2308 | else | 2329 | else |
| 2309 | { | 2330 | { |
| 2310 | mouse.setPosX = video.renderW >> 1; | 2331 | mouse.setPosX = video.renderW / 2; |
| 2311 | mouse.setPosY = video.renderH >> 1; | 2332 | mouse.setPosY = video.renderH / 2; |
| 2312 | } | 2333 | } |
| 2313 | | 2334 | |
| 2314 | mouse.setPosFlag = true; | 2335 | mouse.setPosFlag = true; |
| @@ -2316,14 +2337,10 @@ void toggleFullScreen(void) · 1 unmodified line |
| 2316 | | 2337 | |
| 2317 | bool setupVideo(void) | 2338 | bool setupVideo(void) |
| 2318 | { | 2339 | { |
| 2319 | int32_t screenW, screenH; | 2340 | int32_t screenW = SCREEN_W * config.videoScaleFactor; |
| 2320 | uint32_t rendererFlags; | 2341 | int32_t screenH = SCREEN_H * config.videoScaleFactor; |
| 2321 | SDL_DisplayMode dm; | | |
| 2322 | | | |
| 2323 | screenW = SCREEN_W * config.videoScaleFactor; | | |
| 2324 | screenH = SCREEN_H * config.videoScaleFactor; | | |
| 2325 | | 2342 | |
| 2326 | rendererFlags = 0; | 2343 | uint32_t rendererFlags = 0; |
| 2327 | | 2344 | |
| 2328 | #ifdef _WIN32 | 2345 | #ifdef _WIN32 |
| 2329 | #if SDL_PATCHLEVEL >= 4 | 2346 | #if SDL_PATCHLEVEL >= 4 |
| @@ -2334,7 +2351,13 @@ bool setupVideo(void) · 4 unmodified lines |
| 2334 | video.vsync60HzPresent = false; | 2351 | video.vsync60HzPresent = false; |
| 2335 | if (!config.vsyncOff) | 2352 | if (!config.vsyncOff) |
| 2336 | { | 2353 | { |
| 2337 | SDL_GetDesktopDisplayMode(0, &dm); | 2354 | SDL_DisplayMode dm; |
| | 2355 | |
| | 2356 | int32_t di = SDL_GetWindowDisplayIndex(video.window); |
| | 2357 | if (di < 0) |
| | 2358 | di = 0; // return display index 0 (default) on error |
| | 2359 | |
| | 2360 | SDL_GetDesktopDisplayMode(di, &dm); |
| 2338 | if (dm.refresh_rate >= 59 && dm.refresh_rate <= 61) | 2361 | if (dm.refresh_rate >= 59 && dm.refresh_rate <= 61) |
| 2339 | { | 2362 | { |
| 2340 | video.vsync60HzPresent = true; | 2363 | video.vsync60HzPresent = true; |
| @@ -2407,6 +2430,12 @@ bool setupVideo(void) · 66 unmodified lines |
| 2407 | // we want an aligned pointer | 2430 | // we want an aligned pointer |
| 2408 | video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256); | 2431 | video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256); |
| 2409 | | 2432 | |
| | 2433 | // Workaround: SDL_GetGlobalMouseState() doesn't work with KMSDRM/Wayland |
| | 2434 | video.useDesktopMouseCoords = true; |
| | 2435 | const char *videoDriver = SDL_GetCurrentVideoDriver(); |
| | 2436 | if (videoDriver != NULL && (strcmp("KMSDRM", videoDriver) == 0 || strcmp("wayland", videoDriver) == 0)) |
| | 2437 | video.useDesktopMouseCoords = false; |
| | 2438 | |
| 2410 | updateRenderSizeVars(); | 2439 | updateRenderSizeVars(); |
| 2411 | updateMouseScaling(); | 2440 | updateMouseScaling(); |
| 2412 | | 2441 | |
| @@ -2415,12 +2444,6 @@ bool setupVideo(void) · 2 unmodified lines |
| 2415 | else | 2444 | else |
| 2416 | SDL_ShowCursor(SDL_FALSE); | 2445 | SDL_ShowCursor(SDL_FALSE); |
| 2417 | | 2446 | |
| 2418 | // Workaround: SDL_GetGlobalMouseState() doesn't work with KMSDRM/Wayland | | |
| 2419 | video.useDesktopMouseCoords = true; | | |
| 2420 | const char *videoDriver = SDL_GetCurrentVideoDriver(); | | |
| 2421 | if (videoDriver != NULL && (strcmp("KMSDRM", videoDriver) == 0 || strcmp("wayland", videoDriver) == 0)) | | |
| 2422 | video.useDesktopMouseCoords = false; | | |
| 2423 | | | |
| 2424 | SDL_SetRenderDrawColor(video.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); | 2447 | SDL_SetRenderDrawColor(video.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); |
| 2425 | return true; | 2448 | return true; |
| 2426 | } | 2449 | } |