{"id":20850414,"url":"https://github.com/noteed/loading","last_synced_at":"2025-03-12T12:25:41.854Z","repository":{"id":66654555,"uuid":"302995716","full_name":"noteed/loading","owner":"noteed","description":"A silly experiment with low-res graphics in Haskell","archived":false,"fork":false,"pushed_at":"2024-04-27T18:26:29.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-19T06:11:31.015Z","etag":null,"topics":["haskell","sdl2"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noteed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-10T21:50:44.000Z","updated_at":"2024-04-27T18:26:31.000Z","dependencies_parsed_at":"2024-04-27T19:30:51.092Z","dependency_job_id":"954d84d0-5c00-4f94-94fd-371fa6368e33","html_url":"https://github.com/noteed/loading","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noteed%2Floading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noteed%2Floading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noteed%2Floading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noteed%2Floading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noteed","download_url":"https://codeload.github.com/noteed/loading/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243216099,"owners_count":20255315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haskell","sdl2"],"created_at":"2024-11-18T03:09:19.824Z","updated_at":"2025-03-12T12:25:41.835Z","avatar_url":"https://github.com/noteed.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Loading\n\nJust trying out the SDL2 library with Haskell.\n\n- This uses a `shell.nix` file to bring in the necessary dependencies to build\n  the code.\n- This uses `direnv` (and thus a `.envrc`) with the `use_nix` feature to\n  automatically use the above `shell.nix` upon entering this directory.\n\nThe code doesn't do much: it displays a window, and a littel dot. It can be\nmoved with the arrow keys, a dot can be drawn by pressing `space`, and `q`\nexits the program.\n\nSimply setting an environment variable is enough to get controller events even\nwhen the window is not visible:\n\n```\n$ SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS=1 bin/loading run\n```\n\n\n## Building\n\nTo build the binary at `bin/loading`, simply run\n\n```\n$ nix-build -A binaries\n```\n\nTo validate the code during developement, use `ghcid` by running:\n\n```\n$ scripts/ghcid.sh\n```\n\n\n## Current status\n\n- The rendering is done with a low resolution, similar to old games.\n- Some basic shapes (point, line, triangle) are rendered.\n- Some commands can be done with a gamepad.\n- Left mouse button clicks change the cursor location, and sets the magnified\n  zone location.\n- Pressing `q` quits the application.\n- Pressing `e` enables/disables logging polled events.\n- Pressing `m` or right shoulder button show/hide a magnified zone of the\n  screen.\n- Pressing the arrow keys or d-pad move the cursor.\n- Pressing `space` or \"A\" button draw a point where the cursor is.\n- `loading headless` generates directly a screenshot, without actually opening\n  an interactive window.\n- A crude fixed frame rate is implemented. This limits CPU usage to 2% (window\n  on a hidden workspace) or 5% (window visible) on my T480, instead of 99%\n  (hidden) or 50% (visible).\n\nWhen quitting, a screenshot is captured as `screenshot.png`.\n\nA nice way to view the screenshot that mimics the behavior of the SDL window\nunder my xmonad configuration is using the following call:\n\n```\n$ feh --borderless --force-aliasing -g 1920x1200+320+120 --zoom fill screenshot.png\n```\n\nThis creates a floating, centered window with the 384x240 image scaled,\nconserving sharp \"big\" pixels.\n\n\n## Notes\n\nThe `defaultWindow` has its `windowResizable` to False. With XMonad, this makes\nthe window appear at the requested size and centered (above tiled windows).\nSetting `windowResizable` to True instead makes it behave like a regular\nwindow: when it appears, it is tiled among the other windows.\n\nTo obtain \"big\" pixels, i.e. an appearance of a low resolution image similar to\nold games, there is a `rendererLogicalSize` function. At first it seems to\nwork, but actually some drawing routines are not properly scaled (e.g.\n`drawLine`, or `triangle` from the sdl-gfx library). Instead I have used a low\nresolution texture as rendering target, which is then copied to the default\nrender target.\n\nI was unsure if my X Box controller would work. I plugged it in (wired), and\nchecked `dmesg`:\n\n```\n[16352.189193] input: Microsoft X-Box One S pad as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/input/input21\n[16352.189271] usbcore: registered new interface driver xpad\n```\n\nThis looked good and I confirmed it was working with `jstest /dev/input/js0`.\n\nNote: the build scripts hard-code paths into the Nix store to build against the\nsdl2 image library. This should be fixed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoteed%2Floading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoteed%2Floading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoteed%2Floading/lists"}