Skip to content

jvalver1/DigitalClock-CPP

Repository files navigation

# Digital Clock (C++ / SFML)

A responsive, high-performance digital clock application built using **C++** and **SFML 3.0**. The clock features a responsive layout system that adapts to any window size, maintaining perfect digit spacing and aspect ratio without overlapping.

## Features

* **Real-Time Display:** Shows current time (HH:MM:SS) and date (Day, Month DD, YYYY).
* **Responsive Layout:**
* Uses a "Virtual Box" rendering logic to maintain a 5.5:1 aspect ratio.
* Digits resize dynamically to fit the window.
* Intelligent spacing ensures digits never touch or spread too far apart.


* **Fullscreen Support:** Toggle between borderless fullscreen and windowed mode seamlessly.
* **State Persistence:** Remembers your preferred window size when switching back from fullscreen.
* **Embedded Resources:** Uses `FontData.h` to embed the font directly into the executable, removing the need for external asset files.

## Controls

| Key Combination | Action |
| --- | --- |
| **Alt + Enter** | Toggle Fullscreen / Windowed Mode |
| **Esc** | Exit Fullscreen Mode |
| **Mouse** | Resize window (contents adapt automatically) |

## Requirements

* **C++ Compiler:** GCC (MinGW-w64), Clang, or MSVC.
* **SFML Library:** Version **3.0.0** or later.
* *Note: This project uses `sf::State::Fullscreen`, which was introduced in SFML 3.0. It is not compatible with SFML 2.6.*



## Building the Project

### File Structure

Ensure your directory looks like this:

```text
/DigitalClock
  ├── main.cpp       # The application logic
  └── FontData.h     # Header containing the Orbitron font hex array

```

### Compilation (g++ / MinGW)

If you are compiling from the command line, link the SFML graphics, window, and system modules:

```bash
g++ main.cpp -o DigitalClock.exe -I<path/to/sfml/include> -L<path/to/sfml/lib> -lsfml-graphics -lsfml-window -lsfml-system

```

*Replace `<path/to/sfml/...>` with the actual paths where you installed SFML.*

## Configuration

### Adjusting Spacing

To change how spread out the digits are, modify the `targetAspectRatio` variable in `main.cpp`:

```cpp
// Higher value (e.g., 6.0f) = More spread out
// Lower value (e.g., 4.5f) = More compact
float targetAspectRatio = 5.5f;

```

### Adjusting Vertical Position

To change the vertical alignment, modify `boxStartY` in `main.cpp`:

```cpp
// Currently set to center minus 10% of height (moves it up)
float boxStartY = ((h - boxH) / 2.0f) - (h * 0.1f);

```

## License

This project is open source.

* **Font:** Orbitron (Open Font License).

About

A simple Windows resizable Digital clock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors