imageviewer with sdl2

User projects written in or related to FreeBASIC.
Post Reply
thrive4
Posts: 70
Joined: Jun 25, 2021 15:32

imageviewer with sdl2

Post by thrive4 »

description:
More of a mini app then a project never the less
a 'meat and potato' imageviewer with sdl2 and sdl2_image.

The viewer has most of the basics in terms of navigation:
arrow | dpad left | mouse left : back
arrow | dpad right | mouse right: forward
num plus | R2 | scroll up : zoom in
num min | L2 | scroll down: zoom out
space | button A | scroll mid : reset zoom and scaletype
r / enter | button B | : rotate
z | button Y | : scale type
f11 : toggle fullscreen
esc : close application

Other basic features are:
- generates a playlist from a folder
- supports most common imagetypes .bmp, .gif, .jpg, .png, .pcx, .jpeg, .tff
> plus .mp3 coverart only
- supports haptic devices keyboard, mouse and gamepad
- if present cover art is extracted from mp3 and
> written to a thumb file (thumb.jpg or thumb.png)
- minimal configuration / localization via .ini files

usage:
imageviewer.exe "path to file or folder" optional "fullscreen" parameter
if a file or path is specified the folder will be scanned for an image file
if the folder has subfolder(s) these will be scanned for image files as well.

Intended use is mostly educational but might
be useful to some as bare bones imageviewer.

update v1.2 15/05/2023
- added screen dimming, interval can be set via conf.ini
- improved command line handling catches incorrect files and paths
- added SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1")
> respond to power plan settings blank display on windows
> note: set before sdl init (video) otherwise it will not work!
- tweaked utilfile.bas more in line with other apps
- tweaked shuffleplay scanning from root dir is not supported
- tieded up code in most files

Tested and compiled on windows 7 / 10 as 32bit app

release (32bit windows):
https://github.com/thrive4/app.fb.imageviewer/releases

source:
https://github.com/thrive4/app.fb.imageviewer

requirements:
sdl2 version
sdl2.dll (32bit) v2.24.2.0
https://www.libsdl.org
and
sdl2_image.dll (32bit) v2.6.2.0
https://github.com/libsdl-org/SDL_image/releases

special thanks:
TwinklebearDev SDL 2.0 Tutorial Lesson 3
Tutorial translating to FreeBASIC by Michael "h4tt3n" Schmidt Nissen
split or explode by delimiter return elements in array
based on viewtopic.php?t=31691 code by grindstone
text substitution
found at https://freebasic.net/forum/viewtopic.p ... ing#p86259
thrive4
Posts: 70
Joined: Jun 25, 2021 15:32

Re: imageviewer with sdl2

Post by thrive4 »

Thought this would be worthwhile to mention:

It could be a specific os issue but on windows (7 and 10)
SDL_HINT_VIDEO_ALLOW_SCREENSAVER needs to be
set before sdl_init.....

If the hint is set after sdl_init it will not give the desired result.
On windows this can be verified via command line:
g:\data\text>powercfg /requests
DISPLAY:
None.
SYSTEM:
None.
AWAYMODE:
None.

if set as:
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "0")
aka the default value the 'DISPLAY:' will be blocked also
resulting in the os powerplan 'turn off display' not to occur.
if SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1")
is set after sdl_init the 'DISPLAY:' will still be blocked.

More info see:
https://github.com/libsdl-org/SDL/issues/7712

Blanking the display, similar to 'turn display off' via windows
powerplan can be brute forced with:

Code: Select all

#include once "windows.bi"

SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)

sleep
end
Post Reply