13 Commits
26.4 ... 26.4.1

Author SHA1 Message Date
boreddevnl
8b77e8c48e doc: update grapher with tri-axis marching 2026-04-04 19:39:49 +02:00
boreddevnl
1ce08c70b0 FEAT: add tri-axis marching pipeline and atomic depth-color updates to Grapher 2026-04-04 18:05:04 +02:00
boreddevnl
fca67f68a9 NEW: math.h/libmath.c 2026-04-03 23:28:29 +02:00
boreddevnl
c330382436 DOCS: math.h 2026-04-03 23:27:45 +02:00
boreddevnl
f0c2963793 CHECKPOINT: polygon rendering 2026-04-03 23:16:03 +02:00
boreddevnl
3b24bc882c FEAT: Add grapher to dock 2026-04-03 13:32:38 +02:00
boreddevnl
2b44e59e9f TWEAK: Adjust window size 2026-04-03 13:32:23 +02:00
boreddevnl
7a2769e8e3 UI: New main wallpaper (bored.jpg) 2026-04-03 13:23:52 +02:00
boreddevnl
1a6e30b52e Docs: Clean up README.md 2026-04-03 11:53:57 +02:00
boreddevnl
69847adee6 DOCS: Refine and add documentation for libwidget.c 2026-04-03 11:52:06 +02:00
boreddevnl
f402e5e4f0 Merge branch 'main' of https://github.com/boreddevnl/BoredOS 2026-04-03 11:47:05 +02:00
boreddevnl
684ed774ee TWEAK: Balanced resolution and cpu usage with GRID_3D resolution 2026-04-03 11:46:33 +02:00
Chris
9ed8eac3e5 Update Buy Me A Coffee link in README 2026-04-03 00:08:05 +02:00
17 changed files with 1278 additions and 355 deletions

View File

