No description
Find a file
Cardeal Russo 1213fca41d Rebase
Initial commit

Initial Code

stuff

remove fenster.h

Add fenster submodule

fix header location

Skip examples on nimble

rename to avoid problems with "-'

add license to nimble

fix fenster.h location

info

New example

Update colorProgression.nim

Add files via upload

add access to .keys and a example

Update red_square_exit_on_esc_key.nim

Delete examples/colorProgression.nim

Update whiteNoise.nim

Update whiteNoise.nim

Update red_square_exit_on_esc_key.nim

Update red_square_exit_on_esc_key.nim

circle example

uint32 internally

Update README.md

Update README.md

Update README.md

use destroy

rename destroy to close

better examples

colors

smoll

mouse withe xamples

typo

Project renamed

bump

fix sleep, time function & 3d sample

Handles FPS internally

lib refactoring

add access to modkey and fix bad examples filename

a

remove .close

basic line shape

Create LICENSE

better line & example

shapes folder

use tuple on mouse

add config.nims for shapes

colored fractal tree

Audio implementation with example

Update fenstim_audio.nim

Update fenstim_audio.nim

Update README.md

Update README.md

Pixie support with example. Shapes removed.

Update pixie/text.nim

Accepts RGB

pixie example with system font

trailing comma removed

Update README.md

Update README.md

Update fenstim.nimble

Update README.md

Gets SomeInteger instead of uint8

Plasma example

more arts

Update README.md

Julia Set

get fonts

GUI app example

Update README.md

Update Julia Set

Update README.md

Add close

Update white_noise.nim

Performance tests

Add FPS and access to sleep and time

Avoid SomeInteger

Fast clear using C Memset

Use templates

Small Fix

Update README examples

Create blank.yml

Update blank.yml

Update blank.yml

Create config.nims

Move partial working audio to README

Faster examples with danger, lto, speed and arc

Multi-threaded Mandelbrot Set

Move examples

Update README.md

Update README.md

Add files via upload

Update README.md

Update README.md

Conways game of life Example

Typo

Update Fenster

Add MacOS to action

Update blank.yml

Update blank.yml

Update blank.yml

Audio workaround

closes #1

Move audio example from README to Examples folder

apt install libasound2-dev for ubuntu on workflow

Replace Fenster with FensterB Fork

Bump Version

Strip binaries on Workflow

Update FensterB with new mouse function

Fix mouse examples

Create audio_bytebeats.nim

Create walkable_carpet.nim

Update README.md

Delete examples/gifs directory

Update fenstim.nimble

Update FensterB
2024-10-17 13:34:08 -03:00
.github/workflows Rebase 2024-10-17 13:34:08 -03:00
examples Rebase 2024-10-17 13:34:08 -03:00
src Rebase 2024-10-17 13:34:08 -03:00
.gitmodules Rebase 2024-10-17 13:34:08 -03:00
fenstim.nimble Rebase 2024-10-17 13:34:08 -03:00
LICENSE Rebase 2024-10-17 13:34:08 -03:00
README.md Rebase 2024-10-17 13:34:08 -03:00

Fenstim

Fenstim is a Nim wrapper for Fenster, the most minimal cross-platform GUI with 2D canvas library. It provides a simple and efficient way to create graphical applications in Nim.

Implementation status

  • Minimal 24-bit RGB framebuffer.
  • Application lifecycle and system events are all handled automatically.
  • Simple polling API without a need for callbacks or multithreading (like Arduino/Processing).
  • Cross-platform keyboard events (keycodes).
  • Cross-platform mouse events (X/Y + mouse click).
  • Cross-platform timers to have a stable FPS rate. (builtin)
  • Cross-platform audio playback (WinMM, CoreAudio, ALSA).

Credits

Project done in collaboration with @ElegantBeef and @morturo at https://forum.nim-lang.org/t/12504

Examples

Basic usage

import fenstim, colors

var app = init(Fenster, "My Window", 800, 600, 60)

if app.loop:
  echo "Window target FPS: ", app.targetFps, ", Resolution: ", app.width, "x", app.height

while app.loop:
  # Set pixel color
  app.pixel(400, 300) = 16711680  # Decimal red
  app.pixel(420, 300) = 0x0000FF  # Hex blue
  pixel(app, 410, 300) = 0x00ff00 # Hex green

  # With colors module
  app.pixel(390, 300) = rgb(255, 0, 0).uint32        # Red
  app.pixel(380, 300) = parseColor("#00FF00").uint32 # Green
  app.pixel(370, 300) = colAliceBlue.uint32          # Alice Blue
  app.pixel(360, 300) = parseColor("silver").uint32  # Silver

  # Get pixel color
  let color = app.pixel(420, 300) # Decimal

  # Check key press if A key is pressed
  if app.keys[ord('A')] == 1:
    echo "A key is pressed"

  # Check if scape key is pressed
  if keys(app)[27] == 1:
    app.close
    break

  # Get mouse position and click state
  if app.mouse.mclick[0] == 1:
    echo "Clicked at: ", app.mouse.pos.x, "x", app.mouse.pos.y

  # Adjust FPS
  app.targetFps = 30

Opens a 60fps 800x600 window, draws a red square and exits when pressing the Escape key:

# examples/red_square.nim
import fenstim

var app = init(Fenster, "Red square with fenstim", 800, 600, 60)

while app.loop and app.keys[27] == 0:
  for x in 350 .. 450:
    for y in 250 .. 350:
      app.pixel(x, y) = 0xFF0000

API usage

Initialization

init*(_: type Fenster, title: string, width, height: int, fps: int = 60): Fenster

Creates a new Fenster window with the specified title, dimensions, and target FPS.

Main Loop

loop*(self: var Fenster): bool

Handles events and updates the display. Returns false when the window should close.

Pixel Manipulation

pixel*(self: Fenster, x, y: int): uint32

Get or set a uint32 pixel color at (x, y).

Window Properties

width*(self: Fenster): int
height*(self: Fenster): int
targetFps*(self: Fenster): int
close*(self: var Fenster)
clear*(self: Fenster)

Input Handling

keys*(self: Fenster): array[256, cint]
mouse*(self: Fenster): tuple[pos: tuple[x, y: int], mclick: array[5, cint], mhold: array[3, cint]]
modkey*(self: Fenster): int

keys = Array of key states. Index corresponds to ASCII value (0-255), but arrows are 17..20.
mouse = Get mouse position (x, y), clicked (left, right, middle, scroll up, scroll down) and holding buttons (left, right, middle)
modkey = 4 bits mask, ctrl=1, shift=2, alt=4, meta=8

Examples

Galery

lca1
lca2
lca3
lca5
lca4
interactive_julia_set.nim
ezgif-2-1a773886a7
mandelbrot.nim
threaded_mandelbrot.nim