A modern, cross-platform scientific calculator built with C++ and the Raylib library. This project features a clean user interface with light/dark theme support, immediate feedback with detailed error messages, performance metrics display, and a responsive design that adapts to window resizing. It supports basic arithmetic operations, scientific functions, handles errors gracefully, and is structured for extensibility.
- Cross-Platform: Works on Windows, macOS, and Linux.
- Multi-Compiler Support: MSVC, Clang, and GCC with optimized settings.
- Embedded Resources: Fonts and icons are embedded in the executable for release builds, creating a single, portable application.
- Link Time Optimization (LTO): Enhanced performance in release builds.
- Responsive UI: Adapts to window resizing with configurable layouts.
- Light/Dark Theme: Toggle between light and dark mode with the theme button.
- Performance Metrics: Real-time display of FPS and frame time.
- Scientific Functions: Support for sin, cos, tan, log, sqrt and more.
- Detailed Error Handling: Informative error messages for calculation errors.
- Expression History: View previous calculations with results.
- No Console Window: Clean Windows GUI experience in release builds.
- Modern C++: C++11 standard with clean architecture.
- Easy to Build: Multiple build scripts and manual build options.
- CMake 3.10+ (build system)
- C++ Compiler (one of the following):
- Windows: MSVC 2019+, Clang 12+, or MinGW-w64
- macOS: Xcode Command Line Tools (Clang)
- Linux: GCC 9+ or Clang 12+
- Git (for cloning)
- MSVC: Visual Studio 2019 or later with C++ development tools
- MinGW: MinGW-w64 with GCC 9+ or Clang
- Xcode Command Line Tools:
xcode-select --install - Homebrew: Optional but recommended for additional tools
- Build Tools:
build-essential(Ubuntu/Debian) or equivalent - Development Libraries: Usually pre-installed with build tools
Command Prompt:
# Clone repository
git clone https://github.com/LulzSec6824/calculator_raylib.git
cd calculator_raylib
# Build and run
build.batGit Bash:
# Clone repository
git clone https://github.com/LulzSec6824/calculator_raylib.git
cd calculator_raylib
# Build and run
bash build.sh# Clone repository
git clone https://github.com/LulzSec6824/calculator_raylib.git
cd calculator_raylib
# Build and run
bash build_macos.sh# Clone repository
git clone https://github.com/LulzSec6824/calculator_raylib.git
cd calculator_raylib
# Build and run
bash build.shgit clone https://github.com/LulzSec6824/calculator_raylib.git
cd calculator_raylibChoose your preferred build type:
Debug Build (Development):
cmake -S . -B build -DCMAKE_BUILD_TYPE=DebugRelease Build (Production):
cmake -S . -B build -DCMAKE_BUILD_TYPE=ReleaseRelease with Debug Info:
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfoMinimal Size Release:
cmake -S . -B build -DCMAKE_BUILD_TYPE=MinSizeRelcmake --build build --config Release# Windows
.\build\Release\ray.exe
# macOS/Linux
./build/ray# Explicit compiler selection
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++# Visual Studio 2022 (Windows)
cmake -S . -B build -G "Visual Studio 17 2022"
# Ninja (Cross-platform)
cmake -S . -B build -G Ninja
# Xcode (macOS)
cmake -S . -B build -G Xcodecmake -S . -B build -DCMAKE_INSTALL_PREFIX=/custom/install/path# Configure with MSVC
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release
# Build
cmake --build build --config Release
# Run
.\build\Release\ray.exe# Configure with MinGW
cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release
# Build
cmake --build build --config Release
# Run
.\build\ray.exe# Configure with Xcode generator
cmake -S . -B build -G Xcode -DCMAKE_BUILD_TYPE=Release
# Build
cmake --build build --config Release
# Run
./build/Release/ray# Configure with GCC
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
# Build
cmake --build build --config Release
# Run
./build/ray# Windows: Install via Visual Studio Installer or Chocolatey
choco install cmake
# macOS: Install via Homebrew
brew install cmake
# Linux: Install via package manager
sudo apt install cmake build-essential # Ubuntu/Debian
sudo yum install cmake gcc-c++ make # CentOS/RHEL
sudo pacman -S cmake base-devel # Arch Linux# Windows: Install Visual Studio Build Tools
# Download from: https://visualstudio.microsoft.com/downloads/
# macOS: Install Xcode Command Line Tools
xcode-select --install
# Linux: Install build tools
sudo apt update && sudo apt install build-essential # Ubuntu/Debian# Ensure MinGW-w64 is installed and in PATH
# Download from: https://www.mingw-w64.org/
# Verify installation
gcc --version
g++ --version# Linux: Install development packages
sudo apt install libgl1-mesa-dev libx11-dev libxrandr-dev libxi-dev# Make scripts executable
chmod +x build.sh
chmod +x build_macos.sh# Use specific generator
# Visual Studio 2022
cmake -G "Visual Studio 17 2022" -A x64
# Visual Studio 2019
cmake -G "Visual Studio 16 2019" -A x64# Verify build files exist
ls -la build/
ls -la build/Release/ # Windows
ls -la build/ # macOS/Linux
# Check executable
file build/Release/ray.exe # Windows
file build/ray # macOS/Linux# Quick test run
./build/ray
# Check version info (Windows)
# Right-click executable → Properties → Detailscalculator_raylib/
├── .clang-format # Code formatting rules
├── .github/ # GitHub Actions workflows
│ └── workflows/
│ └── cmake-multi-platform.yml
├── CMakeLists.txt # Enhanced CMake configuration
├── README.md # This file
├── build.bat # Windows Command Prompt build
├── build.sh # Linux/macOS build script
├── build_macos.sh # macOS build script (legacy)
├── EMBEDDING_RESOURCES.md # Resource embedding documentation
├── includes/ # Header files
│ ├── button.h # Button structure and functions
│ ├── calculator.h # Calculator state and logic
│ ├── display.h # Display rendering logic
│ ├── embedded_resources.h # Embedded resources header
│ ├── font_ubuntu.h # Embedded font data
│ ├── icon_calc.h # Embedded icon data
│ ├── metrics.h # Performance metrics
│ ├── parser.h # Mathematical expression parser
│ └── theme.h # Theme definitions
├── raylib/ # Raylib library source
├── resource/ # Application resources
│ ├── Ubuntu-Regular.ttf # Application font
│ └── calc.png # Application icon
└── src/ # Source files
├── button.cpp # Button creation and rendering
├── calculator.cpp # Calculator logic and error handling
├── display.cpp # Display rendering implementation
├── fix_generated_headers.cpp # Utility to fix generated headers
├── main.cpp # Main application entry point
├── metrics.cpp # Performance metrics implementation
├── parser.cpp # Mathematical expression parser implementation
├── resource_exporter.cpp # Resource embedding utility
├── theme.cpp # Theme implementation
└── winmain.cpp # Windows GUI entry point
- Numbers: Click digit buttons (0-9)
- Operators: +, -, ×, ÷
- Equals: = to calculate result
- Clear: C to reset
- Backspace: ← to delete last character (also removes entire function names)
- Decimal: . for floating point numbers
- Sign: ± to toggle positive/negative
- ANS: Use previous result in new calculations
- Trigonometric: sin, cos, tan, asin, acos, atan
- Logarithmic: log (base 10), ln (natural logarithm)
- Other: √ (square root), ^ (power)
- Theme Toggle: Switch between light and dark mode with the ☀/☾ button
- Expression Display: Shows the full expression being built with auto-scrolling
- Result History: View previous calculations and their results
- Performance Metrics: Real-time FPS and frame time display
- Detailed Error Messages: Clear feedback for calculation errors (division by zero, invalid operations, etc.)
- Responsive Design: Adapts to window resizing
- Keyboard Support: Future enhancement planned
- Numbers: 0-9 keys
- Operators: +, -, *, /
- Equals: Enter key
- Clear: Escape key
The calculator now supports a comprehensive theming system with light and dark modes. You can customize the themes by modifying the Theme struct in src/theme.cpp and the category-based button colors in src/button.cpp:
// In src/theme.cpp, modify the Theme struct
struct Theme {
Color bgColor; // Background color
Color displayBoxColor; // Display box color
Color textColor; // Text color
Color buttonColor; // Default button color
};
// In src/button.cpp, modify colors for different button categories
std::unordered_map<int, Color> lightModeColors = {
{NUMBER, LIGHTGRAY},
{OPERATOR, SKYBLUE},
{FUNCTION, GOLD},
{CONTROL, ORANGE},
{SPECIAL, GREEN}
};- Replace
resource/Ubuntu-Regular.ttfwith your preferred font - Ensure the font supports your target languages
- Rebuild the project
- Define in button.h: Add new button definitions
- Add logic in calculator.cpp: Implement new button functionality
- Update layout: Modify grid positioning in
main.cppas needed
- Additional Scientific Functions: Add more functions like exp, factorial, absolute value
- Memory Functions: Add M+, M-, MR, MC buttons
- Persistent Settings: Save user preferences like theme choice
- Graphing Capabilities: Implement basic function graphing
- Custom Button Layout: Allow users to customize button arrangement
- Link Time Optimization (LTO): Enabled for all release builds
- Architecture-Specific: Uses native CPU features when possible
- Compiler Optimizations: Aggressive optimization flags per compiler
- Performance Metrics Display: Real-time FPS and frame time monitoring
- Efficient Rendering: Optimized drawing operations with category-based button rendering
- Memory Management: Minimal allocations during runtime with improved string handling
- Expression Parsing: Enhanced math parser with optimized error handling
- Smart Backspace: Efficiently removes entire function names in one operation
- Cached Theme Colors: Pre-calculated color values for different button categories
- Formatting: Uses
.clang-formatfor consistent style - Naming: Follows C++ standard conventions
- Comments: Doxygen-style documentation
- Manual Testing: Use provided test cases
- Cross-Platform: Test on all target platforms
- Edge Cases: Test division by zero, overflow, etc.
- Debug Builds: Use
-DCMAKE_BUILD_TYPE=Debugfor debugging - Address Sanitizer: Enabled for GCC/Clang debug builds
- Logging: Add debug output as needed
We welcome contributions! Here's how to get started:
-
Fork the repository
-
Clone your fork:
git clone https://github.com/YOUR_USERNAME/calculator_raylib.git cd calculator_raylib -
Create feature branch:
git checkout -b feature/your-feature-name
-
Make changes following the code style
-
Test thoroughly on your platform
-
Commit with clear messages:
git commit -m "Add scientific calculator mode" -
Push to your fork:
git push origin feature/your-feature-name
-
Create Pull Request with detailed description
- Follow .clang-format for consistent style
- Add tests for new features
- Update documentation for user-facing changes
- Test on multiple platforms when possible
- Bug Reports: Include platform, compiler, and build steps
- Feature Requests: Describe use case and expected behavior
- Performance Issues: Provide profiling data when possible
This project is licensed under the GNU General Public License v2 - see the LICENSE file for details.
- Raylib Team: For the excellent graphics library
- Contributors: All who have contributed to this project
- Community: For testing and feedback
Happy Calculating! 🧮
For the most up-to-date information, always check the latest release.