@@ -19,9 +19,9 @@ BoredOS is a x86_64 operating system featuring a custom Desktop Environment (DE)
--- ---
## 🚀 Features ## Features
### ⚙️ System Architecture ### System Architecture
* **64-bit Long Mode:** Fully utilizing the x86_64 architecture. * **64-bit Long Mode:** Fully utilizing the x86_64 architecture.
* **Symmetric Multi-Processing (SMP):** Full support for multi-core CPUs via Limine SMP. * **Symmetric Multi-Processing (SMP):** Full support for multi-core CPUs via Limine SMP.
* **LAPIC & IPI Scheduling:** Advanced interrupt handling and inter-processor communication for task distribution. * **LAPIC & IPI Scheduling:** Advanced interrupt handling and inter-processor communication for task distribution.
@@ -31,12 +31,12 @@ BoredOS is a x86_64 operating system featuring a custom Desktop Environment (DE)
* **Filesystem:** Full **FAT32** support for persistent and in-memory storage. * **Filesystem:** Full **FAT32** support for persistent and in-memory storage.
* **Networking:** Includes the lwIP networking stack. * **Networking:** Includes the lwIP networking stack.
### 📺 Graphical User Interface ### Graphical User Interface
* **BoredWM:** A custom Window Manager with drag-and-drop, mouse-centered interaction. * **BoredWM:** A custom Window Manager with drag-and-drop, mouse-centered interaction.
* **Customization:** Adjustable UI to suit your aesthetic. * **Customization:** Adjustable UI to suit your aesthetic.
* **Media Support:** Built-in image decoding. * **Media Support:** Built-in image decoding.
### 🛠️ Included Applications ### Included Applications
* **Productivity:** GUI Text Editor calculator, Markdown Viewer, a simple browser and BoredWord. * **Productivity:** GUI Text Editor calculator, Markdown Viewer, a simple browser and BoredWord.
* **Creativity:** A Paint application. * **Creativity:** A Paint application.
* **Utilities:** Terminal, Task Manager, File Explorer, Clock and a (limited) C Compiler. * **Utilities:** Terminal, Task Manager, File Explorer, Clock and a (limited) C Compiler.
@@ -55,11 +55,11 @@ Explore the internal workings of BoredOS via our comprehensive guides in the [`d
--- ---
## Support the Journey ## Support the Journey
If you find this project interesting or helpful, consider fueling the development with a coffee! If you find this project interesting or helpful, consider fueling the development with a coffee!
<a href="https://buymeacoffee.com/boreddevnl" target="_blank"> <a href="https://buymeacoffee.com/boreddevhq" target="_blank">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="50" style="border-radius: 8px;" /> <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="50" style="border-radius: 8px;" />
</a> </a>
@@ -68,16 +68,16 @@ If you find this project interesting or helpful, consider fueling the developmen
## ⚠️ Project Disclaimer & Heritage ## ⚠️ Project Disclaimer & Heritage
**BoredOS** is the successor to **BrewKernel**, a text-only project initiated in 2023. **BoredOS** is the successor to **BrewKernel**, a project initiated in 2023.
While BrewKernel served as the foundational learning ground for this OS, it has been officially **deprecated and archived**. It no longer receives updates, bug fixes, or pull request reviews. BoredOS represents a complete architectural reboot, applying years of lessons learned to create a cleaner, more modular, and more capable 64-bit system. While BrewKernel served as the foundational learning ground for this OS, it has been officially **deprecated and archived**. It no longer receives updates, bug fixes, or pull request reviews. BoredOS represents a complete architectural reboot, applying years of lessons learned to create a cleaner, more modular, and more capable system.
> [!IMPORTANT] > [!IMPORTANT]
> Please ensure all issues, discussions, and contributions are directed to this repository. Legacy BrewKernel code is preserved for historical purposes only and is not compatible with BoredOS. > Please ensure all issues, discussions, and contributions are directed to this repository. Legacy BrewKernel code is preserved for historical purposes only and is not compatible with BoredOS.
--- ---
## ⚖️ License ## License
**Copyright (C) 2024-2026 boreddevnl** **Copyright (C) 2024-2026 boreddevnl**

View File

@@ -27,7 +27,9 @@ Instructions for compiling the OS from source.
The SDK and toolchain guides for creating your own `.elf` userland binaries. The SDK and toolchain guides for creating your own `.elf` userland binaries.
- [`SDK Reference`](appdev/sdk_reference.md): Explanation of the custom `libc` wrappers (`stdlib.h`, `string.h`) and system calls. - [`SDK Reference`](appdev/sdk_reference.md): Explanation of the custom `libc` wrappers (`stdlib.h`, `string.h`) and system calls.
- [`UI API`](appdev/ui_api.md): Drawing on the screen, creating windows, and polling the event loop using `libui.h`. - [`UI API`](appdev/ui_api.md): Drawing on the screen, creating windows, and polling the event loop using `libui.h`.
- [`Widget API`](appdev/widget_api.md): High-level UI components like buttons, textboxes, and scrollbars using `libwidget.h`.
- [`Custom Apps`](appdev/custom_apps.md): A step-by-step tutorial on writing a new graphical C application, editing the Makefile, and bundling it into the ISO. - [`Custom Apps`](appdev/custom_apps.md): A step-by-step tutorial on writing a new graphical C application, editing the Makefile, and bundling it into the ISO.
- [`Example Apps`](appdev/examples/README.md): A collection of sample C applications ranging from basic terminal output to advanced TCP networking. - [`Example Apps`](appdev/examples/README.md): A collection of sample C applications ranging from basic terminal output to advanced TCP networking.
- [`Grapher`](appdev/grapher.md): Full reference for the built-in mathematical graphing application — equation syntax, keyboard controls, architecture, and configuration.
--- ---

View File

@@ -10,7 +10,7 @@ This guide explains how to write a new "Hello World" application locally, compil
> [!TIP] > [!TIP]
> **Looking for working code?** Check out the [Examples Directory](examples/README.md) for full source code demonstrating basic CLI, Windows, Animations, and TCP Networking. > **Looking for working code?** Check out the [Examples Directory](examples/README.md) for full source code demonstrating basic CLI, Windows, Animations, and TCP Networking.
## 📝 Step 1: Write the C Source ## Step 1: Write the C Source
Applications reside entirely in the `src/userland/` directory. Create a new file, for example, `src/userland/gui/hello.c`. Applications reside entirely in the `src/userland/` directory. Create a new file, for example, `src/userland/gui/hello.c`.
@@ -52,7 +52,7 @@ int main(void) {
} }
``` ```
## ⚙️ Step 2: Edit the Makefile ## Step 2: Edit the Makefile
Now you need to tell the build system to compile `hello.c`. Fortunately, the `src/userland/Makefile` is designed to detect new C files largely automatically! Now you need to tell the build system to compile `hello.c`. Fortunately, the `src/userland/Makefile` is designed to detect new C files largely automatically!
@@ -64,7 +64,7 @@ Now you need to tell the build system to compile `hello.c`. Fortunately, the `sr
Since you placed the file in `gui/hello.c`, the wildcard logic will pick it up automatically. Since you placed the file in `gui/hello.c`, the wildcard logic will pick it up automatically.
3. The Makefile will generate `bin/hello.elf` during the build phase. 3. The Makefile will generate `bin/hello.elf` during the build phase.
## 📦 Step 3: Bundle it into the OS ## Step 3: Bundle it into the OS
The main overarching `Makefile` (in the project root) takes binaries from `src/userland/bin/*.elf` and places them into the `iso_root/bin/` directory, while also adding them to `limine.conf` as loadable boot modules. The main overarching `Makefile` (in the project root) takes binaries from `src/userland/bin/*.elf` and places them into the `iso_root/bin/` directory, while also adding them to `limine.conf` as loadable boot modules.
@@ -77,7 +77,7 @@ The main overarching `Makefile` (in the project root) takes binaries from `src/u
make clean && make run make clean && make run
``` ```
## 🚀 Step 4: Run it inside BoredOS ## Step 4: Run it inside BoredOS
1. When BoredOS boots, launch the **Terminal** application. 1. When BoredOS boots, launch the **Terminal** application.
2. The OS automatically maps built applications to standard shell commands. Simply type your application's filename (without the `.elf` extension). 2. The OS automatically maps built applications to standard shell commands. Simply type your application's filename (without the `.elf` extension).

345
docs/appdev/grapher.md Normal file
View File

@@ -0,0 +1,345 @@
<div align="center">
<h1>Grapher</h1>
<p><em>An interactive mathematical expression plotter for BoredOS, supporting both 2D and 3D visualizations.</em></p>
</div>
---
Grapher is a built-in GUI application that lets you type any mathematical equation and see it plotted in real time. It supports 2D explicit and implicit curves as well as full 3D surface visualization — including both explicit surfaces (`z = f(x, y)`) and implicit surfaces (`f(x, y, z) = c`).
> [!NOTE]
> Grapher is located at `src/userland/gui/grapher.c`. It runs as a standard BoredOS GUI process and can be launched from the terminal or from the dock.
---
## Features at a Glance
| Feature | Details |
|---|---|
| **2D Explicit** | Plot `y = f(x)` curves |
| **2D Implicit** | Plot any `f(x, y) = g(x, y)` contour via marching squares |
| **3D Explicit** | Plot `z = f(x, y)` surfaces |
| **3D Implicit** | Plot any `f(x, y, z) = c` surface |
| **Rendering modes** | Wireframe and filled polygon modes |
| **Height coloring** | Surfaces are colored by a blue→green→yellow→red gradient based on Z height |
| **Phong-style shading** | Filled mode computes per-face normals and applies diffuse + ambient lighting |
| **Parallel rendering** | Evaluation and projection are distributed across 4 worker threads via `sys_parallel_run` |
| **Preset equations** | 7 built-in presets accessible from the toolbar |
| **Auto-fit** | 2D view auto-fits the Y axis to the plotted curve on first plot |
| **Atomic Color-Depth Buffer** | All 3D drawing uses a 64-bit atomic buffer to prevent depth/color race conditions |
---
## Launching Grapher
From the BoredOS terminal:
```sh
grapher
```
Or click the **Grapher icon** in the system dock.
---
### Toolbar Controls
| Control | Function |
|---|---|
| **Equation box** | Type your mathematical expression, then press **Enter** or **Plot** |
| **Plot button** | Parse and render the current equation |
| **Wire / Filled button** | Toggle wireframe vs. shaded polygon mode (3D only) |
| **Presets button** | Open a dropdown of example equations |
### Status Bar Controls (3D mode)
| Control | Function |
|---|---|
| **`+` button** | Increase the 3D world range (zoom out in world space) |
| **`-` button** | Decrease the 3D world range (zoom in in world space) |
---
## Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| **Enter** (in equation box) | Plot the equation |
| **Ctrl + R** | Reset the view to defaults |
| **F** | Toggle filled / wireframe rendering (3D mode) |
| **Scroll wheel** | Zoom in/out (2D mode adjusts viewport; 3D mode adjusts camera zoom) |
| **Right-click drag** | Rotate the 3D surface |
---
## Writing Equations
Grapher parses equations entered as plain text. It supports a subset of mathematical notation with automatic implicit multiplication.
### Supported Functions
| Syntax | Meaning |
|---|---|
| `sin(x)` | Sine |
| `cos(x)` | Cosine |
| `tan(x)` | Tangent |
| `sqrt(x)` | Square root |
| `abs(x)` | Absolute value |
| `log(x)` | Natural logarithm (base *e*) |
### Supported Operators
| Operator | Meaning |
|---|---|
| `+` `-` `*` `/` | Arithmetic |
| `^` | Exponentiation (right-associative) |
| `(` `)` | Grouping |
### Special Values
| Token | Value |
|---|---|
| `pi` or `PI` | π ≈ 3.14159… |
### Implicit Multiplication
Adjacent tokens that would normally require a `*` are multiplied automatically:
```
2x → 2 * x
3sin(x) → 3 * sin(x)
(x+1)(x) → (x+1) * x
```
### How Equations Are Classified
Grapher looks at which variables appear in your equation to automatically choose the rendering mode:
| Equation form | Auto-detected as |
|---|---|
| `y = f(x)` or just `f(x)` | 2D explicit |
| `f(x, y) = g(x, y)` | 2D implicit |
| `z = f(x, y)` | 3D explicit |
| `f(x, y, z) = c` | 3D implicit |
If you omit the `=` sign, Grapher treats the input as `y = <expression>` when no `y` or `z` is present, or as `<expression> = 0` otherwise.
---
## Example Equations
### 2D Examples
```
y = sin(x)
y = x^2
y = cos(x)*x
y = abs(x) - 2
x^2 + y^2 = 25 ← circle (implicit)
y = log(x)
```
### 3D Explicit Examples
```
z = sin(x)*cos(y)
z = x^2 - y^2 ← saddle surface
z = sqrt(25 - x^2 - y^2)
```
### 3D Implicit Examples
```
x^2 + y^2 + z^2 = 25 ← sphere
x^2 + y^2 = 16 ← cylinder
x^2 + y^2 - z^2 = 1 ← hyperboloid
```
---
## Navigation Controls
### 2D Mode
| Input | Action |
|---|---|
| **Scroll up** | Zoom in |
| **Scroll down** | Zoom out |
| **Ctrl+R** | Reset to default view (`x: [-10, 10]`) |
### 3D Mode
| Input | Action |
|---|---|
| **Right-click drag** | Rotate the surface (orbit camera) |
| **Scroll up** | Zoom camera in |
| **Scroll down** | Zoom camera out |
| **`+` / `-` buttons** | Increase / decrease world range |
| **Ctrl+R** | Reset rotation and zoom |
> [!TIP]
> In 3D mode, the surface auto-rotates slowly by default. This can be disabled by setting `#define ROTATE 0` in the source file.
---
## Architecture Overview
Grapher is implemented as a single self-contained C file. Below is a high-level breakdown of its major components:
### Math Library
Grapher uses the BoredOS freestanding **`libc/math.h`** library, which provides all the math functions it needs without depending on a host standard library:
| Function | Description |
|---|---|
| `sin`, `cos`, `tan` | Trigonometry via Taylor series (8 terms, range-reduced to `[-π, π]`) |
| `sqrt` | Newton-Raphson iteration (25 steps) |
| `log` | Natural logarithm via Padé-style series |
| `log2`, `log10` | Derived from `log` |
| `exp` | Range-reduced Taylor series for `e^x` |
| `pow` | Integer exponents use fast binary exponentiation; fractional exponents use `exp(e * log(b))` |
| `fabs`, `fmod` | Absolute value and floating-point remainder |
| `floor`, `ceil` | Rounding |
| `sinh`, `cosh`, `tanh` | Hyperbolic functions |
| `hypot`, `fmin`, `fmax`, `fclamp` | Utility helpers |
The constants `M_PI`, `M_E`, `M_LN2`, `M_SQRT2` are also defined in the header.
This library is automatically linked into every userland ELF — any app can `#include "math.h"` to use it.
### Expression Parser
Equations are parsed in three stages:
1. **Tokenizer** (`tokenize`) — converts the input string into a flat token array. Handles implicit multiplication by inserting `*` tokens where needed.
2. **Recursive Descent Parser** (`parse_expr`, `parse_term`, `parse_power`, `parse_unary`, `parse_atom`) — produces an Abstract Syntax Tree (AST) with up to `MAX_NODES = 128` nodes.
3. **Bytecode Compiler** (`compile_ast`) — walks the AST in post-order and emits a flat instruction sequence for a simple stack machine. This avoids recursive evaluation during rendering hot paths.
The resulting bytecode is then executed by `run_bc` for every sample point.
### Rendering Pipeline
#### 2D Rendering
- **Explicit** — evaluates `y = f(x)` at every pixel column and connects adjacent samples with Bresenham lines.
- **Implicit** — applies **marching squares** on a 200×130 grid to find sign changes in `f(x,y) - g(x,y)` and plots intersection pixels.
#### 3D Rendering
The 3D pipeline uses a multi-pass system parallelized across worker threads:
| Pass | Function | Description |
|---|---|---|
| 1 | **Evaluation** | Samples the surface at grid points. For implicit surfaces, this uses **tri-axis marching**. |
| 2 | **Projection** | Projects 3D world coordinates to 2D screen coordinates with perspective. |
| 3 | **Drawing** | Rasterizes wireframe lines or filled triangles with Z-buffering. |
##### Tri-Axis Marching (Implicit Surfaces)
Unlike explicit surfaces that only need one evaluation per grid point, implicit surfaces require finding roots of $f(x, y, z) = 0$. To ensure complete surface connectivity and eliminate "cracks," Grapher marches along all three primary axes:
1. **X-Axis Pass**: For every $(y, z)$ pair, march along $x$.
2. **Y-Axis Pass**: For every $(x, z)$ pair, march along $y$.
3. **Z-Axis Pass**: For every $(x, y)$ pair, march along $z$.
Each pass uses a multi-stage root finder (170 linear steps followed by 15 bisection iterations). By sampling along all three axes, the engine "catches" surfaces that are nearly parallel to any specific marching direction, ensuring that vertical walls and steep gradients are rendered solidly from any viewing angle.
##### Atomic Color-Depth Buffer
To prevent "z-fighting" and race conditions between parallel threads, Grapher uses a 64-bit atomic buffer (`graph_czb`). Each 64-bit word stores:
- **Upper 32 bits**: Z-depth (integer).
- **Lower 32 bits**: Pixel color (0xAARRGGBB).
A single `__atomic_compare_exchange_n` operation ensures that a pixel's color and depth are updated together only if the new depth is closer to the camera than the existing one.
Surface normals are estimated using central finite differences of the implicit function.
#### Filled Mod
When filled mode is active, each quad cell is split into two triangles. The average surface normal across the four corner vertices is computed and fed into `apply_shading`, which calculates:
```
intensity = ambient(0.3) + diffuse(0.7) * dot(normal, light_direction)
```
The light direction is fixed at `(0.577, 0.707, 0.408)` (normalized diagonal).
#### Z-Buffer
The depth buffer (`graph_zb`) stores integer depth values. `gfb_pixel_z` uses a **compare-and-swap (CAS) loop** via `__atomic_compare_exchange_n` so multiple parallel draw threads cannot produce race conditions.
### Coordinate Systems
#### 2D
World coordinates map linearly to screen pixels:
```c
screen_x = (wx - view_x_min) / (view_x_max - view_x_min) * graph_w
screen_y = (view_y_max - wy) / (view_y_max - view_y_min) * graph_h
```
#### 3D
Points are first rotated by two Euler angles (`rot_y`, `rot_x`) then projected with a simple perspective divide:
```
persp = d / (pz + d) // d = range_3d * 5
sx = px * scale * persp + screen_cx
sy = -py * scale * persp + screen_cy
```
---
## Configuration Constants
These can be changed at the top of `grapher.c` to tune behaviour:
| Constant | Default | Effect |
|---|---|---|
| `ROTATE` | `1` | Set to `0` to disable auto-rotation in 3D mode |
| `GRID_3D` | `41` | Grid resolution for 3D sampling. Higher = more detail, much slower |
> [!WARNING]
> Setting `GRID_3D` too high (e.g. 9000) will exhaust available memory. The `surf` grid and `surf_x`/`surf_y_3d` arrays are statically allocated at compile time: memory usage grows as **O(GRID_3D²)**. Values above ~512 are not recommended.
> [!TIP]
> `GRID_3D = 256` gives a good balance of detail and performance on typical BoredOS hardware emulation.
---
## Color Palette
3D surfaces are colored by height using a 4-stop rainbow ramp:
```
Low → Blue → Cyan → Green → Yellow → Red → High
```
---
## Preset Equations
The built-in presets are shown in the dropdown when you click **Presets**:
| Label | Type |
|---|---|
| `y = sin(x)` | 2D explicit |
| `y = x^2` | 2D explicit |
| `y = cos(x)*x` | 2D explicit |
| `z = sin(x)*cos(y)` | 3D explicit |
| `z = x^2 - y^2` | 3D explicit |
| `x^2+y^2+z^2=25` | 3D implicit (sphere) |
| `x^2+y^2=16` | 3D implicit (cylinder) |
---
## Known Limitations
- **No parameter slider** — equations are static; there is no way to animate a parameter.
- **No multiple equations** — only one equation can be graphed at a time.
- **Implicit surface precision** — extremely thin or high-frequency implicit surfaces may still have small artifacts if the grid resolution (`GRID_3D`) is too low.
- **3D implicit performance** — tri-axis marching evaluates the function significantly more times than explicit rendering; high resolutions will impact frame rate.
- **Integer axis labels only for large values** — very large axis values are capped at `>2G` or `<-2G` due to `itoa` limitations.

View File

@@ -7,9 +7,13 @@
BoredOS provides a custom `libc` implementation necessary for writing userland applications (`.elf` binaries). By avoiding a full-blown standard library like `glibc`, the OS ensures a minimal executable footprint tailored strictly to the existing kernel features. BoredOS provides a custom `libc` implementation necessary for writing userland applications (`.elf` binaries). By avoiding a full-blown standard library like `glibc`, the OS ensures a minimal executable footprint tailored strictly to the existing kernel features.
All headers are located in `src/userland/libc/`. All headers are located in `src/userland/libc/` (standard functions) and `src/wm/` (UI and widgets).
- `stdlib.h`: Memory, strings, and basic I/O.
- `math.h`: Freestanding floating-point math library.
- `libui.h`: Core window and drawing API.
- `libwidget.h`: High-level UI components.
## 📚 Standard Library (`stdlib.h` & `string.h`) ## Standard Library (`stdlib.h` & `string.h`)
The standard library wrappers provide memory management, string manipulation, and basic IO formatting without needing direct syscalls. The standard library wrappers provide memory management, string manipulation, and basic IO formatting without needing direct syscalls.
@@ -45,7 +49,60 @@ The standard library wrappers provide memory management, string manipulation, an
--- ---
## ⚙️ System Calls (`syscall.h`) ## Math Library (`math.h`)
BoredOS ships a freestanding floating-point math library in `libc/math.h`. It uses pure arithmetic — Taylor series, Newton-Raphson, and range-reduction — with no dependency on a host `libm` or hardware math intrinsics. It is automatically linked into every userland ELF.
```c
#include "math.h"
```
### Constants
| Constant | Value | Description |
|---|---|---|
| `M_PI` | 3.14159… | π |
| `M_E` | 2.71828… | Euler's number |
| `M_LN2` | 0.69315… | Natural log of 2 |
| `M_SQRT2` | 1.41421… | √2 |
| `HUGE_VAL` | ~+∞ | Overflow sentinel |
### Functions
#### Absolute value & remainder
* `double fabs(double x);` — Absolute value.
* `double fmod(double x, double y);` — Floating-point remainder. Returns `0` when `y == 0`.
#### Rounding
* `double floor(double x);` — Largest integer ≤ x.
* `double ceil(double x);` — Smallest integer ≥ x.
#### Trigonometry *(arguments in radians)*
* `double sin(double x);` — Sine. Range-reduced to `[-π, π]` then computed via 8-term Taylor series.
* `double cos(double x);` — Cosine. Computed via `sin(x + π/2)`.
* `double tan(double x);` — Tangent. Returns sentinel `1e15` near poles.
#### Exponential & logarithm
* `double sqrt(double x);` — Square root via Newton-Raphson (25 iterations). Returns `0` for `x ≤ 0`.
* `double log(double x);` — Natural logarithm (ln). Returns `-1e30` for `x ≤ 0`.
* `double log2(double x);` — Base-2 logarithm.
* `double log10(double x);` — Base-10 logarithm.
* `double exp(double x);` — e^x. Saturates to `1e300` for `x > 700`, `0` for `x < -700`.
* `double pow(double base, double exponent);` — General power. Integer exponents use fast binary exponentiation; fractional exponents use `exp(e * log(b))`.
#### Hyperbolic
* `double sinh(double x);` — Hyperbolic sine.
* `double cosh(double x);` — Hyperbolic cosine.
* `double tanh(double x);` — Hyperbolic tangent.
#### Utility
* `double hypot(double x, double y);``sqrt(x² + y²)` without intermediate overflow.
* `double fmin(double a, double b);` — Minimum of two values.
* `double fmax(double a, double b);` — Maximum of two values.
* `double fclamp(double x, double lo, double hi);` — Clamps `x` into `[lo, hi]`.
> [!NOTE]
> The implementation file is named `libc/libmath.c` (not `libc/math.c`) to avoid a name collision with the `math` CLI calculator app in userland. The public header is still included as `#include "math.h"`.
For advanced operations, `syscall.h` provides direct wrappers into the kernel. For advanced operations, `syscall.h` provides direct wrappers into the kernel.
@@ -108,7 +165,7 @@ BoredOS includes lwIP for hardware TCP/UDP networking.
--- ---
## 📑 Core Data Structures ## Core Data Structures
### `os_info_t` ### `os_info_t`
Contains detailed build and version information about the OS. Contains detailed build and version information about the OS.

View File

@@ -7,7 +7,7 @@
The UI library (`libui.h`) is the sole mechanism for Graphical Userland Applications to draw to the screen and receive input events in BoredOS. It wraps `SYS_GUI` kernel calls. The UI library (`libui.h`) is the sole mechanism for Graphical Userland Applications to draw to the screen and receive input events in BoredOS. It wraps `SYS_GUI` kernel calls.
## 🪟 Window Management ## Window Management
A "Window" is a reserved drawing canvas managed by the compositor. A "Window" is a reserved drawing canvas managed by the compositor.
@@ -21,7 +21,7 @@ A "Window" is a reserved drawing canvas managed by the compositor.
* `void ui_get_screen_size(uint64_t *out_w, uint64_t *out_h);` * `void ui_get_screen_size(uint64_t *out_w, uint64_t *out_h);`
Query the global screen resolution of the display. Query the global screen resolution of the display.
## 🎨 Drawing Primitives ## Drawing Primitives
All drawing functions write to an off-screen buffer associated with the window. **You must call `ui_mark_dirty()` to instruct the compositor to push your changes to the physical screen.** All drawing functions write to an off-screen buffer associated with the window. **You must call `ui_mark_dirty()` to instruct the compositor to push your changes to the physical screen.**
@@ -38,7 +38,7 @@ All drawing functions write to an off-screen buffer associated with the window.
> Colors are defined as 32-bit unsigned integers in **ARGB** format: `0xAARRGGBB`. > Colors are defined as 32-bit unsigned integers in **ARGB** format: `0xAARRGGBB`.
> E.g., `0xFF000000` is opaque black, `0xFFFF0000` is opaque red. > E.g., `0xFF000000` is opaque black, `0xFFFF0000` is opaque red.
## 🔤 Text Rendering ## Text Rendering
BoredOS provides multiple text rendering methodologies, including a default system font and scaled/bitmap alternatives. BoredOS provides multiple text rendering methodologies, including a default system font and scaled/bitmap alternatives.
@@ -60,7 +60,7 @@ Used for calculating layout bounds before drawing:
* `uint32_t ui_get_string_width_scaled(const char *str, float scale);` * `uint32_t ui_get_string_width_scaled(const char *str, float scale);`
* `uint32_t ui_get_font_height_scaled(float scale);` * `uint32_t ui_get_font_height_scaled(float scale);`
## 🔄 Event Handling ## Event Handling
Applications must continuously poll for events inside an infinite `$while(1)` loop. Applications must continuously poll for events inside an infinite `$while(1)` loop.
@@ -103,3 +103,9 @@ typedef struct {
*(Note: Coordinate arguments (`arg1`, `arg2`) for mouse events are typically relative to the top-left corner of the window's client area).* *(Note: Coordinate arguments (`arg1`, `arg2`) for mouse events are typically relative to the top-left corner of the window's client area).*
--- ---
> [!TIP]
> **Looking for Buttons, TextBoxes, or Scrollbars?**
> While `libui.h` provides the foundation for drawing, most applications should use the higher-level [**Widget API**](widget_api.md) (`libwidget.h`) for standard interactive components.
---

108
docs/appdev/widget_api.md Normal file
View File

@@ -0,0 +1,108 @@
<div align="center">
<h1>Widget API (<code>libwidget.h</code>)</h1>
<p><em>High-level UI components for BoredOS applications.</em></p>
</div>
---
The Widget library (`libwidget.h`) provides a set of reusable UI components built on top of `libui.h`. It uses an abstract `widget_context_t` to decouple component logic from specific drawing implementations, making it easier to build complex graphical interfaces.
## Widget Context
To use any widget, you must first define a `widget_context_t`. This structure contains function pointers for basic drawing operations (rects, strings) and theme preferences.
```c
typedef struct {
void *user_data;
void (*draw_rect)(void *user_data, int x, int y, int w, int h, uint32_t color);
void (*draw_rounded_rect_filled)(void *user_data, int x, int y, int w, int h, int r, uint32_t color);
void (*draw_string)(void *user_data, int x, int y, const char *str, uint32_t color);
int (*measure_string_width)(void *user_data, const char *str);
void (*mark_dirty)(void *user_data, int x, int y, int w, int h);
bool use_light_theme;
} widget_context_t;
```
> [!TIP]
> Usually, `user_data` is set to your `ui_window_t` handle, and the functions are simple wrappers around `ui_draw_rect`, `ui_draw_string`, etc.
---
## Button (`widget_button_t`)
Standard interactive button with hover and click states.
* `void widget_button_init(widget_button_t *btn, int x, int y, int w, int h, const char *text);`
* `void widget_button_draw(widget_context_t *ctx, widget_button_t *btn);`
* `bool widget_button_handle_mouse(widget_button_t *btn, int mx, int my, bool mouse_down, bool mouse_clicked, void *user_data);`
### Usage Example:
```c
widget_button_t my_btn;
widget_button_init(&my_btn, 10, 10, 80, 25, "Click Me");
my_btn.on_click = my_callback_func;
// In your event loop:
widget_button_handle_mouse(&my_btn, ev.arg1, ev.arg2, is_down, is_clicked, my_data);
```
---
## Scrollbar (`widget_scrollbar_t`)
Vertical scrollbar supporting dragging and track-paging.
* `void widget_scrollbar_init(widget_scrollbar_t *sb, int x, int y, int w, int h);`
* `void widget_scrollbar_update(widget_scrollbar_t *sb, int content_height, int scroll_y);`
* `void widget_scrollbar_draw(widget_context_t *ctx, widget_scrollbar_t *sb);`
* `bool widget_scrollbar_handle_mouse(widget_scrollbar_t *sb, int mx, int my, bool mouse_down, void *user_data);`
> [!NOTE]
> The scrollbar automatically calculates the "thumb" size based on the ratio of `h` to `content_height`.
---
## TextBox (`widget_textbox_t`)
Editable text field with focus support and keyboard handling.
* `void widget_textbox_init(widget_textbox_t *tb, int x, int y, int w, int h, char *buffer, int max_len);`
* `void widget_textbox_draw(widget_context_t *ctx, widget_textbox_t *tb);`
* `bool widget_textbox_handle_mouse(widget_textbox_t *tb, int mx, int my, bool mouse_clicked, void *user_data);`
* `bool widget_textbox_handle_key(widget_textbox_t *tb, char c, void *user_data);`
---
## Dropdown (`widget_dropdown_t`)
Selection menu for picking one item from a list.
* `void widget_dropdown_init(widget_dropdown_t *dd, int x, int y, int w, int h, const char **items, int count);`
* `void widget_dropdown_draw(widget_context_t *ctx, widget_dropdown_t *dd);`
* `bool widget_dropdown_handle_mouse(widget_dropdown_t *dd, int mx, int my, bool mouse_clicked, void *user_data);`
---
## Checkbox / Radio (`widget_checkbox_t`)
Toggleable options with support for circular "Radio" style or square "Checkbox" style.
* `void widget_checkbox_init(widget_checkbox_t *cb, int x, int y, int w, int h, const char *text, bool is_radio);`
* `void widget_checkbox_draw(widget_context_t *ctx, widget_checkbox_t *cb);`
* `bool widget_checkbox_handle_mouse(widget_checkbox_t *cb, int mx, int my, bool mouse_clicked, void *user_data);`
---
## Event Integration
Widgets are designed to be polled within your `libui` event loop. Most handle-mouse functions return `true` if the event was "consumed" by the widget, allowing you to stop further processing for that event.
```c
if (ui_get_event(win, &ev)) {
bool handled = false;
handled |= widget_button_handle_mouse(&btn, ev.arg1, ev.arg2, is_down, is_clicked, NULL);
if (!handled) {
// Handle global window events...
}
}
```

View File

@@ -9,7 +9,7 @@ BoredOS is a 64-bit hobbyist operating system designed for the x86_64 architectu
This document serves as an overview of the core architecture and the layout of the kernel source code. This document serves as an overview of the core architecture and the layout of the kernel source code.
## 📂 Source Code Layout (`src/`) ## Source Code Layout (`src/`)
The OS heavily relies on module separation. The `src/` directory is logically split into several domains: The OS heavily relies on module separation. The `src/` directory is logically split into several domains:
@@ -23,7 +23,7 @@ The OS heavily relies on module separation. The `src/` directory is logically sp
- **`wm/`**: The graphical subsystem. It handles drawing primitives, window structures, font rendering, and double-buffering. - **`wm/`**: The graphical subsystem. It handles drawing primitives, window structures, font rendering, and double-buffering.
- **`userland/`**: Out-of-kernel components. This includes the custom SDK/compiler environment (`libc/`) and user applications (`cli/`, `gui/`, `games/`). - **`userland/`**: Out-of-kernel components. This includes the custom SDK/compiler environment (`libc/`) and user applications (`cli/`, `gui/`, `games/`).
## 🚀 Boot Process ## Boot Process
BoredOS uses **Limine** as its primary bootloader. BoredOS uses **Limine** as its primary bootloader.
@@ -42,7 +42,7 @@ BoredOS utilizes Symmetric Multi-Processing (SMP) to distribute workloads across
- **Scheduler**: A round-robin scheduler runs on each core. Processes are pinned to specific CPUs (CPU Affinity) to maintain cache locality. The BSP timer interrupt (`60Hz`) broadcasts a scheduling IPI to all core to ensure balanced execution. - **Scheduler**: A round-robin scheduler runs on each core. Processes are pinned to specific CPUs (CPU Affinity) to maintain cache locality. The BSP timer interrupt (`60Hz`) broadcasts a scheduling IPI to all core to ensure balanced execution.
- **Spinlocks**: Since multiple cores can access kernel structures (VFS, Process List) simultaneously, the kernel uses **interrupt-safe spinlocks** to prevent race conditions. - **Spinlocks**: Since multiple cores can access kernel structures (VFS, Process List) simultaneously, the kernel uses **interrupt-safe spinlocks** to prevent race conditions.
## 🛡️ Userland Transition ## Userland Transition
The OS supports privilege separation (Ring 0 vs. Ring 3). When an application is launched, the kernel: The OS supports privilege separation (Ring 0 vs. Ring 3). When an application is launched, the kernel:

View File

@@ -7,7 +7,7 @@
BoredOS implements a rudimentary but functional filesystem layer designed to support reading system assets and user applications during runtime. BoredOS implements a rudimentary but functional filesystem layer designed to support reading system assets and user applications during runtime.
## 🗂️ Virtual File System (VFS) ## Virtual File System (VFS)
The Virtual File System acts as an abstraction layer across different underlying storage mechanisms (even if, currently, only one type is fully utilized). System calls targeting files (`SYS_FS`) route through the VFS rather than interacting with the disk directly. The Virtual File System acts as an abstraction layer across different underlying storage mechanisms (even if, currently, only one type is fully utilized). System calls targeting files (`SYS_FS`) route through the VFS rather than interacting with the disk directly.
@@ -17,11 +17,11 @@ Key VFS functionalities include:
- **Path Parsing**: Resolving absolute and relative paths. - **Path Parsing**: Resolving absolute and relative paths.
- **SMP Safety**: All VFS and underlying FAT32 operations are protected by a global **Spinlock**. This ensures that multiple cores can safely read from the filesystem simultaneously without corrupting internal file seek pointers or directory cache states. - **SMP Safety**: All VFS and underlying FAT32 operations are protected by a global **Spinlock**. This ensures that multiple cores can safely read from the filesystem simultaneously without corrupting internal file seek pointers or directory cache states.
## 💾 FAT32 Implementation ## FAT32 Implementation
The primary filesystem logic in `fat32.c` handles both in-memory RAM-based filesystem simulation and physical ATA block devices. The primary filesystem logic in `fat32.c` handles both in-memory RAM-based filesystem simulation and physical ATA block devices.
### 💿 Storage Support ### Storage Support
BoredOS supports two main types of storage for its FAT32 implementation: BoredOS supports two main types of storage for its FAT32 implementation:
@@ -30,7 +30,7 @@ BoredOS supports two main types of storage for its FAT32 implementation:
- **GPT is NOT supported**: Currently, only **MBR (Master Boot Record)** partition tables or **raw (partitionless)** disks are supported. - **GPT is NOT supported**: Currently, only **MBR (Master Boot Record)** partition tables or **raw (partitionless)** disks are supported.
- **Filesystem**: The partition must be formatted as **FAT32**. - **Filesystem**: The partition must be formatted as **FAT32**.
### 🔍 Auto-detection ### Auto-detection
The `Disk Manager` automatically probes primary and secondary IDE channels during initialization. If a valid FAT32 partition is found (either directly at sector 0 or via an MBR partition table), the disk is assigned a drive letter (starting from `B:`) and becomes accessible to the VFS. The `Disk Manager` automatically probes primary and secondary IDE channels during initialization. If a valid FAT32 partition is found (either directly at sector 0 or via an MBR partition table), the disk is assigned a drive letter (starting from `B:`) and becomes accessible to the VFS.

View File

@@ -7,7 +7,7 @@
Memory management in BoredOS is split into physical and virtual layers, designed to support both kernel operations and userland isolation on the x86_64 architecture. Memory management in BoredOS is split into physical and virtual layers, designed to support both kernel operations and userland isolation on the x86_64 architecture.
## 🧠 Physical Memory Management (PMM) ## Physical Memory Management (PMM)
The PMM is responsible for tracking which physical RAM frames (usually 4KB each) are free and which are in use. The PMM is responsible for tracking which physical RAM frames (usually 4KB each) are free and which are in use.
@@ -19,7 +19,7 @@ The PMM is responsible for tracking which physical RAM frames (usually 4KB each)
> [!NOTE] > [!NOTE]
> 4KB frame sizes strike a balance between allocation speed and minimal memory fragmentation, fitting directly with the page tables. > 4KB frame sizes strike a balance between allocation speed and minimal memory fragmentation, fitting directly with the page tables.
## 🗺️ Virtual Memory Management (VMM) and Paging ## Virtual Memory Management (VMM) and Paging
BoredOS uses 4-level paging (PML4), a requirement for x86_64 long mode, dividing the virtual address space between the kernel and userland. BoredOS uses 4-level paging (PML4), a requirement for x86_64 long mode, dividing the virtual address space between the kernel and userland.
@@ -30,7 +30,7 @@ BoredOS uses 4-level paging (PML4), a requirement for x86_64 long mode, dividing
- **User Space**: Userland applications are loaded into lower virtual addresses. - **User Space**: Userland applications are loaded into lower virtual addresses.
- **Page Faults**: The `mem/` subsystem registers an Interrupt Service Routine (ISR) for page faults (Interrupt 14). If a process accesses unmapped memory, the handler determines whether to allocate a new frame or terminate the process. - **Page Faults**: The `mem/` subsystem registers an Interrupt Service Routine (ISR) for page faults (Interrupt 14). If a process accesses unmapped memory, the handler determines whether to allocate a new frame or terminate the process.
## 🏗️ Kernel Heap ## Kernel Heap
Dynamic allocation within the kernel (`kmalloc` and `kfree`) is layered on top of the physical allocator. The kernel maintains its own heap area in virtual memory. When the heap requires more space, it requests physical frames from the PMM and maps them into the kernel's virtual address space. Dynamic allocation within the kernel (`kmalloc` and `kfree`) is layered on top of the physical allocator. The kernel maintains its own heap area in virtual memory. When the heap requires more space, it requests physical frames from the PMM and maps them into the kernel's virtual address space.

View File

@@ -7,7 +7,7 @@
BoredOS features a fully custom, graphical Window Manager built directly into the kernel, residing in the `src/wm/` directory. It is responsible for compositing the screen, handling window logic, rendering text, and dispatching UI events. BoredOS features a fully custom, graphical Window Manager built directly into the kernel, residing in the `src/wm/` directory. It is responsible for compositing the screen, handling window logic, rendering text, and dispatching UI events.
## 🖼️ Framebuffer and Rendering ## Framebuffer and Rendering
1. **Limine Framebuffer**: During boot, the Limine bootloader requests a graphical framebuffer from the hardware (e.g., GOP in UEFI environments) and passes a pointer to this linear memory buffer to the kernel. 1. **Limine Framebuffer**: During boot, the Limine bootloader requests a graphical framebuffer from the hardware (e.g., GOP in UEFI environments) and passes a pointer to this linear memory buffer to the kernel.
2. **Double Buffering**: To prevent screen tearing, the WM does not draw directly to the screen. It allocates a "back buffer" in kernel memory equal to the size of the screen. All drawing operations (lines, rectangles, windows) happen on this back buffer. 2. **Double Buffering**: To prevent screen tearing, the WM does not draw directly to the screen. It allocates a "back buffer" in kernel memory equal to the size of the screen. All drawing operations (lines, rectangles, windows) happen on this back buffer.
@@ -24,7 +24,7 @@ The windowing system is built around a linked list of `Window` structures.
- **Window Structures**: Each window object tracks its dimensions (`x`, `y`, `width`, `height`), title, background color, and an internal buffer if it's acting as a canvas for userland apps. - **Window Structures**: Each window object tracks its dimensions (`x`, `y`, `width`, `height`), title, background color, and an internal buffer if it's acting as a canvas for userland apps.
- **Decorations**: The kernel handles drawing window borders, title bars, and close buttons automatically unless a borderless style is specified. - **Decorations**: The kernel handles drawing window borders, title bars, and close buttons automatically unless a borderless style is specified.
## 🖱️ Input Handling and Events ## Input Handling and Events
The WM acts as the central hub for input routing. The WM acts as the central hub for input routing.

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 KiB

File diff suppressed because it is too large Load Diff

157
src/userland/libc/libmath.c Normal file
View File

@@ -0,0 +1,157 @@
// Copyright (c) 2023-2026 Chris (boreddevnl)
// This software is released under the GNU General Public License v3.0. See LICENSE file for details.
// This header needs to maintain in any file it is present in, as per the GPL license terms.
#include "math.h"
static double _pow_int(double b, int e) {
if (e == 0) return 1.0;
if (e < 0) { return 1.0 / _pow_int(b, -e); }
double r = 1.0;
while (e > 0) {
if (e & 1) r *= b;
b *= b;
e >>= 1;
}
return r;
}
double fabs(double x) {
return x < 0.0 ? -x : x;
}
double fmod(double x, double y) {
if (y == 0.0) return 0.0;
return x - (int)(x / y) * y;
}
double floor(double x) {
int i = (int)x;
return (x < 0.0 && (double)i != x) ? (double)(i - 1) : (double)i;
}
double ceil(double x) {
int i = (int)x;
return (x > 0.0 && (double)i != x) ? (double)(i + 1) : (double)i;
}
double sin(double x) {
x = fmod(x, 2.0 * M_PI);
if (x > M_PI) x -= 2.0 * M_PI;
if (x < -M_PI) x += 2.0 * M_PI;
double x2 = x * x;
double term = x;
double sum = x;
for (int i = 1; i <= 8; i++) {
term *= -x2 / ((2*i) * (2*i + 1));
sum += term;
}
return sum;
}
double cos(double x) {
return sin(x + M_PI / 2.0);
}
double tan(double x) {
double c = cos(x);
if (fabs(c) < 1e-10) return 1e15;
return sin(x) / c;
}
double sqrt(double x) {
if (x <= 0.0) return 0.0;
double g = x * 0.5;
for (int i = 0; i < 25; i++) {
g = (g + x / g) * 0.5;
}
return g;
}
double log(double x) {
if (x <= 0.0) return -1e30;
int e = 0;
while (x > 2.0) { x /= 2.0; e++; }
while (x < 0.5) { x *= 2.0; e--; }
double t = (x - 1.0) / (x + 1.0);
double t2 = t * t;
double sum = t, term = t;
for (int i = 1; i <= 20; i++) {
term *= t2;
sum += term / (2*i + 1);
}
return 2.0 * sum + e * M_LN2;
}
double log2(double x) {
// log2(x) = ln(x) / ln(2)
return log(x) / M_LN2;
}
double log10(double x) {
return log(x) / 2.302585092994046;
}
double exp(double x) {
if (x > 700.0) return 1e300;
if (x < -700.0) return 0.0;
int k = (int)(x / M_LN2);
if (x < 0.0 && (double)k * M_LN2 > x) k--;
double r = x - (double)k * M_LN2;
double sum = 1.0, term = 1.0;
for (int i = 1; i <= 20; i++) {
term *= r / (double)i;
sum += term;
}
double result = sum;
if (k >= 0) { for (int i = 0; i < k; i++) result *= 2.0; }
else { for (int i = 0; i < -k; i++) result /= 2.0; }
return result;
}
double pow(double base, double exponent) {
if (base == 0.0) return 0.0;
if (exponent == 0.0) return 1.0;
int ie = (int)exponent;
if ((double)ie == exponent) return _pow_int(base, ie);
if (base < 0.0) return 0.0;
return exp(exponent * log(base));
}
double sinh(double x) {
double ep = exp(x);
double em = exp(-x);
return (ep - em) * 0.5;
}
double cosh(double x) {
double ep = exp(x);
double em = exp(-x);
return (ep + em) * 0.5;
}
double tanh(double x) {
double e2 = exp(2.0 * x);
return (e2 - 1.0) / (e2 + 1.0);
}
double hypot(double x, double y) {
return sqrt(x*x + y*y);
}
double fmin(double a, double b) {
return a < b ? a : b;
}
double fmax(double a, double b) {
return a > b ? a : b;
}
double fclamp(double x, double lo, double hi) {
if (x < lo) return lo;
if (x > hi) return hi;
return x;
}

40
src/userland/libc/math.h Normal file
View File

@@ -0,0 +1,40 @@
// Copyright (c) 2023-2026 Chris (boreddevnl)
// This software is released under the GNU General Public License v3.0. See LICENSE file for details.
// This header needs to maintain in any file it is present in, as per the GPL license terms.
#ifndef MATH_H
#define MATH_H
#define M_PI 3.14159265358979323846
#define M_E 2.71828182845904523536
#define M_LN2 0.69314718055994530942
#define M_SQRT2 1.41421356237309504880
#define HUGE_VAL (1e300 * 1e300)
double fabs(double x);
double fmod(double x, double y);
double floor(double x);
double ceil(double x);
double sin(double x);
double cos(double x);
double tan(double x);
double sqrt(double x);
double log(double x);
double log2(double x);
double log10(double x);
double exp(double x);
double pow(double base, double exponent);
double sinh(double x);
double cosh(double x);
double tanh(double x);
double hypot(double x, double y);
double fmin(double a, double b);
double fmax(double a, double b);
double fclamp(double x, double lo, double hi);
#endif /* MATH_H */

View File

@@ -151,8 +151,8 @@ int wallpaper_get_height(void) { return wp_height; }
void wallpaper_init(void) { void wallpaper_init(void) {
// We expect Limine modules to have been copied to /Library/images/Wallpapers/ by main.c // We expect Limine modules to have been copied to /Library/images/Wallpapers/ by main.c
// Set a default wallpaper if one exists // Set a default wallpaper if one exists
if (fat32_exists("/Library/images/Wallpapers/mountain.jpg")) { if (fat32_exists("/Library/images/Wallpapers/bored.jpg")) {
wallpaper_request_set_from_file("/Library/images/Wallpapers/mountain.jpg"); wallpaper_request_set_from_file("/Library/images/Wallpapers/bored.jpg");
} else if (fat32_exists("/Library/images/Wallpapers/moon.jpg")) { } else if (fat32_exists("/Library/images/Wallpapers/moon.jpg")) {
wallpaper_request_set_from_file("/Library/images/Wallpapers/moon.jpg"); wallpaper_request_set_from_file("/Library/images/Wallpapers/moon.jpg");
} }

View File

@@ -433,12 +433,14 @@ static void draw_dock_files(int x, int y);
static void draw_dock_settings(int x, int y); static void draw_dock_settings(int x, int y);
static void draw_dock_notepad(int x, int y); static void draw_dock_notepad(int x, int y);
static void draw_dock_calculator(int x, int y); static void draw_dock_calculator(int x, int y);
static void draw_dock_grapher(int x, int y);
static void draw_dock_terminal(int x, int y); static void draw_dock_terminal(int x, int y);
static void draw_dock_minesweeper(int x, int y); static void draw_dock_minesweeper(int x, int y);
static void draw_dock_paint(int x, int y); static void draw_dock_paint(int x, int y);
static void draw_dock_clock(int x, int y); static void draw_dock_clock(int x, int y);
static void draw_dock_taskman(int x, int y); static void draw_dock_taskman(int x, int y);
static void draw_dock_editor(int x, int y); static void draw_dock_word(int x, int y);
static void draw_dock_browser(int x, int y);
static void draw_dock_editor(int x, int y); static void draw_dock_editor(int x, int y);
static void draw_filled_circle(int cx, int cy, int r, uint32_t color); static void draw_filled_circle(int cx, int cy, int r, uint32_t color);
@@ -776,6 +778,11 @@ void draw_calculator_icon(int x, int y, const char *label) {
draw_icon_label(x, y, label); draw_icon_label(x, y, label);
} }
void draw_grapher_icon(int x, int y, const char *label) {
draw_scaled_icon(x, y, draw_dock_grapher);
draw_icon_label(x, y, label);
}
void draw_terminal_icon(int x, int y, const char *label) { void draw_terminal_icon(int x, int y, const char *label) {
draw_scaled_icon(x, y, draw_dock_terminal); draw_scaled_icon(x, y, draw_dock_terminal);
draw_icon_label(x, y, label); draw_icon_label(x, y, label);
@@ -994,6 +1001,42 @@ static void draw_dock_notepad(int x, int y) {
draw_rect(x + 33, y + 24, 1, 2, 0xFF555555); draw_rect(x + 33, y + 24, 1, 2, 0xFF555555);
} }
static void draw_dock_grapher(int x, int y) {
// Dark background with a panel look
draw_rounded_rect_filled(x, y, 48, 48, 10, 0xFF121212);
draw_rounded_rect_filled(x + 1, y + 1, 46, 28, 9, 0xFF1E1E1E);
draw_rounded_rect_filled(x + 1, y + 24, 46, 23, 9, 0xFF161616);
// Subtle grid (matches Grapher's theme)
uint32_t grid_color = 0xFF2A2A2A;
for (int i = 8; i < 40; i += 8) {
draw_rect(x + i, y + 6, 1, 36, grid_color);
draw_rect(x + 6, y + i + 6, 36, 1, grid_color);
}
// Axis line
draw_rect(x + 24, y + 10, 1, 28, 0xFF444444);
draw_rect(x + 10, y + 24, 28, 1, 0xFF444444);
// Vibrant Sine Wave (Neon Cyan)
uint32_t curve_color = 0xFF00E5FF;
int curve_y[] = {24, 23, 21, 19, 17, 16, 15, 15, 16, 17, 19, 21, 23, 24, 26, 28, 30, 32, 33, 33, 32, 30, 28, 26, 24, 23, 21, 19, 17, 16, 15, 15, 16, 17, 19, 21};
for (int i = 0; i < 35; i++) {
int x1 = x + 6 + i;
int y1 = y + curve_y[i];
int y2 = y + curve_y[i+1];
// Anti-aliased look with multi-point vertical connector
if (y1 < y2) for (int j = y1; j <= y2; j++) put_pixel(x1, j, curve_color);
else for (int j = y2; j <= y1; j++) put_pixel(x1, j, curve_color);
}
// Add white indicator "nodes" at the peaks
draw_filled_circle(x + 6 + 7, y + 15, 2, 0xFFFFFFFF);
draw_filled_circle(x + 6 + 18, y + 33, 2, 0xFFFFFFFF);
draw_filled_circle(x + 6 + 30, y + 15, 2, 0xFFFFFFFF);
}
static void draw_dock_calculator(int x, int y) { static void draw_dock_calculator(int x, int y) {
draw_rounded_rect_filled(x, y, 48, 48, 10, 0xFF111111); draw_rounded_rect_filled(x, y, 48, 48, 10, 0xFF111111);
draw_rounded_rect_filled(x + 1, y + 1, 46, 28, 9, 0xFF222222); draw_rounded_rect_filled(x + 1, y + 1, 46, 28, 9, 0xFF222222);
@@ -1309,6 +1352,7 @@ static void wm_paint_region(int y_start, int y_end, DirtyRect dirty, int pass) {
else if (str_starts_with(icon->name, "Recycle Bin")) draw_recycle_bin_icon(icon->x, icon->y, label); else if (str_starts_with(icon->name, "Recycle Bin")) draw_recycle_bin_icon(icon->x, icon->y, label);
else if (str_starts_with(icon->name, "Files")) draw_folder_icon(icon->x, icon->y, label); else if (str_starts_with(icon->name, "Files")) draw_folder_icon(icon->x, icon->y, label);
else if (str_starts_with(icon->name, "Paint")) draw_paint_icon(icon->x, icon->y, label); else if (str_starts_with(icon->name, "Paint")) draw_paint_icon(icon->x, icon->y, label);
else if (str_starts_with(icon->name, "Grapher")) draw_grapher_icon(icon->x, icon->y, label);
else draw_icon(icon->x, icon->y, label); else draw_icon(icon->x, icon->y, label);
} else { } else {
if (str_ends_with(icon->name, ".elf")) draw_elf_icon(icon->x, icon->y, icon->name); if (str_ends_with(icon->name, ".elf")) draw_elf_icon(icon->x, icon->y, icon->name);
@@ -1347,7 +1391,7 @@ static void wm_paint_region(int y_start, int y_end, DirtyRect dirty, int pass) {
int dock_h = 60, dock_y = sh - dock_h - 6; int dock_h = 60, dock_y = sh - dock_h - 6;
if (dock_y < cy + ch && dock_y + dock_h > cy) { if (dock_y < cy + ch && dock_y + dock_h > cy) {
int d_item_sz = 48, d_space = 10, d_total_w = 11 * (d_item_sz + d_space); int d_item_sz = 48, d_space = 10, d_total_w = 12 * (d_item_sz + d_space);
int d_bg_x = (sw - d_total_w) / 2 - 12, d_bg_w = d_total_w + 24; int d_bg_x = (sw - d_total_w) / 2 - 12, d_bg_w = d_total_w + 24;
draw_rounded_rect_blurred(d_bg_x, dock_y, d_bg_w, dock_h, 18, COLOR_DOCK_BG, 5, 140); draw_rounded_rect_blurred(d_bg_x, dock_y, d_bg_w, dock_h, 18, COLOR_DOCK_BG, 5, 140);
int dx = (sw - d_total_w) / 2, dy = dock_y + 6; int dx = (sw - d_total_w) / 2, dy = dock_y + 6;
@@ -1355,6 +1399,7 @@ static void wm_paint_region(int y_start, int y_end, DirtyRect dirty, int pass) {
draw_dock_settings(dx, dy); dx += d_item_sz+d_space; draw_dock_settings(dx, dy); dx += d_item_sz+d_space;
draw_dock_notepad(dx, dy); dx += d_item_sz+d_space; draw_dock_notepad(dx, dy); dx += d_item_sz+d_space;
draw_dock_calculator(dx, dy); dx += d_item_sz+d_space; draw_dock_calculator(dx, dy); dx += d_item_sz+d_space;
draw_dock_grapher(dx, dy); dx += d_item_sz+d_space;
draw_dock_terminal(dx, dy); dx += d_item_sz+d_space; draw_dock_terminal(dx, dy); dx += d_item_sz+d_space;
draw_dock_minesweeper(dx, dy); dx += d_item_sz+d_space; draw_dock_minesweeper(dx, dy); dx += d_item_sz+d_space;
draw_dock_paint(dx, dy); dx += d_item_sz+d_space; draw_dock_paint(dx, dy); dx += d_item_sz+d_space;
@@ -1992,7 +2037,7 @@ static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) {
int dock_y = sh - dock_h - 6; int dock_y = sh - dock_h - 6;
int dock_item_size = 48; int dock_item_size = 48;
int dock_spacing = 10; int dock_spacing = 10;
int total_dock_width = 11 * (dock_item_size + dock_spacing); int total_dock_width = 12 * (dock_item_size + dock_spacing);
int dock_bg_x = (sw - total_dock_width) / 2 - 12; int dock_bg_x = (sw - total_dock_width) / 2 - 12;
int dock_bg_w = total_dock_width + 24; int dock_bg_w = total_dock_width + 24;
@@ -2007,13 +2052,14 @@ static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) {
else if (item == 1) start_menu_pending_app = "Settings"; else if (item == 1) start_menu_pending_app = "Settings";
else if (item == 2) start_menu_pending_app = "Notepad"; else if (item == 2) start_menu_pending_app = "Notepad";
else if (item == 3) start_menu_pending_app = "Calculator"; else if (item == 3) start_menu_pending_app = "Calculator";
else if (item == 4) start_menu_pending_app = "Terminal"; else if (item == 4) start_menu_pending_app = "Grapher";
else if (item == 5) start_menu_pending_app = "Minesweeper"; else if (item == 5) start_menu_pending_app = "Terminal";
else if (item == 6) start_menu_pending_app = "Paint"; else if (item == 6) start_menu_pending_app = "Minesweeper";
else if (item == 7) start_menu_pending_app = "Browser"; else if (item == 7) start_menu_pending_app = "Paint";
else if (item == 8) start_menu_pending_app = "Task Manager"; else if (item == 8) start_menu_pending_app = "Browser";
else if (item == 9) start_menu_pending_app = "Clock"; else if (item == 9) start_menu_pending_app = "Task Manager";
else if (item == 10) start_menu_pending_app = "Word Processor"; else if (item == 10) start_menu_pending_app = "Clock";
else if (item == 11) start_menu_pending_app = "Word Processor";
} }
} else { } else {
wm_handle_click(mx, my); wm_handle_click(mx, my);
@@ -2156,6 +2202,10 @@ static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) {
else process_create_elf("/bin/boredword.elf", NULL); else process_create_elf("/bin/boredword.elf", NULL);
} else if (str_starts_with(start_menu_pending_app, "Terminal")) { } else if (str_starts_with(start_menu_pending_app, "Terminal")) {
cmd_reset(); wm_bring_to_front_locked(&win_cmd); cmd_reset(); wm_bring_to_front_locked(&win_cmd);
} else if (str_starts_with(start_menu_pending_app, "Grapher")) {
Window *existing = wm_find_window_by_title_locked("Grapher");
if (existing) wm_bring_to_front_locked(existing);
else process_create_elf("/bin/grapher.elf", NULL);
} else if (str_starts_with(start_menu_pending_app, "Calculator")) { } else if (str_starts_with(start_menu_pending_app, "Calculator")) {
Window *existing = wm_find_window_by_title_locked("Calculator"); Window *existing = wm_find_window_by_title_locked("Calculator");
if (existing) { if (existing) {